diff --git a/src/lib.rs b/src/lib.rs index 3dacb8b..19bd259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,7 @@ use std::fs; use owo_colors::OwoColorize; use training_mod_consts::OnOff; +use training_mod_tui::Color; fn nro_main(nro: &NroInfo<'_>) { if nro.module.isLoaded { @@ -173,12 +174,16 @@ pub fn main() { unsafe { let mut has_slept_millis = 0; + let render_frames = 5; let mut url = String::new(); let button_presses = &mut common::menu::BUTTON_PRESSES; + let mut received_input = true; loop { - button_presses.a.read_press().then(|| app.on_a()); - button_presses.b.read_press().then(|| { - if app.outer_list == false { + button_presses.a.read_press().then(|| { app.on_a(); received_input = true; }); + let b_press = &mut button_presses.b; + b_press.read_press().then(|| { + received_input = true; + if !app.outer_list { app.on_b() } else { // Leave menu. @@ -186,39 +191,54 @@ pub fn main() { crate::menu::set_menu_from_url(url.as_str()); } }); - button_presses.zl.read_press().then(|| app.on_l()); - button_presses.zr.read_press().then(|| app.on_r()); - button_presses.left.read_press().then(|| app.on_left()); - button_presses.right.read_press().then(|| app.on_right()); - button_presses.up.read_press().then(|| app.on_up()); - button_presses.down.read_press().then(|| app.on_down()); + button_presses.zl.read_press().then(|| { app.on_l(); received_input = true; }); + button_presses.zr.read_press().then(|| { app.on_r(); received_input = true; }); + button_presses.left.read_press().then(|| { app.on_left(); received_input = true; }); + button_presses.right.read_press().then(|| { app.on_right(); received_input = true; }); + button_presses.up.read_press().then(|| { app.on_up(); received_input = true; }); + button_presses.down.read_press().then(|| { app.on_down(); received_input = true; }); std::thread::sleep(std::time::Duration::from_millis(16)); has_slept_millis += 16; - let render_frames = 5; - if has_slept_millis > 16 * render_frames { - has_slept_millis = 16; - let mut view = String::new(); + if has_slept_millis < 16 * render_frames { continue; } + has_slept_millis = 16; + if !menu::QUICK_MENU_ACTIVE { + set_should_display_text_to_screen(false); + continue; + } + if !received_input { continue; } + let mut view = String::new(); - let frame_res = terminal - .draw(|f| url = training_mod_tui::ui(f, &mut app)) - .unwrap(); + let frame_res = terminal + .draw(|f| url = training_mod_tui::ui(f, &mut app)) + .unwrap(); - use std::fmt::Write; - for (i, cell) in frame_res.buffer.content().into_iter().enumerate() { - write!(&mut view, "{}", cell.symbol).unwrap(); - if i % frame_res.area.width as usize == frame_res.area.width as usize - 1 { - write!(&mut view, "\n").unwrap(); - } - } - write!(&mut view, "\n").unwrap(); - - if menu::QUICK_MENU_ACTIVE { - render_text_to_screen(view.as_str()); - } else { - set_should_display_text_to_screen(false); + 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/static/libtraining_modpack_menu.nro b/src/static/libtraining_modpack_menu.nro index 8a85fec..bd750f1 100644 Binary files a/src/static/libtraining_modpack_menu.nro and b/src/static/libtraining_modpack_menu.nro differ diff --git a/src/static/shader_binaries/fragment/code.bin b/src/static/shader_binaries/fragment/code.bin index b845344..3577787 100644 Binary files a/src/static/shader_binaries/fragment/code.bin and b/src/static/shader_binaries/fragment/code.bin differ diff --git a/src/static/shader_binaries/fragment/control.bin b/src/static/shader_binaries/fragment/control.bin index aa04648..c472a20 100644 Binary files a/src/static/shader_binaries/fragment/control.bin and b/src/static/shader_binaries/fragment/control.bin differ diff --git a/src/static/shader_binaries/vertex/code.bin b/src/static/shader_binaries/vertex/code.bin index 6133804..223a31d 100644 Binary files a/src/static/shader_binaries/vertex/code.bin and b/src/static/shader_binaries/vertex/code.bin differ diff --git a/src/static/shader_binaries/vertex/control.bin b/src/static/shader_binaries/vertex/control.bin index 7e4c5e2..24f5e4f 100644 Binary files a/src/static/shader_binaries/vertex/control.bin and b/src/static/shader_binaries/vertex/control.bin differ diff --git a/src/training/character_specific/steve.rs b/src/training/character_specific/steve.rs index 87e811c..2dd8f0a 100644 --- a/src/training/character_specific/steve.rs +++ b/src/training/character_specific/steve.rs @@ -36,7 +36,7 @@ pub fn save_steve_state(module_accessor: &mut app::BattleObjectModuleAccessor) - } else { unsafe { Some(save(module_accessor)) // should return the SteveState - } + } } } diff --git a/training_mod_tui/src/lib.rs b/training_mod_tui/src/lib.rs index 9ca3020..76c4dcf 100644 --- a/training_mod_tui/src/lib.rs +++ b/training_mod_tui/src/lib.rs @@ -2,13 +2,13 @@ use training_mod_consts::{OnOffSelector, Slider, SubMenu, SubMenuType, Toggle}; use tui::{ backend::{Backend}, layout::{Constraint, Corner, Direction, Layout}, - style::{Color, Modifier, Style}, - text::Spans, + style::{Modifier, Style}, + text::{Span, Spans}, widgets::{Tabs, Paragraph, Block, List, ListItem, ListState}, Frame, }; -pub use tui::{backend::TestBackend, Terminal}; +pub use tui::{backend::TestBackend, Terminal, style::Color}; use std::collections::HashMap; mod list; @@ -322,8 +322,13 @@ pub fn ui(f: &mut Frame, app: &mut App) -> String { Spans::from(" ".to_owned() + tab) } }).collect(); + let tabs = Tabs::new(titles) - .block(Block::default().title("Ultimate Training Modpack Menu")) + .block(Block::default() + .title( + Spans::from( + Span::styled("Ultimate Training Modpack Menu", + Style::default().fg(Color::LightRed))))) .style(Style::default().fg(Color::White)) .highlight_style(Style::default().fg(Color::Yellow)) .divider("|") @@ -359,15 +364,17 @@ pub fn ui(f: &mut Frame, app: &mut App) -> String { } else { " ".to_owned() + i.title })]; - ListItem::new(lines).style(Style::default().fg(Color::Black).bg(Color::White)) + ListItem::new(lines).style(Style::default().fg(Color::White)) }) .collect(); let list = List::new(items) - .block(Block::default().title(if list_section == 0 { "Options" } else { "" })) + .block(Block::default() + .title(if list_section == 0 { "Options" } else { "" }) + .style(Style::default().fg(Color::LightRed))) .highlight_style( Style::default() - .bg(Color::LightBlue) + .fg(Color::Green) .add_modifier(Modifier::BOLD), ) .highlight_symbol(">> "); @@ -382,8 +389,8 @@ pub fn ui(f: &mut Frame, app: &mut App) -> String { let help_paragraph = Paragraph::new( item_help.unwrap_or("").replace("\"", "") + - "\nA: Enter sub-menu | B: Exit menu | ZL/ZR: Next tab | R: Save defaults" - ); + "\nA: Enter sub-menu | B: Exit menu | ZL/ZR: Next tab" + ).style(Style::default().fg(Color::Cyan)); f.render_widget(help_paragraph, vertical_chunks[2]); } else { let (title, help_text, mut sub_menu_str_lists) = app.sub_menu_strs_and_states(); @@ -403,7 +410,7 @@ pub fn ui(f: &mut Frame, app: &mut App) -> String { .start_corner(Corner::TopLeft) .highlight_style( Style::default() - .bg(Color::LightGreen) + .fg(Color::LightGreen) .add_modifier(Modifier::BOLD), ) .highlight_symbol(">> "); @@ -413,7 +420,7 @@ pub fn ui(f: &mut Frame, app: &mut App) -> String { let help_paragraph = Paragraph::new( help_text.replace("\"", "") + "\nA: Select toggle | B: Exit submenu" - ); + ).style(Style::default().fg(Color::Cyan)); f.render_widget(help_paragraph, vertical_chunks[2]); }