Skip to content

Commit

Permalink
Compose: Add QOL keybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
0thElement committed Jan 26, 2024
1 parent 4a10ec6 commit b37d9d2
Show file tree
Hide file tree
Showing 12 changed files with 611 additions and 46 deletions.
502 changes: 465 additions & 37 deletions Assets/Scenes/Compose.unity

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion Assets/Scripts/Compose/Components/Fields/TimingGroupField.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Security.Cryptography.X509Certificates;
using ArcCreate.Compose.Popups;
using ArcCreate.Gameplay.Chart;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UIElements;

namespace ArcCreate.Compose.Components
{
Expand All @@ -17,6 +19,12 @@ public class TimingGroupField : MonoBehaviour, IPointerDownHandler

public TimingGroup Value => value;

public void Open(string title)
{
Vector2 position = Input.mousePosition;
OpenWindow(position, title);
}

/// <summary>
/// Set the value without invoking <see cref="OnValueChanged"/> event.
/// </summary>
Expand All @@ -39,10 +47,15 @@ public void SetValue(TimingGroup tg)
}

public void OnPointerDown(PointerEventData eventData)
{
OpenWindow(eventData.position, string.Empty);
}

private void OpenWindow(Vector2 position, string title)
{
if (Services.Gameplay?.IsLoaded ?? false)
{
window = Services.Popups.OpenTimingGroupPicker(eventData.position, value.GroupNumber, this);
window = Services.Popups.OpenTimingGroupPicker(position, value.GroupNumber, title, this);
window.OnEndEdit = OnWindow;
}
}
Expand Down
28 changes: 28 additions & 0 deletions Assets/Scripts/Compose/EventsEditor/Group/GroupTable.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using ArcCreate.Compose.Components;
using ArcCreate.Compose.Navigation;
using ArcCreate.Gameplay;
using ArcCreate.Gameplay.Chart;
using ArcCreate.Gameplay.Data;
using UnityEngine;
using UnityEngine.UI;

namespace ArcCreate.Compose.EventsEditor
{
[EditorScope("Groups")]
public class GroupTable : Table<TimingGroup>
{
[SerializeField] private GameplayData gameplayData;
[SerializeField] private Button addButton;
[SerializeField] private Button removeButton;
[SerializeField] private Button selectButton;
[SerializeField] private TimingGroupField editingTimingGroupField;

public override TimingGroup Selected
Expand All @@ -23,9 +27,17 @@ public override TimingGroup Selected
base.Selected = value;
removeButton.interactable = Selected?.GroupProperties.Editable ?? false
&& Selected?.GroupNumber > 0;
selectButton.interactable = Selected?.GroupProperties.Editable ?? false;
}
}

[EditorAction("ChangeGroup", false, "<c-g>")]
[KeybindHint(Exclude = true)]
public void OpenPicker()
{
editingTimingGroupField.Open(I18n.S("Compose.Dialog.GroupPicker.SelectEditingGroup"));
}

public void UpdateEditingGroupField()
{
editingTimingGroupField.SetValueWithoutNotify(Selected);
Expand All @@ -43,6 +55,7 @@ protected override void Awake()
Values.EditingTimingGroup.OnValueChange += OnEdittingTimingGroup;
addButton.onClick.AddListener(OnAddButton);
removeButton.onClick.AddListener(OnRemoveButton);
selectButton.onClick.AddListener(OnSelectButton);
editingTimingGroupField.OnValueChanged += OnEditingTimingGroupField;
}

Expand All @@ -53,6 +66,7 @@ protected override void OnDestroy()
Values.EditingTimingGroup.OnValueChange -= OnEdittingTimingGroup;
addButton.onClick.RemoveListener(OnAddButton);
removeButton.onClick.RemoveListener(OnRemoveButton);
selectButton.onClick.RemoveListener(OnSelectButton);
editingTimingGroupField.OnValueChanged -= OnEditingTimingGroupField;
}

Expand Down Expand Up @@ -131,6 +145,20 @@ private void OnRemoveConfirm()
Values.OnEditAction?.Invoke();
}

private void OnSelectButton()
{
if (Selected == null)
{
return;
}

Services.Selection.SetSelection(
Selected.GetEventType<Tap>().Cast<Note>()
.Concat(Selected.GetEventType<Hold>().Cast<Note>())
.Concat(Selected.GetEventType<Arc>().Cast<Note>())
.Concat(Selected.GetEventType<ArcTap>().Cast<Note>()));
}

private void OnChart()
{
UpdateTable(Services.Gameplay.Chart.TimingGroups);
Expand Down
15 changes: 15 additions & 0 deletions Assets/Scripts/Compose/Grid/GridService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using ArcCreate.Compose.Navigation;
using ArcCreate.Utility.Parser;
using Cysharp.Threading.Tasks;
Expand Down Expand Up @@ -119,6 +120,20 @@ public async UniTask SetSlot(EditorAction action)
IsGridEnabled = slotSwitched || !IsGridEnabled;
}

