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-04 19:24:51 +01:00
|
|
|
/*
|
2000-11-02 16:46:17 +01:00
|
|
|
Layers[LAYER_TYPE_BACK]= new CLayerBack(this);
|
|
|
|
Layers[LAYER_TYPE_MID]= new CLayerMid(this);
|
|
|
|
Layers[LAYER_TYPE_ACTION]= new CLayerAction(this);
|
|
|
|
Layers[LAYER_TYPE_FORE]= new CLayerFore(this);
|
|
|
|
|
|
|
|
TileViewFlag=0;
|
|
|
|
LayerViewFlag=1;
|
2000-11-04 19:24:51 +01:00
|
|
|
*/
|
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-02 16:46:17 +01:00
|
|
|
int i;
|
|
|
|
for (i=0; i<LAYER_TYPE_MAX; i++) delete Layers[i];
|
2000-09-22 17:11:29 +02:00
|
|
|
}
|
|
|
|
|
2000-09-22 23:19:46 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::Init(CMapEditView *Wnd)
|
|
|
|
{
|
|
|
|
ParentWindow=Wnd;
|
2000-11-04 19:24:51 +01:00
|
|
|
|
|
|
|
RenderFlag=TRUE;
|
|
|
|
UpdateView();
|
|
|
|
|
|
|
|
// To be loaded/created
|
|
|
|
Layers[LAYER_TYPE_BACK]= new CLayerBack(this);
|
|
|
|
Layers[LAYER_TYPE_MID]= new CLayerMid(this);
|
|
|
|
Layers[LAYER_TYPE_ACTION]= new CLayerAction(this);
|
|
|
|
Layers[LAYER_TYPE_FORE]= new CLayerFore(this);
|
|
|
|
|
|
|
|
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);
|
|
|
|
TileSet.push_back(CTileSet("c:/temp/3/test.gin",this));
|
|
|
|
}
|
2000-10-27 02:06:19 +02:00
|
|
|
|
2000-09-22 23:19:46 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::Render()
|
|
|
|
{
|
2000-11-02 16:46:17 +01:00
|
|
|
Vec &ThisCam=GetCam();
|
|
|
|
|
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;
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
Layers[i]->Render(ThisCam,Test3dFlag);
|
|
|
|
}
|
2000-11-02 16:46:17 +01:00
|
|
|
}
|
2000-11-03 23:40:41 +01:00
|
|
|
Layers[ActiveLayer]->RenderGrid(ThisCam);
|
2000-11-02 16:46:17 +01:00
|
|
|
}
|
2000-11-03 23:40:41 +01:00
|
|
|
// Calc CursorPos
|
|
|
|
Layers[ActiveLayer]->FindCursorPos(ThisCam,CurrentMousePos);
|
|
|
|
|
2000-09-22 23:19:46 +02:00
|
|
|
}
|
|
|
|
|
2000-11-02 16:46:17 +01:00
|
|
|
|
2000-09-22 23:19:46 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Control *****************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::LButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::MButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag)
|
|
|
|
{
|
2000-10-25 23:00:54 +02:00
|
|
|
LastMousePos=point;
|
2000-09-22 23:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::RButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::MouseWheel(UINT nFlags, short zDelta, CPoint &pt)
|
|
|
|
{
|
2000-10-25 20:28:44 +02:00
|
|
|
if (zDelta>0)
|
2000-11-02 16:46:17 +01:00
|
|
|
UpdateView(Vec(0,0,1.0f));
|
2000-10-25 20:28:44 +02:00
|
|
|
else
|
2000-11-02 16:46:17 +01:00
|
|
|
UpdateView(Vec(0,0,-1.0f));
|
2000-09-22 23:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-10-25 20:28:44 +02:00
|
|
|
void CCore::MouseMove(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
|
|
|
|
if (theApp.GetCurrent()!=ParentWindow->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;
|
|
|
|
|
|
|
|
ParentWindow->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-02 16:46:17 +01:00
|
|
|
UpdateView(Ofs);
|
2000-09-22 23:19:46 +02:00
|
|
|
}
|
2000-11-03 23:40:41 +01:00
|
|
|
// Mouse has moved, so need to redraw windows, to get CursorPos (And pos render)
|
|
|
|
ParentWindow->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-02 16:46:17 +01:00
|
|
|
void CCore::UpdateLayerBar(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-02 16:46:17 +01:00
|
|
|
void CCore::SetActiveLayer(int i)
|
2000-09-22 17:11:29 +02:00
|
|
|
{
|
2000-11-02 16:46:17 +01:00
|
|
|
UpdateLayerBar(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-02 16:46:17 +01:00
|
|
|
void CCore::UpdateTileView(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-02 16:46:17 +01:00
|
|
|
UpdateView();
|
2000-10-31 23:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-02 16:46:17 +01:00
|
|
|
GLint CCore::GetTile(int Bank,int TileNo)
|
2000-10-31 23:37:59 +01:00
|
|
|
{
|
2000-11-02 16:46:17 +01:00
|
|
|
return(TileSet[Bank].GetTile(TileNo));
|
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-02 16:46:17 +01:00
|
|
|
void CCore::UpdateAll()
|
2000-10-31 23:37:59 +01:00
|
|
|
{
|
2000-11-02 16:46:17 +01:00
|
|
|
UpdateView();
|
|
|
|
UpdateLayerBar(LayerViewFlag);
|
|
|
|
UpdateTileView(TileViewFlag);
|
2000-10-31 23:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-03 23:40:41 +01:00
|
|
|
void CCore::Redraw(BOOL f)
|
2000-11-02 16:46:17 +01:00
|
|
|
{
|
2000-11-03 23:40:41 +01:00
|
|
|
RenderFlag=f;
|
|
|
|
if (RenderFlag)
|
2000-11-02 16:46:17 +01:00
|
|
|
ParentWindow->Invalidate();
|
|
|
|
}
|
2000-09-22 17:11:29 +02:00
|
|
|
|
2000-11-03 23:40:41 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CCore::UpdateView(Vec Ofs)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
Redraw();
|
|
|
|
}
|