From ae87aedb5555e46dd9619a87f37667ffcc71d743 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 6 Apr 2025 16:50:25 +0300 Subject: [PATCH] visuals for the unit state toggle button --- Assets/Scripts/Gui/unitGui.lua | 5 +- Assets/Textures/Icons/Buttons/chase.png | Bin 0 -> 843 bytes Assets/Textures/Icons/Buttons/holdFire.png | Bin 0 -> 549 bytes Assets/Textures/Icons/Buttons/standGround.png | Bin 0 -> 979 bytes Assets/Textures/Icons/Buttons/state.svg | 98 ++++++++++++++++++ stateToggleButton.cpp | 39 ++++++- stateToggleButton.h | 4 + 7 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 Assets/Textures/Icons/Buttons/chase.png create mode 100644 Assets/Textures/Icons/Buttons/holdFire.png create mode 100644 Assets/Textures/Icons/Buttons/standGround.png create mode 100644 Assets/Textures/Icons/Buttons/state.svg 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 0000000000000000000000000000000000000000..75ec3fcc541471aa4a7cb8e92337da5b72cbe1e6 GIT binary patch literal 843 zcmV-R1GM~!P)P000^Y1^@s6LVfqm00009a7bBm000-g z000-g0j5gPPXGV_8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10@z7J zK~zYI#g=bR>PQrapBY;IXhBe#Ac{gZ8)AuBKY@OnyI*$W3yk~1EGQ^Jr2^@S7228m z!q~N2Q14!o{k`isbLN>dbLMo!@$vCDR!D0t27|#bqtWQMr>Cc1!!Rs{VVD;}gi^}C zP179Y^ZD~yt@ejySyQD{>gwvMC8gBWYV}XkGy?!}a&n@V0mkDo-EJ4p^H!}Pk`Myh zwh4lOhld9MY}>|h8~}_ZtEbcHaD9FK;pA^)?(Xhlw$W&W)*2y19HO=6{QR8JX!L2o zd*C1lFikTKxxBnw3NQ?Va=FaL#s=wh8l@Dz?=zW97>~y&rB;IA&2~+vQ+mB#V&LxX zF72&%(K~_mBrJ{O%)v|K^ zDae=3_P;`;lt>w8{ril58Un=X8(=n@eLZA-eLZHpzrX)_h;7?3g<**6 zy0N=wz{?F!r_;>m^T=^=aX}`Np;Rh;8Zev9Xt&$=zK@iW!^1<0#o|jQsZ@$aqY(>G zO3`k&>2x|D7J}BA;c&?5>1mXKQi{P~@J}WHl}ZKIbz?s*tu_6ApPQQ-N~IEoLV;W^ zhhZ3mVMq`Jc%Fyrx;#HWC*av^HVy$eI5^@3kRl~TB_o9Nc>DU-=W?LT%wUiWct zZ|~ESEmJ<9=jiAN(=>r4uN5H#jYflVxlFIu`=LigHk+kZtFgVkjSwQT8(Qn%mjzgs zh2uC(CX@2*?QP5Ryykp9uPCJ~rIaP5^o0;J(==~$xmP000>X1^@s6#OZ}&00009a7bBm000%v z000%v0lW1APhs|IBoy{%Ch8eII!Jr>u`WptJOGg zPeO=?ncwG`0K?&s^Z87grnPMh!@x969LGUQ2|%ycBg-<9BtdIk+eiq3<2VckgC^wZ z>51ud%4)SjDOH)1$pqWB8=H*BV*uhfX1QEeo|F>L^P1Z~-2D^uAM!4lubE0IPN&md zKhN`zLw38}n}$5nKXNDiejm%S?)rJ269mD>AX3W48-J@fj^70NI(PDQAg0zD-}gz= z6s>j5Tr3u}+ie`jVKf>cgrF!2eBZD7;6d7w4Ef0xL&V~z;mUR-EQ{+;JPkZmbH^45ik9C2qCa- nyOdH^U(eP{gFjn;<>~qf^hnjdO7Xk(00000NkvXXu0mjfp|tm) literal 0 HcmV?d00001 diff --git a/Assets/Textures/Icons/Buttons/standGround.png b/Assets/Textures/Icons/Buttons/standGround.png new file mode 100644 index 0000000000000000000000000000000000000000..4a56b92669c1138da5f3e79250d22f9f55127494 GIT binary patch literal 979 zcmV;^11$WBP)P000^Y1^@s6LVfqm00009a7bBm000-g z000-g0j5gPPXGV_8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H117Jx+ zK~zYIotE8hs#p}q|C<3n08y!cjgBeyBW7lL(KP90dwVi3GOsc3F^|)$CQVKgGi_=b zPkL&k7%Iv}ilySYXe0uD^ql_{i@n$Wt;Jq@ZOHlg`9D~rAPCsU$Hx=LasKpue=iI} zDGWoNVHl5P*_UiK`(2jhuZ>3I|J&Q!zlX!&7mnlltyb&5QmJGu)*%-c7xPsB(=^fT zcJcQ1wl0Q9f*`>2Jj~}GOVw&M92^`(e4)u?60?2ZkJ(Jpq1)~L z6kwGW87&mc#C2WtdcBlWCX<1tX%GYf9LFID0#HgZ7z_{u!B%JtVi-m$ih8{cUDv@d z@uW3PL$ldLr_+IHnj0Z8Psed$gOVg+e}6v(h@2S)tyT+?Bz+!|tfXzu3n_{cvpJ4i z56NUQu|Z1dry!L|1uXmV{m&>gTA_frz0rh%4RmNc$ z!m=z_)<>rxgg_KU6bc0ti$%z?9DS~>5CCX4n+SqnV_DAUb5Ke_DMi2E2g5K>6a~7j zBb&{p=Kr?0xA*Vz3qlAgl?r&Chv#{pI&Aa#9FxfehG8I|&u`w7WvQwPRaG$_k73(3 zMxzm2*Trl$TML`bX1Ke%1Iw}~m&@BB3l)n+6pO{k_B;=iQaFwS+qUug`kKnB)9K*s z>?|sd6eJA8wI>_^c%BE(^UyR60ASlT9v&Xxd0sTf_kGy54Ox}}EFDJIb#Zldh0DuJ zwA*cjVYn?x06@81#_{oSs-%}&R0Mf?dW!CW;c$q-VDKpj@Nq_xRkd6&5hQuh^!xo( zM_wn-^Dv!GWABzbLqU@coBtINLU4F^7|Q}!+LLOv z8qs;4N2Af$*xr+pBnc-cC)nNHO~aRe?kvlyQc6`#(;j%9_ktkcdcEEsqtWQE>2&)0 z`}=z(3`3p}5-<$oaU5sn^Z9RzqI|7ZtKZiJ@B@mGY5)ARM5q7&002ovPDHLkV1n2f By*2;< literal 0 HcmV?d00001 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; }; }