Editor Additions (#479)

* favoriting and pick block

favoriting needs to not break after previewing (maybe make it persistent in the settings file?)
pick block needs to pick the icon, too. and preferably scroll to it as well

* final star anim + automatic icon game switching

before i make any more changes im making a checkpoint here cuz i know it works
* i want to add a way to specify which event SwitchGame() will switch to (because that's a cool feature for pick block)
* i'll have to figure out how to auto scroll to the game when the icon is selected
* the star now fully works, even between preview switches 👍

* fix the rest of the stuff

the event name gets colored correctly and hidden games are skipped over, but still loaded.
also i built mm ass buns

* tweaks + zoom and sorting

this stuff will be in the pr desc so it doesn't matter

* oop one more thing

* icons look better now :D

mipmaps to the rescue

* double date fix
This commit is contained in:
AstrlJelly
2023-06-19 16:28:52 -04:00
committed by minenice55
parent 9cf18a797d
commit 51843b310e
128 changed files with 4531 additions and 1091 deletions

View File

@ -22,6 +22,8 @@ namespace HeavenStudio.Editor
public GameObject GameEventSelector;
public GameObject EventRef;
public GameObject CurrentSelected;
public GameObject Scrollbar;
public RectTransform GameSelectionRect;
public RectTransform GameEventSelectorCanScroll;
private RectTransform GameEventSelectorRect;
private RectTransform eventsParent;
@ -29,28 +31,32 @@ namespace HeavenStudio.Editor
[Header("Properties")]
[SerializeField] private int currentEventIndex;
private Minigames.Minigame mg;
private bool gameOpen;
private int dragTimes;
public float posDif;
public int ignoreSelectCount;
private int sortStatus;
private int dragTimes;
private bool gameOpen;
private float selectorHeight;
private float eventSize;
public static GridGameSelector instance;
private void Start()
{
instance = this;
GameEventSelectorRect = GameEventSelector.GetComponent<RectTransform>();
selectorHeight = GameEventSelectorRect.rect.height;
eventSize = EventRef.GetComponent<RectTransform>().rect.height;
eventsParent = EventRef.transform.parent.GetChild(2).GetComponent<RectTransform>();
SelectGame("Game Manager", 1);
SelectGame("gameManager");
SetColors();
//SetColors();
}
private void Update()
{
if (!(EventParameterManager.instance.active || Conductor.instance.NotStopped()) && !IsPointerOverUIElement())
if (!EventParameterManager.instance.active && !IsPointerOverUIElement())
{
if (gameOpen)
{
@ -88,78 +94,84 @@ namespace HeavenStudio.Editor
currentEventIndex = 0;
CurrentSelected.transform.DOLocalMoveY(eventsParent.transform.GetChild(currentEventIndex).localPosition.y + eventsParent.transform.localPosition.y, 0.35f).SetEase(Ease.OutExpo);
if (updateCol)
SetColors(currentEventIndex);
}
private void UpdateScrollPosition()
{
selectorHeight = GameEventSelectorRect.rect.height;
eventSize = EventRef.GetComponent<RectTransform>().rect.height;
// EventRef.transform.parent.DOKill();
float lastLocalY = EventRef.transform.parent.transform.localPosition.y;
//eventSize = EventRef.GetComponent<RectTransform>().rect.height;
Vector3 lastPos = EventRef.transform.parent.transform.localPosition;
float end = 0;
if (currentEventIndex * eventSize >= selectorHeight/2 && eventsParent.childCount * eventSize >= selectorHeight)
if ((currentEventIndex * eventSize >= selectorHeight/2) && (eventsParent.childCount * eventSize >= selectorHeight))
{
if (currentEventIndex * eventSize < eventsParent.childCount * eventSize - selectorHeight/2)
{
EventRef.transform.parent.transform.localPosition = new Vector3(
EventRef.transform.parent.transform.localPosition.x,
Mathf.Lerp(lastLocalY, (currentEventIndex * eventSize) - selectorHeight/2, 12 * Time.deltaTime),
EventRef.transform.parent.transform.localPosition.z
);
}
end = (currentEventIndex * eventSize) - selectorHeight/2;
else
{
EventRef.transform.parent.transform.localPosition = new Vector3(
EventRef.transform.parent.transform.localPosition.x,
Mathf.Lerp(lastLocalY, (eventsParent.childCount * eventSize) - selectorHeight + (eventSize*0.33f), 12 * Time.deltaTime),
EventRef.transform.parent.transform.localPosition.z
);
}
}
else
{
EventRef.transform.parent.transform.localPosition = new Vector3(
EventRef.transform.parent.transform.localPosition.x,
Mathf.Lerp(lastLocalY, 0, 12 * Time.deltaTime),
EventRef.transform.parent.transform.localPosition.z
);
end = (eventsParent.childCount * eventSize) - selectorHeight + (eventSize * 0.33f);
}
EventRef.transform.parent.transform.localPosition = new Vector3(
lastPos.x,
Mathf.Lerp(lastPos.y, end, 12 * Time.deltaTime),
lastPos.z
);
SetColors();
}
public void SelectGame(string gameName, int index)
// 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)
{
EventParameterManager.instance.Disable();
if (SelectedGameIcon != null)
{
SelectedGameIcon.GetComponent<GridGameSelectorGame>().UnClickIcon();
}
mg = EventCaller.instance.minigames.Find(c => c.displayName == gameName);
mg = EventCaller.instance.GetMinigame(gameName);
if (mg == null) {
SelectGame("gameManager");
Debug.LogWarning($"SelectGame() has failed, did you mean to input '{gameName}'?");
return;
}
SelectedMinigame = gameName;
gameOpen = true;
DestroyEvents();
AddEvents();
AddEvents(index);
// transform.GetChild(index).GetChild(0).gameObject.SetActive(true);
SelectedGameIcon = transform.GetChild(index).gameObject;
SelectedGameIcon = transform.Find(gameName).gameObject;
SelectedGameIcon.GetComponent<GridGameSelectorGame>().ClickIcon();
currentEventIndex = 0;
UpdateIndex(0, false);
currentEventIndex = index;
UpdateIndex(index, false);
Editor.instance?.SetGameEventTitle($"Select game event for {gameName.Replace("\n", "")}");
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;
*/
}
private void AddEvents()
private void AddEvents(int index = 0)
{
if (!EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(mg.name)))
{
GameObject sg = Instantiate(EventRef, eventsParent);
sg.GetComponent<TMP_Text>().text = "Switch Game";
sg.SetActive(true);
sg.GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
if (index == 0) sg.GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
} else {
index++;
if (mg.name == "gameManager") index++;
}
for (int i = 0; i < mg.actions.Count; i++)
@ -168,6 +180,7 @@ namespace HeavenStudio.Editor
GameObject g = Instantiate(EventRef, eventsParent);
g.GetComponent<TMP_Text>().text = mg.actions[i].displayName;
g.SetActive(true);
if (index - 1 == i) g.GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
}
}
@ -184,14 +197,66 @@ namespace HeavenStudio.Editor
}
}
private void SetColors(int index = 0)
private void SetColors()
{
CurrentSelected.GetComponent<Image>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
//CurrentSelected.GetComponent<Image>().color = EditorTheme.theme.properties.EventSelectedCol.Hex2RGB();
for (int i = 0; i < eventsParent.transform.childCount; i++)
eventsParent.GetChild(i).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventNormalCol.Hex2RGB();
eventsParent.GetChild(i).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventNormalCol.Hex2RGB();
eventsParent.GetChild(index).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.EventSelectedCol.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]);
}
// 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);
}
}
public bool IsPointerOverUIElement()

