SBSPSS/Utils/MapEdit/Core.cpp

856 lines
20 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-09-22 17:11:29 +02:00
#include "Core.h"
2001-03-22 21:49:58 +01:00
#include "Elem.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"
2001-03-22 21:49:58 +01:00
#include "LayerThing.h"
2001-03-26 23:29:09 +02:00
#include "LayerActor.h"
#include "LayerItem.h"
#include "LayerPlatform.h"
2000-11-21 22:27:55 +01:00
#include "utils.h"
2001-02-01 23:48:22 +01:00
#include "Export.h"
2001-03-13 22:00:34 +01:00
#include "GUILayerList.h"
#include "GUIAddLayer.h"
#include "GUINewMap.h"
2001-02-09 22:17:01 +01:00
2001-03-26 23:29:09 +02:00
#include <IniClass.h>
2001-02-16 19:23:01 +01:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CCore::CCore()
{
2000-11-28 22:16:00 +01:00
CurrentMousePos=CPoint(0,0);
2001-03-01 18:28:20 +01:00
MapCam=DefaultCamPos;
SpareFlag=false;
GridFlag=true;
Is3dFlag=true;
2001-02-14 23:35:47 +01:00
CurrentView=NULL;
2001-04-05 16:20:56 +02:00
CursorPos.x=CursorPos.y=-1;
2001-03-05 21:49:46 +01:00
CurrentLayer=0;
2001-03-22 21:49:58 +01:00
GString Filename;
IconBank=new CElemBank(16,16,false,false);
GetExecPath(Filename);
2001-03-29 19:59:01 +02:00
Filename+=theApp.GetConfigStr("FileLocation","Iconz");
2001-03-22 21:49:58 +01:00
IconBank->AddSet(Filename);
2001-04-05 16:20:56 +02:00
RenderTGAFlag=false;
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()
{
2001-03-22 21:49:58 +01:00
IconBank->CleanUp();
delete IconBank;
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
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CCore::New()
2000-09-22 23:19:46 +02:00
{
2001-03-13 22:00:34 +01:00
CGUINewMap Dlg;
2000-11-28 22:16:00 +01:00
int Width,Height;
2001-03-29 19:59:01 +02:00
Dlg.m_Width=TileLayerMinWidth+2;
Dlg.m_Height=TileLayerMinHeight+2;
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);
2001-03-31 03:30:53 +02:00
#ifdef _DEBUG
2001-04-30 23:49:54 +02:00
// AddLayer(LAYER_TYPE_SHADE,LAYER_SUBTYPE_NONE, Width, Height);
2001-05-01 18:54:13 +02:00
// AddLayer(LAYER_TYPE_TRIGGER,LAYER_SUBTYPE_NONE, Width, Height);
2001-05-05 23:18:12 +02:00
// AddLayer(LAYER_TYPE_PLATFORM,LAYER_SUBTYPE_NONE, Width, Height);
AddLayer(LAYER_TYPE_HAZARD,LAYER_SUBTYPE_NONE, Width, Height);
2001-04-28 01:05:14 +02:00
// AddLayer(LAYER_TYPE_FX,LAYER_SUBTYPE_NONE, Width, Height);
// AddLayer(LAYER_TYPE_ACTOR,LAYER_SUBTYPE_NONE, Width, Height);
2001-04-07 23:05:33 +02:00
// AddLayer(LAYER_TYPE_ITEM,LAYER_SUBTYPE_NONE, Width, Height);
2001-03-31 03:30:53 +02:00
#endif
2001-04-30 23:49:54 +02:00
2001-03-01 18:28:20 +01:00
for (int i=0; i<Layer.size(); i++)
{
Layer[i]->InitSubView(this);
}
2001-02-14 23:35:47 +01:00
ActiveLayer=FindLayer(LAYER_TYPE_TILE,LAYER_SUBTYPE_ACTION);
2001-03-31 03:30:53 +02:00
#ifdef _DEBUG
2001-05-05 23:18:12 +02:00
ActiveLayer=FindLayer(LAYER_TYPE_HAZARD,LAYER_SUBTYPE_NONE);
2001-04-07 23:05:33 +02:00
if (ActiveLayer<0) ActiveLayer=0;
2001-03-31 03:30:53 +02:00
#endif
2001-03-01 18:28:20 +01:00
CurrentLayer=Layer[ActiveLayer];
2000-11-28 22:16:00 +01:00
return(TRUE);
2000-11-06 21:24:11 +01:00
}
/*****************************************************************************/
2000-11-20 21:33:42 +01:00
void CCore::Load(CFile *File)
{
2001-03-01 18:28:20 +01:00
int Version,i;
BOOL F;
2001-03-05 21:49:46 +01:00
Vector3 DuffVector;
2001-04-05 16:20:56 +02: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
2001-03-05 21:49:46 +01:00
#ifndef _DEBUG
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-28 22:16:00 +01:00
}
2001-03-05 21:49:46 +01:00
#endif
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));
2001-03-22 21:49:58 +01:00
if (Version<4)
2001-03-05 21:49:46 +01:00
{
File->Read(&MapCamOfs,sizeof(Vector3));
File->Read(&DuffVector,sizeof(Vector3));
File->Read(&DuffVector,sizeof(Vector3));
}
2001-01-23 22:53:48 +01:00
2001-03-01 18:28:20 +01:00
File->Read(&F,sizeof(BOOL)); SpareFlag=F!=0;
File->Read(&F,sizeof(BOOL)); GridFlag=F!=0;
File->Read(&F,sizeof(BOOL)); Is3dFlag=F!=0;
2000-11-20 21:33:42 +01:00
// Layers
int LayerCount;
File->Read(&LayerCount,sizeof(int));
File->Read(&ActiveLayer,sizeof(int));
2001-03-01 18:28:20 +01:00
for (i=0;i<LayerCount;i++)
2000-11-20 21:33:42 +01:00
{
2001-03-26 23:29:09 +02:00
CLayer *Lyr=CLayer::LoadLayer(File,Version);
TRACE1("Loaded %s\n",Lyr->GetName());
AddLayer(Lyr);
2000-11-20 21:33:42 +01:00
}
2000-11-30 23:17:55 +01:00
2001-03-01 18:28:20 +01:00
for (i=0; i<Layer.size(); i++)
{
Layer[i]->InitSubView(this);
}
GetTileBank()->Load(File,Version);
CurrentLayer=Layer[ActiveLayer];
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-04-07 23:05:33 +02:00
2000-11-20 21:33:42 +01:00
}
2001-04-05 16:20:56 +02:00
2001-03-26 23:29:09 +02:00
/*****************************************************************************/
void CCore::Validate(int Type)
{
int LayerCount=Layer.size();
for (int i=0;i<LayerCount;i++)
{
if (Layer[i]->GetType()==Type)
Layer[i]->Validate(this);
}
}
2000-11-20 21:33:42 +01:00
/*****************************************************************************/
void CCore::Save(CFile *File)
2000-11-06 21:24:11 +01:00
{
2001-03-01 18:28:20 +01:00
BOOL F;
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));
2000-11-20 21:33:42 +01:00
2001-03-01 18:28:20 +01:00
F=SpareFlag; File->Write(&F,sizeof(BOOL));
F=GridFlag; File->Write(&F,sizeof(BOOL));
F=Is3dFlag; File->Write(&F,sizeof(BOOL));
2000-11-20 21:33:42 +01:00
// Layers
int LayerCount=Layer.size();
File->Write(&LayerCount,sizeof(int));
File->Write(&ActiveLayer,sizeof(int));
for (int i=0;i<LayerCount;i++)
{
2001-03-26 23:29:09 +02:00
Layer[i]->CLayer::Save(File);
2000-11-20 21:33:42 +01:00
Layer[i]->Save(File);
}
2001-03-01 18:28:20 +01:00
GetTileBank()->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
/*****************************************************************************/
2001-03-01 18:28:20 +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-03-01 18:28:20 +01:00
void CCore::Render(bool ForceRender)
2000-09-22 23:19:46 +02:00
{
2001-03-01 18:28:20 +01:00
Vector3 &ThisCam=GetCam();
if (!CurrentView)
2001-02-14 23:35:47 +01:00
{
TRACE0("No View\n");
UpdateAll();
return;
}
2001-03-22 21:49:58 +01:00
if (IconBank->NeedLoad()) IconBank->LoadAllSets(this);
2001-04-05 16:20:56 +02:00
if (RenderTGAFlag) RenderToTga();
2000-11-14 16:03:04 +01:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
2001-03-01 18:28:20 +01:00
2001-03-22 21:49:58 +01:00
RenderLayers(IsSubView() || CurrentLayer->IsUnique());
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-03-22 21:49:58 +01:00
void CCore::RenderLayers(bool OneShot)
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;
2001-03-27 18:26:43 +02:00
CLayer *ThisLayer;
2001-02-07 22:31:31 +01:00
2001-03-22 21:49:58 +01:00
if (OneShot)
{
StartLayer=ActiveLayer;
EndLayer=StartLayer+1;
2001-03-27 18:26:43 +02:00
ThisLayer=CurrentLayer;
2001-03-22 21:49:58 +01:00
}
else
{
2001-03-27 18:26:43 +02:00
StartLayer=0;
EndLayer=ListSize;
while (Layer[StartLayer]->IsUnique()) StartLayer++;
ThisLayer=Layer[StartLayer];
2001-03-22 21:49:58 +01:00
}
2001-02-07 22:31:31 +01:00
for (int i=StartLayer; i<EndLayer; i++)
2000-10-31 23:37:59 +01:00
{
2001-05-05 23:18:12 +02:00
ThisLayer->LoadGfx(this);
2001-03-27 18:26:43 +02:00
if (ThisLayer->IsVisible())
2001-02-07 22:31:31 +01:00
{
2001-03-27 18:26:43 +02:00
ThisLayer->Render(this,ThisCam,Is3dFlag);
if (GridFlag) ThisLayer->RenderGrid(this,ThisCam,i==ActiveLayer);
2001-02-07 22:31:31 +01:00
}
2001-03-31 03:30:53 +02:00
if (i<EndLayer-1) ThisLayer=Layer[i+1];
2001-03-27 18:26:43 +02:00
2000-11-02 16:46:17 +01:00
}
2001-03-22 21:49:58 +01:00
CurrentLayer->RenderCursor(this,ThisCam,Is3dFlag);
// Get Cursor Pos
LastCursorPos=CursorPos;
CurrentLayer->FindCursorPos(this,GetCam(),CurrentMousePos);
2001-02-07 22:31:31 +01:00
2000-09-22 23:19:46 +02:00
}
2001-03-29 19:59:01 +02:00
/*****************************************************************************/
void CCore::RenderNumber(int No)
{
int T=No/10;
int U=No%10;
glPushMatrix();
IconBank->RenderElem(0,T,0,false);
glTranslatef(0.5f,0,0);
IconBank->RenderElem(0,U,0,false);
glPopMatrix();
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
/*** Control *****************************************************************/
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CCore::LButtonControl(UINT nFlags, CPoint &point,bool DownFlag)
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
if (CurrentLayer->IsVisible())
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
CurrentLayer->LButtonControl(this,nFlags,CursorPos,DownFlag);
2000-11-15 22:22:40 +01:00
}
2001-03-01 18:28:20 +01:00
Command(CmdMsg_ActiveBrushLeft,0,0);
2000-11-15 22:22:40 +01:00
2001-03-01 18:28:20 +01:00
RedrawView();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CCore::MButtonControl(UINT nFlags, CPoint &point,bool DownFlag)
2000-09-22 23:19:46 +02:00
{
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CCore::RButtonControl(UINT nFlags, CPoint &point,bool DownFlag)
2000-09-22 23:19:46 +02:00
{
2001-03-01 18:28:20 +01:00
if (CurrentLayer->IsVisible())
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
CurrentLayer->RButtonControl(this,nFlags,CursorPos,DownFlag);
2000-11-15 22:22:40 +01:00
}
2001-03-01 18:28:20 +01:00
Command(CmdMsg_ActiveBrushRight,0,0);
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
{
2001-03-01 18:28:20 +01:00
if (CurrentLayer->IsVisible())
2000-11-17 22:36:13 +01:00
{
2001-03-01 18:28:20 +01:00
CurrentLayer->MouseMove(this,nFlags,CursorPos);
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
2001-03-01 18:28:20 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CCore::Command(int CmdMsg,int Param0,int Param1)
{
bool RedrawFlag=false;
switch(CmdMsg)
{
case CmdMsg_ToggleSubView:
ToggleSubView();
break;
case CmdMsg_ToggleGrid:
ToggleGrid();
break;
case CmdMsg_Toggle2d:
Toggle2d3d();
break;
case CmdMsg_ZoomIn:
Zoom(-0.1f);
break;
case CmdMsg_ZoomOut:
Zoom(+0.1f);
break;
case CmdMsg_ResetView:
2001-04-07 23:05:33 +02:00
SetCamPos(DefaultCamPos);
2001-03-01 18:28:20 +01:00
break;
case CmdMsg_SetLayer:
SetLayer(Param0);
break;
case CmdMsg_AddLayer:
AddLayer(Param0);
break;
case CmdMsg_DeleteLayer:
DeleteLayer(Param0);
break;
// Pass remaining to Active Layer
default:
RedrawFlag=CurrentLayer->Command(CmdMsg,this,Param0,Param1);
break;
}
2001-03-05 21:49:46 +01:00
RedrawView();
2001-03-01 18:28:20 +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-03-13 22:00:34 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *ParamBar=Frm->GetParamBar();
2000-11-10 17:17:00 +01:00
2001-02-09 22:17:01 +01:00
GUIRemoveAll();
2001-03-22 21:49:58 +01:00
GUIAdd(LayerList,IDD_LAYER_LIST);
2001-03-01 18:28:20 +01:00
CurrentLayer->GUIInit(this);
2001-02-09 22:17:01 +01:00
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-03-13 22:00:34 +01:00
if (LayerList.m_List)
2000-11-21 22:27:55 +01:00
{
2001-03-13 22:00:34 +01:00
LayerList.m_List.ResetContent();
2001-02-09 22:17:01 +01:00
for (int i=0; i<ListSize; i++)
{
2001-03-13 22:00:34 +01:00
LayerList.m_List.AddString(Layer[i]->GetName());
2001-02-09 22:17:01 +01:00
}
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++)
{
2001-03-13 22:00:34 +01:00
LayerList.m_List.SetCheck(i,Layer[i]->IsVisible());
2001-02-09 22:17:01 +01:00
}
2001-03-13 22:00:34 +01:00
LayerList.m_List.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-03-13 22:00:34 +01:00
if ((int)LayerList.m_List.GetCheck(NewLayer)!=(int)Layer[NewLayer]->IsVisible())
2000-12-01 22:33:02 +01:00
{
2001-03-13 22:00:34 +01:00
Layer[NewLayer]->SetVisible(LayerList.m_List.GetCheck(NewLayer)!=0);
LayerList.m_List.SetCurSel(ActiveLayer);
2000-12-01 22:33:02 +01:00
}
else
2000-11-28 00:14:42 +01:00
{
ActiveLayer=NewLayer;
}
2001-02-14 23:35:47 +01:00
if (LastLayer!=ActiveLayer || Force)
{
2001-03-05 21:49:46 +01:00
if (LastLayer<=LayerCount) Layer[LastLayer]->GUIKill(this);
2001-03-01 18:28:20 +01:00
CurrentLayer=Layer[ActiveLayer];
CurrentLayer->GUIInit(this);
2001-02-14 23:35:47 +01:00
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
2001-03-01 18:28:20 +01:00
if (NewLayer->GetType()==LAYER_TYPE_TILE && NewLayer->GetSubType()==LAYER_SUBTYPE_ACTION) ActionLayer=(CLayerTile*)NewLayer;
2001-02-14 23:35:47 +01:00
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-03-26 23:29:09 +02:00
CLayer *Lyr;
sLayerDef ThisDef;
ThisDef.Type=Type;
ThisDef.SubType=SubType;
ThisDef.Width=Width;
ThisDef.Height=Height;
Lyr=CLayer::NewLayer(ThisDef);
Idx=AddLayer(Lyr);
2001-03-05 21:49:46 +01:00
if (ActionLayer) Layer[Idx]->InitSubView(this);
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;
2001-03-13 22:00:34 +01:00
CGUIAddLayer Dlg;
2001-01-23 22:53:48 +01:00
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
}
/*****************************************************************************/
2001-03-05 21:49:46 +01:00
void CCore::DeleteLayer(int ThisLayer)
2001-01-21 19:04:00 +01:00
{
2001-03-05 21:49:46 +01:00
if (Layer[ThisLayer]->CanDelete())
2001-01-21 19:04:00 +01:00
{
2001-04-07 23:05:33 +02:00
Layer[ThisLayer]->GUIKill(this);
2001-03-05 21:49:46 +01:00
delete Layer[ThisLayer];
Layer.erase(Layer.begin() + ThisLayer);
2001-04-07 23:05:33 +02:00
UpdateLayerGUI();
if (ActiveLayer==ThisLayer)
{
ActiveLayer--;
if (ActiveLayer<0) ActiveLayer=0;
CurrentLayer=Layer[ActiveLayer];
CurrentLayer->GUIInit(this);
GUIUpdate();
}
2001-03-05 21:49:46 +01:00
TRACE1("Deleted Layer %i\n",ThisLayer);
2001-01-21 19:04:00 +01:00
}
else
{
2001-03-05 21:49:46 +01:00
TRACE1("Cant Delete Layer %i\n",ThisLayer);
2001-01-21 19:04:00 +01:00
}
}
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
/*** Grid ********************************************************************/
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CCore::ToggleGrid()
2000-11-29 18:07:57 +01:00
{
2001-03-01 18:28:20 +01:00
GridFlag=!GridFlag;
RedrawView();
2000-11-29 18:07:57 +01:00
}
2001-02-20 16:57:03 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
/*** SubView *****************************************************************/
2001-01-02 15:34:02 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CCore::ToggleSubView()
2001-01-02 15:34:02 +01:00
{
2001-03-01 18:28:20 +01:00
CLayer *LastLayer=CurrentLayer;
2001-01-02 15:34:02 +01:00
2001-03-01 18:28:20 +01:00
CurrentLayer=CurrentLayer->GetSubView(); // <-- Funky toggle code of what!!
if (!CurrentLayer) CurrentLayer=Layer[ActiveLayer];
if (LastLayer!=CurrentLayer)
{
LastLayer->GUIKill(this);
CurrentLayer->GUIInit(this);
GUIUpdate();
2001-03-05 21:49:46 +01:00
UpdateView();
2001-03-01 18:28:20 +01:00
}
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
{
2001-03-05 21:49:46 +01:00
if (IsSubView() || CurrentLayer->IsUnique())
{
return(CurrentLayer->GetCam());
}
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
/*****************************************************************************/
2001-04-07 23:05:33 +02:00
void CCore::SetCamPos(Vector3 Pos)
2001-02-16 19:23:01 +01:00
{
Vector3 &ThisCam=GetCam();
2001-04-07 23:05:33 +02:00
ThisCam=Pos;
UpdateView();
}
/*****************************************************************************/
void CCore::SetCamPos(CPoint &Pos)
{
Vector3 &ThisCam=GetCam();
ThisCam.x=Pos.x;
ThisCam.y=Pos.y;
2001-02-16 19:23:01 +01:00
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-03-13 22:00:34 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *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-03-13 22:00:34 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *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-03-13 22:00:34 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *ParamBar=Frm->GetParamBar();
2001-02-09 22:17:01 +01:00
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-03-13 22:00:34 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *ParamBar=Frm->GetParamBar();
2001-02-09 22:17:01 +01:00
UpdateLayerGUI();
2001-03-01 18:28:20 +01:00
CurrentLayer->GUIUpdate(this);
2001-02-09 22:17:01 +01:00
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-03-01 18:28:20 +01:00
CurrentLayer->GUIChanged(this);
2001-02-09 22:17:01 +01:00
}
/*****************************************************************************/
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)
{
2001-03-05 21:49:46 +01:00
if (!CurrentLayer) return;
2001-02-09 22:17:01 +01:00
if (Ofs)
{
Vector3 &ThisCam=GetCam();
ThisCam.x+=Ofs->x;
ThisCam.y+=Ofs->y;
ThisCam.z-=Ofs->z;
2001-03-05 21:49:46 +01:00
if (!IsSubView())
{
if (ThisCam.x<0) ThisCam.x=0;
if (ThisCam.y<0) ThisCam.y=0;
}
2001-02-09 22:17:01 +01:00
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-04-07 23:05:33 +02:00
void CCore::Export(const 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
}
2001-04-05 16:20:56 +02:00
/*****************************************************************************/
void CCore::RenderToTga(char *Filename)
{
TGAFilename=Filename;
RenderTGAFlag=true;
RedrawView();
}
/*****************************************************************************/
void CCore::RenderToTga()
{
RenderTGAFlag=false;
ActionLayer->Render4TGA(TGAFilename);
}