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-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-08 16:42:48 +00:00
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#region Initializers
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
|
|
|
{
|
|
|
|
var entity = GameManager.instance.Beatmap.entities[i];
|
|
|
|
var e = GameManager.instance.Beatmap.entities[i];
|
2022-01-09 23:35:55 +00:00
|
|
|
|
|
|
|
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(e.datamodel.Split(0)), e.datamodel.Split(1));
|
|
|
|
|
|
|
|
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
2022-01-08 16:42:48 +00:00
|
|
|
g.transform.localPosition = new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -205.36f), 51.34f));
|
|
|
|
g.transform.GetChild(1).GetComponent<TMP_Text>().text = e.datamodel.Split('/')[1];
|
|
|
|
|
2022-01-09 23:35:55 +00:00
|
|
|
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
|
|
|
eventObj.Icon.sprite = Editor.GameIcon(e.datamodel.Split(0));
|
2022-01-08 16:42:48 +00:00
|
|
|
|
|
|
|
if (gameAction != null)
|
|
|
|
{
|
2022-01-09 23:35:55 +00:00
|
|
|
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent<RectTransform>().sizeDelta.y);
|
|
|
|
float length = gameAction.defaultLength;
|
|
|
|
eventObj.length = length;
|
2022-01-08 16:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g.SetActive(true);
|
2022-01-09 23:35:55 +00:00
|
|
|
entity.eventObj = g.GetComponent<TimelineEventObj>();
|
|
|
|
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
|
2022-01-08 16:42:48 +00:00
|
|
|
}
|
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-08 16:42:48 +00:00
|
|
|
Conductor.instance.Play(time);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
{
|
|
|
|
// isPaused = true;
|
2022-01-07 11:36:23 +00:00
|
|
|
Conductor.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-08 16:42:48 +00:00
|
|
|
Conductor.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);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|