1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-24 02:44:17 +00:00

Quick Menu Defaults Help Text (#471)

* Update lib.rs

* Remaining fixes

* Initial

* Forgot to commit

* Clippy
This commit is contained in:
jugeeya 2023-02-05 16:24:56 -08:00 committed by GitHub
parent 9c590df189
commit bbba8fd3ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 319 additions and 238 deletions

View file

@ -1,7 +1,7 @@
use crate::{common::menu::QUICK_MENU_ACTIVE};
use skyline::nn::ui2d::*;
use smash::ui2d::{SmashPane, SmashTextBox};
use training_mod_tui::AppPage;
use training_mod_tui::{App, AppPage};
use training_mod_tui::gauge::GaugeState;
use crate::training::ui;
@ -109,6 +109,24 @@ macro_rules! menu_tab_help_fmt {
};
}
macro_rules! defaults_help_text {
($x:ident) => {
format!("defaults_help_txt_{}", $x).as_str()
};
($x:literal) => {
format!("defaults_help_txt_{}", $x).as_str()
};
}
macro_rules! defaults_help_button {
($x:ident) => {
format!("defaults_help_btn_{}", $x).as_str()
};
($x:literal) => {
format!("defaults_help_txt_{}", $x).as_str()
};
}
macro_rules! menu_text_slider_fmt {
($x:ident) => {
format!("trMod_menu_slider_{}", $x).as_str()
@ -188,95 +206,7 @@ pub unsafe fn all_menu_panes_sorted(root_pane: &Pane) -> Vec<&mut Pane> {
panes
}
pub unsafe fn draw(root_pane: &mut Pane) {
// 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("btn_finish") {
// Normally at (-804, 640)
// Comes down to (-804, 514)
if QUICK_MENU_ACTIVE {
quit_button.pos_y = 514.0;
}
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(if QUICK_MENU_ACTIVE {
"Modpack Menu"
} else {
// Awkward. We should get the o.g. translation for non-english games
// Or create our own textbox here so we don't step on their toes.
"Quit Training"
});
}
}
}
let menu_pane = root_pane.find_pane_by_name_recursive(MENU_NAME).unwrap();
menu_pane.set_visible(QUICK_MENU_ACTIVE);
if !HAS_SORTED_MENU_CHILDREN {
let sorted_panes = all_menu_panes_sorted(root_pane);
// Place in sorted order such that backings are behind, etc.
sorted_panes.iter().for_each(|p| menu_pane.remove_child(p));
sorted_panes.iter().for_each(|p| menu_pane.append_child(p));
HAS_SORTED_MENU_CHILDREN = true;
}
// Make all invisible first
(0..NUM_MENU_TEXT_OPTIONS).for_each(|idx| {
let x = idx % 3;
let y = idx / 3;
root_pane
.find_pane_by_name_recursive(menu_text_name_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_check_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_bg_left_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_bg_back_fmt!(x, y))
.map(|text| text.set_visible(false));
});
(0..NUM_MENU_TEXT_SLIDERS).for_each(|idx| {
root_pane
.find_pane_by_name_recursive(menu_text_slider_fmt!(idx))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_slider_label_fmt!(idx))
.map(|text| text.set_visible(false));
});
root_pane
.find_pane_by_name_recursive(SLIDER_MENU_NAME)
.map(|pane| pane.set_visible(false));
let app_tabs = &app.tabs.items;
let tab_selected = app.tabs.state.selected().unwrap();
let prev_tab = if tab_selected == 0 {
app_tabs.len() - 1
} else {
tab_selected - 1
};
let next_tab = if tab_selected == app_tabs.len() - 1 {
0
} else {
tab_selected + 1
};
let tab_titles = [prev_tab, tab_selected, next_tab].map(|idx| app_tabs[idx]);
(0..NUM_MENU_TABS).for_each(|idx| {
root_pane
.find_pane_by_name_recursive(format!("trMod_menu_tab_{idx}").as_str())
.map(|text| text.as_textbox().set_text_string(tab_titles[idx]));
});
if app.page == AppPage::SUBMENU {
unsafe fn render_submenu_page(app: &App, root_pane: &mut Pane) {
let tab_selected = app.tab_selected();
let tab = app.menu_items.get(tab_selected).unwrap();
@ -337,7 +267,9 @@ pub unsafe fn draw(root_pane: &mut Pane) {
bg_left.set_visible(true);
bg_back.set_visible(true);
});
} else if matches!(app.selected_sub_menu_slider.state, GaugeState::None) {
}
unsafe fn render_toggle_page(app: &App, root_pane: &mut Pane) {
let (_title, _help_text, mut sub_menu_str_lists) = app.sub_menu_strs_and_states();
(0..sub_menu_str_lists.len()).for_each(|list_section| {
let sub_menu_str = sub_menu_str_lists[list_section].0.clone();
@ -398,7 +330,9 @@ pub unsafe fn draw(root_pane: &mut Pane) {
}
});
});
} else {
}
unsafe fn render_slider_page(app: &App, root_pane: &mut Pane) {
let (title, _help_text, gauge_vals) = app.sub_menu_strs_for_slider();
let selected_min = gauge_vals.selected_min;
let selected_max = gauge_vals.selected_max;
@ -508,6 +442,101 @@ pub unsafe fn draw(root_pane: &mut Pane) {
bg_left.set_visible(true);
}
});
}
pub unsafe fn draw(root_pane: &mut Pane) {
// 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("btn_finish") {
// Normally at (-804, 640)
// Comes down to (-804, 514)
if QUICK_MENU_ACTIVE {
quit_button.pos_y = 514.0;
}
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(if QUICK_MENU_ACTIVE {
"Modpack Menu"
} else {
// Awkward. We should get the o.g. translation for non-english games
// Or create our own textbox here so we don't step on their toes.
"Quit Training"
});
}
}
}
let menu_pane = root_pane.find_pane_by_name_recursive(MENU_NAME).unwrap();
menu_pane.set_visible(QUICK_MENU_ACTIVE);
if !HAS_SORTED_MENU_CHILDREN {
let sorted_panes = all_menu_panes_sorted(root_pane);
// Place in sorted order such that backings are behind, etc.
sorted_panes.iter().for_each(|p| menu_pane.remove_child(p));
sorted_panes.iter().for_each(|p| menu_pane.append_child(p));
HAS_SORTED_MENU_CHILDREN = true;
}
// Make all invisible first
(0..NUM_MENU_TEXT_OPTIONS).for_each(|idx| {
let x = idx % 3;
let y = idx / 3;
root_pane
.find_pane_by_name_recursive(menu_text_name_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_check_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_bg_left_fmt!(x, y))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_text_bg_back_fmt!(x, y))
.map(|text| text.set_visible(false));
});
(0..NUM_MENU_TEXT_SLIDERS).for_each(|idx| {
root_pane
.find_pane_by_name_recursive(menu_text_slider_fmt!(idx))
.map(|text| text.set_visible(false));
root_pane
.find_pane_by_name_recursive(menu_slider_label_fmt!(idx))
.map(|text| text.set_visible(false));
});
root_pane
.find_pane_by_name_recursive(SLIDER_MENU_NAME)
.map(|pane| pane.set_visible(false));
let app_tabs = &app.tabs.items;
let tab_selected = app.tabs.state.selected().unwrap();
let prev_tab = if tab_selected == 0 {
app_tabs.len() - 1
} else {
tab_selected - 1
};
let next_tab = if tab_selected == app_tabs.len() - 1 {
0
} else {
tab_selected + 1
};
let tab_titles = [prev_tab, tab_selected, next_tab].map(|idx| app_tabs[idx]);
(0..NUM_MENU_TABS).for_each(|idx| {
root_pane
.find_pane_by_name_recursive(format!("trMod_menu_tab_{idx}").as_str())
.map(|text| text.as_textbox().set_text_string(tab_titles[idx]));
});
match app.page {
AppPage::SUBMENU => render_submenu_page(app, root_pane),
AppPage::SLIDER => render_slider_page(app, root_pane),
AppPage::TOGGLE => render_toggle_page(app, root_pane),
AppPage::CONFIRMATION => todo!()
}
}
@ -620,6 +649,9 @@ pub static BUILD_TAB_TXTS: ui::PaneCreationCallback = |_, root_pane, original_bu
if txt_idx == 1 {
text_pane.set_color(255, 255, 0, 255);
}
text_pane.set_text_shadow(ResVec2::new(4.0, -3.0), ResVec2::new(1.0, 1.0), [BLACK, BLACK], 0.0);
text_pane.text_outline_enable(true);
text_pane.text_shadow_enable(true);
text_pane.detach();
menu_pane.append_child(text_pane);
@ -637,7 +669,7 @@ pub static BUILD_TAB_TXTS: ui::PaneCreationCallback = |_, root_pane, original_bu
0.0,
));
let help_pane = build!(help_block, ResTextBox, kind, TextBox);
help_pane.set_text_string("Help Buttons");
help_pane.set_text_string("Help Button");
let it = help_pane.text_buf as *mut u16;
match txt_idx {
// Left Tab: ZL
@ -659,9 +691,58 @@ pub static BUILD_TAB_TXTS: ui::PaneCreationCallback = |_, root_pane, original_bu
_ => {}
}
// Ensure Material Colors are not hardcoded so we can just use SetTextColor.
help_pane.set_default_material_colors();
help_pane.set_color(255, 255, 255, 255);
help_pane.set_text_shadow(ResVec2::new(4.0, -3.0), ResVec2::new(1.0, 1.0), [BLACK, BLACK], 0.0);
help_pane.text_outline_enable(true);
help_pane.text_shadow_enable(true);
help_pane.detach();
menu_pane.append_child(help_pane);
// Let's also make defaults help buttons below
text_block.pos.y -= 45.0;
// Uncenter from above
if x == 1 {
text_block.pos.x += 25.0;
}
text_block.set_name(defaults_help_text!(txt_idx));
let text_pane = build!(text_block, ResTextBox, kind, TextBox);
text_pane.set_text_string(if txt_idx == 0 {
"Save Defaults"
} else if txt_idx == 1 {
"Reset Current Menu"
} else {
"Reset All Menus"
});
// Ensure Material Colors are not hardcoded so we can just use SetTextColor.
text_pane.set_default_material_colors();
text_pane.set_color(255, 255, 255, 255);
text_pane.set_text_shadow(ResVec2::new(4.0, -3.0), ResVec2::new(1.0, 1.0), [BLACK, BLACK], 0.0);
text_pane.text_outline_enable(true);
text_pane.text_shadow_enable(true);
text_pane.detach();
menu_pane.append_child(text_pane);
help_block.pos.y -= 45.0;
help_block.set_name(defaults_help_button!(txt_idx));
let help_pane = build!(help_block, ResTextBox, kind, TextBox);
help_pane.set_text_string("Help Button");
let it = help_pane.text_buf as *mut u16;
help_pane.text_len = 1;
*(it.add(1)) = 0x0;
if txt_idx == 0 {
*it = 0xE0E2; // X
} else if txt_idx == 1 {
*it = 0xE0E4; // L
} else {
*it = 0xE0E5; // R
}
help_pane.set_default_material_colors();
help_pane.set_color(255, 255, 255, 255);
help_pane.set_text_shadow(ResVec2::new(4.0, -3.0), ResVec2::new(1.0, 1.0), [BLACK, BLACK], 0.0);
help_pane.text_outline_enable(true);
help_pane.text_shadow_enable(true);
help_pane.detach();
menu_pane.append_child(help_pane);
});

