2022-01-06 00:11:33 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
using TMPro;
|
2022-01-08 16:42:48 +00:00
|
|
|
using Starpelly;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Editor
|
|
|
|
{
|
|
|
|
public class Timeline : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Header("Song Positions")]
|
|
|
|
[SerializeField] private TMP_Text SongBeat;
|
|
|
|
[SerializeField] private TMP_Text SongPos;
|
|
|
|
|
|
|
|
[Header("Timeline Properties")]
|
|
|
|
private float lastBeatPos = 0;
|
2022-01-07 23:51:08 +00:00
|
|
|
private Vector2 lastMousePos;
|
2022-01-13 03:59:54 +00:00
|
|
|
public List<TimelineEventObj> eventObjs = new List<TimelineEventObj>();
|
|
|
|
private bool lastFrameDrag;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
|
|
|
[Header("Timeline Components")]
|
2022-01-07 11:36:23 +00:00
|
|
|
[SerializeField] private RectTransform TimelineSlider;
|
2022-01-07 23:51:08 +00:00
|
|
|
[SerializeField] private TMP_Text TimelinePlaybackBeat;
|
2022-01-07 11:36:23 +00:00
|
|
|
[SerializeField] private RectTransform TimelineContent;
|
|
|
|
[SerializeField] private RectTransform TimelineSongPosLineRef;
|
2022-01-09 23:35:55 +00:00
|
|
|
[SerializeField] private RectTransform TimelineEventObjRef;
|
2022-01-07 11:36:23 +00:00
|
|
|
private RectTransform TimelineSongPosLine;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-11 00:17:29 +00:00
|
|
|
public static Timeline instance { get; private set; }
|
2022-01-08 16:42:48 +00:00
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#region Initializers
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
2022-01-11 00:17:29 +00:00
|
|
|
instance = this;
|
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
|
|
|
{
|
2022-01-13 03:59:54 +00:00
|
|
|
var entity = GameManager.instance.Beatmap.entities[i];
|
|
|
|
var e = GameManager.instance.Beatmap.entities[i];
|
|
|
|
|
|
|
|
AddEventObject(e.datamodel, false, new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -205.36f), 51.34f)), i);
|
2022-01-08 16:42:48 +00:00
|
|
|
}
|
2022-01-14 02:33:51 +00:00
|
|
|
|
|
|
|
TimelineSlider.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(1).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(2).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(3).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSongPosLineRef.GetComponent<Image>().color = EditorTheme.theme.properties.CurrentTimeMarkerCol.Hex2RGB();
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-01-07 23:51:08 +00:00
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
|
|
|
{
|
|
|
|
SongBeat.text = $"Beat {string.Format("{0:0.000}", TimelineSlider.localPosition.x)}";
|
|
|
|
SongPos.text = FormatTime(Conductor.instance.GetSongPosFromBeat(TimelineSlider.localPosition.x));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SongBeat.text = $"Beat {string.Format("{0:0.000}", Conductor.instance.songPositionInBeats)}";
|
|
|
|
SongPos.text = FormatTime(Conductor.instance.songPosition);
|
|
|
|
}
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-07 23:51:08 +00:00
|
|
|
SliderControl();
|
2022-01-06 00:11:33 +00:00
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
|
|
{
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
PlayCheck(false);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
PlayCheck(true);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastBeatPos = Conductor.instance.songPositionInBeats;
|
2022-01-07 23:51:08 +00:00
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
if (Input.GetMouseButton(1) && !Conductor.instance.isPlaying)
|
2022-01-07 23:51:08 +00:00
|
|
|
{
|
|
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(TimelineContent, Input.mousePosition, Editor.instance.EditorCamera, out lastMousePos);
|
2022-01-08 16:42:48 +00:00
|
|
|
TimelineSlider.localPosition = new Vector3(Mathp.Round2Nearest(lastMousePos.x + 0.12f, 0.25f), TimelineSlider.transform.localPosition.y);
|
2022-01-07 23:51:08 +00:00
|
|
|
|
|
|
|
Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x);
|
|
|
|
}
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void SliderControl()
|
|
|
|
{
|
2022-01-07 23:51:08 +00:00
|
|
|
TimelinePlaybackBeat.text = $"Beat {string.Format("{0:0.000}", TimelineSlider.localPosition.x)}";
|
|
|
|
|
2022-01-07 11:36:23 +00:00
|
|
|
if (TimelineSongPosLine != null)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-01-07 11:36:23 +00:00
|
|
|
TimelineSongPosLine.transform.localPosition = new Vector3(Conductor.instance.songPositionInBeats, TimelineSlider.transform.localPosition.y);
|
|
|
|
TimelineSongPosLine.transform.localScale = new Vector3(1f / TimelineContent.transform.localScale.x, TimelineSlider.transform.localScale.y, 1);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#region PlayChecks
|
|
|
|
public void PlayCheck(bool fromStart)
|
|
|
|
{
|
|
|
|
if (fromStart)
|
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
if (!Conductor.instance.isPlaying)
|
|
|
|
{
|
|
|
|
Play(false, TimelineSlider.transform.localPosition.x);
|
|
|
|
}
|
2022-01-06 00:11:33 +00:00
|
|
|
else
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
|
|
|
Stop(TimelineSlider.transform.localPosition.x);
|
|
|
|
}
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-07 23:51:08 +00:00
|
|
|
if (!Conductor.instance.isPlaying)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
Play(false, TimelineSongPosLine.transform.localPosition.x);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
public void Play(bool fromStart, float time)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
// if (fromStart) Stop();
|
2022-01-07 11:36:23 +00:00
|
|
|
|
|
|
|
if (!Conductor.instance.isPaused)
|
|
|
|
{
|
|
|
|
TimelineSongPosLine = Instantiate(TimelineSongPosLineRef, TimelineSongPosLineRef.parent).GetComponent<RectTransform>();
|
|
|
|
TimelineSongPosLine.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
GameManager.instance.Play(time);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
{
|
|
|
|
// isPaused = true;
|
2022-01-14 00:35:41 +00:00
|
|
|
GameManager.instance.Pause();
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
public void Stop(float time)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
|
|
|
// isPaused = true;
|
|
|
|
// timelineSlider.value = 0;
|
2022-01-07 11:36:23 +00:00
|
|
|
|
2022-01-07 23:51:08 +00:00
|
|
|
if (TimelineSongPosLine != null)
|
2022-01-07 11:36:23 +00:00
|
|
|
Destroy(TimelineSongPosLine.gameObject);
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
GameManager.instance.Stop(time);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Extras
|
|
|
|
private string FormatTime(float time)
|
|
|
|
{
|
|
|
|
int minutes = (int)time / 60;
|
|
|
|
int seconds = (int)time - 60 * minutes;
|
|
|
|
int milliseconds = (int)(1000 * (time - minutes * 60 - seconds));
|
|
|
|
return string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, milliseconds);
|
|
|
|
}
|
2022-01-11 00:17:29 +00:00
|
|
|
|
|
|
|
public bool CheckIfMouseInTimeline()
|
|
|
|
{
|
|
|
|
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Camera.main));
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Functions
|
|
|
|
|
2022-01-13 03:59:54 +00:00
|
|
|
public void AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), int entityId = 0)
|
2022-01-11 00:17:29 +00:00
|
|
|
{
|
|
|
|
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
2022-01-13 03:59:54 +00:00
|
|
|
g.transform.localPosition = pos;
|
2022-01-11 00:17:29 +00:00
|
|
|
g.transform.GetChild(1).GetComponent<TMP_Text>().text = eventName.Split('/')[1];
|
|
|
|
|
|
|
|
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
|
|
|
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
|
|
|
|
|
|
|
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
|
|
|
|
|
|
|
if (gameAction != null)
|
|
|
|
{
|
|
|
|
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent<RectTransform>().sizeDelta.y);
|
|
|
|
float length = gameAction.defaultLength;
|
|
|
|
eventObj.length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
g.SetActive(true);
|
|
|
|
|
|
|
|
if (dragNDrop)
|
|
|
|
{
|
2022-01-14 00:35:41 +00:00
|
|
|
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
g.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
|
|
|
|
|
2022-01-13 03:59:54 +00:00
|
|
|
|
|
|
|
Beatmap.Entity en = new Beatmap.Entity();
|
|
|
|
en.datamodel = eventName;
|
|
|
|
en.eventObj = eventObj;
|
|
|
|
|
|
|
|
GameManager.instance.Beatmap.entities.Add(en);
|
|
|
|
GameManager.instance.SortEventsList();
|
2022-01-14 00:35:41 +00:00
|
|
|
|
|
|
|
Selections.instance.ClickSelect(eventObj);
|
|
|
|
eventObj.isDragging = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var entity = GameManager.instance.Beatmap.entities[entityId];
|
|
|
|
var e = GameManager.instance.Beatmap.entities[entityId];
|
|
|
|
|
|
|
|
entity.eventObj = g.GetComponent<TimelineEventObj>();
|
|
|
|
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
2022-01-12 03:29:27 +00:00
|
|
|
|
|
|
|
Editor.EventObjs.Add(eventObj);
|
2022-01-13 03:59:54 +00:00
|
|
|
eventObjs.Add(eventObj);
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
public void DestroyEventObject(Beatmap.Entity entity)
|
2022-01-12 03:29:27 +00:00
|
|
|
{
|
2022-01-14 00:35:41 +00:00
|
|
|
Editor.EventObjs.Remove(entity.eventObj);
|
|
|
|
GameManager.instance.Beatmap.entities.Remove(entity);
|
2022-01-12 03:29:27 +00:00
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
Destroy(entity.eventObj.gameObject);
|
|
|
|
GameManager.instance.SortEventsList();
|
2022-01-12 03:29:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 03:59:54 +00:00
|
|
|
public bool IsMouseAboveEvents()
|
|
|
|
{
|
|
|
|
return Timeline.instance.eventObjs.FindAll(c => c.mouseHovering == true).Count > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsEventsDragging()
|
|
|
|
{
|
|
|
|
return Timeline.instance.eventObjs.FindAll(c => c.isDragging == true).Count > 0;
|
|
|
|
}
|
|
|
|
|
2022-01-12 03:29:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Commands
|
|
|
|
|
|
|
|
public void Move()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Undo()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|