2022-09-18 20:48:14 +00:00
|
|
|
using System;
|
2023-02-05 03:05:36 +00:00
|
|
|
using System.Collections;
|
2022-01-06 00:11:33 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
2022-02-06 08:28:14 +00:00
|
|
|
using UnityEngine.EventSystems;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
|
|
|
using TMPro;
|
2022-01-08 16:42:48 +00:00
|
|
|
using Starpelly;
|
2023-06-10 19:17:06 +00:00
|
|
|
using Jukebox;
|
|
|
|
using Jukebox.Legacy;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Editor.Track
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
|
|
|
public class Timeline : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Header("Song Positions")]
|
|
|
|
[SerializeField] private TMP_Text SongBeat;
|
|
|
|
[SerializeField] private TMP_Text SongPos;
|
2022-01-28 02:50:57 +00:00
|
|
|
[SerializeField] private TMP_Text CurrentTempo;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
|
|
|
[Header("Timeline Properties")]
|
|
|
|
private float lastBeatPos = 0;
|
2022-01-07 23:51:08 +00:00
|
|
|
private Vector2 lastMousePos;
|
2022-01-13 03:59:54 +00:00
|
|
|
public List<TimelineEventObj> eventObjs = new List<TimelineEventObj>();
|
|
|
|
private bool lastFrameDrag;
|
2022-07-28 05:17:02 +00:00
|
|
|
public int LayerCount = 5;
|
2022-01-15 17:45:08 +00:00
|
|
|
public bool metronomeEnabled;
|
2022-01-17 19:23:18 +00:00
|
|
|
public bool resizable;
|
2022-01-29 02:26:34 +00:00
|
|
|
private bool movingPlayback;
|
|
|
|
public CurrentTimelineState timelineState = new CurrentTimelineState();
|
2022-02-12 01:15:36 +00:00
|
|
|
public float snapInterval = 0.25f; // 4/4
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
[Header("Components")]
|
|
|
|
[SerializeField] private RawImage waveform;
|
|
|
|
|
2022-02-12 01:15:36 +00:00
|
|
|
public static float SnapInterval() { return instance.snapInterval; }
|
2022-01-29 02:26:34 +00:00
|
|
|
|
2022-07-04 15:29:19 +00:00
|
|
|
public void SetSnap(float snap) { snapInterval = snap; }
|
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
public class CurrentTimelineState
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
public enum State
|
|
|
|
{
|
|
|
|
Selection,
|
|
|
|
TempoChange,
|
|
|
|
MusicVolume,
|
|
|
|
ChartSection
|
|
|
|
}
|
|
|
|
|
|
|
|
public State currentState = State.Selection;
|
|
|
|
|
|
|
|
public bool selected { get { return currentState == State.Selection; } }
|
|
|
|
public bool tempoChange { get { return currentState == State.TempoChange; } }
|
|
|
|
public bool musicVolume { get { return currentState == State.MusicVolume; } }
|
|
|
|
public bool chartSection { get { return currentState == State.ChartSection; } }
|
2022-01-29 02:26:34 +00:00
|
|
|
|
|
|
|
public void SetState(bool selected, bool tempoChange, bool musicVolume)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.NotStopped()) return;
|
|
|
|
|
|
|
|
if (selected)
|
2022-09-18 20:48:14 +00:00
|
|
|
{
|
|
|
|
currentState = State.Selection;
|
2022-01-29 02:26:34 +00:00
|
|
|
instance.SelectionsBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-09-18 20:48:14 +00:00
|
|
|
instance.SelectionsBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
else
|
|
|
|
instance.SelectionsBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
if (tempoChange)
|
2022-09-18 20:48:14 +00:00
|
|
|
{
|
|
|
|
currentState = State.TempoChange;
|
2022-01-29 02:26:34 +00:00
|
|
|
instance.TempoChangeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-09-18 20:48:14 +00:00
|
|
|
instance.TempoChangeBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
else
|
|
|
|
instance.TempoChangeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
if (musicVolume)
|
2022-09-18 20:48:14 +00:00
|
|
|
{
|
|
|
|
currentState = State.MusicVolume;
|
2022-01-29 02:26:34 +00:00
|
|
|
instance.MusicVolumeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-09-18 20:48:14 +00:00
|
|
|
instance.MusicVolumeBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
else
|
|
|
|
instance.MusicVolumeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
|
|
|
|
}
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
public void SetState(State state)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.NotStopped()) return;
|
|
|
|
|
|
|
|
currentState = state;
|
|
|
|
if (selected)
|
|
|
|
{
|
|
|
|
instance.SelectionsBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
|
|
|
instance.SelectionsBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
instance.SelectionsBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
if (tempoChange)
|
|
|
|
{
|
|
|
|
instance.TempoChangeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
|
|
|
instance.TempoChangeBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
instance.TempoChangeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
if (musicVolume)
|
|
|
|
{
|
|
|
|
instance.MusicVolumeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
|
|
|
instance.MusicVolumeBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
instance.MusicVolumeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
if (chartSection)
|
|
|
|
{
|
|
|
|
instance.ChartSectionBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
|
|
|
instance.ChartSectionBTN.GetComponent<TabButton>().Invoke("OnClick", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
instance.ChartSectionBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
}
|
2022-01-29 02:26:34 +00:00
|
|
|
}
|
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-29 02:26:34 +00:00
|
|
|
[SerializeField] private RectTransform TimelineGridSelect;
|
2022-09-18 20:48:14 +00:00
|
|
|
[SerializeField] private RectTransform TimelineEventGrid;
|
2022-01-07 23:51:08 +00:00
|
|
|
[SerializeField] private TMP_Text TimelinePlaybackBeat;
|
2023-02-05 03:05:36 +00:00
|
|
|
public ScrollRect TimelineScroll;
|
2022-02-18 02:57:35 +00:00
|
|
|
public RectTransform TimelineContent;
|
2023-02-05 03:05:36 +00:00
|
|
|
[SerializeField] private ZoomComponent zoomComponent;
|
2022-01-07 11:36:23 +00:00
|
|
|
[SerializeField] private RectTransform TimelineSongPosLineRef;
|
2022-01-09 23:35:55 +00:00
|
|
|
[SerializeField] private RectTransform TimelineEventObjRef;
|
2022-01-14 22:46:14 +00:00
|
|
|
[SerializeField] private RectTransform LayersRect;
|
2022-06-30 01:58:21 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
[Header("Timeline Inputs")]
|
|
|
|
public TMP_InputField FirstBeatOffset;
|
|
|
|
public TMP_InputField StartingTempoSpecialAll;
|
|
|
|
public TMP_InputField StartingTempoSpecialTempo;
|
|
|
|
public TMP_InputField StartingVolumeSpecialVolume;
|
|
|
|
|
|
|
|
public SpecialTimeline SpecialInfo;
|
2022-01-07 11:36:23 +00:00
|
|
|
private RectTransform TimelineSongPosLine;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-01-15 05:20:47 +00:00
|
|
|
[Header("Timeline Playbar")]
|
2022-01-23 03:40:53 +00:00
|
|
|
public Button PlayBTN;
|
|
|
|
public Button PauseBTN;
|
|
|
|
public Button StopBTN;
|
|
|
|
public Button MetronomeBTN;
|
|
|
|
public Button AutoplayBTN;
|
2022-01-28 02:50:57 +00:00
|
|
|
public Button SelectionsBTN;
|
|
|
|
public Button TempoChangeBTN;
|
|
|
|
public Button MusicVolumeBTN;
|
2022-09-18 20:48:14 +00:00
|
|
|
public Button ChartSectionBTN;
|
2023-02-05 03:05:36 +00:00
|
|
|
public Button ZoomInBTN;
|
|
|
|
public Button ZoomOutBTN;
|
|
|
|
public Button ZoomResetBTN;
|
|
|
|
public Button WaveformBTN;
|
2022-02-03 07:28:14 +00:00
|
|
|
public Slider PlaybackSpeed;
|
2022-01-15 05:20:47 +00:00
|
|
|
|
2022-06-30 01:58:21 +00:00
|
|
|
public Vector3[] LayerCorners = new Vector3[4];
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
public float leftSide => (TimelineContent.localPosition.x / TimelineContent.localScale.x) * -1;
|
|
|
|
public float rightSide => (TimelineScroll.viewport.rect.width / TimelineContent.localScale.x) + leftSide;
|
|
|
|
|
2022-01-11 00:17:29 +00:00
|
|
|
public static Timeline instance { get; private set; }
|
2022-01-08 16:42:48 +00:00
|
|
|
|
2022-02-22 08:16:10 +00:00
|
|
|
public bool userIsEditingInputField
|
2022-02-06 08:28:14 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var selectedGO = EventSystem.current.currentSelectedGameObject;
|
|
|
|
return selectedGO != null && (selectedGO.GetComponent<InputField>() != null || selectedGO.GetComponent<TMP_InputField>() != null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#region Initializers
|
|
|
|
|
2022-01-30 12:03:37 +00:00
|
|
|
public void LoadRemix()
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-07-04 14:28:40 +00:00
|
|
|
// beatmap entities
|
2022-01-30 12:03:37 +00:00
|
|
|
for (int i = 0; i < eventObjs.Count; i++)
|
|
|
|
{
|
|
|
|
Destroy(eventObjs[i].gameObject);
|
|
|
|
}
|
|
|
|
eventObjs.Clear();
|
2022-01-11 00:17:29 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
for (int i = 0; i < GameManager.instance.Beatmap.Entities.Count; i++)
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
var e = GameManager.instance.Beatmap.Entities[i];
|
2022-01-13 03:59:54 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
AddEventObject(e.datamodel, false, new Vector3((float)e.beat, -e["track"] * LayerHeight()), e, false);
|
2022-01-08 16:42:48 +00:00
|
|
|
}
|
2022-07-04 14:28:40 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
SpecialInfo.Setup();
|
|
|
|
UpdateOffsetText();
|
|
|
|
UpdateStartingBPMText();
|
|
|
|
UpdateStartingVolText();
|
2022-01-30 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
LoadRemix();
|
2022-01-14 02:33:51 +00:00
|
|
|
|
|
|
|
TimelineSlider.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(1).GetComponent<Image>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(2).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSlider.GetChild(3).GetComponent<TMP_Text>().color = EditorTheme.theme.properties.BeatMarkerCol.Hex2RGB();
|
|
|
|
TimelineSongPosLineRef.GetComponent<Image>().color = EditorTheme.theme.properties.CurrentTimeMarkerCol.Hex2RGB();
|
2022-01-15 05:20:47 +00:00
|
|
|
|
|
|
|
PlayBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
if (Conductor.instance.isPaused)
|
|
|
|
PlayCheck(false);
|
|
|
|
else
|
|
|
|
PlayCheck(true);
|
|
|
|
});
|
2022-01-17 02:31:49 +00:00
|
|
|
PauseBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
if (Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
|
|
|
PlayCheck(false);
|
|
|
|
});
|
|
|
|
StopBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
if (Conductor.instance.isPlaying || Conductor.instance.isPaused)
|
2023-02-05 03:05:36 +00:00
|
|
|
PlayCheck(true);
|
2022-01-17 02:31:49 +00:00
|
|
|
});
|
|
|
|
|
2022-01-15 17:45:08 +00:00
|
|
|
MetronomeBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2022-02-26 07:03:33 +00:00
|
|
|
MetronomeToggle();
|
2022-01-15 17:45:08 +00:00
|
|
|
});
|
2022-01-23 03:40:53 +00:00
|
|
|
AutoplayBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2022-02-26 07:03:33 +00:00
|
|
|
AutoPlayToggle();
|
2022-01-23 03:40:53 +00:00
|
|
|
});
|
2022-01-15 05:20:47 +00:00
|
|
|
|
2022-01-29 02:26:34 +00:00
|
|
|
SelectionsBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.Selection);
|
2022-01-29 02:26:34 +00:00
|
|
|
});
|
|
|
|
TempoChangeBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.TempoChange);
|
2022-01-29 02:26:34 +00:00
|
|
|
});
|
|
|
|
MusicVolumeBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.MusicVolume);
|
|
|
|
});
|
|
|
|
ChartSectionBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
timelineState.SetState(CurrentTimelineState.State.ChartSection);
|
2022-01-29 02:26:34 +00:00
|
|
|
});
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
ZoomInBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2023-02-05 19:48:49 +00:00
|
|
|
zoomComponent.ZoomIn(1, Vector2.zero);
|
2023-02-05 03:05:36 +00:00
|
|
|
});
|
|
|
|
ZoomOutBTN.onClick.AddListener(delegate
|
|
|
|
{
|
2023-02-05 19:48:49 +00:00
|
|
|
zoomComponent.ZoomOut(-1, Vector2.zero);
|
2023-02-05 03:05:36 +00:00
|
|
|
});
|
|
|
|
ZoomResetBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
zoomComponent.ResetZoom();
|
|
|
|
});
|
|
|
|
WaveformBTN.onClick.AddListener(delegate
|
|
|
|
{
|
|
|
|
WaveformToggle();
|
|
|
|
});
|
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
Tooltip.AddTooltip(SongBeat.gameObject, "Current Beat");
|
|
|
|
Tooltip.AddTooltip(SongPos.gameObject, "Current Time");
|
|
|
|
Tooltip.AddTooltip(CurrentTempo.gameObject, "Current Tempo (BPM)");
|
|
|
|
|
2022-01-18 00:40:23 +00:00
|
|
|
Tooltip.AddTooltip(PlayBTN.gameObject, "Play <color=#adadad>[Space]</color>");
|
|
|
|
Tooltip.AddTooltip(PauseBTN.gameObject, "Pause <color=#adadad>[Shift + Space]</color>");
|
|
|
|
Tooltip.AddTooltip(StopBTN.gameObject, "Stop <color=#adadad>[Space]</color>");
|
2022-01-23 03:40:53 +00:00
|
|
|
|
2022-02-26 07:03:33 +00:00
|
|
|
Tooltip.AddTooltip(MetronomeBTN.gameObject, "Metronome <color=#adadad>[M]</color>");
|
2022-03-03 04:40:59 +00:00
|
|
|
Tooltip.AddTooltip(AutoplayBTN.gameObject, "Autoplay <color=#adadad>[P]</color>");
|
2022-01-15 05:20:47 +00:00
|
|
|
|
2022-01-28 02:50:57 +00:00
|
|
|
Tooltip.AddTooltip(SelectionsBTN.gameObject, "Tool: Selection <color=#adadad>[1]</color>");
|
|
|
|
Tooltip.AddTooltip(TempoChangeBTN.gameObject, "Tool: Tempo Change <color=#adadad>[2]</color>");
|
|
|
|
Tooltip.AddTooltip(MusicVolumeBTN.gameObject, "Tool: Music Volume <color=#adadad>[3]</color>");
|
2022-09-18 20:48:14 +00:00
|
|
|
Tooltip.AddTooltip(ChartSectionBTN.gameObject, "Tool: Beatmap Sections <color=#adadad>[4]</color>");
|
|
|
|
|
|
|
|
Tooltip.AddTooltip(StartingTempoSpecialAll.gameObject, "Starting Tempo (BPM)");
|
|
|
|
Tooltip.AddTooltip(StartingTempoSpecialTempo.gameObject, "Starting Tempo (BPM)");
|
|
|
|
Tooltip.AddTooltip(StartingVolumeSpecialVolume.gameObject, "Starting Volume (%)");
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
Tooltip.AddTooltip(ZoomInBTN.gameObject, "Zoom In");
|
|
|
|
Tooltip.AddTooltip(ZoomOutBTN.gameObject, "Zoom Out");
|
|
|
|
Tooltip.AddTooltip(ZoomResetBTN.gameObject, "Zoom Reset");
|
|
|
|
Tooltip.AddTooltip(WaveformBTN.gameObject, "Waveform Toggle");
|
|
|
|
|
2022-02-03 07:28:14 +00:00
|
|
|
Tooltip.AddTooltip(PlaybackSpeed.gameObject, "The preview's playback speed. Right click to reset to 1.0");
|
|
|
|
|
2022-01-15 05:20:47 +00:00
|
|
|
SetTimeButtonColors(true, false, false);
|
2022-01-15 17:45:08 +00:00
|
|
|
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.Selection);
|
2022-02-05 13:47:47 +00:00
|
|
|
|
|
|
|
AutoBtnUpdate();
|
|
|
|
}
|
|
|
|
|
2022-03-10 04:24:06 +00:00
|
|
|
public void FitToSong()
|
|
|
|
{
|
|
|
|
var currentSizeDelta = TimelineContent.sizeDelta;
|
|
|
|
float songBeats = Conductor.instance.SongLengthInBeats();
|
|
|
|
if (songBeats == 0) songBeats = 320;
|
|
|
|
else songBeats += 10;
|
|
|
|
TimelineContent.sizeDelta = new Vector2(songBeats, currentSizeDelta.y);
|
2022-09-19 14:04:56 +00:00
|
|
|
TimelineEventGrid.sizeDelta = new Vector2(songBeats, currentSizeDelta.y);
|
2022-03-10 04:24:06 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
public void CreateWaveform()
|
|
|
|
{
|
|
|
|
Debug.Log("what");
|
|
|
|
// DrawWaveform();
|
2023-06-10 19:17:06 +00:00
|
|
|
// StartCoroutine(DrawWaveformRealtime());
|
2023-02-05 03:05:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 13:47:47 +00:00
|
|
|
public void AutoBtnUpdate()
|
|
|
|
{
|
|
|
|
var animName = GameManager.instance.autoplay ? "Idle" : "Disabled";
|
|
|
|
AutoplayBTN.GetComponent<Animator>().Play(animName, 0, 0);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 07:03:33 +00:00
|
|
|
public void AutoPlayToggle()
|
|
|
|
{
|
|
|
|
if (!GameManager.instance.autoplay)
|
|
|
|
{
|
|
|
|
AutoplayBTN.GetComponent<Animator>().Play("Idle", 0, 0);
|
|
|
|
GameManager.instance.autoplay = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AutoplayBTN.GetComponent<Animator>().Play("Disabled", 0, 0);
|
|
|
|
GameManager.instance.autoplay = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MetronomeToggle()
|
|
|
|
{
|
|
|
|
if (!Conductor.instance.metronome)
|
|
|
|
{
|
|
|
|
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = "009FC6".Hex2RGB();
|
|
|
|
Conductor.instance.metronome = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MetronomeBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
|
|
|
Conductor.instance.metronome = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-23 03:40:53 +00:00
|
|
|
public static string RandomID()
|
|
|
|
{
|
|
|
|
return Starpelly.Random.Strings.RandomString(Starpelly.Enums.Strings.StringType.Alphanumeric, 128);
|
|
|
|
}
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
// waveform.rectTransform.anchoredPosition = new Vector2(
|
|
|
|
// -(GameManager.instance.Beatmap.data.offset / (60.0f / GameManager.instance.Beatmap.bpm)),
|
|
|
|
// waveform.rectTransform.anchoredPosition.y);
|
2023-02-05 03:05:36 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
// WaveformBTN.transform.GetChild(0).GetComponent<Image>().color = (Conductor.instance.musicSource.clip != null && waveform.gameObject.activeInHierarchy) ? Color.white : Color.gray;
|
2023-02-05 03:05:36 +00:00
|
|
|
|
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)}";
|
2022-09-23 02:05:04 +00:00
|
|
|
SongPos.text = FormatTime((float) Conductor.instance.GetSongPosFromBeat(TimelineSlider.localPosition.x));
|
2022-01-07 23:51:08 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2022-07-02 02:03:15 +00:00
|
|
|
#region Keyboard Shortcuts
|
2022-08-27 03:43:01 +00:00
|
|
|
if ((!userIsEditingInputField) && Editor.instance.isShortcutsEnabled)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-07-02 02:03:15 +00:00
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
2022-06-04 03:15:05 +00:00
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
{
|
|
|
|
PlayCheck(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayCheck(true);
|
|
|
|
}
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 02:03:15 +00:00
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
|
|
{
|
2022-06-04 03:15:05 +00:00
|
|
|
AutoPlayToggle();
|
2022-07-02 02:03:15 +00:00
|
|
|
}
|
2022-02-26 07:03:33 +00:00
|
|
|
|
2022-07-02 02:03:15 +00:00
|
|
|
if (Input.GetKeyDown(KeyCode.M))
|
|
|
|
{
|
2022-06-04 03:15:05 +00:00
|
|
|
MetronomeToggle();
|
2022-07-02 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha1))
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.Selection);
|
2022-07-02 02:03:15 +00:00
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.Alpha2))
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.TempoChange);
|
2022-07-02 02:03:15 +00:00
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.Alpha3))
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
timelineState.SetState(CurrentTimelineState.State.MusicVolume);
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.Alpha4))
|
|
|
|
{
|
|
|
|
timelineState.SetState(CurrentTimelineState.State.ChartSection);
|
2022-07-02 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
if (Input.GetKeyDown(KeyCode.F))
|
|
|
|
{
|
|
|
|
PlaybackFocus(false);
|
|
|
|
}
|
2022-02-26 07:03:33 +00:00
|
|
|
|
2022-07-02 02:03:15 +00:00
|
|
|
float moveSpeed = 750;
|
2023-02-05 19:48:49 +00:00
|
|
|
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) moveSpeed *= 6;
|
|
|
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftArrow) || (!Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.A)))
|
2022-07-02 02:03:15 +00:00
|
|
|
{
|
|
|
|
TimelineContent.transform.localPosition += new Vector3(moveSpeed * Time.deltaTime, 0);
|
|
|
|
}
|
2023-02-05 19:48:49 +00:00
|
|
|
else if (Input.GetKey(KeyCode.RightArrow) || (!Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.D)))
|
2022-07-02 02:03:15 +00:00
|
|
|
{
|
|
|
|
TimelineContent.transform.localPosition += new Vector3(-moveSpeed * Time.deltaTime, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2022-02-08 01:07:03 +00:00
|
|
|
if (Input.GetMouseButton(1) && !Conductor.instance.isPlaying && Editor.MouseInRectTransform(TimelineGridSelect))
|
2022-01-29 02:26:34 +00:00
|
|
|
{
|
|
|
|
movingPlayback = true;
|
|
|
|
}
|
2022-07-08 21:58:58 +00:00
|
|
|
else if (Input.GetMouseButtonUp(1) || Conductor.instance.isPlaying)
|
2022-01-29 02:26:34 +00:00
|
|
|
{
|
|
|
|
movingPlayback = false;
|
|
|
|
}
|
|
|
|
if (movingPlayback)
|
2022-01-07 23:51:08 +00:00
|
|
|
{
|
|
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(TimelineContent, Input.mousePosition, Editor.instance.EditorCamera, out lastMousePos);
|
2022-06-06 16:54:57 +00:00
|
|
|
TimelineSlider.localPosition = new Vector3(Mathf.Max(Mathp.Round2Nearest(lastMousePos.x + 0.12f, Timeline.SnapInterval()), 0), TimelineSlider.transform.localPosition.y);
|
2022-01-07 23:51:08 +00:00
|
|
|
|
2022-01-15 18:46:50 +00:00
|
|
|
if (TimelineSlider.localPosition.x != lastBeatPos)
|
|
|
|
Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x);
|
|
|
|
|
|
|
|
lastBeatPos = TimelineSlider.localPosition.x;
|
2022-01-07 23:51:08 +00:00
|
|
|
}
|
2022-01-15 05:20:47 +00:00
|
|
|
|
2022-01-19 05:40:49 +00:00
|
|
|
if (Conductor.instance.isPlaying)
|
2023-02-05 03:05:36 +00:00
|
|
|
PlaybackFocus(true);
|
2022-01-19 05:40:49 +00:00
|
|
|
|
2022-01-15 05:20:47 +00:00
|
|
|
TimelineContent.transform.localPosition = new Vector3(Mathf.Clamp(TimelineContent.transform.localPosition.x, Mathf.NegativeInfinity, 0), TimelineContent.transform.localPosition.y);
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
CurrentTempo.text = $" = {Conductor.instance.songBpm}";
|
2022-01-29 21:59:20 +00:00
|
|
|
|
2022-06-30 01:58:21 +00:00
|
|
|
LayersRect.GetWorldCorners(LayerCorners);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float GetScaleModifier()
|
|
|
|
{
|
|
|
|
Camera cam = Editor.instance.EditorCamera;
|
2022-07-02 02:03:15 +00:00
|
|
|
return Mathf.Pow(cam.pixelWidth/1280f, 1f) * Mathf.Pow(cam.pixelHeight/720f, 0f);
|
2022-06-30 01:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Vector2 LayerCornersToDist()
|
|
|
|
{
|
|
|
|
Vector3[] v = LayerCorners;
|
|
|
|
return new Vector2(Mathf.Abs(v[1].x - v[2].x), Mathf.Abs(v[3].y - v[1].y));
|
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-14 22:46:14 +00:00
|
|
|
TimelineSongPosLine.transform.localPosition = new Vector3(Conductor.instance.songPositionInBeats, TimelineSongPosLine.transform.localPosition.y);
|
|
|
|
TimelineSongPosLine.transform.localScale = new Vector3(1f / TimelineContent.transform.localScale.x, TimelineSongPosLine.transform.localScale.y, 1);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#region PlayChecks
|
|
|
|
public void PlayCheck(bool fromStart)
|
|
|
|
{
|
|
|
|
if (fromStart)
|
|
|
|
{
|
2022-01-17 02:31:49 +00:00
|
|
|
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
|
|
|
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-17 02:31:49 +00:00
|
|
|
if (TimelineSongPosLine == null)
|
|
|
|
{
|
|
|
|
Play(false, TimelineSlider.transform.localPosition.x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Play(false, TimelineSongPosLine.transform.localPosition.x);
|
|
|
|
}
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
2022-01-17 02:31:49 +00:00
|
|
|
else if (!Conductor.instance.isPaused)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
|
|
|
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-14 00:35:41 +00:00
|
|
|
GameManager.instance.Play(time);
|
2022-01-15 05:20:47 +00:00
|
|
|
|
|
|
|
SetTimeButtonColors(false, true, true);
|
2022-01-06 00:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
{
|
|
|
|
// isPaused = true;
|
2022-01-14 00:35:41 +00:00
|
|
|
GameManager.instance.Pause();
|
2022-01-15 05:20:47 +00:00
|
|
|
|
|
|
|
SetTimeButtonColors(true, false, true);
|
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-14 00:35:41 +00:00
|
|
|
GameManager.instance.Stop(time);
|
2022-01-15 05:20:47 +00:00
|
|
|
|
|
|
|
SetTimeButtonColors(true, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetTimeButtonColors(bool playEnabled, bool pauseEnabled, bool stopEnabled)
|
|
|
|
{
|
|
|
|
if (playEnabled)
|
|
|
|
{
|
2023-01-13 22:18:11 +00:00
|
|
|
PlayBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-01-17 05:00:26 +00:00
|
|
|
PlayBTN.enabled = true;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
2022-01-17 05:00:26 +00:00
|
|
|
PlayBTN.enabled = false;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pauseEnabled)
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
PauseBTN.enabled = true;
|
2023-01-13 22:18:11 +00:00
|
|
|
PauseBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ PauseBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
2022-01-17 05:00:26 +00:00
|
|
|
PauseBTN.enabled = false;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stopEnabled)
|
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
StopBTN.enabled = true;
|
2023-01-13 22:18:11 +00:00
|
|
|
StopBTN.transform.GetChild(0).GetComponent<Image>().color = Color.white;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StopBTN.transform.GetChild(0).GetComponent<Image>().color = Color.gray;
|
2022-01-17 05:00:26 +00:00
|
|
|
StopBTN.enabled = false;
|
2022-01-15 05:20:47 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
2022-01-11 00:17:29 +00:00
|
|
|
|
|
|
|
public bool CheckIfMouseInTimeline()
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineEventGrid, Input.mousePosition, Editor.instance.EditorCamera));
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
2023-02-05 03:05:36 +00:00
|
|
|
|
2022-01-11 00:17:29 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Functions
|
|
|
|
|
2023-02-05 03:05:36 +00:00
|
|
|
public void PlaybackFocus(bool lerp)
|
|
|
|
{
|
|
|
|
var lerpSpd = (lerp) ? 12f : 10000000; // im lazy
|
|
|
|
|
|
|
|
var newPos = new Vector3((-Conductor.instance.songPositionInBeats * TimelineContent.localScale.x) + 200, TimelineContent.transform.localPosition.y);
|
|
|
|
TimelineContent.transform.localPosition =
|
|
|
|
Vector3.Lerp(TimelineContent.transform.localPosition, newPos, Time.deltaTime * lerpSpd);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void WaveformToggle()
|
|
|
|
{
|
|
|
|
if (Conductor.instance.musicSource.clip == null) return;
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
// waveform.gameObject.SetActive(!waveform.gameObject.activeInHierarchy);
|
|
|
|
waveform.gameObject.SetActive(false);
|
2023-02-05 03:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator DrawWaveformRealtime()
|
|
|
|
{
|
|
|
|
var clip = Conductor.instance.musicSource.clip;
|
|
|
|
|
|
|
|
if (!clip)
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
waveform.rectTransform.sizeDelta = new Vector2(Conductor.instance.SongLengthInBeats() + 0.15f, waveform.rectTransform.sizeDelta.y);
|
|
|
|
waveform.color = Color.white;
|
|
|
|
|
|
|
|
var num = 12000;
|
|
|
|
var num2 = 1f;
|
|
|
|
var num3 = clip.samples * clip.channels;
|
|
|
|
var array = new float[num3];
|
|
|
|
var wave = new float[num];
|
|
|
|
clip.GetData(array, 0);
|
|
|
|
int packsize = num3 / num;
|
|
|
|
Debug.Log($"drawing waveform. samples:, {clip.samples}, packsize: {packsize}");
|
|
|
|
float num5 = 0f;
|
|
|
|
int num6 = 0;
|
|
|
|
int num7 = 0;
|
|
|
|
for (int i = 0; i < num3; i++)
|
|
|
|
{
|
|
|
|
wave[num6] += Mathf.Abs(array[i]);
|
|
|
|
num7++;
|
|
|
|
if (num7 > packsize)
|
|
|
|
{
|
|
|
|
if (num5 < wave[num6])
|
|
|
|
{
|
|
|
|
num5 = wave[num6];
|
|
|
|
}
|
|
|
|
num6++;
|
|
|
|
num7 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
wave[j] /= num5 * num2;
|
|
|
|
if (wave[j] > 1f)
|
|
|
|
{
|
|
|
|
wave[j] = 1f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int height = 200;
|
|
|
|
Color col = Colors.Hex2RGB("727272");
|
|
|
|
col.a = 0.25f;
|
|
|
|
|
|
|
|
Texture2D tex = new Texture2D(wave.Length, height, TextureFormat.RGBA32, false);
|
|
|
|
|
|
|
|
FillColorAlpha(tex, new Color32(0, 0, 0, 0));
|
|
|
|
|
|
|
|
this.waveform.texture = tex;
|
|
|
|
int waveI = 0;
|
|
|
|
while (waveI < wave.Length)
|
|
|
|
{
|
|
|
|
int num8 = waveI;
|
|
|
|
while (num8 < waveI + 100 && waveI < wave.Length)
|
|
|
|
{
|
|
|
|
int num9 = 0;
|
|
|
|
while ((float)num9 <= wave[num8] * (float)height / 2f)
|
|
|
|
{
|
|
|
|
tex.SetPixel(num8, height / 2 + num9, col);
|
|
|
|
tex.SetPixel(num8, height / 2 - num9, col);
|
|
|
|
num9++;
|
|
|
|
}
|
|
|
|
num8++;
|
|
|
|
}
|
|
|
|
waveI += 100;
|
|
|
|
tex.Apply();
|
|
|
|
yield return null;
|
|
|
|
}
|
|
|
|
tex.Apply();
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Texture2D FillColorAlpha(Texture2D tex2D, Color32? fillColor = null)
|
|
|
|
{
|
|
|
|
if (fillColor == null)
|
|
|
|
{
|
|
|
|
fillColor = Color.clear;
|
|
|
|
}
|
|
|
|
Color32[] fillPixels = new Color32[tex2D.width * tex2D.height];
|
|
|
|
for (int i = 0; i < fillPixels.Length; i++)
|
|
|
|
{
|
|
|
|
fillPixels[i] = (Color32)fillColor;
|
|
|
|
}
|
|
|
|
tex2D.SetPixels32(fillPixels);
|
|
|
|
return tex2D;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public TimelineEventObj AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), RiqEntity entity = null, bool addEvent = false)
|
2022-01-11 00:17:29 +00:00
|
|
|
{
|
2022-08-21 03:54:09 +00:00
|
|
|
var game = EventCaller.instance.GetMinigame(eventName.Split(0));
|
|
|
|
var action = EventCaller.instance.GetGameAction(game, eventName.Split(1));
|
2022-01-11 00:17:29 +00:00
|
|
|
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
2022-01-13 03:59:54 +00:00
|
|
|
g.transform.localPosition = pos;
|
2022-08-21 03:54:09 +00:00
|
|
|
g.transform.GetChild(3).GetComponent<TMP_Text>().text = action.displayName;
|
2022-01-11 00:17:29 +00:00
|
|
|
|
|
|
|
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
2022-01-15 18:46:50 +00:00
|
|
|
|
|
|
|
if (eventName.Split(1) == "switchGame")
|
2023-06-10 19:17:06 +00:00
|
|
|
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(2));
|
|
|
|
else
|
|
|
|
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
2022-01-11 00:17:29 +00:00
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
Minigames.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
2022-01-11 00:17:29 +00:00
|
|
|
|
|
|
|
if (gameAction != null)
|
|
|
|
{
|
2022-01-17 19:23:18 +00:00
|
|
|
if (gameAction.resizable == false)
|
|
|
|
{
|
|
|
|
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
|
|
|
float length = gameAction.defaultLength;
|
|
|
|
eventObj.length = length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventObj.resizable = true;
|
2022-01-24 02:15:23 +00:00
|
|
|
if (entity != null && gameAction.defaultLength != entity.length && dragNDrop == false)
|
2022-01-17 19:23:18 +00:00
|
|
|
{
|
2022-01-22 10:44:19 +00:00
|
|
|
g.GetComponent<RectTransform>().sizeDelta = new Vector2(entity.length, LayerHeight());
|
2022-01-17 19:23:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
|
|
|
}
|
|
|
|
}
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dragNDrop)
|
|
|
|
{
|
2022-02-03 08:25:27 +00:00
|
|
|
var mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
2022-01-14 00:35:41 +00:00
|
|
|
g.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
|
|
|
|
|
|
|
|
Selections.instance.ClickSelect(eventObj);
|
2022-01-17 23:54:25 +00:00
|
|
|
eventObj.moving = true;
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
entity["track"] = eventObj.GetTrack();
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
2022-01-12 03:29:27 +00:00
|
|
|
|
2022-01-22 10:44:19 +00:00
|
|
|
if (addEvent)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
RiqEntity tempEntity = entity;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2022-01-22 10:44:19 +00:00
|
|
|
if (entity == null)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
RiqEntity en = GameManager.instance.Beatmap.AddNewEntity(eventName, g.transform.localPosition.x, gameAction.defaultLength);
|
2022-01-22 10:44:19 +00:00
|
|
|
GameManager.instance.SortEventsList();
|
2022-02-04 03:25:18 +00:00
|
|
|
|
|
|
|
tempEntity = en;
|
|
|
|
|
2022-08-21 03:54:09 +00:00
|
|
|
// default param values
|
|
|
|
var ep = action.parameters;
|
2022-02-04 03:25:18 +00:00
|
|
|
|
2022-07-04 17:09:23 +00:00
|
|
|
if (ep != null)
|
2022-02-04 03:25:18 +00:00
|
|
|
{
|
2022-07-04 17:09:23 +00:00
|
|
|
for (int i = 0; i < ep.Count; i++)
|
2022-02-04 03:25:18 +00:00
|
|
|
{
|
2022-07-04 17:09:23 +00:00
|
|
|
object returnVal = ep[i].parameter;
|
|
|
|
|
|
|
|
var propertyType = returnVal.GetType();
|
|
|
|
if (propertyType == typeof(EntityTypes.Integer))
|
|
|
|
{
|
|
|
|
returnVal = ((EntityTypes.Integer)ep[i].parameter).val;
|
|
|
|
}
|
|
|
|
else if (propertyType == typeof(EntityTypes.Float))
|
|
|
|
{
|
|
|
|
returnVal = ((EntityTypes.Float)ep[i].parameter).val;
|
|
|
|
}
|
2022-08-21 23:46:45 +00:00
|
|
|
else if (propertyType.IsEnum)
|
|
|
|
{
|
|
|
|
returnVal = (int) ep[i].parameter;
|
|
|
|
}
|
2022-07-04 17:09:23 +00:00
|
|
|
|
2022-08-21 23:46:45 +00:00
|
|
|
//tempEntity[ep[i].propertyName] = returnVal;
|
|
|
|
tempEntity.CreateProperty(ep[i].propertyName, returnVal);
|
2022-02-04 03:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-04 17:09:23 +00:00
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
GameManager.instance.Beatmap.Entities.Add(tempEntity);
|
2022-07-04 17:09:23 +00:00
|
|
|
GameManager.instance.SortEventsList();
|
|
|
|
}
|
2023-06-10 19:17:06 +00:00
|
|
|
|
|
|
|
eventObj.entity = tempEntity;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventObj.entity = entity;
|
2022-01-22 10:44:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 03:59:54 +00:00
|
|
|
eventObjs.Add(eventObj);
|
2023-06-10 19:17:06 +00:00
|
|
|
eventObj.eventObjID = eventObj.entity.uid;
|
2022-01-22 10:44:19 +00:00
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
g.SetActive(true);
|
2022-01-22 10:44:19 +00:00
|
|
|
|
|
|
|
return eventObj;
|
2022-01-11 00:17:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 16:50:23 +00:00
|
|
|
private List<TimelineEventObj> duplicatedEventObjs = new List<TimelineEventObj>();
|
|
|
|
public TimelineEventObj CopyEventObject(TimelineEventObj e)
|
2022-07-04 16:57:19 +00:00
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
RiqEntity clone = e.entity.DeepCopy();
|
|
|
|
TimelineEventObj dup = AddEventObject(clone.datamodel, false, new Vector3((float)clone.beat, -clone["track"] * Timeline.instance.LayerHeight()), clone, true);
|
2022-07-08 16:50:23 +00:00
|
|
|
duplicatedEventObjs.Add(dup);
|
2022-07-04 16:57:19 +00:00
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2022-07-08 16:50:23 +00:00
|
|
|
public void FinalizeDuplicateEventStack()
|
|
|
|
{
|
|
|
|
CommandManager.instance.Execute(new Commands.Duplicate(duplicatedEventObjs));
|
|
|
|
duplicatedEventObjs = new List<TimelineEventObj>();
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
public void DestroyEventObject(RiqEntity entity)
|
2022-01-12 03:29:27 +00:00
|
|
|
{
|
2022-02-04 03:25:18 +00:00
|
|
|
if (EventParameterManager.instance.entity == entity)
|
|
|
|
EventParameterManager.instance.Disable();
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
// eventObjs.Remove(entity.eventObj);
|
|
|
|
foreach (TimelineEventObj e in eventObjs)
|
|
|
|
{
|
|
|
|
if (e.entity == entity)
|
|
|
|
{
|
|
|
|
Destroy(e.gameObject);
|
|
|
|
eventObjs.Remove(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GameManager.instance.Beatmap.Entities.Remove(entity);
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
GameManager.instance.SortEventsList();
|
2022-01-12 03:29:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 03:59:54 +00:00
|
|
|
public bool IsMouseAboveEvents()
|
|
|
|
{
|
|
|
|
return Timeline.instance.eventObjs.FindAll(c => c.mouseHovering == true).Count > 0;
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:54:25 +00:00
|
|
|
public bool InteractingWithEvents()
|
2022-01-13 03:59:54 +00:00
|
|
|
{
|
2022-01-17 23:54:25 +00:00
|
|
|
return eventObjs.FindAll(c => c.moving == true).Count > 0 || eventObjs.FindAll(c => c.resizing == true).Count > 0;
|
2022-01-13 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 22:46:14 +00:00
|
|
|
public float SnapToLayer(float y)
|
|
|
|
{
|
|
|
|
float size = LayerHeight();
|
2022-07-28 05:17:02 +00:00
|
|
|
return Mathf.Clamp(Mathp.Round2Nearest(y, size), -size * 4f, 0f);
|
2022-01-14 22:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public float LayerHeight()
|
|
|
|
{
|
2022-07-28 05:17:02 +00:00
|
|
|
return LayersRect.rect.height / 5f;
|
2022-01-14 22:46:14 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 16:26:08 +00:00
|
|
|
const float SpeedSnap = 0.25f;
|
2022-02-03 07:28:14 +00:00
|
|
|
public void SetPlaybackSpeed(float speed)
|
|
|
|
{
|
2023-02-21 16:26:08 +00:00
|
|
|
float spd = Mathp.Round2Nearest(speed, SpeedSnap);
|
2022-02-03 07:28:14 +00:00
|
|
|
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: {spd}x";
|
2023-02-21 16:26:08 +00:00
|
|
|
Conductor.instance.SetTimelinePitch(spd);
|
2022-02-03 07:28:14 +00:00
|
|
|
PlaybackSpeed.value = spd;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetPlaybackSpeed()
|
|
|
|
{
|
|
|
|
if (Input.GetMouseButton(1))
|
|
|
|
{
|
2022-02-03 22:20:26 +00:00
|
|
|
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: 1x";
|
2022-02-03 07:28:14 +00:00
|
|
|
PlaybackSpeed.value = 1f;
|
2023-02-21 16:26:08 +00:00
|
|
|
Conductor.instance.SetTimelinePitch(PlaybackSpeed.value);
|
2022-02-03 07:28:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
public void UpdateOffsetText()
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
FirstBeatOffset.text = (GameManager.instance.Beatmap.data.offset * 1000f).ToString("G");
|
2022-09-18 20:48:14 +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);
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
GameManager.instance.Beatmap.data.offset = newOffset;
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
UpdateOffsetText();
|
2023-06-10 19:17:06 +00:00
|
|
|
FitToSong();
|
2022-09-18 20:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateStartingBPMText()
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
StartingTempoSpecialAll.text = GameManager.instance.Beatmap.TempoChanges[0]["tempo"].ToString("G");
|
2022-09-18 20:48:14 +00:00
|
|
|
StartingTempoSpecialTempo.text = StartingTempoSpecialAll.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateStartingBPMFromText(bool all)
|
|
|
|
{
|
|
|
|
string text = all ? StartingTempoSpecialAll.text : StartingTempoSpecialTempo.text;
|
|
|
|
// Failsafe against empty string.
|
|
|
|
if (String.IsNullOrEmpty(text))
|
|
|
|
text = "120";
|
|
|
|
|
|
|
|
var newBPM = Convert.ToDouble(text);
|
|
|
|
|
|
|
|
// Failsafe against negative BPM.
|
|
|
|
if (newBPM < 1f)
|
|
|
|
{
|
|
|
|
text = "1";
|
|
|
|
newBPM = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit decimal places to 4.
|
|
|
|
newBPM = System.Math.Round(newBPM, 4);
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
RiqEntity tempoChange = GameManager.instance.Beatmap.TempoChanges[0];
|
|
|
|
tempoChange["tempo"] = (float) newBPM;
|
|
|
|
GameManager.instance.Beatmap.TempoChanges[0] = tempoChange;
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
// In case the newBPM ended up differing from the inputted string.
|
|
|
|
UpdateStartingBPMText();
|
|
|
|
|
|
|
|
Timeline.instance.FitToSong();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateStartingVolText()
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
StartingVolumeSpecialVolume.text = (GameManager.instance.Beatmap.VolumeChanges[0]["volume"]).ToString("G");
|
2022-09-18 20:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateStartingVolFromText()
|
|
|
|
{
|
|
|
|
// Failsafe against empty string.
|
|
|
|
if (String.IsNullOrEmpty(StartingVolumeSpecialVolume.text))
|
|
|
|
StartingVolumeSpecialVolume.text = "100";
|
|
|
|
|
|
|
|
var newVol = Convert.ToInt32(StartingVolumeSpecialVolume.text);
|
|
|
|
newVol = Mathf.Clamp(newVol, 0, 100);
|
|
|
|
|
2023-06-10 19:17:06 +00:00
|
|
|
RiqEntity volChange = GameManager.instance.Beatmap.VolumeChanges[0];
|
|
|
|
volChange["volume"] = newVol;
|
|
|
|
GameManager.instance.Beatmap.VolumeChanges[0] = volChange;
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
UpdateStartingVolText();
|
|
|
|
}
|
|
|
|
|
2022-01-12 03:29:27 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Commands
|
|
|
|
|
|
|
|
public void Move()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Undo()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|