2022-01-17 00:40:14 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
2023-04-27 03:09:43 +00:00
|
|
|
using UnityEngine.EventSystems;
|
2022-01-17 00:40:14 +00:00
|
|
|
|
|
|
|
using TMPro;
|
|
|
|
using DG.Tweening;
|
|
|
|
using Starpelly;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Editor.Track;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2023-04-27 03:09:43 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
|
|
|
public class GridGameSelector : MonoBehaviour
|
|
|
|
{
|
|
|
|
public string SelectedMinigame;
|
|
|
|
|
|
|
|
[Header("Components")]
|
2022-06-14 05:24:41 +00:00
|
|
|
public GameObject SelectedGameIcon;
|
2022-01-17 00:40:14 +00:00
|
|
|
public GameObject GameEventSelector;
|
|
|
|
public GameObject EventRef;
|
|
|
|
public GameObject CurrentSelected;
|
2023-06-19 20:28:52 +00:00
|
|
|
public GameObject Scrollbar;
|
|
|
|
public RectTransform GameSelectionRect;
|
2022-07-02 02:29:16 +00:00
|
|
|
public RectTransform GameEventSelectorCanScroll;
|
2022-06-30 19:51:13 +00:00
|
|
|
private RectTransform GameEventSelectorRect;
|
2022-01-17 00:40:14 +00:00
|
|
|
private RectTransform eventsParent;
|
|
|
|
|
|
|
|
[Header("Properties")]
|
2023-04-27 03:09:43 +00:00
|
|
|
[SerializeField] private int currentEventIndex;
|
2022-01-17 19:23:18 +00:00
|
|
|
private Minigames.Minigame mg;
|
2022-01-17 00:40:14 +00:00
|
|
|
public float posDif;
|
|
|
|
public int ignoreSelectCount;
|
2023-06-19 20:28:52 +00:00
|
|
|
private int sortStatus;
|
|
|
|
private int dragTimes;
|
|
|
|
private bool gameOpen;
|
2022-06-30 19:51:13 +00:00
|
|
|
private float selectorHeight;
|
|
|
|
private float eventSize;
|
2022-01-17 00:40:14 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
public static GridGameSelector instance;
|
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
2023-06-19 20:28:52 +00:00
|
|
|
instance = this;
|
2022-06-30 19:51:13 +00:00
|
|
|
GameEventSelectorRect = GameEventSelector.GetComponent<RectTransform>();
|
|
|
|
selectorHeight = GameEventSelectorRect.rect.height;
|
|
|
|
eventSize = EventRef.GetComponent<RectTransform>().rect.height;
|
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
eventsParent = EventRef.transform.parent.GetChild(2).GetComponent<RectTransform>();
|
2023-06-19 20:28:52 +00:00
|
|
|
SelectGame("gameManager");
|
2022-01-17 00:40:14 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
//SetColors();
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-06-19 20:28:52 +00:00
|
|
|
if (!EventParameterManager.instance.active && !IsPointerOverUIElement())
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2022-05-04 17:26:19 +00:00
|
|
|
if (gameOpen)
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2022-05-04 17:26:19 +00:00
|
|
|
if (Input.GetKeyDown(KeyCode.DownArrow))
|
|
|
|
{
|
|
|
|
UpdateIndex(currentEventIndex + 1);
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
|
|
{
|
|
|
|
UpdateIndex(currentEventIndex - 1);
|
|
|
|
}
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
2022-05-04 17:26:19 +00:00
|
|
|
|
2022-07-02 02:29:16 +00:00
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(GameEventSelectorCanScroll, Input.mousePosition, Editor.instance.EditorCamera) && Input.mouseScrollDelta.y != 0)
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2022-05-04 17:26:19 +00:00
|
|
|
UpdateIndex(currentEventIndex - Mathf.RoundToInt(Input.mouseScrollDelta.y));
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-30 19:51:13 +00:00
|
|
|
|
|
|
|
//moved here so this updates dynamically with window scale
|
|
|
|
UpdateScrollPosition();
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Functions
|
|
|
|
|
|
|
|
public void UpdateIndex(int amount, bool updateCol = true)
|
|
|
|
{
|
|
|
|
currentEventIndex = amount;
|
|
|
|
|
|
|
|
CurrentSelected.transform.DOKill();
|
|
|
|
|
|
|
|
if (currentEventIndex < 0)
|
|
|
|
currentEventIndex = eventsParent.childCount - 1;
|
|
|
|
else if (currentEventIndex > eventsParent.childCount - 1)
|
|
|
|
currentEventIndex = 0;
|
|
|
|
|
2022-06-30 19:51:13 +00:00
|
|
|
CurrentSelected.transform.DOLocalMoveY(eventsParent.transform.GetChild(currentEventIndex).localPosition.y + eventsParent.transform.localPosition.y, 0.35f).SetEase(Ease.OutExpo);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateScrollPosition()
|
|
|
|
{
|
|
|
|
selectorHeight = GameEventSelectorRect.rect.height;
|
2023-06-19 20:28:52 +00:00
|
|
|
//eventSize = EventRef.GetComponent<RectTransform>().rect.height;
|
|
|
|
|
|
|
|
Vector3 lastPos = EventRef.transform.parent.transform.localPosition;
|
|
|
|
float end = 0;
|
2022-06-30 19:51:13 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
if ((currentEventIndex * eventSize >= selectorHeight/2) && (eventsParent.childCount * eventSize >= selectorHeight))
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2022-06-30 19:51:13 +00:00
|
|
|
if (currentEventIndex * eventSize < eventsParent.childCount * eventSize - selectorHeight/2)
|
2023-06-19 20:28:52 +00:00
|
|
|
end = (currentEventIndex * eventSize) - selectorHeight/2;
|
2022-01-17 00:40:14 +00:00
|
|
|
else
|
2023-06-19 20:28:52 +00:00
|
|
|
end = (eventsParent.childCount * eventSize) - selectorHeight + (eventSize * 0.33f);
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
2023-06-19 20:28:52 +00:00
|
|
|
EventRef.transform.parent.transform.localPosition = new Vector3(
|
|
|
|
lastPos.x,
|
|
|
|
Mathf.Lerp(lastPos.y, end, 12 * Time.deltaTime),
|
|
|
|
lastPos.z
|
|
|
|
);
|
|
|
|
SetColors();
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
// will automatically select game + game icon, and scroll to the game if it's offscreen
|
|
|
|
// index is the event it will highlight (which was basically just added for pick block)
|
|
|
|
// TODO: automatically scroll if the game is offscreen, because i can't figure it out/can't figure out a good way to do it rn. -AJ
|
|
|
|
public void SelectGame(string gameName, int index = 0)
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2023-06-19 20:28:52 +00:00
|
|
|
EventParameterManager.instance.Disable();
|
2022-06-14 05:24:41 +00:00
|
|
|
if (SelectedGameIcon != null)
|
|
|
|
{
|
|
|
|
SelectedGameIcon.GetComponent<GridGameSelectorGame>().UnClickIcon();
|
|
|
|
}
|
2023-06-19 20:28:52 +00:00
|
|
|
|
|
|
|
mg = EventCaller.instance.GetMinigame(gameName);
|
|
|
|
if (mg == null) {
|
|
|
|
SelectGame("gameManager");
|
|
|
|
Debug.LogWarning($"SelectGame() has failed, did you mean to input '{gameName}'?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
SelectedMinigame = gameName;
|
|
|
|
gameOpen = true;
|
|
|
|
|
|
|
|
DestroyEvents();
|
2023-06-19 20:28:52 +00:00
|
|
|
AddEvents(index);
|
2022-01-17 00:40:14 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
SelectedGameIcon = transform.Find(gameName).gameObject;
|
2022-06-14 05:24:41 +00:00
|
|
|
SelectedGameIcon.GetComponent<GridGameSelectorGame>().ClickIcon();
|
2022-01-17 02:31:49 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
currentEventIndex = index;
|
|
|
|
UpdateIndex(index, false);
|
2022-01-17 00:40:14 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
Editor.instance?.SetGameEventTitle($"Select game event for {mg.displayName.Replace("\n", "")}");
|
|
|
|
|
|
|
|
// should auto scroll if it's offscreen
|
|
|
|
// just barely doesn't work, and works even less with zooming. im sure there's a much better way to do it
|
|
|
|
/*
|
|
|
|
var pos = 1 - ((mgIndex / 4)-0.02f) / (Mathf.Ceil(mgsActive / 4) - 3);
|
|
|
|
var posMin = (pos + Viewport.rect.height); //+ (pos * 0.01f);
|
|
|
|
if (Scrollbar.value < pos) Scrollbar.value = pos;
|
|
|
|
else if (Scrollbar.value > posMin) Scrollbar.value = posMin;
|
|
|
|
*/
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
private void AddEvents(int index = 0)
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2022-02-03 03:58:08 +00:00
|
|
|
if (!EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(mg.name)))
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
|
|
|
GameObject sg = Instantiate(EventRef, eventsParent);
|
2022-08-21 03:54:09 +00:00
|
|
|
sg.GetComponent<TMP_Text>().text = "Switch Game";
|
2022-01-17 00:40:14 +00:00
|
|
|
sg.SetActive(true);
|
2023-06-19 20:28:52 +00:00
|
|
|
if (index == 0) sg.GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
|
|
|
|
} else {
|
|
|
|
index++;
|
|
|
|
if (mg.name == "gameManager") index++;
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < mg.actions.Count; i++)
|
|
|
|
{
|
2022-03-01 08:17:06 +00:00
|
|
|
if (mg.actions[i].actionName == "switchGame" || mg.actions[i].hidden) continue;
|
2022-01-17 00:40:14 +00:00
|
|
|
GameObject g = Instantiate(EventRef, eventsParent);
|
2022-08-21 03:54:09 +00:00
|
|
|
g.GetComponent<TMP_Text>().text = mg.actions[i].displayName;
|
2022-01-17 00:40:14 +00:00
|
|
|
g.SetActive(true);
|
2023-06-19 20:28:52 +00:00
|
|
|
if (index - 1 == i) g.GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DestroyEvents()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
|
|
{
|
|
|
|
transform.GetChild(i).GetChild(0).gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < eventsParent.childCount; i++)
|
|
|
|
{
|
|
|
|
Destroy(eventsParent.GetChild(i).gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
private void SetColors()
|
2022-01-17 00:40:14 +00:00
|
|
|
{
|
2023-06-19 20:28:52 +00:00
|
|
|
//CurrentSelected.GetComponent<Image>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
|
2022-01-17 00:40:14 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < eventsParent.transform.childCount; i++)
|
2023-06-19 20:28:52 +00:00
|
|
|
eventsParent.GetChild(i).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventNormalCol.Hex2RGB();
|
|
|
|
|
|
|
|
eventsParent.GetChild(currentEventIndex).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: find the equation to get the sizes automatically, nobody's been able to figure one out yet (might have to be manual?)
|
|
|
|
public void Zoom()
|
|
|
|
{
|
|
|
|
if (!Input.GetKey(KeyCode.LeftControl)) return;
|
|
|
|
var glg = GetComponent<GridLayoutGroup>();
|
|
|
|
var sizes = new List<float>() {
|
|
|
|
209.5f,
|
|
|
|
102.3f,
|
|
|
|
66.6f,
|
|
|
|
48.6f,
|
|
|
|
37.9f,
|
|
|
|
30.8f,
|
|
|
|
25.7f,
|
|
|
|
24.3f,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (glg.constraintCount + 1 > sizes.Count && Input.GetAxisRaw("Mouse ScrollWheel") < 0) return;
|
|
|
|
|
|
|
|
glg.constraintCount += (Input.GetAxisRaw("Mouse ScrollWheel") > 0) ? -1 : 1;
|
|
|
|
glg.cellSize = new Vector2(sizes[glg.constraintCount - 1], sizes[glg.constraintCount - 1]);
|
|
|
|
}
|
2022-01-17 00:40:14 +00:00
|
|
|
|
2023-06-19 20:28:52 +00:00
|
|
|
// method called when clicking the sort button in the editor, skips sorting first three "games"
|
|
|
|
// sorts by favorites if there are any, and sorts alphabetically if there aren't.
|
|
|
|
public void Sort()
|
|
|
|
{
|
|
|
|
var mgs = EventCaller.instance.minigames;
|
|
|
|
var mgsActive = new List<string>();
|
|
|
|
for (int i = 3; i < mgs.Count; i++)
|
|
|
|
{
|
|
|
|
if (!mgs[i].hidden) mgsActive.Add(mgs[i].name);
|
|
|
|
}
|
|
|
|
mgsActive.Sort();
|
|
|
|
var favs = new List<Transform>();
|
|
|
|
bool fav = false;
|
|
|
|
for (int i = 0; i < mgsActive.Count; i++)
|
|
|
|
{
|
|
|
|
var mg = transform.Find(mgsActive[i]);
|
|
|
|
if (mg.GetComponent<GridGameSelectorGame>().StarActive) {
|
|
|
|
favs.Add(mg);
|
|
|
|
fav = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fav) {
|
|
|
|
for (int i = 0; i < mgsActive.Count; i++)
|
|
|
|
transform.Find(mgsActive[i]).SetSiblingIndex(i+4);
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < favs.Count; i++)
|
|
|
|
favs[i].SetSiblingIndex(i+4);
|
|
|
|
}
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 03:09:43 +00:00
|
|
|
public bool IsPointerOverUIElement()
|
|
|
|
{
|
|
|
|
return IsPointerOverUIElement(GetEventSystemRaycastResults());
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool IsPointerOverUIElement(List<RaycastResult> eventSystemRaysastResults)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < eventSystemRaysastResults.Count; index++)
|
|
|
|
{
|
|
|
|
RaycastResult curRaysastResult = eventSystemRaysastResults[index];
|
|
|
|
if (curRaysastResult.gameObject.layer == 5)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static List<RaycastResult> GetEventSystemRaycastResults()
|
|
|
|
{
|
|
|
|
PointerEventData eventData = new PointerEventData(EventSystem.current);
|
|
|
|
eventData.position = Input.mousePosition;
|
|
|
|
List<RaycastResult> raysastResults = new List<RaycastResult>();
|
|
|
|
EventSystem.current.RaycastAll(eventData, raysastResults);
|
|
|
|
return raysastResults;
|
|
|
|
}
|
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
public void Drag()
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
if (Conductor.instance.NotStopped() || Editor.instance.inAuthorativeMenu) return;
|
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1)
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
Timeline.instance.timelineState.SetState(Timeline.CurrentTimelineState.State.Selection);
|
2022-01-17 00:40:14 +00:00
|
|
|
dragTimes++;
|
2022-01-23 03:40:53 +00:00
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
TimelineEventObj eventObj;
|
2022-01-23 03:40:53 +00:00
|
|
|
|
2022-01-17 00:40:14 +00:00
|
|
|
if (currentEventIndex == 0)
|
|
|
|
{
|
2022-02-03 03:58:08 +00:00
|
|
|
if (EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(mg.name)))
|
|
|
|
{
|
|
|
|
int index = currentEventIndex + 1;
|
|
|
|
if (currentEventIndex - 1 > mg.actions.Count)
|
|
|
|
{
|
|
|
|
index = currentEventIndex;
|
|
|
|
}
|
|
|
|
else if (currentEventIndex - 1 < 0)
|
|
|
|
{
|
|
|
|
if (mg.actions[0].actionName == "switchGame")
|
|
|
|
index = 1;
|
|
|
|
else
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
eventObj = Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[index].actionName, true, new Vector3(0, 0), null, true);
|
2022-02-03 03:58:08 +00:00
|
|
|
}
|
|
|
|
else
|
2023-06-10 19:13:29 +00:00
|
|
|
eventObj = Timeline.instance.AddEventObject($"gameManager/switchGame/{mg.name}", true, new Vector3(0, 0), null, true);
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-03 03:58:08 +00:00
|
|
|
int index = currentEventIndex - 1;
|
|
|
|
if (mg.actions[0].actionName == "switchGame")
|
|
|
|
{
|
|
|
|
index = currentEventIndex + 1;
|
|
|
|
}
|
|
|
|
else if (EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(mg.name)) && mg.actions[0].actionName != "switchGame")
|
|
|
|
{
|
|
|
|
index = currentEventIndex;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
eventObj = Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[index].actionName, true, new Vector3(0, 0), null, true);
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
|
|
|
|
eventObj.isCreating = true;
|
|
|
|
|
|
|
|
// CommandManager.instance.Execute(new Commands.Place(eventObj));
|
2022-01-17 00:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Drop()
|
|
|
|
{
|
|
|
|
if (Conductor.instance.NotStopped()) return;
|
|
|
|
|
|
|
|
dragTimes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|