From 4563e58117c5edb421dc04a3550d0e36209bd5a9 Mon Sep 17 00:00:00 2001 From: Daveo Date: Tue, 13 Mar 2001 18:01:46 +0000 Subject: [PATCH] --- Utils/MapEdit/ElemStore.cpp | 638 ++++++++++++++++++++++++++++++++++++ Utils/MapEdit/ElemStore.h | 108 ++++++ 2 files changed, 746 insertions(+) create mode 100644 Utils/MapEdit/ElemStore.cpp create mode 100644 Utils/MapEdit/ElemStore.h diff --git a/Utils/MapEdit/ElemStore.cpp b/Utils/MapEdit/ElemStore.cpp new file mode 100644 index 000000000..c3c3deb23 --- /dev/null +++ b/Utils/MapEdit/ElemStore.cpp @@ -0,0 +1,638 @@ +/************************/ +/*** Elem Sotre Stuph ***/ +/************************/ + +#include "stdafx.h" +#include +#include +#include +#include "GLEnabledView.h" +#include + +#include + +#include "Core.h" +#include "ElemStore.h" +#include "GinTex.h" +#include "utils.h" + +#include "MapEdit.h" +#include "MapEditDoc.h" +#include "MapEditView.h" +#include "MainFrm.h" +#include "LayerTileGui.h" + +/*****************************************************************************/ +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; + +/*****************************************************************************/ +CElemStore::CElemStore() +{ + LoadFlag=false; + CurrentSet=0; LastSet=0; + for (int i=0; iGetFilePath(); + GString FilePath; + char FixPath[1024]; + + FilePath=RootPath.Drive(); + FilePath+=RootPath.Dir(); + FilePath.Append('\\'); + FilePath.Upper(); + + 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); + if (Version<2) + { + CurrentSet++; + } + + // New Style rel storage + for (int i=0;iRead(&c,1); + FullName.Append(c); + } + FullName.Upper(); + GFName::makeabsolute(FilePath,FullName,FixPath); + FullName=FixPath; + _fullpath( FixPath, FullName, 1024); + for (int z=0; zRead(&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); + } + + +} + +/*****************************************************************************/ +void CElemStore::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); + + CElemBank::Save(File); +} + +/*****************************************************************************/ +void CElemStore::RenderElem(int Set,int Elem,int Flags,bool Is3d) +{ + if (IsValid(Set,Elem)) + { + SetList[Set].RenderElem(Elem,Flags,Is3d); + } + else + { + SetList[0].RenderInvalid(); + } + +} +/*****************************************************************************/ +void CElemStore::DeleteCurrent() +{ +int ListSize=GetSetCount(); +// Remap Brushes + for (int i=0; iListSize) return; + if (!ListSize) return; + + + if (SelStart==-1) + { + Start=GetElemPos(CursorPos,BrowserWidth); + End=Start; + } + else + { + + CPoint S=IDToPoint(SelStart-1,BrowserWidth); + CPoint E=IDToPoint(SelEnd-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)); + if (PointToID(End,BrowserWidth)>=MaxElem) return; // Invalid selection + } + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + for (int Y=Start.y; Y<=End.y; Y++) + { + for (int X=Start.x; X<=End.x; X++) + { + float XPos=(float)X*(1+ElemBrowserGap); + float YPos=(float)Y*(1+ElemBrowserGap); + + glLoadIdentity(); + glScalef(Scale,Scale,Scale); + glTranslatef(-CamPos.x+XPos,CamPos.y-YPos,0); + + + glBegin(GL_QUADS); + glColor4f(1,1,0,0.5); + BuildGLQuad(ElemBrowserX0,ElemBrowserX1,ElemBrowserY0,ElemBrowserY1,0); + glEnd(); + + } + } + glPopMatrix(); + +} + +/*****************************************************************************/ +void CElemStore::RenderGrid(CCore *Core,Vector3 &CamPos,bool Active) +{ + if (!GetSetCount()) return; +CElemSet &ThisSet=SetList[CurrentSet]; +int ListSize=ThisSet.GetCount(); +int BrowserWidth=ThisSet.GetBrowserWidth(); +int ElemID=1; // Dont bother with blank, its sorted +float Scale=CamPos.z/(float)BrowserWidth/2.0; + + if (!ListSize) return; + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + while(ElemID!=ListSize) + { + CPoint Pos=GetElemPos(ElemID,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(); + + ElemID++; + } + glPopMatrix(); +} + +/*****************************************************************************/ +void CElemStore::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 ElemID=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(ElemID!=ListSize) + { + CPoint Pos=GetElemPos(ElemID,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 (ElemID); + glBegin (GL_QUADS); + BuildGLQuad(ElemBrowserX0,ElemBrowserX1,ElemBrowserY0,ElemBrowserY1,0); + glEnd(); + ElemID++; + } + + HitCount= glRenderMode (GL_RENDER); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + +// Process hits + +GLuint *HitPtr=SelectBuffer; + + ElemID=-2; + if (HitCount) // Just take 1st + { + ElemID=HitPtr[3]; + } + glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert + + CursorPos=ElemID; + SelEnd=CursorPos; +} + +/*****************************************************************************/ +bool CElemStore::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) +{ + if (nFlags & MK_RBUTTON) + { + SelectCancel(); + return(false); + } + Select(LBrush,DownFlag); + + return(true); +} + +/*****************************************************************************/ +bool CElemStore::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) +{ + if (nFlags & MK_LBUTTON) + { + SelectCancel(); + return(false); + } + + Select(RBrush,DownFlag); + + return(false); +} + +/*****************************************************************************/ +bool CElemStore::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos) +{ + return(false); +} + +/*****************************************************************************/ +bool CElemStore::Command(int CmdMsg,CCore *Core,int Param0,int Param1) +{ + switch(CmdMsg) + { + case CmdMsg_SubViewLoad: + LoadNewSet(Core); + GUIUpdate(Core); + break; + case CmdMsg_SubViewDelete: + DeleteSet(Core); + GUIUpdate(Core); + break; + case CmdMsg_SubViewUpdate: + ReloadAllSets(); + Core->GetTexCache().Purge(); + GUIUpdate(Core); + break; + case CmdMsg_SubViewSet: + CurrentSet=ElemStoreGUI.m_List.GetCurSel(); + GUIUpdate(Core); + break; + case CmdMsg_ActiveBrushLeft: + ActiveBrush=LBrush; + break; + case CmdMsg_ActiveBrushRight: + ActiveBrush=RBrush; + default: + TRACE3("ElemStore-Unhandled Command %i (%i,%i)\n",CmdMsg,Param0,Param1); + } + return(true); +} + +/*****************************************************************************/ +/*** Gui *********************************************************************/ +/*****************************************************************************/ +void CElemStore::GUIInit(CCore *Core) +{ + Core->GUIAdd(ElemStoreGUI,IDD_LAYERTILE_GUI); +} + +/*****************************************************************************/ +void CElemStore::GUIKill(CCore *Core) +{ + Core->GUIRemove(ElemStoreGUI,IDD_LAYERTILE_GUI); +} + +/*****************************************************************************/ +void CElemStore::GUIUpdate(CCore *Core) +{ +int ListSize=GetSetCount(); +bool IsSubView=Core->IsSubView(); + + if (ElemStoreGUI.m_List) + { + ElemStoreGUI.m_List.ResetContent(); + if (ListSize) + { + for (int i=0; i=MaxElem) SelectCancel(); // Invalid selection + + ThisElem.Set=CurrentSet; + ThisElem.Flags=0; + + ThisBrush.Delete(); + ThisBrush.SetSize(Width,Height); + + for (int Y=0; YQuestion("Delete Current Elem Bank\n\nAll used Elems in current set will be set to blank\nAre you sure?")) + { + int SetCount=GetSetCount(); + int i,ListSize=Core->GetLayerCount(); + + for (i=0;iGetLayer(i); + if (ThisLayer->GetType()==LAYER_TYPE_TILE) + { + ThisLayer->RemoveSet(CurrentSet); + } + } + DeleteCurrent(); + + for (int Set=CurrentSet+1; SetGetLayer(i); + if (ThisLayer->GetType()==LAYER_TYPE_TILE) + { + ThisLayer->RemapSet(Set,Set-1); + } + } + } + } + CurrentSet--; + GUIUpdate(Core); +} + diff --git a/Utils/MapEdit/ElemStore.h b/Utils/MapEdit/ElemStore.h new file mode 100644 index 000000000..7890a5dd9 --- /dev/null +++ b/Utils/MapEdit/ElemStore.h @@ -0,0 +1,108 @@ +/***********************/ +/*** ElemSotre Stuph ***/ +/***********************/ + +#ifndef __ELEMSTORE_HEADER__ +#define __ELEMSTORE_HEADER__ + +#include "stdafx.h" +#include +#include +#include +#include +#include + +#include "Layer.h" +#include "TexCache.h" +#include "Elem.h" + +#include "MapEdit.h" +#include "LayerTileGui.h" + +/*****************************************************************************/ +enum ElemStoreEnum +{ +DefBrowserWidth=8, +}; + +/*****************************************************************************/ +class CCore; + +/*****************************************************************************/ +class CElemStore : public CLayer, public CElemBank +{ +public: + CElemStore(); + ~CElemStore(); + + enum BrushEnum + { + LBrush=0, + RBrush, + MaxBrush + }; +// Overloads + int GetType() {return(0);} + + void Render(CCore *Core,Vector3 &CamPos,bool Is3d); + 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 GUIInit(CCore *Core); + void GUIKill(CCore *Core); + void GUIUpdate(CCore *Core); + void GUIChanged(CCore *Core); + + void Load(CFile *File,int Version); + void Save(CFile *File); + + void Export(CCore *Core,CExport &Exp){}; + + bool LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag); + bool RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag); + 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 &GetElem(int Set,int Elem) {return(SetList[Set].GetElem(Elem));} + void RenderElem(int Set,int Elem,int Flags,bool Is3d); + +// Local + void DeleteCurrent(); + + CMap &GetLBrush() {return(Brush[LBrush]);} + CMap &GetRBrush() {return(Brush[RBrush]);} + CMap &GetBrush(int i) {return(Brush[i]);} + CMap &GetActiveBrush() {return(GetBrush(ActiveBrush));} + + bool CanClose() {return(SelStart==-1);} + CPoint GetElemPos(int ID,int Width); + +// Functions + bool SelectCancel(); + void DeleteSet(CCore *Core); + + +protected: + + bool Select(int BrushID,bool DownFlag); + void SetBrush(CMap &ThisBrush); + + int CurrentSet,LastSet; + CMap Brush[2]; + int ActiveBrush; + int SelStart,SelEnd; + + bool LoadFlag; + int LastCursorPos,CursorPos; + + CLayerTileGUI ElemStoreGUI; + +}; + +/*****************************************************************************/ +#endif \ No newline at end of file