From 52e3528292f4fa0f13158d263ab3fa458eadf6ba Mon Sep 17 00:00:00 2001 From: jugeeya Date: Thu, 29 Dec 2022 20:09:22 -0800 Subject: [PATCH] Use ui2d-based Quick Menu; show dmg percentage on save state % reload with random damage (#450) * A bunch of things * Current progress * Fix for ResAnimationContent * Figure out Parts* * Cleanup, just because * New pane working!!! * New null pane for hierarchy * Success with parent pane * Generate multiple panes * Multiple panes, almost working text color * MaterialColor test, but fails * Forgot bitfield-struct * Vtable for material. Fixes SetWhiteColor! * Refactor color changing, change naming scheme * Just Frame Advantage * Merge * Delete T_test.txt * Delete set_txt_num_01.txt * Delete libtraining_modpack.nro * Format Rust code using rustfmt * Ignore shell scripts in repo languages * General refactor, add basis for quick menu * Small refactor, fix ordering of submenu options * Toggles, sliders * Tons of progress... * Correct dmg updater, remove old quick menu backend * Fix damage percentage display * Small QoL * Format Rust code using rustfmt * More edits. Use Quit Training button as Modpack Menu header * Finish merge * Format Rust code using rustfmt Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/rust.yml | 1 - README.md | 3 +- src/common/menu.rs | 62 +-- src/common/mod.rs | 10 + src/static/libtraining_modpack_menu.nro | Bin 323584 -> 0 bytes src/training/ui/mod.rs | 172 ++++-- src/training/ui/resources.rs | 170 +++++- src/training/ui_hacks.rs | 664 +++++++++++++++++++++--- training_mod_tui/src/lib.rs | 16 +- training_mod_tui/src/list.rs | 9 +- 10 files changed, 921 insertions(+), 186 deletions(-) delete mode 100644 src/static/libtraining_modpack_menu.nro diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index abbf2dc..1bb9f2c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -113,7 +113,6 @@ jobs: cp libparam_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libparam_hook.nro cp libnro_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libnro_hook.nro cp libnn_hid_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libnn_hid_hook.nro - mv static/libtraining_modpack_menu.nro ${{env.SMASH_PLUGIN_DIR}}/libtraining_modpack_menu.nro cp -r static/* ${{env.SMASH_WEB_DIR}} zip -r training_modpack_beta.zip atmosphere - name: Update Release diff --git a/README.md b/README.md index dbbf4ce..db9f278 100644 --- a/README.md +++ b/README.md @@ -262,8 +262,7 @@ SD Card Root ├── libnn_hid_hook.nro ├── libnro_hook.nro ├── libparam_hook.nro - ├── libtraining_modpack.nro - └── libtraining_modpack_menu.nro + └── libtraining_modpack.nro ``` To install a beta version of the modpack, follow the same procedure using the [latest beta release](https://github.com/jugeeya/UltimateTrainingModpack/tree/beta) on Github. Beta releases may have additional features and bugfixes, but are subject to change. diff --git a/src/common/menu.rs b/src/common/menu.rs index 5a90327..34b812e 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -2,7 +2,6 @@ use crate::common::*; use crate::events::{Event, EVENT_QUEUE}; use crate::training::frame_counter; -use owo_colors::OwoColorize; use ramhorns::Template; use skyline::info::get_program_id; use skyline::nn::hid::NpadGcState; @@ -11,7 +10,6 @@ use skyline_web::{Background, BootDisplay, WebSession, Webpage}; use std::fs; use std::path::Path; use training_mod_consts::{MenuJsonStruct, TrainingModpackMenu}; -use training_mod_tui::Color; static mut FRAME_COUNTER_INDEX: usize = 0; pub static mut QUICK_MENU_FRAME_COUNTER_INDEX: usize = 0; @@ -273,32 +271,18 @@ pub fn handle_get_npad_state(state: *mut NpadGcState, _controller_id: *const u32 } } -extern "C" { - #[link_name = "render_text_to_screen"] - pub fn render_text_to_screen_cstr(str: *const skyline::libc::c_char); +use lazy_static::lazy_static; +use parking_lot::Mutex; - #[link_name = "set_should_display_text_to_screen"] - pub fn set_should_display_text_to_screen(toggle: bool); -} - -macro_rules! c_str { - ($l:tt) => { - [$l.as_bytes(), "\u{0}".as_bytes()].concat().as_ptr() - }; -} - -pub fn render_text_to_screen(s: &str) { - unsafe { - render_text_to_screen_cstr(c_str!(s)); - } +lazy_static! { + pub static ref QUICK_MENU_APP: Mutex> = + Mutex::new(training_mod_tui::App::new(unsafe { get_menu() })); } pub unsafe fn quick_menu_loop() { loop { std::thread::sleep(std::time::Duration::from_secs(10)); - let menu = get_menu(); - - let mut app = training_mod_tui::App::new(menu); + 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(); @@ -357,47 +341,15 @@ pub unsafe fn quick_menu_loop() { has_slept_millis = 16; if !QUICK_MENU_ACTIVE { - app = training_mod_tui::App::new(get_menu()); - set_should_display_text_to_screen(false); continue; } if !received_input { continue; } - let mut view = String::new(); - - let frame_res = terminal + terminal .draw(|f| json_response = training_mod_tui::ui(f, &mut app)) .unwrap(); - use std::fmt::Write; - for (i, cell) in frame_res.buffer.content().iter().enumerate() { - match cell.fg { - Color::Black => write!(&mut view, "{}", &cell.symbol.black()), - Color::Blue => write!(&mut view, "{}", &cell.symbol.blue()), - Color::LightBlue => write!(&mut view, "{}", &cell.symbol.bright_blue()), - Color::Cyan => write!(&mut view, "{}", &cell.symbol.cyan()), - Color::LightCyan => write!(&mut view, "{}", &cell.symbol.cyan()), - Color::Red => write!(&mut view, "{}", &cell.symbol.red()), - Color::LightRed => write!(&mut view, "{}", &cell.symbol.bright_red()), - Color::LightGreen => write!(&mut view, "{}", &cell.symbol.bright_green()), - Color::Green => write!(&mut view, "{}", &cell.symbol.green()), - Color::Yellow => write!(&mut view, "{}", &cell.symbol.yellow()), - Color::LightYellow => write!(&mut view, "{}", &cell.symbol.bright_yellow()), - Color::Magenta => write!(&mut view, "{}", &cell.symbol.magenta()), - Color::LightMagenta => { - write!(&mut view, "{}", &cell.symbol.bright_magenta()) - } - _ => write!(&mut view, "{}", &cell.symbol), - } - .unwrap(); - if i % frame_res.area.width as usize == frame_res.area.width as usize - 1 { - writeln!(&mut view).unwrap(); - } - } - writeln!(&mut view).unwrap(); - - render_text_to_screen(view.as_str()); received_input = false; } } diff --git a/src/common/mod.rs b/src/common/mod.rs index 48847a0..9ae493e 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -229,6 +229,16 @@ pub unsafe fn entry_count() -> i32 { FighterManager::entry_count(fighter_manager) } +pub unsafe fn get_player_dmg_digits(p: FighterId) -> (u8, u8, u8, u8) { + let module_accessor = get_module_accessor(p); + let dmg = DamageModule::damage(module_accessor, 0); + let hundreds = dmg as u16 / 100; + let tens = (dmg as u16 - hundreds * 100) / 10; + let ones = (dmg as u16) - (hundreds * 100) - (tens * 10); + let dec = ((dmg * 10.0) as u16) - (hundreds * 1000) - (tens * 100) - ones * 10; + (hundreds as u8, tens as u8, ones as u8, dec as u8) +} + pub unsafe fn get_fighter_distance() -> f32 { let player_module_accessor = get_module_accessor(FighterId::Player); let cpu_module_accessor = get_module_accessor(FighterId::CPU); diff --git a/src/static/libtraining_modpack_menu.nro b/src/static/libtraining_modpack_menu.nro deleted file mode 100644 index dbfa23b967ad09cba1a331d91a2e73081bdb4eae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 323584 zcmdSC51dt1)jq!O%pjwnpo4*e%pC{AfP{iXQscs4W?I@nX=Ql{D@)&$><_)r%T+9W z(`t@VT3TMiH)XP#H?5qMyo!~jy$xt;ZzsY|Irq+B+WY(R z`3!fTv)5j0?X}lld#|(SL94Jb8|!cf{{ZDQD#GltyFv@IDWSqClDd zS@@~X@At&bZ@Xj7&i5a*>f7)A_N$NmbC5H#{~v3d+70aMf7;%#aJFaUmUBKqGmG}4BjJdaM3er11eR=CeW@lU8JbmZT(6VZy@ydY9 zJ(3&r8xQKPHXhu)t#NYqTi$La*qpqu`o|kz0PMgRGk8957aIx-@;UQ5(CIPfEEy~r zb4vm5P2~vhFYh($^QP2^yafYe3WG1KzU#(H;~5Xy_@rFv_`wRwEk`+)ZOa>v<==3I znLzm6<63u`!gX8Q4>ao^J;AJpFgtgTUbK^WLmg&|KiUlXqYHz^6ngRO+3%~PO)vAR zqYJ%|Q*Ud&@z*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