SBSPSS/Utils/MapEdit/Core.cpp

410 lines
11 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-06 21:24:11 +01:00
for (int i=0; i<LAYER_TYPE_MAX; i++) Layers[i]=0;
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-06 21:24:11 +01:00
for (int i=0; i<LAYER_TYPE_MAX; i++) if (Layers[i]) delete Layers[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();
// Layers[ActiveLayer]->InitGUI(this);
// ParamBar->Update();
2000-11-15 22:22:40 +01:00
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::NewMap()
2000-09-22 23:19:46 +02:00
{
2000-11-20 17:21:43 +01:00
// Create Gfx Layers
// Name Width Height SizeDiv ViewDiv 3d? Resizable?
Layers[LAYER_TYPE_BACK]= new CLayerTile( "Back", 32, 32, 1.0f, 4.0f, FALSE, FALSE);
Layers[LAYER_TYPE_MID]= new CLayerTile( "Mid", TileLayerDefaultWidth, TileLayerDefaultHeight, 2.0f, 2.0f, FALSE, TRUE);
Layers[LAYER_TYPE_ACTION]= new CLayerTile( "Action",TileLayerDefaultWidth, TileLayerDefaultHeight, 1.0f, 1.0f, TRUE, TRUE);
Layers[LAYER_TYPE_FORE]= new CLayerTile( "Fore", TileLayerDefaultWidth, TileLayerDefaultHeight, 0.5f, 0.5f, FALSE, TRUE);
2000-11-04 19:24:51 +01:00
2000-11-03 23:40:41 +01:00
ActiveLayer=LAYER_TYPE_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
}
/*****************************************************************************/
void CCore::OpenMap()
{
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();
for (int i=0;i<LAYER_TYPE_MAX;i++)
2000-10-31 23:37:59 +01:00
{
2000-11-14 16:03:04 +01:00
Layers[i]->Render(this,ThisCam,Is3dFlag);
2000-11-02 16:46:17 +01:00
}
2000-11-14 16:03:04 +01:00
2000-11-17 22:36:13 +01:00
Layers[ActiveLayer]->RenderCursor(this,ThisCam,Is3dFlag);
2000-11-14 16:03:04 +01:00
if (GridFlag) Layers[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-14 16:03:04 +01:00
Layers[ActiveLayer]->FindCursorPos(this,View,GetCam(),CurrentMousePos);
}
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;
RedrawFlag=Layers[ActiveLayer]->SetMode(NewMode);
//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
{
RedrawFlag=Layers[ActiveLayer]->LButtonControl(this,View,nFlags,CursorPos,DownFlag);
}
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
{
RedrawFlag=Layers[ActiveLayer]->RButtonControl(this,View,nFlags,CursorPos,DownFlag);
}
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-03 23:40:41 +01:00
XS=ThisCam.z*4;//*Layers[ActiveLayer]->GetLayerZPos();
YS=ThisCam.z*4;//*Layers[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-15 22:22:40 +01:00
Layers[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
{
Layers[ActiveLayer]->InitGUI(this);
}
ParamBar->Update();
2000-09-22 17:11:29 +02:00
}
2000-11-06 21:24:11 +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-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)
{
Layers[ActiveLayer]->MirrorX(this);
UpdateView(View);
}
}
/*****************************************************************************/
void CCore::MirrorY(CMapEditView *View)
{
if (!TileViewFlag)
{
Layers[ActiveLayer]->MirrorY(this);
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);
Layers[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;
for (int i=0; i<LAYER_TYPE_MAX; i++)
{
// Layers[i]->Resize(Width,Height);
}
Layers[LAYER_TYPE_ACTION]->Resize(Width,Height);
UpdateView(View);
}