diff options
author | 0neGal <mail@0negal.com> | 2022-01-03 00:43:45 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-01-03 00:43:45 +0100 |
commit | bf7bd0993714f20fd0ab360de956378113e1d9c2 (patch) | |
tree | 9ba692562f64ed86151617756cfd214e57c8b25d /src/app | |
parent | 9c4b2aa7bfe2a96354f968c23a98213995242380 (diff) | |
download | Viper-bf7bd0993714f20fd0ab360de956378113e1d9c2.tar.gz Viper-bf7bd0993714f20fd0ab360de956378113e1d9c2.zip |
fully working GUI functionality
Smoothly updates and works flawlessly, the only thing that really needs
improvements is the design and on top of that installing mods from a Zip
file over folder.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/index.html | 10 | ||||
-rw-r--r-- | src/app/main.js | 59 |
2 files changed, 56 insertions, 13 deletions
diff --git a/src/app/index.html b/src/app/index.html index ffc31a6..88cfbb5 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -31,11 +31,11 @@ <div class="line"> <div class="text" id="modcount">%%gui.mods%%</div> <div class="buttons"> - <button id="removemod">%%gui.mods.remove%%</button> - <button id="removeall">%%gui.mods.removeall%%</button> - <button id="togglemod">%%gui.mods.toggle%%</button> - <button id="toggleall">%%gui.mods.toggleall%%</button> - <button id="installmod">%%gui.mods.install%%</button> + <button id="removemod" onclick="selected().remove()">%%gui.mods.remove%%</button> + <button id="removeall" onclick="selected(true).remove()">%%gui.mods.removeall%%</button> + <button id="togglemod" onclick="selected().toggle()">%%gui.mods.toggle%%</button> + <button id="toggleall" onclick="selected(true).toggle(true)">%%gui.mods.toggleall%%</button> + <button id="installmod" onclick="installmod()">%%gui.mods.install%%</button> </div> </div> </div> diff --git a/src/app/main.js b/src/app/main.js index c500ba3..f903c29 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -45,18 +45,57 @@ function setButtons(state) { } } +let lastselected = ""; function select(entry) { - let entries = document.querySelectorAll("#modsdiv .mod"); + let entries = document.querySelectorAll("#modsdiv .mod span"); for (let i = 0; i < entries.length; i++) { if (entries[i].innerHTML == entry) { - entries[i].classList.add("selected"); + lastselected = entry; + entries[i].parentElement.classList.add("selected"); } else { - entries[i].classList.remove("selected"); + entries[i].parentElement.classList.remove("selected"); } } } +function selected(all) { + let selected = ""; + if (all) { + selected = "allmods" + } else { + selected = document.querySelector(".mod.selected span"); + if (selected != null) { + selected = selected.innerHTML; + } else { + alert(lang("gui.mods.nothingselected")); + return { + remove: () => {}, + toggle: () => {}, + } + } + } + + return { + remove: () => { + if (selected == "allmods") { + if (! confirm(lang("gui.mods.removeall.confirm"))) { + return; + } + } + + ipcRenderer.send("removemod", selected) + }, + toggle: () => { + ipcRenderer.send("togglemod", selected) + } + } +} + +function installmod() { + ipcRenderer.send("installmod") +} + ipcRenderer.on("ns-updated", () => {setButtons(true)}) ipcRenderer.on("ns-updating", () => {setButtons(false)}) @@ -67,15 +106,19 @@ ipcRenderer.on("newpath", (event, newpath) => { ipcRenderer.on("log", (event, msg) => {log(msg)}) ipcRenderer.on("mods", (event, mods) => { + console.log("refreshed mods") modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; - for (let i = 0; i < mods.enabled.length; i++) { - modsdiv.innerHTML += `<div onclick="select('${mods.enabled[i].Name}')" class="mod">${mods.enabled[i].Name}</div>`; + + let newmod = (name, extra) => { + if (! extra) {extra = ""} + modsdiv.innerHTML += `<div onclick="select('${name}')" class="mod"><span>${name}</span>${extra}</div>`; } - for (let i = 0; i < mods.disabled.length; i++) { - modsdiv.innerHTML += `<div onclick="select('${mods.disabled[i].Name} - Disabled')" class="mod">${mods.disabled[i].Name} - Disabled</div>`; - } + for (let i = 0; i < mods.enabled.length; i++) {newmod(mods.enabled[i].Name)} + for (let i = 0; i < mods.disabled.length; i++) {newmod(mods.disabled[i].Name, " - Disabled")} + + select(lastselected); }) ipcRenderer.on("version", (event, versions) => { |