mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-09-03 12:33:28 +00:00
visuals for the unit state toggle button
This commit is contained in:
+35
-4
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user