mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-25 07:46:11 +00:00
Fix softlock
This commit is contained in:
parent
8711ce6ca0
commit
6a1253671d
4 changed files with 155 additions and 36 deletions
src
|
@ -2,7 +2,6 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::common::*;
|
||||
use crate::input::{ControllerStyle::*, *};
|
||||
use crate::training::frame_counter;
|
||||
use crate::training::ui::menu::VANILLA_MENU_ACTIVE;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -50,6 +49,114 @@ pub fn button_mapping(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn name_to_font_glyph(button: ButtonConfig, style: ControllerStyle) -> Option<u16> {
|
||||
let is_gcc = style == ControllerStyle::GCController;
|
||||
Some(match button {
|
||||
ButtonConfig::A => 0xE0E0,
|
||||
// TODO: Find one that works in training...
|
||||
ButtonConfig::B => 0xE0E0,
|
||||
ButtonConfig::X => {
|
||||
if is_gcc {
|
||||
0xE206
|
||||
} else {
|
||||
0xE0E2
|
||||
}
|
||||
}
|
||||
ButtonConfig::Y => {
|
||||
if is_gcc {
|
||||
0xE207
|
||||
} else {
|
||||
0xE0E3
|
||||
}
|
||||
}
|
||||
ButtonConfig::L => {
|
||||
if is_gcc {
|
||||
return None;
|
||||
} else {
|
||||
0xE0E4
|
||||
}
|
||||
}
|
||||
ButtonConfig::R => {
|
||||
if is_gcc {
|
||||
0xE205
|
||||
} else {
|
||||
0xE0E5
|
||||
}
|
||||
}
|
||||
ButtonConfig::ZL => {
|
||||
if is_gcc {
|
||||
0xE204
|
||||
} else {
|
||||
0xE0E6
|
||||
}
|
||||
}
|
||||
ButtonConfig::ZR => {
|
||||
if is_gcc {
|
||||
0xE208
|
||||
} else {
|
||||
0xE0E7
|
||||
}
|
||||
}
|
||||
ButtonConfig::DPAD_UP => {
|
||||
if is_gcc {
|
||||
0xE209
|
||||
} else {
|
||||
0xE079
|
||||
}
|
||||
}
|
||||
ButtonConfig::DPAD_DOWN => {
|
||||
if is_gcc {
|
||||
0xE20A
|
||||
} else {
|
||||
0xE07A
|
||||
}
|
||||
}
|
||||
ButtonConfig::DPAD_LEFT => {
|
||||
if is_gcc {
|
||||
0xE20B
|
||||
} else {
|
||||
0xE07B
|
||||
}
|
||||
}
|
||||
ButtonConfig::DPAD_RIGHT => {
|
||||
if is_gcc {
|
||||
0xE20C
|
||||
} else {
|
||||
0xE07C
|
||||
}
|
||||
}
|
||||
ButtonConfig::PLUS => {
|
||||
if is_gcc {
|
||||
0xE20D
|
||||
} else {
|
||||
0xE0EF
|
||||
}
|
||||
}
|
||||
ButtonConfig::MINUS => {
|
||||
if is_gcc {
|
||||
return None;
|
||||
} else {
|
||||
0xE0F0
|
||||
}
|
||||
}
|
||||
ButtonConfig::LSTICK => {
|
||||
if is_gcc {
|
||||
return None;
|
||||
} else {
|
||||
0xE104
|
||||
}
|
||||
}
|
||||
ButtonConfig::RSTICK => {
|
||||
if is_gcc {
|
||||
return None;
|
||||
} else {
|
||||
0xE105
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, EnumIter, PartialEq, Eq, Hash, Copy, Clone)]
|
||||
pub enum ButtonCombo {
|
||||
OpenMenu,
|
||||
|
@ -137,8 +244,7 @@ pub fn handle_final_input_mapping(player_idx: i32, controller_struct: &mut SomeC
|
|||
let p1_controller = &mut *controller_struct.controller;
|
||||
let mut start_menu_request = false;
|
||||
|
||||
let menu_close_wait_frame =
|
||||
unsafe { frame_counter::get_frame_count(menu::FRAME_COUNTER_INDEX) };
|
||||
let menu_close_wait_frame = unsafe { *menu::VISUAL_FRAME_COUNTER.data_ptr() };
|
||||
if unsafe { MENU.menu_open_start_press == OnOff::On } {
|
||||
let start_hold_frames = &mut *START_HOLD_FRAMES.lock();
|
||||
if p1_controller.current_buttons.plus() {
|
||||
|
|
|
@ -13,18 +13,10 @@ use crate::consts::MENU_OPTIONS_PATH;
|
|||
use crate::events::{Event, EVENT_QUEUE};
|
||||
use crate::input::*;
|
||||
use crate::logging::*;
|
||||
use crate::training::frame_counter;
|
||||
|
||||
pub static mut FRAME_COUNTER_INDEX: usize = 0;
|
||||
pub const MENU_CLOSE_WAIT_FRAMES: u32 = 15;
|
||||
pub static mut QUICK_MENU_ACTIVE: bool = false;
|
||||
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
FRAME_COUNTER_INDEX = frame_counter::register_counter_no_reset();
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn menu_condition() -> bool {
|
||||
button_config::combo_passes_exclusive(button_config::ButtonCombo::OpenMenu)
|
||||
}
|
||||
|
@ -117,6 +109,8 @@ lazy_static! {
|
|||
(RUp, 0),
|
||||
]))
|
||||
};
|
||||
pub static ref VISUAL_FRAME_COUNTER: Mutex<u32> = Mutex::new(0);
|
||||
pub static ref VISUAL_FRAME_COUNTER_SHOULD_COUNT: Mutex<bool> = Mutex::new(false);
|
||||
}
|
||||
|
||||
pub fn handle_final_input_mapping(
|
||||
|
@ -128,19 +122,16 @@ pub fn handle_final_input_mapping(
|
|||
if player_idx == 0 {
|
||||
let p1_controller = &mut *controller_struct.controller;
|
||||
*P1_CONTROLLER_STYLE.lock() = p1_controller.style;
|
||||
if frame_counter::get_frame_count(FRAME_COUNTER_INDEX) > 0
|
||||
&& frame_counter::get_frame_count(FRAME_COUNTER_INDEX) < MENU_CLOSE_WAIT_FRAMES
|
||||
{
|
||||
let visual_frame_count = *VISUAL_FRAME_COUNTER.data_ptr();
|
||||
if visual_frame_count > 0 && visual_frame_count < MENU_CLOSE_WAIT_FRAMES {
|
||||
// If we just closed the menu, kill all inputs to avoid accidental presses
|
||||
*out = MappedInputs::empty();
|
||||
p1_controller.current_buttons = ButtonBitfield::default();
|
||||
p1_controller.previous_buttons = ButtonBitfield::default();
|
||||
p1_controller.just_down = ButtonBitfield::default();
|
||||
p1_controller.just_release = ButtonBitfield::default();
|
||||
} else if frame_counter::get_frame_count(FRAME_COUNTER_INDEX) >= MENU_CLOSE_WAIT_FRAMES
|
||||
{
|
||||
frame_counter::reset_frame_count(FRAME_COUNTER_INDEX);
|
||||
frame_counter::stop_counting(FRAME_COUNTER_INDEX);
|
||||
} else if visual_frame_count >= MENU_CLOSE_WAIT_FRAMES {
|
||||
*VISUAL_FRAME_COUNTER_SHOULD_COUNT.lock() = false;
|
||||
}
|
||||
|
||||
if QUICK_MENU_ACTIVE {
|
||||
|
@ -199,7 +190,7 @@ pub fn handle_final_input_mapping(
|
|||
app.on_b()
|
||||
} else {
|
||||
// Leave menu.
|
||||
frame_counter::start_counting(FRAME_COUNTER_INDEX);
|
||||
*VISUAL_FRAME_COUNTER_SHOULD_COUNT.lock() = true;
|
||||
QUICK_MENU_ACTIVE = false;
|
||||
let menu_json = app.get_menu_selections();
|
||||
set_menu_from_json(&menu_json);
|
||||
|
@ -211,7 +202,7 @@ pub fn handle_final_input_mapping(
|
|||
.then(|| {
|
||||
received_input = true;
|
||||
// Leave menu.
|
||||
frame_counter::start_counting(FRAME_COUNTER_INDEX);
|
||||
*VISUAL_FRAME_COUNTER_SHOULD_COUNT.lock() = true;
|
||||
QUICK_MENU_ACTIVE = false;
|
||||
let menu_json = app.get_menu_selections();
|
||||
set_menu_from_json(&menu_json);
|
||||
|
|
|
@ -34,6 +34,7 @@ mod character_specific;
|
|||
mod fast_fall;
|
||||
mod full_hop;
|
||||
pub mod input_delay;
|
||||
mod input_log;
|
||||
mod input_record;
|
||||
mod mash;
|
||||
mod reset;
|
||||
|
@ -696,15 +697,35 @@ unsafe fn handle_final_input_mapping(
|
|||
controller_struct: &mut SomeControllerStruct,
|
||||
arg: bool,
|
||||
) {
|
||||
// go through the original mapping function first
|
||||
// Order of hooks here REALLY matters. Tread lightly
|
||||
|
||||
// Go through the original mapping function first
|
||||
original!()(mappings, player_idx, out, controller_struct, arg);
|
||||
if !is_training_mode() {
|
||||
return;
|
||||
}
|
||||
menu::handle_final_input_mapping(player_idx, controller_struct, out);
|
||||
button_config::handle_final_input_mapping(player_idx, controller_struct);
|
||||
|
||||
// Check if we should apply hot reload configs
|
||||
// Non-mutable pull
|
||||
dev_config::handle_final_input_mapping(player_idx, controller_struct);
|
||||
|
||||
// Grab menu inputs from player
|
||||
// MUTATES controller state to kill inputs when in or closing menu
|
||||
menu::handle_final_input_mapping(player_idx, controller_struct, out);
|
||||
|
||||
// Grab button input requests from player
|
||||
// MUTATES controller state to kill start presses for menu
|
||||
button_config::handle_final_input_mapping(player_idx, controller_struct);
|
||||
|
||||
// Potentially apply input delay
|
||||
// MUTATES controller state to delay inputs
|
||||
input_delay::handle_final_input_mapping(player_idx, out);
|
||||
|
||||
// Read potentially delayed state for loggers
|
||||
input_log::handle_final_input_mapping(player_idx, controller_struct, out);
|
||||
|
||||
// Potentially apply input recording, thus with delay
|
||||
// MUTATES controller state to apply recording or playback
|
||||
input_record::handle_final_input_mapping(player_idx, out);
|
||||
}
|
||||
|
||||
|
@ -798,7 +819,7 @@ pub fn training_mods() {
|
|||
buff::init();
|
||||
items::init();
|
||||
tech::init();
|
||||
input_log::init();
|
||||
input_record::init();
|
||||
ui::init();
|
||||
menu::init();
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@ use smash::ui2d::{SmashPane, SmashTextBox};
|
|||
use training_mod_tui::gauge::GaugeState;
|
||||
use training_mod_tui::{App, AppPage, NUM_LISTS};
|
||||
|
||||
use crate::common::menu::{self, MENU_CLOSE_WAIT_FRAMES};
|
||||
use crate::training::frame_counter;
|
||||
use crate::common::menu::{
|
||||
MENU_CLOSE_WAIT_FRAMES, VISUAL_FRAME_COUNTER, VISUAL_FRAME_COUNTER_SHOULD_COUNT,
|
||||
};
|
||||
use crate::{common, common::menu::QUICK_MENU_ACTIVE, input::*};
|
||||
|
||||
use super::fade_out;
|
||||
use super::set_icon_text;
|
||||
|
||||
pub static NUM_MENU_TEXT_OPTIONS: usize = 32;
|
||||
pub static _NUM_MENU_TABS: usize = 3;
|
||||
|
@ -352,6 +354,12 @@ unsafe fn render_slider_page(app: &App, root_pane: &Pane) {
|
|||
}
|
||||
|
||||
pub unsafe fn draw(root_pane: &Pane) {
|
||||
if *VISUAL_FRAME_COUNTER_SHOULD_COUNT.data_ptr() {
|
||||
*VISUAL_FRAME_COUNTER.lock() += 1;
|
||||
} else {
|
||||
*VISUAL_FRAME_COUNTER.lock() = 0;
|
||||
}
|
||||
|
||||
// Determine if we're in the menu by seeing if the "help" footer has
|
||||
// begun moving upward. It starts at -80 and moves to 0 over 10 frames
|
||||
// in info_training_in_menu.bflan
|
||||
|
@ -374,7 +382,7 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
|
||||
let overall_parent_pane = root_pane.find_pane_by_name_recursive("TrModMenu").unwrap();
|
||||
overall_parent_pane.set_visible(true);
|
||||
let menu_close_wait_frame = frame_counter::get_frame_count(menu::FRAME_COUNTER_INDEX);
|
||||
let menu_close_wait_frame = *VISUAL_FRAME_COUNTER.data_ptr();
|
||||
if QUICK_MENU_ACTIVE {
|
||||
overall_parent_pane.alpha = 255;
|
||||
overall_parent_pane.global_alpha = 255;
|
||||
|
@ -483,10 +491,7 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
|
||||
// Left/Right tabs have keys
|
||||
if let Some(key) = key {
|
||||
let it = icon_pane.text_buf as *mut u16;
|
||||
icon_pane.text_len = 1;
|
||||
*it = **key;
|
||||
*(it.add(1)) = 0x0;
|
||||
set_icon_text(icon_pane, &vec![**key]);
|
||||
}
|
||||
|
||||
if *name == "CurrentTab" {
|
||||
|
@ -510,11 +515,7 @@ pub unsafe fn draw(root_pane: &Pane) {
|
|||
.find_pane_by_name_recursive("set_txt_icon")
|
||||
.unwrap()
|
||||
.as_textbox();
|
||||
icon_pane.set_text_string("");
|
||||
let it = icon_pane.text_buf as *mut u16;
|
||||
icon_pane.text_len = 1;
|
||||
*it = *key.unwrap();
|
||||
*(it.add(1)) = 0x0;
|
||||
set_icon_text(icon_pane, &vec![*key.unwrap()]);
|
||||
|
||||
key_help_pane
|
||||
.find_pane_by_name_recursive("set_txt_help")
|
||||
|
|
Loading…
Add table
Reference in a new issue