ddnet/src/game/editor/layer_game.cpp
Robert Müller ede3e5631f Move generic popup handling to UI (port from editor and upstream)
Support using editor popup rendering in game client.

Support unlimited number of popup menus instead of maximum of 8.

Fix non-active popups handling key events. Add `Active` parameter to popup function, so key events are only processed by the active (top-most) popup. Previously the "New folder" popup could be confirmed with enter while an error message is shown, which causes multiple error messages to stack.

Allow popups to close without closing their child popups. Previously a popup could not open another popup and close itself immediately afterwards, as this was causing the newly opened popup to be closed instead.

Support using return/enter keys to confirm binary choice popups and to close message popups for more convenient usage.
2023-04-07 17:16:16 +02:00

73 lines
2.1 KiB
C++

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "editor.h"
CLayerGame::CLayerGame(int w, int h) :
CLayerTiles(w, h)
{
str_copy(m_aName, "Game", sizeof(m_aName));
m_Game = 1;
}
CLayerGame::~CLayerGame() = default;
CTile CLayerGame::GetTile(int x, int y)
{
if(m_pEditor->m_Map.m_pFrontLayer && m_pEditor->m_Map.m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
{
CTile through_cut = {TILE_THROUGH_CUT};
return through_cut;
}
else
{
return CLayerTiles::GetTile(x, y);
}
}
void CLayerGame::SetTile(int x, int y, CTile tile)
{
if(tile.m_Index == TILE_THROUGH_CUT && m_pEditor->m_SelectEntitiesImage == "DDNet")
{
if(!m_pEditor->m_Map.m_pFrontLayer)
{
CLayer *pLayerFront = new CLayerFront(m_Width, m_Height);
m_pEditor->m_Map.MakeFrontLayer(pLayerFront);
m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayerFront);
}
CTile nohook = {TILE_NOHOOK};
CLayerTiles::SetTile(x, y, nohook);
CTile through_cut = {TILE_THROUGH_CUT};
m_pEditor->m_Map.m_pFrontLayer->CLayerTiles::SetTile(x, y, through_cut); // NOLINT(bugprone-parent-virtual-call)
}
else
{
if(m_pEditor->m_SelectEntitiesImage == "DDNet" && m_pEditor->m_Map.m_pFrontLayer && m_pEditor->m_Map.m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
{
CTile air = {TILE_AIR};
m_pEditor->m_Map.m_pFrontLayer->CLayerTiles::SetTile(x, y, air); // NOLINT(bugprone-parent-virtual-call)
}
if(m_pEditor->m_AllowPlaceUnusedTiles || IsValidGameTile(tile.m_Index))
{
CLayerTiles::SetTile(x, y, tile);
}
else
{
CTile air = {TILE_AIR};
CLayerTiles::SetTile(x, y, air);
if(!m_pEditor->m_PreventUnusedTilesWasWarned)
{
m_pEditor->m_PopupEventType = CEditor::POPEVENT_PREVENTUNUSEDTILES;
m_pEditor->m_PopupEventActivated = true;
m_pEditor->m_PreventUnusedTilesWasWarned = true;
}
}
}
}
CUI::EPopupMenuFunctionResult CLayerGame::RenderProperties(CUIRect *pToolbox)
{
const CUI::EPopupMenuFunctionResult Result = CLayerTiles::RenderProperties(pToolbox);
m_Image = -1;
return Result;
}