/*******************/ /*** Layer Shade ***/ /*******************/ #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 "LayerShade.h" #include "Utils.h" #include "Select.h" #include "Export.h" #include "GUILayerShade.h" #include "Elem.h" /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ // New Layer CLayerShade::CLayerShade(sLayerDef &Def) { InitLayer(Def); GString ExecPath; GString ScriptName; GfxBank=new CElemBank(-1,-1,false,CElem::CentreModeLR | CElem::CentreModeTB); LoadGfx(); Cursor.Gfx=-1; Cursor.Ofs[0].x=-2; Cursor.Ofs[0].y=-2; Cursor.Ofs[1].x=+2; Cursor.Ofs[1].y=-2; Cursor.Ofs[2].x=-2; Cursor.Ofs[2].y=+2; Cursor.Ofs[3].x=+2; Cursor.Ofs[3].y=+2; Cursor.TransMode=0; for(int i=0; i<4; i++) { Cursor.RGB[i].R=Cursor.RGB[i].G=Cursor.RGB[i].B=255; } CurrentGfx=-1; } /*****************************************************************************/ CLayerShade::~CLayerShade() { GfxBank->CleanUp(); delete GfxBank; } /*****************************************************************************/ void CLayerShade::LoadGfx() { GString ExecPath; GString ScriptName; GetExecPath(ExecPath); ScriptName=ExecPath+theApp.GetConfigStr("LayerScript","BackGfxScript"); Script.LoadAndImport(ScriptName); int i,ListSize=Script.GetGroupCount(); BankList.resize(ListSize); for (i=0; iAddSet(Filename); } } } /*****************************************************************************/ void CLayerShade::InitLayer(sLayerDef &Def) { CLayer::InitLayer(Def); // LayerDef.Width=TileLayerMinWidth+(Def.Width-TileLayerMinWidth)/GetScaleFactor(); // LayerDef.Height=TileLayerMinHeight+(Def.Height-TileLayerMinHeight)/GetScaleFactor(); ShadeRGB[0].R=255; ShadeRGB[0].G=255; ShadeRGB[0].B=255; ShadeRGB[1].R=255; ShadeRGB[1].G=0; ShadeRGB[1].B=0; ShadeRGB[2].R=0; ShadeRGB[2].G=255; ShadeRGB[2].B=0; ShadeRGB[3].R=0; ShadeRGB[3].G=0; ShadeRGB[3].B=255; ShadeCount=2; } /*****************************************************************************/ void CLayerShade::Load(CFile *File,int Version) { int i; InitLayer(LayerDef); File->Read(&ShadeCount,sizeof(int)); if (Version<9) { // GOD I HATE FILE VERSIONS NOW!! int DummyInt; for (i=0; iRead(&DummyInt,sizeof(int)); File->Read(&RGB,sizeof(RGBQUAD)); ShadeRGB[i].R=RGB.rgbRed; ShadeRGB[i].G=RGB.rgbGreen; ShadeRGB[i].B=RGB.rgbBlue; } File->Read(&DummyInt,sizeof(int)); File->Read(&DummyInt,sizeof(int)); if (Version==8) { File->Read(&DummyInt,sizeof(int)); File->Read(&DummyInt,sizeof(int)); File->Read(&DummyInt,sizeof(int)); File->Read(&DummyInt,sizeof(int)); } } else { int GfxCount; for (i=0; iRead(&ShadeRGB[i],sizeof(sRGBCol)); } // Load GfxList File->Read(&GfxCount,sizeof(int)); GfxList.resize(GfxCount); for (i=0; iRead(&ThisGfx,sizeof(sLayerShadeGfx)); } if (GfxCount) CurrentGfx=0; } } /*****************************************************************************/ void CLayerShade::Save(CFile *File) { // Always Save current version File->Write(&ShadeCount,sizeof(int)); for (int i=0; iWrite(&ShadeRGB[i],sizeof(sRGBCol)); } int GfxCount=GfxList.size(); File->Write(&GfxCount,sizeof(int)); for (i=0; iWrite(&ThisGfx,sizeof(sLayerShadeGfx)); } } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CLayerShade::Render(CCore *Core,Vector3 &CamPos,bool Is3d) { Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor()); float ZoomW=Core->GetZoomW(); float ZoomH=Core->GetZoomH(); float ScrOfsX=(ZoomW/2); float ScrOfsY=(ZoomH/2); Vector3 &Scale=Core->GetScaleVector(); int ThisCount=ShadeCount-1; float X0=0; float X1=LayerDef.Width; float Y=(0+1); float YInc=(float)LayerDef.Height/(float)ThisCount; int i,ListSize; 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 glBegin (GL_QUADS); for (i=0; iOffsetCam(CamPos,GetScaleFactor()); CPoint &CursPos=Core->GetCursorPos(); Cursor.Pos.x=CursPos.x; Cursor.Pos.y=CursPos.y; if (CursPos.x<0 || CursPos.y<0) return; if (Cursor.Gfx==-1) return; RenderBackGfx(Core,ThisCam,Cursor); } /*****************************************************************************/ void CLayerShade::RenderBackGfx(CCore *Core,Vector3 &ThisCam,sLayerShadeGfx &ThisGfx) { float ZoomW=Core->GetZoomW(); float ZoomH=Core->GetZoomH(); Vector3 &Scale=Core->GetScaleVector(); Vector3 ScrOfs(ZoomW/2,ZoomH/2,0); int i; CElem Elem=GfxBank->GetElem(ThisGfx.Gfx,0); 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 glTranslatef(ThisGfx.Pos.x,-ThisGfx.Pos.y,0); // Set Pos glColor3ub(255,255,255); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, Elem.GetTexID()); glBegin (GL_QUADS); i=0; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(0.0f,1.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f); i=1; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(1.0f,1.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f); i=3; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(1.0f,0.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f); i=2; glColor3ub(ThisGfx.RGB[i].R,ThisGfx.RGB[i].G,ThisGfx.RGB[i].B); glTexCoord2f(0.0f,0.0f); glVertex3f(ThisGfx.Ofs[i].x ,-ThisGfx.Ofs[i].y,0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); } /*****************************************************************************/ void CLayerShade::CheckLayerSize(int Width,int Height) { if (Resize(Width,Height)) { CString mexstr; mexstr.Format("%s Layer Resized to Correct Size\nPlease re-save\n", GetName()); AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION); } } /*****************************************************************************/ bool CLayerShade::Resize(int Width,int Height) { Width=TileLayerMinWidth+(Width-TileLayerMinWidth)/GetScaleFactor(); Height=TileLayerMinHeight+(Height-TileLayerMinHeight)/GetScaleFactor(); if (LayerDef.Width!=Width || LayerDef.Height!=Height) { LayerDef.Width=Width; LayerDef.Height=Height; return(true); } return(false); } /*****************************************************************************/ /*** Gui *********************************************************************/ /*****************************************************************************/ void CLayerShade::GUIInit(CCore *Core) { int i,ListSize; GUIShade.DisableCallback(); Core->GUIAdd(GUIShade,IDD_LAYER_SHADE); // Init BankList ListSize=BankList.size(); GUIShade.m_GfxBankList.ResetContent(); GUIShade.m_DefList.ResetContent(); for (i=0; iRedrawView(); } /*****************************************************************************/ void CLayerShade::GUIKill(CCore *Core) { GUIChanged(Core); Core->GUIRemove(GUIShade,IDD_LAYER_SHADE); } /*****************************************************************************/ void CLayerShade::GUIUpdate(CCore *Core) { int i,ListSize; // Shades GUIShade.DisableCallback(); for (i=0; iGfxList.size()-1) CurrentGfx=GfxList.size()-1; GUIUpdate(Core); break; case CmdMsg_ShadeGfxGoto: GotoGfx(Core); break; case CmdMsg_ShadeGfxDelete: DeleteGfx(Core); break; default: break; } return(Ret); } /*****************************************************************************/ void CLayerShade::AddGfx(CCore *Core) { if (Cursor.Gfx==-1) return; CurrentGfx=GfxList.size(); GfxList.push_back(Cursor); Cursor.Gfx=-1; GUIUpdate(Core); } /*****************************************************************************/ void CLayerShade::GotoGfx(CCore *Core) { if (CurrentGfx==-1) return; sLayerShadeGfx &ThisGfx=GfxList[CurrentGfx]; CPoint Pos; Pos.x=ThisGfx.Pos.x; Pos.y=ThisGfx.Pos.y; Core->SetCamPos(Pos); } /*****************************************************************************/ void CLayerShade::DeleteGfx(CCore *Core) { if (!GfxList.size()) return; GfxList.erase(CurrentGfx); if (CurrentGfx) CurrentGfx--; GUIUpdate(Core); } /*****************************************************************************/ void CLayerShade::Export(CCore *Core,CExport &Exp) { int i,ListSize; Exp.ExportLayerHeader(LayerDef);//LAYER_TYPE_SHADE,LayerDef.SubType,LayerDef.Width,LayerDef.Height); Exp.Write(&ShadeCount,sizeof(int)); for (i=0; i