SBSPSS/Utils/MapEdit/Core.cpp

895 lines
21 KiB
C++
Raw Normal View History

2000-09-22 17:11:29 +02:00
/***********************/
/*** Map Editor Core ***/
/***********************/
#include "stdafx.h"
2000-12-04 17:47:34 +01:00
#include <Vector3.h>
2000-09-22 23:19:46 +02:00
#include <gl\gl.h>
#include <gl\glu.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-11-28 22:16:00 +01:00
#include "NewMapGUI.h"
2001-01-23 22:53:48 +01:00
#include "AddLayerDlg.h"
2000-11-28 22:16:00 +01: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"
2001-01-23 22:53:48 +01:00
#include "LayerCollision.h"
2001-02-09 22:17:01 +01:00
#include "LayerShade.h"
2000-11-21 22:27:55 +01:00
#include "utils.h"
2001-02-01 23:48:22 +01:00
#include "Export.h"
2001-02-09 22:17:01 +01:00
#include "LayerList.h"
2001-02-16 19:23:01 +01:00
const Vector3 DefaultCamPos(0.0f,0.0f,0.9f);
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CCore::CCore()
{
2000-11-28 22:16:00 +01:00
CurrentMousePos=CPoint(0,0);
2001-02-14 23:35:47 +01:00
CurrentView=NULL;
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();
2000-11-28 22:16:00 +01:00
for (int i=0; i<ListSize; i++) delete Layer[i];
2000-09-22 17:11:29 +02:00
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2000-11-28 22:16:00 +01:00
BOOL CCore::New()
2000-09-22 23:19:46 +02:00
{
2000-11-28 22:16:00 +01:00
CNewMapGUI Dlg;
int Width,Height;
2000-11-30 23:17:55 +01:00
Dlg.m_Width=TileLayerMinWidth;
Dlg.m_Height=TileLayerMinHeight;
2000-11-28 22:16:00 +01:00
2001-01-21 19:04:00 +01:00
#ifndef _DEBUG
2000-11-28 22:16:00 +01:00
if (Dlg.DoModal()!=IDOK) return FALSE;
2001-01-21 19:04:00 +01:00
#endif
2000-11-28 22:16:00 +01:00
Width=Dlg.m_Width;
Height=Dlg.m_Height;
2000-11-04 19:24:51 +01:00
2000-11-28 22:16:00 +01:00
// Create Tile Layers
2001-02-09 22:17:01 +01:00
AddLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION, Width, Height);
AddLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_SCRATCH, Width, Height);
2000-11-28 22:16:00 +01:00
2001-02-14 23:35:47 +01:00
ActiveLayer=FindLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION);
2001-02-16 19:23:01 +01:00
MapCam=DefaultCamPos;
TileCam=DefaultCamPos;
2000-11-28 22:16:00 +01:00
TileViewFlag=FALSE;
GridFlag=TRUE;
Is3dFlag=TRUE;
return(TRUE);
2000-11-06 21:24:11 +01:00
}
/*****************************************************************************/
2000-11-20 21:33:42 +01:00
void CCore::Load(CFile *File)
{
2001-01-23 22:53:48 +01:00
int Version;
2000-11-20 21:33:42 +01:00
2001-01-23 22:53:48 +01:00
File->Read(&Version,sizeof(int));
if (Version>100000) Version=1; // Check fix for changing version to int from float
2000-11-20 21:33:42 +01:00
2001-01-23 22:53:48 +01:00
if (Version<FileVersion)
2000-11-28 22:16:00 +01:00
{
2001-01-23 22:53:48 +01:00
CString mexstr;
mexstr.Format("Old File Format\n\nPlease re-save\n");
AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
2000-11-20 21:33:42 +01:00
2000-11-28 22:16:00 +01:00
}
2000-11-20 21:33:42 +01:00
2001-01-23 22:53:48 +01:00
TRACE1("Load Version %i\n",Version);
File->Read(&MapCam,sizeof(Vector3));
File->Read(&MapCamOfs,sizeof(Vector3));
File->Read(&TileCam,sizeof(Vector3));
File->Read(&TileCamOfs,sizeof(Vector3));
File->Read(&TileViewFlag,sizeof(BOOL));
File->Read(&GridFlag,sizeof(BOOL));
File->Read(&Is3dFlag,sizeof(BOOL));
2000-11-20 21:33:42 +01:00
// 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:
2001-01-23 22:53:48 +01:00
AddLayer(new CLayerTile(File,Version));
break;
case LAYER_TYPE_COLLISION:
AddLayer(new CLayerCollision(File,Version));
2000-11-20 21:33:42 +01:00
break;
2001-02-09 22:17:01 +01:00
case LAYER_TYPE_SHADE:
AddLayer(new CLayerShade(File,Version));
break;
default:
ASSERT(!"poos");
2000-11-20 21:33:42 +01:00
}
}
2000-11-28 22:16:00 +01:00
TileBank.Load(File,Version);
2000-11-30 23:17:55 +01:00
// Check Layers
2001-02-14 23:35:47 +01:00
int MapWidth=ActionLayer->GetWidth();
int MapHeight=ActionLayer->GetHeight();
2000-11-30 23:17:55 +01:00
for (i=0;i<LayerCount;i++)
{
Layer[i]->CheckLayerSize(MapWidth,MapHeight);
}
2001-02-14 23:35:47 +01:00
2000-11-20 21:33:42 +01:00
}
/*****************************************************************************/
void CCore::Save(CFile *File)
2000-11-06 21:24:11 +01:00
{
2000-11-28 22:16:00 +01:00
// Version 1
2001-01-23 22:53:48 +01:00
File->Write(&FileVersion,sizeof(int));
2000-11-20 21:33:42 +01:00
2000-12-04 17:47:34 +01:00
File->Write(&MapCam,sizeof(Vector3));
File->Write(&MapCamOfs,sizeof(Vector3));
File->Write(&TileCam,sizeof(Vector3));
File->Write(&TileCamOfs,sizeof(Vector3));
2000-11-20 21:33:42 +01:00
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-12-11 22:29:59 +01:00
/*****************************************************************************/
2000-12-29 23:20:38 +01:00
BOOL CCore::Question(char *Txt)
2000-12-11 22:29:59 +01:00
{
2001-02-14 23:35:47 +01:00
CString Str;
Str.Format(Txt);
int Ret=AfxMessageBox(Str,MB_YESNO , MB_ICONQUESTION);
if (Ret==IDYES) return(true);
return(false);
2000-12-11 22:29:59 +01:00
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::Render(BOOL ForceRender)
2000-09-22 23:19:46 +02:00
{
2001-02-14 23:35:47 +01:00
if (!CurrentView)
{
TRACE0("No View\n");
UpdateAll();
return;
}
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)
{
2001-02-14 23:35:47 +01:00
RenderTileView();
2000-11-14 16:03:04 +01:00
}
else
{
2001-02-14 23:35:47 +01:00
RenderLayers();
2000-11-14 16:03:04 +01:00
}
}
2000-11-10 17:17:00 +01:00
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::RenderLayers()
2000-11-14 16:03:04 +01:00
{
2000-12-04 17:47:34 +01:00
Vector3 &ThisCam=GetCam();
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
2001-02-07 22:31:31 +01:00
int StartLayer,EndLayer;
StartLayer=0;
EndLayer=ListSize;
while (Layer[StartLayer]->IsUnique()) StartLayer++;
if (Layer[ActiveLayer]->IsUnique())
{
StartLayer=ActiveLayer;
EndLayer=StartLayer+1;
}
for (int i=StartLayer; i<EndLayer; i++)
2000-10-31 23:37:59 +01:00
{
2000-11-28 00:14:42 +01:00
if (Layer[i]->IsVisible())
2001-02-07 22:31:31 +01:00
{
2000-11-28 00:14:42 +01:00
Layer[i]->Render(this,ThisCam,Is3dFlag);
if (GridFlag) Layer[i]->RenderGrid(this,ThisCam,i==ActiveLayer);
2001-02-07 22:31:31 +01:00
}
2000-11-02 16:46:17 +01:00
}
2001-02-07 22:31:31 +01:00
2000-11-14 16:03:04 +01:00
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->RenderCursor(this,ThisCam,Is3dFlag);
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;
2001-02-14 23:35:47 +01:00
Layer[ActiveLayer]->FindCursorPos(this,GetCam(),CurrentMousePos);
2000-11-14 16:03:04 +01:00
}
2000-11-03 23:40:41 +01:00
2001-02-14 23:35:47 +01:00
/*****************************************************************************/
void CCore::RenderTileView()
2000-11-14 16:03:04 +01:00
{
2000-12-04 17:47:34 +01:00
Vector3 &ThisCam=GetCam();
2000-11-14 16:03:04 +01:00
2001-01-23 22:53:48 +01:00
GetTileBank().RenderSet(this,ThisCam,Is3dFlag);
2001-02-14 23:35:47 +01:00
GetTileBank().FindCursorPos(this,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
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::LButtonControl(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)
2001-01-23 22:53:48 +01:00
RedrawFlag=GetTileBank().SelectCancel();
2000-11-17 22:36:13 +01:00
else
2001-01-23 22:53:48 +01:00
RedrawFlag=GetTileBank().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-12-01 22:33:02 +01:00
if (Layer[ActiveLayer]->IsVisible())
{
2001-02-14 23:35:47 +01:00
RedrawFlag=Layer[ActiveLayer]->LButtonControl(this,nFlags,CursorPos,DownFlag);
2000-12-01 22:33:02 +01:00
}
2000-11-15 22:22:40 +01:00
}
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushL();
2000-11-15 22:22:40 +01:00
2001-02-14 23:35:47 +01:00
if (RedrawFlag) RedrawView();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::MButtonControl(UINT nFlags, CPoint &point,BOOL DownFlag)
2000-09-22 23:19:46 +02:00
{
}
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::RButtonControl(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)
2001-01-23 22:53:48 +01:00
RedrawFlag=GetTileBank().SelectCancel();
2000-11-17 22:36:13 +01:00
else
2001-01-23 22:53:48 +01:00
RedrawFlag=GetTileBank().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-12-01 22:33:02 +01:00
if (Layer[ActiveLayer]->IsVisible())
{
2001-02-14 23:35:47 +01:00
RedrawFlag=Layer[ActiveLayer]->RButtonControl(this,nFlags,CursorPos,DownFlag);
2000-12-01 22:33:02 +01:00
}
2000-11-15 22:22:40 +01:00
}
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushR();
2000-11-14 16:03:04 +01:00
2001-02-14 23:35:47 +01:00
if (RedrawFlag) RedrawView();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::Zoom(float Dst)
2000-09-22 23:19:46 +02:00
{
2000-12-04 17:47:34 +01:00
Vector3 Ofs;
Ofs.Zero();
2000-12-11 22:52:32 +01:00
Ofs.z=Dst;
2001-02-09 22:17:01 +01:00
UpdateView(&Ofs);
2000-09-22 23:19:46 +02:00
}
2000-12-11 22:52:32 +01:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::MouseWheel(UINT nFlags, short zDelta, CPoint &pt)
2000-12-11 22:52:32 +01:00
{
if (zDelta>0)
2001-02-09 22:17:01 +01:00
Zoom(-0.1f);
2001-01-03 23:11:13 +01:00
else
2001-02-09 22:17:01 +01:00
Zoom(+0.1f);
2000-12-11 22:52:32 +01:00
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::MouseMove(UINT nFlags, CPoint &point)
2000-09-22 23:19:46 +02:00
{
2000-12-04 17:47:34 +01:00
Vector3 Ofs;
Vector3 &ThisCam=GetCam();
2000-10-25 20:28:44 +02:00
// check if active doc
2000-12-04 17:47:34 +01:00
Ofs.Zero();
2001-02-14 23:35:47 +01:00
if (theApp.GetCurrent()!=CurrentView->GetDocument()) return;
GetWorkingPath();
2000-10-25 20:28:44 +02:00
CurrentMousePos=point;
2000-10-25 23:00:54 +02:00
// Handle Drag Movement
2000-12-11 23:42:19 +01:00
if (nFlags & MK_MBUTTON || nFlags & MK_SHIFT)
2000-09-22 23:19:46 +02:00
{
float XS,YS;
RECT ThisRect;
2001-01-17 22:52:08 +01:00
float MoveSpd=GetZoomW();
2000-09-22 23:19:46 +02:00
2001-01-17 22:52:08 +01:00
if (nFlags & MK_CONTROL)
{
MoveSpd*=4;
}
2001-02-14 23:35:47 +01:00
CurrentView->GetWindowRect(&ThisRect);
2001-01-17 22:52:08 +01:00
XS=ThisCam.z*MoveSpd;
YS=ThisCam.z*MoveSpd;
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-22 23:19:46 +02:00
2000-11-02 16:46:17 +01:00
Ofs.x*=XS;
Ofs.y*=YS;
2001-02-09 22:17:01 +01:00
UpdateView(&Ofs);
2000-09-22 23:19:46 +02:00
}
2000-11-06 21:24:11 +01:00
else
2000-12-01 22:33:02 +01:00
{
2000-11-17 22:36:13 +01:00
if (TileViewFlag)
{
}
else
{
2000-12-01 22:33:02 +01:00
if (Layer[ActiveLayer]->IsVisible())
{
2001-02-14 23:35:47 +01:00
Layer[ActiveLayer]->MouseMove(this,nFlags,CursorPos);
2000-12-01 22:33:02 +01:00
}
2000-11-17 22:36:13 +01:00
}
2001-02-14 23:35:47 +01:00
// Mouse still moved, so need to redraw windows, to get CursorPos
2001-02-09 22:17:01 +01:00
RedrawView();
2000-11-06 21:24:11 +01:00
}
2000-12-11 23:42:19 +01:00
LastMousePos=CurrentMousePos;
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
{
2001-02-14 23:35:47 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
2000-11-10 17:17:00 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2001-02-09 22:17:01 +01:00
GUIRemoveAll();
GUIAdd(LayerList,IDD_LAYER_LIST_DIALOG);
Layer[ActiveLayer]->GUIInit(this);
GUIUpdate();
2000-09-22 17:11:29 +02:00
}
2000-11-21 22:27:55 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::UpdateLayerGUI()
2000-11-21 22:27:55 +01:00
{
int ListSize=Layer.size();
2001-02-09 22:17:01 +01:00
if (LayerList.ListBox)
2000-11-21 22:27:55 +01:00
{
2001-02-09 22:17:01 +01:00
LayerList.ListBox.ResetContent();
for (int i=0; i<ListSize; i++)
{
LayerList.ListBox.AddString(Layer[i]->GetName());
}
2000-11-21 22:27:55 +01:00
// Now sets checks (silly MSoft bug!!)
2001-02-09 22:17:01 +01:00
for (i=0; i<ListSize; i++)
{
LayerList.ListBox.SetCheck(i,Layer[i]->IsVisible());
}
LayerList.ListBox.SetCurSel(ActiveLayer);
2000-11-21 22:27:55 +01:00
}
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
void CCore::SetLayer(int NewLayer,bool Force)
2000-11-06 21:24:11 +01:00
{
2001-02-14 23:35:47 +01:00
int LayerCount=Layer.size()-1;
int LastLayer=ActiveLayer;
2001-01-21 19:04:00 +01:00
if (NewLayer<0) NewLayer=0;
2001-02-09 22:17:01 +01:00
2000-12-01 22:33:02 +01:00
// If toggling layer, dont change the layer
2001-02-09 22:17:01 +01:00
if ((int)LayerList.ListBox.GetCheck(NewLayer)!=(int)Layer[NewLayer]->IsVisible())
2000-12-01 22:33:02 +01:00
{
2001-02-09 22:17:01 +01:00
Layer[NewLayer]->SetVisible(LayerList.ListBox.GetCheck(NewLayer));
LayerList.ListBox.SetCurSel(ActiveLayer);
2000-12-01 22:33:02 +01:00
}
else
2000-11-28 00:14:42 +01:00
{
2001-01-23 22:53:48 +01:00
bool IsCol=Layer[NewLayer]->GetType()==LAYER_TYPE_COLLISION;
TileBank.SetCollision(IsCol);
2000-11-28 00:14:42 +01:00
ActiveLayer=NewLayer;
}
2001-02-14 23:35:47 +01:00
if (LastLayer!=ActiveLayer || Force)
{
if (TileViewFlag) TileViewFlag=false;
if (LastLayer<=LayerCount) Layer[LastLayer]->GUIKill(this);
Layer[ActiveLayer]->GUIInit(this);
GUIUpdate();
}
2001-02-09 22:17:01 +01:00
RedrawView();
2000-11-06 21:24:11 +01:00
}
2000-11-28 00:07:07 +01:00
2001-01-23 22:53:48 +01:00
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
int CCore::AddLayer(CLayer *NewLayer)
2001-01-23 22:53:48 +01:00
{
int ListSize=Layer.size();
int NewIdx=CLayer::GetLayerIdx(NewLayer->GetType(),NewLayer->GetSubType());
int Idx=ListSize;
TRACE3("Add Layer %i %i @ %i\n",NewLayer->GetType(),NewLayer->GetSubType(),NewIdx);
for (Idx=0; Idx<ListSize; Idx++)
{
int ListIdx=CLayer::GetLayerIdx(Layer[Idx]->GetType(),Layer[Idx]->GetSubType());
if (NewIdx<ListIdx) break;
}
Layer.insert(Layer.begin() + Idx,NewLayer);
2001-02-14 23:35:47 +01:00
if (NewLayer->GetType()==LAYER_TYPE_TILE && NewLayer->GetSubType()==LAYER_SUBTYPE_ACTION) ActionLayer=NewLayer;
return(Idx);
2001-01-23 22:53:48 +01:00
}
/*****************************************************************************/
2001-02-14 23:35:47 +01:00
int CCore::AddLayer(int Type, int SubType, int Width, int Height)
2001-01-23 22:53:48 +01:00
{
2001-02-14 23:35:47 +01:00
int Idx;
2001-01-23 22:53:48 +01:00
switch (Type)
{
case LAYER_TYPE_TILE:
2001-02-14 23:35:47 +01:00
Idx=AddLayer(new CLayerTile(SubType, Width,Height));
2001-01-23 22:53:48 +01:00
break;
case LAYER_TYPE_COLLISION:
2001-02-14 23:35:47 +01:00
Idx=AddLayer(new CLayerCollision(SubType, Width,Height));
2001-01-23 22:53:48 +01:00
break;
2001-02-09 22:17:01 +01:00
case LAYER_TYPE_SHADE:
2001-02-14 23:35:47 +01:00
Idx=AddLayer(new CLayerShade(SubType, Width,Height));
2001-02-09 22:17:01 +01:00
break;
2001-01-23 22:53:48 +01:00
default:
ASSERT(!"AddLayer - Invalid Layer Type");
break;
}
2001-02-14 23:35:47 +01:00
return(Idx);
2001-01-23 22:53:48 +01:00
}
2001-01-21 19:04:00 +01:00
/*****************************************************************************/
void CCore::AddLayer(int CurrentLayer)
{
2001-01-23 22:53:48 +01:00
std::vector<int> List;
CAddLayerDlg Dlg;
int NewLayerId=0;
int Sel;
// Build Unused List
Dlg.Sel=&Sel;
Sel=0;
for (int i=0; i<CLayer::InfoTableSize; i++)
{
if (FindLayer(CLayer::InfoTable[i].Type,CLayer::InfoTable[i].SubType)==-1)
{
List.push_back(i);
Dlg.StrList.push_back(CLayer::InfoTable[i].Name);
}
}
if (Dlg.DoModal()!=IDOK) return;
NewLayerId=List[Sel];
TRACE2("Add Layer %i %s\n",NewLayerId,CLayer::InfoTable[NewLayerId].Name);
2001-01-21 19:04:00 +01:00
2001-02-14 23:35:47 +01:00
int Width=ActionLayer->GetWidth();
int Height=ActionLayer->GetHeight();
int Idx=AddLayer(CLayer::InfoTable[NewLayerId].Type,CLayer::InfoTable[NewLayerId].SubType,Width,Height);
if (ActiveLayer>=Idx) ActiveLayer++;
2001-01-21 19:04:00 +01:00
2001-02-14 23:35:47 +01:00
SetLayer(Idx,true);
2001-01-21 19:04:00 +01:00
}
/*****************************************************************************/
void CCore::DeleteLayer(int CurrentLayer)
{
if (Layer[CurrentLayer]->CanDelete())
{
2001-02-09 22:17:01 +01:00
Layer[CurrentLayer]->GUIKill(this);
2001-01-21 19:04:00 +01:00
delete Layer[CurrentLayer];
Layer.erase(Layer.begin() + CurrentLayer);
2001-02-14 23:35:47 +01:00
SetLayer(CurrentLayer-1,true);
2001-01-21 19:04:00 +01:00
TRACE1("Deleted Layer %i\n",CurrentLayer);
}
else
{
TRACE1("Cant Delete Layer %i\n",CurrentLayer);
}
}
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
/*** Grid ********************************************************************/
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::UpdateGrid(BOOL Toggle)
2000-09-22 17:11:29 +02:00
{
2000-11-14 16:03:04 +01:00
if (Toggle) GridFlag=!GridFlag;
2001-02-14 23:35:47 +01:00
RedrawView();
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-02 16:46:17 +01:00
/*** TileBank ****************************************************************/
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::UpdateTileView(BOOL Toggle)
2000-10-31 23:37:59 +01:00
{
2001-02-14 23:35:47 +01:00
if (!Layer[ActiveLayer]->HasTileView()) return;
2001-02-16 19:23:01 +01:00
if (TileViewFlag && !TileBank.CanClose()) return;
2001-02-14 23:35:47 +01:00
if (Toggle)
{
TileViewFlag=!TileViewFlag;
}
if (TileViewFlag)
{
Layer[ActiveLayer]->GUIKill(this);
TileBank.GUIInit(this);
}
else
{
TileBank.GUIKill(this);
Layer[ActiveLayer]->GUIInit(this);
}
GUIUpdate();
RedrawView();
2000-10-31 23:37:59 +01:00
}
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
void CCore::TileBankLoad(char *Filename)
{
TileBank.AddTileSet(Filename);
2001-02-09 22:17:01 +01:00
TileBank.GUIUpdate(this);
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-15 22:22:40 +01:00
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
void CCore::TileBankDelete()
{
2000-12-11 22:29:59 +01:00
if (Question("Delete Current Tile Bank\n\nAll used tiles in current set will be set to blank\nAre you sure?"))
{
int SetCount=TileBank.GetSetCount();
int Current=TileBank.GetCurrent();
int i,ListSize=Layer.size();
for (i=0;i<ListSize;i++)
{
Layer[i]->DeleteSet(Current);
}
TileBank.Delete();
for (int Set=Current+1; Set<SetCount; Set++)
{
for (i=0;i<ListSize;i++)
{
Layer[i]->RemapSet(Set,Set-1);
}
}
2001-02-14 23:35:47 +01:00
RedrawView();
2000-12-11 22:29:59 +01:00
}
2000-11-29 18:07:57 +01:00
}
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
void CCore::TileBankReload()
2000-11-14 16:03:04 +01:00
{
TileBank.Reload();
TexCache.Purge();
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-14 16:03:04 +01:00
}
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
{
2001-02-09 22:17:01 +01:00
TileBank.SetCurrent();
2000-10-31 23:37:59 +01:00
}
2000-11-06 21:24:11 +01:00
2000-11-17 00:08:54 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::MirrorX()
2000-11-17 00:08:54 +01:00
{
2001-02-09 22:17:01 +01:00
if (TileViewFlag) return;
Layer[ActiveLayer]->MirrorX(this);
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-20 17:21:43 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::MirrorY()
2000-11-20 17:21:43 +01:00
{
2001-02-09 22:17:01 +01:00
if (TileViewFlag) return;
Layer[ActiveLayer]->MirrorY(this);
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-17 00:08:54 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::ActiveBrushLeft()
2000-11-17 00:08:54 +01:00
{
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushL();
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-20 17:21:43 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::ActiveBrushRight()
2000-11-20 17:21:43 +01:00
{
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushR();
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-17 00:08:54 +01:00
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
BOOL CCore::IsTileValid(int Set,int Tile)
{
return(TileBank.IsTileValid(Set,Tile));
}
2001-02-20 16:57:03 +01:00
/*****************************************************************************/
void CCore::SetColFlag(int Flag)
{
if (TileViewFlag) return;
Layer[ActiveLayer]->SetColFlags(this,Flag);
RedrawView();
}
2001-01-02 15:34:02 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::CopySelection()
2001-01-02 15:34:02 +01:00
{
Layer[ActiveLayer]->CopySelection(this);
2001-02-14 23:35:47 +01:00
RedrawView();
2001-01-02 15:34:02 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::PasteSelection()
2001-01-02 15:34:02 +01:00
{
Layer[ActiveLayer]->PasteSelection(this);
2001-02-14 23:35:47 +01:00
RedrawView();
2001-01-02 15:34:02 +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-12-04 17:47:34 +01:00
Vector3 &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-28 00:07:07 +01:00
/*****************************************************************************/
2000-12-29 23:20:38 +01:00
void CCore::SetScale()
2000-11-28 00:07:07 +01:00
{
2000-12-29 23:20:38 +01:00
float XS=GetZoomW();
float YS=GetZoomH();
float ZS=XS/YS;
2000-11-28 00:07:07 +01:00
2000-12-29 23:20:38 +01:00
ScaleVector.x=1.0f/XS;
ScaleVector.y=1.0f/XS;
2001-02-14 23:35:47 +01:00
ScaleVector.z=1.0f/XS;
2000-12-29 23:20:38 +01:00
}
/*****************************************************************************/
float CCore::GetZoomW()
{
Vector3 &ThisCam=GetCam();
2001-02-09 22:17:01 +01:00
return((float)SCREEN_MAP_WIDTH/ThisCam.z);
2000-12-29 23:20:38 +01:00
}
/*****************************************************************************/
float CCore::GetZoomH()
{
Vector3 &ThisCam=GetCam();
2001-02-09 22:17:01 +01:00
return((float)SCREEN_MAP_HEIGHT/ThisCam.z);
2000-11-28 00:07:07 +01:00
}
2001-02-16 19:23:01 +01:00
/*****************************************************************************/
void CCore::ResetView()
{
Vector3 &ThisCam=GetCam();
ThisCam=DefaultCamPos;
UpdateView();
}
2000-10-31 23:37:59 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
/*** GUI *********************************************************************/
/*****************************************************************************/
void CCore::GUIAdd(CDialog &Dlg,int ID,bool Visible,bool Lock)
2000-11-02 16:46:17 +01:00
{
2001-02-14 23:35:47 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
2001-02-09 22:17:01 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-11-14 16:03:04 +01:00
2001-02-09 22:17:01 +01:00
ParamBar->Add(Dlg,ID,Visible,Lock);
}
/*****************************************************************************/
void CCore::GUIRemove(CDialog &Dlg,int ID,bool Force)
{
2001-02-14 23:35:47 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
2001-02-09 22:17:01 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-11-14 16:03:04 +01:00
2001-02-09 22:17:01 +01:00
ParamBar->Remove(Dlg,Force);
2000-11-02 16:46:17 +01:00
}
2000-09-22 17:11:29 +02:00
2000-11-21 22:27:55 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::GUIRemoveAll(bool Force)
2000-11-21 22:27:55 +01:00
{
2001-02-14 23:35:47 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
2001-02-09 22:17:01 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
ParamBar->RemoveAll(Force);
2000-11-21 22:27:55 +01:00
}
2000-11-03 23:40:41 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::GUIUpdate()
2000-11-03 23:40:41 +01:00
{
2001-02-14 23:35:47 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
2001-02-09 22:17:01 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
UpdateLayerGUI();
UpdateGrid();
Layer[ActiveLayer]->GUIUpdate(this);
ParamBar->Update();
}
2000-11-20 17:21:43 +01:00
2000-12-04 17:47:34 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::GUIChanged()
2000-12-04 17:47:34 +01:00
{
2001-02-09 22:17:01 +01:00
Layer[ActiveLayer]->GUIChanged(this);
}
/*****************************************************************************/
void CCore::UpdateAll()
{
UpdateParamBar();
2001-02-14 23:35:47 +01:00
RedrawView();
2001-02-09 22:17:01 +01:00
}
2000-12-04 17:47:34 +01:00
2001-02-09 22:17:01 +01:00
/*****************************************************************************/
void CCore::RedrawView()
{
2001-02-14 23:35:47 +01:00
if (CurrentView) CurrentView->Invalidate();
2001-02-09 22:17:01 +01:00
}
2000-12-29 23:20:38 +01:00
2001-02-09 22:17:01 +01:00
/*****************************************************************************/
void CCore::UpdateView(Vector3 *Ofs)
{
if (Ofs)
{
Vector3 &ThisCam=GetCam();
ThisCam.x+=Ofs->x;
ThisCam.y+=Ofs->y;
ThisCam.z-=Ofs->z;
if (!TileViewFlag)
{
if (ThisCam.x<0) ThisCam.x=0;
if (ThisCam.y<0) ThisCam.y=0;
}
if (ThisCam.z<0.1) ThisCam.z=0.1f;
}
SetScale();
RedrawView();
2000-12-04 17:47:34 +01:00
}
2000-11-21 22:27:55 +01:00
2000-11-20 17:21:43 +01:00
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::SetMapSize(int Width,int Height)
2000-11-20 17:21:43 +01:00
{
2001-02-09 22:17:01 +01:00
if (Width==GetMapWidth() && Height==GetMapHeight()) return;
2000-11-20 17:21:43 +01:00
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
2001-02-09 22:17:01 +01:00
for (int i=0; i<ListSize; i++)
{
Layer[i]->Resize(Width,Height);
}
2000-11-20 17:21:43 +01:00
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-22 23:08:47 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CCore::Toggle2d3d()
2000-11-22 23:08:47 +01:00
{
Is3dFlag=!Is3dFlag;
2001-02-14 23:35:47 +01:00
RedrawView();
2000-11-28 00:07:07 +01:00
}
2000-11-28 22:16:00 +01:00
/*****************************************************************************/
int CCore::FindLayer(int Type,int SubType)
{
int ListSize=Layer.size();
for (int i=0; i<ListSize; i++)
{
if (Layer[i]->GetType()==Type)
if (SubType==-1 || Layer[i]->GetSubType()==SubType)
return(i);
}
return(-1);
}
2000-11-28 00:07:07 +01:00
/*****************************************************************************/
2000-11-24 23:34:20 +01:00
2000-12-04 17:47:34 +01:00
Vector3 CCore::OffsetCam(Vector3 &Cam,float DivVal)
2000-11-28 00:07:07 +01:00
{
2000-12-29 23:20:38 +01:00
Vector3 ThisCam=Cam;
2000-11-28 00:07:07 +01:00
ThisCam=Cam/DivVal;
ThisCam.z=Cam.z;
return(ThisCam);
2000-11-22 23:08:47 +01:00
}
2000-11-24 23:34:20 +01:00
/*****************************************************************************/
2001-02-01 23:48:22 +01:00
void CCore::Export(char *Filename)
2000-11-28 00:07:07 +01:00
{
2000-11-30 23:17:55 +01:00
int LayerCount=Layer.size();
char ExportName[256];
2001-02-01 23:48:22 +01:00
SetFileExt(Filename,ExportName,"MEX");
2000-11-30 23:17:55 +01:00
2001-02-07 22:31:31 +01:00
CExport Exp(ExportName);
2000-11-30 23:17:55 +01:00
2000-12-11 22:29:59 +01:00
for (int i=0;i<LayerCount;i++)
2000-11-30 23:17:55 +01:00
{
2001-02-07 22:31:31 +01:00
if (Layer[i]->CanExport())
{
Layer[i]->Export(this,Exp);
}
2000-11-30 23:17:55 +01:00
}
2000-12-11 22:29:59 +01:00
2000-11-30 23:17:55 +01:00
Exp.ExportTiles(this);
2001-02-06 23:25:39 +01:00
Exp.ExportStrList(this);
2000-12-01 22:08:54 +01:00
2000-12-04 17:47:34 +01:00
}