View File

@ -1,6 +1,7 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using DG.Tweening;
@ -9,6 +10,8 @@ namespace HeavenStudio.Editor
public class GridGameSelectorGame : MonoBehaviour
{
public GameObject GameTitlePreview;
public Animator StarAnim;
public bool StarActive;
public GridGameSelector GridGameSelector;
@ -18,7 +21,12 @@ namespace HeavenStudio.Editor
private void Start()
{
Tooltip.AddTooltip(this.gameObject, this.gameObject.name);
Tooltip.AddTooltip(this.gameObject, EventCaller.instance.GetMinigame(this.gameObject.name).displayName);
}
private void OnEnable()
{
if (StarActive) StarAnim.Play("Appear", 0, 1);
}
public void SetupTextures()
@ -34,7 +42,34 @@ namespace HeavenStudio.Editor
public void OnClick()
{
GridGameSelector.SelectGame(this.gameObject.name, this.transform.GetSiblingIndex());
if (Input.GetMouseButtonUp(0))
{
GridGameSelector.SelectGame(this.gameObject.name);
}
}
public void OnDown()
{
if (Input.GetMouseButtonDown(1))
{
// while holding shift and the game icon clicked has a star, it will disable all stars.
if (Input.GetKey(KeyCode.LeftShift)) {
if (!StarActive) return;
for (int i = 0; i < transform.parent.childCount; i++)
{
var ggsg = transform.parent.GetChild(i).GetComponent<GridGameSelectorGame>();
if (ggsg.StarActive) ggsg.Star();
}
} else {
Star();
}
}
}
public void Star()
{
StarAnim.CrossFade(StarActive ? "Disappear" : "Appear", 0.3f);
StarActive = !StarActive;
}
//TODO: animate between shapes

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 02bf5ce2bfcf09949aca15ff9c98aa33
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: