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