Merge branch 'master' into fix-timeline-seek-while-playing

This commit is contained in:
Dan Balasescu
2020-02-14 13:04:38 +09:00
committed by GitHub
76 changed files with 911 additions and 557 deletions

View File

@ -7,7 +7,6 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects;
@ -62,20 +61,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
private void refreshTool()
{
placementBlueprintContainer.Clear();
currentPlacement?.EndPlacement(false);
currentPlacement = null;
var blueprint = CurrentTool?.CreatePlacementBlueprint();
if (blueprint != null)
{
placementBlueprintContainer.Child = currentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
}
removePlacement();
createPlacement();
}
private void updatePlacementPosition(Vector2 screenSpacePosition)
@ -88,33 +75,23 @@ namespace osu.Game.Screens.Edit.Compose.Components
#endregion
protected override bool OnMouseMove(MouseMoveEvent e)
{
if (currentPlacement != null)
{
updatePlacementPosition(e.ScreenSpaceMousePosition);
return true;
}
return base.OnMouseMove(e);
}
protected override void Update()
{
base.Update();
if (composer.CursorInPlacementArea)
createPlacement();
else if (currentPlacement?.PlacementActive == false)
removePlacement();
if (currentPlacement != null)
{
if (composer.CursorInPlacementArea)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden;
}
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
}
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
{
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
if (drawable == null)
return null;
@ -129,6 +106,30 @@ namespace osu.Game.Screens.Edit.Compose.Components
base.AddBlueprintFor(hitObject);
}
private void createPlacement()
{
if (currentPlacement != null) return;
var blueprint = CurrentTool?.CreatePlacementBlueprint();
if (blueprint != null)
{
placementBlueprintContainer.Child = currentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
}
}
private void removePlacement()
{
if (currentPlacement == null) return;
currentPlacement.EndPlacement(false);
currentPlacement.Expire();
currentPlacement = null;
}
private HitObjectCompositionTool currentTool;
/// <summary>
@ -137,6 +138,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
public HitObjectCompositionTool CurrentTool
{
get => currentTool;
set
{
if (currentTool == value)

View File

@ -6,10 +6,13 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
@ -52,6 +55,45 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
HoverColour = OsuColour.Gray(0.25f);
FlashColour = OsuColour.Gray(0.5f);
}
private ScheduledDelegate repeatSchedule;
/// <summary>
/// The initial delay before mouse down repeat begins.
/// </summary>
private const int repeat_initial_delay = 250;
/// <summary>
/// The delay between mouse down repeats after the initial repeat.
/// </summary>
private const int repeat_tick_rate = 70;
protected override bool OnClick(ClickEvent e)
{
// don't actuate a click since we are manually handling repeats.
return true;
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == MouseButton.Left)
{
Action clickAction = () => base.OnClick(new ClickEvent(e.CurrentState, e.Button));
// run once for initial down
clickAction();
Scheduler.Add(repeatSchedule = new ScheduledDelegate(clickAction, Clock.CurrentTime + repeat_initial_delay, repeat_tick_rate));
}
return base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseUpEvent e)
{
repeatSchedule?.Cancel();
base.OnMouseUp(e);
}
}
}
}