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
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
// New Layer
|
2001-01-23 22:53:48 +01:00
|
|
|
CLayerTile::CLayerTile(int _SubType,int Width,int Height)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-11-28 22:16:00 +01:00
|
|
|
SubType=_SubType;
|
2001-03-01 18:28:20 +01:00
|
|
|
TileBank=0;
|
|
|
|
if (SubType==LAYER_SUBTYPE_ACTION)
|
|
|
|
TileBank=new CTileBank;
|
|
|
|
else
|
|
|
|
TileBank=0;
|
|
|
|
SubView=TileBank;
|
2001-01-23 22:53:48 +01:00
|
|
|
|
|
|
|
SetDefaultParams();
|
|
|
|
|
2000-11-15 22:22:40 +01:00
|
|
|
Mode=MouseModePaint;
|
2000-11-20 17:21:43 +01:00
|
|
|
|
2000-11-28 15:34:42 +01:00
|
|
|
if (ResizeFlag)
|
|
|
|
{
|
2000-11-30 23:17:55 +01:00
|
|
|
Width=TileLayerMinWidth+(Width-TileLayerMinWidth)/ScaleFactor;
|
|
|
|
Height=TileLayerMinHeight+(Height-TileLayerMinHeight)/ScaleFactor;
|
2000-11-28 15:34:42 +01:00
|
|
|
}
|
2001-02-07 22:31:31 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Width=32;
|
|
|
|
Height=32;
|
|
|
|
}
|
2000-11-30 23:17:55 +01:00
|
|
|
|
|
|
|
if (Width<TileLayerMinWidth) Width=TileLayerMinWidth;
|
|
|
|
if (Height<TileLayerMinHeight) Height=TileLayerMinHeight;
|
|
|
|
|
|
|
|
Map.SetSize(Width,Height,TRUE);
|
2001-03-01 18:28:20 +01:00
|
|
|
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
// Load Layer
|
2000-11-20 21:33:42 +01:00
|
|
|
CLayerTile::CLayerTile(CFile *File,int Version)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
Load(File,Version);
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
CLayerTile::~CLayerTile()
|
|
|
|
{
|
2001-03-06 19:39:42 +01:00
|
|
|
if (SubType==LAYER_SUBTYPE_ACTION)
|
|
|
|
{
|
|
|
|
TileBank->CleanUp();
|
|
|
|
delete TileBank;
|
|
|
|
}
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
2000-11-20 21:33:42 +01:00
|
|
|
/*****************************************************************************/
|
2001-01-23 22:53:48 +01:00
|
|
|
void CLayerTile::Load(CFile *File,int Version)
|
2000-11-20 21:33:42 +01:00
|
|
|
{
|
2001-01-23 22:53:48 +01:00
|
|
|
File->Read(&Render3dFlag,sizeof(BOOL));
|
|
|
|
File->Read(&ScaleFactor,sizeof(float));
|
|
|
|
File->Read(&ResizeFlag,sizeof(BOOL));
|
|
|
|
File->Read(&VisibleFlag,sizeof(BOOL));
|
|
|
|
File->Read(&Mode,sizeof(MouseMode));
|
|
|
|
File->Read(&SubType,sizeof(int));
|
|
|
|
Map.Load(File,Version);
|
2000-11-28 22:16:00 +01:00
|
|
|
|
2001-03-01 18:28:20 +01:00
|
|
|
if (SubType==LAYER_SUBTYPE_ACTION)
|
|
|
|
TileBank=new CTileBank;
|
|
|
|
else
|
|
|
|
TileBank=0;
|
|
|
|
SubView=TileBank;
|
|
|
|
|
2000-11-28 22:16:00 +01:00
|
|
|
TRACE1("%s\t",GetName());
|
2000-11-20 21:33:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::Save(CFile *File)
|
|
|
|
{
|
|
|
|
// Always Save current version
|
|
|
|
|
|
|
|
File->Write(&Render3dFlag,sizeof(BOOL));
|
2000-11-28 22:16:00 +01:00
|
|
|
File->Write(&ScaleFactor,sizeof(float));
|
2000-11-20 21:33:42 +01:00
|
|
|
File->Write(&ResizeFlag,sizeof(BOOL));
|
2000-11-21 22:27:55 +01:00
|
|
|
File->Write(&VisibleFlag,sizeof(BOOL));
|
2000-11-20 21:33:42 +01:00
|
|
|
File->Write(&Mode,sizeof(MouseMode));
|
2000-11-28 22:16:00 +01:00
|
|
|
File->Write(&SubType,sizeof(SubType));
|
2000-11-20 21:33:42 +01:00
|
|
|
Map.Save(File);
|
|
|
|
}
|
|
|
|
|
2001-03-01 18:28:20 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::InitSubView(CCore *Core)
|
|
|
|
{
|
|
|
|
// Fix up shared layers
|
2001-03-05 21:49:46 +01:00
|
|
|
if (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-01 18:28:20 +01:00
|
|
|
bool CLayerTile::Resize(int Width,int Height)
|
2000-11-20 17:21:43 +01:00
|
|
|
{
|
2000-11-30 23:17:55 +01:00
|
|
|
if (!ResizeFlag) return(FALSE); // Its a fixed size, so DONT DO IT!
|
2000-11-20 17:21:43 +01:00
|
|
|
|
2000-11-30 23:17:55 +01:00
|
|
|
int ThisWidth=Map.GetWidth();
|
|
|
|
int ThisHeight=Map.GetHeight();
|
|
|
|
Width=TileLayerMinWidth+(Width-TileLayerMinWidth)/ScaleFactor;
|
|
|
|
Height=TileLayerMinHeight+(Height-TileLayerMinHeight)/ScaleFactor;
|
|
|
|
|
|
|
|
if (ThisWidth!=Width || ThisHeight!=Height)
|
|
|
|
{
|
|
|
|
Map.Resize(Width,Height);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
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-05 21:49:46 +01:00
|
|
|
Is3d&=Render3dFlag;
|
|
|
|
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
|
|
|
|
|
|
|
if (Is3d && Render3dFlag)
|
|
|
|
{
|
|
|
|
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-01 18:28:20 +01:00
|
|
|
bool WrapMap=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;
|
|
|
|
|
|
|
|
if (TileBank->NeedLoad()) TileBank->LoadAllSets(Core);
|
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-05 21:49:46 +01:00
|
|
|
TileBank->RenderTile(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-13 22:00:34 +01:00
|
|
|
Core->GUIAdd(GUIToolBar,IDD_LAYERTILE_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-13 22:00:34 +01:00
|
|
|
Core->GUIRemove(GUIToolBar,IDD_LAYERTILE_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);
|
|
|
|
}
|
|
|
|
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-02-16 19:23:01 +01:00
|
|
|
int Width=Map.GetWidth();
|
|
|
|
int Height=Map.GetHeight();
|
|
|
|
|
|
|
|
Exp.ExportLayerHeader(LAYER_TYPE_TILE,SubType,Width,Height);
|
|
|
|
|
|
|
|
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;
|
|
|
|
CElem &ThisTile=TileBank->GetTile(MapElem.Set,MapElem.Tile);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|