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
|
|
|
|
|
|
|
#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
|
|
|
|
2000-11-28 22:16:00 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
char *CLayerTile::LayerName[]=
|
|
|
|
{
|
|
|
|
"Back",
|
|
|
|
"Mid",
|
|
|
|
"Action",
|
|
|
|
"Fore",
|
|
|
|
};
|
2000-11-07 22:15:35 +01:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
// New Layer
|
2000-11-28 22:16:00 +01:00
|
|
|
CLayerTile::CLayerTile(int _SubType,int Width,int Height,float Scale,BOOL Is3d,BOOL Resizable)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-11-28 22:16:00 +01:00
|
|
|
SubType=_SubType;
|
|
|
|
ScaleFactor=Scale;
|
2000-11-20 17:21:43 +01:00
|
|
|
ResizeFlag=Resizable;
|
2000-11-07 22:15:35 +01:00
|
|
|
Render3dFlag=Is3d;
|
2000-11-21 22:27:55 +01:00
|
|
|
VisibleFlag=TRUE;
|
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
|
|
|
}
|
2000-11-30 23:17:55 +01:00
|
|
|
|
|
|
|
if (Width<TileLayerMinWidth) Width=TileLayerMinWidth;
|
|
|
|
if (Height<TileLayerMinHeight) Height=TileLayerMinHeight;
|
|
|
|
|
|
|
|
Map.SetSize(Width,Height,TRUE);
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-11-20 21:33:42 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::Load(CFile *File,float Version)
|
|
|
|
{
|
|
|
|
// Version 1
|
2000-11-28 22:16:00 +01:00
|
|
|
if (Version>=1.0)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE1("%s\t",GetName());
|
|
|
|
TRACE1("Scl:%g\t",ScaleFactor);
|
2000-11-28 00:07:07 +01:00
|
|
|
TRACE1("%i\n",VisibleFlag);
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
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
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2000-12-04 17:47:34 +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
|
|
|
|
|
|
|
if (Is3d && Render3dFlag)
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2000-11-22 23:08:47 +01:00
|
|
|
Render(Core,ThisCam,Map,TRUE);
|
2000-11-17 22:36:13 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-22 23:08:47 +01:00
|
|
|
Render(Core,ThisCam,Map,FALSE);
|
2000-11-17 22:36:13 +01:00
|
|
|
}
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-04 17:47:34 +01:00
|
|
|
void CLayerTile::RenderCursorPaint(CCore *Core,Vector3 &CamPos,BOOL Is3d)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
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();
|
|
|
|
CMap &Brush=TileBank.GetActiveBrush();
|
|
|
|
|
|
|
|
if (!Brush.IsValid()) return;
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
if (CursPos.x<0 || CursPos.y<0) return;
|
|
|
|
ThisCam.x-=CursPos.x;
|
2000-11-17 22:36:13 +01:00
|
|
|
ThisCam.y-=CursPos.y;
|
|
|
|
|
|
|
|
if (Is3d && Render3dFlag)
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2000-11-22 23:08:47 +01:00
|
|
|
Render(Core,ThisCam,Brush,TRUE,0.5);
|
2000-11-17 22:36:13 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-22 23:08:47 +01:00
|
|
|
Render(Core,ThisCam,Brush,FALSE,0.5);
|
2000-11-17 22:36:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-29 23:20:38 +01:00
|
|
|
void CLayerTile::Render(CCore *Core,Vector3 &ThisCam,CMap &ThisMap,BOOL Render3d,float Alpha)
|
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();
|
2000-11-17 22:36:13 +01:00
|
|
|
|
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);
|
|
|
|
glTranslatef(-ThisCam.x,ThisCam.y,0);
|
|
|
|
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
2000-11-07 22:15:35 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
glColor4f(1,1,1,Alpha);
|
|
|
|
for (int YLoop=0; YLoop<MapHeight; YLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int XLoop=0; XLoop<MapWidth; XLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-11-17 22:36:13 +01:00
|
|
|
sMapElem &ThisElem=ThisMap.Get(XLoop,YLoop);
|
2000-11-29 18:07:57 +01:00
|
|
|
if (ThisElem.Tile && Core->IsTileValid(ThisElem.Set,ThisElem.Tile))
|
2000-11-15 22:22:40 +01:00
|
|
|
{ // Render Non Zero Tiles
|
|
|
|
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
|
|
|
|
|
2000-11-22 23:08:47 +01:00
|
|
|
ThisTile.Render(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
|
|
|
}
|
2000-12-29 23:20:38 +01:00
|
|
|
glTranslatef(-MapWidth,-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-12-04 17:47:34 +01:00
|
|
|
void CLayerTile::RenderGrid(CCore *Core,Vector3 &CamPos,BOOL Active)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
|
|
|
int MapWidth=Map.GetWidth();
|
|
|
|
int MapHeight=Map.GetHeight();
|
|
|
|
float ZoomW=Core->GetZoomW();
|
|
|
|
float ZoomH=Core->GetZoomH();
|
|
|
|
float ScrOfsX=(ZoomW/2);
|
|
|
|
float ScrOfsY=(ZoomH/2);
|
|
|
|
Vector3 &Scale=Core->GetScaleVector();
|
|
|
|
float Col;
|
|
|
|
const float OverVal=0.1f;
|
2000-11-07 22:15:35 +01:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2000-12-29 23:20:38 +01:00
|
|
|
glPushMatrix();
|
2000-11-07 22:15:35 +01:00
|
|
|
glLoadIdentity();
|
2000-12-29 23:20:38 +01:00
|
|
|
glScalef(Scale.x,Scale.y,Scale.z);
|
|
|
|
glTranslatef(-ThisCam.x,ThisCam.y,0);
|
|
|
|
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
|
|
|
|
|
|
|
if (Active) Col=1; else Col=0.5f;
|
2000-11-07 22:15:35 +01:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2000-12-29 23:20:38 +01:00
|
|
|
|
|
|
|
glColor3f(Col,Col,Col);
|
2000-11-07 22:15:35 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int YLoop=0; YLoop<MapHeight+1; YLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
glVertex3f( 0-OverVal, -YLoop+1, 0);
|
|
|
|
glVertex3f( MapWidth+OverVal, -YLoop+1, 0);
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int XLoop=0; XLoop<MapWidth+1; XLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
glVertex3f( XLoop, 0+1+OverVal, 0);
|
2000-12-29 23:20:38 +01:00
|
|
|
glVertex3f( XLoop, -MapHeight+1-OverVal, 0);
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
glPopMatrix();
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-04 17:47:34 +01:00
|
|
|
void CLayerTile::FindCursorPos(CCore *Core,CMapEditView *View,Vector3 &CamPos,CPoint &MousePos)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
|
|
|
|
int MapWidth=Map.GetWidth();
|
|
|
|
int MapHeight=Map.GetHeight();
|
|
|
|
float ZoomW=Core->GetZoomW();
|
|
|
|
float ZoomH=Core->GetZoomH();
|
|
|
|
float ScrOfsX=(ZoomW/2);
|
|
|
|
float ScrOfsY=(ZoomH/2);
|
|
|
|
Vector3 &Scale=Core->GetScaleVector();
|
|
|
|
|
|
|
|
GLint Viewport[4];
|
|
|
|
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
|
|
|
int TileID=0;
|
|
|
|
CPoint &CursorPos=Core->GetCursorPos();
|
2000-11-08 20:53:57 +01:00
|
|
|
|
2000-11-07 22:15:35 +01:00
|
|
|
glGetIntegerv(GL_VIEWPORT, Viewport);
|
|
|
|
glSelectBuffer (SELECT_BUFFER_SIZE, SelectBuffer );
|
|
|
|
glRenderMode (GL_SELECT);
|
|
|
|
|
|
|
|
glInitNames();
|
|
|
|
glPushName(-1);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPickMatrix( MousePos.x ,(Viewport[3]-MousePos.y),5.0,5.0,Viewport);
|
|
|
|
View->SetupPersMatrix();
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2000-12-29 23:20:38 +01:00
|
|
|
glPushMatrix();
|
2000-11-07 22:15:35 +01:00
|
|
|
glLoadIdentity();
|
2000-12-29 23:20:38 +01:00
|
|
|
glScalef(Scale.x,Scale.y,Scale.z);
|
|
|
|
glTranslatef(-ThisCam.x,ThisCam.y,0);
|
|
|
|
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
|
2000-11-07 22:15:35 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int YLoop=0; YLoop<MapHeight; YLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int XLoop=0; XLoop<MapWidth; XLoop++)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
glLoadName (TileID);
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
BuildGLQuad(XLoop,XLoop+1,-YLoop,-YLoop+1,0);
|
|
|
|
glEnd();
|
|
|
|
TileID++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
TileID= glRenderMode (GL_RENDER);
|
|
|
|
glPopMatrix();
|
2000-11-07 22:15:35 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
CursorPos.x=CursorPos.y=-1;
|
|
|
|
|
|
|
|
// Process hits
|
|
|
|
|
|
|
|
GLuint *HitPtr=SelectBuffer;
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
if (TileID) // Just take 1st
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
int HitID=HitPtr[3];
|
2000-12-29 23:20:38 +01:00
|
|
|
CursorPos=IDToPoint(HitID,MapWidth);
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
|
|
|
|
}
|
2000-11-14 16:03:04 +01:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Gui *********************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::InitGUI(CCore *Core)
|
|
|
|
{
|
|
|
|
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
|
|
|
|
CMultiBar *ParamBar=Frm->GetParamBar();
|
|
|
|
|
2000-11-28 15:34:42 +01:00
|
|
|
ParamBar->Add(Frm->GetLayerTileGUI(),IDD_LAYERTILE_GUI,TRUE);
|
2000-11-14 16:03:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::UpdateGUI(CCore *Core)
|
|
|
|
{
|
2000-11-28 15:34:42 +01:00
|
|
|
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
|
|
|
|
CLayerTileGUI *Dlg=(CLayerTileGUI *)Frm->GetDialog(IDD_LAYERTILE_GUI);
|
2000-11-17 00:08:54 +01:00
|
|
|
|
2000-11-28 15:34:42 +01:00
|
|
|
if (Dlg)
|
2000-11-17 00:08:54 +01:00
|
|
|
{
|
2000-11-28 15:34:42 +01:00
|
|
|
Dlg->ResetButtons();
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
2000-11-28 15:34:42 +01:00
|
|
|
Dlg->SetButtonState(CLayerTileGUI::PAINT,TRUE);
|
2000-11-17 00:08:54 +01:00
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
2000-11-28 15:34:42 +01:00
|
|
|
Dlg->SetButtonState(CLayerTileGUI::SELECT,TRUE);
|
2000-11-17 00:08:54 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-11-28 15:34:42 +01:00
|
|
|
Core->UpdateTileViewGUI();
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Functions ***************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::SetMode(int NewMode)
|
|
|
|
{
|
|
|
|
BOOL Ret=FALSE;
|
2000-11-17 00:08:54 +01:00
|
|
|
|
2000-11-15 22:22:40 +01:00
|
|
|
// Clean up last mode
|
2000-11-17 00:08:54 +01:00
|
|
|
Ret|=ExitMode();
|
|
|
|
Mode=(MouseMode)NewMode;
|
|
|
|
Ret|=InitMode();
|
|
|
|
return(Ret);
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::InitMode()
|
|
|
|
{
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(FALSE);
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::ExitMode()
|
|
|
|
{
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2000-11-15 22:22:40 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::LButtonControl(CCore *Core,CMapEditView *View,UINT nFlags, CPoint &CursorPos,BOOL DownFlag)
|
|
|
|
{
|
|
|
|
BOOL Ret=FALSE;
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
if (DownFlag)
|
2000-11-17 22:36:13 +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
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::RButtonControl(CCore *Core,CMapEditView *View,UINT nFlags, CPoint &CursorPos,BOOL DownFlag)
|
|
|
|
{
|
|
|
|
BOOL Ret=FALSE;
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
if (DownFlag)
|
2000-11-17 22:36:13 +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
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::MouseMove(CCore *Core,CMapEditView *View,UINT nFlags, CPoint &CursorPos)
|
|
|
|
{
|
|
|
|
BOOL Ret=FALSE;
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
if (nFlags & MK_LBUTTON)
|
2000-11-17 22:36:13 +01:00
|
|
|
Ret=Paint(TileBank.GetLBrush(),CursorPos);
|
2000-11-17 00:08:54 +01:00
|
|
|
else
|
|
|
|
if (nFlags & MK_RBUTTON)
|
2000-11-17 22:36:13 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-04 17:47:34 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::MirrorX(CCore *Core)
|
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModePaint:
|
|
|
|
{
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
2000-11-17 22:36:13 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
TileBank.GetLBrush().MirrorX(TILE_FLAG_MIRROR_X);
|
|
|
|
TileBank.GetRBrush().MirrorX(TILE_FLAG_MIRROR_X);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
{
|
|
|
|
if (!Selection.IsValid()) return(false); // No Selection
|
|
|
|
CRect R=Selection.GetRect();
|
|
|
|
Map.MirrorX(TILE_FLAG_MIRROR_X,&R);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-11-17 22:36:13 +01:00
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-17 22:36:13 +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:
|
|
|
|
{
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
|
|
|
|
TileBank.GetLBrush().MirrorY(TILE_FLAG_MIRROR_Y);
|
|
|
|
TileBank.GetRBrush().MirrorY(TILE_FLAG_MIRROR_Y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
{
|
|
|
|
if (!Selection.IsValid()) return(false); // No Selection
|
|
|
|
CRect R=Selection.GetRect();
|
|
|
|
Map.MirrorY(TILE_FLAG_MIRROR_Y,&R);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-11-17 22:36:13 +01:00
|
|
|
|
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
return(TRUE);
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::CopySelection(CCore *Core)
|
|
|
|
{
|
|
|
|
if (Mode!=MouseModeSelect) return(false); // Not in select mode
|
|
|
|
if (!Selection.IsValid()) return(false); // No Selection
|
|
|
|
|
|
|
|
CTileBank &TileBank=Core->GetTileBank();
|
|
|
|
CRect Rect=Selection.GetRect();
|
|
|
|
|
|
|
|
TileBank.GetLBrush().Set(Map,Rect.left,Rect.top,Rect.Width(),Rect.Height());
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::PasteSelection(CCore *Core)
|
|
|
|
{
|
|
|
|
if (Mode!=MouseModeSelect) return(false); // Not in select mode
|
|
|
|
if (!Selection.IsValid()) return(false); // No Selection
|
|
|
|
|
|
|
|
TRACE0("Paste\n");
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2000-11-15 22:22:40 +01:00
|
|
|
/*****************************************************************************/
|
2000-11-17 00:08:54 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-11-17 22:36:13 +01:00
|
|
|
BOOL CLayerTile::Paint(CMap &Blk,CPoint &CursorPos)
|
2000-11-15 22:22:40 +01:00
|
|
|
{
|
|
|
|
if (CursorPos.y==-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
|
|
|
{
|
2000-11-30 23:17:55 +01:00
|
|
|
Exp.ExportLayerTile(Core,GetName(),SubType,Map);
|
2000-11-24 23:34:20 +01:00
|
|
|
}
|
2000-12-11 22:29:59 +01:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::DeleteSet(int Set)
|
|
|
|
{
|
|
|
|
Map.DeleteSet(Set);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::RemapSet(int OrigSet,int NewSet)
|
|
|
|
{
|
|
|
|
Map.RemapSet(OrigSet,NewSet);
|
|
|
|
|
|
|
|
}
|