generated from 2ndbeam/bevy-template
ui: Beginning of UI-related stuff
- UiRoot component - WindowSize resource and update_window_size system - UiInventory and UiInventorySlot components - UiInventory now shows player inventory slots
This commit is contained in:
parent
5f59e02788
commit
ab993be476
6 changed files with 183 additions and 10 deletions
18
src/lib.rs
18
src/lib.rs
|
|
@ -2,6 +2,7 @@ pub mod player;
|
|||
pub mod layout;
|
||||
pub mod input;
|
||||
pub mod inventory;
|
||||
pub mod ui;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
|
@ -19,6 +20,13 @@ pub enum InputAction {
|
|||
Interact,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
Running,
|
||||
Inventory,
|
||||
}
|
||||
|
||||
impl InputAction {
|
||||
pub fn default_input_map() -> InputMap<Self> {
|
||||
let input_map = InputMap::default()
|
||||
|
|
@ -51,12 +59,20 @@ fn camera_bundle() -> impl Bundle {
|
|||
|
||||
fn setup_global(mut commands: Commands) {
|
||||
commands.spawn(camera_bundle());
|
||||
commands.spawn(ui::UiRoot::new());
|
||||
}
|
||||
|
||||
impl Plugin for ExpeditionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(input::InputAssetPlugin::<InputAction>::default())
|
||||
.init_state::<GameState>()
|
||||
.insert_resource(ui::WindowSize::default())
|
||||
.add_systems(Startup, (player::setup_player, setup_global))
|
||||
.add_systems(Update, player::handle_input);
|
||||
.add_systems(Update, (
|
||||
player::handle_input,
|
||||
ui::update_window_size,
|
||||
))
|
||||
.add_systems(OnEnter(GameState::Inventory), inventory::ui::setup_ui_inventory)
|
||||
.add_systems(OnExit(GameState::Inventory), inventory::ui::clear_ui_inventory);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue