//
// Tools_Overlay_PickMaterialResponse.h
//
// Created by Richard Rice - 19/06/2007
// 
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_OVERLAY_PICKMATERIALRESPONSE__
#define __TOOLS_OVERLAY_PICKMATERIALRESPONSE__

#if defined ASURA_USE_MATERIAL_RESPONSE_SYSTEM

#include "Interface/Asura_Tree_Dialog.h"
#include "Misc/Tools_Modal_Overlay.h"

class Tools_Overlay_PickMaterialResponse : public Tools_Modal_Overlay
{
public :
	Tools_Overlay_PickMaterialResponse(const char* szTitle);
	//~Tools_Overlay_PickMaterialResponse();

	bool DoModal(Asura_Hash_ID uInitialSelection);

	Asura_Hash_ID GetSelection() const;

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

	void UpdateImageDialog();
	void UpdateTreeDialog();


	#define OVERLAY_VOID_CALLBACK(__FnName)\
	static void __FnName(int iThis){((Tools_Overlay_PickMaterialResponse*)iThis)->__FnName();}\
	void __FnName();

	#define OVERLAY_BOOL_CALLBACK(__FnName)\
	static bool __FnName(int iThis){return ((Tools_Overlay_PickMaterialResponse*)iThis)->__FnName();}\
	bool __FnName();

	
	OVERLAY_VOID_CALLBACK(OnOkay)
	OVERLAY_VOID_CALLBACK(OnCancel)

	OVERLAY_BOOL_CALLBACK(IsEnabled_Okay)

	#undef OVERLAY_VOID_CALLBACK
	#undef OVERLAY_BOOL_CALLBACK


	Asura_Hash_ID m_uInitialSelection;
	bool m_bOkaySelected;

	bool m_bSelectionChanged;

	Asura_TreeDialog_Tree m_xMaterialNameTree;
	Asura_Tree_Dialog* m_pxTreeDialog;
	class Asura_Image_Dialog* m_pxImageDialog;

	static bool s_bFilterTreeByEnv;
	bool m_bFilterTreeByEnvChanged;

};

//specialised UI for choosing a MaterialResponse
class Tools_MaterialResponse_Dialog : public Asura_Dialog
{
public :
	Tools_MaterialResponse_Dialog(Asura_Vector_2& xOffset, Asura_Hash_ID* puMaterialResponse, bool* pbChangedFlag = 0);

	// Helpers to make it more obvious how to use this class.
	const char* GetMaterialResponseName() {return m_xMaterialResponseName.GetString();}
	Asura_Hash_ID GetMaterialResponseHash() { return m_uHash; }

	void SetMaterialResponseHash(Asura_Hash_ID uHash);
	void SetFilter(const char*pFilter);

	void UpdateLabel(const char* text);

	void UpdateMax();

	virtual void Render( const Asura_Vector_2& xOrigin );
	virtual void Update( const Asura_Vector_2& xOrigin );

protected:
	void Clicked();

	bool*					m_pbChangedFlag;
	Asura_Hash_ID*			m_puMaterialResponse;
	Asura_Hash_ID			m_uHash;
	Asura_String			m_xMaterialResponseName;
	Asura_String			m_xFilter;
	Asura_Function_Gadget*  m_pFuncGadget;
};


#endif //ASURA_USE_MATERIAL_RESPONSE_SYSTEM
#endif //__TOOLS_OVERLAY_PICKMATERIALRESPONSE__
