Persistent Settings (#234)

* modularize tabs-style menus

* make remix properties use modular design

* add persistent settings
This commit is contained in:
minenice55
2023-01-24 14:31:49 -05:00
committed by GitHub
parent 891daf869a
commit 9cbd353506
35 changed files with 15925 additions and 16579 deletions

View File

@ -9,7 +9,7 @@ namespace HeavenStudio.Editor
{
public class TabButton : MonoBehaviour
{
[SerializeField] GameObject Content;
public GameObject Content;
public void OnClick()
{

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -10,6 +11,9 @@ namespace HeavenStudio.Editor
public class TabsManager : MonoBehaviour
{
[SerializeField] GameObject activeContent;
[SerializeField] public Transform contentHolder;
[SerializeField] public Transform buttonsHolder;
[SerializeField] private GameObject buttonPrefab;
public void SetActiveContent(GameObject content)
{
@ -38,5 +42,49 @@ namespace HeavenStudio.Editor
activeContent.GetComponent<TabsContent>().OnCloseTab();
}
}
public List<GameObject> GenerateTabs(TabsEntry[] tabs)
{
List<GameObject> tabContents = new List<GameObject>();
bool madeFirst = false;
foreach(var tab in tabs)
{
var button = Instantiate(buttonPrefab, buttonsHolder);
button.GetComponentInChildren<TMP_Text>().text = tab.name;
var tabContent = Instantiate(tab.tabPrefab, contentHolder);
if(!madeFirst)
{
madeFirst = true;
SetActiveContent(tabContent);
}
else
{
tabContent.SetActive(false);
}
button.GetComponent<TabButton>().Content = tabContent;
tabContents.Add(tabContent);
}
return tabContents;
}
public void CleanTabs()
{
foreach(Transform child in buttonsHolder)
{
Destroy(child.gameObject);
}
foreach(Transform child in contentHolder)
{
child.GetComponent<TabsContent>()?.OnCloseTab();
Destroy(child.gameObject);
}
}
[Serializable]
public struct TabsEntry
{
public string name;
public GameObject tabPrefab;
}
}
}

View File

@ -15,7 +15,8 @@ namespace HeavenStudio.Editor
{
if (Editor.MouseInRectTransform(transform.GetChild(i).GetComponent<RectTransform>()))
{
eventParameterManager.canDisable = false;
if (eventParameterManager != null)
eventParameterManager.canDisable = false;
}
}
}

View File

@ -13,9 +13,10 @@ using TMPro;
using Starpelly;
using SFB;
using HeavenStudio.Editor;
using HeavenStudio.Common;
using HeavenStudio.Editor.Track;
using HeavenStudio.Util;
using HeavenStudio.StudioDance;
using System.IO.Compression;
using System.Text;
@ -42,6 +43,7 @@ namespace HeavenStudio.Editor
[SerializeField] private Timeline Timeline;
[SerializeField] private TMP_Text GameEventSelectorTitle;
[SerializeField] private TMP_Text BuildDateDisplay;
[SerializeField] public StudioDanceManager StudioDanceManager;
[Header("Toolbar")]
[SerializeField] private Button NewBTN;
@ -75,6 +77,7 @@ namespace HeavenStudio.Editor
public bool editingInputField = false;
public bool inAuthorativeMenu = false;
public bool isCursorEnabled = true;
public bool isDiscordEnabled = true;
public bool isShortcutsEnabled { get { return (!inAuthorativeMenu) && (!editingInputField); } }
@ -119,6 +122,8 @@ namespace HeavenStudio.Editor
UpdateEditorStatus(true);
BuildDateDisplay.text = GlobalGameManager.buildTime;
isCursorEnabled = PersistentDataManager.gameSettings.editorCursorEnable;
isDiscordEnabled = PersistentDataManager.gameSettings.discordRPCEnable;
}
public void AddIcon(Minigames.Minigame minigame)
@ -521,7 +526,12 @@ namespace HeavenStudio.Editor
private void UpdateEditorStatus(bool updateTime)
{
if (discordDuringTesting || !Application.isEditor)
DiscordRPC.DiscordRPC.UpdateActivity("In Editor", $"{remixName}", updateTime);
{
if (isDiscordEnabled)
{ DiscordRPC.DiscordRPC.UpdateActivity("In Editor", $"{remixName}", updateTime);
Debug.Log("Discord status updated");
}
}
}
public string GetJson()

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
@ -8,6 +9,7 @@ using TMPro;
using Starpelly;
using HeavenStudio.Common;
using HeavenStudio.Editor.Track;
namespace HeavenStudio.Editor
@ -26,7 +28,16 @@ namespace HeavenStudio.Editor
private void Awake()
{
theme = JsonConvert.DeserializeObject<Theme>(ThemeTXT.text);
if (File.Exists(Application.persistentDataPath + "/editorTheme.json"))
{
string json = File.ReadAllText(Application.persistentDataPath + "/editorTheme.json");
theme = JsonConvert.DeserializeObject<Theme>(json);
}
else
{
PersistentDataManager.SaveTheme(ThemeTXT.text);
theme = JsonConvert.DeserializeObject<Theme>(ThemeTXT.text);
}
}
private void Start()

