2022-01-03 22:42:43 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
2022-01-14 02:33:51 +00:00
|
|
|
using Newtonsoft.Json;
|
2022-01-16 23:29:45 +00:00
|
|
|
using TMPro;
|
2022-01-22 10:44:19 +00:00
|
|
|
using Starpelly;
|
2022-01-14 02:33:51 +00:00
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
using RhythmHeavenMania.Editor.Track;
|
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
namespace RhythmHeavenMania.Editor
|
|
|
|
{
|
|
|
|
public class Editor : MonoBehaviour
|
|
|
|
{
|
|
|
|
private Initializer Initializer;
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
[SerializeField] private Canvas MainCanvas;
|
2022-01-07 23:51:08 +00:00
|
|
|
[SerializeField] public Camera EditorCamera;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
[Header("Rect")]
|
|
|
|
[SerializeField] private RenderTexture ScreenRenderTexture;
|
|
|
|
[SerializeField] private RawImage Screen;
|
2022-01-09 23:35:55 +00:00
|
|
|
[SerializeField] private RectTransform GridGameSelector;
|
2022-01-03 22:42:43 +00:00
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
[Header("Components")]
|
|
|
|
[SerializeField] private Timeline Timeline;
|
2022-01-16 23:29:45 +00:00
|
|
|
[SerializeField] private TMP_Text GameEventSelectorTitle;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-15 07:08:23 +00:00
|
|
|
[Header("Toolbar")]
|
|
|
|
[SerializeField] private Button NewBTN;
|
|
|
|
[SerializeField] private Button OpenBTN;
|
|
|
|
[SerializeField] private Button SaveBTN;
|
2022-01-22 10:44:19 +00:00
|
|
|
[SerializeField] private Button UndoBTN;
|
|
|
|
[SerializeField] private Button RedoBTN;
|
2022-01-15 07:08:23 +00:00
|
|
|
|
2022-01-12 03:29:27 +00:00
|
|
|
public static List<TimelineEventObj> EventObjs = new List<TimelineEventObj>();
|
|
|
|
|
2022-01-07 23:51:08 +00:00
|
|
|
public static Editor instance { get; private set; }
|
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
2022-01-07 23:51:08 +00:00
|
|
|
instance = this;
|
2022-01-03 22:42:43 +00:00
|
|
|
Initializer = GetComponent<Initializer>();
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
2022-01-03 22:42:43 +00:00
|
|
|
GameManager.instance.GameCamera.targetTexture = ScreenRenderTexture;
|
|
|
|
GameManager.instance.CursorCam.targetTexture = ScreenRenderTexture;
|
|
|
|
Screen.texture = ScreenRenderTexture;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
GameManager.instance.Init();
|
2022-01-06 00:11:33 +00:00
|
|
|
Timeline.Init();
|
2022-01-09 23:35:55 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < EventCaller.instance.minigames.Count; i++)
|
|
|
|
{
|
|
|
|
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
|
|
|
|
GameIcon_.GetComponent<Image>().sprite = GameIcon(EventCaller.instance.minigames[i].name);
|
|
|
|
GameIcon_.gameObject.SetActive(true);
|
2022-01-11 00:17:29 +00:00
|
|
|
GameIcon_.name = EventCaller.instance.minigames[i].displayName;
|
2022-01-09 23:35:55 +00:00
|
|
|
}
|
2022-01-11 02:06:13 +00:00
|
|
|
|
2022-01-23 03:40:53 +00:00
|
|
|
Tooltip.AddTooltip(NewBTN.gameObject, "New <color=#adadad>[Ctrl+N]</color>");
|
|
|
|
Tooltip.AddTooltip(OpenBTN.gameObject, "Open <color=#adadad>[Ctrl+O]</color>");
|
|
|
|
Tooltip.AddTooltip(SaveBTN.gameObject, "Save Project <color=#adadad>[Ctrl+S]</color>\nSave Project As <color=#adadad>[Ctrl+Alt+S]</color>");
|
|
|
|
Tooltip.AddTooltip(UndoBTN.gameObject, "Undo <color=#adadad>[Ctrl+Z]</color>");
|
|
|
|
Tooltip.AddTooltip(RedoBTN.gameObject, "Redo <color=#adadad>[Ctrl+Y or Ctrl+Shift+Z]</color>");
|
2022-01-09 23:35:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 22:46:14 +00:00
|
|
|
public void Update()
|
|
|
|
{
|
|
|
|
// This is buggy
|
|
|
|
/*if (Conductor.instance.isPlaying || Conductor.instance.isPaused)
|
|
|
|
{
|
|
|
|
GetComponent<Selections>().enabled = false;
|
|
|
|
GetComponent<Selector>().enabled = false;
|
|
|
|
GetComponent<BoxSelection>().enabled = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetComponent<Selections>().enabled = true;
|
|
|
|
GetComponent<Selector>().enabled = true;
|
|
|
|
GetComponent<BoxSelection>().enabled = true;
|
|
|
|
}*/
|
2022-01-22 10:44:19 +00:00
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Delete))
|
|
|
|
{
|
|
|
|
List<TimelineEventObj> ev = new List<TimelineEventObj>();
|
|
|
|
for (int i = 0; i < Selections.instance.eventsSelected.Count; i++) ev.Add(Selections.instance.eventsSelected[i]);
|
|
|
|
CommandManager.instance.Execute(new Commands.Deletion(ev));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CommandManager.instance.canUndo())
|
2022-01-25 01:02:45 +00:00
|
|
|
UndoBTN.transform.GetChild(0).GetComponent<Image>().color = "BD8CFF".Hex2RGB();
|
2022-01-22 10:44:19 +00:00
|
|
|
else
|
|
|
|
UndoBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
|
|
|
|
if (CommandManager.instance.canRedo())
|
2022-01-25 01:02:45 +00:00
|
|
|
RedoBTN.transform.GetChild(0).GetComponent<Image>().color = "FFD800".Hex2RGB();
|
2022-01-22 10:44:19 +00:00
|
|
|
else
|
|
|
|
RedoBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
|
2022-01-23 03:40:53 +00:00
|
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.Z))
|
|
|
|
{
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
CommandManager.instance.Redo();
|
|
|
|
else
|
|
|
|
CommandManager.instance.Undo();
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.Y))
|
|
|
|
{
|
|
|
|
CommandManager.instance.Redo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-22 10:44:19 +00:00
|
|
|
if (Input.GetMouseButtonUp(0) && Timeline.instance.CheckIfMouseInTimeline())
|
|
|
|
{
|
|
|
|
List<TimelineEventObj> selectedEvents = Timeline.instance.eventObjs.FindAll(c => c.selected == true && c.eligibleToMove == true);
|
|
|
|
|
|
|
|
if (selectedEvents.Count > 0)
|
|
|
|
{
|
|
|
|
List<TimelineEventObj> result = new List<TimelineEventObj>();
|
|
|
|
|
|
|
|
for (int i = 0; i < selectedEvents.Count; i++)
|
|
|
|
{
|
2022-01-28 02:50:57 +00:00
|
|
|
if (selectedEvents[i].isCreating == false)
|
|
|
|
{
|
|
|
|
result.Add(selectedEvents[i]);
|
|
|
|
}
|
2022-01-22 10:44:19 +00:00
|
|
|
selectedEvents[i].OnUp();
|
|
|
|
}
|
|
|
|
CommandManager.instance.Execute(new Commands.Move(result));
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 22:46:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 23:35:55 +00:00
|
|
|
public static Sprite GameIcon(string name)
|
|
|
|
{
|
|
|
|
return Resources.Load<Sprite>($"Sprites/Editor/GameIcons/{name}");
|
2022-01-03 22:42:43 +00:00
|
|
|
}
|
2022-01-15 22:52:53 +00:00
|
|
|
|
|
|
|
public void CopyJson()
|
|
|
|
{
|
|
|
|
string json = string.Empty;
|
|
|
|
json = JsonConvert.SerializeObject(GameManager.instance.Beatmap);
|
|
|
|
|
|
|
|
Debug.Log(json);
|
|
|
|
}
|
2022-01-16 23:29:45 +00:00
|
|
|
|
2022-01-21 21:09:14 +00:00
|
|
|
public void DebugSave()
|
|
|
|
{
|
|
|
|
// temp
|
2022-01-23 03:40:53 +00:00
|
|
|
#if UNITY_EDITOR
|
2022-01-21 21:09:14 +00:00
|
|
|
string path = UnityEditor.AssetDatabase.GetAssetPath(GameManager.instance.txt);
|
|
|
|
path = Application.dataPath.Remove(Application.dataPath.Length - 6, 6) + path;
|
|
|
|
System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(GameManager.instance.Beatmap));
|
|
|
|
Debug.Log("Saved to " + path);
|
2022-01-23 03:40:53 +00:00
|
|
|
#endif
|
2022-01-21 21:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 23:29:45 +00:00
|
|
|
public void SetGameEventTitle(string txt)
|
|
|
|
{
|
|
|
|
GameEventSelectorTitle.text = txt;
|
|
|
|
}
|
2022-01-03 22:42:43 +00:00
|
|
|
}
|
|
|
|
}
|