Aaaaand... Back to inspector

This commit is contained in:
Franklin 2023-11-08 13:11:14 -04:00
parent 28765e173a
commit f5d92d89f2
7 changed files with 34 additions and 110 deletions

View File

@ -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::<NoUserData>::default())
.add_plugins(bevy_egui::EguiPlugin)
//.add_plugins(bevy_egui::EguiPlugin)
//.add_plugins(WorldInspectorPlugin::new())
.add_plugins(MainGameUIPlugin)
.add_plugins(MainEditorUiPlugin);

View File

@ -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<PrimaryWindow>>,
egui_settings: Res<bevy_egui::EguiSettings>,
mut cameras: Query<&mut Camera, With<MainCamera>>,
) {
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,
});*/
}

View File

@ -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<PrimaryWindow>>()
.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);
});
});
}

View File

@ -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;
*/

View File

@ -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<SelectedEntities>,
) {
if !world.resource::<SettingsScreenUIConfiguration>().settings_menu_shown {
return
}
let mut egui_context = world
.query_filtered::<&mut EguiContext, With<PrimaryWindow>>()
.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());
});
});
}

View File

@ -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::<GltfAssetType>()
.register_type::<GltfAssets>()
.register_type::<Equipment>()
.register_type::<GameLoadState>();
app.insert_resource(EditorUiState::new());
app.add_systems(Update, editor_ui);
app.add_systems(PostUpdate, set_camera_viewport);
.register_type::<GameLoadState>()
.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);
}
}

View File

@ -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,
}
}
}