1
0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2026-01-22 02:10:24 +00:00

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>
This commit is contained in:
jugeeya
2022-12-29 20:09:22 -08:00
committed by GitHub
parent 9a7b5fdf85
commit 52e3528292
10 changed files with 921 additions and 186 deletions

View File

@@ -12,7 +12,7 @@ use std::collections::HashMap;
use serde_json::{Map, json};
pub use tui::{backend::TestBackend, style::Color, Terminal};
mod gauge;
pub mod gauge;
mod list;
use crate::gauge::{DoubleEndedGauge, GaugeState};
@@ -95,7 +95,7 @@ impl<'a> App<'a> {
}
/// Returns the id of the currently selected tab
fn tab_selected(&self) -> &str {
pub fn tab_selected(&self) -> &str {
self.tabs
.items
.get(self.tabs.state.selected().unwrap())
@@ -221,7 +221,7 @@ impl<'a> App<'a> {
/// 3: ListState for toggles, ListState::new() for slider
/// TODO: Refactor return type into a nice struct
pub fn sub_menu_strs_and_states(
&mut self,
&self,
) -> (&str, &str, Vec<(Vec<(bool, &str)>, ListState)>) {
(
self.sub_menu_selected().submenu_title,
@@ -254,7 +254,7 @@ impl<'a> App<'a> {
/// 1: Help text
/// 2: Reference to self.selected_sub_menu_slider
/// TODO: Refactor return type into a nice struct
pub fn sub_menu_strs_for_slider(&mut self) -> (&str, &str, &DoubleEndedGauge) {
pub fn sub_menu_strs_for_slider(&self) -> (&str, &str, &DoubleEndedGauge) {
let slider = match SubMenuType::from_str(self.sub_menu_selected()._type) {
SubMenuType::SLIDER => &self.selected_sub_menu_slider,
_ => {
@@ -780,6 +780,12 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
}
// Collect settings
to_json(app)
// TODO: Add saveDefaults
}
pub fn to_json(app: &App) -> String {
let mut settings = Map::new();
for key in app.menu_items.keys() {
for list in &app.menu_items.get(key).unwrap().lists {
@@ -803,6 +809,4 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) -> String {
}
}
serde_json::to_string(&settings).unwrap()
// TODO: Add saveDefaults
}

View File

@@ -15,16 +15,21 @@ impl<T: Clone> MultiStatefulList<T> {
}
pub fn idx_to_list_idx(&self, idx: usize) -> (usize, usize) {
self.idx_to_list_idx_opt(idx).unwrap_or((0, 0))
}
pub fn idx_to_list_idx_opt(&self, idx: usize) -> Option<(usize, usize)> {
for list_section in 0..self.lists.len() {
let list_section_min_idx = (self.total_len as f32 / self.lists.len() as f32).ceil() as usize * list_section;
let list_section_max_idx = std::cmp::min(
(self.total_len as f32 / self.lists.len() as f32).ceil() as usize * (list_section + 1),
self.total_len);
if (list_section_min_idx..list_section_max_idx).contains(&idx) {
return (list_section, idx - list_section_min_idx)
return Some((list_section, idx - list_section_min_idx));
}
}
(0, 0)
None
}
fn list_idx_to_idx(&self, list_idx: (usize, usize)) -> usize {