Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53727a216c |
+6
-52
@@ -1,17 +1,13 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{fighter::{attack::FighterDamage, manifest::{FighterManifest}}, match_loading::MatchPlayer, player::Player};
|
||||||
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 {
|
||||||
@@ -20,7 +16,6 @@ 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}
|
||||||
}
|
}
|
||||||
@@ -30,10 +25,6 @@ impl FighterInfoUI {
|
|||||||
justify_content: JustifyContent::Center,
|
justify_content: JustifyContent::Center,
|
||||||
}
|
}
|
||||||
Children [
|
Children [
|
||||||
(
|
|
||||||
#StockIconContainer
|
|
||||||
Node
|
|
||||||
)
|
|
||||||
(
|
(
|
||||||
#PercentageText
|
#PercentageText
|
||||||
Text("0.00%")
|
Text("0.00%")
|
||||||
@@ -50,54 +41,17 @@ impl FighterInfoUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_fighter_info_damage(
|
pub fn update_fighter_info_damage(fighters: Query<(&Player, &FighterDamage)>, ui_elements: Query<&mut FighterInfoUI>, mut commands: Commands) {
|
||||||
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
|
let Some((_, damage)) = fighters.iter().find(|(player, _)| {
|
||||||
.iter()
|
player.handle == ui_element.player_handle
|
||||||
.find(|(player, _)| player.handle == ui_element.player_handle)
|
}) else {
|
||||||
else {
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if *damage != ui_element.visible_damage {
|
if *damage != ui_element.visible_damage {
|
||||||
commands
|
commands.entity(ui_element.percentage_text).insert(Text(format!("{}%", damage)));
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-21
@@ -1,15 +1,10 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::AppState;
|
||||||
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;
|
||||||
@@ -18,20 +13,6 @@ 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
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
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