From 720e95810b64d85b17f564fe39c5aeb3c78c4893 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Tue, 12 Sep 2023 09:49:53 -0700 Subject: [PATCH] [Input Display] Use 15 total logs; Small optimizations (#632) * Initial, also up to 15 logs * Add files via upload * Add files via upload * Fix positions * Add files via upload * Add files via upload * Small fixes --- src/common/menu.rs | 1 + src/static/layout.arc | Bin 3652284 -> 3652284 bytes src/training/input_log.rs | 7 +++--- src/training/ui/input_log.rs | 26 +++++++++++++-------- src/training/ui/menu.rs | 43 +++++++++++++++-------------------- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/common/menu.rs b/src/common/menu.rs index 01ffca8..0ed2a0c 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -72,6 +72,7 @@ pub unsafe fn set_menu_from_json(message: &str) { pub fn spawn_menu() { unsafe { QUICK_MENU_ACTIVE = true; + *MENU_RECEIVED_INPUT.data_ptr() = true; } } diff --git a/src/static/layout.arc b/src/static/layout.arc index 547942ba3960b804eaa8907e7c99d3496e99a32d..ab05c96e95b504ceaf8aa8a4ad72f4e370487d3f 100644 GIT binary patch delta 764 zcmZ9|OGs2<7{>AUJx=4K$J^-WoUzGq#&p!YmL}7*Ny|2cN<>hmM%zk^tcB!5m$wj# zXvl$T5d={|PzcS&vW0ER&7_j6a*>N}Ac&i=%lownTzt&${~XTYVu zzG@qL3Ylhx>zx&C<3~ZJ=Zl{L`gt~^gFa2SuW>`D!(>TA6X>8$3{Y4#&KkuKoV99_x zI!DyZ$y3W*GEsh_W!l|7O=PzxkFIiQ>Rgmxxst!4>?C^9e#@Rt#AAWvjb3&qyQ+Ct zBAs@u!1}TKy<>geRCP0l!z%~-z57t*E&2?Zi8LTE7-ZL`V9mE_m!D3yT74q-imr3!^9(MM$n{7P=@31ZfkIox8Y~-~U{=C;R)WX6@YlIq|MQ<$3a+ z_lAf%&lIXeZe_}+texkIR2nbmSKhaF&U#c%t@QdHSv$`ctNcnl@IAG5o-eWY>qFIP z*XG$$mDR(e{sn7icvXu2J@J3AHc!ZSnM%jlLSV%P&bjR>!O4w4&f0mVT;=BbrrICY z&T|zi%VVvzo7T>Q^(rrN-|9p~oyUVJ)tA=mY_~cuHmLZA6TyJBb2O}Sa?uxxSVzMX zDu1IYkGn@hZ8mT|8nY!A9)=EDJICVo>2QBzzqRvxkIL3^RdmqW`E{?#?S;+gX=~?a zhg9Aq{xqGncJ>@m`P`R_ows&gvorf;y?M-f&2JGprZTzuz4e+6obQ}SU&-T{!jGRs zS~NAXp*897xvr&x&Lxp#>Z&)dDl-z(xA~c=Hoe%cgQ=~AMy8YT!1O?$Cv`lo-ps(T zzHCS*<3o9b5_WGR@`(bXkSHQNL@`l9loDQ|jMz?;6BR@y;UlVuYQj(KAZmyJQA^Yj z^~6phNbDjSh!7Db8i@!IC3X`{#2z9>#EE8NFR_nkAzFzxqMhg<_7ew)PNIwGeubWF F-+vz~y7vG8 diff --git a/src/training/input_log.rs b/src/training/input_log.rs index 76bb122..f21baf2 100644 --- a/src/training/input_log.rs +++ b/src/training/input_log.rs @@ -65,8 +65,8 @@ pub static PER_LOG_FRAME_COUNTER: Lazy = pub static OVERALL_FRAME_COUNTER: Lazy = Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGameNoReset)); -pub const NUM_LOGS: usize = 10; -pub static mut DRAW_LOG_BASE_IDX: Lazy = Lazy::new(|| 0); +pub const NUM_LOGS: usize = 15; +pub static mut DRAW_LOG_BASE_IDX: Lazy> = Lazy::new(|| Mutex::new(0)); #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum DirectionStrength { @@ -331,7 +331,8 @@ pub fn handle_final_input_mapping( // We should count this frame already frame_counter::tick_idx(*PER_LOG_FRAME_COUNTER); insert_in_front(input_logs, potential_input_log); - *DRAW_LOG_BASE_IDX = (*DRAW_LOG_BASE_IDX + 1) % NUM_LOGS; + let draw_log_base_idx = &mut *DRAW_LOG_BASE_IDX.data_ptr(); + *draw_log_base_idx = (*draw_log_base_idx + 1) % NUM_LOGS; } else if is_new_frame { *latest_input_log = potential_input_log; latest_input_log.frames = std::cmp::min(current_frame, 99); diff --git a/src/training/ui/input_log.rs b/src/training/ui/input_log.rs index c3f074d..374b5fc 100644 --- a/src/training/ui/input_log.rs +++ b/src/training/ui/input_log.rs @@ -69,24 +69,22 @@ fn get_input_icons(log: &InputLog) -> VecDeque<(&str, ResColor)> { } unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog) { - let draw_log_idx = (log_idx + (NUM_LOGS - *DRAW_LOG_BASE_IDX)) % NUM_LOGS; + let draw_log_idx = (log_idx + (NUM_LOGS - *DRAW_LOG_BASE_IDX.data_ptr())) % NUM_LOGS; let log_pane = root_pane .find_pane_by_name_recursive(log_parent_fmt!(draw_log_idx)) .unwrap(); // Handle visibility and alpha - log_pane.set_visible( - !QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display != InputDisplay::None, - ); - if MENU.input_display == InputDisplay::None { - return; - } + log_pane.set_visible(true); const FADE_FRAMES: u32 = 200; fade_out(log_pane, log.ttl, FADE_FRAMES); // Handle positioning - log_pane.pos_y = -52.5 * log_idx as f32; - log_pane.flags |= 1 << PaneFlag::IsGlobalMatrixDirty as u8; + let new_pos_y = -52.5 * log_idx as f32; + if new_pos_y != log_pane.pos_y { + log_pane.pos_y = new_pos_y; + log_pane.flags |= 1 << PaneFlag::IsGlobalMatrixDirty as u8; + } // Only redraw first log! if log_idx != 0 { @@ -178,6 +176,16 @@ unsafe fn draw_log(root_pane: &Pane, log_idx: usize, log: &InputLog) { } pub unsafe fn draw(root_pane: &Pane) { + let logs_pane = root_pane + .find_pane_by_name_recursive("TrModInputLog") + .unwrap(); + logs_pane.set_visible( + !QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display != InputDisplay::None, + ); + if MENU.input_display == InputDisplay::None { + return; + } + let logs_ptr = P1_INPUT_LOGS.data_ptr(); if logs_ptr.is_null() { return; diff --git a/src/training/ui/menu.rs b/src/training/ui/menu.rs index 58d8a9f..7a1e2cc 100644 --- a/src/training/ui/menu.rs +++ b/src/training/ui/menu.rs @@ -362,33 +362,14 @@ pub unsafe fn draw(root_pane: &Pane) { .pos_y != -80.0; - // Update menu display - // Grabbing lock as read-only, essentially - let app = &*crate::common::menu::QUICK_MENU_APP.data_ptr(); - if let Some(quit_button) = root_pane.find_pane_by_name_recursive("TrModTitle") { - for quit_txt_s in &["set_txt_00", "set_txt_01"] { - if let Some(quit_txt) = quit_button.find_pane_by_name_recursive(quit_txt_s) { - quit_txt.as_textbox().set_text_string("Modpack Menu"); - } - } - } - let overall_parent_pane = root_pane.find_pane_by_name_recursive("TrModMenu").unwrap(); - overall_parent_pane.set_visible(true); + overall_parent_pane.set_visible(QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE); let menu_close_wait_frame = frame_counter::get_frame_count(*MENU_CLOSE_FRAME_COUNTER); - if QUICK_MENU_ACTIVE { - overall_parent_pane.alpha = 255; - overall_parent_pane.global_alpha = 255; - } else if menu_close_wait_frame > 0 { - fade_out( - overall_parent_pane, - MENU_CLOSE_WAIT_FRAMES - menu_close_wait_frame, - MENU_CLOSE_WAIT_FRAMES, - ); - } else { - overall_parent_pane.alpha = 0; - overall_parent_pane.global_alpha = 0; - } + fade_out( + overall_parent_pane, + MENU_CLOSE_WAIT_FRAMES - menu_close_wait_frame, + MENU_CLOSE_WAIT_FRAMES, + ); // Only submit updates if we have received input let received_input = &mut *MENU_RECEIVED_INPUT.data_ptr(); @@ -398,6 +379,14 @@ pub unsafe fn draw(root_pane: &Pane) { *received_input = false; } + if let Some(quit_button) = root_pane.find_pane_by_name_recursive("TrModTitle") { + for quit_txt_s in &["set_txt_00", "set_txt_01"] { + if let Some(quit_txt) = quit_button.find_pane_by_name_recursive(quit_txt_s) { + quit_txt.as_textbox().set_text_string("Modpack Menu"); + } + } + } + // Make all invisible first (0..NUM_MENU_TEXT_OPTIONS).for_each(|idx| { let col_idx = idx % NUM_LISTS; @@ -432,6 +421,10 @@ pub unsafe fn draw(root_pane: &Pane) { .unwrap() .set_visible(false); + // Update menu display + // Grabbing lock as read-only, essentially + let app = &*crate::common::menu::QUICK_MENU_APP.data_ptr(); + let app_tabs = &app.tabs.items; let tab_selected = app.tabs.state.selected().unwrap(); let prev_tab = if tab_selected == 0 {