//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: MiniMap.h: interface for the CMiniMap class.
//
// $NoKeywords: $
//=============================================================================//

#if !defined CHUDMINIMAP_H
#define CHUDMINIMAP_H
#ifdef _WIN32
#pragma once
#endif

#include <vgui_controls/Panel.h>
#include <game/client/iviewport.h>
#include <mathlib/vector.h>
#include <igameevents.h>
#include <shareddefs.h>
#include <const.h>
#include "Sprite.h"

#include <vgui/MouseCode.h>

#define OVERVIEW_MAP_SIZE	1024	// an overview map is 1024x1024 pixels

//using namespace vgui;

class CHudMiniMap : public vgui::Panel, public IGameEventListener2
{
	
	DECLARE_CLASS_SIMPLE( CHudMiniMap, vgui::Panel );

public:	

	enum
	{
		MAP_MODE_OFF = 0,
		MAP_MODE_INSET,
		MAP_MODE_FULL
	};

	CHudMiniMap( const char *pElementName );

	virtual ~CHudMiniMap();

	//virtual const char *GetName( void ) { return "HudMiniMap"; }

	//virtual bool ShouldDraw( void );

#define MAP_OBJECT_ALIGN_TO_MAP	(1<<0)

public: // IViewPortPanel interface:

	virtual void SetData(KeyValues *data);
	void togglePrint(); 

	/////////////
	/////////////
	virtual void Reset();
	virtual void OnThink();
	virtual void Update();
	virtual bool NeedsUpdate( void );
	virtual void ShowPanel( bool bShow );
	virtual void Init( void );
	/////////////
	/////////////

	virtual bool IsVisible() { return BaseClass::IsVisible(); }

protected:	// structures
	typedef struct MapUnit_s {
		Color		color;		// units team color
		Vector	position;	// current x,y pos
		//QAngle		angle;		// view origin 0..360
		//float		size;		// object size
	} MapUnit_t;

	typedef struct MapBounderies_s {
		Vector points[4];
	} MapBounderies_t;

	typedef struct MapObjects_s {
		Vector position;
		Color color;
		int type;
		int	hsize;
		string_t icon;
	} MapObjects_t;

	enum object_types {
		OBJECT_BUILDING = 0,
		OBJECT_CP,
		OBJECT_OBJ,
	};

public: // IGameEventListener

	virtual void FireGameEvent( IGameEvent *event);
	
public:	// VGUI overrides

	virtual void Paint();
	virtual void ApplySchemeSettings(vgui::IScheme *scheme);
	
public:

	virtual float GetZoom( void );
	virtual int GetMode( void );

	// general settings:
	virtual void SetMap(const char * map);
	virtual void SetMode( int mode );
	virtual void SetAngle( float angle);
	virtual Vector2D WorldToMap( const Vector &worldpos );
	virtual Vector2D MapToWorld( Vector2D &offset );
	void	ApplyRotation( Vector *in, Vector *out );

public:
	MESSAGE_FUNC_INT_INT( OnCursorMoved, "OnCursorMoved", x, y );
	virtual void OnMousePressed(vgui::MouseCode code);
	virtual void OnMouseReleased(vgui::MouseCode code);

	void GoToPanelPos( void );
	bool IsValidPosition( Vector position );

protected:		// drawing
	virtual void    DrawPosPlayer( void ); 
	virtual void	DrawUnits( void );
	virtual void	DrawMapObjects();
	virtual void	DrawBackground();
	virtual void	DrawMapTexture( Vector2D *pointsvec );
	virtual void	DrawMapBounderies( );
	virtual void	DrawFOWTexture( Vector2D *pointsvec );

protected:		// updating
	void			UpdateUnits();
	void			UpdateMapBounderies();
	void			UpdateMapObjects();

protected:
	float GetViewAngle( void ); // The angle that determines the viewport twist from map texture to panel drawing.

	bool			IsInPanel(Vector2D &pos);
	Vector2D		MapToPanel( const Vector2D &mappos, bool rotate );
	Vector2D		PanelToMap( Vector2D &panelpos );
	int				GetPixelOffset( float height );
	//void			UpdateFollowEntity();

	int				m_nMode;
	Vector2D		m_vPosition;
	Vector2D		m_vSize;
	float			m_flChangeSpeed;

	IViewPort *		m_pViewPort;

	int m_nBackgroundTextureID;	// texture id for background
	int	 m_nMapTextureID;		// texture id for current overview image
	
	KeyValues * m_MapKeyValues; // keyvalues describing overview parameters

	Vector	m_MapOrigin;	// read from KeyValues files
	float	m_fMapScale;	// origin and scale used when screenshot was made
	bool	m_bRotateMap;	// if true roatate map around 90 degress, so it fits better to 4:3 screen ratio

	//int		m_nFollowEntity;// entity number to follow, 0 = off
	CPanelAnimationVar( float, m_fZoom, "zoom", "1.0f" );	// current zoom n = overview panel shows 1/n^2 of whole map'
	float	m_fFullZoom;	// best zoom factor for full map view (1.0 is map is a square) 
	Vector2D m_ViewOrigin;	// map coordinates that are in the center of the pverview panel
	Vector2D m_MapCenter;	// map coordinates that are in the center of the pverview panel

	float	m_fNextUpdateTime;
	float	m_fViewAngle;	// rotation of overview map
	float	m_fWorldTime;	// current world time
	//float   m_fNextTrailUpdate; // next time to update player trails
	//float	m_fTrailUpdateInterval; // if -1 don't show trails
	bool	m_bFollowAngle;	// if true, map rotates with view angle

	int m_nIcon;

	// objective icons
	CHudTexture *pObjectiveIcon;
	Color	m_clrObjectiveIcon;

	CHudTexture *pBuildingIcon;

	CHudTexture *pResourceIcon;

	// fog of war
	int m_iFogOfWar;
	int m_iFOWSize;
	int m_iFOWSizeWorldH;
	
	CUtlVector<MapUnit_t> m_MapUnits;	// unit objects
	CUtlVector<MapBounderies_t> m_MapBounderies;	// map bounderies
	CUtlVector<MapObjects_t> m_MapObjects;

private:
	int mouse_x_move;
	int mouse_y_move;
	bool left_mouse_pressed;
	bool right_mouse_pressed;
	float m_fLastViewAngle;
};

#endif //