move heads_ui in client only module
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
use crate::{
|
||||
GameState,
|
||||
aim::AimTarget,
|
||||
backpack::UiHeadState,
|
||||
heads::{ActiveHeads, HeadsImages},
|
||||
hitpoints::Hitpoints,
|
||||
loading_assets::UIAssets,
|
||||
npc::Npc,
|
||||
player::LocalPlayer,
|
||||
GameState, aim::AimTarget, backpack::UiHeadState, client::ui::HeadsImages, heads::ActiveHeads,
|
||||
hitpoints::Hitpoints, loading_assets::UIAssets, npc::Npc, player::LocalPlayer,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
pub mod backpack_ui;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(backpack_ui::plugin);
|
||||
}
|
||||
@@ -24,7 +24,6 @@ use bevy_trenchbroom::geometry::Brushes;
|
||||
|
||||
pub mod aim;
|
||||
pub mod audio;
|
||||
pub mod backpack;
|
||||
pub mod control;
|
||||
pub mod debug;
|
||||
pub mod enemy;
|
||||
@@ -39,7 +38,6 @@ pub fn plugin(app: &mut App) {
|
||||
app.add_plugins((
|
||||
aim::plugin,
|
||||
audio::plugin,
|
||||
backpack::plugin,
|
||||
control::plugin,
|
||||
debug::plugin,
|
||||
enemy::plugin,
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
BACKPACK_HEAD_SLOTS, BackpackCountText, BackpackMarker, BackpackUiState, HeadDamage,
|
||||
HeadImage, HeadSelector,
|
||||
},
|
||||
heads::HeadsImages,
|
||||
client::ui::heads_ui::HeadsImages,
|
||||
loading_assets::UIAssets,
|
||||
};
|
||||
use bevy::{ecs::spawn::SpawnIter, prelude::*};
|
||||
@@ -1,11 +1,20 @@
|
||||
use super::{ActiveHeads, HEAD_SLOTS};
|
||||
#[cfg(feature = "client")]
|
||||
use crate::heads::HeadsImages;
|
||||
use crate::{GameState, backpack::UiHeadState, loading_assets::UIAssets, player::LocalPlayer};
|
||||
use crate::{
|
||||
GameState,
|
||||
backpack::UiHeadState,
|
||||
heads::{ActiveHeads, HEAD_COUNT, HEAD_SLOTS},
|
||||
heads_database::HeadsDatabase,
|
||||
loading_assets::UIAssets,
|
||||
player::LocalPlayer,
|
||||
};
|
||||
use bevy::{ecs::spawn::SpawnIter, prelude::*};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HeadsImages {
|
||||
pub heads: Vec<Handle<Image>>,
|
||||
}
|
||||
|
||||
#[derive(Component, Reflect, Default)]
|
||||
#[reflect(Component)]
|
||||
struct HeadSelector(pub usize);
|
||||
@@ -31,15 +40,28 @@ pub fn plugin(app: &mut App) {
|
||||
|
||||
app.init_resource::<UiActiveHeads>();
|
||||
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(OnEnter(GameState::Playing), (setup, setup_heads_images));
|
||||
app.add_systems(FixedUpdate, sync.run_if(in_state(GameState::Playing)));
|
||||
#[cfg(feature = "client")]
|
||||
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
(update, update_ammo, update_health).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
}
|
||||
|
||||
fn setup_heads_images(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
heads: Res<HeadsDatabase>,
|
||||
) {
|
||||
// TODO: load via asset loader
|
||||
let heads = (0usize..HEAD_COUNT)
|
||||
.map(|i| asset_server.load(format!("ui/heads/{}.png", heads.head_key(i))))
|
||||
.collect();
|
||||
|
||||
commands.insert_resource(HeadsImages { heads });
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
|
||||
commands.spawn((
|
||||
Name::new("heads-ui"),
|
||||
@@ -245,7 +267,7 @@ fn sync(
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if active_heads.is_changed() || active_heads.reloading() {
|
||||
state.selected_slot = active_heads.selected_slot;
|
||||
state.selected_slot = active_heads.slot();
|
||||
|
||||
for i in 0..HEAD_SLOTS {
|
||||
state.heads[i] = active_heads
|
||||
@@ -1,7 +1,13 @@
|
||||
mod backpack_ui;
|
||||
mod heads_ui;
|
||||
mod pause;
|
||||
|
||||
pub use heads_ui::HeadsImages;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(heads_ui::plugin);
|
||||
app.add_plugins(backpack_ui::plugin);
|
||||
app.add_plugins(pause::plugin);
|
||||
}
|
||||
|
||||
@@ -13,16 +13,9 @@ use bevy::prelude::*;
|
||||
use bevy_replicon::prelude::FromClient;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod heads_ui;
|
||||
|
||||
pub static HEAD_COUNT: usize = 18;
|
||||
pub static HEAD_SLOTS: usize = 5;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HeadsImages {
|
||||
pub heads: Vec<Handle<Image>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Serialize, Deserialize)]
|
||||
pub struct HeadState {
|
||||
pub head: usize,
|
||||
@@ -74,6 +67,10 @@ impl ActiveHeads {
|
||||
self.heads[self.current_slot]
|
||||
}
|
||||
|
||||
pub fn slot(&self) -> usize {
|
||||
self.current_slot
|
||||
}
|
||||
|
||||
pub fn use_ammo(&mut self, time: f32) {
|
||||
let Some(head) = &mut self.heads[self.current_slot] else {
|
||||
error!("cannot use ammo of empty head");
|
||||
@@ -184,11 +181,8 @@ pub struct HeadChanged {
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(heads_ui::plugin);
|
||||
|
||||
app.register_type::<ActiveHeads>();
|
||||
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
@@ -201,15 +195,6 @@ pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, on_swap_backpack);
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, heads: Res<HeadsDatabase>) {
|
||||
// TODO: load via asset loader
|
||||
let heads = (0usize..HEAD_COUNT)
|
||||
.map(|i| asset_server.load(format!("ui/heads/{}.png", heads.head_key(i))))
|
||||
.collect();
|
||||
|
||||
commands.insert_resource(HeadsImages { heads });
|
||||
}
|
||||
|
||||
fn sync_hp(mut query: Query<(&mut ActiveHeads, &Hitpoints)>) {
|
||||
for (mut active_heads, hp) in query.iter_mut() {
|
||||
if active_heads.hp().get() != hp.get() {
|
||||
|
||||
Reference in New Issue
Block a user