//
// Tools_PickDialogueLine_Overlay.h
//
// Created by Richard Rice - 01/11/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_PICKDIALOGUELINE_OVERLAY__
#define __TOOLS_PICKDIALOGUELINE_OVERLAY__

#ifdef ASURA_USE_DIALOGUE_SYSTEM

#include "Core/Asura_Hash.h"
#include "Core/Asura_Handle.h"
#include "Misc/list_tem.hpp"
#include "Interface/Asura_Overlay.h"

class Asura_Dialogue_Line;

class Tools_PickDialogueLine_Overlay : public Asura_Overlay
{
public :
	Tools_PickDialogueLine_Overlay(const char* szTitle,bool bMultipleSelect = false);
	~Tools_PickDialogueLine_Overlay();

	static void CreateOverlay();
	static void CloseOverlay();

	static bool OverlayExists();

	//pick an event using a modal overlay
	static Asura_Hash_ID PickLine(const char* szTitle,Asura_Hash_ID uInitialSelection = 0, bool bMultipleSelect = false, const Asura_Hash_ID uEventHash = ASURA_HASH_ID_UNSET );

	//gets result of last modal event picking
	static bool WasCancelled(){return s_bCancelled;}

	//Gets selection if multiple selection is used
	static int GetNumSelected();
	static Asura_Hash_ID GetSelection(int iIndex);

	//forces list to be recalculated in response to events being created/deleted etc
	static void InvalidateEventList(){s_bEventListInvalidated = true;}
	static void InvalidateLineList(){s_bLineListInvalidated = true;}

	void SetInitialSelection(Asura_Hash_ID uSelected);

private :
	Tools_PickDialogueLine_Overlay();
	
//	virtual void InitialiseOverlay(class Asura_Overlay* pxOverlay);
//	virtual void Update();

	void SetDefaultTitle();
	void InitialiseOverlay();


	float CalculateDropDownListWidth();


	void BuildLineList();
	void DeleteLineList();
	Asura_Hash_ID GetLineHash(int iIndex) const;

	void BuildEventList();
	void DeleteEventList();
	Asura_Hash_ID GetEventHash(int iIndex) const;

	void PerFrameUpdate();

	bool IsModal() const;
	void EndModal();
	void EnableMultipleSelection(bool bMultipleSelect);

	//update properties text for selected line
	void UpdatePropertiesText();

	static bool DoesLineSatisfySearchFilter(const Asura_Dialogue_Line* pxLine,const char* szWildcardSearchString);



	static void OnDoubleClickList(int iJunk){s_pxThis->OnOkay();}
	static void OnDoubleClickEventList(int iJunk){s_pxThis->OnEditEvent();}


	//overlay callbacks
	#define OVERLAY_VOID_CALLBACK(__FnName)\
	static void __FnName(int iThis){((Tools_PickDialogueLine_Overlay*)iThis)->__FnName();}\
	void __FnName();
	#define OVERLAY_BOOL_CALLBACK(__FnName)\
	static bool __FnName(int iThis){return ((Tools_PickDialogueLine_Overlay*)iThis)->__FnName();}\
	bool __FnName();

	OVERLAY_VOID_CALLBACK(OnOkay)
	OVERLAY_VOID_CALLBACK(OnCancel)
	OVERLAY_VOID_CALLBACK(OnEditEvent)
	OVERLAY_BOOL_CALLBACK(CanEditEvent)
	OVERLAY_BOOL_CALLBACK(CanEditTemplate)

	//OVERLAY_VOID_CALLBACK(OnDoubleClickList)

	OVERLAY_VOID_CALLBACK(CreateEventFromLines)
	OVERLAY_VOID_CALLBACK(EditTemplate)

#ifdef ASURA_USE_ARTICULATION_SYSTEM
	OVERLAY_VOID_CALLBACK(GenerateArticulationTextless)
	OVERLAY_VOID_CALLBACK(GenerateArticulationText)
	OVERLAY_VOID_CALLBACK(RegenerateArticulation)
	void GenerateArticulation(bool bTextless);
#endif

#if defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)
	void		AutoGenerateFacialAnimation(void) const;
	bool		CanAutoGenerateFacialAnimation(void) const;

	static void	AutoGenerateFacialAnimation(int iUserData);
	static bool	CanAutoGenerateFacialAnimation(int iUserData);
#endif	//defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)

	OVERLAY_VOID_CALLBACK(PlaySound)
	OVERLAY_VOID_CALLBACK(StopSound)

	OVERLAY_BOOL_CALLBACK(IsEnabled_OnOkay)
	OVERLAY_BOOL_CALLBACK(IsEnabled_OnCancel)

	#undef OVERLAY_VOID_CALLBACK
	#undef OVERLAY_BOOL_CALLBACK

	static void ShowTooltipForLine(int iIndex, const char* szLineName);


	enum
	{
		OVERLAY_CANCEL,
		OVERLAY_OKAY,
	} m_eResult;


	Asura_Hash_ID m_uInitialSelection;

	Asura_Hash_ID m_uMostRecentSelectedLine;//hash of most recent line selected by user
	static Asura_Hash_ID s_uSelectedLine;//hash of currently selected line
	int m_iLineIndex;
	bool m_bLineChanged;

	static bool m_bRegenAllLines;
	static int m_iNumLines;
	static int m_iCurrentLine;


	bool m_bMultipleSelection;
	static List<Asura_Hash_ID> s_xSelectionList;

	bool m_bFilterChanged;
	static bool s_bEventListInvalidated;
	static bool s_bLineListInvalidated;

	//text search filter
	static int s_iSearchOption;
	static Asura_String s_xSearchText;

	static bool s_bCancelled;//result of most recent use as a modal overlay

	//list of line names
	u_int m_uLineListSize;
	const char** m_apszLineList;
	class Asura_StringTree* m_pxLineStringTree;

	//list of events using the selected line
	bool m_bAnyEvents;
	u_int m_uEventListSize;
	const char** m_apszEventList;
	class Asura_StringTree* m_pxEventStringTree;
	int m_iEventIndex;
	List<Asura_Hash_ID> m_xEventSelectionList;



	class Asura_List_Dialog* m_pxLineListDialog;
	class Asura_List_Dialog* m_pxEventListDialog;
	class Asura_Dialog* m_pxIDDialog;
	class Asura_Dialog* m_pxCharacterDialog;
	class Asura_Dialog* m_pxTemplateDialog;
	class Asura_Dialog* m_pxTextDialog;
#ifdef ASURA_USE_ARTICULATION_SYSTEM
	class Asura_Tickbox_Dialog* m_pxCheckboxArticulation;
#endif
#if defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)
	Asura_Dialog*	m_pxFaceTypeDialog;
	Asura_Dialog*	m_pxBaseFacePoseDialog;
#endif	// defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)

	Asura_Handle m_iSoundHandle;
	static bool s_bAutoPreview;
#ifdef ASURA_USE_ARTICULATION_SYSTEM
	static bool s_bHasArticulation;
#endif
	//most recently used filters
	static Asura_Hash_ID s_uCharacterFilter;

	// Are we only displaying lines from one event?
	static bool s_bSingleEventOnly;
	static Asura_Hash_ID s_uEventHash;

	static Tools_PickDialogueLine_Overlay* s_pxThis;
public :
	static Asura_Vector_2 s_xOverlayPosition;
};

#endif //ASURA_USE_DIALOGUE_SYSTEM


#endif //__TOOLS_PICKDIALOGUELINE_OVERLAY__
