SBSPSS/Utils/MapEdit/Elem.h

223 lines
5.8 KiB
C
Raw Normal View History

2001-03-01 20:42:09 +01:00
/******************/
/*** Elem Stuph ***/
/******************/
#ifndef __ELEM_HEADER__
#define __ELEM_HEADER__
#include "stdafx.h"
#include <Vector3.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <Vector>
#include "TexCache.h"
#include "GinTex.h"
2001-03-22 21:49:58 +01:00
#include "Layer.h"
#include "MapEdit.h"
#include "GUIElemList.h"
2001-03-01 20:42:09 +01:00
struct sTriFace
{
int Mat;
Vector3 vtx[3];
int pts[3];
sUV uvs[3];
};
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
class CCore;
class CElem
{
public:
enum ElemType
{
ElemType2d=0,
ElemType3d,
2001-03-05 21:49:46 +01:00
ElemTypeMax
2001-03-01 20:42:09 +01:00
};
2001-03-31 17:40:20 +02:00
enum CentreMode
{
CentreModeL =1<<0,
CentreModeR =1<<1,
CentreModeLR=1<<2,
CentreModeT =1<<3,
CentreModeB =1<<4,
CentreModeTB=1<<5,
};
2001-03-05 21:49:46 +01:00
enum
2001-03-01 20:42:09 +01:00
{
2001-03-05 21:49:46 +01:00
UnitSize=16,
2001-03-01 20:42:09 +01:00
};
2001-03-22 21:49:58 +01:00
CElem(int Width,int Height); // Blank (2d)
2001-03-31 17:40:20 +02:00
CElem(CCore *Core,const char *Filename,int TexId,int XOfs,int YOfs,int Width,int Height,int CentreMode=0); // 2d elem
2001-03-22 21:49:58 +01:00
CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node); // 3d elem
2001-03-05 21:49:46 +01:00
void CleanUp();
2001-03-06 19:39:42 +01:00
2001-03-01 20:42:09 +01:00
void Purge();
void Render(int Flags,bool Render3d);
2001-03-05 21:49:46 +01:00
int GetElemWidth() {return(ElemWidth);}
int GetElemHeight() {return(ElemHeight);}
u8 *GetElemRGB() {return(ElemRGB);}
2001-03-01 20:42:09 +01:00
bool IsValid() {return(ValidFlag);}
2001-04-07 23:05:33 +02:00
bool IsBlank() {return(BlankFlag);}
2001-03-01 20:42:09 +01:00
bool IsElem3d() {return(Type==ElemType3d);}
int GetTexXOfs() {return(TexXOfs);}
int GetTexYOfs() {return(TexYOfs);}
2001-03-27 18:26:43 +02:00
static void CreateDefaultTileGfx();
static int BlankID;
static int InvalidID;
static bool DefTexFlag;
2001-03-05 21:49:46 +01:00
2001-03-01 20:42:09 +01:00
std::vector<sTriFace> &GetTriList() {return(TriList);}
2001-04-07 23:05:33 +02:00
void SetBlank();
void SetInvalid();
2001-03-01 20:42:09 +01:00
protected:
void Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node);
void Build2dElem(CCore *Core,const char *Filename,int TexId);
void Build3dDrawList(CTexCache &TexCache,GLint &List);
void Build2dDrawList(CTexCache &TexCache,GLint &List);
void RenderElem4Texture(sRGBData &RGBData);
void Create2dTexture(CTexCache &TexCache,const char *Filename,int ID);
bool CheckHasData(sRGBData &RGBData);
2001-03-05 21:49:46 +01:00
void Calc3dSize();
2001-03-01 20:42:09 +01:00
GString SetPath;
std::vector<sTriFace> TriList;
Vector3 Ofs;
2001-03-05 21:49:46 +01:00
GLint DrawList[ElemTypeMax];
2001-03-01 20:42:09 +01:00
ElemType Type;
2001-04-07 23:05:33 +02:00
bool ValidFlag,BlankFlag;
2001-03-01 20:42:09 +01:00
int TexXOfs,TexYOfs;
2001-03-05 21:49:46 +01:00
int ElemWidth,ElemHeight;
float UnitWidth,UnitHeight;
int ElemID;
u8 *ElemRGB;
};
/*****************************************************************************/
class CElemSet
{
public:
enum
{
DEF_ELEMBROWSWEWIDTH=8,
};
2001-03-31 17:40:20 +02:00
CElemSet(const char *_Filename,int Idx,int MaxWidth,int MaxHeight,bool CreateBlank,int Centre=0);
2001-03-05 21:49:46 +01:00
~CElemSet();
2001-03-06 19:39:42 +01:00
void CleanUp();
2001-03-05 21:49:46 +01:00
int IsLoaded() {return(Loaded);}
int GetCount() {return(ElemList.size());}
void Load(CCore *Core);
const char *GetFilename() {return(Filename);}
const char *GetName() {return(Name);}
int GetBrowserWidth() {return(ElemBrowserWidth);}
void RenderElem(int Elem,int Flags,bool Render3d) {ElemList[Elem].Render(Flags,Render3d);}
CElem &GetElem(int No) {return(ElemList[No]);}
void Purge();
bool IsValid(int No);
bool operator==(CElemSet const &v1) {return (Name==v1.Name);}
private:
void Load2d(CCore *Core);
void Load3d(CCore *Core);
CPoint GetElemPos(int ID);
GString Filename,Name;
int SetNumber;
2001-03-22 21:49:58 +01:00
int MaxWidth,MaxHeight;
2001-03-31 03:30:53 +02:00
int BmpW,BmpH;
2001-03-31 17:40:20 +02:00
int CentreMode;
2001-03-05 21:49:46 +01:00
CList<CElem> ElemList;
bool Loaded;
int ElemBrowserWidth;
};
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
class CElemBank : public CLayer
2001-03-05 21:49:46 +01:00
{
public:
2001-03-22 21:49:58 +01:00
// Local
2001-03-31 17:40:20 +02:00
CElemBank(int MaxWidth,int MaxHeight,bool Blank,int Centre=0);
2001-03-22 21:49:58 +01:00
virtual ~CElemBank();
void CleanUp();
2001-03-05 21:49:46 +01:00
2001-03-22 21:49:58 +01:00
virtual void Load(CFile *File,int Version);
virtual void Save(CFile *File);
2001-03-05 21:49:46 +01:00
2001-03-31 03:30:53 +02:00
int AddSet(const char *Filename);
2001-03-05 21:49:46 +01:00
void LoadAllSets(CCore *Core);
void LoadNewSet(CCore *Core);
void ReloadAllSets();
void DeleteSet(int Set);
int NeedLoad() {return(LoadFlag);}
2001-03-22 21:49:58 +01:00
CElem &GetElem(int Set,int Elem) {return(SetList[Set].GetElem(Elem));}
2001-03-05 21:49:46 +01:00
bool IsValid(int Set,int Elem);
2001-03-22 21:49:58 +01:00
void RenderElem(int Set,int Elem,int Flags,bool Is3d);
2001-03-27 18:26:43 +02:00
void RenderInvalid() {glCallList(CElem::InvalidID);}
2001-03-05 21:49:46 +01:00
int GetSetCount() {return(SetList.size());}
2001-03-22 21:49:58 +01:00
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);
2001-03-05 21:49:46 +01:00
2001-03-22 21:49:58 +01:00
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:
2001-03-05 21:49:46 +01:00
CList<CElemSet> SetList;
2001-03-22 21:49:58 +01:00
2001-03-05 21:49:46 +01:00
bool LoadFlag;
2001-03-22 21:49:58 +01:00
int CurrentSet;
int CursorPos;
int MaxWidth,MaxHeight;
2001-03-31 17:40:20 +02:00
bool BlankFlag;
int CentreMode;
2001-03-22 21:49:58 +01:00
CGUIElemList GUIElemList;
2001-03-01 20:42:09 +01:00
};
/*****************************************************************************/
#endif