2000-11-07 22:15:35 +01:00
|
|
|
/******************/
|
|
|
|
/*** Layer Tile ***/
|
|
|
|
/******************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "gl3d.h"
|
|
|
|
#include <gl\gl.h>
|
|
|
|
#include <gl\glu.h>
|
|
|
|
#include <gl\glut.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"
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
// New Layer
|
|
|
|
CLayerTile::CLayerTile(char *_Name,int Width,int Height,float ZDiv,BOOL Is3d)
|
|
|
|
{
|
|
|
|
SetName(_Name);
|
2000-11-15 22:22:40 +01:00
|
|
|
Map.SetSize(Width,Height,TRUE);
|
2000-11-07 22:15:35 +01:00
|
|
|
ZPosDiv=ZDiv;
|
|
|
|
Render3dFlag=Is3d;
|
2000-11-15 22:22:40 +01:00
|
|
|
Mode=MouseModePaint;
|
2000-11-17 00:08:54 +01:00
|
|
|
Flag=0;
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
// Load Layer
|
|
|
|
CLayerTile::CLayerTile(char *_Name)
|
|
|
|
{
|
|
|
|
ASSERT(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
CLayerTile::~CLayerTile()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2000-11-14 16:03:04 +01:00
|
|
|
void CLayerTile::Render(CCore *Core,Vec &CamPos,BOOL Is3d)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
if (Is3d && Render3dFlag)
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2000-11-14 16:03:04 +01:00
|
|
|
Render3d(Core,CamPos);
|
2000-11-07 22:15:35 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-14 16:03:04 +01:00
|
|
|
Render2d(Core,CamPos);
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-14 16:03:04 +01:00
|
|
|
void CLayerTile::Render2d(CCore *Core,Vec &CamPos)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
2000-11-08 20:53:57 +01:00
|
|
|
return;
|
2000-11-07 22:15:35 +01:00
|
|
|
float XYDiv=GetLayerZPosDiv();
|
|
|
|
int MapW=Map.GetWidth();
|
|
|
|
int MapH=Map.GetHeight();
|
2000-11-14 16:03:04 +01:00
|
|
|
float StartX=CamPos.x/XYDiv;
|
|
|
|
float StartY=CamPos.y/XYDiv;
|
2000-11-07 22:15:35 +01:00
|
|
|
CTexCache &TexCache=Core->GetTexCache();
|
|
|
|
|
|
|
|
glColor3f(0.5,0.5,0.5);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
for (int YLoop=0; YLoop<MapH; YLoop++)
|
|
|
|
{
|
|
|
|
for (int XLoop=0; XLoop<MapW; XLoop++)
|
|
|
|
{
|
|
|
|
sMapElem &ThisElem=Map.GetTile(XLoop,YLoop);
|
2000-11-15 22:22:40 +01:00
|
|
|
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
|
2000-11-07 22:15:35 +01:00
|
|
|
|
|
|
|
glLoadIdentity(); // Slow way, but good to go for the mo
|
2000-11-14 16:03:04 +01:00
|
|
|
glTranslatef(StartX+XLoop,StartY-YLoop,CamPos.z);
|
2000-11-07 22:15:35 +01:00
|
|
|
// ThisTile.Render();
|
|
|
|
int c=(XLoop+YLoop)&1;
|
|
|
|
glColor3f(c,1,1);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
BuildGLQuad(0,1,0,1,0);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-14 16:03:04 +01:00
|
|
|
void CLayerTile::Render3d(CCore *Core,Vec &CamPos)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
float XYDiv=GetLayerZPosDiv();
|
|
|
|
int MapW=Map.GetWidth();
|
|
|
|
int MapH=Map.GetHeight();
|
2000-11-14 16:03:04 +01:00
|
|
|
float StartX=CamPos.x/XYDiv;
|
|
|
|
float StartY=CamPos.y/XYDiv;
|
2000-11-07 22:15:35 +01:00
|
|
|
CTexCache &TexCache=Core->GetTexCache();
|
2000-11-17 00:08:54 +01:00
|
|
|
|
2000-11-07 22:15:35 +01:00
|
|
|
glColor3f(0.5,0.5,0.5);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
for (int YLoop=0; YLoop<MapH; YLoop++)
|
|
|
|
{
|
|
|
|
for (int XLoop=0; XLoop<MapW; XLoop++)
|
|
|
|
{
|
|
|
|
sMapElem &ThisElem=Map.GetTile(XLoop,YLoop);
|
2000-11-15 22:22:40 +01:00
|
|
|
if (ThisElem.Tile)
|
|
|
|
{ // Render Non Zero Tiles
|
|
|
|
CTile &ThisTile=Core->GetTile(ThisElem.Set,ThisElem.Tile);
|
|
|
|
|
|
|
|
glLoadIdentity(); // Slow way, but good to go for the mo
|
|
|
|
glTranslatef(StartX+XLoop,StartY-YLoop,CamPos.z);
|
2000-11-17 00:08:54 +01:00
|
|
|
ThisTile.Render(ThisElem.Flags);
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
2000-11-07 22:15:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-14 16:03:04 +01:00
|
|
|
void CLayerTile::RenderGrid(CCore *Core,Vec &CamPos)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
float XYDiv=GetLayerZPosDiv();
|
|
|
|
int MapW=Map.GetWidth();
|
|
|
|
int MapH=Map.GetHeight();
|
2000-11-14 16:03:04 +01:00
|
|
|
float StartX=CamPos.x/XYDiv;
|
|
|
|
float StartY=CamPos.y/XYDiv;
|
2000-11-07 22:15:35 +01:00
|
|
|
float OverVal=0.5;
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2000-11-14 16:03:04 +01:00
|
|
|
glTranslatef(StartX,StartY,CamPos.z);
|
2000-11-07 22:15:35 +01:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glNormal3f( 1,1,1);
|
|
|
|
glColor3ub(255,255,255);
|
|
|
|
|
|
|
|
for (int YLoop=0; YLoop<MapH+1; YLoop++)
|
|
|
|
{
|
|
|
|
glVertex3f( 0-OverVal, -YLoop+1, 0);
|
|
|
|
glVertex3f( MapW+OverVal, -YLoop+1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int XLoop=0; XLoop<MapW+1; XLoop++)
|
|
|
|
{
|
|
|
|
glVertex3f( XLoop, 0+1+OverVal, 0);
|
|
|
|
glVertex3f( XLoop, -MapH+1-OverVal, 0);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-14 16:03:04 +01:00
|
|
|
void CLayerTile::FindCursorPos(CCore *Core,CMapEditView *View,Vec &CamPos,CPoint &MousePos)
|
2000-11-07 22:15:35 +01:00
|
|
|
{
|
|
|
|
GLint Viewport[4];
|
|
|
|
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
|
|
|
|
int HitCount;
|
|
|
|
int TileID=0;
|
|
|
|
CPoint &CursorPos=Core->GetCursorPos();
|
|
|
|
|
|
|
|
float XYDiv=GetLayerZPosDiv();
|
|
|
|
int MapW=Map.GetWidth();
|
|
|
|
int MapH=Map.GetHeight();
|
2000-11-14 16:03:04 +01:00
|
|
|
float StartX=CamPos.x/XYDiv;
|
|
|
|
float StartY=CamPos.y/XYDiv;
|
2000-11-07 22:15:35 +01:00
|
|
|
|
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);
|
|
|
|
glLoadIdentity();
|
2000-11-14 16:03:04 +01:00
|
|
|
glTranslatef(StartX,StartY,CamPos.z);
|
2000-11-07 22:15:35 +01:00
|
|
|
|
|
|
|
for (int YLoop=0; YLoop<MapH; YLoop++)
|
|
|
|
{
|
|
|
|
for (int XLoop=0; XLoop<MapW; XLoop++)
|
|
|
|
{
|
|
|
|
glLoadName (TileID);
|
|
|
|
glBegin (GL_QUADS);
|
|
|
|
BuildGLQuad(XLoop,XLoop+1,-YLoop,-YLoop+1,0);
|
|
|
|
glEnd();
|
|
|
|
TileID++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HitCount= glRenderMode (GL_RENDER);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
CursorPos.x=CursorPos.y=-1;
|
|
|
|
|
|
|
|
// Process hits
|
|
|
|
|
|
|
|
GLuint *HitPtr=SelectBuffer;
|
|
|
|
|
|
|
|
if (HitCount) // Just take 1st
|
|
|
|
|
|
|
|
{
|
|
|
|
int HitID=HitPtr[3];
|
|
|
|
CursorPos.x=HitID%MapW;
|
|
|
|
CursorPos.y=HitID/MapW;
|
|
|
|
}
|
|
|
|
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-15 22:22:40 +01:00
|
|
|
ParamBar->Add(Frm->GetGfxToolBar(),IDD_GFXTOOLBAR,TRUE);
|
2000-11-14 16:03:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CLayerTile::UpdateGUI(CCore *Core)
|
|
|
|
{
|
2000-11-17 00:08:54 +01:00
|
|
|
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
|
|
|
|
CGfxToolBar *GfxDlg=(CGfxToolBar *)Frm->GetDialog(IDD_GFXTOOLBAR);
|
|
|
|
|
|
|
|
if (GfxDlg)
|
|
|
|
{
|
|
|
|
GfxDlg->ResetButtons();
|
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
GfxDlg->SetButtonState(CGfxToolBar::PAINT,TRUE);
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
GfxDlg->SetButtonState(CGfxToolBar::SELECT,TRUE);
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
GfxDlg->SetButtonState(CGfxToolBar::PICKER,TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GfxDlg->SetButtonState(CGfxToolBar::MIRRORX,Flag & MouseFlagMirrorX);
|
|
|
|
GfxDlg->SetButtonState(CGfxToolBar::MIRRORY,Flag & MouseFlagMirrorY);
|
|
|
|
}
|
|
|
|
|
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 MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
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 MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::SetFlag(int NewFlag)
|
|
|
|
{
|
|
|
|
Flag^=NewFlag;
|
|
|
|
return(TRUE);
|
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 MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
if (DownFlag)
|
|
|
|
Ret=Paint(TileBank.GetLTile(),CursorPos);
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
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 MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
if (DownFlag)
|
|
|
|
Ret=Paint(TileBank.GetRTile(),CursorPos);
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
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 MouseModeNone:
|
|
|
|
break;
|
|
|
|
case MouseModePaint:
|
|
|
|
if (nFlags & MK_LBUTTON)
|
|
|
|
Ret=Paint(TileBank.GetLTile(),CursorPos);
|
|
|
|
else
|
|
|
|
if (nFlags & MK_RBUTTON)
|
|
|
|
Ret=Paint(TileBank.GetRTile(),CursorPos);
|
|
|
|
break;
|
|
|
|
case MouseModeSelect:
|
|
|
|
break;
|
|
|
|
case MouseModePicker:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(Ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::MirrorX()
|
|
|
|
{
|
|
|
|
SetFlag(MouseFlagMirrorX);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL CLayerTile::MirrorY()
|
|
|
|
{
|
|
|
|
SetFlag(MouseFlagMirrorY);
|
|
|
|
return(TRUE);
|
2000-11-15 22:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-11-17 00:08:54 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-11-15 22:22:40 +01:00
|
|
|
BOOL CLayerTile::Paint(sMapElem &Tile,CPoint &CursorPos)
|
|
|
|
{
|
|
|
|
if (CursorPos.y==-1 || CursorPos.y==-1) return(FALSE); // Off Map?
|
|
|
|
if (Tile.Set==-1 || Tile.Tile==-1) return(FALSE); // Invalid tile?
|
|
|
|
|
2000-11-17 00:08:54 +01:00
|
|
|
Tile.Flags=Flag;
|
2000-11-15 22:22:40 +01:00
|
|
|
Map.SetTile(CursorPos.x,CursorPos.y,Tile);
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|