From 1274ba20f688672b7f7b4130a5f87367dabda3a0 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 25 May 2024 20:19:09 +0300 Subject: [PATCH] correctly deleting GUI rects when changing trading screens --- Assets/Scripts/Gui/activeGameState.lua | 3 +++ Assets/Scripts/Gui/tradingScreen.lua | 6 ++++++ activeStateButton.cpp | 6 +++++- concreteGuiManager.cpp | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 94a0388..07aa28c 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -44,18 +44,21 @@ gui = { }, { guiType = GuiType.GUI_RECTANGLE, + name = 'refineds', pos = {x = 0, y = 0, z = 0}, size = {x = s, y = s}, imagePath = resIconBasePath .. 'refineds.png', }, { guiType = GuiType.GUI_RECTANGLE, + name = 'wealth', pos = {x = 200, y = 0, z = 0}, size = {x = s, y = s}, imagePath = resIconBasePath .. 'wealth.png', }, { guiType = GuiType.GUI_RECTANGLE, + name = 'research', pos = {x = 400, y = 0, z = 0}, size = {x = s, y = s}, imagePath = resIconBasePath .. 'research.png', diff --git a/Assets/Scripts/Gui/tradingScreen.lua b/Assets/Scripts/Gui/tradingScreen.lua index b62dd42..90aa351 100644 --- a/Assets/Scripts/Gui/tradingScreen.lua +++ b/Assets/Scripts/Gui/tradingScreen.lua @@ -58,6 +58,12 @@ function createResourceTrayGui(cpuPlayer, lineId, guiId, imgPath) end gui = { + { + guiType = GuiType.GUI_RECTANGLE, + pos = HubPos, + size = HubSize, + color = {x = 0, y = 0, z = 0, w = .6} + }, { guiType = GuiType.TEXT, name = 'P0', diff --git a/activeStateButton.cpp b/activeStateButton.cpp index 6e92853..2a25bbb 100644 --- a/activeStateButton.cpp +++ b/activeStateButton.cpp @@ -33,7 +33,11 @@ namespace battleship{ vector checkboxes{}; vector sliders{}; vector textboxes{}; - vector guiRects = guiManager->getGuiRectangles(); + vector guiRects{ + guiManager->getGuiRectangle("refineds"), + guiManager->getGuiRectangle("wealth"), + guiManager->getGuiRectangle("research"), + }; vector texts{ guiManager->getText("depth"), guiManager->getText("refineds"), diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 920bd48..7356c01 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -441,6 +441,7 @@ namespace battleship{ return textbox; } + //TODO factor out checking for optional lua values Node* ConcreteGuiManager::parseGuiRectangle(int guiId){ sol::state_view SOL_LUA_STATE = generateView(); sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1]; @@ -454,6 +455,10 @@ namespace battleship{ string imagePath = (pathOpt != sol::nullopt ? (string)guiTable[ipk] : ""); bool texturingEnabled = (imagePath != ""); + string nk = "name"; + sol::optional nameOpt = guiTable[nk]; + string name = (nameOpt != sol::nullopt ? (string)guiTable[nk] : ""); + mat->addBoolUniform("texturingEnabled", texturingEnabled); if(texturingEnabled){ @@ -471,7 +476,7 @@ namespace battleship{ quad->setMaterial(mat); sol::table posTable = guiTable["pos"]; - Node *guiRectangle = new Node(Vector3(posTable["x"], posTable["y"], posTable["z"])); + Node *guiRectangle = new Node(Vector3(posTable["x"], posTable["y"], posTable["z"]), Quaternion::QUAT_W, Vector3::VEC_IJK, name); guiRectangle->attachMesh(quad); root->getGuiNode()->attachChild(guiRectangle);