#ifndef CGAMECONTEXT_H_INCLUDED
#define CGAMECONTEXT_H_INCLUDED

#include <iostream>
#include <vector>
#include <irrlicht.h>
#include <dirent.h>
#include "CRemontee.h"
#include "CSaveManager.h"
#include "CSettingManager.h"

using namespace irr;

/*
Application context for global variables
*/
struct SAppContext
{
	enum GUIConstants
    {
        GUI_ID_BUTTON_NOUVELLE_PISTE = 3,
        GUI_ID_BUTTON_NOUVEAU_RM = 2,
        GUI_ID_CONSTRUCTION_BUTTON = 1,
        GUI_ID_BUTTON_ARBRES=4,
        GUI_ID_BUTTON_RECHERCHE=5,
        GUI_ID_BUTTON_MENU=6,
        GUI_ID_WINDOW_CONSTRUCTION=7,
        GUI_ID_WINDOW_MENU=8,
        GUI_ID_BUTTON_SAVE=9,
        GUI_ID_BUTTON_QUIT=10,
        GUI_ID_BUTTON_TKFIXE = 11,
        GUI_ID_WINDOW_TYPE_RM=12,
        GUI_ID_WINDOW_PYLONES=13,
        GUI_ID_BUTTON_NOUVEAU_PYLONE=14,
        GUI_ID_BUTTON_TERMINER_PYLONE=15,
        GUI_ID_BUTTON_KILL_LAST_PYLONE=16,
        GUI_ID_WINDOW_NEW_PYLONE=17,
        GUI_ID_SCROLL_BAR_NEW_PYLONE=18,
        GUI_ID_COMBO_TYPE_PYLONE=19,
        GUI_ID_BUTTON_VALIDE_PYLONE=20,
        GUI_ID_BUTTON_ANNULE_PYLONE=21,
        GUI_ID_BUTTON_TS2FIXE = 22,
        GUI_ID_WINDOW_TREE_CUT=23,
        GUI_ID_BOUTON_TREE_CUT=24,
        GUI_ID_WINDOW_STOP_PLANT_TREE=25,
        GUI_ID_BUTTON_STOP_PLANT_TREE=26,
        GUI_ID_WINDOW_ETAT_RM=27,
        GUI_ID_TEXT_NOM_RM=28,
        GUI_ID_BUTTON_MARCHE_RM=29,
        GUI_ID_SCROLL_BAR_VITESSE_RM=30,
        GUI_ID_BUTTON_FERME_ETAT_RM=31,
        GUI_ID_WINDOW_STOP_TREE=32,
        GUI_ID_BOUTON_STOP_TREE=33,
        GUI_ID_BUTTON_TKDEBRAYABLE = 34,
        GUI_ID_BUTTON_LAUNCHPERCHETKD = 35,
    };

    enum GameActions
    {
        ACTION_NONE=0,
        ACTION_PLANT_TREES=1,
        ACTION_BUILD_SLOPE=2,
        ACTION_BUILD_TKF_DEPART=3,
        ACTION_BUILD_TKF_PYLONES=4,
        ACTION_BUILD_TKF_ARRIVEE=5,
        ACTION_BUILD_TKF_NEW_PYLONE=6,
        ACTION_BUILD_TSF2_DEPART=7,
        ACTION_BUILD_TSF2_PYLONES=8,
        ACTION_BUILD_TSF2_ARRIVEE=9,
        ACTION_BUILD_TSF2_NEW_PYLONE=10,
        ACTION_BUILD_TKD_DEPART=11,
        ACTION_BUILD_TKD_PYLONES=12,
        ACTION_BUILD_TKD_ARRIVEE=13,
        ACTION_BUILD_TKD_NEW_PYLONE=14,
    };

	SAppContext()
		: Device(0),Gui(0), Driver(0), SaveManager(0), Settings(0), ShouldQuit(false),
		construtionButton(0), newRMButton(0), newPisteButton(0),
		newArbreButton(0), rechercheButton(0),menuButton(0),saveButton(0),quitButton(0),windowConstruction(0),windowMenu(0)
	{
	}

	~SAppContext()
	{
		if (SaveManager)
			delete SaveManager;

		if (Device)
		{
			Device->closeDevice();
			Device->drop();
		}
	}

	IrrlichtDevice* Device;
	gui::IGUIEnvironment* Gui;
	video::IVideoDriver* Driver;
	CSaveManager* SaveManager;
	CSettingManager* Settings;
	bool ShouldQuit;

	s32 gameAction;
	core::stringc textExplic;
	CRemontee* currentRemontee;
	CPyloneRM* currentPylone;

	//GUI
	gui::IGUIButton* construtionButton;
	gui::IGUIButton* newRMButton;
	gui::IGUIButton* newPisteButton;
	gui::IGUIButton* newArbreButton;
    gui::IGUIButton* rechercheButton;
	gui::IGUIButton* menuButton;
	gui::IGUIButton* saveButton;
	gui::IGUIButton* quitButton;
    gui::IGUIButton* tkfixeButton;
    gui::IGUIButton* ts2fixeButton;
    gui::IGUIButton* tkdebrayableButton;

	gui::IGUIWindow* windowConstruction;
	gui::IGUIWindow* windowMenu;
	gui::IGUIWindow* windowTypeRm;
	gui::IGUIWindow* windowPylones;
	gui::IGUIWindow* windowNewPylone;
	gui::IGUIStaticText* labelNbPylone;

	gui::IGUIButton* newPyloneButton;
	gui::IGUIButton* terminePyloneButton;
	gui::IGUIButton* killLastPyloneButton;

	gui::IGUIComboBox* comboboxTypePylone;
	gui::IGUIScrollBar* scrollbarNewPylone;
	gui::IGUIButton* validePyloneButton;
	gui::IGUIButton* annulePyloneButton;

	gui::IGUIWindow* windowStopTree;
	gui::IGUIWindow* windowCutTree;
	gui::IGUIButton* cutTreeButton;
	gui::IGUIButton* stopTreeButton;

    gui::IGUIWindow* windowRMControl;
    gui::IGUIEditBox* editBoxNameRM;
    gui::IGUIButton* marcheArretRMButton;
    gui::IGUIStaticText* labelVitesseRM;
    gui::IGUIScrollBar* scrollbarVitesseRM;
    gui::IGUIButton* fermeRMControlButton;
    gui::IGUIButton* lauchPercheTkdButton;

    gui::IGUIWindow* windowSaveName;
    gui::IGUIEditBox* editBoxSaveName;
    gui::IGUIButton* okSaveButton;
};

class CGameContext
{
    public:

	CGameContext();

	~CGameContext();

	core::array<core::stringc> LoadMaps();
	core::stringc GetSelectedMap();
	void SetSelectedMap(core::stringc mapname);

	private:
    core::stringc selectedmap;
};


#endif // CGAMECONTEXT_H_INCLUDED
