diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f243f2..17cb141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,6 @@ Game store page: https://crispypin.itch.io/marble-machinations ## [unreleased] -### fixed -- When two input bindings had the same trigger but one has a strict subset of the others modifiers, both would activate when the one with more modifiers was pressed. For example (Ctrl+S -> Save) would also trigger (S -> Wire Tool). Now, Shift+S will still trigger Wire Tool, unless Shift+S (or eg. Shift+Ctrl+S) is bound to something else. ## v0.3.1 - 2025-04-05 ### fixed diff --git a/src/input.rs b/src/input.rs index bc4241b..4d695b0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -54,7 +54,6 @@ impl Default for Input { let mut bindings = [(); ActionId::SIZE].map(|_| Vec::new()); let mut bind_key = |action, mods, trigger| { bindings[action as usize].push(Binding { - blocking_modifiers: Vec::new(), modifiers: mods, trigger, }); @@ -142,26 +141,21 @@ impl Input { if text_button(d, &globals.mouse, buttons_x + 85, y, 45, "edit") { self.editing_binding = Some((action, binding_index, BindingEdit::Init)); } - // let trigger = format!("{:?}", binding.trigger); - let mut x = binding_text_x; - d.draw_text(&trigger, x, y + 5, 20, Color::LIMEGREEN); - x += 10 + d.measure_text(&trigger, 20); - // + d.draw_text(&trigger, binding_text_x, y + 5, 20, Color::LIMEGREEN); + let x = binding_text_x + 10 + d.measure_text(&trigger, 20); let modifiers = format!("{:?}", binding.modifiers); d.draw_text(&modifiers, x, y + 5, 20, Color::LIGHTBLUE); - x += 10 + d.measure_text(&modifiers, 20); - // let conflicts = conflicts(&self.bindings, binding, action); if !conflicts.is_empty() { - let conflict_text = format!("also used by: {conflicts:?}"); - d.draw_text(&conflict_text, x, y + 5, 20, Color::ORANGERED); - x += 10 + d.measure_text(&conflict_text, 20); - } - // - if !binding.blocking_modifiers.is_empty() { - let blocking_text = format!("not while: {:?}", binding.blocking_modifiers); - d.draw_text(&blocking_text, x, y + 5, 20, Color::GRAY); + let x = x + 10 + d.measure_text(&modifiers, 20); + d.draw_text( + &format!("also used by: {conflicts:?}"), + x, + y + 5, + 20, + Color::ORANGERED, + ); } y += 32; } @@ -199,7 +193,6 @@ impl Input { BindingEdit::Init => { if key.just_pressed(d) { *edit_state = BindingEdit::Adding(Binding { - blocking_modifiers: Vec::new(), modifiers: Vec::new(), trigger: key, }); @@ -225,7 +218,6 @@ impl Input { globals.mouse.is_over(ok_btn_rect) && key == Button::MouseLeft; if key.just_pressed(d) && !clicking_ok { *edit_state = BindingEdit::Adding(Binding { - blocking_modifiers: Vec::new(), modifiers: Vec::new(), trigger: key, }); @@ -263,7 +255,6 @@ impl Input { binding_list.push(binding.clone()); } self.editing_binding = None; - self.update_modifier_blocks(); } } if text_button(d, &globals.mouse, x + 100, y + 40, 80, "cancel") { @@ -277,9 +268,7 @@ impl Input { let bindings = &self.bindings[i]; let mut is_active = false; for binding in bindings { - if binding.modifiers.iter().all(|&m| m.is_down(rl)) - && !binding.blocking_modifiers.iter().any(|&m| m.is_down(rl)) - { + if binding.modifiers.iter().all(|&m| m.is_down(rl)) { is_active |= binding.trigger.is_down(rl); } } @@ -310,33 +299,6 @@ impl Input { pub fn is_released(&self, action: ActionId) -> bool { self.states[action as usize] == BindingState::Released } - - /// Must be called after any binding has changed. - /// Ensures a binding "S" is not triggered by "Ctrl+S", if "Ctrl+S" is bound to something else. - pub fn update_modifier_blocks(&mut self) { - for i in 0..ActionId::SIZE { - let bindings = &self.bindings[i]; - for binding_index in 0..bindings.len() { - let binding = &self.bindings[i][binding_index]; - let mut blocking_mods = Vec::new(); - for i in 0..ActionId::SIZE { - let other_bindings = &self.bindings[i]; - for other_binding in other_bindings { - if other_binding.trigger == binding.trigger { - for modifier in &other_binding.modifiers { - if !blocking_mods.contains(modifier) - && !binding.modifiers.contains(modifier) - { - blocking_mods.push(*modifier); - } - } - } - } - } - self.bindings[i][binding_index].blocking_modifiers = blocking_mods; - } - } - } } fn conflicts( @@ -376,8 +338,6 @@ impl ActionId { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct Binding { - #[serde(skip)] - blocking_modifiers: Vec