From 7998933c2dd49a51ac2211c9a1126fc9c2fa999a Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:13:08 -0700 Subject: [PATCH 01/17] Add boilerplate for controls_overlay spawn setup --- game/src/ui.rs | 19 +++++++++++ game/src/ui/controls_overlay.rs | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 game/src/ui/controls_overlay.rs diff --git a/game/src/ui.rs b/game/src/ui.rs index 860fac3..c2a0e28 100644 --- a/game/src/ui.rs +++ b/game/src/ui.rs @@ -1,3 +1,4 @@ +use bevy::ecs::system::EntityCommands; use sickle_ui::ui_builder::UiBuilder; use sickle_ui::widgets::prelude::UiContainerExt; @@ -9,6 +10,7 @@ use crate::ui::skill_toolbar::SkillToolbarPlugin; pub mod ability_widget; mod console; +mod controls_overlay; mod kill_counter; mod mainmenu; mod skill_toolbar; @@ -19,6 +21,7 @@ impl Plugin for UiPlugin { fn build(&self, app: &mut App) { app.add_plugins(iyes_ui::UiExtrasPlugin); app.add_plugins(( + controls_overlay::plugin, self::console::UiConsolePlugin, self::mainmenu::MainMenuPlugin, SkillToolbarPlugin, @@ -115,3 +118,19 @@ pub fn button<'w, 's, 'a>( }, ) } + +trait Spawn { + fn ui_spawn(&mut self, bundle: B) -> EntityCommands; +} + +impl Spawn for Commands<'_, '_> { + fn ui_spawn(&mut self, bundle: B) -> EntityCommands { + Commands::spawn(self, bundle) + } +} + +impl Spawn for ChildBuilder<'_> { + fn ui_spawn(&mut self, bundle: B) -> EntityCommands { + ChildBuilder::spawn(self, bundle) + } +} diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs new file mode 100644 index 0000000..b291b6f --- /dev/null +++ b/game/src/ui/controls_overlay.rs @@ -0,0 +1,57 @@ +use bevy::ecs::system::EntityCommands; +use bevy::prelude::*; + +use super::{AppState, Spawn, StateDespawnMarker}; + +pub(super) fn plugin(app: &mut App) { + app.add_systems(OnEnter(AppState::InGame), setup); +} + +fn setup(mut commands: Commands) { + commands.root().with_children(|root| { + root.container(); + }); +} + +trait ControlsOverlay { + fn root(&mut self) -> EntityCommands; + fn container(&mut self) -> EntityCommands; +} + +impl ControlsOverlay for T { + fn root(&mut self) -> EntityCommands { + self.ui_spawn(( + Name::new("controls_overlay_root"), + StateDespawnMarker, + NodeBundle { + style: Style { + display: Display::Flex, + position_type: PositionType::Absolute, + width: Val::Px(100.0), + height: Val::Px(100.0), + ..default() + }, + background_color: BackgroundColor(Color::rgba( + 0.0, 0.0, 0.0, 0.5, + )), + ..default() + }, + )) + } + + fn container(&mut self) -> EntityCommands { + self.ui_spawn(( + Name::new("controls_overlay_container"), + NodeBundle { + style: Style { + display: Display::Flex, + width: Val::Px(200.0), + height: Val::Px(100.0), + ..default() + }, + background_color: BackgroundColor(Color::rgb(1.0, 1.0, 1.0)), + ..default() + }, + )) + } +} From 84f9978c3c098a31283f73ddddb128265ac165d9 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:15:15 -0700 Subject: [PATCH 02/17] Center controls overlay --- game/src/ui/controls_overlay.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index b291b6f..4cc3f37 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -27,8 +27,10 @@ impl ControlsOverlay for T { style: Style { display: Display::Flex, position_type: PositionType::Absolute, - width: Val::Px(100.0), - height: Val::Px(100.0), + width: Val::Percent(100.0), + height: Val::Percent(100.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, ..default() }, background_color: BackgroundColor(Color::rgba( @@ -49,7 +51,7 @@ impl ControlsOverlay for T { height: Val::Px(100.0), ..default() }, - background_color: BackgroundColor(Color::rgb(1.0, 1.0, 1.0)), + background_color: BackgroundColor(Color::rgb(0.3, 0.32, 0.28)), ..default() }, )) From 3eed97e1520726db30c58f21f2901c565694fff0 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:22:19 -0700 Subject: [PATCH 03/17] Add text node --- game/src/ui.rs | 6 +++--- game/src/ui/controls_overlay.rs | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/game/src/ui.rs b/game/src/ui.rs index c2a0e28..15536d2 100644 --- a/game/src/ui.rs +++ b/game/src/ui.rs @@ -120,17 +120,17 @@ pub fn button<'w, 's, 'a>( } trait Spawn { - fn ui_spawn(&mut self, bundle: B) -> EntityCommands; + fn spawn(&mut self, bundle: B) -> EntityCommands; } impl Spawn for Commands<'_, '_> { - fn ui_spawn(&mut self, bundle: B) -> EntityCommands { + fn spawn(&mut self, bundle: B) -> EntityCommands { Commands::spawn(self, bundle) } } impl Spawn for ChildBuilder<'_> { - fn ui_spawn(&mut self, bundle: B) -> EntityCommands { + fn spawn(&mut self, bundle: B) -> EntityCommands { ChildBuilder::spawn(self, bundle) } } diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 4cc3f37..961f31c 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -9,18 +9,21 @@ pub(super) fn plugin(app: &mut App) { fn setup(mut commands: Commands) { commands.root().with_children(|root| { - root.container(); + root.container().with_children(|container| { + container.text("Test"); + }); }); } trait ControlsOverlay { fn root(&mut self) -> EntityCommands; fn container(&mut self) -> EntityCommands; + fn text(&mut self, string: impl Into) -> EntityCommands; } impl ControlsOverlay for T { fn root(&mut self) -> EntityCommands { - self.ui_spawn(( + self.spawn(( Name::new("controls_overlay_root"), StateDespawnMarker, NodeBundle { @@ -42,7 +45,7 @@ impl ControlsOverlay for T { } fn container(&mut self) -> EntityCommands { - self.ui_spawn(( + self.spawn(( Name::new("controls_overlay_container"), NodeBundle { style: Style { @@ -56,4 +59,18 @@ impl ControlsOverlay for T { }, )) } + + fn text(&mut self, value: impl Into) -> EntityCommands { + self.spawn(( + Name::new("controls_overlay_text"), + TextBundle::from_section( + value, + TextStyle { + font_size: 12.0, + color: Color::rgb(1.0, 1.0, 1.0), + ..default() + }, + ), + )) + } } From 303141d600b5177a5e15099a87c4f6cc7de4adc6 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:32:43 -0700 Subject: [PATCH 04/17] Add text icon --- game/src/ui/controls_overlay.rs | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 961f31c..850d0e4 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -10,7 +10,8 @@ pub(super) fn plugin(app: &mut App) { fn setup(mut commands: Commands) { commands.root().with_children(|root| { root.container().with_children(|container| { - container.text("Test"); + container.text("Move Left: "); + container.control_icon("A"); }); }); } @@ -19,6 +20,7 @@ trait ControlsOverlay { fn root(&mut self) -> EntityCommands; fn container(&mut self) -> EntityCommands; fn text(&mut self, string: impl Into) -> EntityCommands; + fn control_icon(&mut self, string: impl Into) -> EntityCommands; } impl ControlsOverlay for T { @@ -73,4 +75,36 @@ impl ControlsOverlay for T { ), )) } + + fn control_icon(&mut self, value: impl Into) -> EntityCommands { + let mut entity = self.spawn(( + Name::new("controls_overlay_icon"), + NodeBundle { + style: Style { + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + padding: UiRect::all(Val::Px(4.0)), + ..default() + }, + background_color: BackgroundColor(Color::rgb(0.2, 0.2, 0.2)), + ..default() + }, + )); + + entity.with_children(|node| { + node.spawn(( + Name::new("controls_overlay_icon_text"), + TextBundle::from_section( + value, + TextStyle { + font_size: 12.0, + color: Color::rgb(1.0, 1.0, 1.0), + ..default() + }, + ), + )); + }); + + entity + } } From 2b11afb7a3783e482c81d279f2e5afb72cd58198 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:41:42 -0700 Subject: [PATCH 05/17] Adjust icon styles --- game/src/ui/controls_overlay.rs | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 850d0e4..d4646fa 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -10,8 +10,10 @@ pub(super) fn plugin(app: &mut App) { fn setup(mut commands: Commands) { commands.root().with_children(|root| { root.container().with_children(|container| { - container.text("Move Left: "); - container.control_icon("A"); + container.row().with_children(|row| { + row.text("Move Left: "); + row.control_icon("A"); + }); }); }); } @@ -19,6 +21,7 @@ fn setup(mut commands: Commands) { trait ControlsOverlay { fn root(&mut self) -> EntityCommands; fn container(&mut self) -> EntityCommands; + fn row(&mut self) -> EntityCommands; fn text(&mut self, string: impl Into) -> EntityCommands; fn control_icon(&mut self, string: impl Into) -> EntityCommands; } @@ -51,9 +54,7 @@ impl ControlsOverlay for T { Name::new("controls_overlay_container"), NodeBundle { style: Style { - display: Display::Flex, - width: Val::Px(200.0), - height: Val::Px(100.0), + padding: UiRect::all(Val::Px(12.0)), ..default() }, background_color: BackgroundColor(Color::rgb(0.3, 0.32, 0.28)), @@ -62,13 +63,30 @@ impl ControlsOverlay for T { )) } + fn row(&mut self) -> EntityCommands { + self.spawn(( + Name::new("controls_overlay_row"), + NodeBundle { + style: Style { + display: Display::Flex, + width: Val::Percent(100.0), + height: Val::Auto, + align_items: AlignItems::Center, + justify_content: JustifyContent::Start, + ..default() + }, + ..default() + }, + )) + } + fn text(&mut self, value: impl Into) -> EntityCommands { self.spawn(( Name::new("controls_overlay_text"), TextBundle::from_section( value, TextStyle { - font_size: 12.0, + font_size: 16.0, color: Color::rgb(1.0, 1.0, 1.0), ..default() }, @@ -84,6 +102,8 @@ impl ControlsOverlay for T { align_items: AlignItems::Center, justify_content: JustifyContent::Center, padding: UiRect::all(Val::Px(4.0)), + min_width: Val::Px(24.0), + height: Val::Px(24.0), ..default() }, background_color: BackgroundColor(Color::rgb(0.2, 0.2, 0.2)), @@ -97,7 +117,7 @@ impl ControlsOverlay for T { TextBundle::from_section( value, TextStyle { - font_size: 12.0, + font_size: 18.0, color: Color::rgb(1.0, 1.0, 1.0), ..default() }, From 7706dbec1327447eed33d20e9fefda6a140e9b60 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:47:47 -0700 Subject: [PATCH 06/17] Adjust row styles --- game/src/ui/controls_overlay.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index d4646fa..9a18f74 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -13,6 +13,22 @@ fn setup(mut commands: Commands) { container.row().with_children(|row| { row.text("Move Left: "); row.control_icon("A"); + row.text(" or "); + row.control_icon("[<]"); + }); + container.row().with_children(|row| { + row.text("Move Right: "); + row.control_icon("D"); + row.text(" or "); + row.control_icon("[>]"); + }); + container.row().with_children(|row| { + row.text("Jump: "); + row.control_icon("W"); + row.text(" or "); + row.control_icon("SPACE"); + row.text(" or "); + row.control_icon("[^]"); }); }); }); @@ -54,6 +70,8 @@ impl ControlsOverlay for T { Name::new("controls_overlay_container"), NodeBundle { style: Style { + display: Display::Flex, + flex_direction: FlexDirection::Column, padding: UiRect::all(Val::Px(12.0)), ..default() }, @@ -73,6 +91,7 @@ impl ControlsOverlay for T { height: Val::Auto, align_items: AlignItems::Center, justify_content: JustifyContent::Start, + padding: UiRect::vertical(Val::Px(4.0)), ..default() }, ..default() @@ -86,7 +105,7 @@ impl ControlsOverlay for T { TextBundle::from_section( value, TextStyle { - font_size: 16.0, + font_size: 14.0, color: Color::rgb(1.0, 1.0, 1.0), ..default() }, @@ -103,7 +122,6 @@ impl ControlsOverlay for T { justify_content: JustifyContent::Center, padding: UiRect::all(Val::Px(4.0)), min_width: Val::Px(24.0), - height: Val::Px(24.0), ..default() }, background_color: BackgroundColor(Color::rgb(0.2, 0.2, 0.2)), @@ -117,7 +135,7 @@ impl ControlsOverlay for T { TextBundle::from_section( value, TextStyle { - font_size: 18.0, + font_size: 16.0, color: Color::rgb(1.0, 1.0, 1.0), ..default() }, From 902f452fc48c08429bc6dd0fc8c67455e7092fa5 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:51:19 -0700 Subject: [PATCH 07/17] Add all text for controls --- game/src/ui/controls_overlay.rs | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 9a18f74..b659827 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -30,6 +30,44 @@ fn setup(mut commands: Commands) { row.text(" or "); row.control_icon("[^]"); }); + container.row().with_children(|row| { + row.text("Attack: "); + row.control_icon("J"); + row.text(" or "); + row.control_icon("1"); + }); + container.row().with_children(|row| { + row.text("Dash: "); + row.control_icon("K"); + row.text(" or "); + row.control_icon("2"); + }); + container.row().with_children(|row| { + row.text("Whirl: "); + row.control_icon("L"); + row.text(" or "); + row.control_icon("3"); + }); + container.row().with_children(|row| { + row.text("Stealth: "); + row.control_icon(";"); + row.text(" or "); + row.control_icon("4"); + }); + container.row().with_children(|row| { + row.text("Swap Weapon: "); + row.control_icon("H"); + row.text(" or "); + row.control_icon("`"); + }); + container.row().with_children(|row| { + row.text("Interact: "); + row.control_icon("F"); + }); + container.row().with_children(|row| { + row.text("Show/Hide Controls: "); + row.control_icon("C"); + }); }); }); } @@ -91,7 +129,7 @@ impl ControlsOverlay for T { height: Val::Auto, align_items: AlignItems::Center, justify_content: JustifyContent::Start, - padding: UiRect::vertical(Val::Px(4.0)), + padding: UiRect::vertical(Val::Px(2.0)), ..default() }, ..default() @@ -121,7 +159,7 @@ impl ControlsOverlay for T { align_items: AlignItems::Center, justify_content: JustifyContent::Center, padding: UiRect::all(Val::Px(4.0)), - min_width: Val::Px(24.0), + min_width: Val::Px(20.0), ..default() }, background_color: BackgroundColor(Color::rgb(0.2, 0.2, 0.2)), @@ -135,7 +173,7 @@ impl ControlsOverlay for T { TextBundle::from_section( value, TextStyle { - font_size: 16.0, + font_size: 14.0, color: Color::rgb(1.0, 1.0, 1.0), ..default() }, From d6df2629c8852e5d1a3525672fbfb084233c8713 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 10:56:08 -0700 Subject: [PATCH 08/17] Add spacers --- game/src/ui/controls_overlay.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index b659827..a5aeb1c 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -30,6 +30,7 @@ fn setup(mut commands: Commands) { row.text(" or "); row.control_icon("[^]"); }); + container.spacer(); container.row().with_children(|row| { row.text("Attack: "); row.control_icon("J"); @@ -60,10 +61,12 @@ fn setup(mut commands: Commands) { row.text(" or "); row.control_icon("`"); }); + container.spacer(); container.row().with_children(|row| { row.text("Interact: "); row.control_icon("F"); }); + container.spacer(); container.row().with_children(|row| { row.text("Show/Hide Controls: "); row.control_icon("C"); @@ -78,6 +81,7 @@ trait ControlsOverlay { fn row(&mut self) -> EntityCommands; fn text(&mut self, string: impl Into) -> EntityCommands; fn control_icon(&mut self, string: impl Into) -> EntityCommands; + fn spacer(&mut self) -> EntityCommands; } impl ControlsOverlay for T { @@ -183,4 +187,20 @@ impl ControlsOverlay for T { entity } + + fn spacer(&mut self) -> EntityCommands { + self.spawn(( + Name::new("controls_overlay_spacer"), + NodeBundle { + style: Style { + height: Val::Px(1.0), + width: Val::Percent(100.0), + margin: UiRect::all(Val::Px(2.0)), + ..default() + }, + background_color: BackgroundColor(Color::rgb(0.2, 0.1, 0.15)), + ..default() + }, + )) + } } From 1a57c69e7a1961cb936eee1e81e38df05df1f12d Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 11:17:20 -0700 Subject: [PATCH 09/17] Add consts for colors --- game/src/ui/controls_overlay.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index a5aeb1c..b53827f 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -3,6 +3,12 @@ use bevy::prelude::*; use super::{AppState, Spawn, StateDespawnMarker}; +const OVERLAY_COLOR: Color = Color::rgba(0.08, 0.10, 0.06, 0.65); +const BACKGROUND_COLOR: Color = Color::rgb(0.22, 0.27, 0.18); +const ICON_BACKGROUND_COLOR: Color = Color::rgb(0.32, 0.37, 0.28); +const TEXT_COLOR: Color = Color::rgb(0.98, 0.99, 0.94); +const SPACER_COLOR: Color = Color::rgb(0.20, 0.25, 0.15); + pub(super) fn plugin(app: &mut App) { app.add_systems(OnEnter(AppState::InGame), setup); } @@ -99,9 +105,7 @@ impl ControlsOverlay for T { align_items: AlignItems::Center, ..default() }, - background_color: BackgroundColor(Color::rgba( - 0.0, 0.0, 0.0, 0.5, - )), + background_color: BackgroundColor(OVERLAY_COLOR), ..default() }, )) @@ -117,7 +121,7 @@ impl ControlsOverlay for T { padding: UiRect::all(Val::Px(12.0)), ..default() }, - background_color: BackgroundColor(Color::rgb(0.3, 0.32, 0.28)), + background_color: BackgroundColor(BACKGROUND_COLOR), ..default() }, )) @@ -148,7 +152,7 @@ impl ControlsOverlay for T { value, TextStyle { font_size: 14.0, - color: Color::rgb(1.0, 1.0, 1.0), + color: TEXT_COLOR, ..default() }, ), @@ -166,7 +170,7 @@ impl ControlsOverlay for T { min_width: Val::Px(20.0), ..default() }, - background_color: BackgroundColor(Color::rgb(0.2, 0.2, 0.2)), + background_color: BackgroundColor(ICON_BACKGROUND_COLOR), ..default() }, )); @@ -178,7 +182,7 @@ impl ControlsOverlay for T { value, TextStyle { font_size: 14.0, - color: Color::rgb(1.0, 1.0, 1.0), + color: TEXT_COLOR, ..default() }, ), @@ -193,12 +197,12 @@ impl ControlsOverlay for T { Name::new("controls_overlay_spacer"), NodeBundle { style: Style { - height: Val::Px(1.0), + height: Val::Px(2.0), width: Val::Percent(100.0), - margin: UiRect::all(Val::Px(2.0)), + margin: UiRect::vertical(Val::Px(7.0)), ..default() }, - background_color: BackgroundColor(Color::rgb(0.2, 0.1, 0.15)), + background_color: BackgroundColor(SPACER_COLOR), ..default() }, )) From baf0182bd2f97ab937b9f5b79d9adcaab24feaa9 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 11:23:32 -0700 Subject: [PATCH 10/17] Adjust padding --- game/src/ui/controls_overlay.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index b53827f..86eae7e 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -118,7 +118,7 @@ impl ControlsOverlay for T { style: Style { display: Display::Flex, flex_direction: FlexDirection::Column, - padding: UiRect::all(Val::Px(12.0)), + padding: UiRect::axes(Val::Px(24.0), Val::Px(12.0)), ..default() }, background_color: BackgroundColor(BACKGROUND_COLOR), From d334f7d4c3c56885b50140fda05e0cff8bf07d74 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 13:30:41 -0700 Subject: [PATCH 11/17] Make player actions match the control overlay --- game/src/game/player/mod.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/game/src/game/player/mod.rs b/game/src/game/player/mod.rs index 19feea6..d9a8fcd 100644 --- a/game/src/game/player/mod.rs +++ b/game/src/game/player/mod.rs @@ -121,6 +121,9 @@ pub enum PlayerAction { Dash, Whirl, Stealth, + SwapWeapon, + Interact, + ToggleControlOverlay, } #[derive(Component, Debug, Deref, DerefMut)] @@ -322,11 +325,27 @@ fn setup_player( KeyCode::ArrowRight, ), ) - .with(PlayerAction::Attack, KeyCode::Enter) + .with(PlayerAction::Attack, KeyCode::Digit1) .with(PlayerAction::Attack, KeyCode::KeyJ) .with(PlayerAction::Dash, KeyCode::KeyK) + .with(PlayerAction::Dash, KeyCode::Digit2) .with(PlayerAction::Whirl, KeyCode::KeyL) - .with(PlayerAction::Stealth, KeyCode::KeyI), + .with(PlayerAction::Whirl, KeyCode::Digit3) + .with( + PlayerAction::Stealth, + KeyCode::Semicolon, + ) + .with(PlayerAction::Stealth, KeyCode::Digit4) + .with(PlayerAction::SwapWeapon, KeyCode::KeyH) + .with( + PlayerAction::SwapWeapon, + KeyCode::Backquote, + ) + .with(PlayerAction::Interact, KeyCode::KeyF) + .with( + PlayerAction::ToggleControlOverlay, + KeyCode::KeyC, + ), }, // bundling things up becuase we reached max tuple ( From a19b6e8aba4e924a60548e3ab1d228ddfe24537e Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 13:30:55 -0700 Subject: [PATCH 12/17] Toggle control overlay on keypress --- game/src/ui/controls_overlay.rs | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 86eae7e..5430951 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -1,7 +1,11 @@ +use anyhow::Result; use bevy::ecs::system::EntityCommands; use bevy::prelude::*; +use bevy::utils; +use leafwing_input_manager::prelude::ActionState; use super::{AppState, Spawn, StateDespawnMarker}; +use crate::game::player::PlayerAction; const OVERLAY_COLOR: Color = Color::rgba(0.08, 0.10, 0.06, 0.65); const BACKGROUND_COLOR: Color = Color::rgb(0.22, 0.27, 0.18); @@ -10,7 +14,11 @@ const TEXT_COLOR: Color = Color::rgb(0.98, 0.99, 0.94); const SPACER_COLOR: Color = Color::rgb(0.20, 0.25, 0.15); pub(super) fn plugin(app: &mut App) { - app.add_systems(OnEnter(AppState::InGame), setup); + app.add_systems(OnEnter(AppState::InGame), setup) + .add_systems( + Update, + toggle_control_overlay.map(utils::dbg), + ); } fn setup(mut commands: Commands) { @@ -81,6 +89,9 @@ fn setup(mut commands: Commands) { }); } +#[derive(Component)] +struct ControlOverlayRoot; + trait ControlsOverlay { fn root(&mut self) -> EntityCommands; fn container(&mut self) -> EntityCommands; @@ -94,6 +105,7 @@ impl ControlsOverlay for T { fn root(&mut self) -> EntityCommands { self.spawn(( Name::new("controls_overlay_root"), + ControlOverlayRoot, StateDespawnMarker, NodeBundle { style: Style { @@ -105,6 +117,7 @@ impl ControlsOverlay for T { align_items: AlignItems::Center, ..default() }, + visibility: Visibility::Hidden, background_color: BackgroundColor(OVERLAY_COLOR), ..default() }, @@ -208,3 +221,22 @@ impl ControlsOverlay for T { )) } } + +fn toggle_control_overlay( + action_state_q: Query<&ActionState>, + mut control_overlay_q: Query<&mut Visibility, With>, +) -> Result<()> { + let action_state = action_state_q.get_single()?; + if action_state.just_pressed(&PlayerAction::ToggleControlOverlay) { + for mut visibility in &mut control_overlay_q { + *visibility = match *visibility { + Visibility::Inherited | Visibility::Visible => { + Visibility::Hidden + }, + Visibility::Hidden => Visibility::Visible, + } + } + } + + Ok(()) +} From bd6cebfcb23af08bca71ee3e534ab3f90615af54 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 13:53:17 -0700 Subject: [PATCH 13/17] Add popup --- game/src/ui/controls_overlay.rs | 49 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index 5430951..f2a30fa 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -14,14 +14,30 @@ const TEXT_COLOR: Color = Color::rgb(0.98, 0.99, 0.94); const SPACER_COLOR: Color = Color::rgb(0.20, 0.25, 0.15); pub(super) fn plugin(app: &mut App) { - app.add_systems(OnEnter(AppState::InGame), setup) - .add_systems( - Update, - toggle_control_overlay.map(utils::dbg), - ); + app.add_systems( + OnEnter(AppState::InGame), + ( + spawn_control_overlay, + spawn_control_hint, + ), + ) + .add_systems( + Update, + toggle_control_overlay.map(utils::dbg), + ); } -fn setup(mut commands: Commands) { +fn spawn_control_hint(mut commands: Commands) { + commands.popup().with_children(|popup| { + popup.row().with_children(|row| { + row.text("Press "); + row.control_icon("C"); + row.text(" to show Controls"); + }); + }); +} + +fn spawn_control_overlay(mut commands: Commands) { commands.root().with_children(|root| { root.container().with_children(|container| { container.row().with_children(|row| { @@ -99,6 +115,7 @@ trait ControlsOverlay { fn text(&mut self, string: impl Into) -> EntityCommands; fn control_icon(&mut self, string: impl Into) -> EntityCommands; fn spacer(&mut self) -> EntityCommands; + fn popup(&mut self) -> EntityCommands; } impl ControlsOverlay for T { @@ -220,6 +237,26 @@ impl ControlsOverlay for T { }, )) } + + fn popup(&mut self) -> EntityCommands { + self.spawn(( + Name::new("controls_popup"), + NodeBundle { + style: Style { + margin: UiRect::new( + Val::Auto, + Val::Auto, + Val::Percent(65.0), + Val::Auto, + ), + padding: UiRect::axes(Val::Px(16.0), Val::Px(4.0)), + ..default() + }, + background_color: BackgroundColor(OVERLAY_COLOR), + ..default() + }, + )) + } } fn toggle_control_overlay( From 66093f523f6b416771cf27f18151193435465a37 Mon Sep 17 00:00:00 2001 From: bokubeam Date: Tue, 17 Dec 2024 14:08:39 -0700 Subject: [PATCH 14/17] Hide popup after a few seconds --- game/src/ui/controls_overlay.rs | 46 +++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/game/src/ui/controls_overlay.rs b/game/src/ui/controls_overlay.rs index f2a30fa..42ecb94 100644 --- a/game/src/ui/controls_overlay.rs +++ b/game/src/ui/controls_overlay.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use anyhow::Result; use bevy::ecs::system::EntityCommands; use bevy::prelude::*; @@ -12,6 +14,15 @@ const BACKGROUND_COLOR: Color = Color::rgb(0.22, 0.27, 0.18); const ICON_BACKGROUND_COLOR: Color = Color::rgb(0.32, 0.37, 0.28); const TEXT_COLOR: Color = Color::rgb(0.98, 0.99, 0.94); const SPACER_COLOR: Color = Color::rgb(0.20, 0.25, 0.15); +const POPUP_DURATION_SECONDS: u64 = 5; + +#[derive(Component)] +struct ControlsOverlay; + +#[derive(Component)] +struct ControlsPopup { + timer: Timer, +} pub(super) fn plugin(app: &mut App) { app.add_systems( @@ -23,7 +34,10 @@ pub(super) fn plugin(app: &mut App) { ) .add_systems( Update, - toggle_control_overlay.map(utils::dbg), + ( + toggle_control_overlay.map(utils::dbg), + hide_popup, + ), ); } @@ -105,10 +119,7 @@ fn spawn_control_overlay(mut commands: Commands) { }); } -#[derive(Component)] -struct ControlOverlayRoot; - -trait ControlsOverlay { +trait ControlsOverlayUi { fn root(&mut self) -> EntityCommands; fn container(&mut self) -> EntityCommands; fn row(&mut self) -> EntityCommands; @@ -118,11 +129,11 @@ trait ControlsOverlay { fn popup(&mut self) -> EntityCommands; } -impl ControlsOverlay for T { +impl ControlsOverlayUi for T { fn root(&mut self) -> EntityCommands { self.spawn(( Name::new("controls_overlay_root"), - ControlOverlayRoot, + ControlsOverlay, StateDespawnMarker, NodeBundle { style: Style { @@ -241,6 +252,12 @@ impl ControlsOverlay for T { fn popup(&mut self) -> EntityCommands { self.spawn(( Name::new("controls_popup"), + ControlsPopup { + timer: Timer::new( + Duration::from_secs(POPUP_DURATION_SECONDS), + TimerMode::Once, + ), + }, NodeBundle { style: Style { margin: UiRect::new( @@ -261,7 +278,7 @@ impl ControlsOverlay for T { fn toggle_control_overlay( action_state_q: Query<&ActionState>, - mut control_overlay_q: Query<&mut Visibility, With>, + mut control_overlay_q: Query<&mut Visibility, With>, ) -> Result<()> { let action_state = action_state_q.get_single()?; if action_state.just_pressed(&PlayerAction::ToggleControlOverlay) { @@ -277,3 +294,16 @@ fn toggle_control_overlay( Ok(()) } + +fn hide_popup( + mut control_overlay_q: Query<(Entity, &mut ControlsPopup)>, + time: Res