/*******************/ /*** Layer Thing ***/ /*******************/ #include "stdafx.h" #include #include #include #include "GLEnabledView.h" #include "MapEdit.h" #include "MapEditDoc.h" #include "MapEditView.h" #include "MainFrm.h" #include "Core.h" #include "Layer.h" #include "LayerThing.h" #include "Utils.h" #include "Export.h" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CLayerThing::CLayerThing(sLayerDef &Def) { InitLayer(Def); } /*****************************************************************************/ CLayerThing::~CLayerThing() { ThingBank->CleanUp(); delete ThingBank; } /*****************************************************************************/ void CLayerThing::InitLayer(sLayerDef &Def) { CLayer::InitLayer(Def); Mode=MouseModeNormal; Cursor.XY.resize(1); Cursor.ElemID=-1; CurrentDefThing=-1; CurrentThing=-1; CurrentThingPoint=0; DrawPoints=true; } /*****************************************************************************/ void CLayerThing::Load(CFile *File,int Version) { int i,ListSize; File->Read(&Mode,sizeof(MouseMode)); File->Read(&CurrentDefThing,sizeof(int)); File->Read(&CurrentThing,sizeof(int)); File->Read(&CurrentThingPoint,sizeof(int)); File->Read(&ListSize,sizeof(int)); ThingList.resize(ListSize); // Load Data for (i=0;iRead(&ThisThing.Data,sizeof(sLayerThingData)); } LoadThingNames(File,Version); } /*****************************************************************************/ void CLayerThing::LoadThing(CFile *File,int Version,sLayerThing &ThisThing) { int i,ListSize; File->Read(&ListSize,sizeof(int)); ThisThing.XY.resize(ListSize); for (i=0 ;iRead(&ThisThing.XY[i],sizeof(CPoint)); } } /*****************************************************************************/ void CLayerThing::LoadThingNames(CFile *File,int Version) { int i,ListSize=ThingList.size(); for (i=0;iRead(&c,1); ThisName.Append(c); } // Update Gfx ID int Idx=FindDefThing(ThisName); ThisThing.ElemID=DefList[Idx].ElemID; } } /*****************************************************************************/ void CLayerThing::Save(CFile *File) { int i,ListSize=ThingList.size(); // Always Save current version File->Write(&Mode,sizeof(MouseMode)); File->Write(&CurrentDefThing,sizeof(int)); File->Write(&CurrentThing,sizeof(int)); File->Write(&CurrentThingPoint,sizeof(int)); File->Write(&ListSize,sizeof(int)); for (i=0;iWrite(&ThisThing.Data,sizeof(sLayerThingData)); } SaveThingNames(File); } /*****************************************************************************/ void CLayerThing::SaveThing(CFile *File,sLayerThing &ThisThing) { int i,ListSize=ThisThing.XY.size(); File->Write(&ListSize,sizeof(int)); for (i=0 ;iWrite(&ThisThing.XY[i],sizeof(CPoint)); } } /*****************************************************************************/ void CLayerThing::SaveThingNames(CFile *File) { int i,ListSize=ThingList.size(); for (i=0; iWrite(Txt,strlen(Txt)+1); } } /*****************************************************************************/ void CLayerThing::InitSubView(CCore *Core) { } /*****************************************************************************/ void CLayerThing::LoadThingScript(const char *Filename) { GString ExecPath; GString ScriptName; GetExecPath(ExecPath); ScriptName=ExecPath+Filename; ThingScript.LoadAndImport(ScriptName); int i,ListSize=ThingScript.GetGroupCount(); DefList.resize(ListSize); for (i=0; iAddSet(Filename); } else { TRACE1("BAD %s\n",Name); } } } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CLayerThing::Render(CCore *Core,Vector3 &CamPos,bool Is3d) { Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor()); int i,ListSize=ThingList.size(); for (i=0; iGetZoomW(); float ZoomH=Core->GetZoomH(); Vector3 &Scale=Core->GetScaleVector(); Vector3 ScrOfs(ZoomW/2,ZoomH/2,0); if (Render3d) { ScrOfs.z=-4.0f; } if (ThingBank->NeedLoad()) ThingBank->LoadAllSets(Core); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(Scale.x,Scale.y,Scale.z); glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset glTranslatef(-ScrOfs.x,ScrOfs.y,0); // Bring to top left corner int ListSize=ThisThing.XY.size(); for (int i=0;iRenderElem(ThisThing.ElemID,0,0,Render3d); glDisable(GL_DEPTH_TEST); glTranslatef(0,0,-ScrOfs.z); if (Selected) glColor4f(1,1,0,0.8f); else glColor4f(1,1,0,0.5f); if (DrawPoints) Core->RenderNumber(i); } else { if (Selected) glColor4f(1,1,1,1); // Set default Color else glColor4f(1,1,1,0.5); if (DrawPoints) Core->RenderNumber(i); } glPopMatrix(); } glPopMatrix(); } /*****************************************************************************/ /*** Gui *********************************************************************/ /*****************************************************************************/ void CLayerThing::GUIInit(CCore *Core) { } /*****************************************************************************/ void CLayerThing::GUIKill(CCore *Core) { } /*****************************************************************************/ void CLayerThing::GUIUpdate(CCore *Core) { } /*****************************************************************************/ void CLayerThing::GUIChanged(CCore *Core) { } /*****************************************************************************/ void CLayerThing::GUIThingUpdateList(CComboBox &List,bool OnlySel) { int i,ListSize; if (!OnlySel) { // Setup ThingList ListSize=ThingList.size(); List.ResetContent(); for (i=0; iOffsetCam(CamPos,GetScaleFactor()); CPoint &CursPos=Core->GetCursorPos(); Cursor.XY[0]=CursPos; if (CursPos.x<0 || CursPos.y<0) return; if (Mode!=MouseModeNew) return; if (Cursor.ElemID==-1) return; RenderThing(Core,ThisCam,Cursor,Is3d,true); } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ int CLayerThing::CheckThing(CPoint &Pos) { CList List; int Idx=-1,i,ListSize=ThingList.size(); int StartIdx=0; // Build List Of XY Matches for (i=0; i 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=ThisThing.XY.size()) return; CPoint Tmp=ThisThing.XY[CurrentThingPoint]; ThisThing.XY[CurrentThingPoint]=ThisThing.XY[NewPos]; ThisThing.XY[NewPos]=Tmp; CurrentThingPoint=NewPos; GUIThingPointUpdate(); } /*****************************************************************************/ void CLayerThing::DeletePoint() { if (!CurrentThingPoint) return; if (CurrentThing==-1) return; sLayerThing &ThisThing=ThingList[CurrentThing]; ThisThing.XY.erase(CurrentThingPoint); CurrentThingPoint--; if (CurrentThingPoint<0) CurrentThingPoint=0; GUIThingPointUpdate(); } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CLayerThing::Export(CCore *Core,CExport &Exp) { int i,ListSize=ThingList.size(); Exp.ExportLayerHeader(LayerDef); Exp.Write(&ListSize,sizeof(int)); for (i=0;i