diff --git a/assets/test.vvg b/assets/test.vvg index c92f84a..46583f1 100644 --- a/assets/test.vvg +++ b/assets/test.vvg @@ -1,9 +1,16 @@ version 1 -0 0 0|1 0 0 -0 0 1|1 0 0.77999973 -0 0 2|0.0800004 0 1 -0 0 3|0 0.7600002 1 -0 0 4|0 1 0.3399999 -0 0 5|0.5 1 0 -0 0 6|1 0.8399999 0 -0 0 7|1 0.4200003 0 \ No newline at end of file +0 2 -1|1 0.6600001 0 +0 3 -1|1 0.6600001 0 +0 -1 0|1 0.6600001 0 +0 0 0|1 0.6600001 0 +0 1 0|1 0.6600001 0 +0 -1 5|1 0.6600001 0 +0 -1 6|1 0.6600001 0 +0 0 4|1 0.6600001 0 +0 1 4|1 0.6600001 0 +0 0 7|1 0.6600001 0 +0 1 7|1 0.6600001 0 +0 2 1|1 0.6600001 0 +0 3 1|1 0.6600001 0 +0 2 5|1 0.6600001 0 +0 2 6|1 0.6600001 0 \ No newline at end of file diff --git a/src/vvedit/editor_ui.rs b/src/vvedit/editor_ui.rs index e1814fb..cb8fe76 100644 --- a/src/vvedit/editor_ui.rs +++ b/src/vvedit/editor_ui.rs @@ -287,8 +287,8 @@ pub fn edit_window_ui( shared_ui_state.window = pos; } } - response.show(contexts.ctx_mut(), |ui| { + //ui.ctx().set_pixels_per_point(0.1); let mut label = String::from("Pre-Alpha"); use std::fmt::Write; writeln!(label, " Controls:").ok(); @@ -301,6 +301,48 @@ pub fn edit_window_ui( color_picker::Alpha::Opaque, ); ui.label(label); + let mut color_to_set: Option = None; + for each in &shared_ui_state.meshes { + ui.horizontal_wrapped(|ui| { + //color palette clickables. + let handle = each.id.clone(); + let asset = oct_assets.get(handle); + if asset.is_some() { + let list = asset.unwrap().model.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()); + 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 let Some(color) = color_to_set { + shared_ui_state.brush_color = egui_color_from(color); + } if ui.button("Add Origin Voxel").clicked() { // for pair in &mut pairs.handles { @@ -315,7 +357,7 @@ pub fn edit_window_ui( } if ui.button("Save Any Changes").clicked() { //save all files. - for each in &shared_ui_state.meshes { + for each in &mut shared_ui_state.meshes { if each.has_changed_since_last_save { let handle = each.id.clone(); let path = each.path.clone() + ".vvg"; @@ -327,6 +369,7 @@ pub fn edit_window_ui( asset.unwrap(), ); if result { + each.has_changed_since_last_save = false; println!("{} saved to disk.", &path); } }