mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-20 00:46:34 +00:00
Fix two bugs which caused some OnOffs to work incorrectly (#454)
This commit is contained in:
parent
7ec7928c55
commit
f35f10e4f4
2 changed files with 30 additions and 30 deletions
|
@ -69,6 +69,7 @@ const MENU_CONF_PATH: &str = "sd:/TrainingModpack/training_modpack_menu.json";
|
|||
pub unsafe fn set_menu_from_json(message: &str) {
|
||||
let web_response = serde_json::from_str::<MenuJsonStruct>(message);
|
||||
let tui_response = serde_json::from_str::<TrainingModpackMenu>(message);
|
||||
println!("Received menu message: {message}");
|
||||
if let Ok(message_json) = web_response {
|
||||
// Includes both MENU and DEFAULTS_MENU
|
||||
// From Web Applet
|
||||
|
@ -126,6 +127,9 @@ pub fn spawn_menu() {
|
|||
spawn_web_session(new_web_session(false));
|
||||
}
|
||||
} else {
|
||||
let mut app = QUICK_MENU_APP.lock();
|
||||
*app = training_mod_tui::App::new(get_menu());
|
||||
drop(app);
|
||||
QUICK_MENU_ACTIVE = true;
|
||||
}
|
||||
}
|
||||
|
@ -272,17 +276,26 @@ lazy_static! {
|
|||
pub unsafe fn quick_menu_loop() {
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_secs(10));
|
||||
let mut app = QUICK_MENU_APP.lock();
|
||||
|
||||
let backend = training_mod_tui::TestBackend::new(75, 15);
|
||||
let mut terminal = training_mod_tui::Terminal::new(backend).unwrap();
|
||||
|
||||
let mut has_slept_millis = 0;
|
||||
let render_frames = 5;
|
||||
let mut json_response = String::new();
|
||||
let button_presses = &mut BUTTON_PRESSES;
|
||||
let mut received_input = true;
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
has_slept_millis += 16;
|
||||
if has_slept_millis < 16 * render_frames {
|
||||
continue;
|
||||
}
|
||||
has_slept_millis = 0;
|
||||
|
||||
if !QUICK_MENU_ACTIVE {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut app = QUICK_MENU_APP.lock();
|
||||
button_presses.a.read_press().then(|| {
|
||||
app.on_a();
|
||||
received_input = true;
|
||||
|
@ -292,7 +305,9 @@ pub unsafe fn quick_menu_loop() {
|
|||
received_input = true;
|
||||
if !app.outer_list {
|
||||
app.on_b()
|
||||
} else if frame_counter::get_frame_count(QUICK_MENU_FRAME_COUNTER_INDEX) == 0 {
|
||||
} else if frame_counter::get_frame_count(QUICK_MENU_FRAME_COUNTER_INDEX) == 0
|
||||
&& !json_response.is_empty()
|
||||
{
|
||||
// Leave menu.
|
||||
QUICK_MENU_ACTIVE = false;
|
||||
set_menu_from_json(&json_response);
|
||||
|
@ -323,25 +338,14 @@ pub unsafe fn quick_menu_loop() {
|
|||
received_input = true;
|
||||
});
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
has_slept_millis += 16;
|
||||
if has_slept_millis < 16 * render_frames {
|
||||
continue;
|
||||
}
|
||||
|
||||
has_slept_millis = 16;
|
||||
if !QUICK_MENU_ACTIVE {
|
||||
continue;
|
||||
}
|
||||
if !received_input {
|
||||
continue;
|
||||
}
|
||||
if received_input {
|
||||
terminal
|
||||
.draw(|f| json_response = training_mod_tui::ui(f, &mut app))
|
||||
.unwrap();
|
||||
|
||||
received_input = false;
|
||||
}
|
||||
drop(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,15 +363,7 @@ unsafe fn spawn_web_session(session: WebSession) {
|
|||
defaults_menu: DEFAULTS_MENU,
|
||||
};
|
||||
session.send_json(&message_send);
|
||||
println!(
|
||||
"[Training Modpack] Sending message:\n{}",
|
||||
serde_json::to_string_pretty(&message_send).unwrap()
|
||||
);
|
||||
let message_recv = session.recv();
|
||||
println!(
|
||||
"[Training Modpack] Received menu from web:\n{}",
|
||||
&message_recv
|
||||
);
|
||||
println!("[Training Modpack] Tearing down Training Modpack menu session");
|
||||
session.exit();
|
||||
session.wait_for_exit();
|
||||
|
|
|
@ -1298,6 +1298,10 @@ impl<'a> SubMenu<'a> {
|
|||
|| (!values[i] == 0 && initial_value == &0);
|
||||
instance.add_toggle(values[i], titles[i], checked);
|
||||
}
|
||||
// Select the first option if there's nothing selected atm but it's a single option submenu
|
||||
if is_single_option && instance.toggles.iter().all(|t| !t.checked) {
|
||||
instance.toggles[0].checked = true;
|
||||
}
|
||||
instance
|
||||
}
|
||||
pub fn new_with_slider<S: SliderTrait>(
|
||||
|
|
Loading…
Reference in a new issue