From bf7bd0993714f20fd0ab360de956378113e1d9c2 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 3 Jan 2022 00:43:45 +0100 Subject: 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. --- src/app/index.html | 10 ++++----- src/app/main.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 13 deletions(-) (limited to 'src/app') 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 @@
%%gui.mods%%
- - - - - + + + + +
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 += `
${mods.enabled[i].Name}
`; + + let newmod = (name, extra) => { + if (! extra) {extra = ""} + modsdiv.innerHTML += `
${name}${extra}
`; } - for (let i = 0; i < mods.disabled.length; i++) { - modsdiv.innerHTML += `
${mods.disabled[i].Name} - Disabled
`; - } + 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) => { -- cgit v1.2.3