From f5d92d89f2980caeacc2fa1c1506c97ecde257cb Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 8 Nov 2023 13:11:14 -0400 Subject: [PATCH] Aaaaand... Back to inspector --- src/main.rs | 5 ++-- src/ui/editor/camera.rs | 31 --------------------- src/ui/editor/inspector.rs | 17 ++++++++++++ src/ui/editor/mod.rs | 5 +++- src/ui/editor/panels.rs | 55 -------------------------------------- src/ui/editor/plugin.rs | 16 +++++++---- src/ui/editor/state.rs | 15 ----------- 7 files changed, 34 insertions(+), 110 deletions(-) delete mode 100644 src/ui/editor/camera.rs create mode 100644 src/ui/editor/inspector.rs delete mode 100644 src/ui/editor/panels.rs delete mode 100644 src/ui/editor/state.rs diff --git a/src/main.rs b/src/main.rs index 6dbd515..f63167e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ use bevy::prelude::*; -use bevy_inspector_egui::{DefaultInspectorConfigPlugin, bevy_egui::{self}}; use bevy_rapier3d::prelude::*; use scenes::scene1; use ui::{game::plugin::MainGameUIPlugin, editor::plugin::MainEditorUiPlugin}; @@ -25,9 +24,9 @@ fn main() { fn setup_plugins(application: &mut App) { application .add_plugins(DefaultPlugins) - .add_plugins(DefaultInspectorConfigPlugin) + //.add_plugins(DefaultInspectorConfigPlugin) .add_plugins(RapierPhysicsPlugin::::default()) - .add_plugins(bevy_egui::EguiPlugin) + //.add_plugins(bevy_egui::EguiPlugin) //.add_plugins(WorldInspectorPlugin::new()) .add_plugins(MainGameUIPlugin) .add_plugins(MainEditorUiPlugin); diff --git a/src/ui/editor/camera.rs b/src/ui/editor/camera.rs deleted file mode 100644 index 9466047..0000000 --- a/src/ui/editor/camera.rs +++ /dev/null @@ -1,31 +0,0 @@ -use bevy::{prelude::*, window::PrimaryWindow, render::camera::Viewport}; -use bevy_inspector_egui::bevy_egui; - -use crate::comps::core::markers::camera::MainCamera; - -pub fn set_camera_viewport( - primary_window: Query<&mut Window, With>, - egui_settings: Res, - mut cameras: Query<&mut Camera, With>, -) { - let Ok(mut cam) = cameras.get_single_mut() else { - return; - }; - - let Ok(window) = primary_window.get_single() else { - return; - }; - - println!("{}, {}", window.width(), window.height()); - - let scale_factor = window.scale_factor() * egui_settings.scale_factor; - - /*let viewport_pos = ui_state.viewport_rect.left_top().to_vec2() * scale_factor as f32; - let viewport_size = ui_state.viewport_rect.size() * scale_factor as f32; - - cam.viewport = Some(Viewport { - physical_position: UVec2::new(viewport_pos.x as u32, viewport_pos.y as u32), - physical_size: UVec2::new(viewport_size.x as u32, viewport_size.y as u32), - depth: 0.0..1.0, - });*/ -} \ No newline at end of file diff --git a/src/ui/editor/inspector.rs b/src/ui/editor/inspector.rs new file mode 100644 index 0000000..21b1e69 --- /dev/null +++ b/src/ui/editor/inspector.rs @@ -0,0 +1,17 @@ +use bevy::{prelude::*, window::PrimaryWindow}; +use bevy_inspector_egui::{egui, bevy_egui::EguiContext, bevy_inspector}; + +pub fn inspector_ui(world: &mut World) { + let mut egui_context = world + .query_filtered::<&mut EguiContext, With>() + .single(world) + .clone(); + + egui::Window::new("World") + .show(egui_context.get_mut(), |ui| { + egui::ScrollArea::vertical() + .show(ui, |ui| { + bevy_inspector::ui_for_world(world, ui); + }); + }); +} \ No newline at end of file diff --git a/src/ui/editor/mod.rs b/src/ui/editor/mod.rs index 4cf1172..6e7d74d 100644 --- a/src/ui/editor/mod.rs +++ b/src/ui/editor/mod.rs @@ -1,5 +1,8 @@ //! Editor UI means everything that won't be in the actual game pub mod plugin; +pub mod inspector; +/* pub mod panels; pub mod state; -pub mod camera; \ No newline at end of file +pub mod camera; +*/ \ No newline at end of file diff --git a/src/ui/editor/panels.rs b/src/ui/editor/panels.rs deleted file mode 100644 index 649ef54..0000000 --- a/src/ui/editor/panels.rs +++ /dev/null @@ -1,55 +0,0 @@ -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, - ); - println!("{:#?}", ui.clip_rect()); - 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 8d97295..41e419c 100644 --- a/src/ui/editor/plugin.rs +++ b/src/ui/editor/plugin.rs @@ -1,8 +1,11 @@ use bevy::prelude::*; +use bevy_inspector_egui::bevy_egui::EguiPlugin; use crate::{logic::core::{guns::{player_firing::PlayerFiringInfo, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}, player::{player_values_state::PlayerValuesState, camera_player_sync::MouseMovementSettings, player_movement::{PlayerLinearYState, PlayerLinearXZState, PlayerMovementInput}}}, comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::{HoldableObjectData, InPlayerHands}, player::{PlayerData, Player, PlayerHand}}, scenes::scene1::skybox::Cubemap, setup::{animations::{AllFirearmAnimations, FirearmAnimations}, assets::{GltfAssetType, GltfAssets}, equipment::Equipment, load_state::GameLoadState}}; -use super::{panels::editor_ui, state::EditorUiState, camera::set_camera_viewport}; +use super::inspector::inspector_ui; + +//use super::{panels::editor_ui, state::EditorUiState, camera::set_camera_viewport}; pub struct MainEditorUiPlugin; @@ -31,9 +34,12 @@ impl Plugin for MainEditorUiPlugin { .register_type::() .register_type::() .register_type::() - .register_type::(); - app.insert_resource(EditorUiState::new()); - app.add_systems(Update, editor_ui); - app.add_systems(PostUpdate, set_camera_viewport); + .register_type::() + .add_plugins(EguiPlugin) + .add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s + .add_systems(Update, inspector_ui); + //app.insert_resource(EditorUiState::new()); + //app.add_systems(Update, editor_ui); + //app.add_systems(PostUpdate, set_camera_viewport); } } \ No newline at end of file diff --git a/src/ui/editor/state.rs b/src/ui/editor/state.rs deleted file mode 100644 index 41efae9..0000000 --- a/src/ui/editor/state.rs +++ /dev/null @@ -1,15 +0,0 @@ -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