SBSPSS/Utils/MapEdit/Core.cpp

479 lines
12 KiB
C++
Raw Normal View History

2000-09-22 17:11:29 +02:00
/***********************/
/*** Map Editor Core ***/
/***********************/
#include "stdafx.h"
2000-09-22 23:19:46 +02:00
#include "gl3d.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include "GLEnabledView.h"
2000-10-25 20:28:44 +02:00
#include "MapEdit.h"
2000-09-22 23:19:46 +02:00
#include "MapEditDoc.h"
#include "MapEditView.h"
2000-10-31 23:37:59 +01:00
#include "MainFrm.h"
2000-09-22 23:19:46 +02:00
2000-09-22 17:11:29 +02:00
#include "Core.h"
2000-09-25 17:43:52 +02:00
#include "Layer.h"
2000-11-07 21:38:19 +01:00
#include "LayerTile.h"
2000-10-27 02:06:19 +02:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CCore::CCore()
{
2000-11-08 20:53:57 +01:00
TileViewFlag=FALSE;
2000-11-14 16:03:04 +01:00
GridFlag=TRUE;
2000-11-08 20:53:57 +01:00
CurrentMousePos=CPoint(0,0);
ActiveLayer=0;
MapCam=Vec(0,0,0);
TileCam=Vec(0,0,0);
2000-11-14 16:03:04 +01:00
Is3dFlag=TRUE;
2000-09-22 17:11:29 +02:00
}
2000-09-25 17:43:52 +02:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
CCore::~CCore()
{
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
for (int i=0; i<ListSize; i++) delete Layer[i];
2000-09-22 17:11:29 +02:00
}
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
void CCore::Init()
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CMultiBar *ParamBar=Frm->GetParamBar();
ParamBar->RemoveAll();
// Add default parram bar items
ParamBar->Add(Frm->GetLayerList(),IDD_LAYER_LIST_DIALOG,TRUE,TRUE);
ParamBar->Add(Frm->GetTileSetDlg(),IDD_TILESET_DIALOG,TRUE,TRUE);
2000-11-17 00:08:54 +01:00
UpdateParamBar();
2000-11-20 21:33:42 +01:00
// Layer[ActiveLayer]->InitGUI(this);
2000-11-17 00:08:54 +01:00
// ParamBar->Update();
2000-11-20 21:33:42 +01:00
UpdateAll(NULL);
2000-11-15 22:22:40 +01:00
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2000-11-20 21:33:42 +01:00
void CCore::New()
2000-09-22 23:19:46 +02:00
{
2000-11-20 17:21:43 +01:00
// Create Gfx Layers
2000-11-20 21:33:42 +01:00
// Name Width Height SizeDiv ViewDiv 3d? Resizable?
Layer.push_back(new CLayerTile( "Back", 32, 32, 1.0f, 4.0f, FALSE, FALSE));
Layer.push_back(new CLayerTile( "Mid", TileLayerDefaultWidth, TileLayerDefaultHeight, 2.0f, 2.0f, FALSE, TRUE));
Layer.push_back(new CLayerTile( "Action",TileLayerDefaultWidth, TileLayerDefaultHeight, 1.0f, 1.0f, TRUE, TRUE));
Layer.push_back(new CLayerTile( "Fore", TileLayerDefaultWidth, TileLayerDefaultHeight, 0.5f, 0.5f, FALSE, TRUE));
2000-11-04 19:24:51 +01:00
2000-11-20 21:33:42 +01:00
ActiveLayer=LAYER_ACTION;
2000-11-02 16:46:17 +01:00
MapCam=Vec(0,0,0);
TileCam=Vec(0,0,0);
2000-11-15 22:22:40 +01:00
Init();
2000-11-06 21:24:11 +01:00
}
/*****************************************************************************/
2000-11-20 21:33:42 +01:00
void CCore::Load(CFile *File)
{
float Version;
File->Read(&Version,sizeof(float));
File->Read(&MapCam,sizeof(Vec));
File->Read(&TileCam,sizeof(Vec));
File->Read(&TileCam,sizeof(Vec));
File->Read(&TileViewFlag,sizeof(BOOL));
File->Read(&GridFlag,sizeof(BOOL));
File->Read(&Is3dFlag,sizeof(BOOL));
// Layers
int LayerCount;
File->Read(&LayerCount,sizeof(int));
File->Read(&ActiveLayer,sizeof(int));
for (int i=0;i<LayerCount;i++)
{
int Type;
File->Read(&Type,sizeof(int));
switch (Type)
{
case LAYER_TYPE_TILE:
Layer.push_back(new CLayerTile(File,Version));
break;
}
}
TileBank.Load(File,Version);
Init();
}
/*****************************************************************************/
void CCore::Save(CFile *File)
2000-11-06 21:24:11 +01:00
{
2000-11-20 21:33:42 +01:00
File->Write(&FileVersion,sizeof(float));
File->Write(&MapCam,sizeof(Vec));
File->Write(&TileCam,sizeof(Vec));
File->Write(&TileCam,sizeof(Vec));
File->Write(&TileViewFlag,sizeof(BOOL));
File->Write(&GridFlag,sizeof(BOOL));
File->Write(&Is3dFlag,sizeof(BOOL));
// Layers
int LayerCount=Layer.size();
File->Write(&LayerCount,sizeof(int));
File->Write(&ActiveLayer,sizeof(int));
for (int i=0;i<LayerCount;i++)
{
int Type=Layer[i]->GetType();
File->Write(&Type,sizeof(int));
Layer[i]->Save(File);
}
TileBank.Save(File);
2000-11-02 16:46:17 +01:00
}
2000-10-27 02:06:19 +02:00
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
void CCore::Render(CMapEditView *View,BOOL ForceRender)
2000-09-22 23:19:46 +02:00
{
2000-11-06 21:24:11 +01:00
if (TileBank.NeedLoad()) TileBank.LoadTileSets(this);
2000-11-14 16:03:04 +01:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
if (TileViewFlag)
{
RenderTileView(View);
}
else
{
RenderLayers(View);
}
}
2000-11-10 17:17:00 +01:00
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
void CCore::RenderLayers(CMapEditView *View)
{
Vec &ThisCam=GetCam();
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
2000-11-14 16:03:04 +01:00
2000-11-20 21:33:42 +01:00
for (int i=0;i<ListSize;i++)
2000-10-31 23:37:59 +01:00
{
2000-11-20 21:33:42 +01:00
Layer[i]->Render(this,ThisCam,Is3dFlag);
2000-11-02 16:46:17 +01:00
}
2000-11-14 16:03:04 +01:00
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->RenderCursor(this,ThisCam,Is3dFlag);
if (GridFlag) Layer[ActiveLayer]->RenderGrid(this,ThisCam);
2000-11-17 22:36:13 +01:00
2000-11-14 16:03:04 +01:00
// Get Cursor Pos
2000-11-15 22:22:40 +01:00
LastCursorPos=CursorPos;
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->FindCursorPos(this,View,GetCam(),CurrentMousePos);
2000-11-14 16:03:04 +01:00
}
2000-11-03 23:40:41 +01:00
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
void CCore::RenderTileView(CMapEditView *View)
{
Vec &ThisCam=GetCam();
TileBank.RenderSet(this,ThisCam,Is3dFlag);
2000-11-17 22:36:13 +01:00
// TileBank.RenderCursor(this,ThisCam,Is3dFlag);
2000-11-14 16:03:04 +01:00
// Get Cursor Pos
TileBank.FindCursorPos(this,View,GetCam(),CurrentMousePos);
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
/*** Control *****************************************************************/
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
void CCore::SetMode(int NewMode)
{
BOOL RedrawFlag=FALSE;
2000-11-20 21:33:42 +01:00
RedrawFlag=Layer[ActiveLayer]->SetMode(NewMode);
2000-11-15 22:22:40 +01:00
//if (RedrawFlag) View->Invalidate();
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::LButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
2000-09-22 23:19:46 +02:00
{
2000-11-15 22:22:40 +01:00
BOOL RedrawFlag=FALSE;
2000-11-14 16:03:04 +01:00
if (TileViewFlag)
2000-11-15 22:22:40 +01:00
{
2000-11-17 22:36:13 +01:00
if (nFlags & MK_RBUTTON)
RedrawFlag=TileBank.SelectCancel();
else
RedrawFlag=TileBank.SelectL(DownFlag);
2000-11-15 22:22:40 +01:00
}
2000-11-14 16:03:04 +01:00
else
2000-11-15 22:22:40 +01:00
{
2000-11-20 21:33:42 +01:00
RedrawFlag=Layer[ActiveLayer]->LButtonControl(this,View,nFlags,CursorPos,DownFlag);
2000-11-15 22:22:40 +01:00
}
2000-11-17 22:36:13 +01:00
TileBank.SetActiveBrushL();
2000-11-15 22:22:40 +01:00
if (RedrawFlag) View->Invalidate();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::MButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
2000-09-22 23:19:46 +02:00
{
2000-10-25 23:00:54 +02:00
LastMousePos=point;
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
2000-09-22 23:19:46 +02:00
{
2000-11-15 22:22:40 +01:00
BOOL RedrawFlag=FALSE;
2000-11-14 16:03:04 +01:00
if (TileViewFlag)
2000-11-15 22:22:40 +01:00
{
2000-11-17 22:36:13 +01:00
if (nFlags & MK_LBUTTON)
RedrawFlag=TileBank.SelectCancel();
else
RedrawFlag=TileBank.SelectR(DownFlag);
2000-11-15 22:22:40 +01:00
}
2000-11-14 16:03:04 +01:00
else
2000-11-15 22:22:40 +01:00
{
2000-11-20 21:33:42 +01:00
RedrawFlag=Layer[ActiveLayer]->RButtonControl(this,View,nFlags,CursorPos,DownFlag);
2000-11-15 22:22:40 +01:00
}
2000-11-17 22:36:13 +01:00
TileBank.SetActiveBrushR();
2000-11-14 16:03:04 +01:00
2000-11-15 22:22:40 +01:00
if (RedrawFlag) View->Invalidate();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt)
2000-09-22 23:19:46 +02:00
{
2000-10-25 20:28:44 +02:00
if (zDelta>0)
2000-11-06 21:24:11 +01:00
UpdateView(View,Vec(0,0,1.0f));
2000-10-25 20:28:44 +02:00
else
2000-11-06 21:24:11 +01:00
UpdateView(View,Vec(0,0,-1.0f));
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::MouseMove(CMapEditView *View,UINT nFlags, CPoint &point)
2000-09-22 23:19:46 +02:00
{
2000-11-02 16:46:17 +01:00
Vec Ofs(0,0,0);
2000-11-03 23:40:41 +01:00
2000-11-02 16:46:17 +01:00
Vec &ThisCam=GetCam();
2000-10-25 20:28:44 +02:00
// check if active doc
2000-11-06 21:24:11 +01:00
if (theApp.GetCurrent()!=View->GetDocument()) return;
2000-09-22 23:19:46 +02:00
2000-10-25 20:28:44 +02:00
CurrentMousePos=point;
2000-10-25 23:00:54 +02:00
// Handle Drag Movement
if (nFlags & MK_MBUTTON)
2000-09-22 23:19:46 +02:00
{
float XS,YS;
RECT ThisRect;
2000-11-06 21:24:11 +01:00
View->GetWindowRect(&ThisRect);
2000-11-20 21:33:42 +01:00
XS=ThisCam.z*4;//*Layer[ActiveLayer]->GetLayerZPos();
YS=ThisCam.z*4;//*Layer[ActiveLayer]->GetLayerZPos();
2000-10-25 23:00:54 +02:00
XS/=((ThisRect.right-ThisRect.left));
YS/=((ThisRect.bottom-ThisRect.top));
2000-09-22 23:19:46 +02:00
2000-11-02 16:46:17 +01:00
Ofs.x=LastMousePos.x-CurrentMousePos.x;
Ofs.y=LastMousePos.y-CurrentMousePos.y;
2000-09-25 17:43:52 +02:00
LastMousePos=CurrentMousePos;
2000-09-22 23:19:46 +02:00
2000-11-02 16:46:17 +01:00
Ofs.x*=XS;
Ofs.y*=YS;
2000-10-25 20:28:44 +02:00
2000-11-06 21:24:11 +01:00
UpdateView(View,Ofs);
2000-09-22 23:19:46 +02:00
}
2000-11-06 21:24:11 +01:00
else
{ // Mouse still moved, so need to redraw windows, to get CursorPos (And pos render)
View->Invalidate();
2000-11-17 22:36:13 +01:00
if (TileViewFlag)
{
}
else
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->MouseMove(this,View,nFlags,CursorPos);
2000-11-17 22:36:13 +01:00
}
2000-11-06 21:24:11 +01:00
}
2000-10-25 20:28:44 +02:00
2000-09-22 23:19:46 +02:00
}
2000-11-15 22:22:40 +01:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-02 16:46:17 +01:00
/*** Layers ******************************************************************/
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-17 00:08:54 +01:00
void CCore::UpdateParamBar()
2000-09-22 17:11:29 +02:00
{
2000-11-02 16:46:17 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-11-10 17:17:00 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-11-17 00:08:54 +01:00
ParamBar->RemoveAll();
// Add default parram bar items
if (TileViewFlag)
{
// TileBank.InitGUI(this);
}
else
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->InitGUI(this);
2000-11-17 00:08:54 +01:00
}
ParamBar->Update();
2000-09-22 17:11:29 +02:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
2000-11-20 21:33:42 +01:00
/*
2000-11-14 16:03:04 +01:00
void CCore::SetActiveLayer(int i)
2000-11-06 21:24:11 +01:00
{
2000-11-14 16:03:04 +01:00
// UpdateParamBar(NULL,ParamViewFlag);
2000-11-06 21:24:11 +01:00
}
2000-11-20 21:33:42 +01:00
*/
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
/*** Grid ********************************************************************/
/*****************************************************************************/
void CCore::UpdateGrid(CMapEditView *View,BOOL Toggle)
2000-09-22 17:11:29 +02:00
{
2000-11-14 16:03:04 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-09-22 17:11:29 +02:00
2000-11-14 16:03:04 +01:00
if (Toggle) GridFlag=!GridFlag;
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_GRID,GridFlag);
UpdateView(View);
}
2000-11-02 16:46:17 +01:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-02 16:46:17 +01:00
/*** TileBank ****************************************************************/
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
void CCore::UpdateTileView(CMapEditView *View,BOOL Toggle)
2000-10-31 23:37:59 +01:00
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-11-15 22:22:40 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-10-31 23:37:59 +01:00
2000-11-15 22:22:40 +01:00
if (Toggle) TileViewFlag=!TileViewFlag;
ParamBar->RemoveAll();
2000-10-31 23:37:59 +01:00
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_TILEPALETTE,TileViewFlag);
2000-11-17 00:08:54 +01:00
UpdateParamBar();
2000-11-06 21:24:11 +01:00
UpdateView(View);
2000-10-31 23:37:59 +01:00
}
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
void CCore::TileBankLoad(char *Filename)
{
TileBank.AddTileSet(Filename);
TileBank.UpdateGUI(this,TileViewFlag);
UpdateView(NULL);
}
/*****************************************************************************/
void CCore::TileBankReload()
2000-11-14 16:03:04 +01:00
{
TileBank.Reload();
TexCache.Purge();
UpdateView(NULL);
}
2000-11-17 00:08:54 +01:00
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
void CCore::TileBankSet()
2000-10-31 23:37:59 +01:00
{
2000-11-14 16:03:04 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CTileSetDlg *TileSetDlg=(CTileSetDlg*)Frm->GetDialog(IDD_TILESET_DIALOG);
2000-11-15 22:22:40 +01:00
TileBank.SetCurrent(TileSetDlg->TileSetList.GetCurSel());
2000-10-31 23:37:59 +01:00
}
2000-11-06 21:24:11 +01:00
2000-11-17 00:08:54 +01:00
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
void CCore::MirrorX(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2000-11-20 17:21:43 +01:00
if (!TileViewFlag)
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->MirrorX(this);
2000-11-20 17:21:43 +01:00
UpdateView(View);
}
}
/*****************************************************************************/
void CCore::MirrorY(CMapEditView *View)
{
if (!TileViewFlag)
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->MirrorY(this);
2000-11-20 17:21:43 +01:00
UpdateView(View);
}
2000-11-17 00:08:54 +01:00
}
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
void CCore::ActiveBrushLeft(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2000-11-20 17:21:43 +01:00
TileBank.SetActiveBrushL();
UpdateView(View);
}
/*****************************************************************************/
void CCore::ActiveBrushRight(CMapEditView *View)
{
TileBank.SetActiveBrushR();
UpdateView(View);
2000-11-17 00:08:54 +01:00
}
2000-10-31 23:37:59 +01:00
/*****************************************************************************/
2000-11-02 16:46:17 +01:00
/*** Misc ********************************************************************/
2000-10-31 23:37:59 +01:00
/*****************************************************************************/
2000-11-02 16:46:17 +01:00
Vec &CCore::GetCam()
2000-10-31 23:37:59 +01:00
{
2000-11-14 16:03:04 +01:00
if (TileViewFlag)
return(TileCam);
else
return(MapCam);
2000-10-31 23:37:59 +01:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::UpdateAll(CMapEditView *View)
2000-11-02 16:46:17 +01:00
{
2000-11-14 16:03:04 +01:00
UpdateView(View);
UpdateGrid(View);
2000-11-15 22:22:40 +01:00
TileBank.UpdateGUI(this,TileViewFlag);
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->UpdateGUI(this);
2000-11-14 16:03:04 +01:00
2000-11-02 16:46:17 +01:00
}
2000-09-22 17:11:29 +02:00
2000-11-03 23:40:41 +01:00
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::UpdateView(CMapEditView *View,Vec Ofs)
2000-11-03 23:40:41 +01:00
{
Vec &ThisCam=GetCam();
2000-09-22 17:11:29 +02:00
2000-11-03 23:40:41 +01:00
Ofs.y=-Ofs.y;
ThisCam+=Ofs;
if (ThisCam.z>-1) ThisCam.z=-1;
2000-11-14 16:03:04 +01:00
if (View) View->Invalidate();
2000-11-03 23:40:41 +01:00
}
2000-11-20 17:21:43 +01:00
/*****************************************************************************/
void CCore::SetMapSize(CMapEditView *View,int Width,int Height)
{
if (Width==GetMapWidth() && Height==GetMapHeight()) return;
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
for (int i=0; i<ListSize; i++)
2000-11-20 17:21:43 +01:00
{
2000-11-20 21:33:42 +01:00
Layer[i]->Resize(Width,Height);
2000-11-20 17:21:43 +01:00
}
UpdateView(View);
}