Skip to content

Commit

Permalink
feat: display blue square on squad leader
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed Aug 20, 2023
1 parent 4437ca8 commit c6b0fc4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 6 additions & 0 deletions battle_core/src/game/squad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub struct SquadMemberStatus {
ammunition_reserve: AmmunitionReserveStatus,
under_fire_coefficient: f32,
current: CurrentAction,
leader: bool,
}

// FIXME : this func is here because AmmunitionReserveStatus, Soldier, etc will have to move
Expand Down Expand Up @@ -196,6 +197,7 @@ impl SquadMemberStatus {
ammunition_reserve: ammunition_reserve_status(soldier),
under_fire_coefficient: (*soldier.under_fire().value() as f32 / UNDER_FIRE_MAX as f32),
current: CurrentAction::from_soldier(battle_state, squad, soldier),
leader: battle_state.squad(soldier.squad_uuid()).leader() == soldier.uuid(),
}
}

Expand All @@ -222,6 +224,10 @@ impl SquadMemberStatus {
pub fn ammunition_reserve(&self) -> &AmmunitionReserveStatus {
&self.ammunition_reserve
}

pub fn leader(&self) -> bool {
self.leader
}
}

#[derive(Clone, Debug)]
Expand Down
8 changes: 7 additions & 1 deletion battle_gui/src/engine/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ impl Engine {
DEFAULT_SELECTED_SQUARE_SIDE,
DEFAULT_SELECTED_SQUARE_SIDE,
);
let color = SoldierHealthBuilder::new(&soldier).build().color();

let color =
if self.battle_state.squad(soldier.squad_uuid()).leader() == soldier.uuid() {
Color::BLUE
} else {
SoldierHealthBuilder::new(&soldier).build().color()
};
mesh_builder.rectangle(DrawMode::Stroke(StrokeOptions::default()), rect, color)?;
}
}
Expand Down
19 changes: 16 additions & 3 deletions battle_gui/src/ui/hud/detail.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use battle_core::{game::squad::SquadStatusResume, types::WindowPoint};
use ggez::{
graphics::{
Canvas, Color, DrawMode, DrawParam, FillOptions, Mesh, MeshBuilder, Rect, Text,
TextFragment, TextLayout,
Canvas, Color, DrawMode, DrawParam, FillOptions, Mesh, MeshBuilder, Rect, StrokeOptions,
Text, TextFragment, TextLayout,
},
Context, GameResult,
};
Expand Down Expand Up @@ -144,7 +144,20 @@ impl Component<HudEvent> for SquadDetail {
)
.set_layout(TextLayout::center()),
DrawParam::default().dest(text_center_dest.to_vec2()),
)
);

if soldier_status.leader() {
mesh_builder.rectangle(
DrawMode::Stroke(StrokeOptions::default()),
Rect::new(
soldiers_status_start_point.x - SOLDIER_WIDTH + 1.,
soldiers_status_start_point.y + 1.,
SOLDIER_WIDTH - 1.,
SOLDIER_WIDTH - 1.,
),
Color::BLUE,
)?;
}
}

canvas.draw(
Expand Down
17 changes: 15 additions & 2 deletions battle_gui/src/ui/hud/squad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Component<HudEvent> for SquadStatuses {
SQUAD_TYPE_WIDTH + SQUAD_CARD_MARGIN,
SQUAD_CARD_HEADER_HEIGHT + SQUAD_CARD_MARGIN,
));
for (i, solider_status) in draw_card.squad_status.members().iter().enumerate() {
for (i, soldier_status) in draw_card.squad_status.members().iter().enumerate() {
let soldiers_health_dest = soldiers_healths_start_point.apply(Vec2::new(
(SQUAD_CARD_SOLDIER_HEALTH_WIDTH + SQUAD_CARD_MARGIN) * i as f32,
0.,
Expand All @@ -179,9 +179,22 @@ impl Component<HudEvent> for SquadStatuses {
r: 1.,
g: 0.,
b: 0.,
a: solider_status.under_fire_coefficient(),
a: soldier_status.under_fire_coefficient(),
},
)?;

if soldier_status.leader() {
mesh_builder.rectangle(
DrawMode::Stroke(StrokeOptions::default()),
Rect::new(
soldiers_health_dest.x + 1.,
soldiers_health_dest.y + 1.,
SQUAD_CARD_SOLDIER_HEALTH_WIDTH - 1.,
SQUAD_CARD_SOLDIER_HEALTH_HEIGHT - 1.,
),
Color::BLUE,
)?;
}
}

// Outline when hover or selected
Expand Down

0 comments on commit c6b0fc4

Please sign in to comment.