diff --git a/Assets/Scripts/Gui/unitGui.lua b/Assets/Scripts/Gui/unitGui.lua
index 2fb8d74..5a1f44f 100644
--- a/Assets/Scripts/Gui/unitGui.lua
+++ b/Assets/Scripts/Gui/unitGui.lua
@@ -15,6 +15,7 @@ function generateButton(numGui, buttonData)
size = buttonSize,
guiType = GuiType.BUTTON,
name = buttonData.name,
+ imagePath = buttonData.imagePath,
buttonType = buttonData.buttonType,
trigger = (buttonData.trigger or -1),
orderType = buttonData.orderType,
@@ -30,10 +31,10 @@ end
function generateGui(unitId)
local gui = {}
vehicleButtonData = {
- {buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'},
+ {buttonType = ButtonType.UNIT_STATE, imagePath = 'Icons/Buttons/chase.png'},
{buttonType = ButtonType.ORDER, orderType = OrderType.GARRISON, name = 'Garrison'},
{buttonType = ButtonType.ORDER, orderType = OrderType.PATROL, name = 'Patrol'},
- {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'}
+ {buttonType = ButtonType.ORDER, orderType = OrderType.HALT, name = 'Halt'},
}
structureButtonData = {
{buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'},
diff --git a/Assets/Textures/Icons/Buttons/chase.png b/Assets/Textures/Icons/Buttons/chase.png
new file mode 100644
index 0000000..75ec3fc
Binary files /dev/null and b/Assets/Textures/Icons/Buttons/chase.png differ
diff --git a/Assets/Textures/Icons/Buttons/holdFire.png b/Assets/Textures/Icons/Buttons/holdFire.png
new file mode 100644
index 0000000..f5c34f4
Binary files /dev/null and b/Assets/Textures/Icons/Buttons/holdFire.png differ
diff --git a/Assets/Textures/Icons/Buttons/standGround.png b/Assets/Textures/Icons/Buttons/standGround.png
new file mode 100644
index 0000000..4a56b92
Binary files /dev/null and b/Assets/Textures/Icons/Buttons/standGround.png differ
diff --git a/Assets/Textures/Icons/Buttons/state.svg b/Assets/Textures/Icons/Buttons/state.svg
new file mode 100644
index 0000000..9eba101
--- /dev/null
+++ b/Assets/Textures/Icons/Buttons/state.svg
@@ -0,0 +1,98 @@
+
+
+
+
diff --git a/stateToggleButton.cpp b/stateToggleButton.cpp
index 116a8a4..52b09af 100644
--- a/stateToggleButton.cpp
+++ b/stateToggleButton.cpp
@@ -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 units = player->getSelectedUnits();
for(Unit *unit : units) unit->setState(nextState);
+
+ updateStateId();
+ toggleImage();
}
}
diff --git a/stateToggleButton.h b/stateToggleButton.h
index 1303468..774e087 100644
--- a/stateToggleButton.h
+++ b/stateToggleButton.h
@@ -9,6 +9,10 @@ namespace battleship{
StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string);
void onClick();
private:
+ void updateStateId();
+ void toggleImage();
+
+ int currStateId, x;
};
}