Skip to content

Commit

Permalink
Add Arrow Hotkeys for Navigating Heirarchies
Browse files Browse the repository at this point in the history
You can hit up for parent, down for child, and left/right to go through siblings
  • Loading branch information
Froggy618157725 committed Jul 25, 2024
1 parent 1f2d085 commit 68f5662
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
81 changes: 80 additions & 1 deletion crates/alkahest/src/gui/hotkeys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use alkahest_renderer::{
camera::{tween::ease_out_exponential, Camera},
ecs::{common::Hidden, resources::SelectedEntity},
ecs::{
common::Hidden,
hierarchy::{Children, Parent},
resources::SelectedEntity,
},
renderer::RendererShared,
util::scene::SceneExt,
};

use crate::{
Expand Down Expand Up @@ -48,6 +53,18 @@ pub const SHORTCUT_ADD_ROUTE_NODE_NEXT: egui::KeyboardShortcut =
pub const SHORTCUT_ADD_ROUTE_NODE_PREV: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::Minus);

pub const SHORTCUT_SELECT_PARENT: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::ArrowUp);

pub const SHORTCUT_SELECT_CHILD: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::ArrowDown);

pub const SHORTCUT_SELECT_NEXT_CHILD: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::ArrowRight);

pub const SHORTCUT_SELECT_PREV_CHILD: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::ArrowLeft);

pub fn process_hotkeys(ctx: &egui::Context, resources: &mut Resources) {
if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_UNHIDE_ALL)) {
unhide_all(resources);
Expand Down Expand Up @@ -83,6 +100,22 @@ pub fn process_hotkeys(ctx: &egui::Context, resources: &mut Resources) {
if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_GAZE)) {
goto_gaze(resources);
}

if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_SELECT_PARENT)) {
select_parent(resources);
}

if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_SELECT_CHILD)) {
select_child(resources);
}

if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_SELECT_NEXT_CHILD)) {
select_child_offset(resources, true);
}

if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT_SELECT_PREV_CHILD)) {
select_child_offset(resources, false);
}
}

fn hide_unselected(resources: &mut Resources) {
Expand Down Expand Up @@ -126,3 +159,49 @@ fn goto_gaze(resources: &mut Resources) {
));
}
}

fn select_parent(resources: &mut Resources) {
let mut selected = resources.get_mut::<SelectedEntity>();
let mut maps = resources.get_mut::<MapList>();
if let Some(current) = selected.selected() {
if let Some(map) = maps.current_map_mut() {
if let Some(parent) = map.scene.get_parent(current) {
selected.select(parent);
}
}
}
}

fn select_child(resources: &mut Resources) {
let mut selected = resources.get_mut::<SelectedEntity>();
let mut maps = resources.get_mut::<MapList>();
if let Some(current) = selected.selected() {
if let Some(map) = maps.current_map_mut() {
if let Ok(children) = map.scene.get::<&Children>(current) {
selected.select(children.0[0]);
}
}
}
}

fn select_child_offset(resources: &mut Resources, add: bool) {
let mut selected = resources.get_mut::<SelectedEntity>();
let mut maps = resources.get_mut::<MapList>();
if let Some(current) = selected.selected() {
if let Some(map) = maps.current_map_mut() {
if let Some(parent) = map.scene.get_parent(current) {
if let Ok(children) = map.scene.get::<&Children>(parent) {
let i = children
.0
.iter()
.position(|&ent| ent == current)
.unwrap_or(0);
let new_i = if add { i + 1 } else { i - 1 };
if let Some(next) = children.0.get(new_i) {
selected.select(*next);
}
}
}
}
}
}
27 changes: 26 additions & 1 deletion crates/alkahest/src/gui/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use alkahest_renderer::icons::{
ICON_ALPHA_A_BOX_OUTLINE, ICON_ALPHA_D_BOX_OUTLINE, ICON_ALPHA_E_BOX_OUTLINE,
ICON_ALPHA_G_BOX_OUTLINE, ICON_ALPHA_H_BOX_OUTLINE, ICON_ALPHA_I_BOX_OUTLINE,
ICON_ALPHA_Q_BOX_OUTLINE, ICON_ALPHA_S_BOX_OUTLINE, ICON_ALPHA_W_BOX_OUTLINE,
ICON_APPLE_KEYBOARD_SHIFT, ICON_ARROW_ALL, ICON_KEYBOARD_SPACE, ICON_MINUS_BOX_OUTLINE,
ICON_APPLE_KEYBOARD_SHIFT, ICON_ARROW_ALL, ICON_ARROW_DOWN_BOLD_BOX_OUTLINE,
ICON_ARROW_LEFT_BOLD_BOX_OUTLINE, ICON_ARROW_RIGHT_BOLD_BOX_OUTLINE,
ICON_ARROW_UP_BOLD_BOX_OUTLINE, ICON_KEYBOARD_SPACE, ICON_MINUS_BOX_OUTLINE,
ICON_MOUSE_LEFT_CLICK_OUTLINE, ICON_MOUSE_RIGHT_CLICK_OUTLINE, ICON_NUMERIC_1_BOX_OUTLINE,
ICON_NUMERIC_2_BOX_OUTLINE, ICON_NUMERIC_3_BOX_OUTLINE, ICON_NUMERIC_4_BOX_OUTLINE,
ICON_PLUS_BOX_OUTLINE,
Expand Down Expand Up @@ -295,6 +297,29 @@ impl MenuBar {
"Deselect All Objects"
);

control_description!(
ui,
ICON_ARROW_UP_BOLD_BOX_OUTLINE,
"Select Parent"
);

control_description!(
ui,
ICON_ARROW_DOWN_BOLD_BOX_OUTLINE,
"Select First Child"
);

control_description!(
ui,
ICON_ARROW_LEFT_BOLD_BOX_OUTLINE,
"Select Previous Child"
);

control_description!(
ui,
ICON_ARROW_RIGHT_BOLD_BOX_OUTLINE,
"Select Next Child"
);
// control_description!(
// ui,
// format!("{} Shift + Delete", ICON_APPLE_KEYBOARD_SHIFT),
Expand Down

0 comments on commit 68f5662

Please sign in to comment.