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-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-11-08 20:53:57 +01:00
|
|
|
|
|
|
|
RenderFlag=TRUE;
|
|
|
|
TileViewFlag=FALSE;
|
|
|
|
ParamViewFlag=TRUE;
|
|
|
|
CurrentMousePos=CPoint(0,0);
|
|
|
|
ActiveLayer=0;
|
|
|
|
MapCam=Vec(0,0,0);
|
|
|
|
TileCam=Vec(0,0,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
|
|
|
// To be loaded/created
|
2000-11-07 21:38:19 +01:00
|
|
|
Layers[LAYER_TYPE_BACK]= new CLayerTile("Back", 32, 32, 4.0f, FALSE);
|
|
|
|
Layers[LAYER_TYPE_MID]= new CLayerTile("Mid", TileLayerDefaultWidth/2.0f, TileLayerDefaultHeight/2.0f, 2.0f, FALSE);
|
|
|
|
Layers[LAYER_TYPE_ACTION]= new CLayerTile("Action",TileLayerDefaultWidth/1.0f, TileLayerDefaultHeight/1.0f, 1.0f, TRUE);
|
|
|
|
Layers[LAYER_TYPE_FORE]= new CLayerTile("Fore", TileLayerDefaultWidth/0.5f, TileLayerDefaultHeight/0.5f, 0.5f, FALSE);
|
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-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-07 21:38:19 +01: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-08 15:49:33 +01:00
|
|
|
void CCore::UpdateParamBar(CMapEditView *View,BOOL ViewFlag)
|
2000-09-22 17:11:29 +02:00
|
|
|
{
|
2000-11-08 20:53:57 +01:00
|
|
|
/*
|
2000-11-02 16:46:17 +01:00
|
|
|
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
|
|
|
|
CToolBar *ToolBar=Frm->GetToolBar();
|
2000-11-08 20:53:57 +01:00
|
|
|
CDialogBar *ParamBar=Frm->GetParamBar();
|
|
|
|
CListBox *Dlg=(CListBox *)ParamBar->GetDlgItem(IDC_PARAMBAR_LAYER_LIST);
|
2000-11-08 15:49:33 +01:00
|
|
|
|
|
|
|
ParamViewFlag=ViewFlag;
|
|
|
|
if (ParamViewFlag)
|
2000-11-02 16:46:17 +01:00
|
|
|
{
|
|
|
|
Dlg->ResetContent();
|
|
|
|
|
|
|
|
for (int i=0;i<LAYER_TYPE_MAX;i++)
|
|
|
|
{
|
|
|
|
CLayer *ThisLayer=GetLayer(i);
|
|
|
|
Dlg->AddString(ThisLayer->GetName());
|
|
|
|
}
|
|
|
|
Dlg->SetCurSel(ActiveLayer);
|
|
|
|
}
|
|
|
|
|
2000-11-08 15:49:33 +01:00
|
|
|
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_PARAMBAR,ParamViewFlag);
|
|
|
|
Frm->ShowControlBar(ParamBar, ParamViewFlag, FALSE);
|
2000-11-07 21:38:19 +01:00
|
|
|
if (View) UpdateView(View);
|
2000-11-08 20:53:57 +01:00
|
|
|
*/
|
2000-09-22 17:11:29 +02:00
|
|
|
}
|
|
|
|
|
2000-11-06 21:24:11 +01:00
|
|
|
/*****************************************************************************/
|
2000-11-08 15:49:33 +01:00
|
|
|
void CCore::ToggleParamView(CMapEditView *View)
|
2000-11-06 21:24:11 +01:00
|
|
|
{
|
2000-11-08 15:49:33 +01:00
|
|
|
UpdateParamBar(View,!ParamViewFlag);
|
2000-11-06 21:24:11 +01:00
|
|
|
}
|
|
|
|
|
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-08 15:49:33 +01:00
|
|
|
UpdateParamBar(NULL,ParamViewFlag);
|
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);
|
2000-11-08 15:49:33 +01:00
|
|
|
UpdateParamBar(View,ParamViewFlag);
|
2000-11-06 21:24:11 +01:00
|
|
|
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
|
|
|
}
|