mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-02-17 14:40:31 +00:00
Quick Menu: B Button hold fix, update from web menu (#345)
* Fix prev_frame_is_pressed * Update menu when not active * Update lib.rs * Actual fix using frame_counter * Format Rust code using rustfmt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
f948ceec53
commit
71c30990e4
2 changed files with 18 additions and 19 deletions
|
@ -11,17 +11,24 @@ use std::fs;
|
|||
use std::path::Path;
|
||||
|
||||
static mut FRAME_COUNTER_INDEX: usize = 0;
|
||||
pub static mut QUICK_MENU_FRAME_COUNTER_INDEX: usize = 0;
|
||||
const MENU_LOCKOUT_FRAMES: u32 = 15;
|
||||
pub static mut QUICK_MENU_ACTIVE: bool = false;
|
||||
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
FRAME_COUNTER_INDEX = frame_counter::register_counter();
|
||||
QUICK_MENU_FRAME_COUNTER_INDEX = frame_counter::register_counter();
|
||||
write_menu();
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn menu_condition(module_accessor: &mut smash::app::BattleObjectModuleAccessor) -> bool {
|
||||
// also ensure quick menu is reset
|
||||
if frame_counter::get_frame_count(QUICK_MENU_FRAME_COUNTER_INDEX) > 60 {
|
||||
frame_counter::full_reset(QUICK_MENU_FRAME_COUNTER_INDEX);
|
||||
}
|
||||
|
||||
// Only check for button combination if the counter is 0 (not locked out)
|
||||
match frame_counter::get_frame_count(FRAME_COUNTER_INDEX) {
|
||||
0 => {
|
||||
|
@ -93,6 +100,8 @@ pub fn spawn_menu() {
|
|||
unsafe {
|
||||
frame_counter::reset_frame_count(FRAME_COUNTER_INDEX);
|
||||
frame_counter::start_counting(FRAME_COUNTER_INDEX);
|
||||
frame_counter::reset_frame_count(QUICK_MENU_FRAME_COUNTER_INDEX);
|
||||
frame_counter::start_counting(QUICK_MENU_FRAME_COUNTER_INDEX);
|
||||
}
|
||||
|
||||
let mut quick_menu = false;
|
||||
|
@ -156,11 +165,12 @@ impl ButtonPress {
|
|||
}
|
||||
|
||||
pub fn read_press(&mut self) -> bool {
|
||||
let is_pressed = self.is_pressed;
|
||||
if self.is_pressed {
|
||||
self.is_pressed = false;
|
||||
if !self.prev_frame_is_pressed && self.lockout_frames == 0 {
|
||||
self.lockout_frames = 10;
|
||||
if self.lockout_frames == 0 {
|
||||
self.prev_frame_is_pressed = true;
|
||||
self.lockout_frames = 10;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -169,26 +179,11 @@ impl ButtonPress {
|
|||
self.lockout_frames -= 1;
|
||||
}
|
||||
|
||||
self.prev_frame_is_pressed = self.is_pressed;
|
||||
self.prev_frame_is_pressed = is_pressed;
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl ButtonPresses {
|
||||
pub fn default() -> ButtonPresses {
|
||||
ButtonPresses {
|
||||
a: ButtonPress::default(),
|
||||
b: ButtonPress::default(),
|
||||
zr: ButtonPress::default(),
|
||||
zl: ButtonPress::default(),
|
||||
left: ButtonPress::default(),
|
||||
right: ButtonPress::default(),
|
||||
up: ButtonPress::default(),
|
||||
down: ButtonPress::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub static mut BUTTON_PRESSES: ButtonPresses = ButtonPresses {
|
||||
a: ButtonPress {
|
||||
prev_frame_is_pressed: false,
|
||||
|
|
|
@ -28,6 +28,7 @@ use skyline::libc::{c_char, mkdir};
|
|||
use skyline::nro::{self, NroInfo};
|
||||
use std::fs;
|
||||
|
||||
use crate::training::frame_counter;
|
||||
use owo_colors::OwoColorize;
|
||||
use training_mod_consts::OnOff;
|
||||
use training_mod_tui::Color;
|
||||
|
@ -170,7 +171,9 @@ pub fn main() {
|
|||
received_input = true;
|
||||
if !app.outer_list {
|
||||
app.on_b()
|
||||
} else if !b_prev_press {
|
||||
} else if frame_counter::get_frame_count(menu::QUICK_MENU_FRAME_COUNTER_INDEX)
|
||||
== 0
|
||||
{
|
||||
// Leave menu.
|
||||
menu::QUICK_MENU_ACTIVE = false;
|
||||
crate::menu::set_menu_from_url(url.as_str());
|
||||
|
@ -209,6 +212,7 @@ pub fn main() {
|
|||
}
|
||||
has_slept_millis = 16;
|
||||
if !menu::QUICK_MENU_ACTIVE {
|
||||
app = training_mod_tui::App::new(crate::common::consts::get_menu());
|
||||
set_should_display_text_to_screen(false);
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue