visuals for the unit state toggle button

This commit is contained in:
devZoGok
2025-04-06 16:50:25 +03:00
parent 73c7c3b96f
commit ae87aedb55
7 changed files with 140 additions and 6 deletions
+35 -4
View File
@@ -12,10 +12,12 @@ namespace battleship{
using namespace vb01Gui;
using namespace gameBase;
StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) :
Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) {}
StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath) {
updateStateId();
toggleImage();
}
void StateToggleButton::onClick(){
void StateToggleButton::updateStateId(){
const int NUM_STATES = 3;
int numUnitsByState[NUM_STATES]{0, 0, 0};
@@ -33,8 +35,37 @@ namespace battleship{
maxNum = numUnitsByState[maxId];
}
Unit::State nextState = (maxId + 1 == NUM_STATES ? Unit::State(0) : Unit::State(maxId + 1));
currStateId = maxId;
}
void StateToggleButton::toggleImage(){
string imgPath = "";
switch(Unit::State(currStateId)){
case Unit::State::HOLD_FIRE:
imgPath = "holdFire.png";
break;
case Unit::State::CHASE:
imgPath = "chase.png";
break;
case Unit::State::STAND_GROUND:
imgPath = "standGround.png";
break;
}
setImage(GameManager::getSingleton()->getPath() + "Textures/Icons/Buttons/" + imgPath);
}
void StateToggleButton::onClick(){
const int NUM_STATES = 3;
Unit::State nextState = (currStateId + 1 == NUM_STATES ? Unit::State(0) : Unit::State(currStateId + 1));
Player *player = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE))->getPlayer();
vector<Unit*> units = player->getSelectedUnits();
for(Unit *unit : units) unit->setState(nextState);
updateStateId();
toggleImage();
}
}