shell of the beginnings of new-asset and update to load-asset. work still to be done

This commit is contained in:
Lillian Vixe 2024-06-14 15:12:15 -07:00
parent 019d5b655d
commit 20f554b8d5
3 changed files with 72 additions and 31 deletions

View file

@ -56,9 +56,6 @@ pub struct EditWindowUIState {
pub selection: Selection,
pub struct_element_selections: HashMap<String, String>,
}
// SELECTION REWORK:
// hashmap keeps track of what the selected element was per-structure
// Option (Enum(Grid OR Structure)) < early fail out support
#[derive(Default, Clone, PartialEq)]
pub enum Selection {
@ -118,6 +115,7 @@ pub enum PopupWindowMode {
EditStructureElement(String, String, String), // structure subject, rename from and to, otherwise second string is unused
CreateStructureElement(String, String, String), // structure subject, node name, parent node
LoadFile(String, i32, Vec<String>), // string is current selection from list discovered from disk, number is a timer for refreshing asset list via disk scan, last is aforementioned list
NewAsset(String, bool), //name being edited to become new asset, bool: true = structure
}
impl PopupWindowMode {
pub fn is_none(&self) -> bool {
@ -512,8 +510,10 @@ pub fn edit_window_ui(
};
egui::ScrollArea::vertical().max_height(win_size.height()).scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible).show(ui, |ui| {
if ui.button("test directory list popup").clicked() {
if ui.button("New Asset").clicked() {
shared_ui_state.popup = PopupWindowMode::NewAsset("a".into(), false);
}
if ui.button("Load Asset").clicked() {
shared_ui_state.popup = PopupWindowMode::LoadFile("".into(), 0, Vec::new());
}
ui.label("This tool is in early development.");

View file

@ -12,6 +12,7 @@ use bevy_egui::{
self,
ecolor::{hsv_from_rgb, rgb_from_hsv},
epaint::Hsva,
Button,
},
EguiContexts,
};
@ -236,37 +237,40 @@ pub fn show_popup(
});
}
PopupWindowMode::LoadFile(current_selection, counter, files) => {
// immediate mode means we run every frame
if *counter == i32::MIN {
// do nothing. disk inaccessible
} else if (*counter > (30 * 64)) | files.is_empty() {
//rescan disk
let x = fs::read_dir("assets");
if let Ok(x) = x {
let x: Result<Vec<String>, io::Error> = x
.into_iter()
.map(
//
|x| {
x.map(
//
|entry| entry.path().to_string_lossy().into_owned(),
)
},
)
.collect();
// immediate mode means we run every frame. counter and disk scan
{
if *counter == i32::MIN {
// do nothing. disk inaccessible
} else if (*counter > (30 * 64)) | files.is_empty() {
//rescan disk
let x = fs::read_dir("assets");
if let Ok(x) = x {
*files = x;
*counter = 0;
let x: Result<Vec<String>, io::Error> = x
.into_iter()
.map(
//
|x| {
x.map(
//
|entry| entry.path().to_string_lossy().into_owned(),
)
},
)
.collect();
if let Ok(x) = x {
*files = x;
*counter = 0;
} else {
*counter = i32::MIN;
}
} else {
*counter = i32::MIN;
}
} else {
*counter = i32::MIN;
*counter += 1;
}
} else {
*counter += 1;
}
let response =
egui::Window::new("load file".to_owned()).id(state.egui.popup_identifier.unwrap());
response.show(contexts.ctx_mut(), |ui| {
@ -335,7 +339,7 @@ pub fn show_popup(
}
ui.label("");
} else {
ui.label(" not a valid file to load");
ui.label("");
}
if ui.button("close").clicked() {
state_change = PopupStateChange::Cancel;
@ -349,6 +353,43 @@ pub fn show_popup(
}
});
}
PopupWindowMode::NewAsset(current_name, is_structure_or_grid) => {
// things to do to make a new asset
// selector for type of asset
// name (selector ensures its unique before allowing creation)
// upon adding, in V state_change, submit to the selective visibility tech the entities spawned
let mut can_commit = false;
let ui =
egui::Window::new("new asset".to_owned()).id(state.egui.popup_identifier.unwrap());
ui.show(contexts.ctx_mut(), |ui| {
ui.vertical(|ui| {
// ENSURING UNIQUENESS: Must not already exist in assets folder or loaded assets.
// MUST BE A VALID IDENTIFIER
ui.label(
"identifiers cannot contain the pipe character \"|\", \
whitespace (spaces, newlines, tabs), or the comma character \",\". \
slashes \"/\" will create folders automatically if needed.",
);
ui.horizontal(|ui| {
ui.radio_value(is_structure_or_grid, true, "Structure");
ui.radio_value(is_structure_or_grid, false, "Grid");
});
ui.horizontal(|ui| {
if can_commit {
ui.label("");
} else {
ui.label("");
}
if ui.button("Cancel").clicked() {
state_change = PopupStateChange::Cancel;
}
if ui.add_enabled(can_commit, Button::new("create")).clicked() {
//commit changes
}
});
});
});
}
}
match state_change {
PopupStateChange::None => {} // nothing to do if state does not change

View file

@ -1,7 +1,7 @@
what its like to load a file
default structure is empty
no meshes loaded
load a structure: structure is updated. load all meshes in the structure.
load a structure: display structure is updated. load all meshes in the structure.
load a mesh: add a mesh node in the structure at root with name of mesh
~~BONUS: want a discovery-list-display of all known assets - scan assets folder~~