This commit is contained in:
Daveo 2001-03-22 20:49:58 +00:00
parent 3ca7299ba4
commit f201ec651f
22 changed files with 900 additions and 655 deletions

View File

@ -9,30 +9,30 @@ enum CmdMsg
{
CmdMsg_None=0,
// Core
CmdMsg_ToggleSubView,
CmdMsg_ToggleGrid,
CmdMsg_Toggle2d,
CmdMsg_ZoomIn,
CmdMsg_ZoomOut,
CmdMsg_ResetView,
CmdMsg_SetLayer,
CmdMsg_AddLayer,
CmdMsg_DeleteLayer,
CmdMsg_ToggleSubView, // 1
CmdMsg_ToggleGrid, // 2
CmdMsg_Toggle2d, // 3
CmdMsg_ZoomIn, // 4
CmdMsg_ZoomOut, // 5
CmdMsg_ResetView, // 6
CmdMsg_SetLayer, // 7
CmdMsg_AddLayer, // 8
CmdMsg_DeleteLayer, // 9
// Generic
CmdMsg_SetMode,
CmdMsg_Copy,
CmdMsg_Paste,
CmdMsg_SubViewLoad,
CmdMsg_SubViewDelete,
CmdMsg_SubViewUpdate,
CmdMsg_SubViewSet,
CmdMsg_SetMode, // 10
CmdMsg_Copy, // 11
CmdMsg_Paste, // 12
CmdMsg_SubViewLoad, // 13
CmdMsg_SubViewDelete, // 14
CmdMsg_SubViewUpdate, // 15
CmdMsg_SubViewSet, // 16
// TileLayer/TileBank
CmdMsg_MirrorX,
CmdMsg_MirrorY,
CmdMsg_SetColFlag,
CmdMsg_ActiveBrushLeft,
CmdMsg_ActiveBrushRight,
CmdMsg_MirrorX, // 17
CmdMsg_MirrorY, // 18
CmdMsg_SetColFlag, // 19
CmdMsg_ActiveBrushLeft, // 20
CmdMsg_ActiveBrushRight, // 21
};
#endif
/*****************************************************************************/

View File

@ -15,11 +15,12 @@
#include "MainFrm.h"
#include "Core.h"
#include "Elem.h"
#include "Layer.h"
#include "LayerTile.h"
#include "LayerCollision.h"
#include "LayerShade.h"
#include "LayerItem.h"
#include "LayerThing.h"
#include "utils.h"
#include "Export.h"
@ -28,6 +29,8 @@
#include "GUINewMap.h"
GString IconzFileName="Iconz.bmp";
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
@ -41,12 +44,20 @@ CCore::CCore()
CurrentView=NULL;
CursorPos.x=CursorPos.y=0;
CurrentLayer=0;
GString Filename;
IconBank=new CElemBank(16,16,false,false);
GetExecPath(Filename);
Filename+=IconzFileName;
IconBank->AddSet(Filename);
}
/*****************************************************************************/
CCore::~CCore()
{
IconBank->CleanUp();
delete IconBank;
int ListSize=Layer.size();
for (int i=0; i<ListSize; i++) delete Layer[i];
}
@ -101,7 +112,7 @@ Vector3 DuffVector;
TRACE1("Load Version %i\n",Version);
File->Read(&MapCam,sizeof(Vector3));
if (Version<FileVersion)
if (Version<4)
{
File->Read(&MapCamOfs,sizeof(Vector3));
File->Read(&DuffVector,sizeof(Vector3));
@ -134,7 +145,7 @@ int LayerCount;
AddLayer(new CLayerShade(File,Version));
break;
case LAYER_TYPE_ITEM:
AddLayer(new CLayerItem(File,Version));
AddLayer(new CLayerThing(File,Version));
break;
default:
ASSERT(!"poos");
@ -172,7 +183,6 @@ BOOL F;
F=GridFlag; File->Write(&F,sizeof(BOOL));
F=Is3dFlag; File->Write(&F,sizeof(BOOL));
// Layers
int LayerCount=Layer.size();
File->Write(&LayerCount,sizeof(int));
@ -185,12 +195,6 @@ int LayerCount=Layer.size();
Layer[i]->Save(File);
}
GetTileBank()->Save(File);
/*
CString a=File->GetFilePath();
char Txt[256];
sprintf(Txt,"%s",a);
Export(Txt);
*/
}
/*****************************************************************************/
@ -217,44 +221,32 @@ Vector3 &ThisCam=GetCam();
UpdateAll();
return;
}
// if (GetTileBank()->NeedLoad()) GetTileBank()->LoadAllSets(this);
if (IconBank->NeedLoad()) IconBank->LoadAllSets(this);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
if (IsSubView() || CurrentLayer->IsUnique())
{
CurrentLayer->Render(this,ThisCam,Is3dFlag);
if (GridFlag) CurrentLayer->RenderGrid(this,ThisCam,true);
CurrentLayer->FindCursorPos(this,GetCam(),CurrentMousePos);
}
else
{
RenderLayers();
}
CurrentLayer->RenderCursor(this,ThisCam,Is3dFlag);
// Get Cursor Pos
LastCursorPos=CursorPos;
CurrentLayer->FindCursorPos(this,GetCam(),CurrentMousePos);
RenderLayers(IsSubView() || CurrentLayer->IsUnique());
}
/*****************************************************************************/
void CCore::RenderLayers()
void CCore::RenderLayers(bool OneShot)
{
Vector3 &ThisCam=GetCam();
int ListSize=Layer.size();
int StartLayer,EndLayer;
if (OneShot)
{
StartLayer=ActiveLayer;
EndLayer=StartLayer+1;
}
else
{
StartLayer=0;
EndLayer=ListSize;
// while (Layer[StartLayer]->IsUnique()) StartLayer++;
// if (Layer[ActiveLayer]->IsUnique())
// {
// StartLayer=ActiveLayer;
// EndLayer=StartLayer+1;
// }
while (Layer[StartLayer]->IsUnique()) StartLayer++;
}
for (int i=StartLayer; i<EndLayer; i++)
{
@ -264,6 +256,10 @@ int StartLayer,EndLayer;
if (GridFlag) Layer[i]->RenderGrid(this,ThisCam,i==ActiveLayer);
}
}
CurrentLayer->RenderCursor(this,ThisCam,Is3dFlag);
// Get Cursor Pos
LastCursorPos=CursorPos;
CurrentLayer->FindCursorPos(this,GetCam(),CurrentMousePos);
}
@ -419,7 +415,7 @@ CMainFrame *Frm=(CMainFrame*)AfxGetMainWnd();
CGUIMultiBar *ParamBar=Frm->GetParamBar();
GUIRemoveAll();
GUIAdd(LayerList,IDD_LAYER_LIST_DIALOG);
GUIAdd(LayerList,IDD_LAYER_LIST);
CurrentLayer->GUIInit(this);
GUIUpdate();
}
@ -513,7 +509,7 @@ int Idx;
Idx=AddLayer(new CLayerShade(SubType, Width,Height));
break;
case LAYER_TYPE_ITEM:
Idx=AddLayer(new CLayerItem(SubType, Width,Height));
Idx=AddLayer(new CLayerThing(SubType, Width,Height));
break;
default:
ASSERT(!"AddLayer - Invalid Layer Type");
@ -669,6 +665,19 @@ Vector3 &ThisCam=GetCam();
ThisCam=DefaultCamPos;
UpdateView();
}
/*****************************************************************************/
void CCore::GetExecPath(GString &Path)
{
// Get application path
char ExeFilename[2048];
GFName Exe;
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
Exe=ExeFilename;
Exe.File(0);
Exe.Ext(0);
Path=Exe.FullName();
}
/*****************************************************************************/
/*** GUI *********************************************************************/

View File

@ -19,7 +19,7 @@
#include "Layer.h"
#include "LayerTile.h"
const s32 FileVersion=4;
const s32 FileVersion=5;
#define SCREEN_MAP_WIDTH 30
#define SCREEN_MAP_HEIGHT 20
@ -41,7 +41,7 @@ public:
void Save(CFile *File);
bool Question(char *Txt);
void Render(bool ForceRender=FALSE);
void RenderLayers();
void RenderLayers(bool OneShot=false);
void Export(char *Filename);
// View Stuff
@ -114,7 +114,8 @@ public:
void PasteSelection();
void ResetView();
CElemBank *GetIconBank() {return(IconBank);}
void GetExecPath(GString &Path);
private:
CMapEditView *CurrentView;
CPoint CurrentMousePos,LastMousePos;
@ -135,7 +136,9 @@ private:
bool SpareFlag;
bool GridFlag;
bool Is3dFlag;
CElemBank *IconBank;
};
/*****************************************************************************/

View File

