scroll bar
This commit is contained in:
parent
662436bb3e
commit
0e19a10325
|
@ -8,10 +8,9 @@ use bevy::{
|
||||||
},
|
},
|
||||||
math::Vec3,
|
math::Vec3,
|
||||||
prelude::default,
|
prelude::default,
|
||||||
reflect::Reflect,
|
|
||||||
render::{camera::Camera, color::Color},
|
render::{camera::Camera, color::Color},
|
||||||
transform::components::{GlobalTransform, Transform},
|
transform::components::{GlobalTransform, Transform},
|
||||||
window::{PrimaryWindow, Window},
|
window::{PrimaryWindow, Window, WindowResolution},
|
||||||
};
|
};
|
||||||
use bevy_egui::{
|
use bevy_egui::{
|
||||||
egui::{self, color_picker, epaint::Hsva, Id, Pos2, Rect, ScrollArea},
|
egui::{self, color_picker, epaint::Hsva, Id, Pos2, Rect, ScrollArea},
|
||||||
|
@ -412,259 +411,272 @@ pub fn edit_window_ui(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut win_size = Option::<WindowResolution>::None;
|
||||||
for win in &window {
|
for win in &window {
|
||||||
let size = &win.resolution;
|
let size = win.resolution.clone();
|
||||||
response = response.fixed_pos(Pos2::new(0., 0.));
|
response = response.fixed_pos(Pos2::new(0., 0.));
|
||||||
response = response.fixed_size(egui::Vec2::new(
|
response = response.fixed_size(egui::Vec2::new(
|
||||||
size.width() as f32 / 3.,
|
size.width() as f32 / 4.,
|
||||||
size.height() as f32 / 1.,
|
size.height() as f32 / 1.33,
|
||||||
));
|
));
|
||||||
|
response = response.constrain(true);
|
||||||
|
win_size = Some(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.show(contexts.ctx_mut(), |ui: &mut egui::Ui| {
|
response.show(contexts.ctx_mut(), |ui| {
|
||||||
if ui.button("test directory list popup").clicked() {
|
let win_size = {
|
||||||
shared_ui_state.popup = PopupWindowMode::LoadFile("".into(), 0, Vec::new());
|
if win_size.is_some() {
|
||||||
}
|
win_size.unwrap()
|
||||||
ui.label("This tool is in early development.");
|
} else {
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
WindowResolution::new(50f32, 50f32)
|
||||||
ui.collapsing("Mesh Tools", |ui| {
|
}
|
||||||
let mut label = String::from("Controls:");
|
};
|
||||||
writeln!(label, "").ok();
|
egui::ScrollArea::vertical().max_height(win_size.height()).scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible).show(ui, |ui| {
|
||||||
writeln!(label, "click adds a voxel:").ok();
|
|
||||||
writeln!(label, "R+click removes a voxel:").ok();
|
|
||||||
writeln!(label, "E+click paints (edits) a voxel:").ok();
|
|
||||||
color_picker::color_picker_hsva_2d(
|
|
||||||
ui,
|
|
||||||
&mut shared_ui_state.brush_color,
|
|
||||||
color_picker::Alpha::Opaque,
|
|
||||||
);
|
|
||||||
ui.label(label);
|
|
||||||
let mut color_to_set: Option<Color> = None;
|
|
||||||
for each in &shared_ui_state.grids {
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
//color palette clickables.
|
|
||||||
let handle = each.id.clone();
|
|
||||||
let asset = grid_assets.get(handle);
|
|
||||||
if asset.is_some() {
|
|
||||||
let list = {
|
|
||||||
let eoct = asset.unwrap().model.read().unwrap();
|
|
||||||
eoct.collect_voxels()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut count: Vec<(Color, usize)> = Vec::new();
|
if ui.button("test directory list popup").clicked() {
|
||||||
fn eq(c1: &Color, c2: &mut Color) -> bool {
|
shared_ui_state.popup = PopupWindowMode::LoadFile("".into(), 0, Vec::new());
|
||||||
c1.r() == c2.r() && c1.g() == c2.g() && c1.b() == c2.b()
|
}
|
||||||
|
ui.label("This tool is in early development.");
|
||||||
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
ui.collapsing("Mesh Tools", |ui| {
|
||||||
|
let mut label = String::from("Controls:");
|
||||||
|
writeln!(label, "").ok();
|
||||||
|
writeln!(label, "click adds a voxel:").ok();
|
||||||
|
writeln!(label, "R+click removes a voxel:").ok();
|
||||||
|
writeln!(label, "E+click paints (edits) a voxel:").ok();
|
||||||
|
color_picker::color_picker_hsva_2d(
|
||||||
|
ui,
|
||||||
|
&mut shared_ui_state.brush_color,
|
||||||
|
color_picker::Alpha::Opaque,
|
||||||
|
);
|
||||||
|
ui.label(label);
|
||||||
|
let mut color_to_set: Option<Color> = None;
|
||||||
|
for each in &shared_ui_state.grids {
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
//color palette clickables.
|
||||||
|
let handle = each.id.clone();
|
||||||
|
let asset = grid_assets.get(handle);
|
||||||
|
if asset.is_some() {
|
||||||
|
let list = {
|
||||||
|
let eoct = asset.unwrap().model.read().unwrap();
|
||||||
|
eoct.collect_voxels()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut count: Vec<(Color, usize)> = Vec::new();
|
||||||
|
fn eq(c1: &Color, c2: &mut Color) -> bool {
|
||||||
|
c1.r() == c2.r() && c1.g() == c2.g() && c1.b() == c2.b()
|
||||||
|
}
|
||||||
|
for (_, _, color) in &list {
|
||||||
|
let mut is_committed = false;
|
||||||
|
for (each_col, each_count) in &mut count {
|
||||||
|
if eq(color, each_col) {
|
||||||
|
*each_count += 1;
|
||||||
|
is_committed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !is_committed {
|
||||||
|
count.push((color.clone(), 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
if !count.is_empty() {
|
||||||
|
ui.label(each.path.clone());
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
for (color, count) in count {
|
||||||
|
let button = egui::Button::new(count.to_string())
|
||||||
|
.fill(egui_color_from(color));
|
||||||
|
if ui.add(button).clicked() {
|
||||||
|
color_to_set = Some(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (_, _, color) in &list {
|
});
|
||||||
let mut is_committed = false;
|
}
|
||||||
for (each_col, each_count) in &mut count {
|
if let Some(color) = color_to_set {
|
||||||
if eq(color, each_col) {
|
shared_ui_state.brush_color = egui_color_from(color);
|
||||||
*each_count += 1;
|
}
|
||||||
is_committed = true;
|
if ui.button("Add Origin Voxel").clicked() {
|
||||||
|
//
|
||||||
|
for pair in &mut pairs.handles {
|
||||||
|
let id = pair.oct_handle.clone();
|
||||||
|
let tree = grid_assets.get_mut(id);
|
||||||
|
if tree.is_some() {
|
||||||
|
let tree = tree.unwrap();
|
||||||
|
{
|
||||||
|
let mut eoct = tree.model.write().unwrap();
|
||||||
|
eoct.set_voxel_at_location(
|
||||||
|
Vec3::ZERO,
|
||||||
|
color_from(shared_ui_state.brush_color),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.collapsing("grid assets", |ui| {
|
||||||
|
//
|
||||||
|
for (id, _asset) in (&grid_assets).iter() {
|
||||||
|
let path = asset_server.get_path(id.untyped());
|
||||||
|
if let Some(path) = path {
|
||||||
|
ui.label(path.to_string().as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.collapsing("structure assets", |ui| {
|
||||||
|
ui.radio_value(
|
||||||
|
&mut shared_ui_state.selected_structure,
|
||||||
|
"".to_string(),
|
||||||
|
"Deselect",
|
||||||
|
);
|
||||||
|
for (id, _asset) in (&structure_assets).iter() {
|
||||||
|
let path = asset_server.get_path(id.untyped());
|
||||||
|
if let Some(path) = path {
|
||||||
|
//ui.label(path.to_string().as_str());
|
||||||
|
ui.radio_value(
|
||||||
|
&mut shared_ui_state.selected_structure,
|
||||||
|
path.to_string(),
|
||||||
|
path.to_string().as_str(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let mut selected_structure = false;
|
||||||
|
let mut selection = Option::<StringTree>::None;
|
||||||
|
if shared_ui_state.selected_structure != "" {
|
||||||
|
for structure in &shared_ui_state.structures {
|
||||||
|
if structure.path == shared_ui_state.selected_structure {
|
||||||
|
let asset = structure_assets.get_mut(structure.id.clone());
|
||||||
|
if asset.is_some() {
|
||||||
|
selection = Some(asset.unwrap().layout.clone());
|
||||||
|
selected_structure = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if selected_structure {
|
||||||
|
let selection = selection.unwrap();
|
||||||
|
ui.collapsing("Model Structure", |ui| {
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
if ui.button("add element").clicked() {
|
||||||
|
shared_ui_state.popup = PopupWindowMode::CreateStructureElement(
|
||||||
|
shared_ui_state.selected_structure.clone(),
|
||||||
|
"unnamed".to_owned(),
|
||||||
|
"".to_owned(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
if shared_ui_state.selected_structure_element != "" {
|
||||||
|
let structure_name = shared_ui_state.selected_structure.clone();
|
||||||
|
let selection_name = shared_ui_state.selected_structure_element.clone();
|
||||||
|
for structure in &mut shared_ui_state.structures {
|
||||||
|
if structure.path == structure_name {
|
||||||
|
let asset = structure_assets.get_mut(structure.id.clone());
|
||||||
|
if asset.is_some() {
|
||||||
|
let selection = asset.unwrap();
|
||||||
|
ui.collapsing("Node Data", |ui| {
|
||||||
|
let mut trans = {
|
||||||
|
if selection.default_pose_positions.contains_key(&selection_name) {
|
||||||
|
selection.default_pose_positions.get(&selection_name).unwrap().clone()
|
||||||
|
} else {
|
||||||
|
Transform::IDENTITY
|
||||||
|
}
|
||||||
|
}.clone();
|
||||||
|
ui.label("Position");
|
||||||
|
editable_vec3(ui, &mut trans.translation);
|
||||||
|
ui.label("Scale");
|
||||||
|
editable_vec3(ui, &mut trans.scale);
|
||||||
|
ui.label("Rotation");
|
||||||
|
editable_quat(ui, &mut trans.rotation);
|
||||||
|
|
||||||
|
selection.default_pose_positions.insert(selection_name, trans);
|
||||||
|
structure.has_changed_since_last_save = true;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !is_committed {
|
if ui.button("Edit Structure of Node").clicked() {
|
||||||
count.push((color.clone(), 1));
|
let selection = shared_ui_state.selected_structure_element.clone();
|
||||||
}
|
let mut should_close = false;
|
||||||
}
|
if let PopupWindowMode::EditStructureElement(_, val, _) =
|
||||||
count.sort_by(|a, b| b.1.cmp(&a.1));
|
&shared_ui_state.popup
|
||||||
if !count.is_empty() {
|
{
|
||||||
ui.label(each.path.clone());
|
if val == &selection {
|
||||||
ui.horizontal_wrapped(|ui| {
|
should_close = true;
|
||||||
for (color, count) in count {
|
|
||||||
let button = egui::Button::new(count.to_string())
|
|
||||||
.fill(egui_color_from(color));
|
|
||||||
if ui.add(button).clicked() {
|
|
||||||
color_to_set = Some(color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
if should_close {
|
||||||
|
shared_ui_state.popup = PopupWindowMode::None;
|
||||||
|
} else {
|
||||||
|
shared_ui_state.popup = PopupWindowMode::EditStructureElement(
|
||||||
|
shared_ui_state.selected_structure.clone(),
|
||||||
|
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, &selection, &mut string_selection);
|
||||||
|
shared_ui_state.selected_structure_element = string_selection;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(color) = color_to_set {
|
if ui.button("Save Any Changes").clicked() {
|
||||||
shared_ui_state.brush_color = egui_color_from(color);
|
for each in &mut shared_ui_state.grids {
|
||||||
}
|
if each.has_changed_since_last_save {
|
||||||
if ui.button("Add Origin Voxel").clicked() {
|
let handle = each.id.clone();
|
||||||
//
|
let path = each.path.clone() + ".vvg";
|
||||||
for pair in &mut pairs.handles {
|
let asset = grid_assets.get(handle);
|
||||||
let id = pair.oct_handle.clone();
|
if asset.is_some() {
|
||||||
let tree = grid_assets.get_mut(id);
|
let result =
|
||||||
if tree.is_some() {
|
crate::vvlib::s_oct_asset::serialization::meshes::write_latest_version(
|
||||||
let tree = tree.unwrap();
|
&path,
|
||||||
{
|
asset.unwrap(),
|
||||||
let mut eoct = tree.model.write().unwrap();
|
|
||||||
eoct.set_voxel_at_location(
|
|
||||||
Vec3::ZERO,
|
|
||||||
color_from(shared_ui_state.brush_color),
|
|
||||||
);
|
);
|
||||||
|
if result {
|
||||||
|
each.has_changed_since_last_save = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for each in &mut shared_ui_state.structures {
|
||||||
|
if each.has_changed_since_last_save {
|
||||||
|
let handle = each.id.clone();
|
||||||
|
let path = each.path.clone();
|
||||||
|
let asset = structure_assets.get(handle);
|
||||||
|
if asset.is_some() {
|
||||||
|
let result = crate::vvlib::s_structure_asset::serialization::structures::write_latest_version(&path, asset.unwrap());
|
||||||
|
if result {
|
||||||
|
each.has_changed_since_last_save = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.collapsing("grid assets", |ui| {
|
|
||||||
//
|
|
||||||
for (id, _asset) in (&grid_assets).iter() {
|
|
||||||
let path = asset_server.get_path(id.untyped());
|
|
||||||
if let Some(path) = path {
|
|
||||||
ui.label(path.to_string().as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ui.collapsing("structure assets", |ui| {
|
|
||||||
ui.radio_value(
|
|
||||||
&mut shared_ui_state.selected_structure,
|
|
||||||
"".to_string(),
|
|
||||||
"Deselect",
|
|
||||||
);
|
|
||||||
for (id, _asset) in (&structure_assets).iter() {
|
|
||||||
let path = asset_server.get_path(id.untyped());
|
|
||||||
if let Some(path) = path {
|
|
||||||
//ui.label(path.to_string().as_str());
|
|
||||||
ui.radio_value(
|
|
||||||
&mut shared_ui_state.selected_structure,
|
|
||||||
path.to_string(),
|
|
||||||
path.to_string().as_str(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let mut selected_structure = false;
|
|
||||||
let mut selection = Option::<StringTree>::None;
|
|
||||||
if shared_ui_state.selected_structure != "" {
|
|
||||||
for structure in &shared_ui_state.structures {
|
|
||||||
if structure.path == shared_ui_state.selected_structure {
|
|
||||||
let asset = structure_assets.get_mut(structure.id.clone());
|
|
||||||
if asset.is_some() {
|
|
||||||
selection = Some(asset.unwrap().layout.clone());
|
|
||||||
selected_structure = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if selected_structure {
|
|
||||||
let selection = selection.unwrap();
|
|
||||||
ui.collapsing("Model Structure", |ui| {
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
if ui.button("add element").clicked() {
|
|
||||||
shared_ui_state.popup = PopupWindowMode::CreateStructureElement(
|
|
||||||
shared_ui_state.selected_structure.clone(),
|
|
||||||
"unnamed".to_owned(),
|
|
||||||
"".to_owned(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ui.separator();
|
|
||||||
if shared_ui_state.selected_structure_element != "" {
|
|
||||||
let structure_name = shared_ui_state.selected_structure.clone();
|
|
||||||
let selection_name = shared_ui_state.selected_structure_element.clone();
|
|
||||||
for structure in &mut shared_ui_state.structures {
|
|
||||||
if structure.path == structure_name {
|
|
||||||
let asset = structure_assets.get_mut(structure.id.clone());
|
|
||||||
if asset.is_some() {
|
|
||||||
let selection = asset.unwrap();
|
|
||||||
ui.collapsing("Node Data", |ui| {
|
|
||||||
let mut trans = {
|
|
||||||
if selection.default_pose_positions.contains_key(&selection_name) {
|
|
||||||
selection.default_pose_positions.get(&selection_name).unwrap().clone()
|
|
||||||
} else {
|
|
||||||
Transform::IDENTITY
|
|
||||||
}
|
|
||||||
}.clone();
|
|
||||||
ui.label("Position");
|
|
||||||
editable_vec3(ui, &mut trans.translation);
|
|
||||||
ui.label("Scale");
|
|
||||||
editable_vec3(ui, &mut trans.scale);
|
|
||||||
ui.label("Rotation");
|
|
||||||
editable_quat(ui, &mut trans.rotation);
|
|
||||||
|
|
||||||
selection.default_pose_positions.insert(selection_name, trans);
|
|
||||||
structure.has_changed_since_last_save = true;
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ui.button("Edit Structure of Node").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.clone(),
|
|
||||||
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, &selection, &mut string_selection);
|
|
||||||
shared_ui_state.selected_structure_element = string_selection;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if ui.button("Save Any Changes").clicked() {
|
|
||||||
for each in &mut shared_ui_state.grids {
|
|
||||||
if each.has_changed_since_last_save {
|
|
||||||
let handle = each.id.clone();
|
|
||||||
let path = each.path.clone() + ".vvg";
|
|
||||||
let asset = grid_assets.get(handle);
|
|
||||||
if asset.is_some() {
|
|
||||||
let result =
|
|
||||||
crate::vvlib::s_oct_asset::serialization::meshes::write_latest_version(
|
|
||||||
&path,
|
|
||||||
asset.unwrap(),
|
|
||||||
);
|
|
||||||
if result {
|
|
||||||
each.has_changed_since_last_save = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for each in &mut shared_ui_state.structures {
|
|
||||||
if each.has_changed_since_last_save {
|
|
||||||
let handle = each.id.clone();
|
|
||||||
let path = each.path.clone();
|
|
||||||
let asset = structure_assets.get(handle);
|
|
||||||
if asset.is_some() {
|
|
||||||
let result = crate::vvlib::s_structure_asset::serialization::structures::write_latest_version(&path, asset.unwrap());
|
|
||||||
if result {
|
|
||||||
each.has_changed_since_last_save = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
show_popup(
|
show_popup(
|
||||||
&mut shared_ui_state,
|
&mut shared_ui_state,
|
||||||
&mut contexts,
|
&mut contexts,
|
||||||
&mut asset_server,
|
&mut asset_server,
|
||||||
&mut structure_assets,
|
&mut structure_assets,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue