From 5952ee5608da124d3b507e7ecad034e76080ead0 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Wed, 30 Aug 2023 09:33:05 -0700 Subject: [PATCH] move actions to their own UI element --- bin/editor.rs | 242 +++++++++++++++++++++++--------------------------- src/ui.rs | 54 +++++++---- 2 files changed, 150 insertions(+), 146 deletions(-) diff --git a/bin/editor.rs b/bin/editor.rs index 0f155a0..ae7a338 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -3,30 +3,19 @@ // Editor for creating Monologue Trees levels // // BUGS: +// * Not loading scenes with Active refactor +// * Not pause animations with Active refactor // * Camera order ambiguity // * Load new GLTF -> Despawn all level entities // // TODO: // * Disable auto start/load // * (hard) Harden Active Camera -// * (medium) Despawn entire scene when GLTF changed? // * (medium) Select Font -> "Default Font" Resource // * (medium) Pre-compute animation target entities -// * (medium) Animation buttons only visible when playable -// * (easy) Clear button to wipe spawned scene // * Better handle hide/close monologue // * (brutal) export level // * (hard) import level -// -// Asset types: -// * Audios (done) -// * Loop individual (done) -// * Gltfs (doing) -// * Scenes -// * Animations -// * Play/Pause all -// * Fonts (done) -// * Monologues (done) use bevy::{ asset::{Asset, AssetLoader, Assets, ChangeWatcher, LoadContext, LoadedAsset}, @@ -72,8 +61,6 @@ fn main() { .init_resource::() .add_asset::() .init_asset_loader::() - .add_event::>() - .add_event::>() .add_systems(Startup, (initialize_ui, init_texts_ui, welcome_message)) .add_systems( Update, @@ -89,16 +76,8 @@ fn main() { Update, (remove_scenes_ui, add_scenes_ui, control_active_scenes), ) - .add_systems( - Update, - ( - cameras_ui, - manage_active_camera, - control_active_camera, - fallback_camera, - ), - ) - .add_systems(Update, (audio_ui, play_audio)) + .add_systems(Update, (cameras_ui, manage_active_camera, fallback_camera)) + .add_systems(Update, (audio_ui, play_audio, pause_audio)) .add_systems( Update, ( @@ -106,7 +85,7 @@ fn main() { gltf_ui, fonts_ui, texts_ui, - manage_active_gltf, + control_active_gltf, show_preview_text, sync_monologue_font, ), @@ -126,13 +105,6 @@ fn main() { #[derive(Resource, Default)] pub struct AssetRegistry(Vec); -#[derive(Event)] -pub enum CustomAssetEvent { - Add { handle: Handle, name: String }, - Remove { handle: Handle }, - Clear, -} - #[derive(Debug, Component)] pub struct TabRoot; @@ -162,6 +134,15 @@ fn initialize_ui(mut commands: Commands) { ..default() }; + let simple_button = ButtonBundle { + style: Style { + ..base_style.clone() + }, + background_color: Color::WHITE.into(), + border_color: Color::BLACK.into(), + ..default() + }; + commands .spawn(NodeBundle { style: Style { @@ -198,15 +179,6 @@ fn initialize_ui(mut commands: Commands) { // HACK: This is super janky but I think we need it like this for UI layout rules let mut content_containers: Vec<(String, Entity)> = Vec::new(); - let simple_button = ButtonBundle { - style: Style { - ..base_style.clone() - }, - background_color: Color::WHITE.into(), - border_color: Color::BLACK.into(), - ..default() - }; - // Containers with asset content parent .spawn(( @@ -297,25 +269,6 @@ fn initialize_ui(mut commands: Commands) { )); }, ); - - parent.spawn(( - simple_button.clone(), - ClearAssets, - ui::Sorting(90), - ui::Title { - text: "Clear Assets".into(), - ..default() - }, - )); - parent.spawn(( - simple_button.clone(), - ClearLevel, - ui::Sorting(95), - ui::Title { - text: "Reset Level".into(), - ..default() - }, - )); }); }) .id(); @@ -329,6 +282,73 @@ fn initialize_ui(mut commands: Commands) { ui::Sorting(0), )); }); + commands + .spawn(NodeBundle { + style: Style { + bottom: Val::Px(0.0), + left: Val::Px(0.0), + position_type: PositionType::Absolute, + border: UiRect::all(Val::Px(1.0)), + margin: UiRect::all(Val::Px(1.0)), + padding: UiRect::all(Val::Px(1.0)), + flex_direction: FlexDirection::Column, + overflow: Overflow::clip(), + ..default() + }, + background_color: Color::WHITE.into(), + border_color: Color::BLACK.into(), + ..default() + }) + .with_children(|parent| { + let container = parent + .spawn(( + NodeBundle { + style: Style { + border: UiRect::all(Val::Px(1.0)), + margin: UiRect::all(Val::Px(1.0)), + padding: UiRect::all(Val::Px(1.0)), + flex_direction: FlexDirection::Column, + overflow: Overflow::clip(), + ..default() + }, + background_color: Color::WHITE.into(), + border_color: Color::BLACK.into(), + ..default() + }, + ui::Sorting(99), + ui::Select::Action, + )) + .with_children(|parent| { + parent.spawn(( + simple_button.clone(), + ClearAssets, + ui::Sorting(1), + ui::Title { + text: "Clear Assets".into(), + ..default() + }, + )); + parent.spawn(( + simple_button.clone(), + ClearLevel, + ui::Sorting(2), + ui::Title { + text: "Reset Level".into(), + ..default() + }, + )); + }) + .id(); + parent.spawn(( + ui::TitleBarBase::new(Color::WHITE).bundle(), + ui::Title { + text: "Actions".into(), + ..default() + }, + ui::Minimize { target: container }, + ui::Sorting(0), + )); + }); } fn welcome_message(mut writer: EventWriter) { @@ -466,27 +486,22 @@ mod audio { }); } - pub fn play_audio( - events: Query<(Entity, &Interaction, &AudioSink), (With