From 420ec1c99b53468def2ac97b9e109c9fb5196262 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 27 Jan 2023 14:52:08 +0200 Subject: [PATCH] WIP(sdbclient): better UI system --- sdbclient/src/main.rs | 14 ++++++++++++++ sdbclient/src/plugins/menu/mod.rs | 4 ++-- sdbclient/src/plugins/menu/playscreen.rs | 21 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/sdbclient/src/main.rs b/sdbclient/src/main.rs index dd07132..9f6d822 100644 --- a/sdbclient/src/main.rs +++ b/sdbclient/src/main.rs @@ -18,6 +18,8 @@ use bevy_mod_scripting::prelude::*; use iyes_loopless::prelude::*; +use belly::prelude::BellyPlugin; + mod api; mod cfg; mod constants; @@ -77,6 +79,8 @@ fn main() { app.add_plugin(ScriptingPlugin).add_plugin(lua::LuaPlugin); + app.add_plugin(BellyPlugin); + app.insert_resource(cfg::CfgDirs( directories::ProjectDirs::from("com", "liljamo", "deckbuilder") .expect("failed to get project directories"), @@ -109,3 +113,13 @@ pub fn despawn_screen(to_despawn: Query>, mut comm commands.entity(entity).despawn_recursive(); } } + +/// Utility function to remove UI nodes, which is usually just one node +/// NOTE: So, UI shows up as just nodes that don't have parents, so this +/// works mighty fine, at least for now. +/// MAY break something in the future, but that's why this note is here. +pub fn remove_ui(mut commands: Commands, nodes: Query, Without)>) { + for node in &nodes { + commands.entity(node).despawn_recursive(); + } +} diff --git a/sdbclient/src/plugins/menu/mod.rs b/sdbclient/src/plugins/menu/mod.rs index 46b2482..9e3ee5d 100644 --- a/sdbclient/src/plugins/menu/mod.rs +++ b/sdbclient/src/plugins/menu/mod.rs @@ -11,7 +11,7 @@ use iyes_loopless::prelude::*; use crate::cfg::CfgUser; -use crate::{despawn_screen, GameState}; +use crate::{despawn_screen, remove_ui, GameState}; mod mainmenuscreen; use mainmenuscreen::*; @@ -73,7 +73,7 @@ impl Plugin for MenuPlugin { .add_exit_system(MenuState::AccountLoggedIn, despawn_screen::) // Systems for play screen .add_enter_system(MenuState::Play, play_setup) - .add_exit_system(MenuState::Play, despawn_screen::) + .add_exit_system(MenuState::Play, remove_ui) // Common systems .add_system_set( ConditionSet::new() diff --git a/sdbclient/src/plugins/menu/playscreen.rs b/sdbclient/src/plugins/menu/playscreen.rs index 695344a..8e365e4 100644 --- a/sdbclient/src/plugins/menu/playscreen.rs +++ b/sdbclient/src/plugins/menu/playscreen.rs @@ -10,16 +10,20 @@ use bevy::{ prelude::*, ui::{JustifyContent, Size, Style, Val}, }; +use iyes_loopless::prelude::*; + +use belly::prelude::*; use crate::constants::TEXT_COLOR; -use super::{MenuButtonAction, NORMAL_BUTTON}; +use super::{MenuButtonAction, MenuState, NORMAL_BUTTON}; /// Tag component for tagging entities on the play screen #[derive(Component)] pub struct OnPlayScreen; pub fn play_setup(mut commands: Commands, asset_server: Res) { + /* let font = asset_server.load("fonts/FiraMono-Regular.ttf"); let button_style = Style { @@ -35,7 +39,21 @@ pub fn play_setup(mut commands: Commands, asset_server: Res) { font_size: 40.0, color: TEXT_COLOR, }; + */ + + commands.add(eml! { + +
+ +
+ + }); + /* commands .spawn(( NodeBundle { @@ -99,4 +117,5 @@ pub fn play_setup(mut commands: Commands, asset_server: Res) { } }); }); + */ } -- 2.44.1