2022-02-03 22:20:26 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Editor.Track;
|
2023-06-10 19:17:06 +00:00
|
|
|
using Jukebox;
|
|
|
|
using Jukebox.Legacy;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
|
|
|
public class EventParameterManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Header("General References")]
|
|
|
|
[SerializeField] private GameObject eventSelector;
|
2022-02-04 03:25:18 +00:00
|
|
|
[SerializeField] private GridGameSelector gridGameSelector;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
|
|
|
[Header("Property Prefabs")]
|
|
|
|
[SerializeField] private GameObject IntegerP;
|
2022-02-06 08:28:14 +00:00
|
|
|
[SerializeField] private GameObject FloatP;
|
2022-03-01 07:27:49 +00:00
|
|
|
[SerializeField] private GameObject BooleanP;
|
2022-02-04 22:16:22 +00:00
|
|
|
[SerializeField] private GameObject DropdownP;
|
2022-02-08 01:07:03 +00:00
|
|
|
[SerializeField] private GameObject ColorP;
|
2022-06-04 03:15:05 +00:00
|
|
|
[SerializeField] private GameObject StringP;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public RiqEntity entity;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-06-30 01:58:21 +00:00
|
|
|
public bool active;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2022-02-06 09:28:32 +00:00
|
|
|
private int childCountAtStart;
|
|
|
|
|
2022-02-08 01:07:03 +00:00
|
|
|
public bool canDisable = true;
|
|
|
|
|
2022-02-03 22:20:26 +00:00
|
|
|
public static EventParameterManager instance { get; set; }
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
2022-02-06 09:28:32 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
childCountAtStart = transform.childCount;
|
|
|
|
}
|
|
|
|
|
2022-02-04 03:25:18 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
2022-02-08 01:07:03 +00:00
|
|
|
if (canDisable && active)
|
2022-02-04 03:25:18 +00:00
|
|
|
{
|
|
|
|
Disable();
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 20:20:39 +00:00
|
|
|
canDisable = true;
|
2022-02-04 03:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
eventSelector.SetActive(true);
|
|
|
|
|
|
|
|
DestroyParams();
|
2022-03-04 00:15:56 +00:00
|
|
|
Editor.instance.SetGameEventTitle($"Select game event for {gridGameSelector.SelectedMinigame.Replace("\n", "")}");
|
2022-02-04 03:25:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void StartParams(RiqEntity entity)
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
2022-02-04 03:25:18 +00:00
|
|
|
active = true;
|
2022-02-03 22:20:26 +00:00
|
|
|
AddParams(entity);
|
|
|
|
}
|
|
|
|
|
2023-03-27 02:26:01 +00:00
|
|
|
static string TrackToThemeColour(int track) => track switch
|
|
|
|
{
|
|
|
|
1 => EditorTheme.theme.properties.Layer2Col,
|
|
|
|
2 => EditorTheme.theme.properties.Layer3Col,
|
|
|
|
3 => EditorTheme.theme.properties.Layer4Col,
|
|
|
|
4 => EditorTheme.theme.properties.Layer5Col,
|
|
|
|
_ => EditorTheme.theme.properties.Layer1Col
|
|
|
|
};
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
private void AddParams(RiqEntity entity)
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
|
|
|
var minigame = EventCaller.instance.GetMinigame(entity.datamodel.Split(0));
|
|
|
|
int actionIndex = minigame.actions.IndexOf(minigame.actions.Find(c => c.actionName == entity.datamodel.Split(1)));
|
|
|
|
Minigames.GameAction action = minigame.actions[actionIndex];
|
|
|
|
|
|
|
|
if (action.parameters != null)
|
|
|
|
{
|
|
|
|
eventSelector.SetActive(false);
|
|
|
|
this.entity = entity;
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
string col = TrackToThemeColour(entity["track"]);
|
2023-03-27 02:26:01 +00:00
|
|
|
Editor.instance.SetGameEventTitle($"Properties for <color=#{col}>{action.displayName}</color> on Beat {entity.beat}");
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-02-04 03:25:18 +00:00
|
|
|
DestroyParams();
|
2022-02-03 22:20:26 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < action.parameters.Count; i++)
|
|
|
|
{
|
|
|
|
object param = action.parameters[i].parameter;
|
|
|
|
string caption = action.parameters[i].propertyCaption;
|
|
|
|
string propertyName = action.parameters[i].propertyName;
|
2022-03-01 21:37:17 +00:00
|
|
|
string tooltip = action.parameters[i].tooltip;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-03-01 21:37:17 +00:00
|
|
|
AddParam(propertyName, param, caption, tooltip);
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
2022-02-04 03:25:18 +00:00
|
|
|
|
|
|
|
active = true;
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
2023-04-03 04:17:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
}
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:37:17 +00:00
|
|
|
private void AddParam(string propertyName, object type, string caption, string tooltip = "")
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
|
|
|
GameObject prefab = IntegerP;
|
2022-08-23 14:27:30 +00:00
|
|
|
GameObject input;
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-02-06 08:28:14 +00:00
|
|
|
var objType = type.GetType();
|
|
|
|
|
|
|
|
if (objType == typeof(EntityTypes.Integer))
|
2022-02-03 22:20:26 +00:00
|
|
|
{
|
|
|
|
prefab = IntegerP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<NumberPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
2022-02-06 08:28:14 +00:00
|
|
|
else if (objType == typeof(EntityTypes.Float))
|
|
|
|
{
|
|
|
|
prefab = FloatP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<NumberPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-02-06 08:28:14 +00:00
|
|
|
}
|
2022-03-01 07:27:49 +00:00
|
|
|
else if(type is bool)
|
|
|
|
{
|
|
|
|
prefab = BooleanP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<BoolPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-03-01 07:27:49 +00:00
|
|
|
}
|
2022-02-20 13:31:55 +00:00
|
|
|
else if (objType.IsEnum)
|
2022-02-04 22:16:22 +00:00
|
|
|
{
|
|
|
|
prefab = DropdownP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<EnumPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-02-04 22:16:22 +00:00
|
|
|
}
|
2022-08-22 01:57:32 +00:00
|
|
|
else if (objType == typeof(Color))
|
2022-02-08 01:07:03 +00:00
|
|
|
{
|
|
|
|
prefab = ColorP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<ColorPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-02-08 01:07:03 +00:00
|
|
|
}
|
2022-06-04 03:15:05 +00:00
|
|
|
else if(objType == typeof(string))
|
|
|
|
{
|
|
|
|
prefab = StringP;
|
2022-08-23 14:27:30 +00:00
|
|
|
input = InitPrefab(prefab, tooltip);
|
|
|
|
var property = input.GetComponent<StringPropertyPrefab>();
|
|
|
|
property.SetProperties(propertyName, type, caption);
|
2022-06-04 03:15:05 +00:00
|
|
|
}
|
2022-08-23 14:27:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogError("Can't make property interface of type: " + type.GetType());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 22:20:26 +00:00
|
|
|
|
2022-08-23 14:27:30 +00:00
|
|
|
private GameObject InitPrefab(GameObject prefab, string tooltip = "")
|
|
|
|
{
|
2022-02-03 22:20:26 +00:00
|
|
|
GameObject input = Instantiate(prefab);
|
|
|
|
input.transform.SetParent(this.gameObject.transform);
|
|
|
|
input.SetActive(true);
|
|
|
|
input.transform.localScale = Vector2.one;
|
|
|
|
|
2022-08-23 14:27:30 +00:00
|
|
|
if(tooltip != string.Empty)
|
2022-03-01 21:37:17 +00:00
|
|
|
Tooltip.AddTooltip(input, "", tooltip);
|
|
|
|
|
2022-08-23 14:27:30 +00:00
|
|
|
return input;
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
2022-02-04 03:25:18 +00:00
|
|
|
|
|
|
|
private void DestroyParams()
|
|
|
|
{
|
2022-06-04 03:15:05 +00:00
|
|
|
Editor.instance.editingInputField = false;
|
2022-02-04 03:25:18 +00:00
|
|
|
active = false;
|
2022-02-06 09:28:32 +00:00
|
|
|
for (int i = childCountAtStart; i < transform.childCount; i++)
|
2022-02-04 03:25:18 +00:00
|
|
|
{
|
|
|
|
Destroy(transform.GetChild(i).gameObject);
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 22:20:26 +00:00
|
|
|
}
|
|
|
|
}
|