AstrlJelly ee8cc96f15
Editor Refresh (R1) (#911)
* put things in better places

oh this looks. so much fucking better. wow

* new icons and stuff

* modifier, zoom formula, tab name

tab name is future proofing.
also, dllnotfoundexception when using the file explorer? wtf

* dialog placement mostly working

basically ready to pr. just gotta merge stuff into it

* a few tweaks! all good now

---------

Co-authored-by: ev <85412919+iloveoatmeal2022@users.noreply.github.com>
2024-05-08 19:26:43 +00:00

139 lines
4.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using DG.Tweening;
using Jukebox;
using Jukebox.Legacy;
using HeavenStudio.InputSystem;
namespace HeavenStudio.Editor.Track
{
public class TempoTimelineObj : SpecialTimelineObj
{
[Header("Components")]
[SerializeField] private TMP_Text tempoTXT;
[SerializeField] private GameObject tempoLine;
[SerializeField] private TempoDialog tempoDialog;
new private void Update()
{
base.Update();
if (hovering)
{
SpecialTimeline.hoveringTypes |= SpecialTimeline.HoveringTypes.TempoChange;
if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.TempoChange)
{
float newTempo = Input.mouseScrollDelta.y;
if (Input.GetKey(KeyCode.LeftShift))
newTempo *= 5f;
if (Input.GetKey(InputKeyboard.MODIFIER)) {
newTempo *= 0.01f;
}
if (newTempo != 0)
{
SetTempo(chartEntity["tempo"] + newTempo);
tempoDialog.RefreshDialog();
}
}
}
UpdateTempo();
}
public void SetTempo(float tempo)
{
chartEntity["tempo"] = Mathf.Clamp(tempo, 1, 10000);
if (first)
{
Timeline.instance.UpdateStartingBPMText();
}
Timeline.instance.FitToSong();
UpdateTempo();
}
private void UpdateTempo()
{
tempoTXT.text = chartEntity["tempo"].ToString("F") + $" BPM";
if (!moving)
SetX(chartEntity);
}
public void SetSwing(float swing)
{
chartEntity["swing"] = Mathf.Clamp(swing, 0, 0.5f);
UpdateTempo();
}
public void SetSwingDivision(bool sixteenth)
{
chartEntity["swingDivision"] = sixteenth ? 0.5f : 1f;
UpdateTempo();
}
public override void Init()
{
UpdateTempo();
}
public override void OnLeftClick()
{
if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.TempoChange)
StartMove();
}
public override void OnRightClick()
{
if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.TempoChange)
{
tempoDialog.SetTempoObj(this);
tempoDialog.SwitchTempoDialog();
}
}
public override bool OnMove(float beat, bool final = false)
{
if (beat < 0) beat = 0;
foreach (var tempoChange in GameManager.instance.Beatmap.TempoChanges)
{
if (this.chartEntity == tempoChange)
continue;
if (beat > tempoChange.beat - Timeline.instance.snapInterval && beat < tempoChange.beat + Timeline.instance.snapInterval)
return false;
}
if (final)
CommandManager.Instance.AddCommand(new Commands.MoveMarker(chartEntity.guid, beat, type));
else
SetX(beat);
return true;
}
public override void SetVisibility(Timeline.CurrentTimelineState.State state)
{
if (state == Timeline.CurrentTimelineState.State.TempoChange || state == Timeline.CurrentTimelineState.State.Selection)
{
gameObject.SetActive(true);
if (state == Timeline.CurrentTimelineState.State.TempoChange)
tempoLine.SetActive(true);
else
tempoLine.SetActive(false);
}
else
gameObject.SetActive(false);
}
public void Remove()
{
if (first) return;
if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.TempoChange)
{
DeleteObj();
}
}
}
}