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

Use colors in Quick Menu (#325)

This commit is contained in:
jugeeya 2022-03-24 09:27:14 -07:00 committed by GitHub
parent 42ab764757
commit 63d31499f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 41 deletions

View file

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

View file

@ -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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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]);
}