diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bf0de0c..6330fd0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,11 +47,11 @@ jobs: with: name: plugin path: target/aarch64-skyline-switch/release/libtraining_modpack.nro - - name: Upload menu icons + - name: Upload static files uses: actions/upload-artifact@v2 with: - name: svg - path: src/templates/*.svg + name: static + path: src/static plugin_outside_training_mode: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest @@ -81,7 +81,7 @@ jobs: env: SKYLINE_DIR: atmosphere/contents/01006A800016E000 SMASH_PLUGIN_DIR: atmosphere/contents/01006A800016E000/romfs/skyline/plugins - SMASH_WEB_DIR: atmosphere/contents/01006A800016E000/manual_html/html-document/contents.htdocs + SMASH_WEB_DIR: atmosphere/contents/01006A800016E000/manual_html/html-document/training_modpack.htdocs run: | mkdir -p ${{env.SKYLINE_DIR}} mkdir -p ${{env.SMASH_PLUGIN_DIR}} @@ -96,7 +96,8 @@ jobs: cp libparam_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libparam_hook.nro cp libnro_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libnro_hook.nro cp libnn_hid_hook.nro ${{env.SMASH_PLUGIN_DIR}}/libnn_hid_hook.nro - ls -1 svg/*.svg | xargs -n 1 basename | xargs -L1 -I{} cp svg/{} ${{env.SMASH_WEB_DIR}}/{} + cp -r static/* ${{env.SMASH_WEB_DIR}} + rm ${{env.SMASH_WEB_DIR}}/fonts -r zip -r training_modpack_beta.zip atmosphere - name: Update Release uses: meeDamian/github-release@2.0 diff --git a/README.md b/README.md index ea78219..1a96ba9 100644 --- a/README.md +++ b/README.md @@ -141,39 +141,44 @@ SD Card Root └── 01006A800016E000 ├── manual_html │ └── html-document - │ └── contents.htdocs - │ ├── aerial_delay.svg - │ ├── air_dodge_dir.svg - │ ├── attack_angle.svg - │ ├── buff_state.svg - │ ├── check.svg - │ ├── defensive_state.svg - │ ├── di_state.svg - │ ├── falling_aerials.svg - │ ├── fast_fall.svg - │ ├── fast_fall_delay.svg - │ ├── follow_up.svg - │ ├── frame_advantage.svg - │ ├── full_hop.svg - │ ├── input_delay.svg - │ ├── ledge_delay.svg - │ ├── ledge_state.svg - │ ├── mash_in_neutral.svg - │ ├── mash_state.svg - │ ├── miss_tech_state.svg - │ ├── oos_offset.svg - │ ├── pummel_delay.svg - │ ├── reaction_time.svg - │ ├── save_damage.svg - │ ├── save_state_mirroring.svg - │ ├── sdi_state.svg - │ ├── sdi_strength.svg - │ ├── shield_state.svg - │ ├── shield_tilt.svg - │ ├── stage_hazards.svg - │ ├── tech_state.svg - │ ├── throw_delay.svg - │ └── throw_state.svg + │ └── training_modpack.htdocs + │ ├── css + │ │ └── training_modpack.css + │ ├── img + │ │ ├── aerial_delay.svg + │ │ ├── air_dodge_dir.svg + │ │ ├── attack_angle.svg + │ │ ├── buff_state.svg + │ │ ├── check.svg + │ │ ├── defensive_state.svg + │ │ ├── di_state.svg + │ │ ├── falling_aerials.svg + │ │ ├── fast_fall.svg + │ │ ├── fast_fall_delay.svg + │ │ ├── follow_up.svg + │ │ ├── frame_advantage.svg + │ │ ├── full_hop.svg + │ │ ├── input_delay.svg + │ │ ├── ledge_delay.svg + │ │ ├── ledge_state.svg + │ │ ├── mash_in_neutral.svg + │ │ ├── mash_state.svg + │ │ ├── miss_tech_state.svg + │ │ ├── oos_offset.svg + │ │ ├── pummel_delay.svg + │ │ ├── reaction_time.svg + │ │ ├── save_damage.svg + │ │ ├── save_state_mirroring.svg + │ │ ├── sdi_state.svg + │ │ ├── sdi_strength.svg + │ │ ├── shield_state.svg + │ │ ├── shield_tilt.svg + │ │ ├── stage_hazards.svg + │ │ ├── tech_state.svg + │ │ ├── throw_delay.svg + │ │ └── throw_state.svg + │ └── js + │ └── training_modpack.js └── romfs └── skyline └── plugins diff --git a/src/common/menu.rs b/src/common/menu.rs index 77a30dd..226c3a8 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -573,7 +573,7 @@ pub unsafe fn write_menu() { // Now that we have the html, write it to file // From skyline-web let program_id = get_program_id(); - let htdocs_dir = "contents"; + let htdocs_dir = "training_modpack"; let path = Path::new("sd:/atmosphere/contents") .join(&format!("{:016X}", program_id)) .join(&format!("manual_html/html-document/{}.htdocs/", htdocs_dir)) @@ -593,7 +593,7 @@ pub fn spawn_menu() { let params = unsafe { MENU.to_url_params() }; let page_response = Webpage::new() .background(Background::BlurredScreenshot) - .htdocs_dir("contents") + .htdocs_dir("training_modpack") .boot_display(BootDisplay::BlurredScreenshot) .boot_icon(true) .start_page(&format!("{}{}", fname, params)) diff --git a/src/static/css/training_modpack.css b/src/static/css/training_modpack.css new file mode 100644 index 0000000..aa57bb5 --- /dev/null +++ b/src/static/css/training_modpack.css @@ -0,0 +1,356 @@ +@-moz-document url-prefix() { + @font-face { + font-family: "nintendo_udsgr_std_003"; + src: url("../fonts/nintendo_udsgr_std_003.ttf"); + } + + @font-face { + font-family: "nintendo_ext_003"; + src: url("../fonts/nintendo_ext_003.ttf"); + } +} + +@keyframes background-slide { + 0% { + background-position-x: 0px; + } + + 100% { + background-position-x: 422.4px; + } +} + +.answer-border-outer { + margin-top: 5px; +} + +.button-icon { + height: 53px; + margin-left: 4px; + width: 53px; +} + +.button-icon-wrapper { + align-items: center; + background: #000000; + display: flex; + height: 58px; + margin-left: -1px; + width: 80px; +} + +.button-msg-wrapper { + width: 259px; +} + +.checkbox-display { + margin: 10px 70px; +} + +.checkbox-display::after { + /* Displayed Checkbox (unchecked) */ + color: white; + content: "\E14C"; +} + +.defaults-checkbox-container { + /* Save Defaults Container */ + display: flex; + flex-direction: column; + justify-content: center; + margin-top: 10px; + position: fixed; + right: 50px; +} + +.flex-button { + align-items: center; + display: inline-flex; + flex: 1; + justify-content: center; + text-align: center; + vertical-align: middle; +} + +.footer { + align-items: center; + background: #000000; + display: flex; + height: 73px; + justify-content: center; + position: fixed; + z-index: 10; +} + +.header { + align-items: center; + background: #000000; + border-bottom: 7px solid #000000; + display: flex; + height: 65px; +} + +.header-decoration { + align-items: center; + background: #a80114; + display: inline-flex; + height: 65px; + padding-left: 21px; + width: 101px; +} + +.header-desc { + color: white; +} + +.header-title { + color: #f46264; + font-size: 26px; + line-height: 2.5; +} + +.is-appear { + opacity: 1; +} + +.is-focused .question-border::before { + background: #000000; + box-shadow: none; +} + +.is-focused .question-message { + color: #FFFFFF; + text-shadow: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000, 1px 1px #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; +} + +.is-focused .question.scuffle-thema { + background: #df1624; +} + +.is-focused .scuffle-thema { + background: #df1624; +} + +.is-hidden { + display: none; +} + +.is-opened .question { + bottom: 11px; +} + +.is-opened .question-border::before { + background: #000000; + bottom: 5px; +} + +.is-opened .question-outer { + height: 86px; + width: 100%; +} + +.keyword-button { + background: #d9e4ea; + border: solid 4px #2e3c45; + box-shadow: 1px 1px 6px rgba(24, 24, 24, 0.6); + box-sizing: border-box; + height: 66px; + justify-content: flex-start; + position: relative; + z-index: 0; +} + +.keyword-button-outer { + border: 5px solid transparent; + will-change: transform; +} + +.keyword-message { + color: #2b3940; + font-size: 22px; + padding: 0px 5px; +} + +.l-footer { + bottom: 0px; + left: 0px; + width: 100%; +} + +.l-grid { + display: flex; + flex-wrap: wrap; +} + +.l-header { + box-shadow: 0px 1px 1px #000000; + display: flex; + left: 0px; + position: absolute; + top: 0px; + width: 100%; + z-index: 100; +} + +.l-header-title { + align-items: center; + display: flex; + height: 100%; + justify-content: center; + left: 0px; + position: absolute; + top: 0px; + width: 1280px; +} + +.l-item { + margin: 0px 13px; +} + +.l-main-content { + /* Overwrite padding from keyword stuff. */ + padding: 0px 0px 0px; +} + +.l-qa { + /* Column size */ + flex-basis: 33%; +} + +.l-qa:last-child .qa { + /* Overwrite margin on the last child to avoid overlap with footer */ + margin-bottom: 75px; +} + +.l-qa:last-child .qa.is-opened { + margin-bottom: 0px; +} + +.qa { + display: block; + will-change: scroll-position; +} + +.is-focused { + background: linear-gradient(90deg, rgb(255, 109, 0) 0%, rgb(255, 255, 0) 65%, rgb(255, 109, 0) 70%); + will-change: animation; + animation: background-slide 650ms linear infinite normal; +} + +.question { + align-items: center; + background: #d9e4ea; + bottom: 11px; + display: flex; + left: 11px; + padding: 0px 30px 0px 94px; + position: absolute; + right: 28px; + top: 11px; +} + +.question-border::before { + background: #2e3c45; + bottom: 6px; + box-shadow: 3px 3px 3px rgba(24, 24, 24, 0.5); + content: ''; + left: 6px; + position: absolute; + right: 6px; + top: 6px; +} + +.question-icon { + bottom: 0px; + height: 60px; + left: 2px; + position: absolute; + top: 2px; + transition: opacity 0.2s ease; + width: 60px; +} + +.question-message { + color: #2b3940; + font-size: 23px; + width: 100%; + z-index: 0; +} + +.question-message span { + display: block; + letter-spacing: normal; +} + +.question-outer { + height: 86px; + position: relative; +} + +.question::before { + width: 70px; + background: #000000; + bottom: 0px; + content: ''; + left: 0px; + position: absolute; + top: 0px; +} + +.ret-icon { + display: inline-block; + height: 58px; + transition: opacity 0.2s ease; + width: 58px; +} + +.ret-icon-wrapper { + margin-left: -4px; + position: relative; + will-change: transform; +} + +#saveDefaults { + /* Checkbox element (hidden) */ + left: -100vw; + position: absolute; +} + +#saveDefaults:checked~.checkbox-display::after { + /* Displayed Checkbox (checked) */ + content: "\E14B"; +} + +a { + text-decoration: none; +} + +body { + background: none; + width: 1280px; +} + +body, div, th, td, p, ul, ol, dl, dt, dd, img, h1, h2, h3, h4, h5, h6, footer, header, nav, p, section, span, figure { + margin: 0px; + overflow-wrap: break-word; + padding: 0px; + word-break: normal; + font-family: "nintendo_ext_003", "nintendo_udsgr_std_003"; +} + +img, svg { + opacity: 0; +} + +img.question-icon:not(.toggle) { + /* Fade icons slightly */ + opacity: 0.75; +} + +span { + letter-spacing: 0.01px; +} + +ul, ol { + list-style-type: none; +} \ No newline at end of file diff --git a/src/static/fonts/nintendo_ext_003.ttf b/src/static/fonts/nintendo_ext_003.ttf new file mode 100644 index 0000000..9ce7121 Binary files /dev/null and b/src/static/fonts/nintendo_ext_003.ttf differ diff --git a/src/static/fonts/nintendo_udsgr_std_003.ttf b/src/static/fonts/nintendo_udsgr_std_003.ttf new file mode 100644 index 0000000..38d550f Binary files /dev/null and b/src/static/fonts/nintendo_udsgr_std_003.ttf differ diff --git a/src/templates/aerial_delay.svg b/src/static/img/aerial_delay.svg similarity index 100% rename from src/templates/aerial_delay.svg rename to src/static/img/aerial_delay.svg diff --git a/src/templates/air_dodge_dir.svg b/src/static/img/air_dodge_dir.svg similarity index 100% rename from src/templates/air_dodge_dir.svg rename to src/static/img/air_dodge_dir.svg diff --git a/src/templates/attack_angle.svg b/src/static/img/attack_angle.svg similarity index 100% rename from src/templates/attack_angle.svg rename to src/static/img/attack_angle.svg diff --git a/src/templates/buff_state.svg b/src/static/img/buff_state.svg similarity index 97% rename from src/templates/buff_state.svg rename to src/static/img/buff_state.svg index 71effba..ce075af 100644 --- a/src/templates/buff_state.svg +++ b/src/static/img/buff_state.svg @@ -1,82 +1,82 @@ - - + + diff --git a/src/templates/check.svg b/src/static/img/check.svg similarity index 100% rename from src/templates/check.svg rename to src/static/img/check.svg diff --git a/src/templates/defensive_state.svg b/src/static/img/defensive_state.svg similarity index 100% rename from src/templates/defensive_state.svg rename to src/static/img/defensive_state.svg diff --git a/src/templates/di_state.svg b/src/static/img/di_state.svg similarity index 100% rename from src/templates/di_state.svg rename to src/static/img/di_state.svg diff --git a/src/templates/falling_aerials.svg b/src/static/img/falling_aerials.svg similarity index 100% rename from src/templates/falling_aerials.svg rename to src/static/img/falling_aerials.svg diff --git a/src/templates/fast_fall.svg b/src/static/img/fast_fall.svg similarity index 100% rename from src/templates/fast_fall.svg rename to src/static/img/fast_fall.svg diff --git a/src/templates/fast_fall_delay.svg b/src/static/img/fast_fall_delay.svg similarity index 100% rename from src/templates/fast_fall_delay.svg rename to src/static/img/fast_fall_delay.svg diff --git a/src/templates/follow_up.svg b/src/static/img/follow_up.svg similarity index 100% rename from src/templates/follow_up.svg rename to src/static/img/follow_up.svg diff --git a/src/templates/frame_advantage.svg b/src/static/img/frame_advantage.svg similarity index 100% rename from src/templates/frame_advantage.svg rename to src/static/img/frame_advantage.svg diff --git a/src/templates/full_hop.svg b/src/static/img/full_hop.svg similarity index 100% rename from src/templates/full_hop.svg rename to src/static/img/full_hop.svg diff --git a/src/templates/hitbox_vis.svg b/src/static/img/hitbox_vis.svg similarity index 100% rename from src/templates/hitbox_vis.svg rename to src/static/img/hitbox_vis.svg diff --git a/src/templates/input_delay.svg b/src/static/img/input_delay.svg similarity index 100% rename from src/templates/input_delay.svg rename to src/static/img/input_delay.svg diff --git a/src/templates/ledge_delay.svg b/src/static/img/ledge_delay.svg similarity index 100% rename from src/templates/ledge_delay.svg rename to src/static/img/ledge_delay.svg diff --git a/src/templates/ledge_state.svg b/src/static/img/ledge_state.svg similarity index 100% rename from src/templates/ledge_state.svg rename to src/static/img/ledge_state.svg diff --git a/src/static/img/m_retnormal.svg b/src/static/img/m_retnormal.svg new file mode 100644 index 0000000..9ae8b06 --- /dev/null +++ b/src/static/img/m_retnormal.svg @@ -0,0 +1,9 @@ + + + diff --git a/src/templates/mash_in_neutral.svg b/src/static/img/mash_in_neutral.svg similarity index 100% rename from src/templates/mash_in_neutral.svg rename to src/static/img/mash_in_neutral.svg diff --git a/src/templates/mash_state.svg b/src/static/img/mash_state.svg similarity index 100% rename from src/templates/mash_state.svg rename to src/static/img/mash_state.svg diff --git a/src/templates/miss_tech_state.svg b/src/static/img/miss_tech_state.svg similarity index 100% rename from src/templates/miss_tech_state.svg rename to src/static/img/miss_tech_state.svg diff --git a/src/templates/oos_offset.svg b/src/static/img/oos_offset.svg similarity index 100% rename from src/templates/oos_offset.svg rename to src/static/img/oos_offset.svg diff --git a/src/templates/pummel_delay.svg b/src/static/img/pummel_delay.svg similarity index 99% rename from src/templates/pummel_delay.svg rename to src/static/img/pummel_delay.svg index a8e38c7..f012002 100644 --- a/src/templates/pummel_delay.svg +++ b/src/static/img/pummel_delay.svg @@ -1,116 +1,116 @@ - - + + diff --git a/src/templates/reaction_time.svg b/src/static/img/reaction_time.svg similarity index 100% rename from src/templates/reaction_time.svg rename to src/static/img/reaction_time.svg diff --git a/src/templates/save_damage.svg b/src/static/img/save_damage.svg similarity index 100% rename from src/templates/save_damage.svg rename to src/static/img/save_damage.svg diff --git a/src/templates/save_state_enable.svg b/src/static/img/save_state_enable.svg similarity index 100% rename from src/templates/save_state_enable.svg rename to src/static/img/save_state_enable.svg diff --git a/src/templates/save_state_mirroring.svg b/src/static/img/save_state_mirroring.svg similarity index 100% rename from src/templates/save_state_mirroring.svg rename to src/static/img/save_state_mirroring.svg diff --git a/src/templates/sdi_state.svg b/src/static/img/sdi_state.svg similarity index 100% rename from src/templates/sdi_state.svg rename to src/static/img/sdi_state.svg diff --git a/src/templates/sdi_strength.svg b/src/static/img/sdi_strength.svg similarity index 100% rename from src/templates/sdi_strength.svg rename to src/static/img/sdi_strength.svg diff --git a/src/templates/shield_state.svg b/src/static/img/shield_state.svg similarity index 100% rename from src/templates/shield_state.svg rename to src/static/img/shield_state.svg diff --git a/src/templates/shield_tilt.svg b/src/static/img/shield_tilt.svg similarity index 100% rename from src/templates/shield_tilt.svg rename to src/static/img/shield_tilt.svg diff --git a/src/templates/stage_hazards.svg b/src/static/img/stage_hazards.svg similarity index 100% rename from src/templates/stage_hazards.svg rename to src/static/img/stage_hazards.svg diff --git a/src/templates/tech_state.svg b/src/static/img/tech_state.svg similarity index 100% rename from src/templates/tech_state.svg rename to src/static/img/tech_state.svg diff --git a/src/templates/throw_delay.svg b/src/static/img/throw_delay.svg similarity index 99% rename from src/templates/throw_delay.svg rename to src/static/img/throw_delay.svg index 927e7b2..9cdc69e 100644 --- a/src/templates/throw_delay.svg +++ b/src/static/img/throw_delay.svg @@ -1,127 +1,127 @@ - - + + diff --git a/src/templates/throw_state.svg b/src/static/img/throw_state.svg similarity index 99% rename from src/templates/throw_state.svg rename to src/static/img/throw_state.svg index e6ea8cc..99f815f 100644 --- a/src/templates/throw_state.svg +++ b/src/static/img/throw_state.svg @@ -1,201 +1,201 @@ - - + + diff --git a/src/static/js/training_modpack.js b/src/static/js/training_modpack.js new file mode 100644 index 0000000..8cc210f --- /dev/null +++ b/src/static/js/training_modpack.js @@ -0,0 +1,304 @@ +var isNx = (typeof window.nx !== 'undefined'); +var prevQuestionMsg = null; +var prevFocusedElm = null; + +if (isNx) { + window.nx.footer.setAssign('B', '', goBackHook, {se: ''}); + window.nx.footer.setAssign('X', '', resetSubmenu, {se: ''}); + window.nx.footer.setAssign('L', '', resetAllSubmenus, {se: ''}); + window.nx.footer.setAssign('R', '', toggleSaveDefaults, {se: ''}); +} else { + document.getElementById("body").addEventListener('keypress', (event) => { + switch (event.key) { + case "b": + console.log("b"); + goBackHook(); + break; + case "x": + console.log("x"); + resetSubmenu(); + break; + case "l": + console.log("l"); + resetAllSubmenus(); + break; + case "r": + console.log("r"); + toggleSaveDefaults(); + break; + } + }); +} + +window.onload = setSettings; + +function isTextNode(node) { + return node.nodeType == Node.TEXT_NODE +} + +function closestClass(elem, class_) { + // Returns the closest anscestor (including self) with the given class + if (!elem) { + // Reached the end of the DOM + return null + } else if (elem.classList.contains(class_)) { + // Found it + return elem + } else { + // Didn't find it, go up a level + return closestClass(elem.parentElement, class_); + } +} + +function getElementByXpath(path) { + return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; +} + +function focusQA(e) { + playSound("SeSelectUncheck"); + prevFocusedElm = e; + e.classList.add("is-focused"); +} + +function defocusQA(e) { + if (prevFocusedElm) { + prevFocusedElm.classList.remove('is-focused'); + + } + if (prevQuestionMsg) { + prevQuestionMsg.remove(); + prevQuestionMsg = null; + } +} + +function toggleAnswer(e) { + playSound("SeToggleBtnOn"); + e.classList.toggle("is-opened"); + + // Toggle visibility of child answers + [].forEach.call(e.childNodes, function (child) { + if (!isTextNode(child) && child.classList.contains("answer-border-outer")) { + child.classList.toggle("is-hidden"); + } + }); + + // Toggle visibility of sibling answers + var sibling = e.nextElementSibling; + if (sibling.classList.contains("answer-border-outer")) { + sibling.classList.toggle("is-hidden"); + } +} + +function playSound(label) { + // Valid labels: + // SeToggleBtnFocus + // SeToggleBtnOn + // SeToggleBtnOff + // SeCheckboxFocus + // SeCheckboxOn + // SeCheckboxOff + // SeRadioBtnFocus + // SeRadioBtnOn + // SeSelectCheck + // SeSelectUncheck + // SeBtnDecide + // SeTouchUnfocus + // SeBtnFocus + // SeKeyError + // SeDialogOpen + // SeWebZoomOut + // SeWebZoomIn + // SeWebNaviFocus + // SeWebPointerFocus + // SeFooterFocus + // SeFooterDecideBack + // SeFooterDecideFinish + // SeWebChangeCursorPointer + // SeWebTouchFocus + // SeWebLinkDecide + // SeWebTextboxStartEdit + // SeWebButtonDecide + // SeWebRadioBtnOn + // SeWebCheckboxUncheck + // SeWebCheckboxCheck + // SeWebMenuListOpen + if (isNx) { + window.nx.playSystemSe(label); + } else { + console.log("Sound Effect: " + label); + } +} + +function goBackHook() { + // If any submenus are open, close them + // Otherwise if all submenus are closed, exit the menu and return to the game + + if (document.querySelectorAll(".qa.is-opened").length == 0) { + // If all submenus are closed, exit and return through localhost + playSound("SeFooterDecideBack"); + var url = "http://localhost/"; + + var settings = new Map(); + + // Collect settings for toggles + + [].forEach.call(document.querySelectorAll("ul.l-grid"), function (toggle) { + var section = toggle.id; + var val = ""; + + [].forEach.call(toggle.childNodes, function (child) { + if (!isTextNode(child) && child.querySelectorAll(".is-appear").length) { + val += child.getAttribute("val") + ","; + }; + }); + + settings.set(section,val); + }); + + // Collect settings for OnOffs + [].forEach.call(document.querySelectorAll("div.onoff"), function (onoff) { + var section = onoff.id; + var val = ""; + if (onoff.querySelectorAll(".is-appear").length) { + val = "1"; + } else { + val = "0"; + } + settings.set(section,val); + }); + + url += "?"; + settings.forEach((val, section) => { url += section + "=" + val + "&" } ); + + if (document.getElementById("saveDefaults").checked) { + url += "save_defaults=1"; + } else { + url = url.slice(0, -1); + } + + if (isNx) { + window.location.href = url; + } else { + console.log(url); + } + } else { + // Close any open submenus + [].forEach.call(document.querySelectorAll(".qa.is-opened"), function (submenu) { toggleAnswer(submenu); }); + } +} + +function clickToggle(e) { + playSound("SeCheckboxOn"); + var toggleOptions = e.querySelector(".toggle"); + if (e.querySelector(".is-single-option")) { // Single-option submenu + // Deselect all submenu options + closestClass(e, "l-qa").querySelector(".toggle").classList.remove("is-appear"); + closestClass(e, "l-qa").querySelector(".toggle").classList.add("is-hidden"); + // Then set the current one as the active setting + toggleOptions.classList.add("is-appear"); + toggleOptions.classList.remove("is-hidden"); + } else { // Multi-option submenu + toggleOptions.classList.toggle("is-appear"); + toggleOptions.classList.toggle("is-hidden"); + } +} + +function getParams(url) { + var regex = /[?&]([^=#]+)=([^]*)/g, + params = {}, + match; + while (match = regex.exec(url)) { + params[match[1]] = match[2]; + } + return params; +} + +function setSettings() { + // Get settings from the URL GET parameters + const settings = getParams(document.URL); + + // Set Toggles + [].forEach.call(document.querySelectorAll("ul.l-grid"), function (toggle) { + var section = toggle.id; + var section_setting = decodeURIComponent(settings[section]); + + [].forEach.call(toggle.querySelectorAll("li"), function (child) { + var e = child.querySelector("img.toggle"); + if (section_setting.split(",").includes(child.getAttribute("val"))) { + e.classList.add("is-appear"); + e.classList.remove("is-hidden"); + } else { + e.classList.remove("is-appear"); + e.classList.add("is-hidden"); + }; + }); + }); + + // Set OnOffs + [].forEach.call(document.querySelectorAll("div.onoff"), function (onOff) { + var section = onOff.id; + var section_setting = decodeURIComponent(settings[section]); + var e = onOff.querySelector("img.toggle"); + if (section_setting == "1") { + e.classList.add("is-appear"); + e.classList.remove("is-hidden"); + } else { + e.classList.remove("is-appear"); + e.classList.add("is-hidden"); + }; + }); +} + +function resetSubmenu() { + // Resets any open or focused submenus to the default values + playSound("SeToggleBtnOff"); + [].forEach.call(document.querySelectorAll("[default*='is-appear']"), function (item) { + if (isSubmenuFocused(item)) { + item.classList.add("is-appear"); + item.classList.remove("is-hidden"); + } + }); + + [].forEach.call(document.querySelectorAll("[default*='is-hidden']"), function (item) { + if (isSubmenuFocused(item)) { + item.classList.remove("is-appear"); + item.classList.add("is-hidden"); + } + }); +} + +function isSubmenuFocused(elem) { + // Return true if the element is in a submenu which is either focused or opened + return ( + closestClass(elem, "l-qa").querySelectorAll(".is-opened, .is-focused").length + || closestClass(elem, "is-focused") + ) +} + +function resetAllSubmenus() { + // Resets all submenus to the default values + if (confirm("Are you sure that you want to reset all menu settings to the default?")) { + playSound("SeToggleBtnOff"); + [].forEach.call(document.querySelectorAll("[default*='is-appear']"), function (item) { + item.classList.add("is-appear"); + item.classList.remove("is-hidden"); + }); + + [].forEach.call(document.querySelectorAll("[default*='is-hidden']"), function (item) { + item.classList.remove("is-appear"); + item.classList.add("is-hidden"); + }); + } +} + +function setHelpText(text) { + // Modify the help text in the footer + document.getElementById("help-text").innerText = text; +} + +function toggleSaveDefaults() { + // Change the status of the Save Defaults checkbox + playSound("SeCheckboxOn"); + var saveDefaultsCheckbox = document.getElementById("saveDefaults"); + saveDefaultsCheckbox.checked = !saveDefaultsCheckbox.checked; +} \ No newline at end of file diff --git a/src/templates/menu.html b/src/templates/menu.html index 09e0240..37b52e5 100644 --- a/src/templates/menu.html +++ b/src/templates/menu.html @@ -1,487 +1,117 @@ - - - -
- - -Reset Current Menu:
-Reset All Menus:
-