Skip to content

Commit

Permalink
fix undo redo controls
Browse files Browse the repository at this point in the history
  • Loading branch information
ziloka committed Nov 8, 2023
1 parent ffeef42 commit f45daa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 44 deletions.
16 changes: 2 additions & 14 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,12 @@ impl Input {
} else if is_key_pressed(self.settings.controls.restart) {
board.restart(now() as usize);
self.history.add_state(board.clone());
} else if self
.settings
.controls
.undo
.iter()
.all(|k| is_key_pressed(*k))
{
} else if is_key_pressed(self.settings.controls.undo) {
if let Some(new_board) = self.history.undo() {
*board = new_board;
}
}
if self
.settings
.controls
.redo
.iter()
.all(|k| is_key_pressed(*k))
{
if is_key_pressed(self.settings.controls.redo) {
if let Some(new_board) = self.history.redo() {
*board = new_board;
}
Expand Down
38 changes: 8 additions & 30 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct Controls {
pub rotate_180: KeyCode,
pub hold: KeyCode,
pub restart: KeyCode,
pub undo: Vec<KeyCode>,
pub redo: Vec<KeyCode>,
pub undo: KeyCode,
pub redo: KeyCode,
}

enum FocusedOn {
Expand Down Expand Up @@ -68,8 +68,8 @@ impl Default for Settings {
rotate_180: KeyCode::A,
hold: KeyCode::C,
restart: KeyCode::R,
undo: vec![KeyCode::F4],
redo: vec![KeyCode::F5],
undo: KeyCode::F4,
redo: KeyCode::F5,
},
focused_on: None,
subscriber_id: register_input_subscriber(),
Expand Down Expand Up @@ -135,32 +135,10 @@ impl Settings {
if ui.button(None, format!("Restart: {:?}", self.controls.restart)) {
self.focused_on = Some(FocusedOn::Restart);
}
if ui.button(
None,
format!(
"Undo: {:?}",
self.controls
.undo
.iter()
.map(|s| format!("{:?}", s))
.collect::<Vec<String>>()
.join(" + ")
),
) {
if ui.button(None, format!("Undo: {:?}", self.controls.undo)) {
self.focused_on = Some(FocusedOn::Undo);
}
if ui.button(
None,
format!(
"Redo: {:?}",
self.controls
.redo
.iter()
.map(|s| format!("{:?}", s))
.collect::<Vec<String>>()
.join(" + ")
),
) {
if ui.button(None, format!("Redo: {:?}", self.controls.redo)) {
self.focused_on = Some(FocusedOn::Redo);
}
if let Some(focused_on) = &self.focused_on {
Expand Down Expand Up @@ -203,10 +181,10 @@ impl Settings {
self.focused_on = None
}
FocusedOn::Undo => {
self.controls.undo.push(keycode);
self.controls.undo = keycode;
}
FocusedOn::Redo => {
self.controls.redo.push(keycode);
self.controls.redo = keycode;
}
}
}
Expand Down

0 comments on commit f45daa8

Please sign in to comment.