/*******************/ /*** 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" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ // New Layer CLayerThing::CLayerThing(sLayerDef &Def) { InitLayer(Def); } /*****************************************************************************/ // Load Layer //CLayerThing::CLayerThing(CFile *File,int Version) //{ //Load(File,Version); //} /*****************************************************************************/ CLayerThing::~CLayerThing() { ThingBank->CleanUp(); delete ThingBank; } /*****************************************************************************/ void CLayerThing::InitLayer(sLayerDef &Def) { Mode=MouseModeNormal; LayerDef.Width=Width; LayerDef.Height=Height; ThingBank=new CElemBank(-1,-1,false,true); CurrentThing=-1; CurrentPoint=0; } /*****************************************************************************/ void CLayerThing::Load(CFile *File,int Version) { File->Read(&Mode,sizeof(MouseMode)); } /*****************************************************************************/ void CLayerThing::Save(CFile *File) { // Always Save current version File->Write(&Mode,sizeof(MouseMode)); } /*****************************************************************************/ void CLayerThing::InitSubView(CCore *Core) { } /*****************************************************************************/ void CLayerThing::LoadThingScript(const char *Filename) { ThingScript.LoadAndImport(Filename); } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ 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; Is3d&=GetRender3dFlag(); if (Is3d) { 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)); } } */ }