From 640987b9b8317c6e532df55ef19e1c045dd60a88 Mon Sep 17 00:00:00 2001 From: adia redmoon Date: Sun, 28 Apr 2024 14:04:24 -0700 Subject: [PATCH] pre-refactor --- src/vvedit.rs | 2 +- src/vvedit/editor_ui.rs | 35 ++++++++++++++----- .../{ui_extensions.rs => string_tree.rs} | 1 + src/vvlib.rs | 1 + src/vvlib/structure_asset.rs | 25 +++++++++++++ 5 files changed, 54 insertions(+), 10 deletions(-) rename src/vvedit/{ui_extensions.rs => string_tree.rs} (99%) create mode 100644 src/vvlib/structure_asset.rs diff --git a/src/vvedit.rs b/src/vvedit.rs index 8854cc0..4d8d3f9 100644 --- a/src/vvedit.rs +++ b/src/vvedit.rs @@ -7,7 +7,7 @@ use crate::vvlib::oct_asset::{self, OctAssetMarker, OctTreeAsset}; mod editor_bevy_input_shim; pub mod editor_ui; mod orbit_camera; -pub mod ui_extensions; +pub mod string_tree; pub fn setup(app: &mut App) -> &mut App { app.add_plugins(DefaultPlugins.set(WindowPlugin { diff --git a/src/vvedit/editor_ui.rs b/src/vvedit/editor_ui.rs index 1189a06..c7b735e 100644 --- a/src/vvedit/editor_ui.rs +++ b/src/vvedit/editor_ui.rs @@ -37,7 +37,7 @@ use crate::{ use super::{ editor_bevy_input_shim::setup_inputs, orbit_camera::orbit_camera::{pan_orbit_camera, spawn_camera}, - ui_extensions::{StringTree, StringTreeElement}, + string_tree::{StringTree, StringTreeElement}, }; use std::fmt::Write; @@ -48,13 +48,26 @@ pub struct AssetEditData { has_changed_since_last_save: bool, } -#[derive(Default, Resource)] +#[derive(Resource)] pub struct EditWindowUIState { brush_color: Hsva, meshes: Vec, structure: StringTree, egui: EditWindowEguiState, popup: PopupWindowData, + selected_structure_element: String, +} +impl Default for EditWindowUIState { + fn default() -> Self { + Self { + brush_color: Default::default(), + meshes: Default::default(), + structure: Default::default(), + egui: Default::default(), + popup: Default::default(), + selected_structure_element: "".into(), + } + } } #[derive(Default)] pub enum PopupWindowData { @@ -489,7 +502,6 @@ pub fn edit_window_ui( }); show_editable_stringtree(ui, &mut shared_ui_state); if ui.button("Save Any Changes").clicked() { - //save all files. for each in &mut shared_ui_state.meshes { if each.has_changed_since_last_save { let handle = each.id.clone(); @@ -573,15 +585,17 @@ pub fn show_popup(state: &mut EditWindowUIState, contexts: &mut EguiContexts) { } pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState) { + let mut string_selected = state.selected_structure_element.clone(); ui.collapsing("Model Structure", |ui| { ui.vertical(|ui| { for each in &state.structure.root { match each { - super::ui_extensions::StringTreeElement::None => {} - super::ui_extensions::StringTreeElement::Element(name, children) => { + super::string_tree::StringTreeElement::None => {} + super::string_tree::StringTreeElement::Element(name, children) => { ui.horizontal(|ui| { ui.label(">".to_owned()); - ui.label(name.clone()); + //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() { @@ -599,19 +613,21 @@ pub fn show_editable_stringtree(ui: &mut egui::Ui, state: &mut EditWindowUIState } }); for each in children.as_ref() { - show_child(ui, each, 1, &mut state.popup); + show_child(ui, each, 1, &mut state.popup, &mut string_selected); } } } } }); }); + state.selected_structure_element = string_selected; } pub fn show_child( ui: &mut egui::Ui, subject: &StringTreeElement, depth: usize, state: &mut PopupWindowData, + selection: &mut String, ) { match subject { StringTreeElement::None => {} @@ -627,7 +643,8 @@ pub fn show_child( prec = prec + ">"; ui.horizontal(|ui| { ui.label(prec); - ui.label(name.clone()); + //ui.label(name.clone()); + ui.radio_value(selection, name.clone(), name.clone()); if ui.button("...").clicked() { let mut should_close = false; if let PopupWindowData::StructureElement(val) = state { @@ -643,7 +660,7 @@ pub fn show_child( } }); for each in children.as_ref() { - show_child(ui, each, depth + 1, state); + show_child(ui, each, depth + 1, state, selection); } } } diff --git a/src/vvedit/ui_extensions.rs b/src/vvedit/string_tree.rs similarity index 99% rename from src/vvedit/ui_extensions.rs rename to src/vvedit/string_tree.rs index 2502dd1..9cb2afe 100644 --- a/src/vvedit/ui_extensions.rs +++ b/src/vvedit/string_tree.rs @@ -341,6 +341,7 @@ impl StringTree { return list; } } + #[test] pub fn test_string_tree() { let parent = &String::from("parent1"); diff --git a/src/vvlib.rs b/src/vvlib.rs index b285095..a70cdb4 100644 --- a/src/vvlib.rs +++ b/src/vvlib.rs @@ -6,6 +6,7 @@ pub mod intersections; pub mod obb; pub mod oct_asset; pub mod octtree; +pub mod structure_asset; pub const RANDOM_SPACE: f32 = 5.; // size of the random possibility space. pub const INTERVAL: f32 = 0.3; // how often to add ^ that many and remove ^ that many random locations diff --git a/src/vvlib/structure_asset.rs b/src/vvlib/structure_asset.rs new file mode 100644 index 0000000..334bb58 --- /dev/null +++ b/src/vvlib/structure_asset.rs @@ -0,0 +1,25 @@ +use bevy::{ + math::{Quat, Vec3}, + transform::components::Transform, +}; + +pub struct StructureElement { + euler: Vec3, + translation: Vec3, + scale: Vec3, +} +pub enum StructureOptions { + None, +} +impl StructureElement { + pub fn into_transform(&self) -> Transform { + Transform::from_rotation( + Quat::from_rotation_x(self.euler.x) + + Quat::from_rotation_y(self.euler.y) + + Quat::from_rotation_z(self.euler.z), + ) * Transform::from_scale(self.scale) + * Transform::from_translation(self.translation) + } +} + +pub struct StructureAsset {}