From 653c5d0fda3ef5340d82febb0ec33c2f3570c425 Mon Sep 17 00:00:00 2001 From: Daveo Date: Mon, 26 Mar 2001 15:22:59 +0000 Subject: [PATCH] --- Utils/MapEdit/LayerActor.cpp | 459 +++++++++++++++++++++++++++++++++++ Utils/MapEdit/LayerActor.h | 97 ++++++++ 2 files changed, 556 insertions(+) create mode 100644 Utils/MapEdit/LayerActor.cpp create mode 100644 Utils/MapEdit/LayerActor.h diff --git a/Utils/MapEdit/LayerActor.cpp b/Utils/MapEdit/LayerActor.cpp new file mode 100644 index 000000000..a06f01c1d --- /dev/null +++ b/Utils/MapEdit/LayerActor.cpp @@ -0,0 +1,459 @@ +/***********************/ +/*** Layer Character ***/ +/***********************/ + +#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 "LayerThing.h" +#include "Utils.h" +#include "Export.h" + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +// New Layer +CLayerThing::CLayerThing(int _SubType,int _Width,int _Height) +{ + SetDefaultParams(); + + Mode=MouseModeNormal; + Width=_Width; + Height=_Height; + ThingBank=new CElemBank(-1,-1,false,true); + CurrentThing=-1; + CurrentPoint=0; + + LoadThingScript("c:\\temp\\character.txt"); +} + +/*****************************************************************************/ +// Load Layer +CLayerThing::CLayerThing(CFile *File,int Version) +{ + Load(File,Version); +} + +/*****************************************************************************/ +CLayerThing::~CLayerThing() +{ + ThingBank->CleanUp(); + delete ThingBank; +} + +/*****************************************************************************/ +void CLayerThing::Load(CFile *File,int Version) +{ + File->Read(&VisibleFlag,sizeof(BOOL)); + File->Read(&Mode,sizeof(MouseMode)); + + TRACE1("%s\t",GetName()); +} + +/*****************************************************************************/ +void CLayerThing::Save(CFile *File) +{ +// Always Save current version + File->Write(&VisibleFlag,sizeof(BOOL)); + File->Write(&Mode,sizeof(MouseMode)); +} + +/*****************************************************************************/ +void CLayerThing::InitSubView(CCore *Core) +{ +} + +/*****************************************************************************/ +void CLayerThing::LoadThingScript(const char *Filename) +{ + ThingScript.LoadAndImport(Filename); + +int Count=ThingScript.GetGroupCount(); + for (int i=0; iAddSet(Gfx); + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +void CLayerThing::Render(CCore *Core,Vector3 &CamPos,bool Is3d) +{ +Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor()); +int i,ListSize=ThingList.size(); + +// Is3d&=Render3dFlag; + for (i=0; iGetZoomW(); +float ZoomH=Core->GetZoomH(); +float ScrOfsX=(ZoomW/2); +float ScrOfsY=(ZoomH/2); +Vector3 &Scale=Core->GetScaleVector(); +CElemBank *IconBank=Core->GetIconBank(); + + 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(-ScrOfsX,ScrOfsY,0); // Bring to top left corner + +int ListSize=ThisThing.XY.size(); + for (int i=0;iRenderElem(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 CLayerThing::GUIInit(CCore *Core) +{ +// Core->GUIAdd(GUIToolBar,IDD_TOOLBAR); +} + +/*****************************************************************************/ +void CLayerThing::GUIKill(CCore *Core) +{ +// Core->GUIRemove(GUIToolBar,IDD_TOOLBAR); +} + +/*****************************************************************************/ +void CLayerThing::GUIUpdate(CCore *Core) +{ +} + +/*****************************************************************************/ +void CLayerThing::GUIChanged(CCore *Core) +{ +} + +/*****************************************************************************/ +/*** Functions ***************************************************************/ +/*****************************************************************************/ +bool CLayerThing::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) +{ +bool Ret=false; + + switch(Mode) + { + case MouseModeNormal: + if (DownFlag) + { + if (CurrentThing==-1) + AddThing(CursorPos); + else + AddThingPoint(CursorPos); + + } + break; + case MouseModePoints: + break; + default: + break; + } + + return(true); +} + +/*****************************************************************************/ +bool CLayerThing::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag) +{ +bool Ret=FALSE; + + switch(Mode) + { + case MouseModeNormal: + if (DownFlag) + { + SelectThing(CursorPos); + } + break; + case MouseModePoints: + break; + } + + return(Ret); +} + +/*****************************************************************************/ +bool CLayerThing::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos) +{ +bool Ret=false; + + if (CurrentThing!=-1) + { + if (nFlags & MK_LBUTTON) // Drag + { + UpdatePos(CursorPos,CurrentThing,CurrentPoint,true); + Ret=true; + } + else + if (nFlags & MK_RBUTTON) // Cancel + { + CurrentThing=-1; + Ret=true; + } + } + return(Ret); +} + +/*****************************************************************************/ +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=ThingBank->Command(CmdMsg,Core,Param0,Param1); + break; + default: + break; + } +*/ + return(Ret); +} + +/*****************************************************************************/ +void CLayerThing::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d) +{ +Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor()); +CPoint &CursPos=Core->GetCursorPos(); +Vector3 Ofs; + + if (CursPos.x<0 || CursPos.y<0) return; + + Ofs.x=-(CursPos.x-(int)ThisCam.x); + Ofs.y=-(CursPos.y-(int)ThisCam.y); + ThisCam.x-=(int)ThisCam.x; + ThisCam.y-=(int)ThisCam.y; + + if (Is3d && Render3dFlag) + { + glEnable(GL_DEPTH_TEST); +// Render(Core,ThisCam,,TRUE,0.5,&Ofs); + glDisable(GL_DEPTH_TEST); + } + else + { +// Render(Core,ThisCam,Brush,FALSE,0.5,&Ofs); + } +} + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +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; iGetElem(MapElem.Set,MapElem.Elem); + + OutElem.Set=MapElem.Set; + OutElem.Elem=MapElem.Elem; + OutElem.TriStart=0; + OutElem.TriCount=0; + OutElem.XOfs=ThisElem.GetTexXOfs(); + OutElem.YOfs=ThisElem.GetTexYOfs(); + OutElem.Elem=Exp.AddElem(OutElem); + OutElem.Flags=MapElem.Flags; + } + + Exp.Write(&OutElem,sizeof(sExpLayerThing)); + } + } +*/ +} diff --git a/Utils/MapEdit/LayerActor.h b/Utils/MapEdit/LayerActor.h new file mode 100644 index 000000000..4ade9ee28 --- /dev/null +++ b/Utils/MapEdit/LayerActor.h @@ -0,0 +1,97 @@ +/*******************/ +/*** Layer Thing ***/ +/*******************/ + +#ifndef __LAYER_THING_HEADER__ +#define __LAYER_THING_HEADER__ + +#include "Layer.h" +#include "MapEdit.h" +#include "GUIToolbar.h" +#include "Elem.h" + +/*****************************************************************************/ +struct sLayerThing +{ + std::vector XY; + int Type; + int SubType; + int Spare[8]; + +bool operator==(sLayerThing const &v1) +{ + if (XY[0]!=v1.XY[0]) return(false); + return(true); +} + +}; + +/*****************************************************************************/ +class CIni; +class CLayerThing : public CLayer +{ +public: + enum MouseMode + { + MouseModeNormal=0, + MouseModePoints, + }; + + 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); +virtual void LoadThingScript(const char *Filename); + +virtual void Export(CCore *Core,CExport &Exp); + +// Functions +virtual bool LButtonControl(CCore *Core,UINT nFlags, CPoint &point,bool DownFlag); +virtual bool RButtonControl(CCore *Core,UINT nFlags, CPoint &point,bool DownFlag); +virtual bool MouseMove(CCore *Core,UINT nFlags, CPoint &point); +virtual bool Command(int CmdMsg,CCore *Core,int Param0=0,int Param1=0); + +protected: + 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); + + void UpdatePos(CPoint &Pos,int Thing,int PosNo,bool Recurs=false); + + + int Width,Height; + CIni ThingScript; + CElemBank *ThingBank; + CList ThingList; + int CurrentThing,CurrentPoint; + MouseMode Mode; + + + CGUIToolBar GUIToolBar; + +}; + +/*****************************************************************************/ +#endif