2022-01-28 02:50:57 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
2022-02-22 08:16:10 +00:00
|
|
|
using System;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
|
|
|
using TMPro;
|
|
|
|
using Starpelly;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor.Track
|
2022-01-28 02:50:57 +00:00
|
|
|
{
|
|
|
|
public class TempoTimeline : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Header("Components")]
|
|
|
|
private RectTransform rectTransform;
|
|
|
|
[SerializeField] private RectTransform RefTempoChange;
|
2022-02-22 08:16:10 +00:00
|
|
|
public TMP_InputField StartingBPM;
|
|
|
|
private RectTransform StartingBPMRect;
|
2022-02-24 14:02:21 +00:00
|
|
|
public TMP_InputField FirstBeatOffset;
|
2022-01-29 02:26:34 +00:00
|
|
|
|
|
|
|
public List<TempoTimelineObj> tempoTimelineObjs = new List<TempoTimelineObj>();
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
private bool firstUpdate;
|
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
rectTransform = this.GetComponent<RectTransform>();
|
2022-02-22 08:16:10 +00:00
|
|
|
StartingBPMRect = StartingBPM.GetComponent<RectTransform>();
|
2022-01-29 02:26:34 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < GameManager.instance.Beatmap.tempoChanges.Count; i++)
|
|
|
|
{
|
|
|
|
Beatmap.TempoChange tempoChange = GameManager.instance.Beatmap.tempoChanges[i];
|
|
|
|
AddTempoChange(false, tempoChange);
|
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-22 08:16:10 +00:00
|
|
|
if (!firstUpdate)
|
|
|
|
{
|
|
|
|
UpdateStartingBPMText();
|
2022-02-24 14:02:21 +00:00
|
|
|
UpdateOffsetText();
|
2022-02-22 08:16:10 +00:00
|
|
|
firstUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Timeline.instance.userIsEditingInputField)
|
|
|
|
return;
|
2022-01-30 12:03:37 +00:00
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
|
2022-01-28 02:50:57 +00:00
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera))
|
2022-01-28 02:50:57 +00:00
|
|
|
{
|
2022-01-29 02:26:34 +00:00
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
|
|
|
if (tempoTimelineObjs.FindAll(c => c.hovering == true).Count == 0)
|
|
|
|
{
|
|
|
|
AddTempoChange(true);
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPMRect, Input.mousePosition, Editor.instance.EditorCamera))
|
2022-01-29 02:26:34 +00:00
|
|
|
{
|
|
|
|
float increase = Input.mouseScrollDelta.y;
|
|
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
|
|
increase /= 100f;
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
increase *= 5f;
|
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
if (increase != 0f)
|
|
|
|
{
|
|
|
|
GameManager.instance.Beatmap.bpm += increase;
|
|
|
|
UpdateStartingBPMText();
|
2022-03-19 12:46:38 +00:00
|
|
|
UpdateStartingBPMFromText(); // In case the scrolled-to value is invalid.
|
2022-06-28 20:58:23 +00:00
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 08:16:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateStartingBPMText()
|
|
|
|
{
|
|
|
|
StartingBPM.text = GameManager.instance.Beatmap.bpm.ToString("G");
|
|
|
|
}
|
|
|
|
|
2022-02-24 14:02:21 +00:00
|
|
|
public void UpdateOffsetText()
|
|
|
|
{
|
|
|
|
FirstBeatOffset.text = (GameManager.instance.Beatmap.firstBeatOffset * 1000f).ToString("G");
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
public void UpdateStartingBPMFromText()
|
|
|
|
{
|
|
|
|
// Failsafe against empty string.
|
|
|
|
if (String.IsNullOrEmpty(StartingBPM.text))
|
|
|
|
StartingBPM.text = "120";
|
|
|
|
|
|
|
|
var newBPM = Convert.ToSingle(StartingBPM.text);
|
|
|
|
|
|
|
|
// Failsafe against negative BPM.
|
|
|
|
if (newBPM < 1f)
|
2022-01-29 02:26:34 +00:00
|
|
|
{
|
2022-03-19 12:46:38 +00:00
|
|
|
StartingBPM.text = "1";
|
|
|
|
newBPM = 1;
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
2022-02-22 08:16:10 +00:00
|
|
|
|
|
|
|
// Limit decimal places to 4.
|
|
|
|
newBPM = (float)System.Math.Round(newBPM, 4);
|
|
|
|
|
|
|
|
GameManager.instance.Beatmap.bpm = newBPM;
|
|
|
|
|
|
|
|
// In case the newBPM ended up differing from the inputted string.
|
|
|
|
UpdateStartingBPMText();
|
2022-06-28 20:58:23 +00:00
|
|
|
|
|
|
|
Timeline.instance.FitToSong();
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 14:02:21 +00:00
|
|
|
public void UpdateOffsetFromText()
|
|
|
|
{
|
|
|
|
// Failsafe against empty string.
|
|
|
|
if (String.IsNullOrEmpty(FirstBeatOffset.text))
|
|
|
|
FirstBeatOffset.text = "0";
|
|
|
|
|
|
|
|
// Convert ms to s.
|
|
|
|
var newOffset = Convert.ToSingle(FirstBeatOffset.text) / 1000f;
|
|
|
|
|
|
|
|
// Limit decimal places to 4.
|
|
|
|
newOffset = (float)System.Math.Round(newOffset, 4);
|
|
|
|
|
|
|
|
GameManager.instance.Beatmap.firstBeatOffset = newOffset;
|
|
|
|
|
|
|
|
UpdateOffsetText();
|
|
|
|
}
|
|
|
|
|
2022-07-04 14:28:40 +00:00
|
|
|
public void ClearTempoTimeline()
|
|
|
|
{
|
|
|
|
foreach (TempoTimelineObj tempoTimelineObj in tempoTimelineObjs)
|
|
|
|
{
|
|
|
|
Destroy(tempoTimelineObj.gameObject);
|
|
|
|
}
|
|
|
|
tempoTimelineObjs.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddTempoChange(bool create, Beatmap.TempoChange tempoChange_ = null)
|
2022-06-06 16:54:57 +00:00
|
|
|
{
|
2022-01-28 02:50:57 +00:00
|
|
|
GameObject tempoChange = Instantiate(RefTempoChange.gameObject, this.transform);
|
|
|
|
|
|
|
|
tempoChange.transform.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
|
|
|
tempoChange.transform.GetChild(1).GetComponent<Image>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
|
|
|
tempoChange.transform.GetChild(2).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.TempoLayerCol.Hex2RGB();
|
|
|
|
|
|
|
|
tempoChange.SetActive(true);
|
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
TempoTimelineObj tempoTimelineObj = tempoChange.GetComponent<TempoTimelineObj>();
|
|
|
|
|
|
|
|
if (create == true)
|
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
tempoChange.transform.position = new Vector3(Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition).x + 0.08f, tempoChange.transform.position.y);
|
2022-02-12 01:15:36 +00:00
|
|
|
tempoChange.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(tempoChange.transform.localPosition.x, Timeline.SnapInterval()), tempoChange.transform.localPosition.y);
|
2022-01-29 02:26:34 +00:00
|
|
|
|
|
|
|
Beatmap.TempoChange tempoC = new Beatmap.TempoChange();
|
|
|
|
tempoC.beat = tempoChange.transform.localPosition.x;
|
|
|
|
tempoC.tempo = GameManager.instance.Beatmap.bpm;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
tempoTimelineObj.tempoChange = tempoC;
|
|
|
|
GameManager.instance.Beatmap.tempoChanges.Add(tempoC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempoChange.transform.localPosition = new Vector3(tempoChange_.beat, tempoChange.transform.localPosition.y);
|
|
|
|
|
|
|
|
tempoTimelineObj.tempoChange = tempoChange_;
|
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
tempoTimelineObjs.Add(tempoTimelineObj);
|
2022-06-28 20:58:23 +00:00
|
|
|
|
|
|
|
Timeline.instance.FitToSong();
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|