1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 00:46:34 +00:00

Initial tests; need layout.arc changes for font glyphs to not be glitchy?

This commit is contained in:
jugeeya 2023-08-08 13:51:16 -07:00 committed by GitHub
parent cfa659905f
commit 17004fcd47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 176 additions and 47 deletions

View file

@ -15,6 +15,7 @@ bitflags = "1.2.1"
parking_lot = { version = "0.12.0", features = ["nightly"] }
include-flate = "0.1.4"
lazy_static = "1.4.0"
libc-nnsdk = "0.3.0"
modular-bitfield = "0.11.2"
owo-colors = "2.1.0"
once_cell = "1.12.0"

View file

@ -42,6 +42,125 @@ pub fn button_mapping(
}
}
pub fn name_to_font_glyph(name: &str, style: ControllerStyle) -> Option<u16> {
let is_gcc = style == ControllerStyle::GCController;
let button = ButtonConfig::from_name(name)?;
Some(match button {
ButtonConfig::A => {
if is_gcc {
0xE202
} else {
0xE0E0
}
}
ButtonConfig::B => {
if is_gcc {
0xE203
} else {
0xE0E1
}
}
ButtonConfig::X => {
if is_gcc {
0xE206
} else {
0xE0E2
}
}
ButtonConfig::Y => {
if is_gcc {
0xE207
} else {
0xE0E3
}
}
ButtonConfig::L => {
if is_gcc {
return None;
} else {
0xE0E4
}
}
ButtonConfig::R => {
if is_gcc {
0xE205
} else {
0xE0E5
}
}
ButtonConfig::ZL => {
if is_gcc {
0xE204
} else {
0xE0E6
}
}
ButtonConfig::ZR => {
if is_gcc {
0xE208
} else {
0xE0E7
}
}
ButtonConfig::DpadUp => {
if is_gcc {
0xE209
} else {
0xE0EB
}
}
ButtonConfig::DpadDown => {
if is_gcc {
0xE20A
} else {
0xE0EC
}
}
ButtonConfig::DpadLeft => {
if is_gcc {
0xE20B
} else {
0xE0ED
}
}
ButtonConfig::DpadRight => {
if is_gcc {
0xE20C
} else {
0xE0EE
}
}
ButtonConfig::Plus => {
if is_gcc {
0xE20D
} else {
0xE0EF
}
}
ButtonConfig::Minus => {
if is_gcc {
return None;
} else {
0xE0F0
}
}
ButtonConfig::LStick => {
if is_gcc {
return None;
} else {
0xE104
}
}
ButtonConfig::RStick => {
if is_gcc {
return None;
} else {
0xE105
}
}
})
}
#[derive(Debug, EnumIter, PartialEq)]
pub enum ButtonCombo {
OpenMenu,

View file

@ -1,12 +1,18 @@
use std::collections::HashMap;
use lazy_static::lazy_static;
use parking_lot::Mutex;
use skyline::nn::ui2d::*;
use smash::ui2d::{SmashPane, SmashTextBox};
use training_mod_tui::gauge::GaugeState;
use training_mod_tui::{App, AppPage};
use crate::{common, common::menu::QUICK_MENU_ACTIVE, input::*};
use crate::common::button_config::name_to_font_glyph;
use crate::{common, common::menu::QUICK_MENU_ACTIVE};
// TODO: Let's just use the icon font for all text
lazy_static! {
static ref ICON_FONT: Mutex<u64> = Mutex::new(0);
static ref NORMAL_FONT: Mutex<u64> = Mutex::new(0);
}
pub static NUM_MENU_TEXT_OPTIONS: usize = 33;
pub static _NUM_MENU_TABS: usize = 3;
@ -53,24 +59,6 @@ const BG_LEFT_SELECTED_WHITE_COLOR: ResColor = ResColor {
a: 255,
};
lazy_static! {
static ref GCC_BUTTON_MAPPING: HashMap<&'static str, u16> = HashMap::from([
("L", 0xE204),
("R", 0xE205),
("X", 0xE206),
("Y", 0xE207),
("Z", 0xE208)
]);
static ref PROCON_BUTTON_MAPPING: HashMap<&'static str, u16> = HashMap::from([
("L", 0xE0E4),
("R", 0xE0E5),
("X", 0xE0E2),
("Y", 0xE0E3),
("ZL", 0xE0E6),
("ZR", 0xE0E7)
]);
}
unsafe fn render_submenu_page(app: &App, root_pane: &Pane) {
let tab_selected = app.tab_selected();
let tab = app.menu_items.get(tab_selected).unwrap();
@ -198,7 +186,20 @@ unsafe fn render_toggle_page(app: &App, root_pane: &Pane) {
}
});
title_text.set_text_string(name);
let p1_controller_style = (*common::menu::P1_CONTROLLER_STATE.data_ptr()).style;
let potential_font_glyph = name_to_font_glyph(name, p1_controller_style);
if let Some(font_glyph) = potential_font_glyph {
title_text.p_font = *ICON_FONT.data_ptr() as *const libc::c_void;
title_text.set_text_string("");
let it = title_text.text_buf as *mut u16;
title_text.text_len = 1;
*it = font_glyph;
*(it.add(1)) = 0x0;
} else {
// title_text.p_font = *NORMAL_FONT.data_ptr() as *const libc::c_void;
title_text.set_text_string(name);
}
menu_button
.find_pane_by_name_recursive("check")
.unwrap()
@ -405,31 +406,16 @@ pub unsafe fn draw(root_pane: &Pane) {
};
let tab_titles = [prev_tab, tab_selected, next_tab].map(|idx| app_tabs[idx]);
let is_gcc =
(*common::menu::P1_CONTROLLER_STATE.data_ptr()).style == ControllerStyle::GCController;
let button_mapping = if is_gcc {
GCC_BUTTON_MAPPING.clone()
} else {
PROCON_BUTTON_MAPPING.clone()
};
let p1_controller_style = (*common::menu::P1_CONTROLLER_STATE.data_ptr()).style;
let (x_key, y_key, l_key, r_key, zl_key, zr_key, z_key) = (
button_mapping.get("X"),
button_mapping.get("Y"),
button_mapping.get("L"),
button_mapping.get("R"),
button_mapping.get("ZL"),
button_mapping.get("ZR"),
button_mapping.get("Z"),
let (left_tab_key, right_tab_key, save_defaults_key, reset_current_key, reset_all_key) = (
name_to_font_glyph("Pro ZL; GCC L", p1_controller_style),
name_to_font_glyph("Pro ZR; GCC R", p1_controller_style),
name_to_font_glyph("X", p1_controller_style),
name_to_font_glyph("Pro R; GCC Z", p1_controller_style),
name_to_font_glyph("Y", p1_controller_style),
);
let (left_tab_key, right_tab_key, save_defaults_key, reset_current_key, reset_all_key) =
if is_gcc {
(l_key, r_key, x_key, z_key, y_key)
} else {
(zl_key, zr_key, x_key, r_key, y_key)
};
[
(left_tab_key, "LeftTab"),
(None, "CurrentTab"),
@ -449,12 +435,13 @@ pub unsafe fn draw(root_pane: &Pane) {
.unwrap()
.as_textbox();
icon_pane.set_text_string("");
*ICON_FONT.lock() = icon_pane.p_font as u64;
// Left/Right tabs have keys
if let Some(key) = key {
let it = icon_pane.text_buf as *mut u16;
icon_pane.text_len = 1;
*it = **key;
*it = *key;
*(it.add(1)) = 0x0;
}
@ -465,6 +452,7 @@ pub unsafe fn draw(root_pane: &Pane) {
help_pane.set_color(255, 255, 0, 255);
}
help_pane.set_text_string(tab_titles[idx]);
*NORMAL_FONT.lock() = help_pane.p_font as u64;
});
[
(save_defaults_key, "SaveDefaults", "Save Defaults"),
@ -482,7 +470,7 @@ pub unsafe fn draw(root_pane: &Pane) {
icon_pane.set_text_string("");
let it = icon_pane.text_buf as *mut u16;
icon_pane.text_len = 1;
*it = *key.unwrap();
*it = key.unwrap();
*(it.add(1)) = 0x0;
key_help_pane

View file

@ -1466,7 +1466,6 @@ pub enum ButtonConfig {
}
impl ButtonConfig {
// Should we use the font glyphs? Or do that special casing in the menu?
pub fn as_str(self) -> &'static str {
match self {
ButtonConfig::A => "A",
@ -1487,6 +1486,28 @@ impl ButtonConfig {
ButtonConfig::RStick => "Right Stick Press",
}
}
pub fn from_name(name: &str) -> Option<ButtonConfig> {
Some(match name {
"A" => ButtonConfig::A,
"B" => ButtonConfig::B,
"X" => ButtonConfig::X,
"Y" => ButtonConfig::Y,
"Pro L" => ButtonConfig::L,
"Pro R; GCC Z" => ButtonConfig::R,
"Pro ZL; GCC L" => ButtonConfig::ZL,
"Pro ZR; GCC R" => ButtonConfig::ZR,
"DPad Up" => ButtonConfig::DpadUp,
"DPad Down" => ButtonConfig::DpadDown,
"DPad Left" => ButtonConfig::DpadLeft,
"DPad Right" => ButtonConfig::DpadRight,
"Plus" => ButtonConfig::Plus,
"Minus" => ButtonConfig::Minus,
"Left Stick Press" => ButtonConfig::LStick,
"Right Stick Press" => ButtonConfig::RStick,
_ => return None,
})
}
}
impl ToggleTrait for ButtonConfig {