From 2683d754626c1c79b436ede7b12932baf36ec6ae Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 8 Nov 2023 00:11:12 -0400 Subject: [PATCH] Tried to use egui::dock but ended up just using a manual egui --- src/main.rs | 9 ++++--- src/ui/editor/mod.rs | 4 ++- src/ui/editor/panels.rs | 58 +++++++++++++++++++++++++++++++++++++++++ src/ui/editor/plugin.rs | 10 ++++--- src/ui/editor/state.rs | 15 +++++++++++ 5 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 src/ui/editor/panels.rs create mode 100644 src/ui/editor/state.rs diff --git a/src/main.rs b/src/main.rs index dc46d00..e18d5c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ use bevy::prelude::*; -use bevy_inspector_egui::quick::WorldInspectorPlugin; +use bevy_inspector_egui::{DefaultInspectorConfigPlugin, bevy_egui::{self}}; use bevy_rapier3d::prelude::*; use logic::core::{guns::player_firing::PlayerFiringInfo, player::player_values_state::PlayerValuesState}; use scenes::scene1; -use ui::game::plugin::MainGameUIPlugin; +use ui::{game::plugin::MainGameUIPlugin, editor::plugin::MainEditorUiPlugin}; mod comps; mod constants; @@ -26,9 +26,12 @@ fn main() { fn setup_plugins(application: &mut App) { application .add_plugins(DefaultPlugins) + .add_plugins(DefaultInspectorConfigPlugin) .add_plugins(RapierPhysicsPlugin::::default()) - .add_plugins(WorldInspectorPlugin::new()) + .add_plugins(bevy_egui::EguiPlugin) + //.add_plugins(WorldInspectorPlugin::new()) .add_plugins(MainGameUIPlugin) + .add_plugins(MainEditorUiPlugin) .register_type::() .register_type::(); } diff --git a/src/ui/editor/mod.rs b/src/ui/editor/mod.rs index 198833e..0b8003e 100644 --- a/src/ui/editor/mod.rs +++ b/src/ui/editor/mod.rs @@ -1,2 +1,4 @@ //! Editor UI means everything that won't be in the actual game -pub mod plugin; \ No newline at end of file +pub mod plugin; +pub mod panels; +pub mod state; \ No newline at end of file diff --git a/src/ui/editor/panels.rs b/src/ui/editor/panels.rs new file mode 100644 index 0000000..426f7f9 --- /dev/null +++ b/src/ui/editor/panels.rs @@ -0,0 +1,58 @@ +use bevy::{prelude::*, window::PrimaryWindow}; +use bevy_inspector_egui::{bevy_inspector::hierarchy::SelectedEntities, bevy_egui::EguiContext, egui}; + +use crate::ui::game::settings::SettingsScreenUIConfiguration; + +pub fn editor_ui( + world: &mut World, + mut selected_entities: Local, +) { + if !world.resource::().settings_menu_shown { + return + } + let mut egui_context = world + .query_filtered::<&mut EguiContext, With>() + .single(world) + .clone(); + + egui::SidePanel::left("hierarchy") + .default_width(250.0) + .show(egui_context.get_mut(), |ui| { + egui::ScrollArea::vertical().show(ui, |ui| { + ui.heading("Components Hierarchy"); + + bevy_inspector_egui::bevy_inspector::hierarchy::hierarchy_ui( + world, + ui, + &mut selected_entities, + ); + + ui.separator(); + + ui.heading("All Resources"); + bevy_inspector_egui::bevy_inspector::ui_for_resources(world, ui); + ui.allocate_rect(ui.available_rect_before_wrap(), egui::Sense::hover()); + ui.allocate_space(ui.available_size()); + }); + }); + + egui::SidePanel::right("inspector") + .default_width(250.0) + .show(egui_context.get_mut(), |ui| { + egui::ScrollArea::vertical().show(ui, |ui| { + ui.heading("Inspector"); + + match selected_entities.as_slice() { + &[entity] => { + bevy_inspector_egui::bevy_inspector::ui_for_entity(world, entity, ui); + } + entities => { + bevy_inspector_egui::bevy_inspector::ui_for_entities_shared_components( + world, entities, ui, + ); + } + } + ui.allocate_space(ui.available_size()); + }); + }); +} \ No newline at end of file diff --git a/src/ui/editor/plugin.rs b/src/ui/editor/plugin.rs index 4f17edc..fafab44 100644 --- a/src/ui/editor/plugin.rs +++ b/src/ui/editor/plugin.rs @@ -1,10 +1,12 @@ use bevy::prelude::*; -pub struct MainEditorUIPlugin; +use super::{panels::editor_ui, state::EditorUiState}; -#[allow(unused)] -impl Plugin for MainEditorUIPlugin { +pub struct MainEditorUiPlugin; + +impl Plugin for MainEditorUiPlugin { fn build(&self, app: &mut App) { - todo!() + app.insert_resource(EditorUiState::new()); + app.add_systems(Update, editor_ui); } } \ No newline at end of file diff --git a/src/ui/editor/state.rs b/src/ui/editor/state.rs new file mode 100644 index 0000000..41efae9 --- /dev/null +++ b/src/ui/editor/state.rs @@ -0,0 +1,15 @@ +use bevy::prelude::*; +use bevy_inspector_egui::egui; + +#[derive(Resource)] +pub struct EditorUiState { + pub viewport_rect: egui::Rect, +} + +impl EditorUiState { + pub fn new() -> Self { + Self { + viewport_rect: egui::Rect::NOTHING, + } + } +} \ No newline at end of file