// MW4GameEd.h : main header file for the MW4GAMEED application
//

#if !defined(AFX_MW4GAMEED_H__808CF88A_6E5A_11D2_8455_00105A17BC83__INCLUDED_)
#define AFX_MW4GAMEED_H__808CF88A_6E5A_11D2_8455_00105A17BC83__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols

#include <MW4\MW4.hpp>


using namespace MechWarrior4;
using namespace Adept;
using namespace Stuff;

#include <Adept\Entity.hpp>

#include "MissionData.h"
//#include "EditorWaypoint.h"
#include "EditorEntityData.h"

#define CAMERA_FOLLOW_GROUND			0
#define CAMERA_FOLLOW_HIGHESTPOINT		1
#define CAMERA_FOLLOW_NONE				2


class Command;
class CEditWnd;
class CLightWnd;
class FogDlg;
class EditorMovementPath;
class EditorPathNode;
class EditorBoundaryNode;
class EditorLatticeNode;

/////////////////////////////////////////////////////////////////////////////
// CMW4GameEdApp:
// See MW4GameEd.cpp for the implementation of this class
//
extern char Working_Directory[128];

class MissionNamePlug :
	public Plug
{
public:
	MissionNamePlug() :
		Plug(Plug::DefaultData)
	{
		name = NULL;
	}

	~MissionNamePlug()
	{
		if (name)
			delete [] name;
	}

	char* name;
};


//
//-----------
// Class ID's
//-----------
//
enum
{
	MW4GameEdApplicationClassID = MechWarrior4::FirstFreeMW4ClassID,
	EditorWaypointClassID,
	EditorLatticeNodeClassID,
	EditorPathNodeClassID,
	EditorBoundaryNodeClassID,
	FirstFreeMW4GameEdClassID,
	EditorDropNodeClassID,
	EditorDropZonePointClassID,
	EditorObjectiveMarkerClassID,
	EditorMovementPathClassID,
	EditorAmbientLightClassID,
	EditorInfiniteLightClassID,
	EditorPointLightClassID,
	EditorSpotLightClassID,
	EditorLightClassID,
	EditorCameraShipClassID
};

	class CDisplayWindow;
	class COverviewWindow;
	class CResourceWindow;
	class CInstanceWindow;

	class MW4GameEdApplication;
	class CMainFrame;

class CMW4GameEdApp : public CWinApp
{
friend class MW4GameEdApplication;
friend class CMainFrame;
public:

	

	CMW4GameEdApp();
	~CMW4GameEdApp();

	bool CreateNewScenario(char* missionName, char* mapPath, char* skyPath);

	CDisplayWindow
		*displayWindow;
	COverviewWindow
		*overviewWindow;
	CResourceWindow
		*resourceWindow;
	CInstanceWindow
		*instanceWindow;

	CToolBarCtrl
		*toolBar;

	CString
		missionFileName;
	CString
		lightFileName;
	CString
		audioFileName;
	CString
		m_graphName,m_moveGridName,m_rectGridName,m_airMoveGridName;

	Command
		*currentCommand;

	Stuff::Scalar
		cameraHeight;

	int
		cameraSpeed;

	int
		cameraFollowing;

	int
		ambientLightIndex;
	int
		keyLightIndex;
	int
		fillLightIndex;

  int 
    m_nDefaultAlignmentForPlacedObjects;

	bool
		gridOn;
	int	
		gridValue;

	bool
		didIdle;
	bool
		needsToSave;

	bool
		m_showLattice;
	bool
		m_showLatticeLinks;
	bool
		m_showRadii;
	bool
		m_showPaths;
	bool
		m_showBoundary;
	bool
		m_showDropZones;
	bool
		m_showTileBorder;
	bool
		m_showAI;
	bool
		m_MechLabActive;

	bool
		m_MissionSaved;

	int
		m_NumLinks;
	int
		m_NumObjectives;

	CString
		briefingPath;

	CString m_ScriptName;

	char
		m_title[256];

	bool
		m_MultiDrop;

	Stuff::ChainOf<Entity *> 
		culturalList;

	void DisperseCulturals();
	void RemoveCulturals();

	CEditorEntityData *
		GetEntityData(Entity *entity);

	bool
		CreateMissionInstanceFile(char* missionName, char* mapPath, char* skyPath, bool create_new);
	bool
		SaveMissionContentsFile(char *prop_name);
	bool
		SaveMissionDataFile(char* filename);
	bool
		SaveLightFile(char* fname = NULL);

  bool 
    SaveAudioFile(char *fname = NULL);

	void
		CreateMissionResource(char* missionInstance);

	void
		GetGridCoords(Point3D& point);

	void RemoveEditorObjects (void);

	void
		StopMultiPlace();

	void 
		CreateLightDlg();

	int
		nextDamageFileID;
	int
		nextSubsystemFileID;

	void
		LoadLattice();
	void
		RemoveLattice();

	void
		LoadPaths();
	void
		LoadLights();
	void
		LoadBoundary();
	void
		DeleteBoundaryNodes();

	void
		LoadDropZones();
	void
		LoadObjectives();
	void
		LoadCameras();
	void
		VerifyObjectPlacement(bool feedback = false);

	void RotateSel90CCW();
	void RotateSel90CW();

	Stuff::DynamicArrayOf<CEditorEntityData *> m_ExtraDataList;

	bool
		m_AllLoaded;

	enum EditorStateType
		{
			InitializingState = 0,
			NoGameIdleState,
			AddingObjectState,
			IdleState,
			SelectingObjectState,
			DragSelectState,
			ReadyToMoveObjectState,
			MovingObjectState,
			ReadyToStartNavState,
			PlacingNavPointState,
			RotateState,
			RevolveState,
			AddingLinkState,
			SprayingState,
			WaitingToAddState,
			WaitingToSprayState,
			AfterMovingState
		};
	EditorStateType
		m_editorState;

	Stuff::ChainOf<Command *>
		undoChain;
	CString
		m_VersionString;

	bool
		m_AutoBackupOnSave;

	EditorMovementPath*
		m_CurPath;
	EditorPathNode*
		m_LastPathNode;
	int
		m_CurPathNodeCount;

	Stuff::LinearMatrix4D
		m_DefCameraPos[10];
  char m_DefCameraName[10][16];

	CEditWnd*
		briefingWnd;

	HCURSOR	m_WaitCursor;


	CMissionData m_MissionData;

	ChainOf<PlugOf<Resource*>*> dirtyGameModelResources;



	CLightWnd*	lightDlg;
	FogDlg*		fogDlg;

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMW4GameEdApp)
	public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	virtual BOOL OnIdle(LONG lCount);
	virtual int Run();
	//}}AFX_VIRTUAL

// Implementation
protected:
	HMENU				m_hMDIMenu;
	HACCEL				m_hMDIAccel;

	int					m_VideoResolution;
	DynamicArrayOf<Stuff::Vector2DOf<Stuff::Scalar> > missionBoundary,warningBoundary;

//	Stuff::SortedChainOf<LatticeLinkListNode*,int>
//		LatticeLinkChain;
private:         

//  Redundant camera position data/code

  LinearMatrix4D m_4DCameraBookmark[10];
  char           m_szCameraBookmarkNames[10][16];

public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	void LoadWindowStates();
	void SaveWindowStates();
	void OpenFile(char* filename);
	void WriteDirtyGameModels();
	void VerifyWaypointRadius();
	void InitMovementLatticeData() ;
	void CreateLatticeNodeRadius(Entity* entity);
	void CreateLatticeNodeRadius(EditorLatticeNode* node);
	void EditorConstructMissionCreateMessage();
	void FixPaths();
	void MakeObjectsTileBased();
	void MakeObjectsZoneBased();
	void MakeObjectNamesUnique();
	bool IsNameUnique(char *name,Entity *ignore=NULL);
	void MakeNameUnique(MString *str);
  int GetDefaultAlignmentForPlacedObjects() { return m_nDefaultAlignmentForPlacedObjects;};

	//{{AFX_MSG(CMW4GameEdApp)
	afx_msg void OnAppAbout();
	afx_msg void OnFileNew();
	afx_msg void OnToggleOverviewWindow();
	afx_msg void OnToggleResourceWindow();
	afx_msg void OnEditUndo();
	afx_msg void OnAdjustGrid();
	afx_msg void OnFileOpen();
	afx_msg void OnUpdateViewOverviewwindow(CCmdUI* pCmdUI);
	afx_msg void OnUpdateViewResourcewindow(CCmdUI* pCmdUI);
	afx_msg void OnViewDisplaywindow();
	afx_msg void OnUpdateViewDisplaywindow(CCmdUI* pCmdUI);
	afx_msg void OnFileSaveAs();
	afx_msg void OnToolsCameraheightFourtimesmechheight40m();
	afx_msg void OnToolsCameraheightGround();
	afx_msg void OnToolsCameraheightMechheight10m();
	afx_msg void OnToolsCameraheightTwicemechheight20m();
	afx_msg void OnToolsCameraspeedSlow();
	afx_msg void OnToolsCameraspeedRegular();
	afx_msg void OnToolsCameraspeedFast();
	afx_msg void OnViewInstancewindow();
	afx_msg void OnUpdateViewInstancewindow(CCmdUI* pCmdUI);
	afx_msg void OnToolsBriefingfile();
	afx_msg void OnFileSave();
	afx_msg void OnToolsCamerafollowingGround();
	afx_msg void OnToolsCamerafollowingHighestpoint();
	afx_msg void OnToolsCamerafollowingNone();
	afx_msg void OnUpdateToolsCamerafollowingGround(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsCamerafollowingHighestpoint(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsCamerafollowingNone(CCmdUI* pCmdUI);
	afx_msg void OnToolsCameraheightUserdefined();
	afx_msg void OnViewResize1024();
	afx_msg void OnUpdateViewResize1024(CCmdUI* pCmdUI);
	afx_msg void OnViewResize1152();
	afx_msg void OnUpdateViewResize1152(CCmdUI* pCmdUI);
	afx_msg void OnViewResize1280();
	afx_msg void OnUpdateViewResize1280(CCmdUI* pCmdUI);
	afx_msg void OnViewResize1600();
	afx_msg void OnUpdateViewResize1600(CCmdUI* pCmdUI);
	afx_msg void OnViewResize640();
	afx_msg void OnUpdateViewResize640(CCmdUI* pCmdUI);
	afx_msg void OnViewResize800();
	afx_msg void OnUpdateViewResize800(CCmdUI* pCmdUI);
	afx_msg void OnFileAutobackuponsave();
	afx_msg void OnUpdateFileAutobackuponsave(CCmdUI* pCmdUI);
	afx_msg void OnFileClose();
	afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileSaveAs(CCmdUI* pCmdUI);
	afx_msg void OnFileDelete();
	afx_msg void OnToolsMovementlattice();
	afx_msg void OnUpdateToolsMovementlattice(CCmdUI* pCmdUI);
	afx_msg void OnToolsMovmentlayerShowlatticelinks();
	afx_msg void OnUpdateToolsMovmentlayerShowlatticelinks(CCmdUI* pCmdUI);
	afx_msg void OnToolsMovmentlayerRecalclatticelinks();
	afx_msg void OnEditCut();
	afx_msg void OnEditPaste();
	afx_msg void OnToolsMovmentlayerShowall();
	afx_msg void OnToolsMovmentlayerShownoderadii();
	afx_msg void OnToolsMovmentlayerShowpaths();
	afx_msg void OnUpdateToolsMovmentlayerShowall(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsMovmentlayerShownoderadii(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsMovmentlayerShowpaths(CCmdUI* pCmdUI);
	afx_msg void OnToolsMechlab();
	afx_msg void OnToolsMovmentlayerShowmissionboundary();
	afx_msg void OnUpdateToolsMovmentlayerShowmissionboundary(CCmdUI* pCmdUI);
	afx_msg void OnToolsVerifyobjectplacement();
	afx_msg void OnToolsMovmentlayerShowdropzones();
	afx_msg void OnUpdateToolsMovmentlayerShowdropzones(CCmdUI* pCmdUI);
	afx_msg void OnToolsEditmissionscript();
	afx_msg void OnToolsMovmentlayerShowobjectives();
	afx_msg void OnUpdateToolsMovmentlayerShowobjectives(CCmdUI* pCmdUI);
	afx_msg void OnViewShowtileborders();
	afx_msg void OnUpdateViewShowtileborders(CCmdUI* pCmdUI);
	afx_msg void OnToolsSpecifymissionscript();
	afx_msg void OnToolsCheckscripts ();
	afx_msg void OnToolsMovmentlayerCreatelattice();
	afx_msg void OnToolsMovmentlayerCreateRects();
	afx_msg void OnToolsMissionparametersEditfog();
	afx_msg void OnUpdateToolsCameraspeedFast(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsCameraspeedRegular(CCmdUI* pCmdUI);
	afx_msg void OnUpdateToolsCameraspeedSlow(CCmdUI* pCmdUI);
	afx_msg void OnToolsSnapobjectstoterrain();
	afx_msg void OnEditCopy();
  afx_msg void OnToolsWeaponsProperties();
  afx_msg void OnUpdateToolsMechProperties(CCmdUI* pCmdUI);
  afx_msg void OnToolsMechProperties();
  afx_msg void OnUpdateToolsWeaponsProperties(CCmdUI* pCmdUI);
  afx_msg void OnToolsWeaponsBalancing();
  afx_msg void OnUpdateToolsWeaponsBalancing(CCmdUI* pCmdUI);
  afx_msg void OnToolsArmorBalancing();
  afx_msg void OnUpdateToolsArmorBalancing(CCmdUI* pCmdUI);
	afx_msg void OnToolsPlacewithmap();
	afx_msg void OnToolsDisperseculturalwithbitmap();
	afx_msg void OnToolsRemoveculturals();
	//}}AFX_MSG
  
  afx_msg void OnUpdateDefaultAlignmentMenu(CCmdUI* pCmdUI);
  afx_msg void OnDefaultAlignmentMenu(UINT uiID);

  DECLARE_MESSAGE_MAP()

public:
  afx_msg void OnNameNumberedCameraPosition (UINT nID);
  afx_msg void OnSetNumberedCameraPosition (UINT nID);
  afx_msg void OnGotoNumberedCameraPosition(UINT nID);
  afx_msg void OnMenuAvailableNumberedCameraPosition(CCmdUI* pCmdUI );
  
  void UpdateCameraMenus(int index);

  /*
	afx_msg void OnToolsLightingAmbient();
	afx_msg void OnToolsLightingFill();
	afx_msg void OnToolsLightingKey();
*/
private:
	void ShowTipAtStartup(void);
private:
	void ShowTipOfTheDay(void);
  void LoadInSavedCameraPositions(char * filename);
  void SaveEditCameraInfo();


};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MW4GAMEED_H__808CF88A_6E5A_11D2_8455_00105A17BC83__INCLUDED_)
