mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
Merge pull request #434 from timakro/pr_prevent_unused_tiles
Prevent placing unused tiles in the editor
This commit is contained in:
commit
09284c3ba9
|
@ -110,12 +110,12 @@ void CCollision::Init(class CLayers *pLayers)
|
||||||
{
|
{
|
||||||
// remove unused tiles from front layer
|
// remove unused tiles from front layer
|
||||||
Index = m_pFront[i].m_Index;
|
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;
|
m_pFront[i].m_Index = 0;
|
||||||
}
|
}
|
||||||
// remove unused tiles from game layer
|
// remove unused tiles from game layer
|
||||||
Index = m_pTiles[i].m_Index;
|
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;
|
m_pTiles[i].m_Index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1027,6 +1027,17 @@ void CEditor::DoToolbar(CUIRect ToolBar)
|
||||||
m_ShowEnvelopePreview = 0;
|
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);
|
TB_Top.VSplitLeft(15.0f, 0, &TB_Top);
|
||||||
|
|
||||||
// zoom group
|
// zoom group
|
||||||
|
|
|
@ -721,6 +721,7 @@ public:
|
||||||
m_SpeedupMaxSpeed = 0;
|
m_SpeedupMaxSpeed = 0;
|
||||||
m_SpeedupAngle = 0;
|
m_SpeedupAngle = 0;
|
||||||
m_LargeLayerWasWarned = false;
|
m_LargeLayerWasWarned = false;
|
||||||
|
m_AllowPlaceUnusedTiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Init();
|
virtual void Init();
|
||||||
|
@ -787,6 +788,7 @@ public:
|
||||||
int m_PopupEventActivated;
|
int m_PopupEventActivated;
|
||||||
int m_PopupEventWasActivated;
|
int m_PopupEventWasActivated;
|
||||||
bool m_LargeLayerWasWarned;
|
bool m_LargeLayerWasWarned;
|
||||||
|
bool m_AllowPlaceUnusedTiles;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,13 @@ void CLayerGame::SetTile(int x, int y, CTile tile, bool force)
|
||||||
CTile air = {TILE_AIR, 0, 0, 0};
|
CTile air = {TILE_AIR, 0, 0, 0};
|
||||||
m_pEditor->m_Map.m_pFrontLayer->SetTile(x, y, air, true);
|
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;
|
m_pTiles[y*m_Width+x] = tile;
|
||||||
|
} else {
|
||||||
|
CTile air = {TILE_AIR, 0, 0, 0};
|
||||||
|
SetTile(x, y, air);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1312,8 +1312,15 @@ CTile CLayerFront::GetTile(int x, int y, bool force)
|
||||||
|
|
||||||
void CLayerFront::SetTile(int x, int y, CTile tile, 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;
|
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)
|
void CLayerFront::Resize(int NewW, int NewH)
|
||||||
|
|
41
src/game/mapitems.cpp
Normal file
41
src/game/mapitems.cpp
Normal 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;
|
||||||
|
}
|
|
@ -152,7 +152,9 @@ enum
|
||||||
TILE_NPC_START = 104,
|
TILE_NPC_START = 104,
|
||||||
TILE_SUPER_START,
|
TILE_SUPER_START,
|
||||||
TILE_JETPACK_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
|
//End of higher tiles
|
||||||
//Layers
|
//Layers
|
||||||
LAYER_GAME=0,
|
LAYER_GAME=0,
|
||||||
|
@ -453,4 +455,9 @@ public:
|
||||||
unsigned char m_Type;
|
unsigned char m_Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bool IsValidGameTile(int Index);
|
||||||
|
bool IsValidFrontTile(int Index);
|
||||||
|
bool IsValidEntity(int Index);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue