//
// Tools_Entity_Simulation.h
//
// Created by Richard Rice - 20/10/2004
// 
// Copyright (C) 2004 Rebellion, All Rights Reserved.
//


#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef _TOOLS_ENTITY_SIMULATION_H_
#define _TOOLS_ENTITY_SIMULATION_H_

#include "Network/Asura_Guid.h"

template<class T> class List;

class Tools_Entity_Simulation
{
public :

	//starts entity simulation
	static void Start();
	//ends simulation ,and resets the states of all entities
	static void End();
	//restarts entity simulation
	static void Reset();

	
	//per-framme update of the system
	static void Update();
	static void Render();

	//temporarily enables/disables system fo allowing normal entity
	//destruction to take place if needed
	static void Enable() {s_bEnabled = true;}
	static void Disable() {s_bEnabled = false;}

	//returns true if simulation is currently active
	static bool IsActive(){return s_bActive && s_bEnabled;}

	//add message sent in game to text and dat logfile
	static void LogInGameMessage(const struct Asura_StaticMessage* pxMessage,Asura_Guid uFrom,bool bDelayed, float fDelay);
	static void LogInGameMessage(const class Asura_Message* pxMessage,Asura_Guid uTo, Asura_Guid uFrom);
	static void IncreaseMessageLogIndent(){s_iMessageLogIndent++;}
	static void DecreaseMessageLogIndent(){s_iMessageLogIndent--;}
	static void ResetLogFile(){s_bMessageDatFileNeedsReset = true;}

	//Adds controls for filtering the message log file according to the entity file that each entity comes from
	static void AddMessageLogFilterOverlayControls(class Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset);


	
	//overlay handling
	static void ToggleOverlay();
	static bool OverlayIsOn();
	static void CreateOverlay();
	static void CloseOverlay();


private :


	static void UpdateMessageListBox();

	static void AddToMessageLog(const class Asura_Message* pxMessage,bool bQuiet,float fDelay,bool bDelayed);

	static bool ShouldLogMessage(class Asura_Entity_Server* pxFrom, class Asura_Entity_Server* pxTo);

	enum FilterType
	{
		MESSAGEFILTER_NONE,
		MESSAGEFILTER_OBJECT,
		MESSAGEFILTER_CAUSEDBY,
		MESSAGEFILTER_CAUSING,
	};

	static void SetFilter_None();
	static void SetFilter_SelectedObjects();
	static void SetFilter_CausedByMessage();
	static void SetFilter_CausingMessage();

	static void FindMessageFrom();
	static void FindMessageTo();

	//pause or resume 'game' time
	static void PauseOrResume();

	static void AddMessageToDatFile(Asura_Guid uFrom,const struct Asura_StaticMessage* pxMessage,bool bDelayed);
	static void LoadMessageDatFile();

	//overlay callbacks
	static bool IsEntityFileFiltered(int iHash);
	static void SetEntityFileFiltered(bool bSet, int iHash);




	static bool s_bActive;
	static bool s_bEnabled;
	static bool s_bPaused;
	
	static float s_fTimer;

	static bool s_bOverlayOpen;


	static bool s_bShowMessages;//display messages as they occur?

	static bool s_bMessageListBoxValid;//does the message list need be redone?

	static int s_iMessageListBoxSize;
	static char** s_ppszMessageStrings;
	static char** s_ppszMessageHelp;
	static int* s_piMessageIndeces;
	static int s_iSelectedMessage;//index in listbox

	static enum FilterType s_eFilter;//filter to determine which messages to show
	static List<Asura_Guid> s_xFilter_GuidList;//list of guids of objects to show when using object filter
	static int s_iFilter_MessageIndex;//message for 'caused by' and 'causing' filters

	static bool s_bMessageDatFileNeedsReset;

	static bool s_bAllowTemplateMemberSelection;

	static int s_iMessageLogIndent;
	
	static List<Asura_Hash_ID> s_xMessageLogFilter;
	static bool s_bMessageLogFilter_TemplateMessages;


	static class Asura_List_Dialog* s_pxListDialog;

};

struct Tools_SavedMessageData
{
	float m_fTime;
	Asura_Guid m_uFrom;
	Asura_Guid m_uTo;
	u_int m_uMessage;
	float m_fDelay;
	bool m_bDelayed;
};

#endif //_TOOLS_ENTITY_SIMULATION_H_
