bugfix for crashes when clicking on trade centers or labs

This commit is contained in:
devZoGok
2026-01-02 17:22:56 +02:00
parent b2cf1bb1e0
commit 86b5bf9731
18 changed files with 265 additions and 70 deletions
+8 -4
View File
@@ -4,26 +4,30 @@
#include <stateManager.h>
#include <solUtil.h>
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<Unit*> UnitButton::getUnits(int unitId){
vector<Unit*> UnitButton::getUnits(){
vector<Unit*> 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<Unit*> selUnits = player->getSelectedUnits(), researchStructs = player->getUnitsById(unitId);
for(Unit *rs : researchStructs)