HeavenStudioPlus/Assets/Scripts/LevelEditor/GridGameSelector.cs

165 lines
4.9 KiB
C#
Raw Normal View History

2022-01-11 00:17:29 +00:00
using System.Collections;
using System.Collections.Generic;
2022-01-09 23:35:55 +00:00
using UnityEngine;
using UnityEngine.UI;
2022-01-11 00:17:29 +00:00
using TMPro;
2022-01-11 02:06:13 +00:00
using DG.Tweening;
using Starpelly;
2022-01-09 23:35:55 +00:00
namespace RhythmHeavenMania.Editor
{
public class GridGameSelector : MonoBehaviour
{
2022-01-11 00:17:29 +00:00
public string SelectedMinigame;
[Header("Components")]
public GameObject GameEventSelector;
public GameObject EventRef;
2022-01-11 02:06:13 +00:00
public GameObject CurrentSelected;
2022-01-11 00:17:29 +00:00
[Header("Properties")]
private EventCaller.MiniGame mg;
private bool gameOpen;
[SerializeField] private int currentEventIndex;
private int dragTimes;
private void Update()
{
if (gameOpen)
{
if (Input.GetKeyDown(KeyCode.DownArrow))
{
UpdateIndex(1);
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
UpdateIndex(-1);
}
}
}
#region Events
public void Drag()
{
if (Conductor.instance.NotStopped()) return;
if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1)
{
dragTimes++;
2022-01-15 18:46:50 +00:00
if (currentEventIndex == 0)
{
Timeline.instance.AddEventObject($"gameManager/switchGame/{mg.name}", true, new Vector3(0, 0));
}
else
{
Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex - 1].actionName, true, new Vector3(0, 0));
}
2022-01-11 00:17:29 +00:00
}
}
public void Drop()
{
if (Conductor.instance.NotStopped()) return;
dragTimes = 0;
}
#endregion
2022-01-09 23:35:55 +00:00
2022-01-11 00:17:29 +00:00
#region Functions
public void UpdateIndex(int amount)
{
currentEventIndex += amount;
if (currentEventIndex < 0)
{
2022-01-15 18:46:50 +00:00
currentEventIndex = EventRef.transform.parent.childCount - 2;
2022-01-11 00:17:29 +00:00
}
2022-01-15 18:46:50 +00:00
else if (currentEventIndex > EventRef.transform.parent.childCount - 2)
2022-01-11 00:17:29 +00:00
{
currentEventIndex = 0;
}
2022-01-11 02:06:13 +00:00
if (currentEventIndex > 2)
{
EventRef.transform.parent.parent.transform.DOLocalMoveY((EventRef.GetComponent<RectTransform>().sizeDelta.y + 5) * (currentEventIndex - 2), 0.35f).SetEase(Ease.OutExpo);
}
else
{
EventRef.transform.parent.parent.transform.DOLocalMoveY(0, 0.35f).SetEase(Ease.OutExpo);
}
CurrentSelected.transform.DOLocalMoveY(EventRef.transform.parent.GetChild(currentEventIndex + 1).transform.localPosition.y, 0.35f).SetEase(Ease.OutExpo);
2022-01-11 00:17:29 +00:00
SetColor(currentEventIndex);
}
2022-01-11 02:06:13 +00:00
public void SelectGame(string gameName, int index)
2022-01-11 00:17:29 +00:00
{
DestroyEvents();
2022-01-11 02:06:13 +00:00
transform.GetChild(index).GetChild(0).gameObject.SetActive(true);
2022-01-11 00:17:29 +00:00
SelectedMinigame = gameName;
mg = EventCaller.instance.minigames.Find(c => c.displayName == gameName);
2022-01-15 18:46:50 +00:00
AddEvents();
2022-01-11 00:17:29 +00:00
gameOpen = true;
currentEventIndex = 0;
SetColor(0);
}
2022-01-15 18:46:50 +00:00
private void AddEvents()
{
if (mg.name != "gameManager")
{
GameObject sg = Instantiate(EventRef, EventRef.transform.parent);
sg.GetComponent<TMP_Text>().text = "switchGame";
sg.SetActive(true);
}
for (int i = 0; i < mg.actions.Count; i++)
{
if (mg.actions[i].actionName != "switchGame")
{
GameObject e = Instantiate(EventRef, EventRef.transform.parent);
e.GetComponent<TMP_Text>().text = mg.actions[i].actionName;
e.SetActive(true);
}
}
}
2022-01-11 00:17:29 +00:00
private void SetColor(int ind)
2022-01-09 23:35:55 +00:00
{
2022-01-12 03:29:27 +00:00
for (int i = 0; i < EventRef.transform.parent.childCount; i++)
{
EventRef.transform.parent.GetChild(i).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventNormalCol.Hex2RGB();
2022-01-12 03:29:27 +00:00
}
2022-01-11 00:17:29 +00:00
EventRef.transform.parent.GetChild(ind + 1).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
CurrentSelected.GetComponent<Image>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
2022-01-09 23:35:55 +00:00
}
2022-01-11 00:17:29 +00:00
private void DestroyEvents()
2022-01-09 23:35:55 +00:00
{
2022-01-11 02:06:13 +00:00
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).GetChild(0).gameObject.SetActive(false);
}
2022-01-11 00:17:29 +00:00
for (int i = 1; i < EventRef.transform.parent.childCount; i++)
{
Destroy(EventRef.transform.parent.GetChild(i).gameObject);
}
gameOpen = false;
2022-01-09 23:35:55 +00:00
}
2022-01-11 00:17:29 +00:00
#endregion
2022-01-09 23:35:55 +00:00
}
}