Skip to content

Commit

Permalink
Add hotkeys for adding Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Froggy618157725 committed Jul 25, 2024
1 parent bf6b934 commit 1f2d085
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions crates/alkahest/src/gui/hotkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub const SHORTCUT_MAP_PREV: egui::KeyboardShortcut =
pub const SHORTCUT_MAP_NEXT: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::PageDown);

pub const SHORTCUT_ADD_ROUTE_NODE_NEXT: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::Plus);

pub const SHORTCUT_ADD_ROUTE_NODE_PREV: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(egui::Modifiers::NONE, egui::Key::Minus);

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
12 changes: 10 additions & 2 deletions crates/alkahest/src/gui/inspector/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use egui::{
use hecs::EntityRef;

use crate::{
gui::inspector::ComponentPanel,
gui::{
hotkeys::{SHORTCUT_ADD_ROUTE_NODE_NEXT, SHORTCUT_ADD_ROUTE_NODE_PREV},
inspector::ComponentPanel,
},
input_float3,
resources::Resources,
util::action::{ActionList, FollowAction},
Expand Down Expand Up @@ -398,8 +401,9 @@ impl ComponentPanel for Route {
ui.horizontal(|ui| {
if ui
.button(format!("{}", ICON_MAP_MARKER_PLUS))
.on_hover_text("Add Node")
.on_hover_text("Hotkey: +")
.clicked()
|| ui.input_mut(|i| i.consume_shortcut(&SHORTCUT_ADD_ROUTE_NODE_NEXT))
{
let node = scene.reserve_entity();
cmd.insert(
Expand Down Expand Up @@ -499,7 +503,9 @@ impl ComponentPanel for RouteNode {
ui.horizontal(|ui| {
if ui
.button(format!("{}{}", ICON_ARROW_LEFT, ICON_MAP_MARKER_PLUS))
.on_hover_text("Hotkey: -")
.clicked()
|| ui.input_mut(|i| i.consume_shortcut(&SHORTCUT_ADD_ROUTE_NODE_PREV))
{
if let Some(mut children) = parent.get::<&mut Children>() {
let node = scene.reserve_entity();
Expand Down Expand Up @@ -538,7 +544,9 @@ impl ComponentPanel for RouteNode {
ui.horizontal(|ui| {
if ui
.button(format!("{}{}", ICON_MAP_MARKER_PLUS, ICON_ARROW_RIGHT))
.on_hover_text("Hotkey: +")
.clicked()
|| ui.input_mut(|i| i.consume_shortcut(&SHORTCUT_ADD_ROUTE_NODE_NEXT))
{
if let Some(mut children) = parent.get::<&mut Children>() {
let node = scene.reserve_entity();
Expand Down
21 changes: 18 additions & 3 deletions crates/alkahest/src/gui/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ 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_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_APPLE_KEYBOARD_SHIFT, ICON_ARROW_ALL, 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,
};
use egui::{vec2, Color32, RichText, Vec2};
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
Expand Down Expand Up @@ -323,6 +324,20 @@ impl MenuBar {
control_description!(ui, "Page Up", "Swap to Previous Map in List");

control_description!(ui, "Page Down", "Swap to Next Map in List");

control_section_title!(ui, "Route Editing");

control_description!(
ui,
ICON_PLUS_BOX_OUTLINE,
"Add node at end of route, or after selected node"
);

control_description!(
ui,
ICON_MINUS_BOX_OUTLINE,
"Add node before selected node"
);
});
});
});
Expand Down

0 comments on commit 1f2d085

Please sign in to comment.