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
@@ -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,
+106
View File
@@ -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,
},
}
+106
View File
@@ -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,
},
}
@@ -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,
+9 -8
View File
@@ -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 = {
@@ -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
},
}
+5 -2
View File
@@ -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){
+1 -1
View File
@@ -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;
+10 -7
View File
@@ -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);
+1
View File
@@ -45,6 +45,7 @@ namespace battleship{
SELL_REFINEDS,
BUY_RESEARCH,
SELL_RESEARCH,
ACTIVE_STATE_BUTTON,
ACTIVE_STATE_BACK,
PLAYER_TRADE,
TRADING_SCREEN,
+4 -4
View File
@@ -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<Unit*> labs = getUnits(unitId);
vector<Unit*> labs = getUnits();
for(Unit *lab : labs)
((ResearchStruct*)lab)->appendToQueue(techId);
@@ -72,7 +72,7 @@ namespace battleship{
active = true;
overlay->setVisible(false);
vector<Unit*> labs = getUnits(unitId);
vector<Unit*> labs = getUnits();
for(Unit *lab : labs){
vector<int> researchQueue = ((ResearchStruct*)lab)->getQueue();
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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;
+5 -5
View File
@@ -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<Unit*> labs = getUnits(unitId);
vector<Unit*> factories = getUnits();
for(Unit *lab : labs)
((Factory*)lab)->appendToQueue(slotId);
for(Unit *fac : factories)
((Factory*)fac)->appendToQueue(slotId);
}
}
+1 -1
View File
@@ -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;
+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)
+2 -4
View File
@@ -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<Unit*> getUnits(int);
std::vector<Unit*> getUnits();
};
}