View File

@ -16,7 +16,24 @@ namespace HeavenStudio.Editor
[Header("Containers")]
[SerializeField] ChartInfoProperties[] containers;
public DynamicBeatmap chart;
[Header("Tabs")]
[SerializeField] private TabsManager.TabsEntry[] tabs;
[Header("Property Prefabs")]
[SerializeField] public GameObject IntegerP;
[SerializeField] public GameObject FloatP;
[SerializeField] public GameObject BooleanP;
[SerializeField] public GameObject DropdownP;
[SerializeField] public GameObject ColorP;
[SerializeField] public GameObject StringP;
[Header("Layout Prefabs")]
[SerializeField] public GameObject DividerP;
[SerializeField] public GameObject HeaderP;
[SerializeField] public GameObject SubHeaderP;
[NonSerialized] public DynamicBeatmap chart;
List<GameObject> tabContents;
private void Start() { }
@ -24,27 +41,28 @@ namespace HeavenStudio.Editor
{
if (dialog.activeSelf)
{
tabsManager.CloseContent();
Editor.instance.canSelect = true;
Editor.instance.inAuthorativeMenu = false;
dialog.SetActive(false);
tabsManager.CleanTabs();
tabContents = null;
}
else
{
ResetAllDialogs();
foreach (var container in containers)
{
container.Init(this);
}
tabsManager.OpenContent();
Editor.instance.canSelect = false;
Editor.instance.inAuthorativeMenu = true;
dialog.SetActive(true);
chart = GameManager.instance.Beatmap;
chart["propertiesmodified"] = true;
tabContents = tabsManager.GenerateTabs(tabs);
foreach (var tab in tabContents)
{
tab.GetComponent<ChartInfoProperties>().Init(this);
}
}
}

View File

