//
// Tools_Overlay_ImportMaterialResponse.h
//
// Created by Richard Rice - 18/09/2007
// 
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_OVERLAY_IMPORTMATERIALRESPONSE__
#define __TOOLS_OVERLAY_IMPORTMATERIALRESPONSE__

#ifdef ASURA_USE_MATERIAL_RESPONSE_SYSTEM

#include "Interface/Asura_Overlay.h"

#include "Misc/list_tem.hpp"


class Tools_MaterialResponse_ImportData;
class Asura_Image_Dialog;


class Tools_Overlay_ImportMaterialResponse : public Asura_Overlay
{
public :
	~Tools_Overlay_ImportMaterialResponse();

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

	static bool OverlayExists();

private :
	Tools_Overlay_ImportMaterialResponse();

	void InitialiseOverlay();

	void FindMaterialsToImport();
	void AddEntryToImportList(int iMaterialID, int iSlot);

	void BuildMaterialNameList();

	void UpdateDialogsForCurrentSelection();

	virtual void PerFrameUpdate();

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

	OVERLAY_VOID_CALLBACK(ViewAssignedMaterial)
	OVERLAY_VOID_CALLBACK(SelectMaterial)
	OVERLAY_VOID_CALLBACK(SelectMaterialFromTree)
	OVERLAY_VOID_CALLBACK(CreateMaterial)
	OVERLAY_VOID_CALLBACK(ApplyMaterial)
	OVERLAY_VOID_CALLBACK(ApplyAll)
	OVERLAY_VOID_CALLBACK(FindPolygons)
	OVERLAY_VOID_CALLBACK(ForceImport)



	OVERLAY_BOOL_CALLBACK(CanFindPolygons)
	OVERLAY_BOOL_CALLBACK(IsMaterialSelected)
	OVERLAY_BOOL_CALLBACK(IsMaterialAssigned)

	#undef OVERLAY_VOID_CALLBACK
	#undef OVERLAY_BOOL_CALLBACK

	void ApplyMaterial(Tools_MaterialResponse_ImportData* pxImport);


	List<Tools_MaterialResponse_ImportData*> m_xImportList;

	//strings for overlay
	int m_iMaterialNameListSize;
	char** m_pszMaterialNameList;

	int m_iSelection;
	bool m_bSelectionChanged;

	Asura_Image_Dialog* m_pxAlbedoImageDialog;
	Asura_Image_Dialog* m_pxNormalMapImageDialog;
	Asura_Image_Dialog* m_pxSpecularMapImageDialog;

	Asura_Dialog* m_pxAlbedoNameDialog;
	Asura_Dialog* m_pxNormalMapNameDialog;
	Asura_Dialog* m_pxSpecularMapNameDialog;
	Asura_Dialog* m_pxPolygonsDialog;

	Asura_Dialog* m_pxMaterialToUseDialog;


};

class Tools_MaterialResponse_ModuleImportData
{
public :
	Tools_MaterialResponse_ModuleImportData()
	{
		m_iNumberOfPolygons = 0;
	}

	int m_iNumberOfPolygons;
	List<int> m_xPolygonList;
};

class Tools_MaterialResponse_ImportData
{
public :
	Tools_MaterialResponse_ImportData()
	{
		m_iMaterialID = -1;
		m_iSlot = 0;
		m_uPolygons = 0;
		m_bDone = false;
		m_iNumberOfModules = 0;
		m_pxModules = 0;
	}
	~Tools_MaterialResponse_ImportData()
	{
		delete [] m_pxModules;
	}

	void UpdatePolygonLists();

	int m_iMaterialID;
	int m_iSlot;//indicates primary/secondary textures
	u_int m_uPolygons;//number of polys this is applied to
	bool m_bDone;

	Asura_Hash_ID m_uMaterialResponse;//material response to be used in place of the old material

	//contains list of polygons that need to be updated
	int m_iNumberOfModules;
	Tools_MaterialResponse_ModuleImportData* m_pxModules;
};



#endif //ASURA_USE_MATERIAL_RESPONSE_SYSTEM


#endif //__TOOLS_OVERLAY_IMPORTMATERIALRESPONSE__
