mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
visuals for the unit state toggle button
This commit is contained in:
@@ -15,6 +15,7 @@ function generateButton(numGui, buttonData)
|
|||||||
size = buttonSize,
|
size = buttonSize,
|
||||||
guiType = GuiType.BUTTON,
|
guiType = GuiType.BUTTON,
|
||||||
name = buttonData.name,
|
name = buttonData.name,
|
||||||
|
imagePath = buttonData.imagePath,
|
||||||
buttonType = buttonData.buttonType,
|
buttonType = buttonData.buttonType,
|
||||||
trigger = (buttonData.trigger or -1),
|
trigger = (buttonData.trigger or -1),
|
||||||
orderType = buttonData.orderType,
|
orderType = buttonData.orderType,
|
||||||
@@ -30,10 +31,10 @@ end
|
|||||||
function generateGui(unitId)
|
function generateGui(unitId)
|
||||||
local gui = {}
|
local gui = {}
|
||||||
vehicleButtonData = {
|
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.GARRISON, name = 'Garrison'},
|
||||||
{buttonType = ButtonType.ORDER, orderType = OrderType.PATROL, name = 'Patrol'},
|
{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 = {
|
structureButtonData = {
|
||||||
{buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'},
|
{buttonType = ButtonType.UNIT_STATE, name = 'Change unit state'},
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 843 B |
Binary file not shown.
|
After Width: | Height: | Size: 549 B |
Binary file not shown.
|
After Width: | Height: | Size: 979 B |
@@ -0,0 +1,98 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="210mm"
|
||||||
|
height="297mm"
|
||||||
|
viewBox="0 0 210 297"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
|
||||||
|
sodipodi:docname="state.svg"
|
||||||
|
xml:space="preserve"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:zoom="0.75900674"
|
||||||
|
inkscape:cx="229.90573"
|
||||||
|
inkscape:cy="538.20339"
|
||||||
|
inkscape:window-width="1918"
|
||||||
|
inkscape:window-height="1058"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="20"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="layer1" /><defs
|
||||||
|
id="defs1"><pattern
|
||||||
|
inkscape:collect="always"
|
||||||
|
xlink:href="#invert grid"
|
||||||
|
preserveAspectRatio="xMidYMid"
|
||||||
|
id="pattern15"
|
||||||
|
patternTransform="scale(0.5)"
|
||||||
|
x="0"
|
||||||
|
y="0" /><pattern
|
||||||
|
patternUnits="userSpaceOnUse"
|
||||||
|
width="12"
|
||||||
|
height="12"
|
||||||
|
preserveAspectRatio="xMidYMid"
|
||||||
|
id="invert grid"
|
||||||
|
x="0"
|
||||||
|
y="0"
|
||||||
|
style="fill:#11a529"
|
||||||
|
inkscape:label="Inverted grid"
|
||||||
|
inkscape:collect="always"
|
||||||
|
inkscape:isstock="true"><rect
|
||||||
|
style="stroke:none;paint-order:markers fill stroke"
|
||||||
|
id="rect2-0"
|
||||||
|
width="10"
|
||||||
|
height="10"
|
||||||
|
x="0"
|
||||||
|
y="0" /></pattern><linearGradient
|
||||||
|
id="swatch7"
|
||||||
|
inkscape:swatch="solid"><stop
|
||||||
|
style="stop-color:#3f3f3f;stop-opacity:1;"
|
||||||
|
offset="0"
|
||||||
|
id="stop8" /></linearGradient><inkscape:perspective
|
||||||
|
sodipodi:type="inkscape:persp3d"
|
||||||
|
inkscape:vp_x="-2.2804804 : 132.16513 : 1"
|
||||||
|
inkscape:vp_y="0 : 1000 : 0"
|
||||||
|
inkscape:vp_z="210 : 135.28811 : 1"
|
||||||
|
inkscape:persp3d-origin="102.71952 : 82.665123 : 1"
|
||||||
|
id="perspective1" /></defs><g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"><path
|
||||||
|
id="rect4"
|
||||||
|
style="fill:#3f3f3f;fill-rule:evenodd;stroke:#121212;stroke-width:3;stroke-linecap:square;stroke-linejoin:round;paint-order:stroke fill markers;fill-opacity:1;stroke-opacity:1;stroke-dasharray:none"
|
||||||
|
d="M 51.291495,136.05279 H 152.77511 l 32.78747,68.1354 H 18.504013 Z"
|
||||||
|
sodipodi:nodetypes="ccccc"
|
||||||
|
inkscape:export-filename="noHack.png"
|
||||||
|
inkscape:export-xdpi="5.6718144"
|
||||||
|
inkscape:export-ydpi="5.6718144" /><path
|
||||||
|
id="rect4-7"
|
||||||
|
style="fill:url(#pattern15);fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:square;stroke-linejoin:round;paint-order:stroke fill markers;fill-opacity:1;stroke-dasharray:none"
|
||||||
|
d="M 152.77511,136.05279 H 51.291488 L 40.93474,67.91739 h 122.19713 z"
|
||||||
|
sodipodi:nodetypes="ccccc"
|
||||||
|
inkscape:export-filename="hack.png"
|
||||||
|
inkscape:export-xdpi="7.4680233"
|
||||||
|
inkscape:export-ydpi="7.4680233" /><path
|
||||||
|
id="path2"
|
||||||
|
style="display:inline;fill:#f21104;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.1;stroke-linecap:square;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||||
|
d="M 102.03357,27.226245 A 111.90711,111.90711 0 0 0 -9.8738159,139.13311 111.90711,111.90711 0 0 0 102.03357,251.04049 111.90711,111.90711 0 0 0 213.94043,139.13311 111.90711,111.90711 0 0 0 102.03357,27.226245 Z m 0,13.79554 A 98.111313,98.111313 0 0 1 200.14489,139.13311 98.111313,98.111313 0 0 1 102.03357,237.24443 98.111313,98.111313 0 0 1 3.9222412,139.13311 98.111313,98.111313 0 0 1 102.03357,41.021785 Z" /><rect
|
||||||
|
style="display:inline;fill:#f21104;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.113265;stroke-linecap:square;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||||
|
id="rect3"
|
||||||
|
width="222.7867"
|
||||||
|
height="17.734119"
|
||||||
|
x="-147.01964"
|
||||||
|
y="159.95135"
|
||||||
|
transform="rotate(-48.17088)" /></g></svg>
|
||||||
|
After Width: | Height: | Size: 4.2 KiB |
+35
-4
@@ -12,10 +12,12 @@ namespace battleship{
|
|||||||
using namespace vb01Gui;
|
using namespace vb01Gui;
|
||||||
using namespace gameBase;
|
using namespace gameBase;
|
||||||
|
|
||||||
StateToggleButton::StateToggleButton(Vector3 pos, Vector2 size, string name, int trigger, string 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) {
|
||||||
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;
|
const int NUM_STATES = 3;
|
||||||
int numUnitsByState[NUM_STATES]{0, 0, 0};
|
int numUnitsByState[NUM_STATES]{0, 0, 0};
|
||||||
|
|
||||||
@@ -33,8 +35,37 @@ namespace battleship{
|
|||||||
maxNum = numUnitsByState[maxId];
|
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);
|
for(Unit *unit : units) unit->setState(nextState);
|
||||||
|
|
||||||
|
updateStateId();
|
||||||
|
toggleImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ namespace battleship{
|
|||||||
StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string);
|
StateToggleButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string);
|
||||||
void onClick();
|
void onClick();
|
||||||
private:
|
private:
|
||||||
|
void updateStateId();
|
||||||
|
void toggleImage();
|
||||||
|
|
||||||
|
int currStateId, x;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user