add scrolling to config menu, use new input system for tile group cycling

This commit is contained in:
Crispy 2025-04-03 00:44:34 +02:00
parent 8d81f94b70
commit d62dbe3462
4 changed files with 51 additions and 41 deletions

View file

@ -26,6 +26,8 @@ pub enum ActionId {
StartSim,
StopSim,
StepSim,
CycleGroup,
CycleGroupRevMod,
// just like in C, because this way doesn't need more dependencies
_EnumSize,
}
@ -49,11 +51,13 @@ 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::CycleGroupRevMod, vec![], LShift);
Self {
bindings,
states: Default::default(),
editing_input: None,
editing_binding: None,
}
}
}
@ -75,7 +79,7 @@ pub struct Input {
bindings: [Vec<Binding>; ActionId::SIZE],
states: [BindingState; ActionId::SIZE],
#[serde(skip)]
editing_input: Option<(ActionId, usize, BindingEdit)>,
editing_binding: Option<(ActionId, usize, BindingEdit)>,
}
#[derive(Clone, Debug)]
@ -86,9 +90,9 @@ enum BindingEdit {
}
impl Input {
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals) {
let mut y = 96;
if self.editing_input.is_some() {
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals, y: i32) {
let mut y = y + 96;
if self.editing_binding.is_some() {
globals.mouse.clear();
}
@ -105,7 +109,7 @@ impl Input {
return;
}
if text_button(d, &globals.mouse, 245, y, 45, "edit") {
self.editing_input = Some((action, binding_index, BindingEdit::Init));
self.editing_binding = Some((action, binding_index, BindingEdit::Init));
}
let trigger = format!("{:?}", binding.trigger);
d.draw_text(&trigger, 300, y, 20, Color::LIMEGREEN);
@ -115,13 +119,13 @@ impl Input {
y += 32;
}
if text_button(d, &globals.mouse, 160, y, 130, "add binding") {
self.editing_input =
self.editing_binding =
Some((action, self.bindings[action_index].len(), BindingEdit::Init));
}
y += 45;
}
if let Some((action, binding_index, edit_state)) = &mut self.editing_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);
d.draw_rectangle_rec(border, BG_LIGHT);
@ -198,11 +202,11 @@ impl Input {
} else {
binding_list.push(binding.clone());
}
self.editing_input = None;
self.editing_binding = None;
}
}
if text_button(d, &globals.mouse, x + 100, y + 40, 80, "cancel") {
self.editing_input = None;
self.editing_binding = None;
}
}
}