From 6a8bc840b4aaa351883c51d94e3bbbc22cc834da Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Thu, 3 Apr 2025 13:45:49 +0200 Subject: [PATCH] add bindings (default qwerty + asdfgh) for the tile tools --- CHANGELOG.md | 3 +- README.md | 2 +- src/editor.rs | 90 ++++++++++++++++++++++++++++++++------------------- src/input.rs | 27 +++++++++++++++- src/ui.rs | 5 ++- 5 files changed, 89 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b42b962..65ded18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ Game store page: https://crispypin.itch.io/marble-machinations ## [Unreleased] ### added -- configurable key bindings for the basic editor actions +- configurable key bindings for many editor actions +- QWERTY+ASDFGH keybindings for the tile tools - OS clipboard copy/paste, with fallback to old behavior when copying - in-grid text comments (not yet editable in-game) - changelog file diff --git a/README.md b/README.md index 53dae80..2f92f82 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble #### undecided - option to use 8-bit marbles? - blueprint rotation? -- changable marble start direction? +- settable marble start direction? ## playtesting observations - 'loops' introduces too many things (powering, redirection, generating zeroes) diff --git a/src/editor.rs b/src/editor.rs index ea6b14c..7820d57 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -523,7 +523,6 @@ impl Editor { if globals.is_pressed(ActionId::CycleGroup) { if globals.is_held(ActionId::CycleGroupRevMod) { - println!("rotate reverse"); match &self.active_tool { Tool::Math => self.tool_math.prev(), Tool::Comparator => self.tool_comparator.prev(), @@ -533,7 +532,6 @@ impl Editor { _ => (), } } else { - println!("rotate"); match &self.active_tool { Tool::Math => self.tool_math.next(), Tool::Comparator => self.tool_comparator.next(), @@ -545,12 +543,14 @@ impl Editor { } } - if rl.is_key_pressed(KeyboardKey::KEY_N) { - self.machine.subtick_index += 1; - self.machine.subtick_index %= self.machine.debug_subticks.len(); - } - if rl.is_key_pressed(KeyboardKey::KEY_M) { - self.machine.subtick_index = self.machine.subtick_index.saturating_sub(1); + if !self.machine.debug_subticks.is_empty() { + if rl.is_key_pressed(KeyboardKey::KEY_N) { + self.machine.subtick_index += 1; + self.machine.subtick_index %= self.machine.debug_subticks.len(); + } + if rl.is_key_pressed(KeyboardKey::KEY_M) { + self.machine.subtick_index = self.machine.subtick_index.saturating_sub(1); + } } if self.sim_state == SimState::Editing { @@ -1062,39 +1062,44 @@ impl Editor { draw_scaled_texture(d, globals.get_tex("eraser"), 236, y + 4, 2.); } - let mut tool_button = - |(row, col): (i32, i32), texture: &str, tooltip: &'static str, tool_option: Tool| { - let border = 4.; - let gap = 2.; - let button_size = 32. + border * 2.; - let grid_size = button_size + gap * 2.; - let pos = Vector2 { - x: 100. + col as f32 * grid_size - if col < 0 { 10. } else { 0. }, - y: footer_top + 5. + row as f32 * grid_size, - }; - self.tooltip.add_rec( - Rectangle::new(pos.x, pos.y, button_size, button_size), - tooltip, - ); - scrollable_texture_option_button( - (d, &self.mouse), - pos, - globals.get_tex(texture), - tool_option, - &mut self.active_tool, - border, - ) + let mut tool_button = |(row, col): (i32, i32), + texture: &str, + tooltip: &'static str, + tool_option: Tool, + action: Option| { + let border = 4.; + let gap = 2.; + let button_size = 32. + border * 2.; + let grid_size = button_size + gap * 2.; + let pos = Vector2 { + x: 100. + col as f32 * grid_size - if col < 0 { 10. } else { 0. }, + y: footer_top + 5. + row as f32 * grid_size, }; - tool_button((0, -2), "eraser", "Eraser", Tool::Erase); + self.tooltip.add_rec( + Rectangle::new(pos.x, pos.y, button_size, button_size), + tooltip, + ); + scrollable_texture_option_button( + (d, &self.mouse), + pos, + globals.get_tex(texture), + tool_option, + &mut self.active_tool, + border, + action.map(|a| globals.is_pressed(a)).unwrap_or(false), + ) + }; + tool_button((0, -2), "eraser", "Eraser", Tool::Erase, None); tool_button( (1, -2), "selection", "Select", Tool::SelectArea(Selection::default()), + None, ); - tool_button((0, -1), "blueprint", "Blueprints", Tool::Blueprint); - tool_button((1, -1), "transparent", "None", Tool::None); + tool_button((0, -1), "blueprint", "Blueprints", Tool::Blueprint, None); + tool_button((1, -1), "transparent", "None", Tool::None, None); if !hide_tile_tools { tool_button( @@ -1102,44 +1107,57 @@ impl Editor { "block", "Block", Tool::SetTile(Tile::from_char('#')), + Some(ActionId::TileBlock), ); tool_button( (0, 1), "silo_off", "Silo", Tool::SetTile(Tile::from_char('B')), + Some(ActionId::TileSilo), ); tool_button( (0, 2), "button_off", "Button", Tool::SetTile(Tile::from_char('*')), + Some(ActionId::TileButton), ); tool_button( (0, 3), "io_tile_off", "Input/Output silo", Tool::SetTile(Tile::from_char('I')), + Some(ActionId::TileIOSilo), ); tool_button( (0, 4), "flipper_off", "Flipper", Tool::SetTile(Tile::from_char('F')), + Some(ActionId::TileFlipper), + ); + tool_button( + (0, 5), + "digit_tool", + "Digit", + Tool::Digits(None), + Some(ActionId::TileDigit), ); - tool_button((0, 5), "digit_tool", "Digit", Tool::Digits(None)); tool_button( (1, 0), "marble", "Marble", Tool::SetTile(Tile::from_char('o')), + Some(ActionId::TileMarble), ); match tool_button( (1, 1), self.tool_wire.texture_name_off(), self.tool_wire.human_name(), Tool::Wire, + Some(ActionId::TileGroupWire), ) { Some(Scroll::Down) => self.tool_wire.next(), Some(Scroll::Up) => self.tool_wire.prev(), @@ -1151,6 +1169,7 @@ impl Editor { self.tool_arrow.arrow_tile_texture_name(), self.tool_arrow.arrow_tile_human_name(), Tool::Arrow, + Some(ActionId::TileGroupArrow), ) { Some(Scroll::Down) => self.tool_arrow = self.tool_arrow.right(), Some(Scroll::Up) => self.tool_arrow = self.tool_arrow.left(), @@ -1161,6 +1180,7 @@ impl Editor { self.tool_mirror.texture_name(), self.tool_mirror.human_name(), Tool::Mirror, + Some(ActionId::TileGroupMirror), ) .is_some() { @@ -1171,6 +1191,7 @@ impl Editor { self.tool_math.texture_name_off(), self.tool_math.human_name(), Tool::Math, + Some(ActionId::TileGroupMath), ) { Some(Scroll::Down) => self.tool_math.next(), Some(Scroll::Up) => self.tool_math.prev(), @@ -1181,6 +1202,7 @@ impl Editor { self.tool_comparator.texture_name_off(), self.tool_comparator.human_name(), Tool::Comparator, + Some(ActionId::TileGroupCompare), ) { Some(Scroll::Down) => self.tool_comparator.next(), Some(Scroll::Up) => self.tool_comparator.prev(), diff --git a/src/input.rs b/src/input.rs index 5f99347..c74de9b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -28,6 +28,19 @@ pub enum ActionId { StepSim, CycleGroup, CycleGroupRevMod, + + TileBlock, + TileSilo, + TileButton, + TileIOSilo, + TileFlipper, + TileDigit, + TileMarble, + TileGroupWire, + TileGroupArrow, + TileGroupMirror, + TileGroupMath, + TileGroupCompare, // just like in C, because this way doesn't need more dependencies _EnumSize, } @@ -51,8 +64,20 @@ impl Default for Input { bind_key(ActionId::StartSim, vec![], Enter); bind_key(ActionId::StopSim, vec![], Enter); bind_key(ActionId::StepSim, vec![], Space); - bind_key(ActionId::CycleGroup, vec![], R); + bind_key(ActionId::CycleGroup, vec![], Tab); bind_key(ActionId::CycleGroupRevMod, vec![], LShift); + bind_key(ActionId::TileBlock, vec![], Q); + bind_key(ActionId::TileSilo, vec![], W); + bind_key(ActionId::TileButton, vec![], E); + bind_key(ActionId::TileIOSilo, vec![], R); + bind_key(ActionId::TileFlipper, vec![], T); + bind_key(ActionId::TileDigit, vec![], Y); + bind_key(ActionId::TileMarble, vec![], A); + bind_key(ActionId::TileGroupWire, vec![], S); + bind_key(ActionId::TileGroupArrow, vec![], D); + bind_key(ActionId::TileGroupMirror, vec![], F); + bind_key(ActionId::TileGroupMath, vec![], G); + bind_key(ActionId::TileGroupCompare, vec![], H); Self { bindings, diff --git a/src/ui.rs b/src/ui.rs index e211105..32c80f0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -304,6 +304,7 @@ pub fn scrollable_texture_option_button( option: T, current: &mut T, border: f32, + clicked_override: bool, ) -> Option where T: PartialEq, @@ -329,7 +330,9 @@ where 32. / texture.width as f32, Color::WHITE, ); - if mouse.is_over(bounds) { + if clicked_override { + *current = option; + } else if mouse.is_over(bounds) { if mouse.left_click() { *current = option; }