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/main.js | |
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/main.js')
-rw-r--r-- | src/app/main.js | 59 |
1 files changed, 51 insertions, 8 deletions
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) => { |