SBSPSS/Utils/MapEdit/LayerCollision.cpp

179 lines
4.8 KiB
C++
Raw Normal View History

2001-01-22 18:01:20 +01:00
/******************/
/*** Layer Tile ***/
/******************/
#include "stdafx.h"
#include <Vector3.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
#include "MainFrm.h"
#include "Core.h"
#include "Layer.h"
#include "LayerTile.h"
2001-01-23 22:53:48 +01:00
#include "LayerCollision.h"
2001-01-22 18:01:20 +01:00
#include "Utils.h"
#include "Select.h"
#include "Export.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// New Layer
2001-03-26 23:29:09 +02:00
//CLayerCollision::CLayerCollision(int Type,int SubType,int Width,int Height) :CLayerTile(LAYER_TYPE_COLLISION,SubType,Width,Height)
CLayerCollision::CLayerCollision(sLayerDef &Def)
2001-01-22 18:01:20 +01:00
{
2001-03-26 23:29:09 +02:00
InitLayer(Def);
2001-01-22 18:01:20 +01:00
}
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
CLayerCollision::~CLayerCollision()
2001-01-22 18:01:20 +01:00
{
2001-03-22 21:49:58 +01:00
TileBank->CleanUp();
2001-03-05 21:49:46 +01:00
delete TileBank;
}
/*****************************************************************************/
void CLayerCollision::InitSubView(CCore *Core)
{
2001-03-22 21:49:58 +01:00
GString Filename;
2001-03-05 21:49:46 +01:00
TileBank=new CTileBank;
SubView=TileBank;
2001-03-31 03:30:53 +02:00
GetExecPath(Filename);
2001-03-29 19:59:01 +02:00
Filename+=theApp.GetConfigStr("FileLocation","Collision");
2001-03-05 21:49:46 +01:00
TileBank->AddSet(Filename);
2001-01-22 18:01:20 +01:00
}
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
void CLayerCollision::Load(CFile *File,int Version)
2001-01-22 18:01:20 +01:00
{
2001-03-26 23:29:09 +02:00
if (Version<=5)
{
BOOL DB;
float DF;
LayerDef.Type=LAYER_TYPE_COLLISION;
File->Read(&DB,sizeof(BOOL));
File->Read(&DF,sizeof(float));
File->Read(&DB,sizeof(BOOL));
File->Read(&LayerDef.VisibleFlag,sizeof(BOOL));
File->Read(&Mode,sizeof(MouseMode));
File->Read(&LayerDef.SubType,sizeof(int));
}
else
{
File->Read(&Mode,sizeof(MouseMode));
}
InitLayer(LayerDef);
2001-01-23 22:53:48 +01:00
Map.Load(File,Version);
2001-01-22 18:01:20 +01:00
}
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
void CLayerCollision::Save(CFile *File)
2001-01-22 18:01:20 +01:00
{
// Always Save current version
2001-03-27 18:26:43 +02:00
File->Write(&Mode,sizeof(MouseMode));
2001-01-22 18:01:20 +01:00
Map.Save(File);
}
2001-02-20 16:57:03 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CLayerCollision::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
2001-02-20 16:57:03 +01:00
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
2001-03-05 21:49:46 +01:00
CLayerTile::Render(Core,ThisCam,Map,false,0.5f);
2001-02-20 16:57:03 +01:00
}
2001-03-01 18:28:20 +01:00
/*****************************************************************************/
2001-02-20 16:57:03 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerCollision::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
2001-02-20 16:57:03 +01:00
{
2001-03-01 18:28:20 +01:00
bool Ret=false;
switch(CmdMsg)
{
case CmdMsg_MirrorY:
// Ret=MirrorY(Core); No longer mirror Y collision tiles
break;
default:
Ret=CLayerTile::Command(CmdMsg,Core,Param0,Param1);
break;
}
return(Ret);
2001-02-20 16:57:03 +01:00
}
2001-01-22 18:01:20 +01:00
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CLayerCollision::GUIInit(CCore *Core)
2001-01-22 18:01:20 +01:00
{
2001-03-22 21:49:58 +01:00
Core->GUIAdd(GUIToolBar,IDD_TOOLBAR);
2001-03-13 22:00:34 +01:00
Core->GUIAdd(GUI,IDD_LAYER_COLLISION);
2001-02-09 22:17:01 +01:00
}
2001-01-22 18:01:20 +01:00
2001-02-09 22:17:01 +01:00
/*****************************************************************************/
void CLayerCollision::GUIKill(CCore *Core)
{
2001-03-22 21:49:58 +01:00
Core->GUIRemove(GUIToolBar,IDD_TOOLBAR);
2001-03-13 22:00:34 +01:00
Core->GUIRemove(GUI,IDD_LAYER_COLLISION);
2001-02-09 22:17:01 +01:00
}
/*****************************************************************************/
void CLayerCollision::GUIUpdate(CCore *Core)
{
CLayerTile::GUIUpdate(Core);
2001-01-22 18:01:20 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CLayerCollision::GUIChanged(CCore *Core)
2001-01-22 18:01:20 +01:00
{
2001-02-09 22:17:01 +01:00
CLayerTile::GUIChanged(Core);
2001-01-22 18:01:20 +01:00
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
void CLayerCollision::Export(CCore *Core,CExport &Exp)
2001-01-22 18:01:20 +01:00
{
2001-02-16 19:23:01 +01:00
int Width=Map.GetWidth();
int Height=Map.GetHeight();
2001-03-26 23:29:09 +02:00
LayerDef.Width=Width;
LayerDef.Height=Height;
Exp.ExportLayerHeader(LayerDef);//LAYER_TYPE_COLLISION,LayerDef.SubType,Width,Height);
2001-02-16 19:23:01 +01:00
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &MapElem=Map.Get(X,Y);
2001-02-20 16:57:03 +01:00
sExpColTile OutElem;
2001-02-16 19:23:01 +01:00
if (MapElem.Tile)
{
2001-05-09 23:56:48 +02:00
// new OutElem.Tile=(MapElem.Tile-1)<<1;
// OutElem.Tile+=MapElem.Flags & PC_TILE_FLAG_MIRROR_X;
// OutElem.Flags=MapElem.Flags>>PC_TILE_FLAG_COLLISION_SHIFT;
// Old
2001-02-20 16:57:03 +01:00
OutElem.Tile=((MapElem.Tile-1)*4)+1;
OutElem.Tile+=MapElem.Flags & PC_TILE_FLAG_MIRROR_XY;
OutElem.Flags=MapElem.Flags>>PC_TILE_FLAG_COLLISION_SHIFT;
2001-05-09 23:56:48 +02:00
2001-02-20 16:57:03 +01:00
}
else
{
OutElem.Tile=0;
OutElem.Flags=0;
2001-02-16 19:23:01 +01:00
}
2001-02-20 16:57:03 +01:00
Exp.Write(&OutElem,sizeof(sExpColTile));
2001-02-16 19:23:01 +01:00
}
}
2001-01-22 18:01:20 +01:00
}