show input conflicts in binding menu
This commit is contained in:
parent
3fdcb50694
commit
11fd29c9c6
1 changed files with 49 additions and 4 deletions
53
src/input.rs
53
src/input.rs
|
@ -140,6 +140,17 @@ impl Input {
|
|||
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);
|
||||
let conflicts = conflicts(&self.bindings, binding, action);
|
||||
if !conflicts.is_empty() {
|
||||
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;
|
||||
}
|
||||
if text_button(d, &globals.mouse, buttons_x, y, 130, "add binding") {
|
||||
|
@ -151,15 +162,15 @@ impl Input {
|
|||
|
||||
if let Some((action, binding_index, edit_state)) = &mut self.editing_binding {
|
||||
globals.mouse.update(d);
|
||||
let border = screen_centered_rect(d, 368, 128);
|
||||
let border = screen_centered_rect(d, 408, 128);
|
||||
d.draw_rectangle_rec(border, BG_LIGHT);
|
||||
let bounds = screen_centered_rect(d, 360, 120);
|
||||
let bounds = screen_centered_rect(d, 400, 120);
|
||||
d.draw_rectangle_rec(bounds, BG_DARK);
|
||||
let x = bounds.x as i32;
|
||||
let y = bounds.y as i32;
|
||||
d.draw_text(
|
||||
&format!("editing binding for {action:?}"),
|
||||
x + 5,
|
||||
x + 10,
|
||||
y + 5,
|
||||
20,
|
||||
Color::WHITE,
|
||||
|
@ -217,6 +228,17 @@ impl Input {
|
|||
};
|
||||
let text = format!("{:?} + {:?}", b.modifiers, b.trigger);
|
||||
d.draw_text(&text, x + 5, y + 5, 20, colour);
|
||||
|
||||
let conflicts = conflicts(&self.bindings, b, *action);
|
||||
if !conflicts.is_empty() {
|
||||
d.draw_text(
|
||||
&format!("conflicts: {conflicts:?}"),
|
||||
x + 200,
|
||||
y + 40,
|
||||
20,
|
||||
Color::ORANGERED,
|
||||
);
|
||||
}
|
||||
}
|
||||
if text_button(d, &globals.mouse, ok_btn_x, ok_btn_y, ok_btn_width, "ok") {
|
||||
if let BindingEdit::Releasing(binding) = edit_state {
|
||||
|
@ -273,6 +295,29 @@ impl Input {
|
|||
}
|
||||
}
|
||||
|
||||
fn conflicts(
|
||||
bindings: &[Vec<Binding>; ActionId::SIZE],
|
||||
search: &Binding,
|
||||
skip: ActionId,
|
||||
) -> Vec<ActionId> {
|
||||
let mut matches = Vec::new();
|
||||
|
||||
for i in 0..ActionId::SIZE {
|
||||
if skip as usize == i {
|
||||
continue;
|
||||
}
|
||||
let bindings = &bindings[i];
|
||||
for binding in bindings {
|
||||
if binding == search {
|
||||
matches.push(ActionId::from_usize(i).unwrap());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matches
|
||||
}
|
||||
|
||||
impl ActionId {
|
||||
pub const SIZE: usize = Self::_EnumSize as usize;
|
||||
|
||||
|
@ -285,7 +330,7 @@ impl ActionId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Binding {
|
||||
modifiers: Vec<Button>,
|
||||
trigger: Button,
|
||||
|
|
Loading…
Add table
Reference in a new issue