SBSPSS/Utils/MapEdit/TileSet.cpp

781 lines
18 KiB
C++
Raw Normal View History

2000-10-27 02:06:19 +02:00
/*********************/
/*** TileSet Stuph ***/
/*********************/
#include "stdafx.h"
2000-12-04 17:47:34 +01:00
#include <Vector3.h>
2000-10-27 02:06:19 +02:00
#include <gl\gl.h>
#include <gl\glu.h>
2000-11-14 16:03:04 +01:00
#include "GLEnabledView.h"
2000-10-27 02:06:19 +02:00
#include <Vector>
2001-01-23 22:53:48 +01:00
//#include <direct.h>
2000-12-04 17:47:34 +01:00
#include <GFName.hpp>
2000-10-27 02:06:19 +02:00
2000-11-06 21:24:11 +01:00
#include "Core.h"
2000-10-27 02:06:19 +02:00
#include "TileSet.h"
#include "GinTex.h"
#include "utils.h"
2000-11-14 16:03:04 +01:00
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
#include "MainFrm.h"
2000-11-28 15:34:42 +01:00
#include "LayerTileGui.h"
2000-11-14 16:03:04 +01:00
2001-01-23 22:53:48 +01:00
// Reserve slot 0 for collision :o)
char *ColFName="Collision.bmp";
2000-10-27 02:06:19 +02:00
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
/*** TileBank ****************************************************************/
2000-10-27 02:06:19 +02:00
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
const float TileBrowserGap=0.2f;
const float TileBrowserX0=0-TileBrowserGap/2;
const float TileBrowserX1=1+TileBrowserGap/2;
const float TileBrowserY0=0-TileBrowserGap/2;
const float TileBrowserY1=1+TileBrowserGap/2;
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
CTileBank::CTileBank()
{
2001-01-23 22:53:48 +01:00
GFName ExePath;
GString Filename;
// Get application path
#ifdef _DEBUG
ExePath="C:/Spongebob/tools/mapedit/mapedit/";
#else
char ExeFilename[2048];
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
ExePath=ExeFilename;
ExePath.File(0);
ExePath.Ext(0);
#endif
Filename=ExePath.FullName();
Filename+=ColFName;
2000-11-17 22:36:13 +01:00
LoadFlag=FALSE;
2001-01-23 22:53:48 +01:00
CurrentSet=0; LastSet=0;
2000-11-17 22:36:13 +01:00
for (int i=0; i<MaxBrush; i++) Brush[i].Delete();
LastCursorPos=CursorPos=-1;
ActiveBrush=0;
SelStart=-1;
2000-11-28 22:16:00 +01:00
SelEnd=-1;
2001-01-23 22:53:48 +01:00
TileSet.push_back(CTileSet(Filename,0));
LoadFlag=TRUE;
2000-11-06 21:24:11 +01:00
}
/*****************************************************************************/
CTileBank::~CTileBank()
{
}
2000-11-20 21:33:42 +01:00
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
void CTileBank::SetCollision(bool f)
{
if (f)
{ // Is collision
LastSet=CurrentSet;
CurrentSet=0;
}
else
{
CurrentSet=LastSet;
}
}
/*****************************************************************************/
void CTileBank::Load(CFile *File,int Version)
2000-11-20 21:33:42 +01:00
{
int ListSize;
2000-12-04 17:47:34 +01:00
GFName RootPath=File->GetFilePath();
2000-12-11 22:29:59 +01:00
GString FilePath;
FilePath=RootPath.Drive();
FilePath+=RootPath.Dir();
2000-12-04 17:47:34 +01:00
FilePath.Append('\\');
2000-11-20 21:33:42 +01:00
2000-12-11 22:29:59 +01:00
File->Read(&ListSize,sizeof(int));
File->Read(&CurrentSet,sizeof(int));
File->Read(&ActiveBrush,sizeof(int));
Brush[0].Load(File,Version);
Brush[1].Load(File,Version);
2001-01-23 22:53:48 +01:00
if (Version<2)
2000-12-04 17:47:34 +01:00
{
2001-01-23 22:53:48 +01:00
CurrentSet++;
2000-12-04 17:47:34 +01:00
}
2001-01-23 22:53:48 +01:00
// New Style rel storage
for (int i=0;i<ListSize;i++)
{
char c=1,RelName[256+64],FullName[256+64];
int Len=0;
while (c)
2000-12-04 17:47:34 +01:00
{
2001-01-23 22:53:48 +01:00
File->Read(&c,1);
RelName[Len++]=c;
2000-12-04 17:47:34 +01:00
}
2001-01-23 22:53:48 +01:00
RootPath.makeabsolute(FilePath,RelName,FullName);
AddTileSet(FullName);
2000-12-04 17:47:34 +01:00
}
2000-11-20 21:33:42 +01:00
}
/*****************************************************************************/
void CTileBank::Save(CFile *File)
{
int ListSize=TileSet.size();
2001-01-23 22:53:48 +01:00
int NewListSize=ListSize-1;
2000-12-11 22:29:59 +01:00
GString FilePath;
2000-12-04 17:47:34 +01:00
GFName RootPath=File->GetFilePath();
2000-12-11 22:29:59 +01:00
FilePath=RootPath.Drive();
FilePath+=RootPath.Dir();
2000-12-04 17:47:34 +01:00
FilePath.Append('\\');
2000-11-20 21:33:42 +01:00
2001-01-23 22:53:48 +01:00
File->Write(&NewListSize,sizeof(int));
2000-11-28 15:34:42 +01:00
File->Write(&CurrentSet,sizeof(int));
File->Write(&ActiveBrush,sizeof(int));
Brush[0].Save(File);
Brush[1].Save(File);
2000-11-20 21:33:42 +01:00
2001-01-23 22:53:48 +01:00
for (int i=1; i<ListSize; i++)
2000-11-28 15:34:42 +01:00
{
CTileSet &ThisSet=TileSet[i];
char Filename[256+64];
2000-11-20 21:33:42 +01:00
2000-12-04 17:47:34 +01:00
RootPath.makerelative(FilePath,ThisSet.GetFilename(),Filename);
File->Write(Filename,strlen(Filename)+1);
2000-11-28 15:34:42 +01:00
}
2000-11-21 22:27:55 +01:00
2000-11-20 21:33:42 +01:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
void CTileBank::AddTileSet(const char *Filename)
2000-11-06 21:24:11 +01:00
{
2000-11-28 15:34:42 +01:00
int ListSize=TileSet.size();
2000-11-29 18:07:57 +01:00
if (FindTileSet(Filename) ==-1)
{
TileSet.push_back(CTileSet(Filename,ListSize));
LoadFlag=TRUE;
}
}
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
int CTileBank::FindTileSet(const char *Filename)
2000-11-29 18:07:57 +01:00
{
int ListSize=TileSet.size();
CTileSet FindSet(Filename,ListSize);
for (int i=0; i<ListSize; i++)
{
CTileSet &ThisSet=TileSet[i];
2000-12-04 17:47:34 +01:00
if (IsStrSame((char*)FindSet.GetName(),(char*)ThisSet.GetName(),-1)) return(i);
2000-11-29 18:07:57 +01:00
}
return(-1);
2000-11-06 21:24:11 +01:00
}
/*****************************************************************************/
void CTileBank::LoadTileSets(CCore *Core)
{
2000-11-28 15:34:42 +01:00
int ListSize=TileSet.size();
2000-11-06 21:24:11 +01:00
2000-11-28 15:34:42 +01:00
for (int i=0;i<ListSize;i++)
{
CTileSet &ThisSet=TileSet[i];
2000-11-06 21:24:11 +01:00
2000-11-28 15:34:42 +01:00
if (!ThisSet.IsLoaded()) ThisSet.Load(Core);
}
LoadFlag=FALSE;
2000-11-06 21:24:11 +01:00
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
void CTileBank::Delete()
{
2000-12-11 22:29:59 +01:00
int ListSize=TileSet.size();
// Remap Brushes
for (int i=0; i<MaxBrush; i++)
{
Brush[i].DeleteSet(CurrentSet);
}
for (int Set=CurrentSet; Set<ListSize; Set++)
{
for (int i=0; i<MaxBrush; i++)
{
2001-01-23 22:53:48 +01:00
Brush[i].RemapSet(Set,Set);
2000-12-11 22:29:59 +01:00
}
}
TileSet.erase(TileSet.begin()+CurrentSet);
CurrentSet=0;
2000-11-29 18:07:57 +01:00
}
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
void CTileBank::Reload()
{
2000-11-28 15:34:42 +01:00
int ListSize=TileSet.size();
2000-11-14 16:03:04 +01:00
2000-11-28 15:34:42 +01:00
for (int i=0; i<ListSize; i++)
{
TileSet[i].Purge();
}
2000-11-14 16:03:04 +01:00
2000-11-28 15:34:42 +01:00
LoadFlag=TRUE;
2000-11-14 16:03:04 +01:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
CTile &CTileBank::GetTile(int Bank,int Tile)
{
2000-11-29 18:07:57 +01:00
ASSERT(Bank>=0 && Tile>=0);
2000-11-28 15:34:42 +01:00
return(TileSet[Bank].GetTile(Tile));
2000-11-06 21:24:11 +01:00
}
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
void CTileBank::RenderSet(CCore *Core,Vector3 &CamPos,BOOL Is3d)
2000-11-14 16:03:04 +01:00
{
2000-11-15 22:22:40 +01:00
if (!TileSet.size()) return; // No tiles, return
2000-11-14 16:03:04 +01:00
if (Is3d)
{
glEnable(GL_DEPTH_TEST);
2000-12-29 23:20:38 +01:00
TileSet[CurrentSet].Render(Core,CamPos,GetLBrush(),GetRBrush(),TRUE);
2000-11-14 16:03:04 +01:00
glDisable(GL_DEPTH_TEST);
}
else
{
2000-12-29 23:20:38 +01:00
TileSet[CurrentSet].Render(Core,CamPos,GetLBrush(),GetRBrush(),FALSE);
2000-11-14 16:03:04 +01:00
}
2000-11-17 22:36:13 +01:00
TileSet[CurrentSet].RenderCursor(CamPos,CursorPos,SelStart,SelEnd);
if (Core->IsGridOn()) TileSet[CurrentSet].RenderGrid(CamPos);
2000-11-14 16:03:04 +01:00
}
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
void CTileBank::FindCursorPos(CCore *Core,CMapEditView *View,Vector3 &CamPos,CPoint &MousePos)
2000-11-14 16:03:04 +01:00
{
2000-11-15 22:22:40 +01:00
if (!TileSet.size()) return; // No tiles, return
2000-11-14 16:03:04 +01:00
2000-11-15 22:22:40 +01:00
CursorPos=TileSet[CurrentSet].FindCursorPos(Core,View,CamPos,MousePos);
2000-11-17 22:36:13 +01:00
SelEnd=CursorPos;
2000-11-14 16:03:04 +01:00
}
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
/*** Gui *********************************************************************/
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
void CTileBank::UpdateGUI(CCore *Core,BOOL IsTileView)
2000-11-14 16:03:04 +01:00
{
2000-11-28 15:34:42 +01:00
CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd();
CLayerTileGUI *Dlg=(CLayerTileGUI*)Frm->GetDialog(IDD_LAYERTILE_GUI);
int ListSize=TileSet.size();
2000-11-14 16:03:04 +01:00
2000-11-28 15:34:42 +01:00
if (Dlg)
2000-11-14 16:03:04 +01:00
{
2000-11-28 15:34:42 +01:00
Dlg->m_List.ResetContent();
2001-01-23 22:53:48 +01:00
if (ListSize-1)
2000-11-28 15:34:42 +01:00
{
2001-01-23 22:53:48 +01:00
for (int i=1; i<ListSize; i++)
2000-11-28 15:34:42 +01:00
{
Dlg->m_List.AddString(TileSet[i].GetName());
}
2001-01-23 22:53:48 +01:00
Dlg->m_List.SetCurSel(CurrentSet-1);
2000-11-28 15:34:42 +01:00
}
else
{
IsTileView=FALSE;
}
Dlg->m_List.EnableWindow(IsTileView);
2000-11-14 16:03:04 +01:00
}
2001-01-23 22:53:48 +01:00
2000-11-14 16:03:04 +01:00
}
/*****************************************************************************/
2000-11-15 22:22:40 +01:00
/*** Functions ***************************************************************/
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-11-17 22:36:13 +01:00
BOOL CTileBank::Select(int BrushID,BOOL DownFlag)
{
if (DownFlag && SelStart==-1)
{
2000-11-28 22:16:00 +01:00
if (CursorPos<0) return(FALSE);
2000-11-17 22:36:13 +01:00
SelStart=CursorPos;
2000-11-28 22:16:00 +01:00
if (CursorPos==0)
{
SetBrush(GetBrush(BrushID));
SelStart=-1;
TRACE0("Selected Blank\n");
}
2000-11-17 22:36:13 +01:00
}
else
if (!DownFlag && SelStart!=-1)
{
if (CursorPos==-1) return(SelectCancel());
SetBrush(GetBrush(BrushID));
SelStart=-1;
TRACE0("END SEL\n");
}
return(TRUE);
}
/*****************************************************************************/
void CTileBank::SetBrush(CMap &ThisBrush)
2000-11-14 16:03:04 +01:00
{
2000-11-28 22:16:00 +01:00
int BW=TileSet[CurrentSet].GetTileBrowserWidth();
CPoint S=IDToPoint(SelStart-1,BW);
CPoint E=IDToPoint(SelEnd-1,BW);
int Width=abs(E.x-S.x)+1;
int Height=abs(E.y-S.y)+1;
2000-11-17 22:36:13 +01:00
sMapElem ThisElem;
int MaxTile=TileSet[CurrentSet].GetTileCount();
2000-11-28 22:16:00 +01:00
// if (PointToID(End,BW)>=MaxTile) SelectCancel(); // Invalid selection
2000-11-17 22:36:13 +01:00
ThisElem.Set=CurrentSet;
ThisElem.Flags=0;
ThisBrush.Delete();
ThisBrush.SetSize(Width,Height);
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
2000-11-28 22:16:00 +01:00
ThisElem.Tile=SelStart+X+(Y*BW);
2000-11-29 18:07:57 +01:00
if (!IsTileValid(CurrentSet,ThisElem.Tile))
{
ThisElem.Tile=-1;
}
ThisBrush.Set(X,Y,ThisElem,TRUE);
2000-11-17 22:36:13 +01:00
}
2000-11-15 22:22:40 +01:00
}
2000-11-17 22:36:13 +01:00
}
2000-11-14 16:03:04 +01:00
2000-11-17 22:36:13 +01:00
/*****************************************************************************/
BOOL CTileBank::SelectCancel()
{
SelStart=-1;
TRACE0("Select Cancelled\n");
2000-11-15 22:22:40 +01:00
return(TRUE);
2000-11-14 16:03:04 +01:00
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
BOOL CTileBank::IsTileValid(int Set,int Tile)
{
2000-12-11 22:29:59 +01:00
if (Set<0 || Tile<0) return(FALSE);
2001-01-04 22:53:14 +01:00
if (Tile==0) return(TRUE);
2000-12-11 22:29:59 +01:00
ASSERT(Set<TileSet.size());
2000-11-29 18:07:57 +01:00
return(TileSet[Set].IsTileValid(Tile));
}
/*****************************************************************************/
BOOL CTileBank::IsTileValidGB(int Set,int Tile)
{
2000-12-11 22:29:59 +01:00
if (Set<0 || Tile<0) return(FALSE);
2000-11-29 18:07:57 +01:00
return(TileSet[Set].IsTileValidGB(Tile));
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*** TileSet *****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-01-23 22:53:48 +01:00
CTileSet::CTileSet(const char *_Filename,int Idx)
2000-10-27 02:06:19 +02:00
{
2000-12-04 17:47:34 +01:00
Filename=_Filename;
2000-11-22 23:08:47 +01:00
2000-11-15 22:22:40 +01:00
Loaded=FALSE;
2000-11-17 22:36:13 +01:00
SetNumber=Idx;
2000-10-27 02:06:19 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CTileSet::~CTileSet()
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2000-11-06 21:24:11 +01:00
void CTileSet::Load(CCore *Core)
2000-10-27 02:06:19 +02:00
{
2000-12-04 17:47:34 +01:00
GString Ext=Filename.Ext();
Ext.Upper();
2000-11-22 23:08:47 +01:00
2000-12-04 17:47:34 +01:00
if (Ext=="GIN")
2000-11-22 23:08:47 +01:00
{
Load3d(Core);
}
else
{
Load2d(Core);
}
Loaded=TRUE;
}
/*****************************************************************************/
2000-11-30 23:17:55 +01:00
2000-11-22 23:08:47 +01:00
void CTileSet::Load2d(CCore *Core)
{
2000-11-28 00:07:07 +01:00
CTexCache &TexCache=Core->GetTexCache();
2000-11-22 23:08:47 +01:00
2000-12-04 17:47:34 +01:00
int TexID=TexCache.ProcessTexture((char*)Filename.FullName(),0);
2000-11-30 23:17:55 +01:00
sTex &ThisTex=TexCache.GetTex(TexID);
2000-11-28 00:07:07 +01:00
2000-11-30 23:17:55 +01:00
int Width=ThisTex.TexWidth/16;
int Height=ThisTex.TexHeight/16;
2000-11-28 00:07:07 +01:00
2000-12-14 17:38:34 +01:00
// TRACE3("Load 2d TileBank %s (%i,%i)\n",Filename.FullName(),Width,Height);
2000-11-28 00:07:07 +01:00
2000-11-28 22:16:00 +01:00
Tile.push_back(CTile(0)); // Insert Blank
2000-11-28 00:07:07 +01:00
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
2000-11-30 23:17:55 +01:00
Tile.push_back(CTile(Core,this,TexID,X,Y));
2000-11-28 00:07:07 +01:00
}
}
2000-11-28 22:16:00 +01:00
TileBrowserWidth=Width;
2000-11-28 00:07:07 +01:00
}
2000-11-22 23:08:47 +01:00
/*****************************************************************************/
void CTileSet::Load3d(CCore *Core)
{
2000-11-06 21:24:11 +01:00
CScene Scene;
2000-10-27 02:06:19 +02:00
2000-12-04 17:47:34 +01:00
Scene.Load(Filename.FullName());
2000-10-27 02:06:19 +02:00
2000-10-27 20:18:30 +02:00
CNode &ThisNode=Scene.GetSceneNode(0);
int ChildCount=ThisNode.GetPruneChildCount();
2000-11-28 00:07:07 +01:00
Tile.push_back(CTile(0)); // Insert Blank
2000-11-28 22:16:00 +01:00
2000-10-27 20:18:30 +02:00
for (int Child=0; Child<ChildCount; Child++)
2000-10-27 02:06:19 +02:00
{
2000-11-15 22:22:40 +01:00
Tile.push_back(CTile(Core,this,Scene,ThisNode.PruneChildList[Child]));
2000-10-27 02:06:19 +02:00
}
2000-11-28 22:16:00 +01:00
TileBrowserWidth=DefTileBrowserWidth;
2001-01-17 22:52:08 +01:00
TRACE1("%i\n",Tile.size());
2000-10-27 20:18:30 +02:00
2000-10-27 02:06:19 +02:00
}
2000-11-06 21:24:11 +01:00
/*****************************************************************************/
2000-11-14 16:03:04 +01:00
void CTileSet::Purge()
{
int ListSize=Tile.size();
for (int i=0; i<ListSize; i++)
{
Tile[i].Purge();
}
Tile.clear();
Loaded=FALSE;
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
CPoint CTileSet::GetTilePos(int ID)
{
if (ID==0)
return(CPoint(-1,-1));
else
return(IDToPoint(ID-1,TileBrowserWidth));
}
2000-11-30 23:17:55 +01:00
/*****************************************************************************/
BOOL CTileSet::IsTileValid(int No)
{
2001-01-17 22:52:08 +01:00
// ASSERT(No<Tile.size());
if (No>Tile.size()) return(FALSE);
2000-12-29 23:20:38 +01:00
{return(Tile[No].IsValid());}
2000-11-30 23:17:55 +01:00
}
/*****************************************************************************/
BOOL CTileSet::IsTileValidGB(int No)
{
2001-01-17 22:52:08 +01:00
// ASSERT(No<Tile.size());
if (No>Tile.size()) return(FALSE);
2000-11-30 23:17:55 +01:00
return(Tile[No].IsValidGB());
}
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-12-29 23:20:38 +01:00
void CTileSet::Render(CCore *Core,Vector3 &CamPos,CMap &LBrush,CMap &RBrush,BOOL Render3d)
2000-11-14 16:03:04 +01:00
{
int ListSize=Tile.size();
int TileID=0;
2000-11-17 22:36:13 +01:00
sMapElem ThisElem;
int SelFlag;
2000-11-29 18:07:57 +01:00
BOOL ValidTile=TRUE;
2001-01-03 23:11:13 +01:00
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
2000-11-17 22:36:13 +01:00
ThisElem.Flags=0;
ThisElem.Set=SetNumber;
2000-11-14 16:03:04 +01:00
glMatrixMode(GL_MODELVIEW);
2000-12-29 23:20:38 +01:00
glPushMatrix();
2000-11-14 16:03:04 +01:00
while(TileID!=ListSize)
{
2000-11-29 18:07:57 +01:00
CPoint Pos=GetTilePos(TileID);
2000-12-29 23:20:38 +01:00
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
2000-11-28 22:16:00 +01:00
2000-11-14 16:03:04 +01:00
glLoadIdentity();
2000-12-29 23:20:38 +01:00
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
2000-11-14 16:03:04 +01:00
2000-11-29 18:07:57 +01:00
ValidTile=IsTileValid(TileID);
if (TileID && ValidTile)
{
2000-12-01 22:08:54 +01:00
glColor3f(1,1,1);
2000-11-29 18:07:57 +01:00
Tile[TileID].Render(0,Render3d);
}
// Selection
2000-11-17 22:36:13 +01:00
ThisElem.Tile=TileID;
SelFlag=0;
if (LBrush.DoesContainTile(ThisElem)) SelFlag|=1;
if (RBrush.DoesContainTile(ThisElem)) SelFlag|=2;
if (SelFlag)
{
glBegin(GL_QUADS);
switch(SelFlag)
{
case 1: // L
glColor4f(1,0,0,0.5);
2000-12-29 23:20:38 +01:00
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
2000-11-17 22:36:13 +01:00
break;
case 2: // R
glColor4f(0,0,1,0.5);
2000-12-29 23:20:38 +01:00
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
2000-11-17 22:36:13 +01:00
break;
case 3: // LR
glColor4f(1,0,0,0.5);
2000-12-29 23:20:38 +01:00
BuildGLQuad(TileBrowserX0,0.5,TileBrowserY0,TileBrowserY1,0.01f);
2000-11-17 22:36:13 +01:00
glColor4f(0,0,1,0.5);
2000-12-29 23:20:38 +01:00
BuildGLQuad(0.5,TileBrowserX1,TileBrowserY0,TileBrowserY1,0.01f);
2000-11-17 22:36:13 +01:00
break;
}
2000-11-29 18:07:57 +01:00
glEnd();
}
// Invalid tile?
if (!ValidTile)
{
glBegin(GL_LINES);
2000-12-01 22:08:54 +01:00
glColor3f(1,1,1);
2000-11-29 18:07:57 +01:00
glVertex3f( TileBrowserX0,TileBrowserY0,0);
glVertex3f( TileBrowserX1,TileBrowserY1,0);
glVertex3f( TileBrowserX1,TileBrowserY0,0);
glVertex3f( TileBrowserX0,TileBrowserY1,0);
2000-11-17 22:36:13 +01:00
glEnd();
}
2000-11-30 23:17:55 +01:00
// Draw Box around bloody Blank so you can see it
if (!TileID)
{
CPoint Pos=GetTilePos(TileID);
glBegin(GL_LINES);
2000-12-01 22:08:54 +01:00
glColor3f(1,1,1);
2000-11-30 23:17:55 +01:00
glVertex3f( TileBrowserX0,TileBrowserY0,0);
glVertex3f( TileBrowserX1,TileBrowserY0,0);
2000-11-15 22:22:40 +01:00
2000-11-30 23:17:55 +01:00
glVertex3f( TileBrowserX0,TileBrowserY1,0);
glVertex3f( TileBrowserX1,TileBrowserY1,0);
glVertex3f( TileBrowserX0,TileBrowserY0,0);
glVertex3f( TileBrowserX0,TileBrowserY1,0);
glVertex3f( TileBrowserX1,TileBrowserY0,0);
glVertex3f( TileBrowserX1,TileBrowserY1,0);
glEnd();
}
2000-11-29 18:07:57 +01:00
2000-11-14 16:03:04 +01:00
TileID++;
}
2000-12-29 23:20:38 +01:00
glPopMatrix();
2000-11-14 16:03:04 +01:00
}
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
void CTileSet::RenderCursor(Vector3 &CamPos,int CursorPos,int SelStart,int SelEnd)
2000-11-17 22:36:13 +01:00
{
2000-12-29 23:20:38 +01:00
int ListSize=Tile.size();
CPoint Start,End;
int MaxTile=Tile.size();
2001-01-03 23:11:13 +01:00
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
2000-11-28 22:16:00 +01:00
if (CursorPos<-1 || CursorPos>ListSize) return;
2000-11-17 22:36:13 +01:00
if (SelStart==-1)
{
2000-11-29 18:07:57 +01:00
Start=GetTilePos(CursorPos);
2000-11-17 22:36:13 +01:00
End=Start;
}
else
{
2000-11-28 22:16:00 +01:00
CPoint S=IDToPoint(SelStart-1,TileBrowserWidth);
CPoint E=IDToPoint(SelEnd-1,TileBrowserWidth);
2000-11-17 22:36:13 +01:00
Start=CPoint( min(S.x,E.x), min(S.y,E.y));
End=CPoint( max(S.x,E.x), max(S.y,E.y));
if (PointToID(End,TileBrowserWidth)>=MaxTile) return; // Invalid selection
}
glMatrixMode(GL_MODELVIEW);
2000-12-29 23:20:38 +01:00
glPushMatrix();
2000-11-17 22:36:13 +01:00
for (int Y=Start.y; Y<=End.y; Y++)
{
for (int X=Start.x; X<=End.x; X++)
{
2000-12-29 23:20:38 +01:00
float XPos=(float)X*(1+TileBrowserGap);
float YPos=(float)Y*(1+TileBrowserGap);
2000-11-17 22:36:13 +01:00
glLoadIdentity();
2000-12-29 23:20:38 +01:00
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
2000-11-17 22:36:13 +01:00
glBegin(GL_QUADS);
glColor4f(1,1,0,0.5);
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
glEnd();
}
}
2000-12-29 23:20:38 +01:00
glPopMatrix();
2000-11-17 22:36:13 +01:00
}
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
void CTileSet::RenderGrid(Vector3 &CamPos)
2000-11-17 22:36:13 +01:00
{
int ListSize=Tile.size();
2000-11-30 23:17:55 +01:00
int TileID=1; // Dont bother with blank, its sorted
2001-01-03 23:11:13 +01:00
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
2000-11-17 22:36:13 +01:00
glMatrixMode(GL_MODELVIEW);
2000-12-29 23:20:38 +01:00
glPushMatrix();
2000-11-17 22:36:13 +01:00
while(TileID!=ListSize)
{
2000-11-29 18:07:57 +01:00
CPoint Pos=GetTilePos(TileID);
2000-12-29 23:20:38 +01:00
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
2000-11-17 22:36:13 +01:00
2000-12-29 23:20:38 +01:00
glLoadIdentity();
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
2000-11-17 22:36:13 +01:00
glBegin(GL_LINES);
2000-12-01 22:08:54 +01:00
glColor3f(1,1,1);
2000-11-17 22:36:13 +01:00
glVertex3f( TileBrowserX0,TileBrowserY0,0);
glVertex3f( TileBrowserX1,TileBrowserY0,0);
glVertex3f( TileBrowserX0,TileBrowserY1,0);
glVertex3f( TileBrowserX1,TileBrowserY1,0);
glVertex3f( TileBrowserX0,TileBrowserY0,0);
glVertex3f( TileBrowserX0,TileBrowserY1,0);
glVertex3f( TileBrowserX1,TileBrowserY0,0);
glVertex3f( TileBrowserX1,TileBrowserY1,0);
glEnd();
TileID++;
}
2000-12-29 23:20:38 +01:00
glPopMatrix();
2000-11-17 22:36:13 +01:00
}
2000-11-14 16:03:04 +01:00
/*****************************************************************************/
2000-12-04 17:47:34 +01:00
int CTileSet::FindCursorPos(CCore *Core,CMapEditView *View,Vector3 &CamPos,CPoint &MousePos)
2000-11-14 16:03:04 +01:00
{
int ListSize=Tile.size();
GLint Viewport[4];
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
int HitCount;
int TileID=0;
2001-01-03 23:11:13 +01:00
//float Scale=1.0f/(float)TileBrowserWidth/CamPos.z;
float Scale=CamPos.z/(float)TileBrowserWidth/2.0;
2000-11-14 16:03:04 +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-14 16:03:04 +01:00
while(TileID!=ListSize)
{
2000-11-29 18:07:57 +01:00
CPoint Pos=GetTilePos(TileID);
2000-12-29 23:20:38 +01:00
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
2000-11-14 16:03:04 +01:00
glLoadIdentity();
2000-12-29 23:20:38 +01:00
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
2000-11-14 16:03:04 +01:00
glLoadName (TileID);
glBegin (GL_QUADS);
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
glEnd();
TileID++;
}
HitCount= glRenderMode (GL_RENDER);
2000-12-29 23:20:38 +01:00
glPopMatrix();
2000-11-14 16:03:04 +01:00
glMatrixMode(GL_PROJECTION);
glPopMatrix();
// Process hits
GLuint *HitPtr=SelectBuffer;
2000-11-28 22:16:00 +01:00
TileID=-2;
2000-11-14 16:03:04 +01:00
if (HitCount) // Just take 1st
{
TileID=HitPtr[3];
}
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
2000-11-17 22:36:13 +01:00
2000-11-14 16:03:04 +01:00
return(TileID);
}