mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-28 04:44:06 +00:00
Fixes for Quick Menu Multi-selections (#362)
This commit is contained in:
parent
9cc4c6b73b
commit
283279b10c
4 changed files with 44 additions and 19 deletions
|
@ -145,7 +145,7 @@ pub fn main() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(10));
|
std::thread::sleep(std::time::Duration::from_secs(10));
|
||||||
let menu;
|
let menu;
|
||||||
unsafe {
|
unsafe {
|
||||||
menu = crate::common::consts::get_menu();
|
menu = consts::get_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut app = training_mod_tui::App::new(menu);
|
let mut app = training_mod_tui::App::new(menu);
|
||||||
|
@ -157,7 +157,7 @@ pub fn main() {
|
||||||
let mut has_slept_millis = 0;
|
let mut has_slept_millis = 0;
|
||||||
let render_frames = 5;
|
let render_frames = 5;
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
let button_presses = &mut common::menu::BUTTON_PRESSES;
|
let button_presses = &mut menu::BUTTON_PRESSES;
|
||||||
let mut received_input = true;
|
let mut received_input = true;
|
||||||
loop {
|
loop {
|
||||||
button_presses.a.read_press().then(|| {
|
button_presses.a.read_press().then(|| {
|
||||||
|
@ -174,7 +174,7 @@ pub fn main() {
|
||||||
{
|
{
|
||||||
// Leave menu.
|
// Leave menu.
|
||||||
menu::QUICK_MENU_ACTIVE = false;
|
menu::QUICK_MENU_ACTIVE = false;
|
||||||
crate::menu::set_menu_from_url(url.as_str());
|
menu::set_menu_from_url(url.as_str());
|
||||||
println!("URL: {}", url.as_str());
|
println!("URL: {}", url.as_str());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -210,7 +210,7 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
has_slept_millis = 16;
|
has_slept_millis = 16;
|
||||||
if !menu::QUICK_MENU_ACTIVE {
|
if !menu::QUICK_MENU_ACTIVE {
|
||||||
app = training_mod_tui::App::new(crate::common::consts::get_menu());
|
app = training_mod_tui::App::new(consts::get_menu());
|
||||||
set_should_display_text_to_screen(false);
|
set_should_display_text_to_screen(false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,8 @@ fn once_per_frame_per_fighter(
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if crate::common::menu::menu_condition(module_accessor) {
|
if menu::menu_condition(module_accessor) {
|
||||||
crate::common::menu::spawn_menu();
|
menu::spawn_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
input_record::get_command_flag_cat(module_accessor);
|
input_record::get_command_flag_cat(module_accessor);
|
||||||
|
|
|
@ -1571,19 +1571,15 @@ pub unsafe fn get_menu() -> UiMenu<'static> {
|
||||||
let non_ui_menu = MENU;
|
let non_ui_menu = MENU;
|
||||||
let url_params = non_ui_menu.to_url_params(false);
|
let url_params = non_ui_menu.to_url_params(false);
|
||||||
let toggle_values_all = url_params.split("&");
|
let toggle_values_all = url_params.split("&");
|
||||||
let mut sub_menu_id_to_vals : HashMap<&str, Vec<u32>> = HashMap::new();
|
let mut sub_menu_id_to_vals : HashMap<&str, u32> = HashMap::new();
|
||||||
for toggle_values in toggle_values_all {
|
for toggle_values in toggle_values_all {
|
||||||
let toggle_value_split = toggle_values.split('=').collect::<Vec<&str>>();
|
let toggle_value_split = toggle_values.split('=').collect::<Vec<&str>>();
|
||||||
let mut sub_menu_id = toggle_value_split[0];
|
let mut sub_menu_id = toggle_value_split[0];
|
||||||
if sub_menu_id.is_empty() { continue }
|
if sub_menu_id.is_empty() { continue }
|
||||||
sub_menu_id = sub_menu_id.strip_prefix("__").unwrap_or(sub_menu_id);
|
sub_menu_id = sub_menu_id.strip_prefix("__").unwrap_or(sub_menu_id);
|
||||||
|
|
||||||
let bits: u32 = toggle_value_split[1].parse().unwrap_or(0);
|
let full_bits: u32 = toggle_value_split[1].parse().unwrap_or(0);
|
||||||
if sub_menu_id_to_vals.contains_key(sub_menu_id) {
|
sub_menu_id_to_vals.insert(sub_menu_id, full_bits);
|
||||||
sub_menu_id_to_vals.get_mut(sub_menu_id).unwrap().push(bits);
|
|
||||||
} else {
|
|
||||||
sub_menu_id_to_vals.insert(sub_menu_id, vec![bits]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
overall_menu.tabs.iter_mut()
|
overall_menu.tabs.iter_mut()
|
||||||
.for_each(|tab| {
|
.for_each(|tab| {
|
||||||
|
@ -1591,7 +1587,7 @@ pub unsafe fn get_menu() -> UiMenu<'static> {
|
||||||
let sub_menu_id = sub_menu.submenu_id;
|
let sub_menu_id = sub_menu.submenu_id;
|
||||||
sub_menu.toggles.iter_mut().for_each(|toggle| {
|
sub_menu.toggles.iter_mut().for_each(|toggle| {
|
||||||
if sub_menu_id_to_vals.contains_key(sub_menu_id) &&
|
if sub_menu_id_to_vals.contains_key(sub_menu_id) &&
|
||||||
sub_menu_id_to_vals[sub_menu_id].contains(&(toggle.toggle_value as u32)) {
|
(sub_menu_id_to_vals[sub_menu_id] & (toggle.toggle_value as u32) != 0) {
|
||||||
toggle.checked = true
|
toggle.checked = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,6 +17,39 @@ use tui::Terminal;
|
||||||
|
|
||||||
use training_mod_consts::*;
|
use training_mod_consts::*;
|
||||||
|
|
||||||
|
fn test_backend_setup(ui_menu: UiMenu) -> Result<
|
||||||
|
(Terminal<training_mod_tui::TestBackend>, training_mod_tui::App),
|
||||||
|
Box<dyn Error>> {
|
||||||
|
let app = training_mod_tui::App::new(ui_menu);
|
||||||
|
let backend = tui::backend::TestBackend::new(75, 15);
|
||||||
|
let terminal = Terminal::new(backend)?;
|
||||||
|
let mut state = tui::widgets::ListState::default();
|
||||||
|
state.select(Some(1));
|
||||||
|
|
||||||
|
Ok((terminal, app))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ensure_menu_retains_multi_selections() -> Result<(), Box<dyn Error>> {
|
||||||
|
let menu;
|
||||||
|
unsafe {
|
||||||
|
menu = get_menu();
|
||||||
|
println!("MENU.miss_tech_state: {}", MENU.miss_tech_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (mut terminal, mut app) = test_backend_setup(menu)?;
|
||||||
|
let mut url = String::new();
|
||||||
|
let _frame_res = terminal.draw(|f| url = training_mod_tui::ui(f, &mut app))?;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
// At this point, we didn't change the menu at all; we should still see all missed tech flags.
|
||||||
|
assert_eq!(get_menu_from_url(MENU, url.as_str(), false).miss_tech_state,
|
||||||
|
MissTechFlags::all());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let menu;
|
let menu;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -24,11 +57,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "has_terminal"))] {
|
#[cfg(not(feature = "has_terminal"))] {
|
||||||
let mut app = training_mod_tui::App::new(menu);
|
let (mut terminal, mut app) = test_backend_setup(menu)?;
|
||||||
let backend = tui::backend::TestBackend::new(75, 15);
|
|
||||||
let mut terminal = Terminal::new(backend)?;
|
|
||||||
let mut state = tui::widgets::ListState::default();
|
|
||||||
state.select(Some(1));
|
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
let frame_res = terminal.draw(|f| url = training_mod_tui::ui(f, &mut app))?;
|
let frame_res = terminal.draw(|f| url = training_mod_tui::ui(f, &mut app))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue