generated from GarandPLG/rust-flake-template
Add GameStates, typed enums, and App::new constructor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::app::{
|
||||
App,
|
||||
App, View,
|
||||
keybindings::{Action, event_to_action},
|
||||
};
|
||||
use ratatui::crossterm::event::KeyEvent;
|
||||
@@ -8,7 +8,35 @@ pub fn main_menu_keybindings(app: &mut App, event: &KeyEvent) {
|
||||
if let Some(action) = event_to_action(&event) {
|
||||
match action {
|
||||
Action::Quit => app.exit = true,
|
||||
_ => (),
|
||||
Action::ScrollUp => {
|
||||
app.game_states.main_menu_state.selected_view = app
|
||||
.game_states
|
||||
.main_menu_state
|
||||
.selected_view
|
||||
.saturating_sub(1)
|
||||
.max(1);
|
||||
}
|
||||
Action::ScrollDown => {
|
||||
app.game_states.main_menu_state.selected_view = app
|
||||
.game_states
|
||||
.main_menu_state
|
||||
.selected_view
|
||||
.saturating_add(1)
|
||||
.min(4);
|
||||
}
|
||||
Action::Select => {
|
||||
let selected_view: usize = app.game_states.main_menu_state.selected_view;
|
||||
|
||||
if selected_view == 1 {
|
||||
app.view = View::Skirmish;
|
||||
} else if selected_view == 2 {
|
||||
app.view = View::PerkDecks;
|
||||
} else if selected_view == 3 {
|
||||
app.view = View::SkillsConfig;
|
||||
} else if selected_view == 4 {
|
||||
app.view = View::Settings;
|
||||
}
|
||||
} // _ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user