@ -26,56 +26,60 @@ namespace HeavenStudio.Editor
[Header("Editable Properties")]
[SerializeField] RemixPropertiesDialog.PropertyTag[] tags;
bool initialized = false;
public void Init(RemixPropertiesDialog diag)
{
dialog = diag;
dialog.SetupDialog(tags, this);
initialized = true;
}
public void AddParam(RemixPropertiesDialog diag, string propertyName, object type, string caption, bool isReadOnly = false, string tooltip = "")
{
GameObject prefab = IntegerP;
GameObject prefab = diag.IntegerP;
GameObject input;
var objType = type.GetType();
if (objType == typeof(EntityTypes.Integer))
{
prefab = IntegerP;
prefab = diag.IntegerP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(EntityTypes.Float))
{
prefab = FloatP;
prefab = diag.FloatP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (type is bool)
{
prefab = BooleanP;
prefab = diag.BooleanP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<BoolChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType.IsEnum)
{
prefab = DropdownP;
prefab = diag.DropdownP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<EnumChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(Color))
{
prefab = ColorP;
prefab = diag.ColorP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<ColorChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(string))
{
prefab = StringP;
prefab = diag.StringP;
input = InitPrefab(prefab, tooltip);
var property = input.GetComponent<StringChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
@ -89,18 +93,18 @@ namespace HeavenStudio.Editor
public void AddDivider(RemixPropertiesDialog diag)
{
InitPrefab(DividerP);
InitPrefab(diag.DividerP);
}
public void AddHeader(RemixPropertiesDialog diag, string text)
{
var input = InitPrefab(HeaderP);
var input = InitPrefab(diag.HeaderP);
input.GetComponent<RemixPropertyPrefab>().InitProperties(diag, "", text);
}
public void AddSubHeader(RemixPropertiesDialog diag, string text)
{
var input = InitPrefab(SubHeaderP);
var input = InitPrefab(diag.SubHeaderP);
input.GetComponent<RemixPropertyPrefab>().InitProperties(diag, "", text);
}
@ -119,11 +123,16 @@ namespace HeavenStudio.Editor
public override void OnOpenTab()
{
dialog.SetupDialog(tags, this);
if (dialog != null && !initialized)
{
initialized = true;
dialog.SetupDialog(tags, this);
}
}
public override void OnCloseTab()
{
initialized = false;
foreach (Transform child in propertyHolder.transform) {
Destroy(child.gameObject);
}

View File

@ -1,11 +1,18 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using HeavenStudio.Common;
namespace HeavenStudio.Editor
{
public class SettingsDialog : Dialog
{
[SerializeField] private TMP_Text BuildDateDisplay;
[SerializeField] private TabsManager tabsManager;
[SerializeField] private TabsManager.TabsEntry[] tabs;
private void Start() {}
public void SwitchSettingsDialog()
@ -14,12 +21,17 @@ namespace HeavenStudio.Editor
Editor.instance.canSelect = true;
Editor.instance.inAuthorativeMenu = false;
dialog.SetActive(false);
PersistentDataManager.SaveSettings();
tabsManager.CleanTabs();
} else {
ResetAllDialogs();
Editor.instance.canSelect = false;
Editor.instance.inAuthorativeMenu = true;
dialog.SetActive(true);
tabsManager.GenerateTabs(tabs);
BuildDateDisplay.text = GlobalGameManager.buildTime;
}
}

View File

@ -13,8 +13,9 @@ namespace HeavenStudio.Editor
{
private int SecretCounter = 0;
private bool SecretActive = false;
[SerializeField] private TextAsset creditsText;
[SerializeField] private TMP_Text creditsDisplay;
[SerializeField] private GameObject secretObject;
[SerializeField] private StudioDanceManager secretContent;
private void Start()
{
@ -40,7 +41,7 @@ namespace HeavenStudio.Editor
Jukebox.PlayOneShot("applause");
Debug.Log("Activating Studio Dance...");
secretContent.OpenDanceWindow();
Editor.instance.StudioDanceManager.OpenDanceWindow();
}
public void MakeSecretInactive()
@ -48,11 +49,12 @@ namespace HeavenStudio.Editor
SecretCounter = 0;
secretObject.SetActive(false);
SecretActive = false;
secretContent.CloseDanceWindow();
Editor.instance.StudioDanceManager.CloseDanceWindow();
}
public override void OnOpenTab()
{
creditsDisplay.text = creditsText.text;
}
public override void OnCloseTab()

View File

@ -46,6 +46,9 @@ namespace HeavenStudio.Editor
heightInputField.text = GlobalGameManager.CustomScreenHeight.ToString();
});
widthInputField.text = GlobalGameManager.CustomScreenWidth.ToString();
heightInputField.text = GlobalGameManager.CustomScreenHeight.ToString();
volSlider.value = GlobalGameManager.MasterVolume;
volLabel.text = System.Math.Round(volSlider.value * 100, 2).ToString();
}

View File

@ -2,21 +2,36 @@ using UnityEngine;
using UnityEngine.UI;
using TMPro;
using HeavenStudio.Common;
namespace HeavenStudio.Editor
{
public class EditorSettings : TabsContent
{
public Toggle cursorCheckbox;
public Toggle discordRPCCheckbox;
private void Start() {
cursorCheckbox.isOn = PersistentDataManager.gameSettings.editorCursorEnable;
discordRPCCheckbox.isOn = PersistentDataManager.gameSettings.discordRPCEnable;
}
public void OnCursorCheckboxChanged()
{
Editor.instance.isCursorEnabled = cursorCheckbox.isOn;
PersistentDataManager.gameSettings.editorCursorEnable = cursorCheckbox.isOn;
if (!Editor.instance.fullscreen)
{
GameManager.instance.CursorCam.enabled = Editor.instance.isCursorEnabled;
}
}
public void OnRPCCheckboxChanged()
{
PersistentDataManager.gameSettings.discordRPCEnable = discordRPCCheckbox.isOn;
Editor.instance.isDiscordEnabled = discordRPCCheckbox.isOn;
}
public override void OnOpenTab()
{
}