HeavenStudio/Assets/Scripts/LevelEditor/EditorTheme.cs

92 lines
3.2 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json;
2022-01-14 22:46:14 +00:00
using TMPro;
using Starpelly;
using HeavenStudio.Common;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Editor.Track;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Editor
{
public class EditorTheme : MonoBehaviour
{
public TextAsset ThemeTXT;
public static Theme theme;
[Header("Components")]
2022-01-14 22:46:14 +00:00
[SerializeField] private Image layer;
[SerializeField] private Image specialLayers;
2022-01-14 22:46:14 +00:00
[SerializeField] private Image tempoLayer;
[SerializeField] private Image musicLayer;
[SerializeField] private Image sectionLayer;
private void Awake()
{
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()
{
if (Editor.instance == null) return;
specialLayers.GetComponent<Image>().color = theme.properties.SpecialLayersCol.Hex2RGB();
2022-01-14 22:46:14 +00:00
tempoLayer.GetComponent<Image>().color = theme.properties.TempoLayerCol.Hex2RGB();
musicLayer.GetComponent<Image>().color = theme.properties.MusicLayerCol.Hex2RGB();
sectionLayer.GetComponent<Image>().color = theme.properties.SectionLayerCol.Hex2RGB();
Tooltip.AddTooltip(specialLayers.gameObject, $"All Special Tracks");
2022-01-18 00:40:23 +00:00
Tooltip.AddTooltip(tempoLayer.gameObject, $"Tempo Track");
Tooltip.AddTooltip(musicLayer.gameObject, $"Music Volume Track");
Tooltip.AddTooltip(sectionLayer.gameObject, $"Remix Sections Track");
2022-01-14 22:46:14 +00:00
layer.gameObject.SetActive(false);
for (int i = 0; i < Timeline.instance.LayerCount; i++)
{
GameObject layer = Instantiate(this.layer.gameObject, this.layer.transform.parent);
layer.SetActive(true);
layer.transform.GetChild(0).GetComponent<TMP_Text>().text = $"Track {i + 1}";
2022-01-14 22:46:14 +00:00
Color c = Color.white;
switch (i)
{
case 0:
c = theme.properties.Layer1Col.Hex2RGB();
break;
case 1:
c = theme.properties.Layer2Col.Hex2RGB();
break;
case 2:
c = theme.properties.Layer3Col.Hex2RGB();
break;
case 3:
c = theme.properties.Layer4Col.Hex2RGB();
break;
case 4:
c = theme.properties.Layer5Col.Hex2RGB();
break;
2022-01-14 22:46:14 +00:00
}
2022-01-14 22:46:14 +00:00
layer.GetComponent<Image>().color = c;
2022-01-18 00:40:23 +00:00
Tooltip.AddTooltip(layer, $"Track {i + 1}");
2022-01-14 22:46:14 +00:00
}
Destroy(layer);
}
}
}