SBSPSS/Utils/MapEdit/LayerTile.cpp

684 lines
16 KiB
C++
Raw Normal View History

2000-11-07 22:15:35 +01:00
/******************/
/*** Layer Tile ***/
/******************/
#include "stdafx.h"
2000-12-04 17:47:34 +01:00
#include <Vector3.h>
2000-11-07 22:15:35 +01:00
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
2000-11-14 16:03:04 +01:00
#include "MapEdit.h"
2000-11-07 22:15:35 +01:00
#include "MapEditDoc.h"
#include "MapEditView.h"
2000-11-14 16:03:04 +01:00
#include "MainFrm.h"
2000-11-07 22:15:35 +01:00
2001-03-01 18:28:20 +01:00
#include "TileSet.h"
2000-11-07 22:15:35 +01:00
#include "Core.h"
#include "Layer.h"
#include "LayerTile.h"
#include "Utils.h"
2000-12-29 23:20:38 +01:00
#include "Select.h"
2000-11-24 23:34:20 +01:00
#include "Export.h"
2000-11-07 22:15:35 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-03-26 23:29:09 +02:00
CLayerTile::CLayerTile(sLayerDef &Def)
2000-11-07 22:15:35 +01:00
{
2001-03-26 23:29:09 +02:00
InitLayer(Def);
2000-11-07 22:15:35 +01:00
}
/*****************************************************************************/
CLayerTile::~CLayerTile()
{
2001-03-26 23:29:09 +02:00
if (LayerDef.SubType==LAYER_SUBTYPE_ACTION)
2001-03-06 19:39:42 +01:00
{
TileBank->CleanUp();
delete TileBank;
}
2000-11-07 22:15:35 +01:00
}
2000-11-20 21:33:42 +01:00
/*****************************************************************************/
2001-03-26 23:29:09 +02:00
void CLayerTile::InitLayer(sLayerDef &Def)
2000-11-20 21:33:42 +01:00
{
2001-03-26 23:29:09 +02:00
CLayer::InitLayer(Def);
Mode=MouseModePaint;
2000-11-28 22:16:00 +01:00
2001-03-26 23:29:09 +02:00
if (LayerDef.SubType==LAYER_SUBTYPE_ACTION)
2001-03-01 18:28:20 +01:00
TileBank=new CTileBank;
else
TileBank=0;
SubView=TileBank;
2001-03-26 23:29:09 +02:00
if (!GetResizeFlag())
{
LayerDef.Width=32;
LayerDef.Height=32;
}
Resize(LayerDef.Width,LayerDef.Height);
}
/*****************************************************************************/
void CLayerTile::Load(CFile *File,int Version)
{
if (Version<=5)
{
LayerDef.Type=LAYER_TYPE_TILE;
BOOL DB;
float DF;
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);
Map.Load(File,Version);
// if (LayerDef.SubType==LAYER_SUBTYPE_ACTION)
// TileBank=new CTileBank;
// else
// TileBank=0;
// SubView=TileBank;
2001-03-01 18:28:20 +01:00
2000-11-20 21:33:42 +01:00
}
/*****************************************************************************/
void CLayerTile::Save(CFile *File)
{
// Always Save current version
File->Write(&Mode,sizeof(MouseMode));
Map.Save(File);
}
2001-03-01 18:28:20 +01:00
/*****************************************************************************/
void CLayerTile::InitSubView(CCore *Core)
{
// Fix up shared layers
2001-03-26 23:29:09 +02:00
if (LayerDef.SubType!=LAYER_SUBTYPE_ACTION)
2001-03-01 18:28:20 +01:00
{
2001-03-05 21:49:46 +01:00
TileBank=Core->GetTileBank();
SubView=(CLayer*)TileBank;
2001-03-01 18:28:20 +01:00
}
}
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
/*****************************************************************************/
2000-11-30 23:17:55 +01:00
void CLayerTile::CheckLayerSize(int Width,int Height)
{
if (Resize(Width,Height))
{
CString mexstr;
mexstr.Format("%s Layer Resized to Correct Size\nPlease re-save\n", GetName());
AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
}
}
/*****************************************************************************/
2001-03-26 23:29:09 +02:00
void CLayerTile::Validate(CCore *Core)
2000-11-20 17:21:43 +01:00
{
2001-03-26 23:29:09 +02:00
int Width=Map.GetWidth();
int Height=Map.GetHeight();
int Invalid=0;
int X,Y;
bool Ret=false;
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sMapElem &MapElem=Map.Get(X,Y);
if (!TileBank->IsValid(MapElem.Set,MapElem.Tile))
{
Invalid++;
}
}
}
if (Invalid)
{
char Txt[256];
sprintf(Txt,"Map contains %i invalid tiles\n Do you want them removed?",Invalid);
Ret=Core->Question(Txt);
}
if (Ret)
{
for (Y=0; Y<Height; Y++)
{
for (X=0; X<Width; X++)
{
sMapElem &MapElem=Map.Get(X,Y);
if (!TileBank->IsValid(MapElem.Set,MapElem.Tile))
{
MapElem.Set=0;
MapElem.Tile=0;
}
}
}
}
}
2000-11-20 17:21:43 +01:00
2001-03-26 23:29:09 +02:00
/*****************************************************************************/
bool CLayerTile::Resize(int Width,int Height)
{
2000-11-30 23:17:55 +01:00
int ThisWidth=Map.GetWidth();
int ThisHeight=Map.GetHeight();
2001-03-26 23:29:09 +02:00
bool Flag=GetResizeFlag();
2000-11-30 23:17:55 +01:00
2001-03-26 23:29:09 +02:00
Width=TileLayerMinWidth+(Width-TileLayerMinWidth)/GetScaleFactor();
Height=TileLayerMinHeight+(Height-TileLayerMinHeight)/GetScaleFactor();
if (Width<TileLayerMinWidth) Width=TileLayerMinWidth;
if (Height<TileLayerMinHeight) Height=TileLayerMinHeight;
if (!ThisWidth || !ThisHeight) Flag=true;
if (Flag)
2000-11-30 23:17:55 +01:00
{
2001-03-26 23:29:09 +02:00
if (ThisWidth!=Width || ThisHeight!=Height)
{
Map.Resize(Width,Height);
return(true);
}
2000-11-30 23:17:55 +01:00
}
2001-03-26 23:29:09 +02:00
return(false);
2000-11-20 17:21:43 +01:00
}
2000-11-07 22:15:35 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CLayerTile::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
2000-11-07 22:15:35 +01:00
{
2000-12-29 23:20:38 +01:00
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
2000-11-17 22:36:13 +01:00
2001-03-26 23:29:09 +02:00
Is3d&=GetRender3dFlag();
2001-03-05 21:49:46 +01:00
Render(Core,ThisCam,Map,Is3d);
2000-11-07 22:15:35 +01:00
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CLayerTile::RenderCursorPaint(CCore *Core,Vector3 &CamPos,bool Is3d)
2000-11-17 22:36:13 +01:00
{
2000-12-04 17:47:34 +01:00
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
2000-11-17 22:36:13 +01:00
CPoint &CursPos=Core->GetCursorPos();
2001-03-01 18:28:20 +01:00
CMap &Brush=TileBank->GetActiveBrush();
2001-01-17 22:52:08 +01:00
Vector3 Ofs;
2000-11-17 22:36:13 +01:00
if (!Brush.IsValid()) return;
2000-12-29 23:20:38 +01:00
if (CursPos.x<0 || CursPos.y<0) return;
2001-01-17 22:52:08 +01:00
Ofs.x=-(CursPos.x-(int)ThisCam.x);
Ofs.y=-(CursPos.y-(int)ThisCam.y);
ThisCam.x-=(int)ThisCam.x;
ThisCam.y-=(int)ThisCam.y;
2000-11-17 22:36:13 +01:00
2001-03-26 23:29:09 +02:00
Is3d&=GetRender3dFlag();
if (Is3d)
2000-11-17 22:36:13 +01:00
{
glEnable(GL_DEPTH_TEST);
2001-01-17 22:52:08 +01:00
Render(Core,ThisCam,Brush,TRUE,0.5,&Ofs);
2000-11-17 22:36:13 +01:00
glDisable(GL_DEPTH_TEST);
}
else
{
2001-01-17 22:52:08 +01:00
Render(Core,ThisCam,Brush,FALSE,0.5,&Ofs);
2000-11-17 22:36:13 +01:00
}
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
void CLayerTile::Render(CCore *Core,Vector3 &ThisCam,CMap &ThisMap,bool Render3d,float Alpha,Vector3 *Ofs)
2000-11-07 22:15:35 +01:00
{
2000-12-29 23:20:38 +01:00
int MapWidth=ThisMap.GetWidth();
int MapHeight=ThisMap.GetHeight();
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
float ScrOfsX=(ZoomW/2);
float ScrOfsY=(ZoomH/2);
Vector3 &Scale=Core->GetScaleVector();
2001-03-26 23:29:09 +02:00
bool WrapMap=LayerDef.SubType==LAYER_SUBTYPE_BACK;
2001-03-05 21:49:46 +01:00
int StartX=(int)ThisCam.x;
int StartY=(int)ThisCam.y;
float ShiftX=ThisCam.x - (int)ThisCam.x;
float ShiftY=ThisCam.y - (int)ThisCam.y;
2001-03-26 23:29:09 +02:00
if (TileBank->NeedLoad())
{
TileBank->LoadAllSets(Core);
Core->Validate(GetType());
}
2001-01-17 22:52:08 +01:00
if (StartX<0) StartX=0;
if (StartY<0) StartY=0;
int DrawW=ZoomW+8;
int DrawH=ZoomH+8;
if (StartX+DrawW>MapWidth) DrawW=MapWidth-StartX;
if (StartY+DrawH>MapHeight) DrawH=MapHeight-StartY;
2000-11-07 22:15:35 +01:00
glMatrixMode(GL_MODELVIEW);
2000-12-29 23:20:38 +01:00
glPushMatrix();
glLoadIdentity();
glScalef(Scale.x,Scale.y,Scale.z);
2001-01-17 22:52:08 +01:00
glTranslatef(-ShiftX,ShiftY,0); // Set scroll offset
2000-12-29 23:20:38 +01:00
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
2000-11-07 22:15:35 +01:00
2001-01-17 22:52:08 +01:00
if (Ofs)
{
glTranslatef(-Ofs->x,Ofs->y,0); // Set scroll offset
}
2001-03-01 18:28:20 +01:00
if (WrapMap)
{
DrawW=MapWidth;
DrawH=MapHeight;
}
2001-01-17 22:52:08 +01:00
for (int YLoop=0; YLoop<DrawH; YLoop++)
2000-11-07 22:15:35 +01:00
{
2001-01-17 22:52:08 +01:00
for (int XLoop=0; XLoop<DrawW; XLoop++)
2000-11-07 22:15:35 +01:00
{
2001-03-01 18:28:20 +01:00
int XPos=StartX+XLoop;
int YPos=StartY+YLoop;
if (WrapMap)
{
XPos%=MapWidth;
YPos%=MapHeight;
}
sMapElem &ThisElem=ThisMap.Get(XPos,YPos);
2001-03-05 21:49:46 +01:00
if (ThisElem.Tile>0)
{ // Render Non Zero and Valid Tiles
2001-02-20 16:57:03 +01:00
glColor4f(1,1,1,Alpha); // Set default Color
2001-03-22 21:49:58 +01:00
TileBank->RenderElem(ThisElem.Set,ThisElem.Tile,ThisElem.Flags,Render3d);
2000-11-15 22:22:40 +01:00
}
2000-12-29 23:20:38 +01:00
glTranslatef(1.0f,0,0); // Next X
2000-11-07 22:15:35 +01:00
}
2001-01-17 22:52:08 +01:00
glTranslatef(-DrawW,-1,0); // Next y, rewind to start X
2000-11-07 22:15:35 +01:00
}
2000-12-29 23:20:38 +01:00
glPopMatrix();
}
/*****************************************************************************/
void CLayerTile::RenderSelection(CCore *Core,Vector3 &CamPos)
{
CRect Rect=Selection.GetRect();
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
float ScrOfsX=(ZoomW/2);
float ScrOfsY=(ZoomH/2);
Vector3 &Scale=Core->GetScaleVector();
if (!Selection.IsValid()) return;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glScalef(Scale.x,Scale.y,Scale.z);
glTranslatef(-ThisCam.x,ThisCam.y,0);
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
glColor4f(1,0,1,0.5f);
glBegin (GL_QUADS);
float X0=Rect.left;
float X1=Rect.right;
float Y0=Rect.top-1;
float Y1=Rect.bottom-1;
glVertex3f( X0, -Y0, 0);
glVertex3f( X1, -Y0, 0);
glVertex3f( X1, -Y1, 0);
glVertex3f( X0, -Y1, 0);
glEnd();
glPopMatrix();
2000-11-07 22:15:35 +01:00
}
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CLayerTile::GUIInit(CCore *Core)
2000-11-14 16:03:04 +01:00
{
2001-03-01 18:28:20 +01:00
TileBank->GUIInit(Core);
2001-03-22 21:49:58 +01:00
Core->GUIAdd(GUIToolBar,IDD_TOOLBAR);
2000-11-14 16:03:04 +01:00
}
/*****************************************************************************/
2001-02-09 22:17:01 +01:00
void CLayerTile::GUIKill(CCore *Core)
2000-11-14 16:03:04 +01:00
{
2001-03-01 18:28:20 +01:00
TileBank->GUIKill(Core);
2001-03-22 21:49:58 +01:00
Core->GUIRemove(GUIToolBar,IDD_TOOLBAR);
2001-02-09 22:17:01 +01:00
}
2000-11-17 00:08:54 +01:00
2001-02-09 22:17:01 +01:00
/*****************************************************************************/
void CLayerTile::GUIUpdate(CCore *Core)
{
2001-03-13 22:00:34 +01:00
GUIToolBar.ResetButtons();
2001-02-09 22:17:01 +01:00
switch(Mode)
2000-11-17 00:08:54 +01:00
{
2001-02-09 22:17:01 +01:00
case MouseModePaint:
2001-03-13 22:00:34 +01:00
GUIToolBar.SetButtonState(CGUIToolBar::PAINT,TRUE);
2001-02-09 22:17:01 +01:00
break;
case MouseModeSelect:
2001-03-13 22:00:34 +01:00
GUIToolBar.SetButtonState(CGUIToolBar::SELECT,TRUE);
2001-02-09 22:17:01 +01:00
break;
default:
break;
2000-11-17 00:08:54 +01:00
}
2001-03-01 18:28:20 +01:00
TileBank->GUIUpdate(Core);
2001-02-09 22:17:01 +01:00
}
/*****************************************************************************/
void CLayerTile::GUIChanged(CCore *Core)
{
2000-11-15 22:22:40 +01:00
}
/*****************************************************************************/
/*** Functions ***************************************************************/
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
bool Ret=false;
2000-11-15 22:22:40 +01:00
2000-11-17 00:08:54 +01:00
switch(Mode)
{
case MouseModePaint:
if (DownFlag)
2001-03-01 18:28:20 +01:00
Ret=Paint(TileBank->GetLBrush(),CursorPos);
2000-11-17 00:08:54 +01:00
break;
case MouseModeSelect:
2000-12-29 23:20:38 +01:00
Ret=Selection.Handle(CursorPos,nFlags);
if (Selection.HasSelection())
{
TRACE0("LMB Selection\n");
}
2000-11-17 00:08:54 +01:00
break;
default:
break;
}
return(Ret);
2000-11-15 22:22:40 +01:00
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
bool Ret=FALSE;
2000-11-15 22:22:40 +01:00
2000-11-17 00:08:54 +01:00
switch(Mode)
{
case MouseModePaint:
if (DownFlag)
2001-03-01 18:28:20 +01:00
Ret=Paint(TileBank->GetRBrush(),CursorPos);
2000-11-17 00:08:54 +01:00
break;
case MouseModeSelect:
2000-12-29 23:20:38 +01:00
Ret=Selection.Handle(CursorPos,nFlags);
if (Selection.HasSelection())
{
TRACE0("RMB Selection\n");
}
2000-11-17 00:08:54 +01:00
break;
default:
break;
}
return(Ret);
2000-11-15 22:22:40 +01:00
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
2000-11-15 22:22:40 +01:00
{
2001-03-01 18:28:20 +01:00
bool Ret=FALSE;
2000-11-15 22:22:40 +01:00
2000-11-17 00:08:54 +01:00
switch(Mode)
{
case MouseModePaint:
if (nFlags & MK_LBUTTON)
2001-03-01 18:28:20 +01:00
Ret=Paint(TileBank->GetLBrush(),CursorPos);
2000-11-17 00:08:54 +01:00
else
if (nFlags & MK_RBUTTON)
2001-03-01 18:28:20 +01:00
Ret=Paint(TileBank->GetRBrush(),CursorPos);
2000-11-17 00:08:54 +01:00
break;
case MouseModeSelect:
2000-12-29 23:20:38 +01:00
Ret=Selection.Handle(CursorPos,nFlags);
2000-11-17 00:08:54 +01:00
break;
default:
break;
}
return(Ret);
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
{
bool Ret=false;
switch(CmdMsg)
{
case CmdMsg_SetMode:
Mode=(MouseMode)Param0;
Core->GUIUpdate();
break;
case CmdMsg_Copy:
CopySelection(Core);
break;
case CmdMsg_Paste:
PasteSelection(Core);
break;
case CmdMsg_MirrorX:
Ret=MirrorX(Core);
break;
case CmdMsg_MirrorY:
Ret=MirrorY(Core);
break;
case CmdMsg_SetColFlag:
Ret=SetColFlags(Core,Param0);
break;
case CmdMsg_SubViewLoad:
case CmdMsg_SubViewDelete:
case CmdMsg_SubViewUpdate:
case CmdMsg_SubViewSet:
case CmdMsg_ActiveBrushLeft:
case CmdMsg_ActiveBrushRight:
Ret=TileBank->Command(CmdMsg,Core,Param0,Param1);
2001-03-05 21:49:46 +01:00
break;
2001-03-01 18:28:20 +01:00
default:
TRACE3("LayerTile-Unhandled Command %i (%i,%i)\n",CmdMsg,Param0,Param1);
2001-03-22 21:49:58 +01:00
break;
2001-03-01 18:28:20 +01:00
}
return(Ret);
}
/*****************************************************************************/
void CLayerTile::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
2000-11-17 00:08:54 +01:00
{
2000-11-17 22:36:13 +01:00
switch(Mode)
{
case MouseModePaint:
RenderCursorPaint(Core,CamPos,Is3d);
break;
case MouseModeSelect:
2000-12-29 23:20:38 +01:00
RenderSelection(Core,CamPos);
2000-11-17 22:36:13 +01:00
break;
default:
break;
}
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::MirrorX(CCore *Core)
2000-11-17 22:36:13 +01:00
{
2000-12-29 23:20:38 +01:00
switch(Mode)
{
case MouseModePaint:
{
2001-03-01 18:28:20 +01:00
TileBank->GetLBrush().MirrorX(PC_TILE_FLAG_MIRROR_X);
TileBank->GetRBrush().MirrorX(PC_TILE_FLAG_MIRROR_X);
2000-12-29 23:20:38 +01:00
}
break;
case MouseModeSelect:
{
if (!Selection.IsValid()) return(false); // No Selection
CRect R=Selection.GetRect();
2001-02-20 16:57:03 +01:00
Map.MirrorX(PC_TILE_FLAG_MIRROR_X,&R);
2000-12-29 23:20:38 +01:00
}
break;
default:
break;
}
2001-03-01 18:28:20 +01:00
Core->UpdateView();
2000-11-17 00:08:54 +01:00
return(TRUE);
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::MirrorY(CCore *Core)
2000-11-17 00:08:54 +01:00
{
2000-12-29 23:20:38 +01:00
switch(Mode)
{
case MouseModePaint:
{
2001-03-01 18:28:20 +01:00
TileBank->GetLBrush().MirrorY(PC_TILE_FLAG_MIRROR_Y);
TileBank->GetRBrush().MirrorY(PC_TILE_FLAG_MIRROR_Y);
2000-12-29 23:20:38 +01:00
}
break;
case MouseModeSelect:
{
if (!Selection.IsValid()) return(false); // No Selection
CRect R=Selection.GetRect();
2001-02-20 16:57:03 +01:00
Map.MirrorY(PC_TILE_FLAG_MIRROR_Y,&R);
2000-12-29 23:20:38 +01:00
}
break;
default:
break;
}
2001-03-01 18:28:20 +01:00
Core->UpdateView();
2000-11-17 00:08:54 +01:00
return(TRUE);
2000-11-15 22:22:40 +01:00
}
2001-02-20 16:57:03 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::SetColFlags(CCore *Core,int Flags)
2001-02-20 16:57:03 +01:00
{
switch(Mode)
{
case MouseModePaint:
{
2001-03-01 18:28:20 +01:00
TileBank->GetLBrush().SetFlags(Flags<<PC_TILE_FLAG_COLLISION_SHIFT,PC_TILE_FLAG_MIRROR_XY);
TileBank->GetRBrush().SetFlags(Flags<<PC_TILE_FLAG_COLLISION_SHIFT,PC_TILE_FLAG_MIRROR_XY);
2001-02-20 16:57:03 +01:00
}
break;
case MouseModeSelect:
{
if (!Selection.IsValid()) return(false); // No Selection
CRect R=Selection.GetRect();
Map.SetFlags(Flags<<PC_TILE_FLAG_COLLISION_SHIFT,PC_TILE_FLAG_MIRROR_XY,&R);
}
break;
default:
break;
}
return(TRUE);
}
2000-12-29 23:20:38 +01:00
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::CopySelection(CCore *Core)
2000-12-29 23:20:38 +01:00
{
if (Mode!=MouseModeSelect) return(false); // Not in select mode
if (!Selection.IsValid()) return(false); // No Selection
CRect Rect=Selection.GetRect();
2001-03-01 18:28:20 +01:00
TileBank->GetActiveBrush().Set(Map,Rect.left,Rect.top,Rect.Width(),Rect.Height());
2000-12-29 23:20:38 +01:00
return(true);
}
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::PasteSelection(CCore *Core)
2000-12-29 23:20:38 +01:00
{
if (Mode!=MouseModeSelect) return(false); // Not in select mode
if (!Selection.IsValid()) return(false); // No Selection
2001-01-02 15:34:02 +01:00
CRect Rect=Selection.GetRect();
2001-03-01 18:28:20 +01:00
Map.Paste(TileBank->GetActiveBrush(),&Rect);
2000-12-29 23:20:38 +01:00
return(true);
}
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
2000-11-17 00:08:54 +01:00
/*****************************************************************************/
/*****************************************************************************/
2001-03-01 18:28:20 +01:00
bool CLayerTile::Paint(CMap &Blk,CPoint &CursorPos)
2000-11-15 22:22:40 +01:00
{
2001-03-05 21:49:46 +01:00
if (CursorPos.x==-1 || CursorPos.y==-1) return(FALSE); // Off Map?
2000-11-17 22:36:13 +01:00
if (!Blk.IsValid()) return(FALSE); // Invalid tile?
Map.Set(CursorPos.x,CursorPos.y,Blk);
2000-11-15 22:22:40 +01:00
return(TRUE);
}
2000-11-24 23:34:20 +01:00
/*****************************************************************************/
2000-11-29 18:07:57 +01:00
void CLayerTile::Export(CCore *Core,CExport &Exp)
2000-11-24 23:34:20 +01:00
{
2001-03-26 23:29:09 +02:00
int Width=Map.GetWidth();
int Height=Map.GetHeight();
2001-02-16 19:23:01 +01:00
2001-03-26 23:29:09 +02:00
LayerDef.Width=Width;
LayerDef.Height=Height;
Exp.ExportLayerHeader(LayerDef);
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);
sExpLayerTile OutElem;
2001-03-05 21:49:46 +01:00
if (MapElem.Set==0 && MapElem.Tile==0)
{ // Blank
OutElem.Tile=0;
OutElem.Flags=0;
}
else
{
sExpTile OutTile;
2001-03-22 21:49:58 +01:00
CElem &ThisTile=TileBank->GetElem(MapElem.Set,MapElem.Tile);
2001-03-05 21:49:46 +01:00
OutTile.Set=MapElem.Set;
OutTile.Tile=MapElem.Tile;
OutTile.TriStart=0;
OutTile.TriCount=0;
OutTile.XOfs=ThisTile.GetTexXOfs();
OutTile.YOfs=ThisTile.GetTexYOfs();
OutElem.Tile=Exp.AddTile(OutTile);
OutElem.Flags=MapElem.Flags;
}
2001-02-16 19:23:01 +01:00
Exp.Write(&OutElem,sizeof(sExpLayerTile));
}
}
2000-11-24 23:34:20 +01:00
}
2000-12-11 22:29:59 +01:00
/*****************************************************************************/
2001-03-05 21:49:46 +01:00
void CLayerTile::RemoveSet(int Set)
2000-12-11 22:29:59 +01:00
{
2001-03-05 21:49:46 +01:00
Map.RemoveSet(Set);
2000-12-11 22:29:59 +01:00
}
/*****************************************************************************/
void CLayerTile::RemapSet(int OrigSet,int NewSet)
{
Map.RemapSet(OrigSet,NewSet);
}