Merge pull request #434 from timakro/pr_prevent_unused_tiles

Prevent placing unused tiles in the editor
This commit is contained in:
Dennis Felsing 2016-04-29 22:36:35 +02:00
commit 09284c3ba9
7 changed files with 81 additions and 7 deletions

View file

@ -110,12 +110,12 @@ void CCollision::Init(class CLayers *pLayers)
{
// remove unused tiles from front layer
Index = m_pFront[i].m_Index;
if(Index <= TILE_NPH_START && !(Index == TILE_DEATH || (Index >= TILE_NOLASER && Index <= TILE_THROUGH) || Index == TILE_FREEZE || (Index >= TILE_UNFREEZE && Index <= TILE_DUNFREEZE) || (Index >= TILE_WALLJUMP && Index <= TILE_SOLO_END) || (Index >= TILE_REFILL_JUMPS && Index <= TILE_STOPA) || (Index >= TILE_CP && Index <= TILE_THROUGH_DIR) || (Index >= TILE_OLDLASER && Index <= TILE_UNLOCK_TEAM) || (Index >= TILE_NPC_END && Index <= TILE_NPH_END) || (Index >= TILE_NPC_START && Index <= TILE_NPH_START)))
if(!IsValidFrontTile(Index))
m_pFront[i].m_Index = 0;
}
// remove unused tiles from game layer
Index = m_pTiles[i].m_Index;
if(Index <= TILE_NPH_START && !((Index >= TILE_SOLID && Index <= TILE_NOLASER) || Index == TILE_THROUGH || Index == TILE_FREEZE || (Index >= TILE_UNFREEZE && Index <= TILE_DUNFREEZE) || (Index >= TILE_WALLJUMP && Index <= TILE_SOLO_END) || (Index >= TILE_REFILL_JUMPS && Index <= TILE_STOPA) || (Index >= TILE_CP && Index <= TILE_THROUGH_DIR) || (Index >= TILE_OLDLASER && Index <= TILE_UNLOCK_TEAM) || (Index >= TILE_NPC_END && Index <= TILE_NPH_END) || (Index >= TILE_NPC_START && Index <= TILE_NPH_START)))
if(!IsValidGameTile(Index))
m_pTiles[i].m_Index = 0;
}

View file

@ -1027,6 +1027,17 @@ void CEditor::DoToolbar(CUIRect ToolBar)
m_ShowEnvelopePreview = 0;
}
TB_Top.VSplitLeft(5.0f, 0, &TB_Top);
// allow place unused tiles button
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_AllowPlaceUnusedTilesButton = 0;
if(DoButton_Editor(&s_AllowPlaceUnusedTilesButton, "Unused", m_AllowPlaceUnusedTiles, &Button, 0, "[ctrl+u] Allow placing unused tiles") ||
(Input()->KeyDown('u') && (Input()->KeyPressed(KEY_LCTRL) || Input()->KeyPressed(KEY_RCTRL))))
{
m_AllowPlaceUnusedTiles = !m_AllowPlaceUnusedTiles;
}
TB_Top.VSplitLeft(15.0f, 0, &TB_Top);
// zoom group

View file

@ -721,6 +721,7 @@ public:
m_SpeedupMaxSpeed = 0;
m_SpeedupAngle = 0;
m_LargeLayerWasWarned = false;
m_AllowPlaceUnusedTiles = false;
}
virtual void Init();
@ -787,6 +788,7 @@ public:
int m_PopupEventActivated;
int m_PopupEventWasActivated;
bool m_LargeLayerWasWarned;
bool m_AllowPlaceUnusedTiles;
enum
{

View file

@ -42,7 +42,13 @@ void CLayerGame::SetTile(int x, int y, CTile tile, bool force)
CTile air = {TILE_AIR, 0, 0, 0};
m_pEditor->m_Map.m_pFrontLayer->SetTile(x, y, air, true);
}
// set normal game tile
if(m_pEditor->m_AllowPlaceUnusedTiles || IsValidGameTile(tile.m_Index)) {
m_pTiles[y*m_Width+x] = tile;
} else {
CTile air = {TILE_AIR, 0, 0, 0};
SetTile(x, y, air);
}
}
}

