mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-24 10:54:16 +00:00
Use colors in Quick Menu (#325)
This commit is contained in:
parent
42ab764757
commit
63d31499f5
8 changed files with 68 additions and 41 deletions
78
src/lib.rs
78
src/lib.rs
|
@ -28,6 +28,7 @@ use std::fs;
|
||||||
|
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
use training_mod_consts::OnOff;
|
use training_mod_consts::OnOff;
|
||||||
|
use training_mod_tui::Color;
|
||||||
|
|
||||||
fn nro_main(nro: &NroInfo<'_>) {
|
fn nro_main(nro: &NroInfo<'_>) {
|
||||||
if nro.module.isLoaded {
|
if nro.module.isLoaded {
|
||||||
|
@ -173,12 +174,16 @@ pub fn main() {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut has_slept_millis = 0;
|
let mut has_slept_millis = 0;
|
||||||
|
let render_frames = 5;
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
let button_presses = &mut common::menu::BUTTON_PRESSES;
|
let button_presses = &mut common::menu::BUTTON_PRESSES;
|
||||||
|
let mut received_input = true;
|
||||||
loop {
|
loop {
|
||||||
button_presses.a.read_press().then(|| app.on_a());
|
button_presses.a.read_press().then(|| { app.on_a(); received_input = true; });
|
||||||
button_presses.b.read_press().then(|| {
|
let b_press = &mut button_presses.b;
|
||||||
if app.outer_list == false {
|
b_press.read_press().then(|| {
|
||||||
|
received_input = true;
|
||||||
|
if !app.outer_list {
|
||||||
app.on_b()
|
app.on_b()
|
||||||
} else {
|
} else {
|
||||||
// Leave menu.
|
// Leave menu.
|
||||||
|
@ -186,39 +191,54 @@ pub fn main() {
|
||||||
crate::menu::set_menu_from_url(url.as_str());
|
crate::menu::set_menu_from_url(url.as_str());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
button_presses.zl.read_press().then(|| app.on_l());
|
button_presses.zl.read_press().then(|| { app.on_l(); received_input = true; });
|
||||||
button_presses.zr.read_press().then(|| app.on_r());
|
button_presses.zr.read_press().then(|| { app.on_r(); received_input = true; });
|
||||||
button_presses.left.read_press().then(|| app.on_left());
|
button_presses.left.read_press().then(|| { app.on_left(); received_input = true; });
|
||||||
button_presses.right.read_press().then(|| app.on_right());
|
button_presses.right.read_press().then(|| { app.on_right(); received_input = true; });
|
||||||
button_presses.up.read_press().then(|| app.on_up());
|
button_presses.up.read_press().then(|| { app.on_up(); received_input = true; });
|
||||||
button_presses.down.read_press().then(|| app.on_down());
|
button_presses.down.read_press().then(|| { app.on_down(); received_input = true; });
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||||
has_slept_millis += 16;
|
has_slept_millis += 16;
|
||||||
let render_frames = 5;
|
if has_slept_millis < 16 * render_frames { continue; }
|
||||||
if has_slept_millis > 16 * render_frames {
|
has_slept_millis = 16;
|
||||||
has_slept_millis = 16;
|
if !menu::QUICK_MENU_ACTIVE {
|
||||||
let mut view = String::new();
|
set_should_display_text_to_screen(false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if !received_input { continue; }
|
||||||
|
let mut view = String::new();
|
||||||
|
|
||||||
let frame_res = terminal
|
let frame_res = terminal
|
||||||
.draw(|f| url = training_mod_tui::ui(f, &mut app))
|
.draw(|f| url = training_mod_tui::ui(f, &mut app))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
for (i, cell) in frame_res.buffer.content().into_iter().enumerate() {
|
for (i, cell) in frame_res.buffer.content().iter().enumerate() {
|
||||||
write!(&mut view, "{}", cell.symbol).unwrap();
|
match cell.fg {
|
||||||
if i % frame_res.area.width as usize == frame_res.area.width as usize - 1 {
|
Color::Black => write!(&mut view, "{}", &cell.symbol.black()),
|
||||||
write!(&mut view, "\n").unwrap();
|
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()),
|
||||||
write!(&mut view, "\n").unwrap();
|
Color::LightCyan => write!(&mut view, "{}", &cell.symbol.cyan()),
|
||||||
|
Color::Red => write!(&mut view, "{}", &cell.symbol.red()),
|
||||||
if menu::QUICK_MENU_ACTIVE {
|
Color::LightRed => write!(&mut view, "{}", &cell.symbol.bright_red()),
|
||||||
render_text_to_screen(view.as_str());
|
Color::LightGreen => write!(&mut view, "{}", &cell.symbol.bright_green()),
|
||||||
} else {
|
Color::Green => write!(&mut view, "{}", &cell.symbol.green()),
|
||||||
set_should_display_text_to_screen(false);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,13 +2,13 @@ use training_mod_consts::{OnOffSelector, Slider, SubMenu, SubMenuType, Toggle};
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::{Backend},
|
backend::{Backend},
|
||||||
layout::{Constraint, Corner, Direction, Layout},
|
layout::{Constraint, Corner, Direction, Layout},
|
||||||
style::{Color, Modifier, Style},
|
style::{Modifier, Style},
|
||||||
text::Spans,
|
text::{Span, Spans},
|
||||||
widgets::{Tabs, Paragraph, Block, List, ListItem, ListState},
|
widgets::{Tabs, Paragraph, Block, List, ListItem, ListState},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use tui::{backend::TestBackend, Terminal};
|
pub use tui::{backend::TestBackend, Terminal, style::Color};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
mod list;
|
mod list;
|
||||||
|
@ -322,8 +322,13 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
|
||||||
Spans::from(" ".to_owned() + tab)
|
Spans::from(" ".to_owned() + tab)
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let tabs = Tabs::new(titles)
|
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))
|
.style(Style::default().fg(Color::White))
|
||||||
.highlight_style(Style::default().fg(Color::Yellow))
|
.highlight_style(Style::default().fg(Color::Yellow))
|
||||||
.divider("|")
|
.divider("|")
|
||||||
|
@ -359,15 +364,17 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
|
||||||
} else {
|
} else {
|
||||||
" ".to_owned() + i.title
|
" ".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();
|
.collect();
|
||||||
|
|
||||||
let list = List::new(items)
|
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(
|
.highlight_style(
|
||||||
Style::default()
|
Style::default()
|
||||||
.bg(Color::LightBlue)
|
.fg(Color::Green)
|
||||||
.add_modifier(Modifier::BOLD),
|
.add_modifier(Modifier::BOLD),
|
||||||
)
|
)
|
||||||
.highlight_symbol(">> ");
|
.highlight_symbol(">> ");
|
||||||
|
@ -382,8 +389,8 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
|
||||||
|
|
||||||
let help_paragraph = Paragraph::new(
|
let help_paragraph = Paragraph::new(
|
||||||
item_help.unwrap_or("").replace("\"", "") +
|
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]);
|
f.render_widget(help_paragraph, vertical_chunks[2]);
|
||||||
} else {
|
} else {
|
||||||
let (title, help_text, mut sub_menu_str_lists) = app.sub_menu_strs_and_states();
|
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)
|
.start_corner(Corner::TopLeft)
|
||||||
.highlight_style(
|
.highlight_style(
|
||||||
Style::default()
|
Style::default()
|
||||||
.bg(Color::LightGreen)
|
.fg(Color::LightGreen)
|
||||||
.add_modifier(Modifier::BOLD),
|
.add_modifier(Modifier::BOLD),
|
||||||
)
|
)
|
||||||
.highlight_symbol(">> ");
|
.highlight_symbol(">> ");
|
||||||
|
@ -413,7 +420,7 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
|
||||||
let help_paragraph = Paragraph::new(
|
let help_paragraph = Paragraph::new(
|
||||||
help_text.replace("\"", "") +
|
help_text.replace("\"", "") +
|
||||||
"\nA: Select toggle | B: Exit submenu"
|
"\nA: Select toggle | B: Exit submenu"
|
||||||
);
|
).style(Style::default().fg(Color::Cyan));
|
||||||
f.render_widget(help_paragraph, vertical_chunks[2]);
|
f.render_widget(help_paragraph, vertical_chunks[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue