Skip to content

Commit

Permalink
wip: enable layer system only for current layer
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jul 23, 2024
1 parent 9fc8f4c commit d8064e8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sandpolis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reqwest = { version = "0.12.5", default-features = false, features = ["stream",
serde_bytes = "0.11.15"
serde = { version = "1.0.203", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
tokio = { version = "1.34.0", features = ["full"] }
tokio = { version = "1.34.0", default-features = false, features = ["rt", "macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
uuid = { version = "1.10.0", features = ["v7", "serde"] }
Expand Down
15 changes: 10 additions & 5 deletions sandpolis/src/client/ui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,20 @@ pub fn handle_camera(
}

/// Show a help window with keyboard shortcuts.
pub fn handle_keymap(mut contexts: EguiContexts, keyboard_input: Res<ButtonInput<KeyCode>>) {
pub fn handle_keymap(
mut contexts: EguiContexts,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut windows: Query<&mut Window>,
) {
if keyboard_input.pressed(KeyCode::KeyK) {
let window_size = windows.single_mut().size();
egui::Window::new("Keyboard shortcuts")
.id(egui::Id::new("keymap"))
.pivot(egui::Align2::CENTER_CENTER)
.resizable(false)
.movable(false)
.collapsible(false)
.fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y / 2.0))
.show(contexts.ctx_mut(), |ui| {
ui.label("W - Pan camera upwards");
ui.label("A - Pan camera upwards");
Expand Down Expand Up @@ -159,13 +166,11 @@ pub fn handle_layer_change(
let window_size = windows.single_mut().size();
egui::Window::new("Current layer")
.id(egui::Id::new("current_layer"))
.pivot(egui::Align2::CENTER_CENTER)
.resizable(false)
.movable(false)
.collapsible(false)
.fixed_pos(egui::Pos2::new(
window_size.x / 2.0,
window_size.y + window_size.y / 3.0,
))
.fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y - 30.0))
.show(contexts.ctx_mut(), |ui| {
ui.label(format!("{:?}", **current_layer));
});
Expand Down
9 changes: 9 additions & 0 deletions sandpolis/src/client/ui/layer/desktop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use bevy::prelude::*;

use crate::{client::ui::CurrentLayer, core::Layer};

pub fn check_layer_active(current_layer: Res<CurrentLayer>) -> bool {
return **current_layer == Layer::Desktop;
}

pub fn handle_layer(mut commands: Commands) {}
2 changes: 2 additions & 0 deletions sandpolis/src/client/ui/layer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(feature = "layer-desktop")]
pub mod desktop;
7 changes: 7 additions & 0 deletions sandpolis/src/client/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::core::{database::Database, Layer};
use self::{input::MousePressed, node::spawn_node};

pub mod input;
pub mod layer;
pub mod node;

#[derive(Resource)]
Expand Down Expand Up @@ -73,6 +74,12 @@ pub fn run(state: AppState) {
),
);

#[cfg(feature = "layer-desktop")]
app.add_systems(
Update,
self::layer::desktop::handle_layer.run_if(self::layer::desktop::check_layer_active),
);

// MSAA makes some Android devices panic, this is under investigation
// https://github.com/bevyengine/bevy/issues/8229
#[cfg(target_os = "android")]
Expand Down
15 changes: 8 additions & 7 deletions sandpolis/src/client/ui/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Node {
pub collier: Collider,
pub rigid_body: RigidBody,
// /// User indication of whether an entity is visible
// pub visibility: Visibility,
pub visibility: Visibility,
pub sprite: SpriteBundle,
// // Inherited visibility of an entity.
// pub inherited_visibility: InheritedVisibility,
Expand All @@ -38,19 +38,20 @@ pub fn spawn_node(
rigid_body: RigidBody::Dynamic,
// visibility: todo!(),
restitution: Restitution::coefficient(0.7),
visibility: Visibility::Visible,
sprite: SpriteBundle {
texture: asset_server.load(get_os_image(os_type)),
..default()
},
};

// TODO store a handle somehow
egui::Window::new("Hello")
.resizable(false)
.movable(false)
.show(contexts.ctx_mut(), |ui| {
ui.label("world");
});
// egui::Window::new("Hello")
// .resizable(false)
// .movable(false)
// .show(contexts.ctx_mut(), |ui| {
// ui.label("world");
// });

commands.spawn(node);
}
Expand Down
2 changes: 1 addition & 1 deletion sandpolis/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl InstanceId {
}
}

#[derive(Serialize, Deserialize, Clone, Copy, EnumIter, Debug)]
#[derive(Serialize, Deserialize, Clone, Copy, EnumIter, Debug, PartialEq, Eq)]
pub enum Layer {
/// Interact with Desktop environments.
#[cfg(feature = "layer-desktop")]
Expand Down

0 comments on commit d8064e8

Please sign in to comment.