From fd7c0c39ac78f272a3796108b2ca925c0e77dd79 Mon Sep 17 00:00:00 2001 From: GreYFoXGTi Date: Fri, 27 Aug 2010 07:19:10 +0200 Subject: [PATCH] Reworked the Front Layer after reworking the front layer a similar bug was found, but this time fixed on double save, so i added a work around that double saves ( I'm not proud of this T.T ) Signed-off-by: GreYFoXGTi --- src/game/editor/ed_editor.cpp | 19 +++++++++-- src/game/editor/ed_editor.h | 12 +++++++ src/game/editor/ed_io.cpp | 22 +++++++++++++ src/game/editor/ed_layer_tiles.cpp | 53 ++++++++++++++++++++++++++++-- src/game/editor/ed_popups.cpp | 24 ++++++++++++-- src/game/layers.cpp | 3 ++ src/game/layers.h | 2 ++ 7 files changed, 126 insertions(+), 9 deletions(-) diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 686e92981..9253705e7 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -591,7 +591,8 @@ static void CallbackSaveMap(const char *pFileName, void *pUser) CEditor *pEditor = static_cast(pUser); if(pEditor->Save(pFileName)) - str_copy(pEditor->m_aFileName, pFileName, sizeof(pEditor->m_aFileName)); + if(pEditor->Save(pFileName)) + str_copy(pEditor->m_aFileName, pFileName, sizeof(pEditor->m_aFileName)); } void CEditor::DoToolbar(CUIRect ToolBar) @@ -1134,12 +1135,14 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) //UI()->ClipEnable(&view); } - // render the game, tele and speedup above everything else + // render the game, tele, speedup and front above everything else if(m_Map.m_pGameGroup->m_Visible) { m_Map.m_pGameGroup->MapScreen(); if(m_Map.m_pGameLayer->m_Visible) m_Map.m_pGameLayer->Render(); + if(m_Map.m_pFrontLayer && m_Map.m_pFrontLayer->m_Visible) + m_Map.m_pFrontLayer->Render(); if(m_Map.m_pTeleLayer && m_Map.m_pTeleLayer->m_Visible) m_Map.m_pTeleLayer->Render(); if(m_Map.m_pSpeedupLayer && m_Map.m_pSpeedupLayer->m_Visible) @@ -3016,6 +3019,13 @@ void CEditorMap::MakeSpeedupLayer(CLayer *pLayer) m_pSpeedupLayer->m_TexId = m_pEditor->ms_EntitiesTexture; } +void CEditorMap::MakeFrontLayer(CLayer *pLayer) +{ + m_pFrontLayer = (CLayerFront *)pLayer; + m_pFrontLayer->m_pEditor = m_pEditor; + m_pFrontLayer->m_TexId = m_pEditor->ms_EntitiesTexture; +} + void CEditorMap::MakeGameGroup(CLayerGroup *pGroup) { m_pGameGroup = pGroup; @@ -3034,6 +3044,7 @@ void CEditorMap::Clean() m_pGameLayer = 0x0; m_pTeleLayer = 0x0; m_pSpeedupLayer = 0x0; + m_pFrontLayer = 0x0; m_pGameGroup = 0x0; } @@ -3060,10 +3071,12 @@ void CEditorMap::CreateDefault(int EntitiesTexture) pQuad->m_aColors[2].b = pQuad->m_aColors[3].b = 255; pGroup->AddLayer(pLayer); - // add game layer + // add game layer and front MakeGameGroup(NewGroup()); MakeGameLayer(new CLayerGame(50, 50)); + MakeFrontLayer(new CLayerFront(50, 50)); m_pGameGroup->AddLayer(m_pGameLayer); + m_pGameGroup->AddLayer(m_pFrontLayer); m_pTeleLayer = 0x0; m_pSpeedupLayer = 0x0; } diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index 54a95fd11..a879edb29 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -265,6 +265,7 @@ public: class CLayerGame *m_pGameLayer; class CLayerTele *m_pTeleLayer; class CLayerSpeedup *m_pSpeedupLayer; + class CLayerFront *m_pFrontLayer; CLayerGroup *m_pGameGroup; CEnvelope *NewEnvelope(int Channels) @@ -321,6 +322,7 @@ public: void MakeTeleLayer(CLayer *pLayer); void MakeSpeedupLayer(CLayer *pLayer); + void MakeFrontLayer(CLayer *pLayer); }; @@ -387,6 +389,7 @@ public: int m_Game; int m_Tele; int m_Speedup; + int m_Front; int m_Image; int m_Width; int m_Height; @@ -455,6 +458,15 @@ public: virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect); }; +class CLayerFront : public CLayerTiles +{ +public: + CLayerFront(int w, int h); + + virtual void Resize(int NewW, int NewH); + virtual void BrushDraw(CLayer *pBrush, float wx, float wy); +}; + class CEditor : public IEditor { class IInput *m_pInput; diff --git a/src/game/editor/ed_io.cpp b/src/game/editor/ed_io.cpp index ba73ef1a4..be486303a 100644 --- a/src/game/editor/ed_io.cpp +++ b/src/game/editor/ed_io.cpp @@ -286,6 +286,8 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) Item.m_Flags = 2; else if(pLayer->m_Speedup) Item.m_Flags = 4; + else if(pLayer->m_Front) + Item.m_Flags = 8; else Item.m_Flags = pLayer->m_Game; Item.m_Image = pLayer->m_Image; @@ -305,6 +307,14 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName) Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile); delete[] Tiles; } + else if(pLayer->m_Front) + { + CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height]; + mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile)); + Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles); + Item.m_Front = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);//Thanks Sushi Tee + delete[] Tiles; + } else Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles); df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item); @@ -522,6 +532,11 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName) pTiles = new CLayerSpeedup(pTilemapItem->m_Width, pTilemapItem->m_Height); MakeSpeedupLayer(pTiles); } + else if(pTilemapItem->m_Flags&8) + { + pTiles = new CLayerFront(pTilemapItem->m_Width, pTilemapItem->m_Height); + MakeFrontLayer(pTiles); + } else { pTiles = new CLayerTiles(pTilemapItem->m_Width, pTilemapItem->m_Height); @@ -579,6 +594,13 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName) DataFile.UnloadData(pTilemapItem->m_Speedup); } + else if(pTiles->m_Front) + { + void *pFrontData = DataFile.GetData(pTilemapItem->m_Front); + mem_copy(((CLayerFront*)pTiles)->m_pTiles, pFrontData, pTiles->m_Width*pTiles->m_Height*sizeof(CTile)); + + DataFile.UnloadData(pTilemapItem->m_Front); + } } else if(pLayerItem->m_Type == LAYERTYPE_QUADS) { diff --git a/src/game/editor/ed_layer_tiles.cpp b/src/game/editor/ed_layer_tiles.cpp index 5a8d687ed..8111f4876 100644 --- a/src/game/editor/ed_layer_tiles.cpp +++ b/src/game/editor/ed_layer_tiles.cpp @@ -22,6 +22,7 @@ CLayerTiles::CLayerTiles(int w, int h) m_Game = 0; m_Tele = 0; m_Speedup = 0; + m_Front = 0; m_pTiles = new CTile[m_Width*m_Height]; mem_zero(m_pTiles, m_Width*m_Height*sizeof(CTile)); @@ -242,7 +243,7 @@ void CLayerTiles::BrushDraw(CLayer *pBrush, float wx, float wy) if(fx<0 || fx >= m_Width || fy < 0 || fy >= m_Height) continue; - // dont allow tele in and out tiles... same with speedup tile + // dont allow tele in and out tiles... same with speedup tile in game layer if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pGameLayer && (l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEIN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEOUT || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_BOOST)) continue; @@ -302,6 +303,10 @@ void CLayerTiles::Resize(int NewW, int NewH) // resize speedup layer if available if(m_Game && m_pEditor->m_Map.m_pSpeedupLayer && (m_pEditor->m_Map.m_pSpeedupLayer->m_Width != NewW || m_pEditor->m_Map.m_pSpeedupLayer->m_Height != NewH)) m_pEditor->m_Map.m_pSpeedupLayer->Resize(NewW, NewH); + + // resize front layer + if(m_Game && m_pEditor->m_Map.m_pFrontLayer && (m_pEditor->m_Map.m_pFrontLayer->m_Width != NewW || m_pEditor->m_Map.m_pFrontLayer->m_Height != NewH)) + m_pEditor->m_Map.m_pFrontLayer->Resize(NewW, NewH); } @@ -311,7 +316,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox) pToolBox->HSplitBottom(12.0f, pToolBox, &Button); bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty(); - if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this) + if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this) InGameGroup = false; static int s_ColclButton = 0; if(m_pEditor->DoButton_Editor(&s_ColclButton, Localize("Clear collision"), InGameGroup?0:-1, &Button, 0, Localize("Removes collision from this layer"))) @@ -362,7 +367,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox) {0}, }; - if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this) // remove the image from the selection if this is the game layer + if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this) // remove the image from the selection if this is the game/tele/speedup/front layer aProps[2].m_pName = 0; static int s_aIds[NUM_PROPS] = {0}; @@ -642,3 +647,45 @@ void CLayerSpeedup::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect) } } } + +CLayerFront::CLayerFront(int w, int h) +: CLayerTiles(w, h) +{ + m_pTypeName = "Front"; + m_Front = 1; +} + +void CLayerFront::Resize(int NewW, int NewH) +{ + // resize tile data + CLayerTiles::Resize(NewW, NewH); + + // resize gamelayer too + if(m_pEditor->m_Map.m_pGameLayer->m_Width != NewW || m_pEditor->m_Map.m_pGameLayer->m_Height != NewH) + m_pEditor->m_Map.m_pGameLayer->Resize(NewW, NewH); +} + +void CLayerFront::BrushDraw(CLayer *pBrush, float wx, float wy) +{ + if(m_Readonly) + return; + + // + CLayerTiles *l = (CLayerTiles *)pBrush; + int sx = ConvertX(wx); + int sy = ConvertY(wy); + + for(int y = 0; y < l->m_Height; y++) + for(int x = 0; x < l->m_Width; x++) + { + int fx = x+sx; + int fy = y+sy; + if(fx<0 || fx >= m_Width || fy < 0 || fy >= m_Height) + continue; + + // dont allow tele in and out tiles... same with speedup tile in front + if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pFrontLayer && (l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEIN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEOUT || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_BOOST)) + continue; + m_pTiles[fy*m_Width+fx] = l->m_pTiles[y*l->m_Width+x]; + } +} diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp index 5b14c8cc7..a2d3de868 100644 --- a/src/game/editor/ed_popups.cpp +++ b/src/game/editor/ed_popups.cpp @@ -127,6 +127,24 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View) } } + if(pEditor->GetSelectedGroup()->m_GameGroup && !pEditor->m_Map.m_pFrontLayer) + { + // new force layer + View.HSplitBottom(10.0f, &View, &Button); + View.HSplitBottom(12.0f, &View, &Button); + static int s_NewFrontLayerButton = 0; + if(pEditor->DoButton_Editor(&s_NewFrontLayerButton, "Add Front Layer", 0, &Button, 0, "Creates a new item layer")) + { + CLayer *l = new CLayerFront(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + pEditor->m_Map.MakeFrontLayer(l); + pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->AddLayer(l); + pEditor->m_SelectedLayer = pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_lLayers.size()-1; + pEditor->m_Brush.Clear(); + return 1; + } + } + + // new tile layer View.HSplitBottom(10.0f, &View, &Button); View.HSplitBottom(12.0f, &View, &Button); @@ -218,8 +236,8 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) View.HSplitBottom(12.0f, &View, &Button); static int s_DeleteButton = 0; - // don't allow deletion of game layer - if(pEditor->m_Map.m_pGameLayer != pEditor->GetSelectedLayer(0) && + // don't allow deletion of game/front layer + if(pEditor->m_Map.m_pGameLayer != pEditor->GetSelectedLayer(0) && pEditor->m_Map.m_pFrontLayer != pEditor->GetSelectedLayer(0) && pEditor->DoButton_Editor(&s_DeleteButton, Localize("Delete layer"), 0, &Button, 0, Localize("Deletes the layer"))) { if(pEditor->GetSelectedLayer(0) == pEditor->m_Map.m_pTeleLayer) @@ -250,7 +268,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View) {0}, }; - if(pEditor->m_Map.m_pGameLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pTeleLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pSpeedupLayer == pEditor->GetSelectedLayer(0)) // dont use Group and Detail from the selection if this is the game layer + if(pEditor->m_Map.m_pGameLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pTeleLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pSpeedupLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pFrontLayer == pEditor->GetSelectedLayer(0)) // dont use Group and Detail from the selection if this is the game layer { aProps[0].m_Type = PROPTYPE_NULL; aProps[2].m_Type = PROPTYPE_NULL; diff --git a/src/game/layers.cpp b/src/game/layers.cpp index 248b89436..6cbf22c9c 100644 --- a/src/game/layers.cpp +++ b/src/game/layers.cpp @@ -10,6 +10,7 @@ CLayers::CLayers() m_pGameLayer = 0; m_pTeleLayer = 0; m_pSpeedupLayer = 0; + m_pFrontLayer = 0; m_pMap = 0; } @@ -51,6 +52,8 @@ void CLayers::Init(class IKernel *pKernel) m_pTeleLayer = pTilemap; if(pTilemap->m_Flags&4) m_pSpeedupLayer = pTilemap; + if(pTilemap->m_Flags&8) + m_pFrontLayer = pTilemap; } } } diff --git a/src/game/layers.h b/src/game/layers.h index 97bd9521d..3b8ae9201 100644 --- a/src/game/layers.h +++ b/src/game/layers.h @@ -14,6 +14,7 @@ class CLayers CMapItemLayerTilemap *m_pGameLayer; CMapItemLayerTilemap *m_pTeleLayer; CMapItemLayerTilemap *m_pSpeedupLayer; + CMapItemLayerTilemap *m_pFrontLayer; class IMap *m_pMap; public: @@ -25,6 +26,7 @@ public: CMapItemLayerTilemap *GameLayer() const { return m_pGameLayer; } CMapItemLayerTilemap *TeleLayer() const { return m_pTeleLayer; } CMapItemLayerTilemap *SpeedupLayer() const { return m_pSpeedupLayer; } + CMapItemLayerTilemap *FrontLayer() const { return m_pFrontLayer; } CMapItemGroup *GetGroup(int Index) const; CMapItemLayer *GetLayer(int Index) const; };