Editor: Starting BPM can be entered via input field as well as through the BPM change tool.

This commit is contained in:
Jenny Crowe 2022-02-22 01:16:10 -07:00
parent 12c70d4311
commit 19a76babd2
5 changed files with 1105 additions and 277 deletions

File diff suppressed because it is too large Load diff

View file

@ -350,6 +350,7 @@ namespace RhythmHeavenMania.Editor
string json = Encoding.Default.GetString(bytes); string json = Encoding.Default.GetString(bytes);
GameManager.instance.LoadRemix(json); GameManager.instance.LoadRemix(json);
Timeline.instance.LoadRemix(); Timeline.instance.LoadRemix();
Timeline.instance.TempoInfo.UpdateStartingBPMText();
} }
} }
} }

View file

@ -71,12 +71,13 @@ namespace RhythmHeavenMania.Editor
slider.maxValue = fl.max; slider.maxValue = fl.max;
slider.value = System.Convert.ToSingle(parameterManager.entity[propertyName]); slider.value = System.Convert.ToSingle(parameterManager.entity[propertyName]);
inputField.text = slider.value.ToString("G4"); // G4 = Display no more than 4 decimal places. inputField.text = slider.value.ToString("G");
slider.onValueChanged.AddListener(delegate slider.onValueChanged.AddListener(delegate
{ {
inputField.text = slider.value.ToString("G4"); var newValue = (float)System.Math.Round(slider.value, 4);
parameterManager.entity[propertyName] = (float)System.Math.Round(slider.value, 4); inputField.text = newValue.ToString("G");
parameterManager.entity[propertyName] = newValue;
}); });
inputField.onEndEdit.AddListener(delegate inputField.onEndEdit.AddListener(delegate

View file

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System;
using TMPro; using TMPro;
using Starpelly; using Starpelly;
@ -13,13 +14,17 @@ namespace RhythmHeavenMania.Editor.Track
[Header("Components")] [Header("Components")]
private RectTransform rectTransform; private RectTransform rectTransform;
[SerializeField] private RectTransform RefTempoChange; [SerializeField] private RectTransform RefTempoChange;
[SerializeField] private RectTransform StartingBPM; public TMP_InputField StartingBPM;
private RectTransform StartingBPMRect;
public List<TempoTimelineObj> tempoTimelineObjs = new List<TempoTimelineObj>(); public List<TempoTimelineObj> tempoTimelineObjs = new List<TempoTimelineObj>();
private bool firstUpdate;
private void Start() private void Start()
{ {
rectTransform = this.GetComponent<RectTransform>(); rectTransform = this.GetComponent<RectTransform>();
StartingBPMRect = StartingBPM.GetComponent<RectTransform>();
for (int i = 0; i < GameManager.instance.Beatmap.tempoChanges.Count; i++) for (int i = 0; i < GameManager.instance.Beatmap.tempoChanges.Count; i++)
{ {
@ -30,7 +35,14 @@ namespace RhythmHeavenMania.Editor.Track
private void Update() private void Update()
{ {
StartingBPM.GetChild(0).GetComponent<TMP_Text>().text = GameManager.instance.Beatmap.bpm.ToString(); if (!firstUpdate)
{
UpdateStartingBPMText();
firstUpdate = true;
}
if (Timeline.instance.userIsEditingInputField)
return;
if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped()) if (Timeline.instance.timelineState.tempoChange && !Conductor.instance.NotStopped())
{ {
@ -45,7 +57,7 @@ namespace RhythmHeavenMania.Editor.Track
} }
} }
if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPM, Input.mousePosition, Editor.instance.EditorCamera)) if (RectTransformUtility.RectangleContainsScreenPoint(StartingBPMRect, Input.mousePosition, Editor.instance.EditorCamera))
{ {
float increase = Input.mouseScrollDelta.y; float increase = Input.mouseScrollDelta.y;
if (Input.GetKey(KeyCode.LeftControl)) if (Input.GetKey(KeyCode.LeftControl))
@ -53,19 +65,42 @@ namespace RhythmHeavenMania.Editor.Track
if (Input.GetKey(KeyCode.LeftShift)) if (Input.GetKey(KeyCode.LeftShift))
increase *= 5f; increase *= 5f;
GameManager.instance.Beatmap.bpm += increase; if (increase != 0f)
StartingBPM.transform.GetChild(0).GetComponent<TMP_Text>().text = GameManager.instance.Beatmap.bpm.ToString(); {
GameManager.instance.Beatmap.bpm += increase;
UpdateStartingBPMText();
}
} }
}
}
StartingBPM.GetComponent<Image>().enabled = true; public void UpdateStartingBPMText()
StartingBPM.GetComponent<Button>().enabled = true; {
} StartingBPM.text = GameManager.instance.Beatmap.bpm.ToString("G");
else }
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)
{ {
StartingBPM.GetComponent<Image>().enabled = false; StartingBPM.text = "120";
StartingBPM.GetComponent<Button>().enabled = false; newBPM = 100;
StartingBPM.GetComponent<Button>().targetGraphic.color = Color.white;
} }
// 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();
} }
private void AddTempoChange(bool create, Beatmap.TempoChange tempoChange_ = null) private void AddTempoChange(bool create, Beatmap.TempoChange tempoChange_ = null)

View file

@ -68,6 +68,7 @@ namespace RhythmHeavenMania.Editor.Track
[SerializeField] private RectTransform TimelineSongPosLineRef; [SerializeField] private RectTransform TimelineSongPosLineRef;
[SerializeField] private RectTransform TimelineEventObjRef; [SerializeField] private RectTransform TimelineEventObjRef;
[SerializeField] private RectTransform LayersRect; [SerializeField] private RectTransform LayersRect;
public TempoTimeline TempoInfo;
private RectTransform TimelineSongPosLine; private RectTransform TimelineSongPosLine;
[Header("Timeline Playbar")] [Header("Timeline Playbar")]
@ -83,7 +84,7 @@ namespace RhythmHeavenMania.Editor.Track
public static Timeline instance { get; private set; } public static Timeline instance { get; private set; }
private bool userIsEditingInputField public bool userIsEditingInputField
{ {
get get
{ {