[EditorAction("DecreaseDensity", false, "-")]
[KeybindHint(Priority = KeybindPriorities.Grid - 1)]
public void DecreaseGridDensity()
{
Values.BeatlineDensity.Value = Mathf.Max(Values.BeatlineDensity.Value - 1, 1);
}

[EditorAction("IncreaseDensity", false, "=")]
[KeybindHint(Priority = KeybindPriorities.Grid - 2)]
public void IncreaseGridDensity()
{
Values.BeatlineDensity.Value = Values.BeatlineDensity.Value + 1;
}

public (float fromX, float fromY, float toX, float toY) GetVerticalGridBound()
{
return verticalGrid.GetBounds();
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Compose/Popups/IPopupsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public interface IPopupsService
/// </summary>
/// <param name="screenPosition">The screen position to open the picker at.</param>
/// <param name="defaultTimingGroup">The timing group to initialize the picker with.</param>
/// <param name="title">The title of the display.</param>
/// <param name="caller">The object that opened this window.</param>
/// <returns>An arc type picker instance.</returns>
TimingGroupPicker OpenTimingGroupPicker(Vector2 screenPosition, int? defaultTimingGroup, object caller);
TimingGroupPicker OpenTimingGroupPicker(Vector2 screenPosition, int? defaultTimingGroup, string title, object caller);

/// <summary>
/// Open a text dialog.
Expand Down
28 changes: 27 additions & 1 deletion Assets/Scripts/Compose/Popups/Picker/TimingGroupPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class TimingGroupPicker : Table<TimingGroup>
[SerializeField] private RectTransform canvasRect;
[SerializeField] private float minDistanceFromBorder;
[SerializeField] private TMP_InputField numberField;
[SerializeField] private TMP_Text title;
[SerializeField] private GameObject titleFrame;
private RectTransform rect;

public Action<TimingGroup> OnValueChanged { get; set; }
Expand All @@ -27,7 +29,9 @@ public class TimingGroupPicker : Table<TimingGroup>

public object Owner { get; private set; }

public void OpenAt(Vector2 screenPosition, int? defaultTg, object caller)
public bool IsCursorHovering => RectTransformUtility.RectangleContainsScreenPoint(rect, Input.mousePosition, null);

public void OpenAt(Vector2 screenPosition, int? defaultTg, string title, object caller)
{
window.SetActive(true);
Owner = caller;
Expand All @@ -36,6 +40,9 @@ public void OpenAt(Vector2 screenPosition, int? defaultTg, object caller)

RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPosition, null, out Vector2 position);

titleFrame.SetActive(!string.IsNullOrEmpty(title));
this.title.text = title;

float canvasWidth = canvasRect.rect.width;
float canvasHeight = canvasRect.rect.height;
float rectWidth = rect.rect.width;
Expand Down Expand Up @@ -92,6 +99,8 @@ protected override void Awake()
base.Awake();
numberField.onValueChanged.AddListener(OnNumberFieldChange);
numberField.onSubmit.AddListener(OnNumberFieldSubmit);
numberField.onDeselect.AddListener(OnNumberFieldDeselect);
numberField.onEndEdit.AddListener(OnNumberFieldEndEdit);
rect = window.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
Expand All @@ -103,9 +112,26 @@ protected override void OnDestroy()
base.OnDestroy();
numberField.onValueChanged.RemoveListener(OnNumberFieldChange);
numberField.onSubmit.RemoveListener(OnNumberFieldSubmit);
numberField.onDeselect.RemoveListener(OnNumberFieldDeselect);
numberField.onEndEdit.RemoveListener(OnNumberFieldEndEdit);
closeButton.onClick.RemoveListener(CloseWindow);
}

private void OnNumberFieldDeselect(string val)
{
if (IsCursorHovering)
{
return;
}

OnNumberFieldSubmit(val);
}

private void OnNumberFieldEndEdit(string arg0)
{
CloseWindow();
}

private void OnNumberFieldChange(string val)
{
BuildTable(val);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Compose/Popups/PopupsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public ColorPickerWindow OpenColorPicker(Vector2 screenPosition, Color defaultCo
return colorPickerWindow;
}

public TimingGroupPicker OpenTimingGroupPicker(Vector2 screenPosition, int? defaultTg, object caller)
public TimingGroupPicker OpenTimingGroupPicker(Vector2 screenPosition, int? defaultTg, string title, object caller)
{
timingGroupPickerWindow.OpenAt(screenPosition, defaultTg, caller);
timingGroupPickerWindow.OpenAt(screenPosition, defaultTg, title, caller);
return timingGroupPickerWindow;
}

Expand Down
16 changes: 16 additions & 0 deletions Assets/Scripts/Compose/Project/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ public void SaveProject()
SerializeProject(CurrentProject);
}

[EditorAction("Reload", false, "<c-s-r>")]
[KeybindHint(Exclude = true)]
[RequireGameplayLoaded]
public void ReloadChart()
{
if (CurrentProject == null)
{
return;
}

int currentTiming = Services.Gameplay.Audio.AudioTiming;
SaveProject();
LoadChart(CurrentChart);
Services.Gameplay.Audio.AudioTiming = currentTiming;
}

