SBSPSS/Utils/MapEdit/Core.cpp

854 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-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"
2000-11-21 22:27:55 +01:00
#include "utils.h"
2000-11-24 23:34:20 +01:00
#include "ExportAGB.h"
2000-11-30 23:17:55 +01:00
#include "ExportPSX.h"
2000-11-24 23:34:20 +01:00
2000-10-27 02:06:19 +02:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CCore::CCore()
{
2001-01-23 22:53:48 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CMultiBar *ParamBar=Frm->GetParamBar();
2000-11-28 22:16:00 +01:00
CurrentMousePos=CPoint(0,0);
2001-01-23 22:53:48 +01:00
// Add default param bar items
ParamBar->RemoveAll();
ParamBar->Add(Frm->GetLayerList(),IDD_LAYER_LIST_DIALOG,TRUE,TRUE);
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-11-15 22:22:40 +01:00
/*****************************************************************************/
void CCore::Init()
{
2000-11-17 00:08:54 +01:00
UpdateParamBar();
2001-01-23 22:53:48 +01:00
// UpdateAll(NULL);
2000-11-15 22:22:40 +01: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-01-23 22:53:48 +01:00
AddLayer(LAYER_TYPE_TILE,LAYERTILE_ACTION, Width, Height);
// AddLayer(LAYER_TYPE_COLLISION,-1, Width, Height);
2000-11-28 22:16:00 +01:00
ActiveLayer=FindActionLayer();
2000-12-04 17:47:34 +01:00
MapCam.Zero();
TileCam.Zero();
2000-11-28 22:16:00 +01:00
TileViewFlag=FALSE;
GridFlag=TRUE;
Is3dFlag=TRUE;
Init();
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;
}
}
2000-11-28 22:16:00 +01:00
TileBank.Load(File,Version);
2000-11-30 23:17:55 +01:00
// Check Layers
int MapWidth=Layer[FindActionLayer()]->GetWidth();
int MapHeight=Layer[FindActionLayer()]->GetHeight();
for (i=0;i<LayerCount;i++)
{
Layer[i]->CheckLayerSize(MapWidth,MapHeight);
}
2000-11-28 22:16:00 +01:00
Init();
2001-01-23 22:53:48 +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
{
return(theApp.GetCurrent()->Question(Txt));
}
2000-09-22 23:19:46 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
void CCore::Render(CMapEditView *View,BOOL ForceRender)
2000-09-22 23:19:46 +02:00
{
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)
{
RenderTileView(View);
}
else
{
RenderLayers(View);
}
}
2000-11-10 17:17:00 +01:00
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
void CCore::RenderLayers(CMapEditView *View)
{
2000-12-04 17:47:34 +01:00
Vector3 &ThisCam=GetCam();
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
2000-11-28 00:07:07 +01:00
2000-11-20 21:33:42 +01:00
for (int i=0;i<ListSize;i++)
2000-10-31 23:37:59 +01:00
{
2000-11-28 00:14:42 +01:00
if (Layer[i]->IsVisible())
{
Layer[i]->Render(this,ThisCam,Is3dFlag);
if (GridFlag) Layer[i]->RenderGrid(this,ThisCam,i==ActiveLayer);
}
2000-11-02 16:46:17 +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;
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->FindCursorPos(this,View,GetCam(),CurrentMousePos);
2000-11-14 16:03:04 +01:00
}
2000-11-03 23:40:41 +01:00
2000-11-21 22:27:55 +01:00
/////////////////////////////////////////////////////////////////////////////
2000-11-14 16:03:04 +01:00
void CCore::RenderTileView(CMapEditView *View)
{
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);
GetTileBank().FindCursorPos(this,View,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
/*****************************************************************************/
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-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())
{
RedrawFlag=Layer[ActiveLayer]->LButtonControl(this,View,nFlags,CursorPos,DownFlag);
}
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
if (RedrawFlag) View->Invalidate();
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-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-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())
{
RedrawFlag=Layer[ActiveLayer]->RButtonControl(this,View,nFlags,CursorPos,DownFlag);
}
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
2000-11-15 22:22:40 +01:00
if (RedrawFlag) View->Invalidate();
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-12-11 22:52:32 +01:00
void CCore::Zoom(CMapEditView *View,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;
2000-12-04 17:47:34 +01:00
UpdateView(View,Ofs);
2000-09-22 23:19:46 +02:00
}
2000-12-11 22:52:32 +01:00
/*****************************************************************************/
void CCore::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt)
{
if (zDelta>0)
2000-12-29 23:20:38 +01:00
Zoom(View,-0.1f);
2001-01-03 23:11:13 +01:00
else
Zoom(View,+0.1f);
2000-12-11 22:52:32 +01:00
}
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-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();
2000-11-06 21:24:11 +01:00
if (theApp.GetCurrent()!=View->GetDocument()) return;
2000-09-22 23:19:46 +02:00
2000-12-11 23:42:19 +01:00
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;
}
2000-11-06 21:24:11 +01:00
View->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;
2000-12-29 23:20:38 +01:00
UpdateView(View,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())
{
Layer[ActiveLayer]->MouseMove(this,View,nFlags,CursorPos);
}
2000-11-17 22:36:13 +01:00
}
2000-12-01 22:33:02 +01:00
View->Invalidate(); // Mouse still moved, so need to redraw windows, to get CursorPos (And pos render)
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
{
2000-11-02 16:46:17 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-11-10 17:17:00 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-11-17 00:08:54 +01:00
ParamBar->RemoveAll();
2000-11-28 15:34:42 +01:00
Layer[ActiveLayer]->InitGUI(this);
Layer[ActiveLayer]->UpdateGUI(this);
2000-11-17 00:08:54 +01:00
ParamBar->Update();
2000-09-22 17:11:29 +02:00
}
2000-11-21 22:27:55 +01:00
/*****************************************************************************/
void CCore::UpdateLayerGUI(CMapEditView *View)
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CMultiBar *ParamBar=Frm->GetParamBar();
CLayerList *List=(CLayerList*)Frm->GetDialog(IDD_LAYER_LIST_DIALOG);
int ListSize=Layer.size();
List->ListBox.ResetContent();
for (int i=0; i<ListSize; i++)
{
List->ListBox.AddString(Layer[i]->GetName());
}
// Now sets checks (silly MSoft bug!!)
for (i=0; i<ListSize; i++)
{
List->ListBox.SetCheck(i,Layer[i]->IsVisible());
}
2000-11-28 00:07:07 +01:00
List->ListBox.SetCurSel(ActiveLayer);
2000-11-21 22:27:55 +01:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
2000-11-28 00:14:42 +01:00
void CCore::SetLayer(int NewLayer)
2000-11-06 21:24:11 +01:00
{
2000-11-28 00:14:42 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CMultiBar *ParamBar=Frm->GetParamBar();
CLayerList *List=(CLayerList*)Frm->GetDialog(IDD_LAYER_LIST_DIALOG);
2001-01-21 19:04:00 +01:00
if (NewLayer<0) NewLayer=0;
2000-12-01 22:33:02 +01:00
// If toggling layer, dont change the layer
2000-12-29 23:20:38 +01:00
if ((int)List->ListBox.GetCheck(NewLayer)!=(int)Layer[NewLayer]->IsVisible())
2000-12-01 22:33:02 +01:00
{
Layer[NewLayer]->SetVisible(List->ListBox.GetCheck(NewLayer));
List->ListBox.SetCurSel(ActiveLayer);
}
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-01-23 22:53:48 +01:00
UpdateParamBar();
2000-11-28 00:14:42 +01:00
}
2000-11-06 21:24:11 +01:00
}
2000-11-28 00:07:07 +01:00
2001-01-23 22:53:48 +01:00
/*****************************************************************************/
CLayer *CCore::AddLayer(CLayer *NewLayer)
{
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);
return(NewLayer);
}
/*****************************************************************************/
void CCore::AddLayer(int Type, int SubType, int Width, int Height)
{
CLayer *Layer;
switch (Type)
{
case LAYER_TYPE_TILE:
Layer=AddLayer(new CLayerTile(SubType, Width,Height));
break;
case LAYER_TYPE_COLLISION:
Layer=AddLayer(new CLayerCollision(SubType, Width,Height));
break;
default:
ASSERT(!"AddLayer - Invalid Layer Type");
break;
}
}
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-01-23 22:53:48 +01:00
int Width=Layer[FindActionLayer()]->GetWidth();
int Height=Layer[FindActionLayer()]->GetHeight();
2001-01-21 19:04:00 +01:00
2001-01-23 22:53:48 +01:00
AddLayer(CLayer::InfoTable[NewLayerId].Type,CLayer::InfoTable[NewLayerId].SubType,Width,Height);
2001-01-21 19:04:00 +01:00
}
/*****************************************************************************/
void CCore::DeleteLayer(int CurrentLayer)
{
if (Layer[CurrentLayer]->CanDelete())
{
delete Layer[CurrentLayer];
Layer.erase(Layer.begin() + CurrentLayer);
SetLayer(CurrentLayer-1);
UpdateAll(NULL);
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 ********************************************************************/
/*****************************************************************************/
void CCore::UpdateGrid(CMapEditView *View,BOOL Toggle)
2000-09-22 17:11:29 +02:00
{
2001-01-23 22:53:48 +01:00
//CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
//CToolBar *ToolBar=Frm->GetToolBar();
2000-09-22 17:11:29 +02:00
2000-11-14 16:03:04 +01:00
if (Toggle) GridFlag=!GridFlag;
2001-01-23 22:53:48 +01:00
// ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_GRID,GridFlag);
2000-11-14 16:03:04 +01:00
UpdateView(View);
}
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-14 16:03:04 +01:00
void CCore::UpdateTileView(CMapEditView *View,BOOL Toggle)
2000-10-31 23:37:59 +01:00
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CToolBar *ToolBar=Frm->GetToolBar();
2000-11-15 22:22:40 +01:00
CMultiBar *ParamBar=Frm->GetParamBar();
2000-10-31 23:37:59 +01:00
2000-11-15 22:22:40 +01:00
if (Toggle) TileViewFlag=!TileViewFlag;
ParamBar->RemoveAll();
2000-10-31 23:37:59 +01:00
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_TILEPALETTE,TileViewFlag);
2000-11-17 00:08:54 +01:00
UpdateParamBar();
2000-11-06 21:24:11 +01:00
UpdateView(View);
2000-10-31 23:37:59 +01:00
}
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
void CCore::TileBankLoad(char *Filename)
{
TileBank.AddTileSet(Filename);
TileBank.UpdateGUI(this,TileViewFlag);
UpdateView(NULL);
}
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);
}
}
UpdateView(NULL);
}
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();
UpdateView(NULL);
}
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
{
2000-11-28 15:34:42 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CLayerTileGUI *Dlg=(CLayerTileGUI*)Frm->GetDialog(IDD_LAYERTILE_GUI);
2000-11-14 16:03:04 +01:00
2000-11-28 15:34:42 +01:00
TileBank.SetCurrent(Dlg->m_List.GetCurSel());
2000-10-31 23:37:59 +01:00
}
2000-11-06 21:24:11 +01:00
2000-11-17 00:08:54 +01:00
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
void CCore::MirrorX(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2000-11-20 17:21:43 +01:00
if (!TileViewFlag)
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->MirrorX(this);
2000-11-20 17:21:43 +01:00
UpdateView(View);
}
}
/*****************************************************************************/
void CCore::MirrorY(CMapEditView *View)
{
if (!TileViewFlag)
{
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->MirrorY(this);
2000-11-20 17:21:43 +01:00
UpdateView(View);
}
2000-11-17 00:08:54 +01:00
}
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
void CCore::ActiveBrushLeft(CMapEditView *View)
2000-11-17 00:08:54 +01:00
{
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushL();
2000-11-20 17:21:43 +01:00
UpdateView(View);
}
/*****************************************************************************/
void CCore::ActiveBrushRight(CMapEditView *View)
{
2001-01-23 22:53:48 +01:00
GetTileBank().SetActiveBrushR();
2000-11-20 17:21:43 +01:00
UpdateView(View);
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-01-02 15:34:02 +01:00
/*****************************************************************************/
void CCore::CopySelection(CMapEditView *View)
{
Layer[ActiveLayer]->CopySelection(this);
UpdateView(View);
}
/*****************************************************************************/
void CCore::PasteSelection(CMapEditView *View)
{
Layer[ActiveLayer]->PasteSelection(this);
UpdateView(View);
}
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;
ScaleVector.z=1.0f/XS;//4.0f;
}
/*****************************************************************************/
float CCore::GetZoomW()
{
Vector3 &ThisCam=GetCam();
return((float)SCREEN_MAP_WIDTH/ThisCam.z);
}
/*****************************************************************************/
float CCore::GetZoomH()
{
Vector3 &ThisCam=GetCam();
return((float)SCREEN_MAP_HEIGHT/ThisCam.z);
2000-11-28 00:07:07 +01:00
}
2000-10-31 23:37:59 +01:00
/*****************************************************************************/
2000-11-21 22:27:55 +01:00
void CCore::UpdateGUI(CMapEditView *View)
2000-11-02 16:46:17 +01:00
{
2000-11-21 22:27:55 +01:00
UpdateLayerGUI(View);
2000-11-14 16:03:04 +01:00
UpdateGrid(View);
2000-11-20 21:33:42 +01:00
Layer[ActiveLayer]->UpdateGUI(this);
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-21 22:27:55 +01:00
/*****************************************************************************/
void CCore::UpdateAll(CMapEditView *View)
{
UpdateGUI(View);
UpdateView(View);
}
2000-11-03 23:40:41 +01:00
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
void CCore::UpdateView(CMapEditView *View)
2000-11-03 23:40:41 +01:00
{
2000-12-29 23:20:38 +01:00
SetScale();
2000-11-14 16:03:04 +01:00
if (View) View->Invalidate();
2000-11-03 23:40:41 +01:00
}
2000-11-20 17:21:43 +01:00
2000-12-04 17:47:34 +01:00
/*****************************************************************************/
void CCore::UpdateView(CMapEditView *View,Vector3 &Ofs)
{
Vector3 &ThisCam=GetCam();
ThisCam.x+=Ofs.x;
2000-12-29 23:20:38 +01:00
ThisCam.y+=Ofs.y;
ThisCam.z-=Ofs.z;
2001-01-03 23:11:13 +01:00
if (!TileViewFlag)
{
if (ThisCam.x<0) ThisCam.x=0;
if (ThisCam.y<0) ThisCam.y=0;
}
2000-12-29 23:20:38 +01:00
if (ThisCam.z<0.1) ThisCam.z=0.1f;
2001-01-23 22:53:48 +01:00
// TRACE1("ZoomVal %f\n",ThisCam.z);
2000-12-29 23:20:38 +01:00
2000-12-04 17:47:34 +01:00
UpdateView(View);
}
2000-11-21 22:27:55 +01:00
2000-11-20 17:21:43 +01:00
/*****************************************************************************/
void CCore::SetMapSize(CMapEditView *View,int Width,int Height)
{
if (Width==GetMapWidth() && Height==GetMapHeight()) return;
2000-11-20 21:33:42 +01:00
int ListSize=Layer.size();
for (int i=0; i<ListSize; i++)
2000-11-20 17:21:43 +01:00
{
2000-11-20 21:33:42 +01:00
Layer[i]->Resize(Width,Height);
2000-11-20 17:21:43 +01:00
}
UpdateView(View);
2000-11-22 23:08:47 +01:00
}
/*****************************************************************************/
void CCore::Toggle2d3d(CMapEditView *View)
{
Is3dFlag=!Is3dFlag;
UpdateView(View);
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);
}
/*****************************************************************************/
int CCore::FindActionLayer()
{
2000-12-06 20:29:40 +01:00
int Idx=FindLayer(LAYER_TYPE_TILE,LAYERTILE_ACTION);
2000-11-28 22:16:00 +01:00
return(Idx);
}
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
/*****************************************************************************/
2000-11-28 00:07:07 +01:00
void CCore::ExportAGB(char *Filename)
2000-11-24 23:34:20 +01:00
{
int LayerCount=Layer.size();
2000-11-28 00:07:07 +01:00
char ExportName[256];
2000-11-29 18:07:57 +01:00
SetFileExt(Filename,ExportName,"c");
2000-11-28 00:07:07 +01:00
CExportAGB Exp(ExportName);
2000-11-24 23:34:20 +01:00
for (int i=0;i<LayerCount;i++)
{
2000-11-29 18:07:57 +01:00
Layer[i]->Export(this,Exp);
2000-11-24 23:34:20 +01:00
}
2000-11-30 23:17:55 +01:00
Exp.ExportTiles(this);
Exp.ExportPalette();
2000-11-28 00:07:07 +01:00
}
/*****************************************************************************/
void CCore::ExportPSX(char *Filename)
{
2000-11-30 23:17:55 +01:00
int LayerCount=Layer.size();
char ExportName[256];
SetFileExt(Filename,ExportName,"PME");
2000-12-06 20:29:40 +01:00
CExportPSX Exp(ExportName,LayerCount);
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
{
Layer[i]->Export(this,Exp);
}
2000-12-11 22:29:59 +01:00
2000-11-30 23:17:55 +01:00
Exp.ExportTiles(this);
2000-12-01 22:08:54 +01:00
Exp.ExportTexList(this);
2000-12-04 17:47:34 +01:00
}
/*****************************************************************************/
GString CCore::GetCurrentPath()
{
GFName FullPath=theApp.GetCurrent()->GetPathName();
GString Path=FullPath.Dir();
return(Path);
}
2000-12-11 22:52:32 +01:00