浏览代码

Add functionality to mods tab.

Mod configurations can now be changed and saved.
Still pending optimization to allow required mods to
properly declare optional mods.
Show main UI on interactive event. We shouldn't wait for
remote images to load first.
Daniel Scalzi 7 年之前
父节点
当前提交
60ba7b4f8a
共有 3 个文件被更改,包括 66 次插入16 次删除
  1. 3 2
      app/assets/css/launcher.css
  2. 58 9
      app/assets/js/scripts/settings.js
  3. 5 5
      app/assets/js/scripts/uibinder.js

+ 3 - 2
app/assets/css/launcher.css

@@ -1402,6 +1402,7 @@ input:checked + .toggleSwitchSlider:before {
     border-radius: 50%;
     border-radius: 50%;
     background-color: #c32625;
     background-color: #c32625;
     margin-right: 15px;
     margin-right: 15px;
+    transition: 0.25s ease;
 }
 }
 
 
 .settingsModContent {
 .settingsModContent {
@@ -1430,8 +1431,8 @@ input:checked + .toggleSwitchSlider:before {
     pointer-events: none;
     pointer-events: none;
 }
 }
 
 
-.settingsMod[enabled] .settingsModStatus,
-.settingsSubMod[enabled] .settingsModStatus{
+.settingsMod[enabled] > .settingsModContent > .settingsModMainWrapper > .settingsModStatus,
+.settingsSubMod[enabled] > .settingsModContent > .settingsModMainWrapper > .settingsModStatus {
     background-color: rgb(165, 195, 37);
     background-color: rgb(165, 195, 37);
 }
 }
 
 

+ 58 - 9
app/assets/js/scripts/settings.js

@@ -55,12 +55,12 @@ function initSettingsValidators(){
 function initSettingsValues(){
 function initSettingsValues(){
     const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
     const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
     Array.from(sEls).map((v, index, arr) => {
     Array.from(sEls).map((v, index, arr) => {
-        const gFn = ConfigManager['get' + v.getAttribute('cValue')]
+        const cVal = v.getAttribute('cValue')
+        const gFn = ConfigManager['get' + cVal]
         if(typeof gFn === 'function'){
         if(typeof gFn === 'function'){
             if(v.tagName === 'INPUT'){
             if(v.tagName === 'INPUT'){
                 if(v.type === 'number' || v.type === 'text'){
                 if(v.type === 'number' || v.type === 'text'){
                     // Special Conditions
                     // Special Conditions
-                    const cVal = v.getAttribute('cValue')
                     if(cVal === 'JavaExecutable'){
                     if(cVal === 'JavaExecutable'){
                         populateJavaExecDetails(v.value)
                         populateJavaExecDetails(v.value)
                         v.value = gFn()
                         v.value = gFn()
@@ -75,7 +75,6 @@ function initSettingsValues(){
             } else if(v.tagName === 'DIV'){
             } else if(v.tagName === 'DIV'){
                 if(v.classList.contains('rangeSlider')){
                 if(v.classList.contains('rangeSlider')){
                     // Special Conditions
                     // Special Conditions
-                    const cVal = v.getAttribute('cValue')
                     if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
                     if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
                         let val = gFn()
                         let val = gFn()
                         if(val.endsWith('M')){
                         if(val.endsWith('M')){
@@ -101,12 +100,12 @@ function initSettingsValues(){
 function saveSettingsValues(){
 function saveSettingsValues(){
     const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
     const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
     Array.from(sEls).map((v, index, arr) => {
     Array.from(sEls).map((v, index, arr) => {
-        const sFn = ConfigManager['set' + v.getAttribute('cValue')]
+        const cVal = v.getAttribute('cValue')
+        const sFn = ConfigManager['set' + cVal]
         if(typeof sFn === 'function'){
         if(typeof sFn === 'function'){
             if(v.tagName === 'INPUT'){
             if(v.tagName === 'INPUT'){
                 if(v.type === 'number' || v.type === 'text'){
                 if(v.type === 'number' || v.type === 'text'){
                     // Special Conditions
                     // Special Conditions
-                    const cVal = v.getAttribute('cValue')
                     if(cVal === 'JVMOptions'){
                     if(cVal === 'JVMOptions'){
                         sFn(v.value.split(' '))
                         sFn(v.value.split(' '))
                     } else {
                     } else {
@@ -115,7 +114,6 @@ function saveSettingsValues(){
                 } else if(v.type === 'checkbox'){
                 } else if(v.type === 'checkbox'){
                     sFn(v.checked)
                     sFn(v.checked)
                     // Special Conditions
                     // Special Conditions
-                    const cVal = v.getAttribute('cValue')
                     if(cVal === 'AllowPrerelease'){
                     if(cVal === 'AllowPrerelease'){
                         changeAllowPrerelease(v.checked)
                         changeAllowPrerelease(v.checked)
                     }
                     }
@@ -123,7 +121,6 @@ function saveSettingsValues(){
             } else if(v.tagName === 'DIV'){
             } else if(v.tagName === 'DIV'){
                 if(v.classList.contains('rangeSlider')){
                 if(v.classList.contains('rangeSlider')){
                     // Special Conditions
                     // Special Conditions
-                    const cVal = v.getAttribute('cValue')
                     if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
                     if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
                         let val = Number(v.getAttribute('value'))
                         let val = Number(v.getAttribute('value'))
                         if(val%1 > 0){
                         if(val%1 > 0){
@@ -234,6 +231,7 @@ function settingsSaveDisabled(v){
 /* Closes the settings view and saves all data. */
 /* Closes the settings view and saves all data. */
 settingsNavDone.onclick = () => {
 settingsNavDone.onclick = () => {
     saveSettingsValues()
     saveSettingsValues()
+    saveModConfiguration()
     ConfigManager.save()
     ConfigManager.save()
     switchView(getCurrentView(), VIEWS.landing)
     switchView(getCurrentView(), VIEWS.landing)
 }
 }
@@ -426,6 +424,8 @@ document.getElementById('settingsGameHeight').addEventListener('keydown', (e) =>
  * Mods Tab
  * Mods Tab
  */
  */
 
 
+const settingsModsContainer = document.getElementById('settingsModsContainer')
+
 function resolveModsForUI(){
 function resolveModsForUI(){
     const serv = ConfigManager.getSelectedServer()
     const serv = ConfigManager.getSelectedServer()
 
 
@@ -484,12 +484,12 @@ function parseModulesForUI(mdls, submodules = false, servConf){
                             </div>
                             </div>
                         </div>
                         </div>
                         <label class="toggleSwitch">
                         <label class="toggleSwitch">
-                            <input type="checkbox" ${val ? 'checked' : ''}>
+                            <input type="checkbox" formod="${mdl.getVersionlessID()}" ${val ? 'checked' : ''}>
                             <span class="toggleSwitchSlider"></span>
                             <span class="toggleSwitchSlider"></span>
                         </label>
                         </label>
                     </div>
                     </div>
                     ${mdl.hasSubModules() ? `<div class="settingsSubModContainer">
                     ${mdl.hasSubModules() ? `<div class="settingsSubModContainer">
-                        ${mdl.hasSubModules() ? Object.values(parseModulesForUI(mdl.getSubModules(), true, conf.mods)).join('') : ''}
+                        ${Object.values(parseModulesForUI(mdl.getSubModules(), true, conf.mods)).join('')}
                     </div>` : ''}
                     </div>` : ''}
                 </div>`
                 </div>`
 
 
@@ -506,11 +506,60 @@ function parseModulesForUI(mdls, submodules = false, servConf){
 
 
 }
 }
 
 
+/**
+ * Bind functionality to mod config toggle switches. Switching the value
+ * will also switch the status color on the left of the mod UI.
+ */
+function bindModsToggleSwitch(){
+    const sEls = settingsModsContainer.querySelectorAll('[formod]')
+    Array.from(sEls).map((v, index, arr) => {
+        v.onchange = () => {
+            if(v.checked) {
+                document.getElementById(v.getAttribute('formod')).setAttribute('enabled', '')
+            } else {
+                document.getElementById(v.getAttribute('formod')).removeAttribute('enabled')
+            }
+        }
+    })
+}
+
+
+/**
+ * Save the mod configuration based on the UI values.
+ */
+function saveModConfiguration(){
+    const serv = ConfigManager.getSelectedServer()
+    const modConf = ConfigManager.getModConfiguration(serv)
+    modConf.mods = _saveModConfiguration(modConf.mods)
+    ConfigManager.setModConfiguration(serv, modConf)
+}
+
+/**
+ * Recursively save mod config with submods.
+ * 
+ * @param {Object} modConf Mod config object to save.
+ */
+function _saveModConfiguration(modConf){
+    for(m of Object.entries(modConf)){
+        const val = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`)[0].checked
+        if(typeof m[1] === 'boolean'){
+            modConf[m[0]] = val
+        } else {
+            if(m[1] != null){
+                modConf[m[0]].value = val
+                modConf[m[0]].mods = _saveModConfiguration(modConf[m[0]].mods)
+            }
+        }
+    }
+    return modConf
+}
+
 /**
 /**
  * Prepare the Java tab for display.
  * Prepare the Java tab for display.
  */
  */
 function prepareModsTab(){
 function prepareModsTab(){
     resolveModsForUI()
     resolveModsForUI()
+    bindModsToggleSwitch()
 }
 }
 
 
 /**
 /**

+ 5 - 5
app/assets/js/scripts/uibinder.js

@@ -344,7 +344,7 @@ function setSelectedAccount(uuid){
 // Synchronous Listener
 // Synchronous Listener
 document.addEventListener('readystatechange', function(){
 document.addEventListener('readystatechange', function(){
 
 
-    if (document.readyState === 'complete'){
+    if (document.readyState === 'interactive' || document.readyState === 'complete'){
         if(rscShouldLoad){
         if(rscShouldLoad){
             if(!fatalStartupError){
             if(!fatalStartupError){
                 const data = DistroManager.getDistribution()
                 const data = DistroManager.getDistribution()
@@ -353,9 +353,9 @@ document.addEventListener('readystatechange', function(){
                 showFatalStartupError()
                 showFatalStartupError()
             }
             }
         } 
         } 
-    } else if(document.readyState === 'interactive'){
+    }// else if(document.readyState === 'interactive'){
         //toggleOverlay(true, 'loadingContent')
         //toggleOverlay(true, 'loadingContent')
-    }
+    //}
 
 
     /*if (document.readyState === 'interactive'){
     /*if (document.readyState === 'interactive'){
         
         
@@ -367,14 +367,14 @@ ipcRenderer.on('distributionIndexDone', (event, res) => {
     if(res) {
     if(res) {
         const data = DistroManager.getDistribution()
         const data = DistroManager.getDistribution()
         syncModConfigurations(data)
         syncModConfigurations(data)
-        if(document.readyState === 'complete'){
+        if(document.readyState === 'interactive' || document.readyState === 'complete'){
             showMainUI(data)
             showMainUI(data)
         } else {
         } else {
             rscShouldLoad = true
             rscShouldLoad = true
         }
         }
     } else {
     } else {
         fatalStartupError = true
         fatalStartupError = true
-        if(document.readyState === 'complete'){
+        if(document.readyState === 'interactive' || document.readyState === 'complete'){
             showFatalStartupError()
             showFatalStartupError()
         } else {
         } else {
             rscShouldLoad = true
             rscShouldLoad = true