@ -6,6 +6,7 @@
#include <Vector3.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
#include <Vector>
#include <GFName.hpp>
@ -15,7 +16,25 @@
#include "GinTex.h"
#include "utils.h"
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
#include "MainFrm.h"
#include "GUITileBank.h"
const Vector3 DefOfs(+0.5f,0,+4.0f);
/*****************************************************************************/
// All Elems MUST run from 0,0 ->
/*****************************************************************************/
const float ElemBrowserGap=0.2f;
const float ElemBrowserX0=0-ElemBrowserGap/2;
const float ElemBrowserX1=1+ElemBrowserGap/2;
const float ElemBrowserY0=0-ElemBrowserGap/2;
const float ElemBrowserY1=1+ElemBrowserGap/2;
/*****************************************************************************/
const float XFlipMtx[]=
@ -66,10 +85,11 @@ GFName Path=Filename;
Type=ElemType3d;
TexXOfs=-1;
TexYOfs=-1;
Ofs.Zero();
Build3dElem(TexCache,ThisScene,Node);
Calc3dSize();
Ofs.x=+0.5f; Ofs.y=0; Ofs.z=+4.0f;
Build3dDrawList(TexCache,DrawList[ElemType3d]);
Ofs.Zero();
Create2dTexture(TexCache,Path.File(),Node);
Build2dDrawList(TexCache,DrawList[ElemType2d]);
if (!ValidFlag) CreateInvalidTileGfx();
@ -78,7 +98,7 @@ GFName Path=Filename;
/*****************************************************************************/
// 2d Elem (From Bmp File)
CElem::CElem(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs,int Width,int Height)
CElem::CElem(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs,int Width,int Height,bool Centre)
{
CTexCache &TexCache=Core->GetTexCache();
GFName Path=Filename;
@ -91,8 +111,15 @@ GFName Path=Filename;
Type=ElemType2d;
TexXOfs=XOfs;
TexYOfs=YOfs;
Build2dElem(Core,Path.File(),TexID);
Ofs.Zero();
if (Centre)
{
Ofs.x=0.5-UnitWidth/2;
// Ofs.y=0.5-UnitHeight/2;
Ofs.y=-1.0f;
}
Build2dElem(Core,Path.File(),TexID);
Build3dDrawList(TexCache,DrawList[ElemType3d]);
Create2dTexture(TexCache,Path.File(),TexID);
Build2dDrawList(TexCache,DrawList[ElemType2d]);
@ -108,10 +135,15 @@ void CElem::CleanUp()
/*****************************************************************************/
void CElem::Build2dElem(CCore *Core,const char *Filename,int TexID)
{
const Vector3 P0(0.0f,0.0f,0.0f);
const Vector3 P1(1.0f,0.0f,0.0f);
const Vector3 P2(0.0f,1.0f,0.0f);
const Vector3 P3(1.0f,1.0f,0.0f);
float X0=0;
float X1=+UnitWidth;
float Y0=0;
float Y1=+UnitHeight;
Vector3 P0(X0,Y0,0);
Vector3 P1(X1,Y0,0);
Vector3 P2(X0,Y1,0);
Vector3 P3(X1,Y1,0);
int ListSize=TriList.size();
TriList.resize(ListSize+2);
@ -121,13 +153,14 @@ sTriFace &Tri1=TriList[ListSize+1];
CTexCache &TexCache=Core->GetTexCache();
sTex &ThisTex=TexCache.GetTex(TexID);
float u0,u1,v0,v1;
u0=(TexXOfs)*ThisTex.dW;
u1=u0+ThisTex.dW;
float dU=1.0/((float)ThisTex.TexWidth/(float)ElemWidth);
float dV=1.0/((float)ThisTex.TexHeight/(float)ElemHeight);
v0=(((ThisTex.TexHeight/UnitSize)-(TexYOfs+1))*ThisTex.dH);
v1=v0+ThisTex.dH;
float u0=(TexXOfs*dU);
float u1=u0+dU;
float v1=1.0-(TexYOfs*dV);
float v0=v1-dV;
Tri0.Mat=TexID;
@ -151,13 +184,15 @@ float u0,u1,v0,v1;
void CElem::Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node)
{
CNode &ThisNode=ThisScene.GetNode(Node);
int ChildCount=ThisNode.GetChildCount();
CNode &ParentNode=ThisScene.GetNode(ThisNode.ParentIdx);
int ChildCount=ThisNode.GetPruneChildCount();
std::vector<sGinTri> const &NodeTriList=ThisNode.GetTris();
std::vector<Vector3>const &NodeVtxList=ThisNode.GetRelPts();
std::vector<Vector3>const &NodeVtxList=ThisNode.GetPts();
std::vector<sUVTri> const &NodeUVList=ThisNode.GetUVTris();
std::vector<int> const &NodeTriMat=ThisNode.GetTriMaterial();
std::vector<GString> const &TexList= ThisScene.GetTexNames();//List();
std::vector<Material> const &MatList= ThisScene.GetMaterials();
std::vector<GString> const &SceneTexList=ThisScene.GetTexList();
std::vector<int> const &SceneUsedMatList=ThisScene.GetUsedMaterialIdx();
int TriCount=NodeTriList.size();
int ListSize=TriList.size();
@ -169,28 +204,38 @@ int ListSize=TriList.size();
sUVTri const &ThisUV=NodeUVList[T];
sTriFace &Tri=TriList[ListSize+T];
int ThisMat=NodeTriMat[T];
int TexID=1;
int TexID;
// Sort Textures - Only add the ones that are used :o)
TexID=MatList[ThisMat].TexId;
// Sort Textures - Only add the ones nthat are used :o)
TexID=SceneUsedMatList[ThisMat];
if (TexID!=-1)
{
GString ThisName;
ThisName=SetPath+TexList[TexID];
TexID=TexCache.ProcessTexture(ThisName,MatList[ThisMat].Flags);
ThisName=SetPath+SceneTexList[TexID];
TRACE2("%i !%s!\n",TexID,ThisName);
TexID=TexCache.ProcessTexture(ThisName);
}
// Sort Rest of Tri info
Matrix4x4 TransMtx;
TransMtx.Identity();
if (ParentNode.GetTris().size() || !ThisNode.ParentIdx)
{
TransMtx=ThisNode.Mtx;
TransMtx.Invert();
}
for (int p=0; p<3; p++)
{
Tri.vtx[p]=NodeVtxList[ThisTri.p[p]];
Tri.vtx[p]=TransMtx*NodeVtxList[ThisTri.p[p]];
Tri.uvs[p].u=ThisUV.p[p].u;
Tri.uvs[p].v=ThisUV.p[p].v;
Tri.Mat=TexID;
}
}
for (int Child=0; Child<ChildCount; Child++) Build3dElem(TexCache,ThisScene,ThisNode.PruneChildList[Child]);
}
@ -198,52 +243,62 @@ int ListSize=TriList.size();
/*****************************************************************************/
void CElem::Calc3dSize()
{
int ListSize=TriList.size();
float XMin=+9999;
float XMax=-9999;
float YMin=+9999;
float YMax=-9999;
int i,ListSize=TriList.size();
Vector3 Min(+32000,+32000,+32000);
Vector3 Max(-32000,-32000,-32000);
Vector3 Mid;
for (int i=0; i<ListSize; i++)
for (i=0; i<ListSize; i++)
{
sTriFace &Tri=TriList[i];
for (int p=0; p<3; p++)
{
if (XMin>Tri.vtx[p].x) XMin=Tri.vtx[p].x;
if (XMax<Tri.vtx[p].x) XMax=Tri.vtx[p].x;
if (YMin>Tri.vtx[p].y) YMin=Tri.vtx[p].y;
if (YMax<Tri.vtx[p].y) YMax=Tri.vtx[p].y;
if (Min.x>Tri.vtx[p].x) Min.x=Tri.vtx[p].x;
if (Min.y>Tri.vtx[p].y) Min.y=Tri.vtx[p].y;
if (Min.z>Tri.vtx[p].z) Min.z=Tri.vtx[p].z;
if (Max.x<Tri.vtx[p].x) Max.x=Tri.vtx[p].x;
if (Max.y<Tri.vtx[p].y) Max.y=Tri.vtx[p].y;
if (Max.z<Tri.vtx[p].z) Max.z=Tri.vtx[p].z;
}
}
UnitWidth=round(XMax-XMin);
UnitHeight=round(YMax-YMin);
UnitWidth=round(Max.x-Min.x);
UnitHeight=round(Max.y-Min.y);
if (UnitWidth<1) UnitWidth=1;
if (UnitHeight<1) UnitHeight=1;
ElemWidth=UnitWidth*UnitSize;
ElemHeight=UnitHeight*UnitSize;
Min.z=0;
Ofs=DefOfs;
// Ofs.x=+0.5f; Ofs.y=0; Ofs.z=+4.0f;
}
/*****************************************************************************/
void CElem::Build2dDrawList(CTexCache &TexCache,GLint &List)
{
float X0=Ofs.x;
float X1=Ofs.x+UnitWidth;
float Y0=Ofs.y;
float Y1=Ofs.y+UnitHeight;
float Z=Ofs.z;
List=glGenLists(1);
glNewList(List,GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, TexCache.GetTexGLId(ElemID));
glBegin (GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex3f( 0.0f,0.0f,0.0f);
glVertex3f(X0,Y0,Z);
glTexCoord2f(1.0f,0.0f);
glVertex3f( UnitWidth,0.0f,0.0f);
glVertex3f(X1,Y0,Z);
glTexCoord2f(1.0f,1.0f);
glVertex3f( UnitWidth,UnitHeight,0.0f);
glVertex3f(X1,Y1,Z);
glTexCoord2f(0.0f,1.0f);
glVertex3f( 0.0f,UnitHeight,0.0f);
glVertex3f(X0,Y1,Z);
glEnd();
glEndList();
@ -255,6 +310,7 @@ void CElem::Build3dDrawList(CTexCache &TexCache,GLint &List)
{
int TriCount=TriList.size();
int LastMat=-1,ThisMat;
float ScaleU,ScaleV;
List=glGenLists(1);
glNewList(List,GL_COMPILE);
@ -265,19 +321,32 @@ int LastMat=-1,ThisMat;
ThisMat=ThisTri.Mat;
if (!T || ThisMat!=LastMat) // First Tri or new material
{
{
if (T) glEnd(); // Not first tri, so end previous mat set
glBindTexture(GL_TEXTURE_2D, TexCache.GetTexGLId(ThisMat));
glBegin (GL_TRIANGLES);
LastMat=ThisMat;
sTex &Tex=TexCache.GetTex(ThisMat);
int AW=TexCache.AlignSize(Tex.TexWidth);
int AH=TexCache.AlignSize(Tex.TexHeight);
if (AW!=Tex.TexWidth || AH!=Tex.TexHeight)
{
ScaleU=(float)Tex.TexWidth/(float)AW;
ScaleV=(float)Tex.TexHeight/(float)AH;
}
else
{
ScaleU=ScaleV=1;
}
}
for (int p=0; p<3; p++)
{
Vector3 &ThisVtx=ThisTri.vtx[p];
glTexCoord2f(ThisTri.uvs[p].u, ThisTri.uvs[p].v);
float u=ThisTri.uvs[p].u*ScaleU;
float v=ThisTri.uvs[p].v*ScaleV;
glTexCoord2f(u,v);
glVertex3f( (ThisVtx.x+Ofs.x), (ThisVtx.y+Ofs.y), -(ThisVtx.z+Ofs.z)); // Neg Z (cos openGL)
}
}
@ -426,8 +495,11 @@ float Y1=UnitHeight;
/*****************************************************************************/
void CElem::RenderElem4Texture(sRGBData &RGBData)
{
float W=UnitWidth;
float H=UnitHeight;
glClearColor(1,0,1,1 );
// glClearColor(1,1,1,1 );
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,RGBData.Width,RGBData.Height);
@ -435,12 +507,12 @@ void CElem::RenderElem4Texture(sRGBData &RGBData)
glPushMatrix();
glLoadIdentity();
glOrtho(-0.5f, +0.5f, -0.5f, +0.5f, -16.0f, +16.0f);
glOrtho(0, W, 0, H, -16.0f, +16.0f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(-0.5f,-0.5f,0);
glTranslatef(-Ofs.x,-Ofs.y,-Ofs.z);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
@ -466,23 +538,22 @@ void CElem::RenderElem4Texture(sRGBData &RGBData)
void CElem::Create2dTexture(CTexCache &TexCache,const char *Filename,int ID)
{
sRGBData RGBData;
char TexName[256];
sprintf(TexName,"_2dPc_%s_%03d",Filename,ID);
ElemRGB=(u8*)malloc(ElemWidth*ElemHeight*3);
RGBData.Width=ElemWidth;
RGBData.Height=ElemHeight;
RGBData.RGB=ElemRGB;
RenderElem4Texture(RGBData);
ElemID=TexCache.ProcessTexture("",0,&RGBData);
ElemID=TexCache.ProcessTexture(TexName,&RGBData);
ValidFlag=CheckHasData(RGBData);
#ifdef _DEBUG
if (0)
{
char Filename[256];
char TexName[256];
static asd=0;
sprintf(TexName,"_2dPc_%s_%03d",Filename,asd++);
sprintf(Filename,"/x/%s.Tga",TexName);
SaveTGA(Filename,ElemWidth,ElemHeight,ElemRGB);
}
@ -505,7 +576,7 @@ int Size=RGBData.Width*RGBData.Height;
if (R!=255 || G!=0 || B!=255) return(TRUE);
}
return(FALSE);
return(false);
}
/*****************************************************************************/
@ -513,17 +584,24 @@ int Size=RGBData.Width*RGBData.Height;
/*** Elem Set ****************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CElemSet::CElemSet(const char *_Filename,int Idx,int Width,int Height)
CElemSet::CElemSet(const char *_Filename,int Idx,int Width,int Height,bool CreateBlank,bool Centre)
{
GFName FName=_Filename;
Filename=_Filename;
Name=FName.File();
DefWidth=Width;
DefHeight=Height;
MaxWidth=Width;
MaxHeight=Height;
CentreFlag=Centre;
Loaded=FALSE;
SetNumber=Idx;
if (CreateBlank)
{
ElemList.push_back(CElem(MaxWidth,MaxHeight)); // Insert Blank
}
}
/*****************************************************************************/
@ -560,18 +638,22 @@ GString Ext=FName.Ext();
void CElemSet::Load2d(CCore *Core)
{
CTexCache &TexCache=Core->GetTexCache();
int TexID=TexCache.ProcessTexture(Filename,0);
int TexID=TexCache.ProcessTexture(Filename);
sTex &ThisTex=TexCache.GetTex(TexID);
int Width=ThisTex.TexWidth/DefWidth;
int Height=ThisTex.TexHeight/DefHeight;
int Width,Height;
if (MaxWidth==-1) MaxWidth=ThisTex.TexWidth;
if (MaxHeight==-1) MaxHeight=ThisTex.TexHeight;
Width=ThisTex.TexWidth/MaxWidth;
Height=ThisTex.TexHeight/MaxHeight;
ElemList.push_back(CElem(DefWidth,DefHeight)); // Insert Blank
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
ElemList.push_back(CElem(Core,Filename,TexID,X,Y,DefWidth,DefHeight));
ElemList.push_back(CElem(Core,Filename,TexID,X,Y,MaxWidth,MaxHeight,CentreFlag));
}
}
ElemBrowserWidth=Width;
@ -587,8 +669,6 @@ CScene Scene;
CNode &ThisNode=Scene.GetSceneNode(0);
int ChildCount=ThisNode.GetPruneChildCount();
ElemList.push_back(CElem(DefWidth,DefHeight)); // Insert Blank
for (int Child=0; Child<ChildCount; Child++)
{
ElemList.push_back(CElem(Core,Filename,Scene,ThisNode.PruneChildList[Child]));
@ -632,9 +712,16 @@ int ListSize=ElemList.size();
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CElemBank::CElemBank()
CElemBank::CElemBank(int W,int H,bool Blank,bool Centre)
{
LoadFlag=FALSE;
MaxWidth=W;
MaxHeight=H;
BlankFlag=Blank;
CentreFlag=Centre;
LoadFlag=false;
CurrentSet=0;
VisibleFlag=true;
}
/*****************************************************************************/
@ -666,6 +753,10 @@ char FixPath[1024];
FilePath.Append('\\');
FilePath.Upper();
if (Version>=5)
{
File->Read(&CurrentSet,sizeof(int));
}
File->Read(&ListSize,sizeof(int));
// New Style rel storage
@ -708,6 +799,7 @@ GString SavePath;
SavePath.Upper();
File->Write(&CurrentSet,sizeof(int));
File->Write(&ListSize,sizeof(int));
for (int i=0; i<ListSize; i++)
@ -723,7 +815,7 @@ GString SavePath;
void CElemBank::AddSet(const char *Filename)
{
int ListSize=SetList.size();
CElemSet NewSet(Filename,ListSize);
CElemSet NewSet(Filename,ListSize,MaxWidth,MaxHeight,BlankFlag,CentreFlag);
SetList.Add(NewSet);
if (SetList.size()!=ListSize) LoadFlag=TRUE;
@ -777,19 +869,198 @@ void CElemBank::DeleteSet(int Set)
SetList.erase(Set);
}
/*****************************************************************************/
CElem &CElemBank::GetElem(int Set,int Elem)
{
ASSERT(Set>=0 && Elem>=0);
return(SetList[Set].GetElem(Elem));
}
/*****************************************************************************/
bool CElemBank::IsValid(int Set,int Elem)
{
if (Set<0 || Elem<0) return(false);
if (Elem==0) return(true);
if (Set>=SetList.size()) return(false);
ASSERT(Set<SetList.size());
return(SetList[Set].IsValid(Elem));
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
CPoint CElemBank::GetElemPos(int ID,int Width)
{
if (ID==0)
return(CPoint(-1,-1));
else
return(IDToPoint(ID-1,Width));
}
/*****************************************************************************/
void CElemBank::RenderElem(int Set,int Elem,int Flags,bool Is3d)
{
if (IsValid(Set,Elem))
{
SetList[Set].RenderElem(Elem,Flags,Is3d);
}
else
{
SetList[0].RenderInvalid();
}
}
/*****************************************************************************/
void CElemBank::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active)
{
if (!GetSetCount()) return;
CElemSet &ThisSet=SetList[CurrentSet];
int ListSize=ThisSet.GetCount();
int BrowserWidth=ThisSet.GetBrowserWidth();
int TileID=1; // Dont bother with blank, its sorted
float Scale=CamPos.z/(float)BrowserWidth/2.0;
if (!ListSize) return;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
while(TileID!=ListSize)
{
CPoint Pos=GetElemPos(TileID,BrowserWidth);
float XPos=(float)Pos.x*(1+ElemBrowserGap);
float YPos=(float)Pos.y*(1+ElemBrowserGap);
glLoadIdentity();
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
glBegin(GL_LINES);
glColor3f(1,1,1);
glVertex3f( ElemBrowserX0,ElemBrowserY0,0);
glVertex3f( ElemBrowserX1,ElemBrowserY0,0);
glVertex3f( ElemBrowserX0,ElemBrowserY1,0);
glVertex3f( ElemBrowserX1,ElemBrowserY1,0);
glVertex3f( ElemBrowserX0,ElemBrowserY0,0);
glVertex3f( ElemBrowserX0,ElemBrowserY1,0);
glVertex3f( ElemBrowserX1,ElemBrowserY0,0);
glVertex3f( ElemBrowserX1,ElemBrowserY1,0);
glEnd();
TileID++;
}
glPopMatrix();
}
/*****************************************************************************/
void CElemBank::FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos)
{
if (!GetSetCount()) return;
CElemSet &ThisSet=SetList[CurrentSet];
int ListSize=ThisSet.GetCount();
int BrowserWidth=ThisSet.GetBrowserWidth();
GLint Viewport[4];
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
int HitCount;
int TileID=0;
float Scale=CamPos.z/(float)BrowserWidth/2.0;
if (!ListSize) return;
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);
Core->GetView()->SetupPersMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
while(TileID!=ListSize)
{
CPoint Pos=GetElemPos(TileID,BrowserWidth);
float XPos=(float)Pos.x*(1+ElemBrowserGap);
float YPos=(float)Pos.y*(1+ElemBrowserGap);
glLoadIdentity();
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
glLoadName (TileID);
glBegin (GL_QUADS);
BuildGLQuad(ElemBrowserX0,ElemBrowserX1,ElemBrowserY0,ElemBrowserY1,0);
glEnd();
TileID++;
}
HitCount= glRenderMode (GL_RENDER);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
// Process hits
GLuint *HitPtr=SelectBuffer;
TileID=-2;
if (HitCount) // Just take 1st
{
TileID=HitPtr[3];
}
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
CursorPos=TileID;
}
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
void CElemBank::GUIInit(CCore *Core)
{
Core->GUIAdd(GUIElemList,IDD_ELEMLIST);
}
/*****************************************************************************/
void CElemBank::GUIKill(CCore *Core)
{
Core->GUIRemove(GUIElemList,IDD_ELEMLIST);
}
/*****************************************************************************/
void CElemBank::GUIUpdate(CCore *Core)
{
int ListSize=GetSetCount();
bool IsSubView=Core->IsSubView();
if (GUIElemList.m_List)
{
GUIElemList.m_List.ResetContent();
if (ListSize)
{
for (int i=0; i<ListSize; i++)
{
GUIElemList.m_List.AddString(GetSetName(i));
}
GUIElemList.m_List.SetCurSel(CurrentSet);
}
else
{
IsSubView=FALSE;
}
GUIElemList.m_List.EnableWindow(IsSubView);
}
}
/*****************************************************************************/
void CElemBank::GUIChanged(CCore *Core)
{
}
/*****************************************************************************/

View File

@ -13,6 +13,10 @@
#include "TexCache.h"
#include "GinTex.h"
#include "Layer.h"
#include "MapEdit.h"
#include "GUIElemList.h"
struct sTriFace
{
int Mat;
@ -40,9 +44,9 @@ public:
UnitSize=16,
};
CElem(int Width,int Height); // Blank (2d)
CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs,int Width,int Height); // 2d elem
CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node); // 3d elem
CElem(int Width,int Height); // Blank (2d)
CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs,int Width,int Height,bool Centre); // 2d elem
CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node); // 3d elem
void CleanUp();
void Purge();
@ -98,12 +102,10 @@ class CElemSet
public:
enum
{
DEF_ELEMWIDTH=16,
DEF_ELEMHEIGHT=16,
DEF_ELEMBROWSWEWIDTH=8,
};
CElemSet(const char *_Filename,int Idx,int Width=DEF_ELEMWIDTH,int Height=DEF_ELEMHEIGHT);
CElemSet(const char *_Filename,int Idx,int MaxWidth,int MaxHeight,bool CreateBlank,bool Centre);
~CElemSet();
void CleanUp();
@ -133,22 +135,24 @@ private:
GString Filename,Name;
int SetNumber;
int DefWidth,DefHeight;
int MaxWidth,MaxHeight;
bool CentreFlag;
CList<CElem> ElemList;
bool Loaded;
int ElemBrowserWidth;
};
/*****************************************************************************/
class CElemBank
class CElemBank : public CLayer
{
public:
CElemBank();
~CElemBank();
void CleanUp();
// Local
CElemBank(int MaxWidth,int MaxHeight,bool Blank,bool Centre);
virtual ~CElemBank();
void CleanUp();
void Load(CFile *File,int Version);
void Save(CFile *File);
virtual void Load(CFile *File,int Version);
virtual void Save(CFile *File);
void AddSet(const char *Filename);
void LoadAllSets(CCore *Core);
@ -156,16 +160,49 @@ public:
void ReloadAllSets();
void DeleteSet(int Set);
int NeedLoad() {return(LoadFlag);}
CElem &GetElem(int Set,int Elem);
CElem &GetElem(int Set,int Elem) {return(SetList[Set].GetElem(Elem));}
bool IsValid(int Set,int Elem);
void RenderElem(int Set,int Elem,int Flags,bool Is3d);
int GetSetCount() {return(SetList.size());}
const char *GetSetName(int Set) {return(SetList[Set].GetName());}
const char *GetSetFilename(int Set) {return(SetList[Set].GetFilename());}
// Overloads
virtual int GetType() {return(0);}
virtual void RenderGrid(CCore *Core,Vector3 &CamPos,bool Active);
virtual void RenderSelection(CCore *Core,Vector3 &ThisCam){};
virtual void FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos);
virtual void GUIInit(CCore *Core);
virtual void GUIKill(CCore *Core);
virtual void GUIUpdate(CCore *Core);
virtual void GUIChanged(CCore *Core);
virtual void Export(CCore *Core,CExport &Exp){};
virtual bool LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) {return(false);}
virtual bool RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) {return(false);}
virtual bool MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos) {return(false);}
virtual bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0) {return(false);}
CPoint GetElemPos(int ID,int Width);
// Local
virtual bool CanClose() {return(true);}
protected:
CList<CElemSet> SetList;
bool LoadFlag;
int CurrentSet;
int CursorPos;
int MaxWidth,MaxHeight;
bool BlankFlag,CentreFlag;
CGUIElemList GUIElemList;
};

View File

@ -125,7 +125,7 @@ CTileBank *TileBank=Core->GetTileBank();
}
else
{
CElem &ThisTile=TileBank->GetTile(OutTile.Set,OutTile.Tile);
CElem &ThisTile=TileBank->GetElem(OutTile.Set,OutTile.Tile);
GString SetName=TileBank->GetSetFilename(OutTile.Set);
ASSERT(ThisTile.GetElemWidth()==FileHdr.TileW);

View File

@ -33,7 +33,7 @@ public:
// Dialog Data
//{{AFX_DATA(CGUILayerShade)
enum { IDD = IDD_LAYERSHADE_GUI };
enum { IDD = IDD_LAYER_SHADE };
CEdit m_R0;
CEdit m_G0;
CEdit m_B0;

View File

@ -24,7 +24,7 @@ public:
// Dialog Data
//{{AFX_DATA(GUIToolBar)
enum { IDD = IDD_LAYER_TOOLBAR };
enum { IDD = IDD_TOOLBAR };
CButton m_Select;
CButton m_Paint;
//}}AFX_DATA

View File

@ -21,7 +21,6 @@
#include "Select.h"
#include "Export.h"
// Reserve slot 0 for collision :o)
GString ColFName="Collision.bmp";
/*****************************************************************************/
@ -47,32 +46,20 @@ CLayerCollision::CLayerCollision(CFile *File,int Version)
/*****************************************************************************/
CLayerCollision::~CLayerCollision()
{
TileBank->CleanUp();
delete TileBank;
}
/*****************************************************************************/
void CLayerCollision::InitSubView(CCore *Core)
{
GString Filename;
TileBank=new CTileBank;
SubView=TileBank;
GFName ExePath;
GString Filename;
// Get application path
#ifdef _DEBUG
ExePath="C:\\Spongebob\\tools\\mapedit\\";
#else
char ExeFilename[2048];
GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048);
ExePath=ExeFilename;
ExePath.File(0);
ExePath.Ext(0);
#endif
Filename=ExePath.FullName();
Core->GetExecPath(Filename);
Filename+=ColFName;
TileBank->AddSet(Filename);
}
/*****************************************************************************/
@ -135,14 +122,14 @@ bool Ret=false;
/*****************************************************************************/
void CLayerCollision::GUIInit(CCore *Core)
{
Core->GUIAdd(GUIToolBar,IDD_LAYERTILE_TOOLBAR);
Core->GUIAdd(GUIToolBar,IDD_TOOLBAR);
Core->GUIAdd(GUI,IDD_LAYER_COLLISION);
}
/*****************************************************************************/
void CLayerCollision::GUIKill(CCore *Core)
{
Core->GUIRemove(GUIToolBar,IDD_LAYERTILE_TOOLBAR);
Core->GUIRemove(GUIToolBar,IDD_TOOLBAR);
Core->GUIRemove(GUI,IDD_LAYER_COLLISION);
}

View File

@ -1,6 +1,6 @@
/******************/
/*** Layer Elem ***/
/******************/
/*******************/
/*** Layer Thing ***/
/*******************/
#include "stdafx.h"
@ -14,44 +14,68 @@
#include "MapEditView.h"
#include "MainFrm.h"
//#include "ElemSet.h"
#include "Core.h"
#include "Layer.h"
#include "LayerElem.h"
#include "LayerThing.h"
#include "Utils.h"
//#include "Select.h"
#include "Export.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// New Layer
CLayerElem::CLayerElem(int _SubType,int _Width,int _Height)
CLayerThing::CLayerThing(int _SubType,int _Width,int _Height)
{
SetDefaultParams();
Mode=MouseModePaint;
// ElemBank=new CElemBank;
Mode=MouseModeNormal;
Width=_Width;
Height=_Height;
ThingBank=new CElemBank(-1,-1,false,true);
CurrentThing=-1;
CurrentPoint=0;
ThingBank->AddSet("\\spongebob\\graphics\\Babyoctopus.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\barnicleboy.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Caterpillar.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\clam.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Eyeball.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\FlyingDutchman.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\gary.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\GiantWorm.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\HermitCrab.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\IronDogFish.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Krusty.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\MermaidMan.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Neptune.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Patrick.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\plankton.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\PuffaFish.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Sandy.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\SeaSnake.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\SharkSub.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\SpiderCrab.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\spongebob.bmp");
ThingBank->AddSet("\\spongebob\\graphics\\Squidward.bmp");
}
/*****************************************************************************/
// Load Layer
CLayerElem::CLayerElem(CFile *File,int Version)
CLayerThing::CLayerThing(CFile *File,int Version)
{
Load(File,Version);
}
/*****************************************************************************/
CLayerElem::~CLayerElem()
CLayerThing::~CLayerThing()
{
// ElemBank->CleanUp();
// delete ElemBank;
ThingBank->CleanUp();
delete ThingBank;
}
/*****************************************************************************/
void CLayerElem::Load(CFile *File,int Version)
void CLayerThing::Load(CFile *File,int Version)
{
File->Read(&VisibleFlag,sizeof(BOOL));
File->Read(&Mode,sizeof(MouseMode));
@ -60,7 +84,7 @@ void CLayerElem::Load(CFile *File,int Version)
}
/*****************************************************************************/
void CLayerElem::Save(CFile *File)
void CLayerThing::Save(CFile *File)
{
// Always Save current version
File->Write(&VisibleFlag,sizeof(BOOL));
@ -68,39 +92,36 @@ void CLayerElem::Save(CFile *File)
}
/*****************************************************************************/
void CLayerElem::InitSubView(CCore *Core)
void CLayerThing::InitSubView(CCore *Core)
{
ElemBank=&Core->GetIconz();
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerElem::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
void CLayerThing::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
int i,ListSize=ThingList.size();
Is3d&=Render3dFlag;
for (int x=0; x<20; x++)
// Is3d&=Render3dFlag;
for (i=0; i<ListSize; i++)
{
CPoint XY;
XY.x=x;
XY.y=0;
RenderElem(Core,ThisCam,XY,x&7,Is3d);
RenderThing(Core,ThisCam,ThingList[i],Is3d,i==CurrentThing);
}
}
/*****************************************************************************/
void CLayerElem::RenderElem(CCore *Core,Vector3 &ThisCam,CPoint &Pos,int Elem,bool Render3d,float Alpha)
void CLayerThing::RenderThing(CCore *Core,Vector3 &ThisCam,sLayerThing &ThisThing,bool Render3d,bool Selected)
{
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
float ScrOfsX=(ZoomW/2);
float ScrOfsY=(ZoomH/2);
Vector3 &Scale=Core->GetScaleVector();
CElemBank *IconBank=Core->GetIconBank();
if (ElemBank->NeedLoad()) ElemBank->LoadAllSets(Core);
if (ThingBank->NeedLoad()) ThingBank->LoadAllSets(Core);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -108,137 +129,150 @@ Vector3 &Scale=Core->GetScaleVector();
glLoadIdentity();
glScalef(Scale.x,Scale.y,Scale.z);
glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
glTranslatef(Pos.x,Pos.y,0); // Set Elem Pos
glColor4f(1,1,1,Alpha); // Set default Color
ElemBank->RenderElem(0,Elem+1,0,Render3d);
glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset
glTranslatef(-ScrOfsX,ScrOfsY,0); // Bring to top left corner
int ListSize=ThisThing.XY.size();
TRACE1("%i pts\n",ListSize);
for (int i=0;i<ListSize; i++)
{
// Render Thing
glPushMatrix();
glTranslatef(ThisThing.XY[i].x,-ThisThing.XY[i].y,0); // Set Pos
if (Selected)
glColor4f(1,1,1,1); // Set default Color
else
glColor4f(1,1,1,0.5);
IconBank->RenderElem(0,i,0,Render3d);
if (i==0)
{
glColor4f(1,1,1,1); // Set default Color
ThingBank->RenderElem(ThisThing.Type,0,0,Render3d);
}
glPopMatrix();
}
glPopMatrix();
}
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
void CLayerElem::GUIInit(CCore *Core)
void CLayerThing::GUIInit(CCore *Core)
{
// Core->GUIAdd(GUIToolBar,IDD_TOOLBAR);
}
/*****************************************************************************/
void CLayerElem::GUIKill(CCore *Core)
void CLayerThing::GUIKill(CCore *Core)
{
// Core->GUIRemove(GUIToolBar,IDD_TOOLBAR);
}
/*****************************************************************************/
void CLayerElem::GUIUpdate(CCore *Core)
void CLayerThing::GUIUpdate(CCore *Core)
{
}
/*****************************************************************************/
void CLayerElem::GUIChanged(CCore *Core)
void CLayerThing::GUIChanged(CCore *Core)
{
}
/*****************************************************************************/
/*** Functions ***************************************************************/
/*****************************************************************************/
bool CLayerElem::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
bool CLayerThing::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
{
bool Ret=false;
/*
switch(Mode)
{
case MouseModePaint:
case MouseModeNormal:
if (DownFlag)
Ret=Paint(ElemBank->GetLBrush(),CursorPos);
{
if (CurrentThing==-1)
AddThing(CursorPos);
else
AddThingPoint(CursorPos);
}
break;
case MouseModeSelect:
Ret=Selection.Handle(CursorPos,nFlags);
if (Selection.HasSelection())
{
TRACE0("LMB Selection\n");
}
case MouseModePoints:
break;
default:
break;
}
*/
return(Ret);
return(true);
}
/*****************************************************************************/
bool CLayerElem::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
bool CLayerThing::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
{
bool Ret=FALSE;
/*
switch(Mode)
{
case MouseModePaint:
case MouseModeNormal:
if (DownFlag)
Ret=Paint(ElemBank->GetRBrush(),CursorPos);
{
SelectThing(CursorPos);
}
break;
case MouseModeSelect:
Ret=Selection.Handle(CursorPos,nFlags);
if (Selection.HasSelection())
{
TRACE0("RMB Selection\n");
}
break;
default:
case MouseModePoints:
break;
}
*/
return(Ret);
}
/*****************************************************************************/
bool CLayerElem::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
bool CLayerThing::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
{
bool Ret=FALSE;
/*
switch(Mode)
bool Ret=false;
if (CurrentThing!=-1)
{
case MouseModePaint:
if (nFlags & MK_LBUTTON)
Ret=Paint(ElemBank->GetLBrush(),CursorPos);
if (nFlags & MK_LBUTTON) // Drag
{
UpdatePos(CursorPos,CurrentThing,CurrentPoint,true);
Ret=true;
}
else
if (nFlags & MK_RBUTTON)
Ret=Paint(ElemBank->GetRBrush(),CursorPos);
break;
case MouseModeSelect:
Ret=Selection.Handle(CursorPos,nFlags);
break;
default:
break;
if (nFlags & MK_RBUTTON) // Cancel
{
CurrentThing=-1;
Ret=true;
}
}
*/
return(Ret);
}
/*****************************************************************************/
bool CLayerElem::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
bool CLayerThing::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_SubViewSet:
Ret=ElemBank->Command(CmdMsg,Core,Param0,Param1);
// Mode=(MouseMode)Param0;
// Core->GUIUpdate();
// break;
// case CmdMsg_SubViewSet:
// Ret=ThingBank->Command(CmdMsg,Core,Param0,Param1);
break;
default:
TRACE3("LayerElem-Unhandled Command %i (%i,%i)\n",CmdMsg,Param0,Param1);
break;
}
*/
return(Ret);
}
/*****************************************************************************/
void CLayerElem::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
void CLayerThing::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
CPoint &CursPos=Core->GetCursorPos();
@ -264,19 +298,135 @@ Vector3 Ofs;
}
/*****************************************************************************/
bool CLayerElem::Paint(CMap &Blk,CPoint &CursorPos)
/*****************************************************************************/
/*****************************************************************************/
int CLayerThing::CheckThing(CPoint &Pos)
{
CList<int> List;
int Idx=-1,i,ListSize=ThingList.size();
int StartIdx=0;
if (CursorPos.x==-1 || CursorPos.y==-1) return(false); // Off Map?
if (!Blk.IsValid()) return(false); // Invalid Elem?
/*
Map.Set(CursorPos.x,CursorPos.y,Blk);
*/
return(true);
// Build List Of XY Matches
for (i=0; i<ListSize; i++)
{
sLayerThing &ThisThing=ThingList[i];
if (ThisThing.XY[0]==Pos)
{
if (i==CurrentThing) StartIdx=List.size();
List.push_back(i);
}
}
ListSize=List.size();
if (ListSize)
{
StartIdx=(StartIdx+1)%ListSize;
Idx=List[StartIdx];
}
return(Idx);
}
/*****************************************************************************/
void CLayerElem::Export(CCore *Core,CExport &Exp)
void CLayerThing::AddThing(CPoint &Pos)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
CurrentThing=CheckThing(Pos);
CurrentPoint=0;
if (CurrentThing!=-1) return;
CurrentThing=ThingList.size();
ThingList.resize(CurrentThing+1);
sLayerThing &ThisThing=ThingList[CurrentThing];
ThisThing.XY.push_back(Pos);
ThisThing.Type=ThingList.size()%22;
ThisThing.SubType=0;
}
/*****************************************************************************/
void CLayerThing::SelectThing(CPoint &Pos)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
CurrentThing=CheckThing(Pos);
CurrentPoint=0;
}
/*****************************************************************************/
/*****************************************************************************/
int CLayerThing::CheckThingPoint(CPoint &Pos)
{
CList<int> List;
sLayerThing &ThisThing=ThingList[CurrentThing];
int Idx=-1,i,ListSize=ThisThing.XY.size();
int StartIdx=0;
// Build List Of XY Matches
for (i=0; i<ListSize; i++)
{
if (ThisThing.XY[i]==Pos)
{
if (i==CurrentThing) StartIdx=List.size();
List.push_back(i);
}
}
ListSize=List.size();
if (ListSize)
{
StartIdx=(StartIdx+1)%ListSize;
Idx=List[StartIdx];
}
return(Idx);
}
/*****************************************************************************/
void CLayerThing::AddThingPoint(CPoint &Pos)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
CurrentPoint=CheckThingPoint(Pos);
if (CurrentPoint!=-1) return;
sLayerThing &ThisThing=ThingList[CurrentThing];
CurrentPoint=ThisThing.XY.size();
ThisThing.XY.resize(CurrentPoint+1);
ThisThing.XY[CurrentPoint]=Pos;
}
/*****************************************************************************/
void CLayerThing::SelectThingPoint(CPoint &Pos)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
CurrentPoint=CheckThing(Pos);
}
/*****************************************************************************/
void CLayerThing::UpdatePos(CPoint &Pos,int Thing,int PosIdx,bool Recurs)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
sLayerThing &ThisThing=ThingList[Thing];
CPoint dPos=Pos-ThisThing.XY[PosIdx];
int StartIdx=PosIdx,EndIdx=ThisThing.XY.size();
if (!Recurs)
{
StartIdx=PosIdx;
EndIdx=StartIdx++;
}
for (int i=StartIdx; i<EndIdx; i++)
{
ThisThing.XY[i]+=dPos;
}
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerThing::Export(CCore *Core,CExport &Exp)
{
/*
int Width=Map.GetWidth();
@ -289,7 +439,7 @@ int Height=Map.GetHeight();
for (int X=0; X<Width; X++)
{
sMapElem &MapElem=Map.Get(X,Y);
sExpLayerElem OutElem;
sExpLayerThing OutElem;
if (MapElem.Set==0 && MapElem.Elem==0)
{ // Blank
@ -311,7 +461,7 @@ int Height=Map.GetHeight();
OutElem.Flags=MapElem.Flags;
}
Exp.Write(&OutElem,sizeof(sExpLayerElem));
Exp.Write(&OutElem,sizeof(sExpLayerThing));
}
}
*/

View File

@ -1,9 +1,9 @@
/******************/
/*** Layer Elem ***/
/******************/
/*******************/
/*** Layer Thing ***/
/*******************/
#ifndef __LAYER_ELEM_HEADER__
#define __LAYER_ELEM_HEADER__
#ifndef __LAYER_THING_HEADER__
#define __LAYER_THING_HEADER__
#include "Layer.h"
#include "MapEdit.h"
@ -11,40 +11,51 @@
#include "Elem.h"
/*****************************************************************************/
struct sLayerElem
struct sLayerThing
{
std::vector<CPoint> XY;
int Type;
int SubType;
std::vector<CPoint> XY;
int Type;
int SubType;
int Spare[8];
bool operator==(sLayerThing const &v1)
{
if (XY[0]!=v1.XY[0]) return(false);
return(true);
}
};
/*****************************************************************************/
class CLayerElem : public CElemBank
class CLayerThing : public CLayer
{
public:
enum MouseMode
{
MouseModePaint=0,
MouseModeSelect,
MouseModeNormal=0,
MouseModePoints,
};
CLayerElem(){};
CLayerElem(int SubType,int Width,int Height); // New Layer
CLayerElem(CFile *File,int Version); // Load Layer
~CLayerElem();
CLayerThing(){};
CLayerThing(int SubType,int Width,int Height); // New Layer
CLayerThing(CFile *File,int Version); // Load Layer
~CLayerThing();
virtual int GetType() {return(LAYER_TYPE_ITEM);}
virtual void InitSubView(CCore *Core);
virtual void Render(CCore *Core,Vector3 &CamPos,bool Is3d);
void RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d);
// void FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos);
virtual void GUIInit(CCore *Core);
virtual void GUIKill(CCore *Core);
virtual void GUIUpdate(CCore *Core);
virtual void GUIChanged(CCore *Core);
int GetWidth() {return(Width);}
int GetHeight() {return(Height);}
virtual void Load(CFile *File,int Version);
virtual void Save(CFile *File);
@ -56,18 +67,25 @@ virtual bool RButtonControl(CCore *Core,UINT nFlags, CPoint &point,bool DownFl
virtual bool MouseMove(CCore *Core,UINT nFlags, CPoint &point);
virtual bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0);
// Local
// CElemBank *GetElemBank() {return(ElemBank);}
protected:
void RenderElem(CCore *Core,Vector3 &CamPos,CPoint &Pos,int Elem,bool Render3d,float Alpha=1.0f);
void RenderThing(CCore *Core,Vector3 &CamPos,sLayerThing &ThisThing,bool Render3d,bool Selected);
int CheckThing(CPoint &Pos);
void AddThing(CPoint &Pos);
void SelectThing(CPoint &Pos);
int CheckThingPoint(CPoint &Pos);
void AddThingPoint(CPoint &Pos);
void SelectThingPoint(CPoint &Pos);
bool Paint(CMap &Blk,CPoint &CursorPos);
void UpdatePos(CPoint &Pos,int Thing,int PosNo,bool Recurs=false);
CElemBank *ElemBank;
CList<sLayerElem> ElemList;
int Width,Height;
CElemBank *ThingBank;
CList<sLayerThing> ThingList;
int CurrentThing,CurrentPoint;
MouseMode Mode;
CGUIToolBar GUIToolBar;
};