public void OpenProject(string path)
{
ProjectSettings project = DeserializeProject(path);
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/Compose/Selection/InspectorMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using ArcCreate.Compose.Components;
using ArcCreate.Compose.History;
using ArcCreate.Compose.Navigation;
using ArcCreate.Gameplay;
using ArcCreate.Gameplay.Chart;
using ArcCreate.Gameplay.Data;
Expand All @@ -13,6 +14,7 @@

namespace ArcCreate.Compose.Selection
{
[EditorScope("Inspector")]
public class InspectorMenu : MonoBehaviour
{
private const string Mixed = "-";
Expand Down Expand Up @@ -55,6 +57,14 @@ public void ApplySelection(HashSet<Note> selected)
Rebuild();
}

[EditorAction("AssignToGroup", false, "<c-s-g>")]
[KeybindHint(Exclude = true)]
[SelectionService.RequireSelection]
public void AssignSelectedToGroup()
{
groupField.Open(I18n.S("Compose.Dialog.GroupPicker.AssignNotesToGroup"));
}

private void Rebuild()
{
bool includeTap = false;
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Compose/Selection/SelectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using ArcCreate.Compose.Navigation;
using ArcCreate.Compose.Popups;
using ArcCreate.Compose.Timeline;
using ArcCreate.Gameplay.Data;
using Cysharp.Threading.Tasks;
Expand All @@ -23,6 +24,7 @@ public class SelectionService : MonoBehaviour, ISelectionService
[SerializeField] private LayerMask gameplayLayer;
[SerializeField] private GameObject inspectorWindow;
[SerializeField] private InspectorMenu inspectorMenu;
[SerializeField] private TimingGroupPicker timingGroupPicker;
[SerializeField] private MarkerRange rangeSelectPreview;

private readonly HashSet<Note> selectedNotes = new HashSet<Note>();
Expand Down Expand Up @@ -53,6 +55,7 @@ public void SelectSingle()
if (EventSystem.current.currentSelectedGameObject != null
|| !Services.Cursor.IsCursorAboveViewport
|| inspectorMenu.IsCursorHovering
|| timingGroupPicker.IsCursorHovering
|| RangeSelected)
{
return;
Expand Down
26 changes: 22 additions & 4 deletions Assets/Scripts/Compose/Timeline/TimelineService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArcCreate.Compose.Navigation;
using ArcCreate.Gameplay;
using ArcCreate.Utility;
using Cysharp.Threading.Tasks;
using UnityEngine;
Expand All @@ -10,6 +11,7 @@ namespace ArcCreate.Compose.Timeline
public class TimelineService : MonoBehaviour, ITimelineService
{
[SerializeField] private WaveformDisplay waveformDisplay;
[SerializeField] private GameplayData gameplayData;

[Header("Markers")]
[SerializeField] private Marker timingMarker;
Expand Down Expand Up @@ -37,7 +39,7 @@ public class TimelineService : MonoBehaviour, ITimelineService
private bool IsPlaying => Services.Gameplay?.Audio.IsPlaying ?? false;

[EditorAction("TogglePlay", false, "q")]
[KeybindHint(Priority = KeybindPriorities.Playback + 1)]
[KeybindHint(Priority = KeybindPriorities.Playback + 3)]
[RequireGameplayLoaded]
public void TogglePlay()
{
Expand All @@ -54,9 +56,9 @@ public void TogglePlay()
[EditorAction("PlayReturn", false, "<space>")]
[SubAction("Return", false, "<u-space>")]
[SubAction("Pause", false, "q")]
[KeybindHint(Priority = KeybindPriorities.Playback)]
[KeybindHint("Return", Priority = KeybindPriorities.Playback + 2)]
[KeybindHint("Pause", Priority = KeybindPriorities.Playback + 1)]
[KeybindHint(Priority = KeybindPriorities.Playback + 2)]
[KeybindHint("Return", Priority = KeybindPriorities.Playback + 4)]
[KeybindHint("Pause", Priority = KeybindPriorities.Playback + 3)]
[RequireGameplayLoaded]
public async UniTask StartPlayReturn(EditorAction action)
{
Expand Down Expand Up @@ -168,6 +170,22 @@ public async UniTask ScrollForwardOneBeat(EditorAction action)
}
}

[EditorAction("DecreaseSpeed", false, "[")]
[KeybindHint(Exclude = false, Priority = KeybindPriorities.Playback + 1)]
public void DecreasePlaybackSpeed()
{
gameplayData.PlaybackSpeed.Value
= Mathf.Max(gameplayData.PlaybackSpeed.Value - 0.25f, 0.1f);
}

[EditorAction("IncreaseSpeed", false, "]")]
[KeybindHint(Exclude = false, Priority = KeybindPriorities.Playback)]
public void IncreasePlaybackSpeed()
{
gameplayData.PlaybackSpeed.Value
= Mathf.Min(gameplayData.PlaybackSpeed.Value + 0.25f, 5f);
}

private void Awake()
{
timingMarker.OnValueChanged += OnTimingMarker;
Expand Down
Loading

0 comments on commit b37d9d2

Please sign in to comment.