//
// Tools_GUIMenu_System.h
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_GUIMENU_SYSTEM__
#define __TOOLS_GUIMENU_SYSTEM__

#ifdef ASURA_USE_GUI_MENU_SYSTEM
#include "GUIMenu/Asura_GUIMenu_System.h"

struct Asura_Message_GUIMenu_Activate;
class Tools_GUIMenu_FileData;

template <class T> class List;

static const char* szTOOLS_GUIMENU_SEQUENCES_FILE = "GUIMenu\\sequences.asr";
static const char* szTOOLS_GUIMENU_TEXTUREFLAGS_FILE = "GUIMenu\\GUITextureFlags.asr";
static const char* szTOOLS_GUIMENU_AUDIO = "GUIAudio";

class Tools_GUIMenu_System
{
public :
	enum Element_Filter
	{
		ELEMENT_FILTER_ALLOW_ALL = 0,
		ELEMENT_FILTER_ALLOW_IMAGES,
		ELEMENT_FILTER_ALLOW_TEXT,
		ELEMENT_FILTER_ALLOW_PATH,
		ELEMENT_FILTER_ALLOW_STATUSTEXT,
	};

	static void Initialise();
	static void Shutdown();

	static void Update();

	//returns true if any guimenu files are modified
	static bool IsModified();	
	//Save all guimenu files
	static void SaveAll();
	//save all files marked as modified
	static void SaveModified();
	
	static bool SaveAudioData( void);
	static bool IsAudioModified( void);

	//sets the file containing the menu as modified
	static void SetModified(class Asura_GUIMenu_Menu_Page* pxMenu);

	//szFilename is filename without path/extension
	static void SetModified(const char* szFilename);

	//set the animator sequences file as modified
	static void SetAnimatorsModified();

	//set the menu texture flags file as modified
	static void SetTextureFlagsModified();

	//Checks to make sure the file is writeable
	//szFilename is filename without path/extension
	static bool CanSaveFile(const char* szFilename);

	//Used by Tools_SaveAsura to mark the sound event files as ones to be tracked
	static void SetFilesToCheckForExternalModification();

	//Used by Tools_SaveAsura to load the .gui specific to a given level.
	static void LoadLevelSpecificFile();


	//Gets default file for new events
	//static const char* GetDefaultFile() {return "Default";}

	//Gets the dummy filename used to represent the level specific gui
	//(The file itself will share the same name as the level)
	static const char* GetLevelSpecificFile() {return "Level";}

	//Get the full name of the level specific file (will change during exports)
	static const char* GetLevelSpecificFilename();

	//gets a list of filenames (without path/extension) used by the menus
	static void ListMenuFiles(List<Asura_String>& xOutputList);

	//static bool IsLevelSpecific(const class Asura_Dialogue_Event* pxEvent);

	//Registers a new event that has been created in this trip into tools
	//This is used to track which ones can be safely transferred between files.
//	static void RegisterNewEvent(const class Asura_Dialogue_Event* pxEvent);
//	static bool CanTransferEvent(const class Asura_Dialogue_Event* pxEvent,const char* szDestFile);

	//main dialogue overlay
	static void ToggleOverlay();
	static bool OverlayIsOn();
	
	//Adds some sound event editing controls to another overlay
	static void AddOverlayControls(class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);
	static void CloseOverlays();


	//Checks gui for errors ,and shows a log of them if any are found
	static void Verify(bool bAutomatic);

	static bool SaveMenuPageAndContents(const char* szFileName);
	static void SaveAnimators();
	static void SaveTextureFlags();

	static char** GetAvailableMenuPageNames( int* piMenuMageCount);

	// Count all descendants from the root widget
	static u_int CountAllWidgetsRecursive( Asura_GUIMenu_Root* pxWidgetRoot);

	static const Asura_Char** GetAllMenuWidgetNames( Asura_Hash_ID uHashMenu, int* piItemCount, const Asura_Hash_ID** puHashIDs = NULL);

	static const Asura_Hash_ID* GetCurrentHashIds();

	static const Asura_Char** GetAllWidgetElementNames( Asura_Hash_ID uHashWidget, int* piItemCount, Element_Filter eFilterType);


	static void AddOverlayControls_ActivateGUIMenuPage(struct Asura_StaticMessage* pxMessage,class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);

	//Gets/set a sort key which is used for determining the order to use in the tree view in tools.
	static int GetFileSortKey(const char* szFile);
	static void SetFileSortKey(const char* szFile,int iSortKey);

	static void SetAudioModified( void);

private :
	
	// Fill in the static s_ppcMenuWidgetNames with all names of descendants
	static u_int GetAllWidgetNamesRecursive( Asura_GUIMenu_Root* pxWidgetRoot, u_int uCurrentCount);

	static void DestroyStaticCollections();

	static bool SaveFile(const char* szFilename);
	static void AddTextureToNameTree(int iTextureID, void* pTree);

	static void Verify() {Verify(false);}

	//adds path and extension to get full filename
	static void GetFullFilename(const char* szFilename,Asura_String& xFullFilename);
	static void GetIDListFilename(const char* szFilename,Asura_String& xFullFilename);
	static bool OutputGUIMenuIDInfo( const char* szFileName);

	static void _MenuNameListBoxCallBack( void);

	static Tools_GUIMenu_FileData* GetFileData(const char* szFile);

	static void GetFullAudioFilename(const char* szFilename,Asura_String& xFullFilename);

	static bool s_bGlobalSettingsChanged;

	static bool	s_bAudioDataChanged;

	static Asura_Vector_2 s_xOverlayPosition;

	static List<Asura_String> s_xModifiedFiles;
	static List<Tools_GUIMenu_FileData*> s_xFileDataList;
	static bool s_bAnimatorsModified;
	static bool s_bTextureFlagsModified;

	static const char* s_apszAvailableMenuNames[ASURA_GUIMENU_MAX_MENU_PAGES+1];	// +1 is so first entry can be reserved for nothing selected etc...

	static const Asura_Char** s_ppcMenuWidgetNames;
	static const Asura_Char** s_ppcWidgetElementNames;
	static Asura_Hash_ID* s_puMenuWidgetHashes;
	static u_int s_uWidgetCount;

	static int			s_iSelectedMenuIndex;
	static Asura_Message_GUIMenu_Activate* s_pxSelectedMenuMsgData;
};

//stores tools data associated with a menu file
class Tools_GUIMenu_FileData
{
public :
	Tools_GUIMenu_FileData(const char* szFile);


	Asura_String m_xFilename;
	int m_iSortKey;
};



#endif //ASURA_USE_GUI_MENU_SYSTEM
#endif //__TOOLS_GUIMENU_SYSTEM__
