| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | #include "layer_game.h" |
| 4 | |
| 5 | #include <game/editor/editor.h> |
| 6 | #include <game/editor/editor_actions.h> |
| 7 | |
| 8 | CLayerGame::CLayerGame(CEditorMap *pMap, int w, int h) : |
| 9 | CLayerTiles(pMap, w, h) |
| 10 | { |
| 11 | str_copy(dst&: m_aName, src: "Game" ); |
| 12 | m_HasGame = true; |
| 13 | } |
| 14 | |
| 15 | CLayerGame::~CLayerGame() = default; |
| 16 | |
| 17 | CTile CLayerGame::GetTile(int x, int y) const |
| 18 | { |
| 19 | if(Map()->m_pFrontLayer && Map()->m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT) |
| 20 | { |
| 21 | return CTile{.m_Index: TILE_THROUGH_CUT}; |
| 22 | } |
| 23 | else |
| 24 | { |
| 25 | return CLayerTiles::GetTile(x, y); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void CLayerGame::SetTile(int x, int y, CTile Tile) |
| 30 | { |
| 31 | if(Tile.m_Index == TILE_THROUGH_CUT && Editor()->m_SelectEntitiesImage == "DDNet" ) |
| 32 | { |
| 33 | if(!Map()->m_pFrontLayer) |
| 34 | { |
| 35 | std::shared_ptr<CLayer> pLayerFront = std::make_shared<CLayerFront>(args: Map(), args&: m_Width, args&: m_Height); |
| 36 | Map()->MakeFrontLayer(pLayer: pLayerFront); |
| 37 | Map()->m_pGameGroup->AddLayer(pLayer: pLayerFront); |
| 38 | int GameGroupIndex = std::find(first: Map()->m_vpGroups.begin(), last: Map()->m_vpGroups.end(), val: Map()->m_pGameGroup) - Map()->m_vpGroups.begin(); |
| 39 | int LayerIndex = Map()->m_vpGroups[GameGroupIndex]->m_vpLayers.size() - 1; |
| 40 | Map()->m_EditorHistory.RecordAction(pAction: std::make_shared<CEditorActionAddLayer>(args: Map(), args&: GameGroupIndex, args&: LayerIndex)); |
| 41 | } |
| 42 | CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_NOHOOK}); |
| 43 | Map()->m_pFrontLayer->CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_THROUGH_CUT}); // NOLINT(bugprone-parent-virtual-call) |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | if(Editor()->m_SelectEntitiesImage == "DDNet" && Map()->m_pFrontLayer && Map()->m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT) |
| 48 | { |
| 49 | Map()->m_pFrontLayer->CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_AIR}); // NOLINT(bugprone-parent-virtual-call) |
| 50 | } |
| 51 | if(Editor()->IsAllowPlaceUnusedTiles() || IsValidGameTile(Index: Tile.m_Index)) |
| 52 | { |
| 53 | CLayerTiles::SetTile(x, y, Tile); |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_AIR}); |
| 58 | ShowPreventUnusedTilesWarning(); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | bool CLayerGame::IsEmpty() const |
| 64 | { |
| 65 | for(int y = 0; y < m_Height; y++) |
| 66 | { |
| 67 | for(int x = 0; x < m_Width; x++) |
| 68 | { |
| 69 | const int Index = GetTile(x, y).m_Index; |
| 70 | if(Index == 0) |
| 71 | { |
| 72 | continue; |
| 73 | } |
| 74 | if(Editor()->IsAllowPlaceUnusedTiles() || IsValidGameTile(Index)) |
| 75 | { |
| 76 | return false; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | CUi::EPopupMenuFunctionResult CLayerGame::RenderProperties(CUIRect *pToolbox) |
| 84 | { |
| 85 | const CUi::EPopupMenuFunctionResult Result = CLayerTiles::RenderProperties(pToolbox); |
| 86 | m_Image = -1; |
| 87 | return Result; |
| 88 | } |
| 89 | |
| 90 | const char *CLayerGame::TypeName() const |
| 91 | { |
| 92 | return "game" ; |
| 93 | } |
| 94 | |