View file

@ -627,7 +627,7 @@ fn render_submenu_page<B: Backend>(f: &mut Frame<B>, app: &mut App, list_chunks:
let help_paragraph = Paragraph::new(
item_help.unwrap_or("").replace('\"', "")
+ "\nA: Enter sub-menu | B: Exit menu | ZL/ZR: Next tab | X: Save Defaults",
+ "\nZL/ZR: Next tab | X: Save Defaults | R: Reset All Menus",
)
.style(Style::default().fg(Color::Cyan));
f.render_widget(help_paragraph, help_chunk);
@ -659,7 +659,7 @@ pub fn render_toggle_page<B: Backend>(f: &mut Frame<B>, app: &mut App, list_chun
f.render_stateful_widget(values_list, list_chunks[list_section], sub_menu_state);
}
let help_paragraph = Paragraph::new(
help_text.replace('\"', "") + "\nA: Select toggle | B: Exit submenu | X: Reset to defaults",
help_text.replace('\"', "") + "\nL: Reset Current Menu",
)
.style(Style::default().fg(Color::Cyan));
f.render_widget(help_paragraph, help_chunk);
@ -744,7 +744,7 @@ pub fn render_slider_page<B: Backend>(f: &mut Frame<B>, app: &mut App, vertical_
}
let help_paragraph = Paragraph::new(
help_text.replace('\"', "") + "\nA: Select toggle | B: Exit submenu | X: Reset to defaults",
help_text.replace('\"', "") + "\nL: Reset Current Menu",
)
.style(Style::default().fg(Color::Cyan));
f.render_widget(help_paragraph, help_chunk);