SBSPSS/Utils/MapEdit/Core.cpp

255 lines
6.8 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-10-25 20:28:44 +02:00
#include "LayerBack.h"
#include "LayerMid.h"
#include "LayerAction.h"
#include "LayerFore.h"
2000-09-22 17:11:29 +02:00
2000-10-27 02:06:19 +02:00
2000-10-25 23:00:54 +02:00
BOOL Test3dFlag=TRUE;
2000-09-22 23:19:46 +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-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-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-04 19:24:51 +01:00
RenderFlag=TRUE;
// To be loaded/created
2000-11-06 21:24:11 +01:00
Layers[LAYER_TYPE_BACK]= new CLayerBack();
Layers[LAYER_TYPE_MID]= new CLayerMid();
Layers[LAYER_TYPE_ACTION]= new CLayerAction();
Layers[LAYER_TYPE_FORE]= new CLayerFore();
2000-11-04 19:24:51 +01:00
TileViewFlag=0;
LayerViewFlag=1;
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-06 21:24:11 +01:00
TileBank.AddTileSet("c:/temp/3/test.gin");
}
/*****************************************************************************/
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-06 21:24:11 +01:00
void CCore::Render(CMapEditView *View)
2000-09-22 23:19:46 +02:00
{
2000-11-02 16:46:17 +01:00
Vec &ThisCam=GetCam();
2000-11-06 21:24:11 +01:00
if (TileBank.NeedLoad()) TileBank.LoadTileSets(this);
2000-11-03 23:40:41 +01:00
if (RenderFlag)
2000-10-31 23:37:59 +01:00
{
2000-11-03 23:40:41 +01:00
RenderFlag=FALSE;
2000-11-06 21:24:11 +01:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
2000-11-03 23:40:41 +01:00
if (GetTileView())
2000-11-02 16:46:17 +01:00
{
2000-11-03 23:40:41 +01:00
}
else
{
for (int i=0;i<LAYER_TYPE_MAX;i++)
{
2000-11-06 21:24:11 +01:00
Layers[i]->Render(this,ThisCam,Test3dFlag);
2000-11-03 23:40:41 +01:00
}
2000-11-02 16:46:17 +01:00
}
2000-11-06 21:24:11 +01:00
Layers[ActiveLayer]->RenderGrid(this,ThisCam);
2000-11-02 16:46:17 +01:00
}
2000-11-03 23:40:41 +01:00
// Calc CursorPos
2000-11-06 21:24:11 +01:00
Layers[ActiveLayer]->FindCursorPos(this,View,ThisCam,CurrentMousePos);
2000-11-03 23:40:41 +01:00
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
/*** Control *****************************************************************/
/*****************************************************************************/
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-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-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-10-25 20:28:44 +02:00
2000-09-22 23:19:46 +02: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-06 21:24:11 +01:00
void CCore::UpdateLayerBar(CMapEditView *View,BOOL ViewFlag)
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();
CDialogBar *LayerBar=Frm->GetLayerBar();
CListBox *Dlg=(CListBox *)LayerBar->GetDlgItem(IDC_LAYERBAR_LIST);
2000-09-22 17:11:29 +02:00
2000-11-02 16:46:17 +01:00
LayerViewFlag=ViewFlag;
if (LayerViewFlag)
{
Dlg->ResetContent();
for (int i=0;i<LAYER_TYPE_MAX;i++)
{
CLayer *ThisLayer=GetLayer(i);
Dlg->AddString(ThisLayer->GetName());
}
Dlg->SetCurSel(ActiveLayer);
}
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_LAYERBAR,LayerViewFlag);
Frm->ShowControlBar(LayerBar, LayerViewFlag, FALSE);
2000-09-22 17:11:29 +02:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
void CCore::ToggleLayerView(CMapEditView *View)
{
UpdateLayerBar(View,!LayerViewFlag);
}
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-02 16:46:17 +01:00
void CCore::SetActiveLayer(int i)
2000-09-22 17:11:29 +02:00
{
2000-11-06 21:24:11 +01:00
UpdateLayerBar(NULL,LayerViewFlag);
2000-09-22 17:11:29 +02:00
}
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-06 21:24:11 +01:00
/*****************************************************************************/
void CCore::UpdateTileView(CMapEditView *View,BOOL ViewFlag)
2000-10-31 23:37:59 +01:00
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-11-02 16:46:17 +01:00
TileViewFlag=ViewFlag;
2000-10-31 23:37:59 +01:00
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_TILEPALETTE,TileViewFlag);
2000-11-06 21:24:11 +01:00
UpdateView(View);
2000-10-31 23:37:59 +01:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::ToggleTileView(CMapEditView *View)
2000-10-31 23:37:59 +01:00
{
2000-11-06 21:24:11 +01:00
UpdateTileView(View,!TileViewFlag);
2000-10-31 23:37:59 +01:00
}
2000-11-06 21:24:11 +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-02 16:46:17 +01:00
if (GetTileView())
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-06 21:24:11 +01:00
UpdateView(View);
UpdateLayerBar(View,LayerViewFlag);
UpdateTileView(View,TileViewFlag);
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-06 21:24:11 +01:00
RenderFlag=TRUE;
View->Invalidate();
2000-11-03 23:40:41 +01:00
}