restructured UI details file to extrapolate out editing the tree from the primary act of selecting objects within the structure tree

This commit is contained in:
Lillian Vixe 2024-05-19 15:30:43 -07:00
parent 2f8afb8403
commit 8c7fba2a04
3 changed files with 75 additions and 66 deletions

View file

@ -496,7 +496,46 @@ pub fn edit_window_ui(
} }
} }
}); });
show_editable_stringtree(ui, &mut shared_ui_state); ui.collapsing("Model Structure", |ui| {
ui.vertical(|ui| {
if shared_ui_state.selected_structure_element != "" {
if ui.button("...").clicked() {
let selection = shared_ui_state.selected_structure_element.clone();
let mut should_close = false;
if let PopupWindowMode::EditStructureElement(val, _) =
&shared_ui_state.popup
{
if val == &selection {
should_close = true;
}
}
if should_close {
shared_ui_state.popup = PopupWindowMode::None;
} else {
shared_ui_state.popup = PopupWindowMode::EditStructureElement(
shared_ui_state.selected_structure_element.clone(),
shared_ui_state.selected_structure_element.clone(),
)
}
ui.label(
"Tree Element Selection: ".to_owned()
+ &shared_ui_state.selected_structure_element,
);
}
if ui.button("deselect").clicked() {
shared_ui_state.selected_structure_element = "".into();
}
ui.separator();
}
let mut string_selection = shared_ui_state.selected_structure_element.clone();
show_stringtree_selector(
ui,
&mut shared_ui_state.structure,
&mut string_selection,
);
shared_ui_state.selected_structure_element = string_selection;
})
});
if ui.button("Save Any Changes").clicked() { if ui.button("Save Any Changes").clicked() {
for each in &mut shared_ui_state.meshes { for each in &mut shared_ui_state.meshes {
if each.has_changed_since_last_save { if each.has_changed_since_last_save {

View file

@ -12,7 +12,7 @@ use crate::vvlib::s_identifier_validation;
use super::{ use super::{
s_editor_ui::{EditWindowUIState, PopupWindowMode}, s_editor_ui::{EditWindowUIState, PopupWindowMode},
s_string_tree::StringTreeElement, s_string_tree::{StringTree, StringTreeElement},
}; };
pub fn color_from(egui_color: Hsva) -> Color { pub fn color_from(egui_color: Hsva) -> Color {
@ -142,60 +142,27 @@ pub fn show_popup(state: &mut EditWindowUIState, contexts: &mut EguiContexts) {
} }
} }
pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState) { pub fn show_stringtree_selector(ui: &mut egui::Ui, tree: &StringTree, selection: &mut String) {
let mut string_selected = state.selected_structure_element.clone(); for each in &tree.root {
ui.collapsing("Model Structure", |ui| { match each {
ui.vertical(|ui| { super::s_string_tree::StringTreeElement::None => {}
if state.selected_structure_element != "" { super::s_string_tree::StringTreeElement::Element(name, children) => {
ui.label("Tree Element Selection: ".to_owned() + &state.selected_structure_element); ui.horizontal(|ui| {
if ui.button("deselect").clicked() { ui.label(">".to_owned());
state.selected_structure_element = "".into(); //ui.label(name.clone());
} ui.radio_value(selection, name.clone(), name.clone());
ui.separator(); });
} for each in children.as_ref() {
for each in &state.structure.root { show_child(ui, each, 1, selection);
match each {
super::s_string_tree::StringTreeElement::None => {}
super::s_string_tree::StringTreeElement::Element(name, children) => {
ui.horizontal(|ui| {
ui.label(">".to_owned());
//ui.label(name.clone());
ui.radio_value(&mut string_selected, name.clone(), name.clone());
let but = egui::Button::new("...");
if ui.add_enabled(true, but).clicked() {
let mut should_close = false;
if let PopupWindowMode::EditStructureElement(val, _) = &state.popup
{
if val == name {
should_close = true;
}
}
if should_close {
state.popup = PopupWindowMode::None;
} else {
state.popup = PopupWindowMode::EditStructureElement(
name.clone(),
name.clone(),
)
}
}
});
for each in children.as_ref() {
show_child(ui, each, 1, &mut state.popup, &mut string_selected);
}
}
} }
} }
}); }
}); }
state.selected_structure_element = string_selected;
} }
pub fn show_child( pub fn show_child(
ui: &mut egui::Ui, ui: &mut egui::Ui,
subject: &StringTreeElement, subject: &StringTreeElement,
depth: usize, depth: usize,
state: &mut PopupWindowMode,
selection: &mut String, selection: &mut String,
) { ) {
match subject { match subject {
@ -212,9 +179,8 @@ pub fn show_child(
prec = prec + ">"; prec = prec + ">";
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(prec); ui.label(prec);
//ui.label(name.clone());
ui.radio_value(selection, name.clone(), name.clone()); ui.radio_value(selection, name.clone(), name.clone());
if ui.button("...").clicked() { /* if ui.button("...").clicked() {
let mut should_close = false; let mut should_close = false;
if let PopupWindowMode::EditStructureElement(val, _) = state { if let PopupWindowMode::EditStructureElement(val, _) = state {
if val == name { if val == name {
@ -226,10 +192,10 @@ pub fn show_child(
} else { } else {
*state = PopupWindowMode::EditStructureElement(name.clone(), name.clone()) *state = PopupWindowMode::EditStructureElement(name.clone(), name.clone())
} }
} } */
}); });
for each in children.as_ref() { for each in children.as_ref() {
show_child(ui, each, depth + 1, state, selection); show_child(ui, each, depth + 1, selection);
} }
} }
} }

View file

@ -1,10 +1,13 @@
use bevy::{
asset::{Asset, AssetLoader, AsyncReadExt},
reflect::TypePath,
transform::components::Transform,
utils::{hashbrown::HashMap, thiserror},
};
use s_string_tree::StringTree; use s_string_tree::StringTree;
use bevy::{asset::{Asset, AssetLoader, AsyncReadExt}, reflect::TypePath, transform::components::Transform, utils::{hashbrown::HashMap, thiserror}};
use thiserror::Error;
use crate::vvedit::s_string_tree; use crate::vvedit::s_string_tree;
use thiserror::Error;
#[derive(Asset, TypePath)] #[derive(Asset, TypePath)]
pub struct StructureAsset { pub struct StructureAsset {
@ -36,10 +39,10 @@ pub mod serialization {
tasks::block_on, tasks::block_on,
}; };
use super::super::{StructureLoadError, StructureAsset}; use super::super::{StructureAsset, StructureLoadError};
pub fn load_detect_version(bytes: Vec<u8>) -> Result<StructureAsset, StructureLoadError> { pub fn load_detect_version(_bytes: Vec<u8>) -> Result<StructureAsset, StructureLoadError> {
return Err(StructureLoadError::FileDataInvalid("".to_string())); return Err(StructureLoadError::FileDataInvalid("".to_string()));
} }
pub fn write_latest_version(path: &String, asset: &StructureAsset) -> bool { pub fn write_latest_version(path: &String, asset: &StructureAsset) -> bool {
@ -91,12 +94,13 @@ pub mod serialization {
pub mod version_1 { pub mod version_1 {
use super::super::super::super::{StructureLoadError, StructureAsset}; use super::super::super::super::{StructureAsset, StructureLoadError};
pub fn load(data: std::str::Lines<'_>) -> Result<StructureAsset, StructureLoadError> { pub fn load(
_data: std::str::Lines<'_>,
Err(StructureLoadError::FileDataInvalid("".to_string())) ) -> Result<StructureAsset, StructureLoadError> {
Err(StructureLoadError::FileDataInvalid("".to_string()))
} }
pub fn save(asset: &StructureAsset) -> Option<Vec<u8>> { pub fn save(_asset: &StructureAsset) -> Option<Vec<u8>> {
None None
} }
} }
@ -142,4 +146,4 @@ impl AssetLoader for StructureLoader {
return serialization::meshes::load_detect_version(bytes); return serialization::meshes::load_detect_version(bytes);
}) })
} }
} }