/*********************************************************************
*	HUD ( head up display )
*	HEADER FILE
*	Autor:	Michal Jirouš
*	Datum: 12.9.2008
*	Soubor: HUD.h
*	Popis: Zde je definovana trida pro predpis vykreslovani a ovladani
*			informacnich panelu ve hre jako napriklad zdravi, pocet naboju
*			zamerovac.
**********************************************************************/


#ifndef __HUD_H__
#define __HUD_H__

#include "gfg.h"
#include "SDL/SDL.h"
#include "graphics.h"
#include <list>
namespace HUD
{
	const int NORMAL = 0;
	const int SETTING = 1;

	extern int g_iHUDState;
	

	const float BUTTON_WIDTH = 250.0f;
	const float BUTTON_PREFFERED_HEIGHT = 32.0f;
	const float CONTAINER_HOR_PADDING = 0.1f;
	const float WINDOW_HEIGHT_ADDING_CONSTANT = GFG_SUBWINDOW_PADDING + GFG_SUBWINDOW_TOP_PANEL_HEIGHT;
	
	const float WINDOW_HEIGHT = BUTTON_PREFFERED_HEIGHT * 3.0f + WINDOW_HEIGHT_ADDING_CONSTANT;

	enum HUD_components
	{
		HUD_BUTTON_OK = 1,
		HUD_BUTTON_DEFAULT,
		HUD_BUTTON_CANCEL
	};

	const int HUD_VALUE_HOLDER_ANIM_NUM_STEPS = 100;
	const float HUD_VALUE_HOLDER_ANIM_MAX	 = 1.1f;
	const float HUD_VALUE_HOLDER_ANIM_MIN	 = 1.0f;
	const Uint32 HUD_VALUE_HOLDER_TIME_PERIOD		 = 30;
	const Uint32 HUD_VALUE_HOLDER_BACK_TIME_PERIOD	 = 1000;
	const float HUD_VALUE_HOLDER_MAX_ALPHA			 = ALPHA_OPAQUE;

	class HUDValueHolder
	{
		Uint32 m_uiBackTime;
		Color4I m_ColorDefault, m_ColorCritical, m_ColorHighLighted;
		Color4I m_vecColorChange, m_ColorCurrent;
		Uint32 m_uiTimePeriod;
		
		int m_iAnimStepLeft;
		int m_iValue, m_iCriticalValue;
		float m_fScaleValue, m_fScaleStep;
		bool m_bValueSet;

		void setString();
		void createColorChangeVector();
		void saveValue( int value );
		void determineTargetColor( Color4I &store_here );
		void update();
	public:
		std::string m_sValue;
		HUDValueHolder();
		void reInitValue();
		void setCriticalValue( int value ) { m_iCriticalValue = value; }
		void setColorDefault( const Color4I &color )	{ m_ColorDefault = color; }
		void setColorCritical( const Color4I &color )	{ m_ColorCritical = color; }
		void setColorHighLighted( const Color4I &color )	{ m_ColorHighLighted = color; }
		void setValue( int value );
		void setValueHighLighted( int value );
		void draw( float x, float y, std::string font, float aplha = 0.95f );
		void run();
	};


	const Color4I HUD_COLOR_WINDOW_TOP_AVERAGE		( 255, 64, 196,  230 );
	const Color4I HUD_COLOR_WINDOW_TOP_DARK			( 255, 64, 196,  230 );
	const Color4I HUD_COLOR_WINDOW_TOP_LIGHT		( 255, 196, 255, 255 );
	const Color4I HUD_COLOR_WINDOW_TOP_LIGHTUNFOCUSED	( 255, 64, 128, 64 );

	const Color4I HUD_COLOR_CRITICAL				( 255, 32, 32 , 210 );

	const float HUD_WINDOW_PACKING_BUTTON_OFFSET = 1.0f;

	class HUDBaseWindow : public CSubWindow
	{
		void onCancelButtonClick();
		virtual void windowTopPanelDraw( ScissorBox &scissorBox );
	protected:
		HUDValueHolder m_ValueHolder;
		void HUDBaseWindowInit();
		virtual void componentDraw( ScissorBox &scissorBox ) = 0;
	public:
		virtual void onDefault() = 0;
		virtual void onCancel() = 0;
		virtual void onSave() = 0;
		virtual void onRun() = 0;
		HUDBaseWindow();
		virtual void draw( ScissorBox &scissorBox );
	};

	class CHUD : public CMainWindow
	{
		Button *m_pButtonOK, *m_pButtonDefault, *m_pButtonCancel;
		CSubWindow *m_pHUDWindow;
		list<HUDBaseWindow*> m_windows;
		HUDBaseWindow *m_pCrosshairWindow;
	public:
		CHUD();
		~CHUD();
		void setState( int state );
		void use_this_run();
		void use_this_draw();
		void refresh();
		void onSave();
		void onCancel();
		void onDefault();

		void init( float width, float height );
		void HUD_SDL_controller( SDL_Event &event );
		void addWindow( HUDBaseWindow *window );

		HUDBaseWindow *getCrosshairWindow() { return m_pCrosshairWindow; }
		void setCrosshair( int id );
	};
	extern CHUD hud;


};

#endif
