From c60a104f2dadde44e9246030ee152a514921f426 Mon Sep 17 00:00:00 2001 From: ThePurpleAnon <100617766+ThePurpleAnon@users.noreply.github.com> Date: Sun, 26 May 2024 15:06:20 -0500 Subject: [PATCH] Metronome Subdivision and More Snapping Options BUT for real this time:tm: (#957) * blargh * oopsie lol --- Assets/Scenes/Editor.unity | 118 +++++++++--------- Assets/Scripts/Conductor.cs | 32 +++-- .../LevelEditor/SnapDialog/SnapDialog.cs | 20 ++- .../Scripts/LevelEditor/Timeline/Timeline.cs | 70 +++++++++-- Assets/Scripts/UI/UIButton.cs | 54 ++++++++ Assets/Scripts/UI/UIButton.cs.meta | 11 ++ 6 files changed, 222 insertions(+), 83 deletions(-) create mode 100644 Assets/Scripts/UI/UIButton.cs create mode 100644 Assets/Scripts/UI/UIButton.cs.meta diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index 4409bfd93..51e95a13a 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -4452,8 +4452,8 @@ GameObject: - component: {fileID: 129013733} - component: {fileID: 129013736} - component: {fileID: 129013735} - - component: {fileID: 129013734} - component: {fileID: 129013737} + - component: {fileID: 129013738} m_Layer: 5 m_Name: MetronomeBTN m_TagString: Untagged @@ -4484,62 +4484,6 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 32, y: 32} m_Pivot: {x: 1, y: 0.5} ---- !u!114 &129013734 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 129013732} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Navigation: - m_Mode: 0 - m_WrapAround: 0 - m_SelectOnUp: {fileID: 0} - m_SelectOnDown: {fileID: 0} - m_SelectOnLeft: {fileID: 0} - m_SelectOnRight: {fileID: 0} - m_Transition: 1 - m_Colors: - m_NormalColor: {r: 1, g: 1, b: 1, a: 1} - m_HighlightedColor: {r: 0.7924528, g: 0.7924528, b: 0.7924528, a: 1} - m_PressedColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} - m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} - m_ColorMultiplier: 1 - m_FadeDuration: 0.05 - m_SpriteState: - m_HighlightedSprite: {fileID: 0} - m_PressedSprite: {fileID: 0} - m_SelectedSprite: {fileID: 0} - m_DisabledSprite: {fileID: 0} - m_AnimationTriggers: - m_NormalTrigger: Normal - m_HighlightedTrigger: Highlighted - m_PressedTrigger: Pressed - m_SelectedTrigger: Selected - m_DisabledTrigger: Disabled - m_Interactable: 1 - m_TargetGraphic: {fileID: 129013735} - m_OnClick: - m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 1861169747} - m_TargetAssemblyTypeName: HeavenStudio.Editor.Track.Timeline, Assembly-CSharp - m_MethodName: MetronomeToggle - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 --- !u!114 &129013735 MonoBehaviour: m_ObjectHideFlags: 0 @@ -4591,6 +4535,56 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: TooltipText: Metronome [M] +--- !u!114 &129013738 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 129013732} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b6238d133d620234fbd17867a344bbe4, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 0 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.7921569, g: 0.7921569, b: 0.7921569, a: 1} + m_PressedColor: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.05 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 129013735} + m_OnClick: + m_PersistentCalls: + m_Calls: [] + onRightClick: + m_PersistentCalls: + m_Calls: [] + isHovering: 0 + isHolding: 0 + wasHolding: 0 --- !u!1 &143407410 GameObject: m_ObjectHideFlags: 0 @@ -25979,7 +25973,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1589389271} m_Direction: 2 m_Value: 1 - m_Size: 0.9992818 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -31856,7 +31850,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0, y: 274.53052} + m_AnchoredPosition: {x: 0, y: 113.102036} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 1} --- !u!222 &1154875945 @@ -42004,8 +41998,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1220118245} m_HandleRect: {fileID: 1220118244} m_Direction: 2 - m_Value: 1 - m_Size: 1 + m_Value: 1.0000002 + m_Size: 0.5712372 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -47289,7 +47283,7 @@ MonoBehaviour: PlayBTN: {fileID: 1345846031} PauseBTN: {fileID: 9435782} StopBTN: {fileID: 1783491359} - MetronomeBTN: {fileID: 129013734} + MetronomeBTN: {fileID: 129013738} AutoplayBTN: {fileID: 121871281} SelectionsBTN: {fileID: 270008766} TempoChangeBTN: {fileID: 456434811} diff --git a/Assets/Scripts/Conductor.cs b/Assets/Scripts/Conductor.cs index 4f2300f9f..fe1ce5db0 100644 --- a/Assets/Scripts/Conductor.cs +++ b/Assets/Scripts/Conductor.cs @@ -81,7 +81,8 @@ namespace HeavenStudio public bool isPaused; // Metronome tick sound enabled - public bool metronome = false; + public int metronome = 0; + public bool metronomeActive = false; Util.MultiSound metronomeSound; private int _metronomeTally = 0; @@ -442,13 +443,30 @@ namespace HeavenStudio { if (songPositionInBeatsAsDouble >= Math.Ceiling(startBeat) + _metronomeTally) { - // if (metronome) metronomeSound = Util.SoundByte.PlayOneShot("metronome", Math.Ceiling(startBeat) + _metronomeTally); - if (metronome) + if (metronomeActive) { - metronomeSound = Util.MultiSound.Play(new List { - new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally), - new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally + 0.5, 1.5f, 0.5f) - }, false, true); + switch (metronome) + { + case 0: + metronomeSound = Util.MultiSound.Play(new List { + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally), + }, false, true); + break; + case 1: + metronomeSound = Util.MultiSound.Play(new List { + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally), + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally + 0.5, 1.5f, 0.5f) + }, false, true); + break; + case 2: + metronomeSound = Util.MultiSound.Play(new List { + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally), + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally + 0.25, 2f, 0.3f), + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally + 0.5, 1.5f, 0.5f), + new Util.MultiSound.Sound("metronome", Math.Ceiling(startBeat) + _metronomeTally + 0.75, 2f, 0.3f) + }, false, true); + break; + } } _metronomeTally++; } diff --git a/Assets/Scripts/LevelEditor/SnapDialog/SnapDialog.cs b/Assets/Scripts/LevelEditor/SnapDialog/SnapDialog.cs index 9b55b6c3e..202518898 100644 --- a/Assets/Scripts/LevelEditor/SnapDialog/SnapDialog.cs +++ b/Assets/Scripts/LevelEditor/SnapDialog/SnapDialog.cs @@ -14,7 +14,7 @@ namespace HeavenStudio.Editor private Timeline timeline; - private static float[] CommonDenominators = { 1, 2, 3, 4, 6, 8, 12, 16 }; + private static float[] CommonDenominators = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, -1 }; private int currentCommon = 3; private void Start() { @@ -45,12 +45,26 @@ namespace HeavenStudio.Editor currentCommon = CommonDenominators.Length - 1; } - timeline.SetSnap(1f / CommonDenominators[currentCommon]); + if (CommonDenominators[currentCommon] < 0) + { + timeline.SetSnap(1f / 65536f); + } + else + { + timeline.SetSnap(1f / CommonDenominators[currentCommon]); + } } private void Update() { - snapText.text = $"1/{CommonDenominators[currentCommon]}"; + if (CommonDenominators[currentCommon] < 0) + { + snapText.text = "Free"; + } + else + { + snapText.text = $"1/{CommonDenominators[currentCommon]}"; + } } } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index 80f051818..4c13bbad3 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -172,7 +172,7 @@ namespace HeavenStudio.Editor.Track public Button PlayBTN; public Button PauseBTN; public Button StopBTN; - public Button MetronomeBTN; + public UIButton MetronomeBTN; public Button AutoplayBTN; public Button SelectionsBTN; public Button TempoChangeBTN; @@ -268,10 +268,18 @@ namespace HeavenStudio.Editor.Track { timelineState.SetState(CurrentTimelineState.State.ChartSection); }); + MetronomeBTN.onClick.AddListener(delegate + { + MetronomeToggle(); + }); + MetronomeBTN.onRightClick.AddListener(delegate + { + MetronomeCycle(); + }); SetTimeButtonColors(true, false, false); MetronomeBTN.transform.GetChild(0).GetComponent().color = Color.gray; - MetronomeBTN.transform.GetChild(1).GetComponent().color = Color.gray; + MetronomeBTN.transform.GetChild(1).GetComponent().color = "009FC6".Hex2RGB(); MetronomeBTN.transform.GetChild(2).GetComponent().color = Color.gray; timelineState.SetState(CurrentTimelineState.State.Selection); @@ -342,19 +350,52 @@ namespace HeavenStudio.Editor.Track public void MetronomeToggle() { - if (!Conductor.instance.metronome) + Conductor.instance.metronomeActive = !Conductor.instance.metronomeActive; + if (Conductor.instance.metronomeActive) { - MetronomeBTN.transform.GetChild(0).GetComponent().color = "009FC6".Hex2RGB(); - MetronomeBTN.transform.GetChild(1).GetComponent().color = "009FC6".Hex2RGB(); - MetronomeBTN.transform.GetChild(2).GetComponent().color = "009FC6".Hex2RGB(); - Conductor.instance.metronome = true; + MetronomeBTN.transform.GetChild(0).GetComponent().color = MetronomeBTN.transform.GetChild(1).GetComponent().color; + MetronomeBTN.transform.GetChild(2).GetComponent().color = MetronomeBTN.transform.GetChild(1).GetComponent().color; } else { MetronomeBTN.transform.GetChild(0).GetComponent().color = Color.gray; - MetronomeBTN.transform.GetChild(1).GetComponent().color = Color.gray; MetronomeBTN.transform.GetChild(2).GetComponent().color = Color.gray; - Conductor.instance.metronome = false; + } + } + + public void MetronomeCycle() + { + Conductor.instance.metronome++; + Conductor.instance.metronome %= 3; + + switch (Conductor.instance.metronome) + { + case 0: + MetronomeBTN.transform.GetChild(1).GetComponent().color = "009FC6".Hex2RGB(); + if (Conductor.instance.metronomeActive) + { + MetronomeBTN.transform.GetChild(0).GetComponent().color = "009FC6".Hex2RGB(); + MetronomeBTN.transform.GetChild(2).GetComponent().color = "009FC6".Hex2RGB(); + } + break; + + case 1: + MetronomeBTN.transform.GetChild(1).GetComponent().color = "DB7B04".Hex2RGB(); + if (Conductor.instance.metronomeActive) + { + MetronomeBTN.transform.GetChild(0).GetComponent().color = "DB7B04".Hex2RGB(); + MetronomeBTN.transform.GetChild(2).GetComponent().color = "DB7B04".Hex2RGB(); + } + break; + + case 2: + MetronomeBTN.transform.GetChild(1).GetComponent().color = "3AC211".Hex2RGB(); + if (Conductor.instance.metronomeActive) + { + MetronomeBTN.transform.GetChild(0).GetComponent().color = "3AC211".Hex2RGB(); + MetronomeBTN.transform.GetChild(2).GetComponent().color = "3AC211".Hex2RGB(); + } + break; } } @@ -404,7 +445,7 @@ namespace HeavenStudio.Editor.Track { RectTransform rectTransform = MetronomeBTN.transform.GetChild(1).GetComponent(); float rot = 0f; - if (cond.metronome) + if (cond.metronomeActive) { int startBeat = (int)Math.Floor(cond.songPositionInBeats - 0.5); float nm = cond.GetLoopPositionFromBeat(0.5f, 1f, ignoreSwing: false); @@ -448,7 +489,14 @@ namespace HeavenStudio.Editor.Track if (Input.GetKeyDown(KeyCode.M)) { - MetronomeToggle(); + if (Input.GetKey(KeyCode.LeftShift)) + { + MetronomeCycle(); + } + else + { + MetronomeToggle(); + } } if (Input.GetKeyDown(KeyCode.Alpha1)) diff --git a/Assets/Scripts/UI/UIButton.cs b/Assets/Scripts/UI/UIButton.cs new file mode 100644 index 000000000..a4b1e7890 --- /dev/null +++ b/Assets/Scripts/UI/UIButton.cs @@ -0,0 +1,54 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; +using UnityEngine.UI.Extensions; + +/// +/// This is a custom button class that inherits from the default button. This allows us to have seperate events for left and right click, utilising all of the handy features of Button. +/// + +public class UIButton : Button, IPointerEnterHandler, IPointerExitHandler +{ + public UnityEngine.Events.UnityEvent onRightClick = new UnityEngine.Events.UnityEvent(); + public override void OnPointerClick(PointerEventData eventData) + { + if (eventData.button == PointerEventData.InputButton.Left) + { + // Invoke the left click event + base.OnPointerClick(eventData); + } + else if (eventData.button == PointerEventData.InputButton.Right) + { + // Invoke the right click event + onRightClick.Invoke(); + } + } + + public bool isHovering = false; + public bool isHolding = false; + public bool wasHolding = false; + + public override void OnPointerEnter(PointerEventData eventData) + { + isHovering = true; + base.OnPointerEnter(eventData); + } + + public override void OnPointerExit(PointerEventData eventData) + { + isHovering = false; + base.OnPointerExit(eventData); + } + + public void Update() + { + if (Input.GetMouseButton(1) && isHovering) isHolding = true; + if (!Input.GetMouseButton(1)) isHolding = false; + + if (isHolding) DoStateTransition(Button.SelectionState.Pressed, false); + if (isHolding != wasHolding) DoStateTransition(currentSelectionState, false); + + wasHolding = isHolding; + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/UIButton.cs.meta b/Assets/Scripts/UI/UIButton.cs.meta new file mode 100644 index 000000000..008c66e2f --- /dev/null +++ b/Assets/Scripts/UI/UIButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b6238d133d620234fbd17867a344bbe4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: