HeavenStudioPlus/Assets/Scripts/LevelEditor/Timeline/TempoTimeline.cs

106 lines
4.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Starpelly;
namespace RhythmHeavenMania.Editor.Track
{
public class TempoTimeline : MonoBehaviour
{
[Header("Components")]
private RectTransform rectTransform;
[SerializeField] private RectTransform RefTempoChange;
2022-01-29 02:26:34 +00:00
[SerializeField] private RectTransform StartingBPM;
public List<TempoTimelineObj> tempoTimelineObjs = new List<TempoTimelineObj>();
private void Start()
{
rectTransform = this.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);
}
}
private void Update()
{
2022-01-30 12:03:37 +00:00
StartingBPM.GetChild(0).GetComponent<TMP_Text>().text = GameManager.instance.Beatmap.bpm.ToString();
2022-01-29 02:26:34 +00:00
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
{
2022-02-03 08:25:27 +00:00
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera))
{
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-29 02:26:34 +00:00
2022-02-03 08:25:27 +00:00
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, 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;
GameManager.instance.Beatmap.bpm += increase;
StartingBPM.transform.GetChild(0).GetComponent<TMP_Text>().text = GameManager.instance.Beatmap.bpm.ToString();
}
StartingBPM.GetComponent<Image>().enabled = true;
StartingBPM.GetComponent<Button>().enabled = true;
}
else
{
StartingBPM.GetComponent<Image>().enabled = false;
StartingBPM.GetComponent<Button>().enabled = false;
StartingBPM.GetComponent<Button>().targetGraphic.color = Color.white;
}
}
2022-01-29 02:26:34 +00:00
private void AddTempoChange(bool create, Beatmap.TempoChange tempoChange_ = null)
{
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);
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-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-29 02:26:34 +00:00
tempoTimelineObjs.Add(tempoTimelineObj);
}
}
}