1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 00:46:34 +00:00

[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
This commit is contained in:
jugeeya 2023-09-12 09:49:53 -07:00 committed by GitHub
parent 267cb0c310
commit 720e95810b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 37 deletions

View file

@ -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;
}
}

Binary file not shown.

View file

@ -65,8 +65,8 @@ pub static PER_LOG_FRAME_COUNTER: Lazy<usize> =
pub static OVERALL_FRAME_COUNTER: Lazy<usize> =
Lazy::new(|| frame_counter::register_counter(frame_counter::FrameCounterType::InGameNoReset));
pub const NUM_LOGS: usize = 10;
pub static mut DRAW_LOG_BASE_IDX: Lazy<usize> = Lazy::new(|| 0);
pub const NUM_LOGS: usize = 15;
pub static mut DRAW_LOG_BASE_IDX: Lazy<Mutex<usize>> = 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);

View file

@ -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;

View file

@ -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 {