using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using TMPro; namespace QuestAppLauncher { public class SettingsHandler : MonoBehaviour { public GameObject panelContainer; public GameObject openSettingsButton; public GameObject closeSettingsButton; public GameObject settingsContainer; public GameObject gridCols; public GameObject gridColsText; public GameObject gridRows; public GameObject gridRowsText; public GameObject gridPopulation; public GameObject show2DToggle; public Toggle tabsNone; public Toggle tabsAuto; public Toggle tabsCustom; private Config config = new Config(); public void OpenSettings() { Debug.Log("Open Settings"); this.panelContainer.SetActive(false); this.openSettingsButton.SetActive(false); this.closeSettingsButton.SetActive(true); this.settingsContainer.SetActive(true); // Load config ConfigPersistence.LoadConfig(this.config); // Set current cols & rows var colsSlider = this.gridCols.GetComponent(); colsSlider.value = this.config.gridSize.cols; var colsText = this.gridColsText.GetComponent(); colsText.text = string.Format("{0} Cols", this.config.gridSize.cols); var rowsSlider = this.gridRows.GetComponent(); rowsSlider.value = this.config.gridSize.rows; var rowsText = this.gridRowsText.GetComponent(); rowsText.text = string.Format("{0} Rows", this.config.gridSize.rows); // Set 2D toggle this.show2DToggle.GetComponent().SetIsOnWithoutNotify(this.config.show2D); // Set tab mode if (this.config.categoryType.Equals(Config.Category_None, StringComparison.OrdinalIgnoreCase)) { this.tabsNone.isOn = true; } else if (this.config.categoryType.Equals(Config.Category_Auto, StringComparison.OrdinalIgnoreCase)) { this.tabsAuto.isOn = true; } else { this.tabsCustom.isOn = true; } } public void CloseSettings() { // Persist any config changes PersistConfig(); Debug.Log("Close Settings"); this.panelContainer.SetActive(true); this.openSettingsButton.SetActive(true); this.closeSettingsButton.SetActive(false); this.settingsContainer.SetActive(false); } public void DeleteExcludedApksFile() { Debug.Log("Delete Excluded Apk List"); QuestAppLauncher.GridPopulation.DeleteExcludedApksFile(); } public void UpdateGridColText() { var cols = gridCols.GetComponent().value; var colsText = this.gridColsText.GetComponent(); colsText.text = string.Format("{0} Cols", cols); } public void UpdateGridRowText() { var rows = gridRows.GetComponent().value; var rowsText = this.gridRowsText.GetComponent(); rowsText.text = string.Format("{0} Rows", rows); } private void PersistConfig() { bool saveConfig = false; // Update grid size var cols = (int)gridCols.GetComponent().value; var rows = (int)gridRows.GetComponent().value; if (cols != this.config.gridSize.cols || rows != this.config.gridSize.rows) { this.config.gridSize.cols = cols; this.config.gridSize.rows = rows; saveConfig = true; } // Update 2D toggle var show2D = this.show2DToggle.GetComponent().isOn; if (show2D != this.config.show2D) { this.config.show2D = show2D; saveConfig = true; } // Update tabbing string tabMode; if (this.tabsNone.isOn) { tabMode = Config.Category_None; } else if (this.tabsAuto.isOn) { tabMode = Config.Category_Auto; } else { tabMode = Config.Category_Custom; } if (!this.config.categoryType.Equals(tabMode, StringComparison.OrdinalIgnoreCase)) { this.tabsNone.isOn = true; this.config.categoryType = tabMode; saveConfig = true; } // Persist configuration & re-populate if (saveConfig) { ConfigPersistence.SaveConfig(this.config); // Re-populate grid Debug.Log("Re-populating panel"); this.gridPopulation.GetComponent().StartPopulate(); } } } }