1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:47:28 +08:00

Basic inter-column selection movement

This commit is contained in:
smoogipoo 2018-11-15 21:37:22 +09:00
parent df7515b66f
commit f7fc2ca569
8 changed files with 93 additions and 4 deletions

View File

@ -46,5 +46,7 @@ namespace osu.Game.Rulesets.Mania.Tests
protected override void AddHitObject(DrawableHitObject hitObject) => column.Add((DrawableManiaHitObject)hitObject);
public Column ColumnAt(Vector2 screenSpacePosition) => column;
public int TotalColumns => 1;
}
}

View File

@ -2,14 +2,37 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Timing;
using osu.Game.Rulesets.Mania.Edit;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Tests.Visual;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Rulesets.Mania.Tests
{
public abstract class ManiaSelectionBlueprintTestCase : SelectionBlueprintTestCase
[Cached(Type = typeof(IManiaHitObjectComposer))]
public abstract class ManiaSelectionBlueprintTestCase : SelectionBlueprintTestCase, IManiaHitObjectComposer
{
[Cached(Type = typeof(IAdjustableClock))]
private readonly IAdjustableClock clock = new StopwatchClock();
private readonly Column column;
protected ManiaSelectionBlueprintTestCase()
{
Add(column = new Column(0)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AccentColour = Color4.OrangeRed,
Clock = new FramedClock(new StopwatchClock()), // No scroll
});
}
public Column ColumnAt(Vector2 screenSpacePosition) => column;
public int TotalColumns => 1;
}
}

View File

@ -2,11 +2,15 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
using OpenTK;
@ -20,6 +24,9 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
[Resolved]
private IScrollingInfo scrollingInfo { get; set; }
[Resolved]
private IManiaHitObjectComposer composer { get; set; }
public ManiaSelectionBlueprint(DrawableHitObject hitObject)
: base(hitObject)
{
@ -41,6 +48,8 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
public override void AdjustPosition(DragEvent dragEvent, IEnumerable<DrawableHitObject> selectedObjects)
{
var maniaObject = (ManiaHitObject)HitObject.HitObject;
var objectParent = HitObject.Parent;
// Using the hitobject position is required since AdjustPosition can be invoked multiple times per frame
@ -60,6 +69,34 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
EditorClock.CurrentTime,
scrollingInfo.TimeRange.Value,
objectParent.DrawHeight);
var lastColumn = ColumnAt(dragEvent.ScreenSpaceLastMousePosition);
var currentColumn = ColumnAt(dragEvent.ScreenSpaceMousePosition);
if (lastColumn != null && currentColumn != null)
{
int columnDelta = currentColumn.Index - lastColumn.Index;
if (columnDelta != 0)
{
int minColumn = int.MaxValue;
int maxColumn = int.MinValue;
foreach (var obj in selectedObjects.OfType<DrawableManiaHitObject>())
{
if (obj.HitObject.Column < minColumn)
minColumn = obj.HitObject.Column;
if (obj.HitObject.Column > maxColumn)
maxColumn = obj.HitObject.Column;
}
columnDelta = MathHelper.Clamp(columnDelta, -minColumn, composer.TotalColumns - 1 - maxColumn);
}
Schedule(() => maniaObject.Column += columnDelta);
}
}
protected Column ColumnAt(Vector2 screenSpacePosition) => composer.ColumnAt(screenSpacePosition);
}
}

View File

@ -9,5 +9,7 @@ namespace osu.Game.Rulesets.Mania.Edit
public interface IManiaHitObjectComposer
{
Column ColumnAt(Vector2 screenSpacePosition);
int TotalColumns { get; }
}
}

View File

@ -31,6 +31,8 @@ namespace osu.Game.Rulesets.Mania.Edit
public Column ColumnAt(Vector2 screenSpacePosition) => ((ManiaPlayfield)RulesetContainer.Playfield).GetColumnByPosition(screenSpacePosition);
public int TotalColumns => ((ManiaPlayfield)RulesetContainer.Playfield).TotalColumns;
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
{
var rulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap);

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Game.Rulesets.Mania.Objects.Types;
using osu.Game.Rulesets.Objects;
@ -8,7 +9,13 @@ namespace osu.Game.Rulesets.Mania.Objects
{
public abstract class ManiaHitObject : HitObject, IHasColumn
{
public virtual int Column { get; set; }
public readonly Bindable<int> ColumnBindable = new Bindable<int>();
public virtual int Column
{
get => ColumnBindable;
set => ColumnBindable.Value = value;
}
protected override HitWindows CreateHitWindows() => new ManiaHitWindows();
}

View File

@ -5,6 +5,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects.Drawables;
@ -81,6 +82,11 @@ namespace osu.Game.Rulesets.Mania.UI
return found;
}
/// <summary>
/// Retrieves the total amount of columns across all stages in this playfield.
/// </summary>
public int TotalColumns => stages.Sum(s => s.Columns.Count);
private ManiaStage getStageByColumn(int column)
{
int sum = 0;

View File

@ -152,8 +152,18 @@ namespace osu.Game.Rulesets.Mania.UI
public override void Add(DrawableHitObject h)
{
var maniaObject = (ManiaHitObject)h.HitObject;
int columnIndex = maniaObject.Column - firstColumnIndex;
int columnIndex = -1;
maniaObject.ColumnBindable.BindValueChanged(_ =>
{
if (columnIndex != -1)
Columns.ElementAt(columnIndex).Remove(h);
columnIndex = maniaObject.Column - firstColumnIndex;
Columns.ElementAt(columnIndex).Add(h);
}, true);
h.OnNewResult += OnNewResult;
}