fix cash ui
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{GameState, global_observer, protocol::PlaySound, server_observer};
|
||||||
GameState, HEDZ_GREEN, global_observer, loading_assets::UIAssets, protocol::PlaySound,
|
|
||||||
server_observer,
|
|
||||||
};
|
|
||||||
use avian3d::prelude::Rotation;
|
use avian3d::prelude::Rotation;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -24,11 +21,7 @@ pub struct CashInventory {
|
|||||||
pub struct CashCollectEvent;
|
pub struct CashCollectEvent;
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
app.add_systems(Update, rotate.run_if(in_state(GameState::Playing)));
|
||||||
app.add_systems(
|
|
||||||
Update,
|
|
||||||
(rotate, update_ui).run_if(in_state(GameState::Playing)),
|
|
||||||
);
|
|
||||||
|
|
||||||
server_observer!(app, on_cash_collect);
|
server_observer!(app, on_cash_collect);
|
||||||
}
|
}
|
||||||
@@ -55,37 +48,3 @@ fn rotate(time: Res<Time>, mut query: Query<&mut Rotation, With<Cash>>) {
|
|||||||
.mul_quat(Quat::from_rotation_y(time.delta_secs()));
|
.mul_quat(Quat::from_rotation_y(time.delta_secs()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_ui(
|
|
||||||
cash: Single<&CashInventory, Changed<CashInventory>>,
|
|
||||||
text: Query<Entity, With<CashText>>,
|
|
||||||
mut writer: TextUiWriter,
|
|
||||||
) {
|
|
||||||
let Some(text) = text.iter().next() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
*writer.text(text, 0) = cash.cash.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
|
|
||||||
commands.spawn((
|
|
||||||
Name::new("cash-ui"),
|
|
||||||
Text::new("0"),
|
|
||||||
TextShadow::default(),
|
|
||||||
CashText,
|
|
||||||
TextFont {
|
|
||||||
font: assets.font.clone(),
|
|
||||||
font_size: 34.0,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
TextColor(HEDZ_GREEN.into()),
|
|
||||||
TextLayout::new_with_justify(Justify::Center),
|
|
||||||
Node {
|
|
||||||
position_type: PositionType::Absolute,
|
|
||||||
bottom: Val::Px(40.0),
|
|
||||||
left: Val::Px(100.0),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|||||||
47
crates/hedz_reloaded/src/client/ui/cash_ui.rs
Normal file
47
crates/hedz_reloaded/src/client/ui/cash_ui.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use crate::{
|
||||||
|
GameState, HEDZ_GREEN, cash::CashInventory, loading_assets::UIAssets, player::LocalPlayer,
|
||||||
|
};
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component, Reflect, Default)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
struct CashText;
|
||||||
|
|
||||||
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||||
|
app.add_systems(Update, update_ui.run_if(in_state(GameState::Playing)));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_ui(
|
||||||
|
cash: Single<&CashInventory, (Changed<CashInventory>, With<LocalPlayer>)>,
|
||||||
|
text: Query<Entity, With<CashText>>,
|
||||||
|
mut writer: TextUiWriter,
|
||||||
|
) {
|
||||||
|
let Some(text) = text.iter().next() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
*writer.text(text, 0) = cash.cash.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
|
||||||
|
commands.spawn((
|
||||||
|
Name::new("cash-ui"),
|
||||||
|
Text::new("0"),
|
||||||
|
TextShadow::default(),
|
||||||
|
CashText,
|
||||||
|
TextFont {
|
||||||
|
font: assets.font.clone(),
|
||||||
|
font_size: 34.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
TextColor(HEDZ_GREEN.into()),
|
||||||
|
TextLayout::new_with_justify(Justify::Center),
|
||||||
|
Node {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
bottom: Val::Px(40.0),
|
||||||
|
left: Val::Px(100.0),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
mod backpack_ui;
|
mod backpack_ui;
|
||||||
|
mod cash_ui;
|
||||||
mod heads_ui;
|
mod heads_ui;
|
||||||
mod pause;
|
mod pause;
|
||||||
|
|
||||||
@@ -11,4 +12,5 @@ pub fn plugin(app: &mut App) {
|
|||||||
app.add_plugins(heads_ui::plugin);
|
app.add_plugins(heads_ui::plugin);
|
||||||
app.add_plugins(backpack_ui::plugin);
|
app.add_plugins(backpack_ui::plugin);
|
||||||
app.add_plugins(pause::plugin);
|
app.add_plugins(pause::plugin);
|
||||||
|
app.add_plugins(cash_ui::plugin);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user