Skip to content

Commit

Permalink
Done unhide all functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Liby99 committed Oct 10, 2019
1 parent d415e6a commit ba8f68d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() {
.with(interactions::remove::RemoveSelectedViaDelete, "remove_selected_via_delete", &[])
.with(interactions::create::line::AbortCreateLineViaKeyboard, "abort_create_line_via_keyboard", &[])
.with(interactions::hide::HideSelectedViaKeyboard, "hide_selected_via_keyboard", &[])
.with(interactions::hide::UnhideAllViaKeyboard, "unhide_all_via_keyboard", &[])
.with(interactions::history::UndoViaKeyboard, "undo_via_keyboard", &[])
.with(interactions::history::RedoViaKeyboard, "redo_via_keyboard", &[])

Expand All @@ -58,6 +59,7 @@ fn main() {
.with(geometry_actions::SeldeAllHandler::default(), "selde_all_handler", &["selde_all_via_keyboard", "selde_via_mouse"])
.with(geometry_actions::RemoveSelectedHandler::default(), "remove_selected_handler", &["remove_selected_via_delete", "dependency_graph_cache"])
.with(geometry_actions::HideSelectedHandler::default(), "hide_selected_handler", &["hide_selected_via_keyboard"])
.with(geometry_actions::UnhideAllHandler::default(), "unhide_all_handler", &["unhide_all_via_keyboard"])

// Geometry helpers
.with(interactions::create::point::SnapPointSystem, "snap_point_system", &["spatial_hash_cache", "tool_state_manager", "viewport_state_manager"])
Expand Down
3 changes: 3 additions & 0 deletions src/systems/geometry_actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub use remove_selected_handler::*;
mod hide_selected_handler;
pub use hide_selected_handler::*;

mod unhide_all_handler;
pub use unhide_all_handler::*;

mod selde_all_handler;
pub use selde_all_handler::*;

Expand Down
50 changes: 50 additions & 0 deletions src/systems/geometry_actions/unhide_all_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use specs::prelude::*;
use crate::{
resources::{
events::{
GeometryAction, GeometryActionChannel, GeometryActionReader,
SketchEvent, SketchEventChannel
},
},
components::Hidden,
};

pub struct UnhideAllHandler {
geometry_action_reader: Option<GeometryActionReader>,
}

impl Default for UnhideAllHandler {
fn default() -> Self {
Self { geometry_action_reader: None }
}
}

impl<'a> System<'a> for UnhideAllHandler {
type SystemData = (
Entities<'a>,
Read<'a, GeometryActionChannel>,
Write<'a, SketchEventChannel>,
ReadStorage<'a, Hidden>,
);

fn setup(&mut self, world: &mut World) {
Self::SystemData::setup(world);
self.geometry_action_reader = Some(world.fetch_mut::<GeometryActionChannel>().register_reader());
}

fn run(&mut self, (entities, geometry_actiona_channel, mut sketch_event_channel, hidden): Self::SystemData) {
if let Some(reader_id) = &mut self.geometry_action_reader {
for event in geometry_actiona_channel.read(reader_id) {
match event {
GeometryAction::UnhideAll => {
for (entity, _) in (&entities, &hidden).join() {
sketch_event_channel.single_write(SketchEvent::unhide(entity));
}
break;
},
_ => (),
}
}
}
}
}
5 changes: 4 additions & 1 deletion src/systems/interactions/hide/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
mod hide_selected_via_keyboard;
pub use hide_selected_via_keyboard::*;
pub use hide_selected_via_keyboard::*;

mod unhide_all_via_keyboard;
pub use unhide_all_via_keyboard::*;
23 changes: 23 additions & 0 deletions src/systems/interactions/hide/unhide_all_via_keyboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use specs::prelude::*;
use crate::{
utilities::Key,
resources::{
InputState,
events::{GeometryAction, GeometryActionChannel},
},
};

pub struct UnhideAllViaKeyboard;

impl<'a> System<'a> for UnhideAllViaKeyboard {
type SystemData = (
Read<'a, InputState>,
Write<'a, GeometryActionChannel>,
);

fn run(&mut self, (input_state, mut geometry_action_channel): Self::SystemData) {
if input_state.keyboard.just_activated(Key::H) && input_state.keyboard.is_shift_activated() && input_state.keyboard.is_command_activated() {
geometry_action_channel.single_write(GeometryAction::UnhideAll);
}
}
}

0 comments on commit ba8f68d

Please sign in to comment.