View file

@ -1312,8 +1312,15 @@ CTile CLayerFront::GetTile(int x, int y, bool force)
void CLayerFront::SetTile(int x, int y, CTile tile, bool force)
{
if(force || (GetTile(x, y, true).m_Index != TILE_THROUGH_CUT && tile.m_Index != TILE_THROUGH_CUT))
if(force || (GetTile(x, y, true).m_Index != TILE_THROUGH_CUT && tile.m_Index != TILE_THROUGH_CUT)) {
// set normal front tile
if(m_pEditor->m_AllowPlaceUnusedTiles || IsValidFrontTile(tile.m_Index)) {
m_pTiles[y*m_Width+x] = tile;
} else {
CTile air = {TILE_AIR, 0, 0, 0};
SetTile(x, y, air);
}
}
}
void CLayerFront::Resize(int NewW, int NewH)

41
src/game/mapitems.cpp Normal file
View file

@ -0,0 +1,41 @@
#include <game/mapitems.h>
bool IsValidGameTile(int Index)
{
return (IsValidEntity(Index)
|| Index == TILE_AIR
|| (Index >= TILE_SOLID && Index <= TILE_NOLASER)
|| Index == TILE_THROUGH
|| Index == TILE_FREEZE
|| (Index >= TILE_UNFREEZE && Index <= TILE_DUNFREEZE)
|| (Index >= TILE_WALLJUMP && Index <= TILE_SOLO_END)
|| (Index >= TILE_REFILL_JUMPS && Index <= TILE_STOPA)
|| (Index >= TILE_CP && Index <= TILE_THROUGH_DIR)
|| (Index >= TILE_OLDLASER && Index <= TILE_UNLOCK_TEAM)
|| (Index >= TILE_NPC_END && Index <= TILE_NPH_END)
|| (Index >= TILE_NPC_START && Index <= TILE_NPH_START)
|| (Index >= TILE_ENTITIES_OFF_1 && Index <= TILE_ENTITIES_OFF_2)
);
}
bool IsValidFrontTile(int Index)
{
return (IsValidEntity(Index)
|| Index == TILE_AIR
|| Index == TILE_DEATH
|| (Index >= TILE_NOLASER && Index <= TILE_THROUGH)
|| Index == TILE_FREEZE
|| (Index >= TILE_UNFREEZE && Index <= TILE_DUNFREEZE)
|| (Index >= TILE_WALLJUMP && Index <= TILE_SOLO_END)
|| (Index >= TILE_REFILL_JUMPS && Index <= TILE_STOPA)
|| (Index >= TILE_CP && Index <= TILE_THROUGH_DIR)
|| (Index >= TILE_OLDLASER && Index <= TILE_UNLOCK_TEAM)
|| (Index >= TILE_NPC_END && Index <= TILE_NPH_END)
|| (Index >= TILE_NPC_START && Index <= TILE_NPH_START)
);
}
bool IsValidEntity(int Index)
{
return Index > ENTITY_OFFSET;
}

View file

@ -152,7 +152,9 @@ enum
TILE_NPC_START = 104,
TILE_SUPER_START,
TILE_JETPACK_START,
TILE_NPH_START,//Remember to change this in collision.cpp if you add anymore tiles
TILE_NPH_START,
TILE_ENTITIES_OFF_1 = 190,
TILE_ENTITIES_OFF_2,
//End of higher tiles
//Layers
LAYER_GAME=0,
@ -453,4 +455,9 @@ public:
unsigned char m_Type;
};
bool IsValidGameTile(int Index);
bool IsValidFrontTile(int Index);
bool IsValidEntity(int Index);
#endif