SBSPSS/Utils/MapEdit/Core.cpp

729 lines
17 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 "gl3d.h"
#include <Vector3.h>
2000-09-22 23:19:46 +02:00
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include "GLEnabledView.h"
2000-10-25 20:28:44 +02:00
#include "MapEdit.h"
2000-09-22 23:19:46 +02:00
#include "MapEditDoc.h"
#include "MapEditView.h"
2000-10-31 23:37:59 +01:00
#include "MainFrm.h"
2000-09-22 23:19:46 +02:00
2000-11-28 22:16:00 +01:00
#include "NewMapGUI.h"
2000-09-22 17:11:29 +02:00
#include "Core.h"
2000-09-25 17:43:52 +02:00
#include "Layer.h"
2000-11-07 21:38:19 +01:00
#include "LayerTile.h"
2000-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()
{
2000-11-28 22:16:00 +01:00
CurrentMousePos=CPoint(0,0);
2000-09-22 17:11:29 +02:00
}
2000-09-25 17:43:52 +02:00
2000-09-22 17:11:29 +02:00
/*****************************************************************************/
CCore::~CCore()
{
2000-11-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()
{
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CMultiBar *ParamBar=Frm->GetParamBar();
ParamBar->RemoveAll();
2000-11-28 22:16:00 +01:00
// Add default param bar items
2000-11-15 22:22:40 +01:00
ParamBar->Add(Frm->GetLayerList(),IDD_LAYER_LIST_DIALOG,TRUE,TRUE);
2000-11-17 00:08:54 +01:00
UpdateParamBar();
2000-11-20 21:33:42 +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
Dlg.m_Back=TRUE;
Dlg.m_Mid=TRUE;
Dlg.m_Fore=FALSE;
if (Dlg.DoModal()!=IDOK) return FALSE;
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
// Type Width Height Scale 3d? Resizable?
2000-12-06 20:29:40 +01:00
if (Dlg.m_Back) Layer.push_back(new CLayerTile( LAYERTILE_BACK, 32, 32, 4.0f, FALSE, FALSE));
if (Dlg.m_Mid) Layer.push_back(new CLayerTile( LAYERTILE_MID, Width, Height, 2.0f, FALSE, TRUE));
Layer.push_back(new CLayerTile( LAYERTILE_ACTION, Width, Height, 1.0f, TRUE, TRUE));
if (Dlg.m_Fore) Layer.push_back(new CLayerTile( LAYERTILE_FORE, Width, Height, 0.5f, FALSE, TRUE));
2000-11-28 22:16:00 +01:00
2000-12-04 17:47:34 +01:00
Vector3 CamOfs;
CamOfs.Zero();
CamOfs.x=-15;
2000-12-11 22:29:59 +01:00
CamOfs.y=+10;
2000-12-04 17:47:34 +01:00
2000-11-28 22:16:00 +01:00
ActiveLayer=FindActionLayer();
2000-12-04 17:47:34 +01:00
MapCam.Zero();
MapCamOfs=CamOfs;
TileCam.Zero();
TileCamOfs=CamOfs;
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-28 22:16:00 +01:00
2000-11-20 21:33:42 +01:00
void CCore::Load(CFile *File)
{
float Version;
File->Read(&Version,sizeof(float));
2000-11-28 22:16:00 +01:00
TRACE1("Load Version %g\n",Version);
2000-11-20 21:33:42 +01:00
2000-11-28 22:16:00 +01:00
if (Version>=1.0)
{
2000-12-04 17:47:34 +01:00
File->Read(&MapCam,sizeof(Vector3));
File->Read(&MapCamOfs,sizeof(Vector3));
File->Read(&TileCam,sizeof(Vector3));
File->Read(&TileCamOfs,sizeof(Vector3));
2000-11-28 22:16:00 +01:00
File->Read(&TileViewFlag,sizeof(BOOL));
File->Read(&GridFlag,sizeof(BOOL));
File->Read(&Is3dFlag,sizeof(BOOL));
}
if (Version>=1.1)
{
2000-11-20 21:33:42 +01:00
2000-11-28 22:16:00 +01:00
}
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:
Layer.push_back(new CLayerTile(File,Version));
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();
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
2000-11-20 21:33:42 +01:00
File->Write(&FileVersion,sizeof(float));
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
/*****************************************************************************/
bool CCore::Question(char *Txt)
{
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
TileBank.RenderSet(this,ThisCam,Is3dFlag);
2000-11-21 22:27:55 +01:00
2000-11-14 16:03:04 +01:00
// Get Cursor Pos
TileBank.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-12-01 22:33:02 +01:00
2000-11-20 21:33:42 +01:00
RedrawFlag=Layer[ActiveLayer]->SetMode(NewMode);
2000-12-01 22:33:02 +01:00
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)
RedrawFlag=TileBank.SelectCancel();
else
RedrawFlag=TileBank.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
}
2000-11-17 22:36:13 +01:00
TileBank.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-10-25 23:00:54 +02:00
LastMousePos=point;
2000-09-22 23:19:46 +02:00
}
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CCore::RButtonControl(CMapEditView *View,UINT nFlags, CPoint &point,BOOL DownFlag)
2000-09-22 23:19:46 +02:00
{
2000-11-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)
RedrawFlag=TileBank.SelectCancel();
else
RedrawFlag=TileBank.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
}
2000-11-17 22:36:13 +01:00
TileBank.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-11-06 21:24:11 +01:00
void CCore::MouseWheel(CMapEditView *View,UINT nFlags, short zDelta, CPoint &pt)
2000-09-22 23:19:46 +02:00
{
2000-12-04 17:47:34 +01:00
Vector3 Ofs;
Ofs.Zero();
2000-10-25 20:28:44 +02:00
if (zDelta>0)
2000-12-04 17:47:34 +01:00
Ofs.z=+1.0f;
2000-10-25 20:28:44 +02:00
else
2000-12-04 17:47:34 +01:00
Ofs.z=-1.0f;
UpdateView(View,Ofs);
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-10-25 20:28:44 +02:00
CurrentMousePos=point;
2000-10-25 23:00:54 +02:00
// Handle Drag Movement
if (nFlags & MK_MBUTTON)
2000-09-22 23:19:46 +02:00
{
float XS,YS;
RECT ThisRect;
2000-11-06 21:24:11 +01:00
View->GetWindowRect(&ThisRect);
2000-11-20 21:33:42 +01:00
XS=ThisCam.z*4;//*Layer[ActiveLayer]->GetLayerZPos();
YS=ThisCam.z*4;//*Layer[ActiveLayer]->GetLayerZPos();
2000-10-25 23:00:54 +02:00
XS/=((ThisRect.right-ThisRect.left));
YS/=((ThisRect.bottom-ThisRect.top));
2000-09-22 23:19:46 +02:00
2000-11-02 16:46:17 +01:00
Ofs.x=LastMousePos.x-CurrentMousePos.x;
Ofs.y=LastMousePos.y-CurrentMousePos.y;
2000-09-25 17:43:52 +02:00
LastMousePos=CurrentMousePos;
2000-09-22 23:19:46 +02:00
2000-11-02 16:46:17 +01:00
Ofs.x*=XS;
Ofs.y*=YS;
2000-12-11 22:29:59 +01:00
if (nFlags & MK_CONTROL)
2000-11-28 00:07:07 +01:00
{ // Move Ofs
2000-12-04 17:47:34 +01:00
Vector3 &CamOfs=GetCamOfs();
2000-11-28 00:07:07 +01:00
Ofs.y=-Ofs.y;
CamOfs+=Ofs;
UpdateView(View);
}
else
2000-12-11 22:29:59 +01:00
{
2000-11-28 00:07:07 +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-10-25 20:28:44 +02:00
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);
2000-12-01 22:33:02 +01:00
// If toggling layer, dont change the layer
if (List->ListBox.GetCheck(NewLayer)!=Layer[NewLayer]->IsVisible())
{
Layer[NewLayer]->SetVisible(List->ListBox.GetCheck(NewLayer));
List->ListBox.SetCurSel(ActiveLayer);
}
else
2000-11-28 00:14:42 +01:00
{
ActiveLayer=NewLayer;
}
2000-11-06 21:24:11 +01:00
}
2000-11-28 00:07:07 +01:00
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
{
2000-11-14 16:03:04 +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;
ToolBar->GetToolBarCtrl().PressButton(ID_TOOLBAR_GRID,GridFlag);
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
{
2000-11-20 17:21:43 +01:00
TileBank.SetActiveBrushL();
UpdateView(View);
}
/*****************************************************************************/
void CCore::ActiveBrushRight(CMapEditView *View)
{
TileBank.SetActiveBrushR();
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));
}
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-04 17:47:34 +01:00
Vector3 &CCore::GetCamOfs()
2000-11-28 00:07:07 +01:00
{
if (TileViewFlag)
return(TileCamOfs);
else
return(MapCamOfs);
}
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-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;
ThisCam.y-=Ofs.y;
ThisCam.z+=Ofs.z;
if (ThisCam.z>-1) ThisCam.z=-1;
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-30 23:17:55 +01:00
// ExportPSX("c:/temp/test.pme");
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-04 17:47:34 +01:00
Vector3 ThisCam;
2000-11-28 00:07:07 +01:00
ThisCam=Cam/DivVal;
ThisCam.z=Cam.z;
ThisCam+=GetCamOfs();
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
// Layer[FindActionLayer()]->Export(this,Exp);
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);
}