Compare commits
No commits in common. "11fd29c9c60ada37837e5ad800449bf42dcd81ca" and "7800e8d5fe5e99a00d8cc6eec352cc5da5f44654" have entirely different histories.
11fd29c9c6
...
7800e8d5fe
1 changed files with 7 additions and 51 deletions
58
src/input.rs
58
src/input.rs
|
@ -103,6 +103,7 @@ type InputMap = BTreeMap<ActionId, Vec<Binding>>;
|
|||
pub struct Input {
|
||||
bindings: [Vec<Binding>; ActionId::SIZE],
|
||||
states: [BindingState; ActionId::SIZE],
|
||||
#[serde(skip)]
|
||||
editing_binding: Option<(ActionId, usize, BindingEdit)>,
|
||||
}
|
||||
|
||||
|
@ -140,17 +141,6 @@ 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") {
|
||||
|
@ -162,15 +152,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, 408, 128);
|
||||
let border = screen_centered_rect(d, 368, 128);
|
||||
d.draw_rectangle_rec(border, BG_LIGHT);
|
||||
let bounds = screen_centered_rect(d, 400, 120);
|
||||
let bounds = screen_centered_rect(d, 360, 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 + 10,
|
||||
x + 5,
|
||||
y + 5,
|
||||
20,
|
||||
Color::WHITE,
|
||||
|
@ -228,17 +218,6 @@ 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 {
|
||||
|
@ -295,29 +274,6 @@ 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;
|
||||
|
||||
|
@ -330,7 +286,7 @@ impl ActionId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Binding {
|
||||
modifiers: Vec<Button>,
|
||||
trigger: Button,
|
||||
|
@ -339,8 +295,8 @@ pub struct Binding {
|
|||
impl From<InputMap> for Input {
|
||||
fn from(value: InputMap) -> Self {
|
||||
let mut new = Self::default();
|
||||
for (action, loaded_bindings) in value {
|
||||
new.bindings[action as usize] = loaded_bindings;
|
||||
for (action, saved_bindings) in value {
|
||||
new.bindings[action as usize] = saved_bindings;
|
||||
}
|
||||
new
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue