diff --git a/src/common/menu.rs b/src/common/menu.rs index cb2b1f4..f955777 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -6,6 +6,17 @@ use smash::lib::lua_const::*; use skyline_web::{Background, BootDisplay, Webpage}; use ramhorns::{Template, Content}; use strum::IntoEnumIterator; +use crate::training::frame_counter; + +static mut FRAME_COUNTER_INDEX: usize = 0; +const MENU_LOCKOUT_FRAMES: u32 = 5; + +pub fn init() { + unsafe { + FRAME_COUNTER_INDEX = frame_counter::register_counter(); + } +} + #[derive(Content)] struct Slider { @@ -245,8 +256,19 @@ pub fn set_menu_from_url(s: &str) { } pub unsafe fn menu_condition(module_accessor: &mut smash::app::BattleObjectModuleAccessor) -> bool { - ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_SPECIAL) && - ControlModule::check_button_on_trriger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI) + // Only check for button combination if the counter is 0 (not locked out) + match frame_counter::get_frame_count(FRAME_COUNTER_INDEX) { + 0 => { + ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_SPECIAL) && + ControlModule::check_button_on_trriger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI) + }, + 1..MENU_LOCKOUT_FRAMES => false, + _ => { + // Waited longer than the lockout time, reset the counter so the menu can be opened again + frame_counter::full_reset(FRAME_COUNTER_INDEX); + false + } + } } pub unsafe fn write_menu() { @@ -318,6 +340,8 @@ pub unsafe fn write_menu() { } pub unsafe fn spawn_menu() { + frame_counter::reset_frame_count(FRAME_COUNTER_INDEX); + frame_counter::start_counting(FRAME_COUNTER_INDEX); let fname = "training_menu.html"; let params = MENU.to_url_params(); let page_response = Webpage::new() diff --git a/src/training/mod.rs b/src/training/mod.rs index c727ba6..21cd812 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -12,12 +12,12 @@ pub mod sdi; pub mod shield; pub mod tech; pub mod ledge; +pub mod frame_counter; mod air_dodge_direction; mod attack_angle; mod character_specific; mod fast_fall; -mod frame_counter; mod full_hop; mod input_delay; mod input_record;