SBSPSS/Utils/MapEdit/MapEditDoc.cpp

365 lines
9.4 KiB
C++
Raw Normal View History

2000-09-22 17:11:29 +02:00
// MapEditDoc.cpp : implementation of the CMapEditDoc class
//
#include "stdafx.h"
#include "MapEdit.h"
#include "MapEditDoc.h"
2000-11-20 17:21:43 +01:00
#include "MapSizeDlg.h"
2000-09-22 17:11:29 +02:00
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapEditDoc
IMPLEMENT_DYNCREATE(CMapEditDoc, CDocument)
BEGIN_MESSAGE_MAP(CMapEditDoc, CDocument)
//{{AFX_MSG_MAP(CMapEditDoc)
2000-11-06 21:24:11 +01:00
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURSORXY, OnStatusCursorXY)
2001-02-01 23:48:22 +01:00
ON_COMMAND(ID_EXPORT, OnExport)
2000-12-11 22:52:32 +01:00
ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
2000-09-22 17:11:29 +02:00
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMapEditDoc construction/destruction
CMapEditDoc::CMapEditDoc()
{
}
CMapEditDoc::~CMapEditDoc()
{
}
BOOL CMapEditDoc::OnNewDocument()
{
2000-11-06 21:24:11 +01:00
if (!CDocument::OnNewDocument()) return FALSE;
2000-09-22 17:11:29 +02:00
2000-11-28 22:16:00 +01:00
return(Core.New());
// return TRUE;
2000-09-22 17:11:29 +02:00
}
2000-11-04 19:24:51 +01:00
BOOL CMapEditDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
return TRUE;
}
2000-09-22 17:11:29 +02:00
/////////////////////////////////////////////////////////////////////////////
// CMapEditDoc serialization
void CMapEditDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
2000-11-20 21:33:42 +01:00
Core.Save(ar.GetFile());
2000-09-22 17:11:29 +02:00
}
else
{
2000-11-20 21:33:42 +01:00
Core.Load(ar.GetFile());
2000-09-22 17:11:29 +02:00
}
}
/////////////////////////////////////////////////////////////////////////////
// CMapEditDoc diagnostics
#ifdef _DEBUG
void CMapEditDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMapEditDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
2000-11-06 21:24:11 +01:00
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
void CMapEditDoc::UpdateView(CMapEditView *View)
{
2001-02-09 22:17:01 +01:00
CView *V=(CView*)View;
V->Invalidate();
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
void CMapEditDoc::Render(CMapEditView *View)
{
2001-02-10 16:23:30 +01:00
2001-02-09 22:17:01 +01:00
if (View)
2000-11-06 21:24:11 +01:00
Core.Render(View);
}
2000-11-20 21:33:42 +01:00
/*********************************************************************************/
void CMapEditDoc::UpdateAll(CMapEditView *View)
{
2001-02-10 16:23:30 +01:00
2001-02-09 22:17:01 +01:00
if (View)
Core.UpdateAll();
2001-02-10 16:23:30 +01:00
2000-11-20 21:33:42 +01:00
}
2000-11-06 21:24:11 +01:00
/*********************************************************************************/
void CMapEditDoc::OnStatusCursorXY(CCmdUI *pCmdUI)
{
CPoint &XY=Core.GetCursorPos();
CString XYStr;
pCmdUI->Enable();
if (XY.x!=-1 && XY.y!=-1)
2001-02-10 16:23:30 +01:00
XYStr.Format( "%d %d", XY.x,XY.y);
2000-11-06 21:24:11 +01:00
pCmdUI->SetText(XYStr);
}
2000-12-11 22:29:59 +01:00
/*********************************************************************************/
bool CMapEditDoc::Question(char *Txt)
{
CString Str;
Str.Format(Txt);
int Ret=AfxMessageBox(Str,MB_YESNO , MB_ICONQUESTION);
if (Ret==IDYES) return(true);
return(false);
}
2001-02-09 22:17:01 +01:00
/*********************************************************************************/
void CMapEditDoc::GUIUpdate()
{
Core.GUIUpdate();
}
/*********************************************************************************/
void CMapEditDoc::GUIChanged()
{
Core.GUIChanged();
UpdateAllViews(NULL);
}
2000-11-06 21:24:11 +01:00
/*********************************************************************************/
/*********************************************************************************/
/*** Windows Message Handlers ****************************************************/
/*********************************************************************************/
/*********************************************************************************/
void CMapEditDoc::LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
2001-02-10 16:23:30 +01:00
Core.LButtonControl(View,nFlags,point,DownFlag);
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
void CMapEditDoc::MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
2001-02-10 16:23:30 +01:00
Core.MButtonControl(View,nFlags,point,DownFlag);
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
void CMapEditDoc::RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
{
2001-02-10 16:23:30 +01:00
Core.RButtonControl(View,nFlags,point,DownFlag);
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
void CMapEditDoc::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &point)
{
2001-02-10 16:23:30 +01:00
Core.MouseWheel(View,nFlags,zDelta,point);
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
void CMapEditDoc::MouseMove(CMapEditView *View,UINT nFlags, CPoint &point)
{
2000-11-15 22:22:40 +01:00
Core.MouseMove(View,nFlags,point);
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
2000-11-14 16:03:04 +01:00
void CMapEditDoc::ToggleTileView(CMapEditView *View)
2000-11-06 21:24:11 +01:00
{
2001-02-09 22:17:01 +01:00
Core.UpdateTileView(true);
Core.UpdateAll();
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-06 21:24:11 +01:00
}
/*********************************************************************************/
2000-11-14 16:03:04 +01:00
void CMapEditDoc::ToggleGrid(CMapEditView *View)
2000-11-06 21:24:11 +01:00
{
2001-02-09 22:17:01 +01:00
Core.UpdateGrid(TRUE);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-17 00:08:54 +01:00
}
/*********************************************************************************/
2000-11-20 17:21:43 +01:00
void CMapEditDoc::MirrorX(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2001-02-09 22:17:01 +01:00
Core.MirrorX();
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-17 00:08:54 +01:00
}
/*********************************************************************************/
2000-11-20 17:21:43 +01:00
void CMapEditDoc::MirrorY(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2001-02-09 22:17:01 +01:00
Core.MirrorY();
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-06 21:24:11 +01:00
}
2001-01-02 15:34:02 +01:00
/*********************************************************************************/
void CMapEditDoc::CopySelection(CMapEditView *View)
{
2001-02-09 22:17:01 +01:00
Core.CopySelection();
2001-01-02 15:34:02 +01:00
FocusView();
}
/*********************************************************************************/
void CMapEditDoc::PasteSelection(CMapEditView *View)
{
2001-02-09 22:17:01 +01:00
Core.PasteSelection();
2001-01-02 15:34:02 +01:00
FocusView();
}
2000-11-14 16:03:04 +01:00
/*********************************************************************************/
2000-11-15 22:22:40 +01:00
void CMapEditDoc::SetMode(int NewMode)
2000-11-14 16:03:04 +01:00
{
2000-11-15 22:22:40 +01:00
Core.SetMode(NewMode);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-15 22:22:40 +01:00
}
/*********************************************************************************/
2000-11-28 00:07:07 +01:00
void CMapEditDoc::SetLayer(int Layer)
{
Core.SetLayer(Layer);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-28 00:07:07 +01:00
}
2001-01-21 19:04:00 +01:00
/*********************************************************************************/
void CMapEditDoc::AddLayer(int Layer)
{
Core.AddLayer(Layer);
FocusView();
}
/*********************************************************************************/
void CMapEditDoc::DeleteLayer(int Layer)
{
Core.DeleteLayer(Layer);
FocusView();
}
2000-11-28 00:07:07 +01:00
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
2001-02-01 23:48:22 +01:00
void CMapEditDoc::OnExport()
2000-11-28 00:07:07 +01:00
{
2001-02-01 23:48:22 +01:00
char BASED_CODE Filter[]= "Export Data Type (*.MEX)|*.MEX|All Files (*.*)|*.*||";
CFileDialog Dlg(FALSE,"*.MEX",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,Filter);
2000-11-28 00:07:07 +01:00
if (Dlg.DoModal()!=IDOK) return;
char Filename[256];
sprintf(Filename,"%s",Dlg.GetPathName());
2001-02-01 23:48:22 +01:00
Core.Export(Filename);
2000-11-28 00:07:07 +01:00
}
/*********************************************************************************/
2000-11-15 22:22:40 +01:00
/*** Tilebank Functions **********************************************************/
/*********************************************************************************/
void CMapEditDoc::TileBankLoad()
{
2000-11-22 23:08:47 +01:00
char BASED_CODE GinFilter[]= "All Tile Files (*.Gin; *.Bmp)|*.gin;*.Bmp|3d Tile Files (*.Gin)|*.Gin|2d Tile Files (*.Bmp)|*.Bmp|All Files (*.*)|*.*||";
2000-11-15 22:22:40 +01:00
CFileDialog Dlg(TRUE,"Gin",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,GinFilter);
if (Dlg.DoModal()!=IDOK) return;
char Filename[256];
sprintf(Filename,"%s",Dlg.GetPathName());
Core.TileBankLoad(Filename);
UpdateAllViews(NULL);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-15 22:22:40 +01:00
}
2000-11-29 18:07:57 +01:00
/*********************************************************************************/
void CMapEditDoc::TileBankDelete()
{
Core.TileBankDelete();
UpdateAllViews(NULL);
FocusView();
}
2000-11-15 22:22:40 +01:00
/*********************************************************************************/
void CMapEditDoc::TileBankReload()
{
Core.TileBankReload();
2000-11-14 16:03:04 +01:00
UpdateAllViews(NULL);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-14 16:03:04 +01:00
}
/*********************************************************************************/
2000-11-15 22:22:40 +01:00
void CMapEditDoc::TileBankSet()
2000-11-14 16:03:04 +01:00
{
2000-11-15 22:22:40 +01:00
Core.TileBankSet();
2000-11-14 16:03:04 +01:00
UpdateAllViews(NULL);
2000-11-28 15:34:42 +01:00
FocusView();
2000-11-14 16:03:04 +01:00
}
2000-11-15 22:22:40 +01:00
2000-11-17 22:36:13 +01:00
/*********************************************************************************/
2000-11-20 17:21:43 +01:00
void CMapEditDoc::ActiveBrushLeft(CMapEditView *View)
2000-11-17 22:36:13 +01:00
{
2001-02-09 22:17:01 +01:00
Core.ActiveBrushLeft();
2000-11-17 22:36:13 +01:00
}
/*********************************************************************************/
2000-11-20 17:21:43 +01:00
void CMapEditDoc::ActiveBrushRight(CMapEditView *View)
2000-11-17 22:36:13 +01:00
{
2001-02-09 22:17:01 +01:00
Core.ActiveBrushRight();
2000-11-20 17:21:43 +01:00
}
/*********************************************************************************/
void CMapEditDoc::MapSetSize(CMapEditView *View)
{
CMapSizeDlg Dlg;
Dlg.m_Width=Core.GetMapWidth();
Dlg.m_Height=Core.GetMapHeight();
if (Dlg.DoModal()!=IDOK) return;
2000-11-17 22:36:13 +01:00
2001-02-09 22:17:01 +01:00
Core.SetMapSize(Dlg.m_Width,Dlg.m_Height);
2000-11-17 22:36:13 +01:00
}
2000-11-22 23:08:47 +01:00
2000-12-11 22:52:32 +01:00
/*********************************************************************************/
void CMapEditDoc::OnZoomIn()
{
2001-02-09 22:17:01 +01:00
Core.Zoom(-0.1f);
2000-12-11 22:52:32 +01:00
UpdateAllViews(NULL);
}
/*********************************************************************************/
void CMapEditDoc::OnZoomOut()
{
2001-02-09 22:17:01 +01:00
Core.Zoom(+0.1f);
2000-12-11 22:52:32 +01:00
UpdateAllViews(NULL);
}
2000-11-22 23:08:47 +01:00
/*********************************************************************************/
void CMapEditDoc::Toggle2d3d(CMapEditView *View)
{
2001-02-09 22:17:01 +01:00
Core.Toggle2d3d();
2000-11-22 23:08:47 +01:00
}
2000-11-28 15:34:42 +01:00
/*********************************************************************************/
void CMapEditDoc::FocusView()
{
theApp.GetMainWnd()->SetFocus(); // Put control back to Window :o)
2000-12-11 22:52:32 +01:00
}
2000-12-29 23:20:38 +01:00