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 <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
GreYFoXGTi 2010-08-27 07:19:10 +02:00
parent b3736dded4
commit fd7c0c39ac
7 changed files with 126 additions and 9 deletions

View file

@ -591,7 +591,8 @@ static void CallbackSaveMap(const char *pFileName, void *pUser)
CEditor *pEditor = static_cast<CEditor*>(pUser); CEditor *pEditor = static_cast<CEditor*>(pUser);
if(pEditor->Save(pFileName)) 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) void CEditor::DoToolbar(CUIRect ToolBar)
@ -1134,12 +1135,14 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
//UI()->ClipEnable(&view); //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) if(m_Map.m_pGameGroup->m_Visible)
{ {
m_Map.m_pGameGroup->MapScreen(); m_Map.m_pGameGroup->MapScreen();
if(m_Map.m_pGameLayer->m_Visible) if(m_Map.m_pGameLayer->m_Visible)
m_Map.m_pGameLayer->Render(); 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) if(m_Map.m_pTeleLayer && m_Map.m_pTeleLayer->m_Visible)
m_Map.m_pTeleLayer->Render(); m_Map.m_pTeleLayer->Render();
if(m_Map.m_pSpeedupLayer && m_Map.m_pSpeedupLayer->m_Visible) 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; 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) void CEditorMap::MakeGameGroup(CLayerGroup *pGroup)
{ {
m_pGameGroup = pGroup; m_pGameGroup = pGroup;
@ -3034,6 +3044,7 @@ void CEditorMap::Clean()
m_pGameLayer = 0x0; m_pGameLayer = 0x0;
m_pTeleLayer = 0x0; m_pTeleLayer = 0x0;
m_pSpeedupLayer = 0x0; m_pSpeedupLayer = 0x0;
m_pFrontLayer = 0x0;
m_pGameGroup = 0x0; m_pGameGroup = 0x0;
} }
@ -3060,10 +3071,12 @@ void CEditorMap::CreateDefault(int EntitiesTexture)
pQuad->m_aColors[2].b = pQuad->m_aColors[3].b = 255; pQuad->m_aColors[2].b = pQuad->m_aColors[3].b = 255;
pGroup->AddLayer(pLayer); pGroup->AddLayer(pLayer);
// add game layer // add game layer and front
MakeGameGroup(NewGroup()); MakeGameGroup(NewGroup());
MakeGameLayer(new CLayerGame(50, 50)); MakeGameLayer(new CLayerGame(50, 50));
MakeFrontLayer(new CLayerFront(50, 50));
m_pGameGroup->AddLayer(m_pGameLayer); m_pGameGroup->AddLayer(m_pGameLayer);
m_pGameGroup->AddLayer(m_pFrontLayer);
m_pTeleLayer = 0x0; m_pTeleLayer = 0x0;
m_pSpeedupLayer = 0x0; m_pSpeedupLayer = 0x0;
} }

View file

@ -265,6 +265,7 @@ public:
class CLayerGame *m_pGameLayer; class CLayerGame *m_pGameLayer;
class CLayerTele *m_pTeleLayer; class CLayerTele *m_pTeleLayer;
class CLayerSpeedup *m_pSpeedupLayer; class CLayerSpeedup *m_pSpeedupLayer;
class CLayerFront *m_pFrontLayer;
CLayerGroup *m_pGameGroup; CLayerGroup *m_pGameGroup;
CEnvelope *NewEnvelope(int Channels) CEnvelope *NewEnvelope(int Channels)
@ -321,6 +322,7 @@ public:
void MakeTeleLayer(CLayer *pLayer); void MakeTeleLayer(CLayer *pLayer);
void MakeSpeedupLayer(CLayer *pLayer); void MakeSpeedupLayer(CLayer *pLayer);
void MakeFrontLayer(CLayer *pLayer);
}; };
@ -387,6 +389,7 @@ public:
int m_Game; int m_Game;
int m_Tele; int m_Tele;
int m_Speedup; int m_Speedup;
int m_Front;
int m_Image; int m_Image;
int m_Width; int m_Width;
int m_Height; int m_Height;
@ -455,6 +458,15 @@ public:
virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect); 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 CEditor : public IEditor
{ {
class IInput *m_pInput; class IInput *m_pInput;

View file

@ -286,6 +286,8 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Flags = 2; Item.m_Flags = 2;
else if(pLayer->m_Speedup) else if(pLayer->m_Speedup)
Item.m_Flags = 4; Item.m_Flags = 4;
else if(pLayer->m_Front)
Item.m_Flags = 8;
else else
Item.m_Flags = pLayer->m_Game; Item.m_Flags = pLayer->m_Game;
Item.m_Image = pLayer->m_Image; 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); Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile);
delete[] Tiles; 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 else
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles); Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item); 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); pTiles = new CLayerSpeedup(pTilemapItem->m_Width, pTilemapItem->m_Height);
MakeSpeedupLayer(pTiles); MakeSpeedupLayer(pTiles);
} }
else if(pTilemapItem->m_Flags&8)
{
pTiles = new CLayerFront(pTilemapItem->m_Width, pTilemapItem->m_Height);
MakeFrontLayer(pTiles);
}
else else
{ {
pTiles = new CLayerTiles(pTilemapItem->m_Width, pTilemapItem->m_Height); 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); 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) else if(pLayerItem->m_Type == LAYERTYPE_QUADS)
{ {

View file

@ -22,6 +22,7 @@ CLayerTiles::CLayerTiles(int w, int h)
m_Game = 0; m_Game = 0;
m_Tele = 0; m_Tele = 0;
m_Speedup = 0; m_Speedup = 0;
m_Front = 0;
m_pTiles = new CTile[m_Width*m_Height]; m_pTiles = new CTile[m_Width*m_Height];
mem_zero(m_pTiles, m_Width*m_Height*sizeof(CTile)); 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) if(fx<0 || fx >= m_Width || fy < 0 || fy >= m_Height)
continue; 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)) 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; continue;
@ -302,6 +303,10 @@ void CLayerTiles::Resize(int NewW, int NewH)
// resize speedup layer if available // 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)) 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); 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); pToolBox->HSplitBottom(12.0f, pToolBox, &Button);
bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty(); 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; InGameGroup = false;
static int s_ColclButton = 0; 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"))) 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}, {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; aProps[2].m_pName = 0;
static int s_aIds[NUM_PROPS] = {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];
}
}

View file

@ -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 // new tile layer
View.HSplitBottom(10.0f, &View, &Button); View.HSplitBottom(10.0f, &View, &Button);
View.HSplitBottom(12.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); View.HSplitBottom(12.0f, &View, &Button);
static int s_DeleteButton = 0; static int s_DeleteButton = 0;
// don't allow deletion of game layer // don't allow deletion of game/front layer
if(pEditor->m_Map.m_pGameLayer != pEditor->GetSelectedLayer(0) && 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"))) pEditor->DoButton_Editor(&s_DeleteButton, Localize("Delete layer"), 0, &Button, 0, Localize("Deletes the layer")))
{ {
if(pEditor->GetSelectedLayer(0) == pEditor->m_Map.m_pTeleLayer) if(pEditor->GetSelectedLayer(0) == pEditor->m_Map.m_pTeleLayer)
@ -250,7 +268,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View)
{0}, {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[0].m_Type = PROPTYPE_NULL;
aProps[2].m_Type = PROPTYPE_NULL; aProps[2].m_Type = PROPTYPE_NULL;

View file

@ -10,6 +10,7 @@ CLayers::CLayers()
m_pGameLayer = 0; m_pGameLayer = 0;
m_pTeleLayer = 0; m_pTeleLayer = 0;
m_pSpeedupLayer = 0; m_pSpeedupLayer = 0;
m_pFrontLayer = 0;
m_pMap = 0; m_pMap = 0;
} }
@ -51,6 +52,8 @@ void CLayers::Init(class IKernel *pKernel)
m_pTeleLayer = pTilemap; m_pTeleLayer = pTilemap;
if(pTilemap->m_Flags&4) if(pTilemap->m_Flags&4)
m_pSpeedupLayer = pTilemap; m_pSpeedupLayer = pTilemap;
if(pTilemap->m_Flags&8)
m_pFrontLayer = pTilemap;
} }
} }
} }

View file

@ -14,6 +14,7 @@ class CLayers
CMapItemLayerTilemap *m_pGameLayer; CMapItemLayerTilemap *m_pGameLayer;
CMapItemLayerTilemap *m_pTeleLayer; CMapItemLayerTilemap *m_pTeleLayer;
CMapItemLayerTilemap *m_pSpeedupLayer; CMapItemLayerTilemap *m_pSpeedupLayer;
CMapItemLayerTilemap *m_pFrontLayer;
class IMap *m_pMap; class IMap *m_pMap;
public: public:
@ -25,6 +26,7 @@ public:
CMapItemLayerTilemap *GameLayer() const { return m_pGameLayer; } CMapItemLayerTilemap *GameLayer() const { return m_pGameLayer; }
CMapItemLayerTilemap *TeleLayer() const { return m_pTeleLayer; } CMapItemLayerTilemap *TeleLayer() const { return m_pTeleLayer; }
CMapItemLayerTilemap *SpeedupLayer() const { return m_pSpeedupLayer; } CMapItemLayerTilemap *SpeedupLayer() const { return m_pSpeedupLayer; }
CMapItemLayerTilemap *FrontLayer() const { return m_pFrontLayer; }
CMapItemGroup *GetGroup(int Index) const; CMapItemGroup *GetGroup(int Index) const;
CMapItemLayer *GetLayer(int Index) const; CMapItemLayer *GetLayer(int Index) const;
}; };