View File

@ -252,7 +252,7 @@ int DrawH=ZoomH+8;
if (ThisElem.Tile>0)
{ // Render Non Zero and Valid Tiles
glColor4f(1,1,1,Alpha); // Set default Color
TileBank->RenderTile(ThisElem.Set,ThisElem.Tile,ThisElem.Flags,Render3d);
TileBank->RenderElem(ThisElem.Set,ThisElem.Tile,ThisElem.Flags,Render3d);
}
glTranslatef(1.0f,0,0); // Next X
}
@ -302,14 +302,14 @@ float Y1=Rect.bottom-1;
void CLayerTile::GUIInit(CCore *Core)
{
TileBank->GUIInit(Core);
Core->GUIAdd(GUIToolBar,IDD_LAYERTILE_TOOLBAR);
Core->GUIAdd(GUIToolBar,IDD_TOOLBAR);
}
/*****************************************************************************/
void CLayerTile::GUIKill(CCore *Core)
{
TileBank->GUIKill(Core);
Core->GUIRemove(GUIToolBar,IDD_LAYERTILE_TOOLBAR);
Core->GUIRemove(GUIToolBar,IDD_TOOLBAR);
}
/*****************************************************************************/
@ -443,6 +443,7 @@ bool Ret=false;
break;
default:
TRACE3("LayerTile-Unhandled Command %i (%i,%i)\n",CmdMsg,Param0,Param1);
break;
}
return(Ret);
}
@ -601,7 +602,7 @@ int Height=Map.GetHeight();
else
{
sExpTile OutTile;
CElem &ThisTile=TileBank->GetTile(MapElem.Set,MapElem.Tile);
CElem &ThisTile=TileBank->GetElem(MapElem.Set,MapElem.Tile);
OutTile.Set=MapElem.Set;
OutTile.Tile=MapElem.Tile;

View File

@ -57,7 +57,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
}
// ParamBar
if (!ParamBar.Create(this,IDD_PARAMBAR,(CBRS_LEFT | CBRS_SIZE_DYNAMIC),IDD_PARAMBAR))
if (!ParamBar.Create(this,IDD_MULTIBAR,(CBRS_LEFT | CBRS_SIZE_DYNAMIC),IDD_MULTIBAR))
{
TRACE0("Failed to create ParamBar\n");
return -1;

View File

@ -29,19 +29,19 @@ Class17=CMapEditDoc
Class18=CMapEditView
ResourceCount=14
Resource1=IDD_LAYER_TOOLBAR
Resource1=IDD_LAYER_SHADE
Resource2=IDR_MAPEDITYPE (English (U.S.))
Resource3=IDD_LAYER_SHADE
Resource4=IDD_LAYER_COLLISION
Resource5=IDR_TOOLBAR (English (U.S.))
Resource6=IDR_MAINFRAME (English (U.S.))
Resource7=IDD_ABOUTBOX (English (U.S.))
Resource8=IDD_MULTIBAR (English (U.S.))
Resource9=IDD_LAYER_LIST
Resource10=IDD_RESIZE
Resource11=IDD_NEWMAP
Resource12=IDD_ADDLAYER
Resource13=IDD_TILEBANK
Resource3=IDD_TILEBANK
Resource4=IDD_TOOLBAR
Resource5=IDD_ADDLAYER
Resource6=IDD_LAYER_COLLISION
Resource7=IDR_TOOLBAR (English (U.S.))
Resource8=IDR_MAINFRAME (English (U.S.))
Resource9=IDD_ABOUTBOX (English (U.S.))
Resource10=IDD_MULTIBAR (English (U.S.))
Resource11=IDD_LAYER_LIST
Resource12=IDD_RESIZE
Resource13=IDD_NEWMAP
Resource14=IDD_ELEMLIST
[CLS:CChildFrame]
@ -222,13 +222,6 @@ Control1=IDD_TILEBANK_UPDATE,button,1342242816
Control2=IDD_TILEBANK_LOAD,button,1342242816
Control3=IDD_TILEBANK_DELETE,button,1342242816
[DLG:IDD_LAYER_TOOLBAR]
Type=1
Class=GUIToolBar
ControlCount=2
Control1=IDD_LAYERTILE_BTN_PAINT,button,1342177344
Control2=IDD_LAYERTILE_BTN_SELECT,button,1342177344
[DLG:IDD_LAYERSHADE_GUI]
Type=1
Class=CLayerShadeGUI
@ -363,3 +356,10 @@ Control14=IDC_LAYERSHADE_EDITB3,edit,1350770816
Control15=IDC_LAYERSHADE_COUNTEDIT,edit,1350576256
Control16=IDC_SPIN2,msctls_updown32,1342177302
[DLG:IDD_TOOLBAR]
Type=1
Class=GUIToolBar
ControlCount=2
Control1=IDD_LAYERTILE_BTN_PAINT,button,1342177344
Control2=IDD_LAYERTILE_BTN_SELECT,button,1342177344

View File

@ -80,6 +80,12 @@ BSC32=bscmake.exe
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 opengl32.lib glu32.lib glib.lib ginlib.lib maths.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /libpath:"..\libs\ginlib\debug\\" /libpath:"..\libs\glib\debug\\" /libpath:"..\libs\maths\debug\\"
# Begin Special Build Tool
ProjDir=.
TargetDir=.\Debug
SOURCE="$(InputPath)"
PostBuild_Cmds=if not exist $(TargetDir)\collision.bmp copy $(ProjDir)\res\collision.bmp $(TargetDir)\collision.bmp if not exist $(TargetDir)\iconz.bmp copy $(ProjDir)\res\iconz.bmp $(TargetDir)\iconz.bmp
# End Special Build Tool
!ENDIF
@ -115,14 +121,6 @@ SOURCE=.\LayerDef.h
# End Source File
# Begin Source File
SOURCE=.\LayerItem.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerItem.h
# End Source File
# Begin Source File
SOURCE=.\LayerShade.cpp
# End Source File
# Begin Source File
@ -131,6 +129,14 @@ SOURCE=.\LayerShade.h
# End Source File
# Begin Source File
SOURCE=.\LayerThing.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerThing.h
# End Source File
# Begin Source File
SOURCE=.\LayerTile.cpp
# End Source File
# Begin Source File
@ -176,14 +182,6 @@ SOURCE=.\Elem.h
# End Source File
# Begin Source File
SOURCE=.\ElemStore.cpp
# End Source File
# Begin Source File
SOURCE=.\ElemStore.h
# End Source File
# Begin Source File
SOURCE=.\Map.cpp
# End Source File
# Begin Source File
@ -351,9 +349,14 @@ SOURCE=.\StdAfx.h
# Begin Group "GUI"
# PROP Default_Filter ""
# Begin Group "New"
# Begin Source File
# PROP Default_Filter ""
SOURCE=.\GUIAddLayer.cpp
# End Source File
# Begin Source File
SOURCE=.\GUIAddLayer.h
# End Source File
# Begin Source File
SOURCE=.\GUIElemList.cpp
@ -364,76 +367,67 @@ SOURCE=.\GUIElemList.h
# End Source File
# Begin Source File
SOURCE=.\GUILayerCollision.cpp
# End Source File
# Begin Source File
SOURCE=.\GUILayerCollision.h
# End Source File
# Begin Source File
SOURCE=.\GUILayerList.cpp
# End Source File
# Begin Source File
SOURCE=.\GUILayerList.h
# End Source File
# Begin Source File
SOURCE=.\GUILayerShade.cpp
# End Source File
# Begin Source File
SOURCE=.\GUILayerShade.h
# End Source File
# Begin Source File
SOURCE=.\GUIMultibar.cpp
# End Source File
# Begin Source File
SOURCE=.\GUIMultibar.h
# End Source File
# Begin Source File
SOURCE=.\GUINewMap.cpp
# End Source File
# Begin Source File
SOURCE=.\GUINewMap.h
# End Source File
# Begin Source File
SOURCE=.\GUIResize.cpp
# End Source File
# Begin Source File
SOURCE=.\GUIResize.h
# End Source File
# Begin Source File
SOURCE=.\GUITileBank.cpp
# End Source File
# Begin Source File
SOURCE=.\GUITileBank.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\AddLayerDlg.cpp
SOURCE=.\GUIToolBar.cpp
# End Source File
# Begin Source File
SOURCE=.\AddLayerDlg.h
# End Source File
# Begin Source File
SOURCE=.\LayerCollisionGUI.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerCollisionGUI.h
# End Source File
# Begin Source File
SOURCE=.\LayerList.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerList.h
# End Source File
# Begin Source File
SOURCE=.\LayerShadeGUI.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerShadeGUI.h
# End Source File
# Begin Source File
SOURCE=.\LayerTileToolbar.cpp
# End Source File
# Begin Source File
SOURCE=.\LayerTileToolbar.h
# End Source File
# Begin Source File
SOURCE=.\MapSizeDlg.cpp
# End Source File
# Begin Source File
SOURCE=.\MapSizeDlg.h
# End Source File
# Begin Source File
SOURCE=.\MultiBar.cpp
# End Source File
# Begin Source File
SOURCE=.\MultiBar.h
# End Source File
# Begin Source File
SOURCE=.\NewMapGUI.cpp
# End Source File
# Begin Source File
SOURCE=.\NewMapGUI.h
SOURCE=.\GUIToolBar.h
# End Source File
# End Group
# End Target

View File

@ -520,7 +520,7 @@ BEGIN
PUSHBUTTON "Delete",IDD_TILEBANK_DELETE,50,5,45,15
END
IDD_LAYER_TOOLBAR DIALOG DISCARDABLE 0, 0, 156, 16
IDD_TOOLBAR DIALOG DISCARDABLE 0, 0, 156, 16
STYLE WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
@ -632,7 +632,7 @@ BEGIN
BOTTOMMARGIN, 19
END
IDD_LAYER_TOOLBAR, DIALOG
IDD_TOOLBAR, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 149

View File

@ -25,7 +25,7 @@ BEGIN_MESSAGE_MAP(CMapEditDoc, CDocument)
ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
ON_COMMAND(ID_TOGGLE_SUBVIEW, OnToggleSubView)
ON_COMMAND(ID_TOOLBAR_GRID, OnToggleGrid)
ON_COMMAND(ID_TOGGLE_GRID, OnToggleGrid)
ON_COMMAND(ID_MIRRORX, OnMirrorx)
ON_COMMAND(ID_MIRRORY, OnMirrory)
ON_COMMAND(ID_ACTIVEBRUSH_LEFT, OnActivebrushLeft)

View File

@ -15,18 +15,8 @@
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*
int CTexCache::GetTexIdx(const char *Filename,int Flags)
{
sTex Tex;
Tex.Filename=Filename;
Tex.Flags=Flags;
return(TexList.Find(Tex));
}
*/
/*****************************************************************************/
// Checks loaded files for dups, assumes all passed RGB is unique
int CTexCache::ProcessTexture(const char *Filename,int Flags,sRGBData *RGBData)
int CTexCache::ProcessTexture(const char *Filename,sRGBData *RGBData)
{
int ListSize=TexList.size();
sTex NewTex;
@ -35,7 +25,6 @@ GFName FName=Filename;
NewTex.Name=FName.File();
NewTex.Filename=Filename;
NewTex.Flags=Flags;
if (!RGBData) // Need to load file
{
@ -124,13 +113,13 @@ void CTexCache::LoadTex(sTex &ThisTex,sRGBData *TexData)
u8 *Buffer;
int TexWidth=TexData->Width;
int TexHeight=TexData->Height;
int GLWidth=AlignSize(TexWidth);
int GLHeight=AlignSize(TexHeight);
int AlignWidth=AlignSize(TexWidth);
int AlignHeight=AlignSize(TexHeight);
u8 *Src,*Dst;
// create RGB & alpha texture & ensuse texture is correct size for GL
Buffer=(u8*)malloc(GLWidth*GLHeight*4);
Buffer=(u8*)malloc(AlignWidth*AlignHeight*4);
Src=TexData->RGB;
Dst=&Buffer[0];
@ -153,18 +142,18 @@ u8 *Src,*Dst;
*Dst++=B;
*Dst++=A;
}
Dst+=(GLWidth-TexWidth)*4;
Dst+=(AlignWidth-TexWidth)*4;
}
ThisTex.TexWidth=TexWidth;
ThisTex.TexHeight=TexHeight;
ThisTex.dW=(1.0f)/(float)(GLWidth/16.0f);
ThisTex.dH=(1.0f)/(float)(GLHeight/16.0f);
ThisTex.ScaleU=(float)TexWidth/(float)AlignWidth;
ThisTex.ScaleV=(float)TexHeight/(float)AlignHeight;
glGenTextures(1, &ThisTex.TexID);
glBindTexture(GL_TEXTURE_2D, ThisTex.TexID);
glTexImage2D(GL_TEXTURE_2D, 0, 4, GLWidth, GLHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &Buffer[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 4, AlignWidth, AlignHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &Buffer[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);

View File

@ -25,12 +25,11 @@ struct sTex
GString Filename;
GString Name;
GLuint TexID;
int Flags;
int TexWidth,TexHeight;
float dW,dH;
float ScaleU,ScaleV; // For wrong size textures
bool Loaded;
bool operator==(sTex const &v1) {return (Filename==v1.Filename && Flags==v1.Flags);}
bool operator==(sTex const &v1) {return (Filename==v1.Filename);}
};
const RGBQUAD BlankRGB={255,0,255};
@ -44,7 +43,7 @@ public:
int GetTexIdx(sTex &Tex) {return(TexList.Find(Tex));}
int ProcessTexture(const char *Name,int Flags,sRGBData *RGBData=0);
int ProcessTexture(const char *Name,sRGBData *RGBData=0);
void Purge();
bool LoadBMP(const char *Filename,sRGBData &RGBData);

View File

@ -33,16 +33,11 @@ const float TileBrowserY0=0-TileBrowserGap/2;
const float TileBrowserY1=1+TileBrowserGap/2;
/*****************************************************************************/
CTileBank::CTileBank()
CTileBank::CTileBank() : CElemBank(16,16,true,false)
{
LoadFlag=false;
CurrentSet=0; LastSet=0;
for (int i=0; i<MaxBrush; i++) Brush[i].Delete();
LastCursorPos=CursorPos=-1;
ActiveBrush=0;
SelStart=-1;
SelEnd=-1;
VisibleFlag=true;
}
/*****************************************************************************/
@ -55,82 +50,27 @@ void CTileBank::Load(CFile *File,int Version)
{
if (Version<FileVersion)
{
int ListSize;
GFName RootPath=File->GetFilePath();
GString FilePath;
char FixPath[1024];
FilePath=RootPath.Drive();
FilePath+=RootPath.Dir();
FilePath.Append('\\');
FilePath.Upper();
File->Read(&ListSize,sizeof(int));
File->Read(&LayerCam,sizeof(Vector3));
File->Read(&CurrentSet,sizeof(int));
File->Read(&ActiveBrush,sizeof(int));
Brush[0].Load(File,Version);
Brush[1].Load(File,Version);
if (Version<2)
{
CurrentSet++;
}
// New Style rel storage
for (int i=0;i<ListSize;i++)
{
char c=1;
GString FullName;
while (c)
{
File->Read(&c,1);
FullName.Append(c);
}
FullName.Upper();
GFName::makeabsolute(FilePath,FullName,FixPath);
FullName=FixPath;
_fullpath( FixPath, FullName, 1024);
for (int z=0; z<strlen(FixPath); z++)
{// Invalidate any long name short cackness
if (FixPath[z]=='~') FixPath[z]='_';
}
FullName=FixPath;
CheckFilename(FullName);
FullName.Upper();
AddSet(FullName);
}
}
else
{
File->Read(&LayerCam,sizeof(Vector3));
File->Read(&CurrentSet,sizeof(int));
File->Read(&ActiveBrush,sizeof(int));
Brush[0].Load(File,Version);
Brush[1].Load(File,Version);
CElemBank::Load(File,Version);
File->Read(&LayerCam,sizeof(Vector3));
File->Read(&ActiveBrush,sizeof(int));
Brush[0].Load(File,Version);
Brush[1].Load(File,Version);
}
CElemBank::Load(File,Version);
}
/*****************************************************************************/
void CTileBank::Save(CFile *File)
{
int ListSize=GetSetCount();
GFName RootPath=File->GetFilePath();
GString SavePath;
SavePath=RootPath.Drive();
SavePath+=RootPath.Dir();
SavePath.Append('\\');
SavePath.Upper();
File->Write(&LayerCam,sizeof(Vector3));
File->Write(&CurrentSet,sizeof(int));
File->Write(&ActiveBrush,sizeof(int));
Brush[0].Save(File);
Brush[1].Save(File);
@ -138,19 +78,6 @@ GString SavePath;
CElemBank::Save(File);
}
/*****************************************************************************/
void CTileBank::RenderTile(int Set,int Elem,int Flags,bool Is3d)
{
if (IsValid(Set,Elem))
{
SetList[Set].RenderElem(Elem,Flags,Is3d);
}
else
{
SetList[0].RenderInvalid();
}
}
/*****************************************************************************/
void CTileBank::DeleteCurrent()
{
@ -171,15 +98,6 @@ int ListSize=GetSetCount();
if (CurrentSet) CurrentSet--;
}
/*****************************************************************************/
CPoint CTileBank::GetTilePos(int ID,int Width)
{
if (ID==0)
return(CPoint(-1,-1));
else
return(IDToPoint(ID-1,Width));
}
/*****************************************************************************/
void CTileBank::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
{
@ -200,7 +118,7 @@ float Scale=CamPos.z/(float)BrowserWidth/2.0;
while(TileID!=ListSize)
{
CPoint Pos=GetTilePos(TileID,BrowserWidth);
CPoint Pos=GetElemPos(TileID,BrowserWidth);
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
@ -263,14 +181,14 @@ float Scale=CamPos.z/(float)BrowserWidth/2.0;
if (SelStart==-1)
{
Start=GetTilePos(CursorPos,BrowserWidth);
Start=GetElemPos(CursorPos,BrowserWidth);
End=Start;
}
else
{
CPoint S=IDToPoint(SelStart-1,BrowserWidth);
CPoint E=IDToPoint(SelEnd-1,BrowserWidth);
CPoint E=IDToPoint(CursorPos-1,BrowserWidth);
Start=CPoint( min(S.x,E.x), min(S.y,E.y));
End=CPoint( max(S.x,E.x), max(S.y,E.y));
@ -303,119 +221,6 @@ float Scale=CamPos.z/(float)BrowserWidth/2.0;
}
/*****************************************************************************/
void CTileBank::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active)
{
if (!GetSetCount()) return;
CElemSet &ThisSet=SetList[CurrentSet];
int ListSize=ThisSet.GetCount();
int BrowserWidth=ThisSet.GetBrowserWidth();
int TileID=1; // Dont bother with blank, its sorted
float Scale=CamPos.z/(float)BrowserWidth/2.0;
if (!ListSize) return;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
while(TileID!=ListSize)
{
CPoint Pos=GetTilePos(TileID,BrowserWidth);
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
glLoadIdentity();
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
glBegin(GL_LINES);
glColor3f(1,1,1);
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++;
}
glPopMatrix();
}
/*****************************************************************************/
void CTileBank::FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos)
{
if (!GetSetCount()) return;
CElemSet &ThisSet=SetList[CurrentSet];
int ListSize=ThisSet.GetCount();
int BrowserWidth=ThisSet.GetBrowserWidth();
GLint Viewport[4];
GLuint SelectBuffer[SELECT_BUFFER_SIZE];
int HitCount;
int TileID=0;
float Scale=CamPos.z/(float)BrowserWidth/2.0;
if (!ListSize) return;
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);
Core->GetView()->SetupPersMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
while(TileID!=ListSize)
{
CPoint Pos=GetTilePos(TileID,BrowserWidth);
float XPos=(float)Pos.x*(1+TileBrowserGap);
float YPos=(float)Pos.y*(1+TileBrowserGap);
glLoadIdentity();
glScalef(Scale,Scale,Scale);
glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0);
glLoadName (TileID);
glBegin (GL_QUADS);
BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0);
glEnd();
TileID++;
}
HitCount= glRenderMode (GL_RENDER);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
// Process hits
GLuint *HitPtr=SelectBuffer;
TileID=-2;
if (HitCount) // Just take 1st
{
TileID=HitPtr[3];
}
glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert
CursorPos=TileID;
SelEnd=CursorPos;
}
/*****************************************************************************/
bool CTileBank::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
{
@ -567,7 +372,7 @@ void CTileBank::SetBrush(CMap &ThisBrush)
{
int BW=SetList[CurrentSet].GetBrowserWidth();
CPoint S=IDToPoint(SelStart-1,BW);
CPoint E=IDToPoint(SelEnd-1,BW);
CPoint E=IDToPoint(CursorPos-1,BW);
int Width=abs(E.x-S.x)+1;
int Height=abs(E.y-S.y)+1;

View File

@ -21,16 +21,10 @@
#include "GUIElemList.h"
/*****************************************************************************/
enum TileSetEnum
{
DefTileBrowserWidth=8,
};
/*****************************************************************************/
class CCore;
/*****************************************************************************/
class CTileBank : public CLayer, public CElemBank
class CTileBank : public CElemBank
{
public:
CTileBank();
@ -46,10 +40,10 @@ public:
int GetType() {return(0);}
void Render(CCore *Core,Vector3 &CamPos,bool Is3d);
void RenderGrid(CCore *Core,Vector3 &CamPos,bool Active);
// void RenderGrid(CCore *Core,Vector3 &CamPos,bool Active);
void RenderSelection(CCore *Core,Vector3 &ThisCam){};
void RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d);
void FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos);
// void FindCursorPos(CCore *Core,Vector3 &CamPos,CPoint &MousePos);
void GUIInit(CCore *Core);
void GUIKill(CCore *Core);
@ -66,12 +60,6 @@ public:
bool MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos);
bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0);
// ElemSet Thruput
const char *GetSetName(int Set) {return(SetList[Set].GetName());}
const char *GetSetFilename(int Set) {return(SetList[Set].GetFilename());}
CElem &GetTile(int Set,int Tile) {return(SetList[Set].GetElem(Tile));}
void RenderTile(int Set,int Elem,int Flags,bool Is3d);
// Local
void DeleteCurrent();
@ -81,7 +69,6 @@ const char *GetSetFilename(int Set) {return(SetList[Set].GetFilename());
CMap &GetActiveBrush() {return(GetBrush(ActiveBrush));}
bool CanClose() {return(SelStart==-1);}
CPoint GetTilePos(int ID,int Width);
// Functions
bool SelectCancel();
@ -89,20 +76,15 @@ const char *GetSetFilename(int Set) {return(SetList[Set].GetFilename());
protected:
bool Select(int BrushID,bool DownFlag);
void SetBrush(CMap &ThisBrush);
int CurrentSet,LastSet;
CMap Brush[2];
int ActiveBrush;
int SelStart,SelEnd;
CMap Brush[2];
int ActiveBrush;
int SelStart;
bool LoadFlag;
int LastCursorPos,CursorPos;
CGUIElemList GUIElemList;
CGUITileBank GUITileBank;
CGUIElemList GUIElemList;
CGUITileBank GUITileBank;
};
/*****************************************************************************/

View File

@ -14,7 +14,7 @@
#define IDD_NEWMAP 169
#define IDD_ADDLAYER 172
#define IDD_TILEBANK 173
#define IDD_LAYER_TOOLBAR 174
#define IDD_TOOLBAR 174
#define IDD_LAYER_SHADE 175
#define IDD_LAYER_COLLISION 177
#define IDD_ELEMLIST 178