Compare commits
1
Commits
7819b95bc6
...
stocks_ui
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
886f1e7040 |
+52
-6
@@ -1,13 +1,17 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{fighter::{attack::FighterDamage, manifest::{FighterManifest}}, match_loading::MatchPlayer, player::Player};
|
use crate::{
|
||||||
|
fighter::{attack::FighterDamage, manifest::FighterManifest}, match_loading::{MatchPlayer}, match_runtime::MatchState, player::Player, ui::stock_icon::BattleUIStockIcon,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Component, FromTemplate)]
|
#[derive(Component, FromTemplate)]
|
||||||
pub struct FighterInfoUI {
|
pub struct FighterInfoUI {
|
||||||
percentage_text: Entity,
|
percentage_text: Entity,
|
||||||
|
stock_icon_container: Entity,
|
||||||
_name_text: Entity,
|
_name_text: Entity,
|
||||||
player_handle: usize,
|
player_handle: usize,
|
||||||
visible_damage: FighterDamage,
|
visible_damage: FighterDamage,
|
||||||
|
visible_stocks: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FighterInfoUI {
|
impl FighterInfoUI {
|
||||||
@@ -16,6 +20,7 @@ impl FighterInfoUI {
|
|||||||
bsn! {
|
bsn! {
|
||||||
FighterInfoUI {
|
FighterInfoUI {
|
||||||
percentage_text: #PercentageText,
|
percentage_text: #PercentageText,
|
||||||
|
stock_icon_container: #StockIconContainer,
|
||||||
_name_text: #NameText,
|
_name_text: #NameText,
|
||||||
player_handle: {match_player.handle}
|
player_handle: {match_player.handle}
|
||||||
}
|
}
|
||||||
@@ -25,6 +30,10 @@ impl FighterInfoUI {
|
|||||||
justify_content: JustifyContent::Center,
|
justify_content: JustifyContent::Center,
|
||||||
}
|
}
|
||||||
Children [
|
Children [
|
||||||
|
(
|
||||||
|
#StockIconContainer
|
||||||
|
Node
|
||||||
|
)
|
||||||
(
|
(
|
||||||
#PercentageText
|
#PercentageText
|
||||||
Text("0.00%")
|
Text("0.00%")
|
||||||
@@ -41,17 +50,54 @@ impl FighterInfoUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_fighter_info_damage(fighters: Query<(&Player, &FighterDamage)>, ui_elements: Query<&mut FighterInfoUI>, mut commands: Commands) {
|
pub fn update_fighter_info_damage(
|
||||||
|
fighters: Query<(&Player, &FighterDamage)>,
|
||||||
|
ui_elements: Query<&mut FighterInfoUI>,
|
||||||
|
mut commands: Commands,
|
||||||
|
) {
|
||||||
for mut ui_element in ui_elements {
|
for mut ui_element in ui_elements {
|
||||||
let Some((_, damage)) = fighters.iter().find(|(player, _)| {
|
let Some((_, damage)) = fighters
|
||||||
player.handle == ui_element.player_handle
|
.iter()
|
||||||
}) else {
|
.find(|(player, _)| player.handle == ui_element.player_handle)
|
||||||
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if *damage != ui_element.visible_damage {
|
if *damage != ui_element.visible_damage {
|
||||||
commands.entity(ui_element.percentage_text).insert(Text(format!("{}%", damage)));
|
commands
|
||||||
|
.entity(ui_element.percentage_text)
|
||||||
|
.insert(Text(format!("{}%", damage)));
|
||||||
ui_element.visible_damage = damage.clone();
|
ui_element.visible_damage = damage.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_fighter_info_stocks(
|
||||||
|
match_state: Res<MatchState>,
|
||||||
|
ui_elements: Query<&mut FighterInfoUI>,
|
||||||
|
mut commands: Commands,
|
||||||
|
) {
|
||||||
|
|
||||||
|
for mut ui_element in ui_elements {
|
||||||
|
let handle = ui_element.player_handle;
|
||||||
|
let Some(match_player) = match_state.players.get(handle) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(stocks) = match_player.stocks_remaining else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
if stocks != ui_element.visible_stocks {
|
||||||
|
commands
|
||||||
|
.entity(ui_element.stock_icon_container)
|
||||||
|
.despawn_children()
|
||||||
|
.with_children(|spawner| {
|
||||||
|
for _ in 0..stocks {
|
||||||
|
spawner.spawn_empty().apply_scene(BattleUIStockIcon::scene());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui_element.visible_stocks = stocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+21
-2
@@ -1,10 +1,15 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::{
|
||||||
|
AppState,
|
||||||
|
match_loading::{MatchConfig, MatchRules},
|
||||||
|
match_runtime::MatchState,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod battle_ui;
|
pub mod battle_ui;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod fighter_info;
|
pub mod fighter_info;
|
||||||
|
pub mod stock_icon;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct InGameUIPlugin;
|
pub struct InGameUIPlugin;
|
||||||
@@ -13,6 +18,20 @@ impl Plugin for InGameUIPlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(OnEnter(AppState::InMatch), battle_ui::spawn_battle_ui)
|
app.add_systems(OnEnter(AppState::InMatch), battle_ui::spawn_battle_ui)
|
||||||
.add_systems(OnExit(AppState::InMatch), battle_ui::cleanup_battle_ui)
|
.add_systems(OnExit(AppState::InMatch), battle_ui::cleanup_battle_ui)
|
||||||
.add_systems(PostUpdate, fighter_info::update_fighter_info_damage);
|
.add_systems(PostUpdate, fighter_info::update_fighter_info_damage)
|
||||||
|
.add_systems(
|
||||||
|
PostUpdate,
|
||||||
|
fighter_info::update_fighter_info_stocks.run_if(
|
||||||
|
resource_exists::<MatchState>
|
||||||
|
.and_then(resource_exists::<MatchConfig>)
|
||||||
|
.and_then(|match_config: Res<MatchConfig>| {
|
||||||
|
if let MatchRules::Stock { .. } = match_config.rules {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(SceneComponent, Clone, FromTemplate)]
|
||||||
|
pub struct BattleUIStockIcon;
|
||||||
|
|
||||||
|
impl BattleUIStockIcon {
|
||||||
|
pub fn scene() -> impl Scene {
|
||||||
|
bsn! {
|
||||||
|
Node {
|
||||||
|
width: px(32),
|
||||||
|
height: px(32),
|
||||||
|
border_radius: BorderRadius::MAX,
|
||||||
|
}
|
||||||
|
BackgroundColor({bevy::color::palettes::css::RED})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user