1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-02-17 14:40:31 +00:00

Configurable default menu (#288)

* Allow saving current menu as new defaults

* Save menu defaults in the HTML file. Write html when saving

* Add effect when saving defaults

* Adjust effect size

* Use URL param to save defaults instead of ingame chord

* Update the menu to include checkbox for saving defaults

* Fix menu styling

* Update README

Co-authored-by: asimon-1 <asimon1@protonmail.com>
This commit is contained in:
asimon-1 2021-12-19 17:43:57 -08:00 committed by GitHub
parent 9d1d2ca76b
commit b52112bb12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 19 deletions

View file

@ -85,7 +85,8 @@ The timing of the CPU option can be influenced by the following settings:
## Menu Settings
When multiple options are selected, one of the selected options will be chosen at random. Open / focused menus can be reset by pressing the `X` button. All menus can be reset to the default by pressing the `L` button.
When multiple options are selected, one of the selected options will be chosen at random. Open / focused menus can be reset by pressing the `X` button. All menus can be reset to the default by pressing the `L` button. These defaults can be saved upon exiting the menu by pressing `R` when in-menu. Use this to make a preset that fits your personal training style.
| Feature | Description | Options |
|----------------------|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|

View file

@ -265,7 +265,7 @@ macro_rules! add_onoff_submenu {
};
}
pub fn set_menu_from_url(s: &str) {
pub fn get_menu_from_url(mut menu: TrainingModpackMenu, s: &str) -> TrainingModpackMenu {
let base_url_len = "http://localhost/?".len();
let total_len = s.len();
@ -291,10 +291,9 @@ pub fn set_menu_from_url(s: &str) {
.map(|val| val.parse().unwrap())
.fold(0, bitwise_or);
unsafe {
MENU.set(toggle, bits);
}
menu.set(toggle, bits);
}
menu
}
pub unsafe fn menu_condition(module_accessor: &mut smash::app::BattleObjectModuleAccessor) -> bool {
@ -573,9 +572,21 @@ pub fn spawn_menu() {
.open()
.unwrap();
let last_url = page_response.get_last_url().unwrap();
set_menu_from_url(last_url);
let orig_last_url = page_response.get_last_url().unwrap();
let last_url = &orig_last_url.replace("&save_defaults=1", "");
unsafe {
MENU = get_menu_from_url(MENU, last_url);
}
if last_url.len() != orig_last_url.len() {
// Save as default
unsafe {
DEFAULT_MENU = get_menu_from_url(DEFAULT_MENU, last_url);
write_menu();
}
let menu_defaults_conf_path = "sd:/TrainingModpack/training_modpack_menu_defaults.conf";
std::fs::write(menu_defaults_conf_path, last_url)
.expect("Failed to write default menu conf file");
}
std::fs::write(MENU_CONF_PATH, last_url).expect("Failed to write menu conf file");
unsafe {

View file

@ -9,7 +9,7 @@ use smash::app::{self, lua_bind::*};
use smash::hash40;
use smash::lib::lua_const::*;
pub static DEFAULT_MENU: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
pub static BASE_MENU: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
hitbox_vis: OnOff::On,
stage_hazards: OnOff::Off,
di_state: Direction::empty(),
@ -41,7 +41,8 @@ pub static DEFAULT_MENU: consts::TrainingModpackMenu = consts::TrainingModpackMe
save_state_enable: OnOff::On,
};
pub static mut MENU: TrainingModpackMenu = DEFAULT_MENU;
pub static mut DEFAULT_MENU: TrainingModpackMenu = BASE_MENU;
pub static mut MENU: TrainingModpackMenu = BASE_MENU;
pub static mut FIGHTER_MANAGER_ADDR: usize = 0;
pub static mut STAGE_MANAGER_ADDR: usize = 0;

View file

@ -26,7 +26,7 @@ extern crate num_derive;
use crate::common::*;
use crate::events::{Event, EVENT_QUEUE};
use crate::menu::set_menu_from_url;
use crate::menu::get_menu_from_url;
use skyline::libc::mkdir;
use skyline::nro::{self, NroInfo};
@ -88,12 +88,39 @@ pub fn main() {
release::version_check();
let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.conf";
log!("Checking for previous menu in training_modpack_menu.conf...");
if fs::metadata(menu_conf_path).is_ok() {
log!("Loading previous menu from training_modpack_menu.conf...");
let menu_conf = fs::read(menu_conf_path).unwrap();
if menu_conf.starts_with(b"http://localhost") {
set_menu_from_url(std::str::from_utf8(&menu_conf).unwrap());
log!("Previous menu found, loading from training_modpack_menu.conf");
unsafe {
MENU = get_menu_from_url(MENU, std::str::from_utf8(&menu_conf).unwrap());
}
} else {
log!("Previous menu found but is invalid.");
}
} else {
log!("No previous menu file found.");
}
let menu_defaults_conf_path = "sd:/TrainingModpack/training_modpack_menu_defaults.conf";
log!("Checking for previous menu defaults in training_modpack_menu_defaults.conf...");
if fs::metadata(menu_defaults_conf_path).is_ok() {
let menu_defaults_conf = fs::read(menu_defaults_conf_path).unwrap();
if menu_defaults_conf.starts_with(b"http://localhost") {
log!("Menu defaults found, loading from training_modpack_menu_defaults.conf");
unsafe {
DEFAULT_MENU = get_menu_from_url(
DEFAULT_MENU,
std::str::from_utf8(&menu_defaults_conf).unwrap(),
);
crate::menu::write_menu();
}
} else {
log!("Previous menu defaults found but are invalid.");
}
} else {
log!("No previous menu defaults found.");
}
std::thread::spawn(|| loop {

View file

@ -90,6 +90,37 @@
position: fixed;
z-index: 10;
}
/* Save Defaults Container */
.defaults-checkbox-container {
position: fixed;
right: 50px;
margin-top: 10px;
display: flex;
justify-content: center;
flex-direction: column;
}
/* Checkbox element (hidden) */
#saveDefaults {
position: absolute;
left: -100vw;
}
.checkbox-display {
margin: 10px 70px;
}
/* Displayed Checkbox (unchecked) */
.checkbox-display::after {
content: "\E14C";
color: white;
}
/* Displayed Checkbox (checked) */
#saveDefaults:checked ~ .checkbox-display::after {
content: "\E14B";
}
</style>
</head>
@ -249,6 +280,11 @@
{{/sub_menus}}
<footer id="footer" class="footer l-footer f-u-bold">
<p id="help-text" class="header-desc"></p>
<div class="defaults-checkbox-container">
<label class="header-desc" for="saveDefaults">Save defaults: &#xE0A5;</label>
<input type="checkbox" id="saveDefaults">
<div class="checkbox-display"></div>
</div>
</footer>
<script>
if (isNx) {
@ -261,6 +297,9 @@
window.nx.footer.setAssign('L', '', resetAllSubmenus, {
se: ''
})
window.nx.footer.setAssign('R', '', toggleSaveDefaults, {
se: ''
})
}
function goBackHook() {
// If any submenus are open, close them
@ -274,11 +313,6 @@
playSound('cancel')
fadeOutPage(function () {
window.history.back()
})
var url = "http://localhost/"
var settings = [];
@ -317,7 +351,16 @@
});
});
location.href = url + "?" + decodeURIComponent($.param(settings));
url += "?" + decodeURIComponent($.param(settings));
if ($("#saveDefaults").prop("checked")) {
url += "&save_defaults=1";
}
// console.log(url);
location.href = url;
fadeOutPage(function () {
window.history.back()
})
} else {
// Close any open submenus
$(".qa.is-opened").each(function () { openAnswer(this); });
@ -426,6 +469,15 @@
// Modify the help text in the footer
$("#help-text").text(text);
}
function toggleSaveDefaults() {
// Change the status of the Save Defaults checkbox
var saveDefaultsCheckbox = $("#saveDefaults");
saveDefaultsCheckbox.prop(
"checked",
!saveDefaultsCheckbox.prop("checked")
);
}
</script>
<script>
window.onload = setSettings;