Skip to content

Commit

Permalink
Store components state for each entity
Browse files Browse the repository at this point in the history
Store components state for each entity
  • Loading branch information
rewin123 authored Nov 27, 2023
2 parents f8fde93 + 4abd498 commit 9fcd99b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
47 changes: 29 additions & 18 deletions src/editor/ui/inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bevy::{
prelude::*,
ptr::PtrMut,
reflect::ReflectFromPtr,
utils::HashMap,
};

use bevy_egui::*;
Expand Down Expand Up @@ -55,11 +56,13 @@ impl Plugin for SpaceInspectorPlugin {
}

#[derive(Resource, Default)]
pub struct InspectorTab {}
pub struct InspectorTab {
open_components: HashMap<String, bool>,
}

impl EditorTab for InspectorTab {
fn ui(&mut self, ui: &mut egui::Ui, _: &mut Commands, world: &mut World) {
inspect(ui, world);
inspect(ui, world, &mut self.open_components);
}

fn title(&self) -> egui::WidgetText {
Expand Down Expand Up @@ -126,7 +129,7 @@ fn execute_inspect_command(
}

/// System to show inspector panel
pub fn inspect(ui: &mut egui::Ui, world: &mut World) {
pub fn inspect(ui: &mut egui::Ui, world: &mut World, open_components: &mut HashMap<String, bool>) {
let selected_entity = world
.query_filtered::<Entity, With<Selected>>()
.get_single(world);
Expand Down Expand Up @@ -207,21 +210,29 @@ pub fn inspect(ui: &mut egui::Ui, world: &mut World) {

if !editor_registry.silent.contains(&registration.type_id()) {
ui.push_id(format!("{:?}-{}", &e.id(), &name), |ui| {
ui.collapsing(name, |ui| {
ui.push_id(
format!("content-{:?}-{}", &e.id(), &name),
|ui| {
if env.ui_for_reflect_with_options(
value,
ui,
ui.id(),
&(),
) {
set_changed();
}
},
);
});
let header = egui::CollapsingHeader::new(name)
.default_open(*open_components.get(name).unwrap_or(&false))
.show(ui, |ui| {
ui.push_id(
format!("content-{:?}-{}", &e.id(), &name),
|ui| {
if env.ui_for_reflect_with_options(
value,
ui,
ui.id(),
&(),
) {
set_changed();
}
},
);
});
if header.header_response.clicked() {
let open_name =
open_components.entry(name.clone()).or_default();
//At click header not opened simultaneously so its need to check percent of opened
*open_name = header.openness < 0.5;
}
});

ui.push_id(
Expand Down
12 changes: 6 additions & 6 deletions src/editor/ui/tools/gizmo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub enum GizmoHotkey {
impl Hotkey for GizmoHotkey {
fn name<'a>(&self) -> String {
match self {
GizmoHotkey::Translate => "Translate entity".to_string(),
GizmoHotkey::Rotate => "Rotate entity".to_string(),
GizmoHotkey::Scale => "Scale entity".to_string(),
GizmoHotkey::Delete => "Delete entity".to_string(),
GizmoHotkey::Multiple => "Change multiple entities".to_string(),
GizmoHotkey::Clone => "Clone entity".to_string(),
Self::Translate => "Translate entity".to_string(),
Self::Rotate => "Rotate entity".to_string(),
Self::Scale => "Scale entity".to_string(),
Self::Delete => "Delete entity".to_string(),
Self::Multiple => "Change multiple entities".to_string(),
Self::Clone => "Clone entity".to_string(),
}
}
}
Expand Down

0 comments on commit 9fcd99b

Please sign in to comment.