From 86b5bf9731681c6a26f2ee3aa847b147efa7b2e3 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 2 Jan 2026 17:22:56 +0200 Subject: [PATCH] bugfix for crashes when clicking on trade centers or labs --- Assets/Scripts/GameObjects/Units/unitData.lua | 6 +- Assets/Scripts/Gui/acsTechTree.lua | 106 ++++++++++++++++++ Assets/Scripts/Gui/aincTechTree.lua | 106 ++++++++++++++++++ .../Gui/{techTree.lua => erTechTree.lua} | 2 +- Assets/Scripts/Gui/main.lua | 17 +-- Assets/Scripts/Gui/researchStructCommands.lua | 27 ----- buildButton.cpp | 7 +- buildButton.h | 2 +- concreteGuiManager.cpp | 17 +-- concreteGuiManager.h | 1 + researchButton.cpp | 8 +- researchButton.h | 2 +- tradeButton.cpp | 2 +- tradeButton.h | 2 +- trainButton.cpp | 10 +- trainButton.h | 2 +- unitButton.cpp | 12 +- unitButton.h | 6 +- 18 files changed, 265 insertions(+), 70 deletions(-) create mode 100644 Assets/Scripts/Gui/acsTechTree.lua create mode 100644 Assets/Scripts/Gui/aincTechTree.lua rename Assets/Scripts/Gui/{techTree.lua => erTechTree.lua} (99%) delete mode 100644 Assets/Scripts/Gui/researchStructCommands.lua diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 0f1b8e1..7264e45 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -2676,7 +2676,7 @@ units = { unitClass = UnitClass.LAB, unitType = UnitType.LAND, maxUnevenness = .5, - abilityButtons = {{buttonType = ButtonType.RESEARCH, name = 'Tech tree', guiScreen = 'researchStructCommands.lua'}}, + abilityButtons = {{buttonType = ButtonType.ACTIVE_STATE, name = 'Tech tree', guiScreen = 'acsTechTree.lua'}}, isVehicle = false, health = 500, buildTime = 1000, @@ -2699,7 +2699,7 @@ units = { unitClass = UnitClass.LAB, unitType = UnitType.LAND, maxUnevenness = .5, - abilityButtons = {{buttonType = ButtonType.RESEARCH, name = 'Tech tree', guiScreen = 'researchStructCommands.lua'}}, + abilityButtons = {{buttonType = ButtonType.ACTIVE_STATE, name = 'Tech tree', guiScreen = 'aincTechTree.lua'}}, isVehicle = false, health = 500, buildTime = 1000, @@ -2722,7 +2722,7 @@ units = { unitClass = UnitClass.LAB, unitType = UnitType.LAND, maxUnevenness = .5, - abilityButtons = {{buttonType = ButtonType.RESEARCH, name = 'Tech tree', guiScreen = 'researchStructCommands.lua'}}, + abilityButtons = {{buttonType = ButtonType.ACTIVE_STATE, name = 'Tech tree', guiScreen = 'erTechTree.lua'}}, isVehicle = false, health = 500, buildTime = 1000, diff --git a/Assets/Scripts/Gui/acsTechTree.lua b/Assets/Scripts/Gui/acsTechTree.lua new file mode 100644 index 0000000..0b97011 --- /dev/null +++ b/Assets/Scripts/Gui/acsTechTree.lua @@ -0,0 +1,106 @@ +res = graphics.resolution +Size = {x = res.x * .5, y = res.y * .5} +techButtonSize = {x = 50, y = 50} +Pos = {x = res.x * .3, y = res.y * .1, z = .1} +margin = {top = 10, left = 10, right = 10, bottom = 10} +baseTechPath = 'Icons/Technologies/' +heightOffset = techButtonSize.y + 10 + +gui = { + { + guiType = GuiType.GUI_RECTANGLE, + pos = Pos, + size = Size, + color = {x = 0, y = 0, z = 0, w = .6} + }, + { + pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top, z = .11}, + size = techButtonSize, + name = "ACS APT", + imagePath = baseTechPath .. 'apt.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.APT, + trigger = 82, + }, + { + pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "FPT", + imagePath = baseTechPath .. 'fpt.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.FPT, + trigger = 82, + }, + { + pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Cruisers", + imagePath = baseTechPath .. 'cruisers.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.CRUISERS, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "EFT", + imagePath = baseTechPath .. 'ept.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.EFT, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x - 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Stealth", + imagePath = baseTechPath .. 'stealth.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.ST_SUB, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Robotics", + imagePath = baseTechPath .. 'robo.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.ROBO, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "PCT", + imagePath = baseTechPath .. 'pct.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.PCT, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Carriers", + imagePath = baseTechPath .. 'carriers.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.CARRIERS, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Tanks", + imagePath = baseTechPath .. 'tanks.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.TANKS, + trigger = 82, + }, +} diff --git a/Assets/Scripts/Gui/aincTechTree.lua b/Assets/Scripts/Gui/aincTechTree.lua new file mode 100644 index 0000000..7782408 --- /dev/null +++ b/Assets/Scripts/Gui/aincTechTree.lua @@ -0,0 +1,106 @@ +res = graphics.resolution +Size = {x = res.x * .5, y = res.y * .5} +techButtonSize = {x = 50, y = 50} +Pos = {x = res.x * .3, y = res.y * .1, z = .1} +margin = {top = 10, left = 10, right = 10, bottom = 10} +baseTechPath = 'Icons/Technologies/' +heightOffset = techButtonSize.y + 10 + +gui = { + { + guiType = GuiType.GUI_RECTANGLE, + pos = Pos, + size = Size, + color = {x = 0, y = 0, z = 0, w = .6} + }, + { + pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top, z = .11}, + size = techButtonSize, + name = "AInc APT", + imagePath = baseTechPath .. 'apt.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.APT, + trigger = 82, + }, + { + pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "FPT", + imagePath = baseTechPath .. 'fpt.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.FPT, + trigger = 82, + }, + { + pos = {x = Pos.x + margin.left, y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Cruisers", + imagePath = baseTechPath .. 'cruisers.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.CRUISERS, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "EFT", + imagePath = baseTechPath .. 'ept.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.EFT, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x - 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Stealth", + imagePath = baseTechPath .. 'stealth.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.ST_SUB, + trigger = 82, + }, + { + pos = {x = Pos.x + .5 * (Size.x + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Robotics", + imagePath = baseTechPath .. 'robo.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.ROBO, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + heightOffset, z = .11}, + size = techButtonSize, + name = "PCT", + imagePath = baseTechPath .. 'pct.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.PCT, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + 3 * techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Carriers", + imagePath = baseTechPath .. 'carriers.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.CARRIERS, + trigger = 82, + }, + { + pos = {x = Pos.x + Size.x - (margin.right + techButtonSize.x), y = Pos.y + margin.top + 2 * heightOffset, z = .11}, + size = techButtonSize, + name = "Tanks", + imagePath = baseTechPath .. 'tanks.jpg', + guiType = GuiType.BUTTON, + buttonType = ButtonType.RESEARCH, + techId = TechId.TANKS, + trigger = 82, + }, +} diff --git a/Assets/Scripts/Gui/techTree.lua b/Assets/Scripts/Gui/erTechTree.lua similarity index 99% rename from Assets/Scripts/Gui/techTree.lua rename to Assets/Scripts/Gui/erTechTree.lua index 953403c..795769f 100644 --- a/Assets/Scripts/Gui/techTree.lua +++ b/Assets/Scripts/Gui/erTechTree.lua @@ -16,7 +16,7 @@ gui = { { pos = {x = Pos.x + .5 * (Size.x - techButtonSize.x), y = Pos.y + margin.top, z = .11}, size = techButtonSize, - name = "APT", + name = "ER APT", imagePath = baseTechPath .. 'apt.jpg', guiType = GuiType.BUTTON, buttonType = ButtonType.RESEARCH, diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 828c015..2badc7b 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -31,14 +31,15 @@ ButtonType = { SELL_REFINEDS = 27, BUY_RESEARCH = 28, SELL_RESEARCH = 29, - ACTIVE_STATE_BACK = 30, - PLAYER_TRADE = 31, - TRADING_SCREEN = 32, - TRADE_OFFER = 33, - RESOURCE_AMMOUNT = 34, - UNIT_STATE = 35, - ORDER = 36, - MINIMAP = 37, + ACTIVE_STATE = 30, + ACTIVE_STATE_BACK = 31, + PLAYER_TRADE = 32, + TRADING_SCREEN = 33, + TRADE_OFFER = 34, + RESOURCE_AMMOUNT = 35, + UNIT_STATE = 36, + ORDER = 37, + MINIMAP = 38, } ListboxType = { diff --git a/Assets/Scripts/Gui/researchStructCommands.lua b/Assets/Scripts/Gui/researchStructCommands.lua deleted file mode 100644 index 8c17b96..0000000 --- a/Assets/Scripts/Gui/researchStructCommands.lua +++ /dev/null @@ -1,27 +0,0 @@ -res = graphics.resolution -Size = {x = 70, y = 70} -margin = 10 -sz = {x = Size.x - margin, y = Size.y - margin} - -gui = { - --[[ - { - pos = {x = res.x - Size.x, y = res.y - Size.y}, - size = sz, - name = "Research", - guiType = GuiType.BUTTON, - buttonType = ButtonType.RESEARCH, - techId = TechId.APT, - trigger = 82, - }, - ]]-- - { - guiType = GuiType.BUTTON, - buttonType = ButtonType.ACTIVE_GAME_STATE, - name = 'Tech', - guiScreen = 'techTree.lua', - pos = {x = res.x - 2 * Size.x, y = res.y - Size.y, z = 0}, - size = sz, - trigger = 85 - }, -} diff --git a/buildButton.cpp b/buildButton.cpp index af0b31e..6146b6f 100644 --- a/buildButton.cpp +++ b/buildButton.cpp @@ -16,12 +16,15 @@ namespace battleship{ using namespace vb01Gui; using namespace gameBase; - BuildButton::BuildButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) : - UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), slotId(slId){} + BuildButton::BuildButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int slId) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath), slotId(slId){} void BuildButton::onClick(){ ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); Player *player = activeState->getPlayer(); + + sol::state_view SOL_LUA_VIEW = generateView(); + int unitId = SOL_LUA_VIEW["_mainUnitId"]; Unit* builder = player->getUnitsById(unitId)[0]; if(builder->getBuildableUnit(slotId).buildable){ diff --git a/buildButton.h b/buildButton.h index a87af94..770a479 100644 --- a/buildButton.h +++ b/buildButton.h @@ -6,7 +6,7 @@ namespace battleship{ class BuildButton : public UnitButton{ public: - BuildButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int, int); + BuildButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int); void onClick(); private: int slotId; diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 865282c..76c6939 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -186,28 +186,31 @@ namespace battleship{ break; } case BUILD: - button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["engineerId"], (int)guiTable["slotId"]); + button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["slotId"]); break; case TRAIN: - button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["factoryId"], (int)guiTable["slotId"]); + button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["slotId"]); break; case STATISTICS: button = new StatsButton(pos, size, name, (int)guiTable["trigger"], imagePath); break; case RESEARCH: - button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["LAB"], (int)guiTable["techId"]); + button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["techId"]); break; case BUY_REFINEDS: - button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::BUY_REFINEDS); + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::BUY_REFINEDS); break; case SELL_REFINEDS: - button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_REFINEDS); + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::SELL_REFINEDS); break; case BUY_RESEARCH: - button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::BUY_RESEARCH); + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::BUY_RESEARCH); break; case SELL_RESEARCH: - button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_RESEARCH); + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::SELL_RESEARCH); + break; + case ACTIVE_STATE_BUTTON: + button = new ActiveStateButton(pos, size, guiTable["guiScreen"], name, fontBasePath + "batang.ttf", (int)guiTable["trigger"], imagePath); break; case ACTIVE_STATE_BACK: button = new ActiveStateBackButton(pos, size, name); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 47035fb..06ae6a2 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -45,6 +45,7 @@ namespace battleship{ SELL_REFINEDS, BUY_RESEARCH, SELL_RESEARCH, + ACTIVE_STATE_BUTTON, ACTIVE_STATE_BACK, PLAYER_TRADE, TRADING_SCREEN, diff --git a/researchButton.cpp b/researchButton.cpp index 2fcd966..21d1944 100644 --- a/researchButton.cpp +++ b/researchButton.cpp @@ -19,8 +19,8 @@ namespace battleship{ using namespace vb01; using namespace std; - ResearchButton::ResearchButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int tid) : - UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), techId(tid){ + ResearchButton::ResearchButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int tid) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath), techId(tid){ Root *root = Root::getSingleton(); Material *mat = new Material(root->getLibPath() + "gui"); mat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL); @@ -41,7 +41,7 @@ namespace battleship{ void ResearchButton::onClick(){ if(!active) return; - vector labs = getUnits(unitId); + vector labs = getUnits(); for(Unit *lab : labs) ((ResearchStruct*)lab)->appendToQueue(techId); @@ -72,7 +72,7 @@ namespace battleship{ active = true; overlay->setVisible(false); - vector labs = getUnits(unitId); + vector labs = getUnits(); for(Unit *lab : labs){ vector researchQueue = ((ResearchStruct*)lab)->getQueue(); diff --git a/researchButton.h b/researchButton.h index 639f8e9..f6e2d2b 100644 --- a/researchButton.h +++ b/researchButton.h @@ -6,7 +6,7 @@ namespace battleship{ class ResearchButton : public UnitButton{ public: - ResearchButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int, int); + ResearchButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int); ~ResearchButton(); void onClick(); void update(); diff --git a/tradeButton.cpp b/tradeButton.cpp index 4ea639f..51b98a5 100644 --- a/tradeButton.cpp +++ b/tradeButton.cpp @@ -9,7 +9,7 @@ namespace battleship{ using namespace vb01; using namespace gameBase; - TradeButton::TradeButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int uid, Type t) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), type(t){} + TradeButton::TradeButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, Type t) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath), type(t){} void TradeButton::onClick(){ ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); diff --git a/tradeButton.h b/tradeButton.h index a1fbe4e..604858b 100644 --- a/tradeButton.h +++ b/tradeButton.h @@ -8,7 +8,7 @@ namespace battleship{ public: enum class Type{BUY_REFINEDS, SELL_REFINEDS, BUY_RESEARCH, SELL_RESEARCH}; - TradeButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int, Type); + TradeButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, Type); void onClick(); private: Type type; diff --git a/trainButton.cpp b/trainButton.cpp index a7ede04..eedc5ce 100644 --- a/trainButton.cpp +++ b/trainButton.cpp @@ -11,14 +11,14 @@ namespace battleship{ using namespace vb01; using namespace gameBase; - TrainButton::TrainButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) : - UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), + TrainButton::TrainButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int slId) : + UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath), slotId(slId) {} void TrainButton::onClick(){ - vector labs = getUnits(unitId); + vector factories = getUnits(); - for(Unit *lab : labs) - ((Factory*)lab)->appendToQueue(slotId); + for(Unit *fac : factories) + ((Factory*)fac)->appendToQueue(slotId); } } diff --git a/trainButton.h b/trainButton.h index 3d71268..6b7ca6e 100644 --- a/trainButton.h +++ b/trainButton.h @@ -6,7 +6,7 @@ namespace battleship{ class TrainButton : public UnitButton{ public: - TrainButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int, int); + TrainButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int); void onClick(); private: int slotId; diff --git a/unitButton.cpp b/unitButton.cpp index 620398c..8b0c3f3 100644 --- a/unitButton.cpp +++ b/unitButton.cpp @@ -4,26 +4,30 @@ #include +#include + namespace battleship{ using namespace std; using namespace vb01; using namespace vb01Gui; using namespace gameBase; - UnitButton::UnitButton(Vector3 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath, int uid) : Button(pos, size, name, fontPath, trigger, true, imagePath), unitId(uid){ + UnitButton::UnitButton(Vector3 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, trigger, true, imagePath){ StateManager *stateManager = GameManager::getSingleton()->getStateManager(); ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE); - if(activeState) - activeState->addButton(this); + if(activeState) activeState->addButton(this); } //TODO optimize this code - vector UnitButton::getUnits(int unitId){ + vector UnitButton::getUnits(){ vector units; ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); Player *player = activeState->getPlayer(); + + sol::state_view SOL_LUA_VIEW = generateView(); + int unitId = SOL_LUA_VIEW["_mainUnitId"]; vector selUnits = player->getSelectedUnits(), researchStructs = player->getUnitsById(unitId); for(Unit *rs : researchStructs) diff --git a/unitButton.h b/unitButton.h index 89a1b69..86944ad 100644 --- a/unitButton.h +++ b/unitButton.h @@ -8,11 +8,9 @@ namespace battleship{ class UnitButton : public vb01Gui::Button{ public: - UnitButton(vb01::Vector3, vb01::Vector2, std::string, std::string, int, std::string, int); + UnitButton(vb01::Vector3, vb01::Vector2, std::string, std::string, int, std::string); protected: - int unitId; - - std::vector getUnits(int); + std::vector getUnits(); }; }