From a95ee7494f54b36929dbc7574b893adc199b47a8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 16:01:18 +0900 Subject: [PATCH 01/83] Initial conversion of taiko to use ScrollingPlayfield. --- .../Visual/TestCaseTaikoPlayfield.cs | 12 ++----- .../Objects/Drawables/DrawableBarLine.cs | 29 +++++---------- .../Objects/Drawables/DrawableDrumRoll.cs | 36 ++++++++----------- .../Objects/Drawables/DrawableDrumRollTick.cs | 5 --- .../Objects/Drawables/DrawableSwell.cs | 13 +++---- .../Drawables/DrawableTaikoHitObject.cs | 18 +--------- .../Drawables/Pieces/ElongatedCirclePiece.cs | 12 +------ osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs | 1 - .../Objects/TaikoHitObject.cs | 14 -------- .../UI/TaikoHitRenderer.cs | 4 +-- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 20 ++++------- 11 files changed, 41 insertions(+), 123 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs index 45be9e800d..f6ee2a5bf3 100644 --- a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs @@ -151,13 +151,9 @@ namespace osu.Desktop.Tests.Visual private void addBarLine(bool major, double delay = scroll_time) { - BarLine bl = new BarLine - { - StartTime = playfield.Time.Current + delay, - ScrollTime = scroll_time - }; + BarLine bl = new BarLine { StartTime = playfield.Time.Current + delay }; - playfield.AddBarLine(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl)); + playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl)); } private void addSwell(double duration = default_duration) @@ -166,7 +162,6 @@ namespace osu.Desktop.Tests.Visual { StartTime = playfield.Time.Current + scroll_time, Duration = duration, - ScrollTime = scroll_time })); } @@ -180,7 +175,6 @@ namespace osu.Desktop.Tests.Visual StartTime = playfield.Time.Current + scroll_time, IsStrong = strong, Duration = duration, - ScrollTime = scroll_time, }; playfield.Add(new DrawableDrumRoll(d)); @@ -191,7 +185,6 @@ namespace osu.Desktop.Tests.Visual Hit h = new Hit { StartTime = playfield.Time.Current + scroll_time, - ScrollTime = scroll_time, IsStrong = strong }; @@ -206,7 +199,6 @@ namespace osu.Desktop.Tests.Visual Hit h = new Hit { StartTime = playfield.Time.Current + scroll_time, - ScrollTime = scroll_time, IsStrong = strong }; diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs index 7507ee600e..f6959fb426 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs @@ -5,13 +5,16 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using OpenTK; +using osu.Game.Rulesets.Objects.Drawables; +using System; +using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; namespace osu.Game.Rulesets.Taiko.Objects.Drawables { /// /// A line that scrolls alongside hit objects in the playfield and visualises control points. /// - public class DrawableBarLine : Container + public class DrawableBarLine : DrawableTaikoHitObject { /// /// The width of the line tracker. @@ -34,15 +37,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables protected readonly BarLine BarLine; public DrawableBarLine(BarLine barLine) + : base(barLine) { BarLine = barLine; - Anchor = Anchor.CentreLeft; - Origin = Anchor.Centre; - - RelativePositionAxes = Axes.X; RelativeSizeAxes = Axes.Y; - Width = tracker_width; Children = new[] @@ -56,24 +55,12 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables Alpha = 0.75f } }; - - LifetimeStart = BarLine.StartTime - BarLine.ScrollTime * 2; - LifetimeEnd = BarLine.StartTime + BarLine.ScrollTime; } - protected override void LoadComplete() + protected override TaikoPiece CreateMainPiece() => new TaikoPiece(); + + protected override void UpdateState(ArmedState state) { - base.LoadComplete(); - this.Delay(BarLine.StartTime - Time.Current).FadeOut(base_fadeout_time * BarLine.ScrollTime / 1000); - } - - private void updateScrollPosition(double time) => this.MoveToX((float)((BarLine.StartTime - time) / BarLine.ScrollTime)); - - protected override void Update() - { - base.Update(); - - updateScrollPosition(Time.Current); } } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs index 74f0f2326d..e9c50dacf8 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs @@ -11,6 +11,7 @@ using OpenTK; using OpenTK.Graphics; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; namespace osu.Game.Rulesets.Taiko.Objects.Drawables { @@ -34,27 +35,29 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; + Width = (float)HitObject.Duration; + + Container tickContainer; + MainPiece.Add(tickContainer = new Container + { + RelativeSizeAxes = Axes.Both, + RelativeChildOffset = new Vector2((float)HitObject.StartTime, 0), + RelativeChildSize = new Vector2((float)HitObject.Duration, 1) + }); + foreach (var tick in drumRoll.Ticks) { - var newTick = new DrawableDrumRollTick(tick) - { - X = (float)((tick.StartTime - HitObject.StartTime) / HitObject.Duration) - }; - + var newTick = new DrawableDrumRollTick(tick) { X = (float)tick.StartTime }; newTick.OnJudgement += onTickJudgement; AddNested(newTick); - MainPiece.Add(newTick); + tickContainer.Add(newTick); } } protected override TaikoJudgement CreateJudgement() => new TaikoJudgement { SecondHit = HitObject.IsStrong }; - protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece - { - Length = (float)(HitObject.Duration / HitObject.ScrollTime), - PlayfieldLengthReference = () => Parent.DrawSize.X - }; + protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece(); [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -63,17 +66,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables accentDarkColour = colours.YellowDarker; } - protected override void LoadComplete() - { - base.LoadComplete(); - - // This is naive, however it's based on the reasoning that the hit target - // is further than mid point of the play field, so the time taken to scroll in should always - // be greater than the time taken to scroll out to the left of the screen. - // Thus, using PreEmpt here is enough for the drum roll to completely scroll out. - LifetimeEnd = HitObject.EndTime + HitObject.ScrollTime; - } - private void onTickJudgement(DrawableHitObject obj) { if (obj.Judgement.Result == HitResult.Hit) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs index 0e1cd05de3..ad065395b9 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs @@ -47,11 +47,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables } } - protected override void UpdateScrollPosition(double time) - { - // Ticks don't move - } - protected override bool HandleKeyPress(Key key) { return Judgement.Result == HitResult.None && UpdateJudgement(true); diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs index e861af03cf..f704879f1a 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs @@ -118,7 +118,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables }); MainPiece.Add(symbol = new SwellSymbolPiece()); - } [BackgroundDependencyLoader] @@ -189,20 +188,22 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables Expire(); } - protected override void UpdateScrollPosition(double time) + protected override void Update() { - // Make the swell stop at the hit target - double t = Math.Min(HitObject.StartTime, time); + base.Update(); + // Make the swell stop at the hit target + X = (float)Math.Max(Time.Current, HitObject.StartTime); + + double t = Math.Min(HitObject.StartTime, Time.Current); if (t == HitObject.StartTime && !hasStarted) { OnStart?.Invoke(); hasStarted = true; } - - base.UpdateScrollPosition(t); } + protected override bool HandleKeyPress(Key key) { if (Judgement.Result != HitResult.None) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableTaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableTaikoHitObject.cs index 510994ed70..caae70fe05 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableTaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableTaikoHitObject.cs @@ -12,7 +12,7 @@ using OpenTK.Input; namespace osu.Game.Rulesets.Taiko.Objects.Drawables { - public abstract class DrawableTaikoHitObject : DrawableHitObject + public abstract class DrawableTaikoHitObject : DrawableScrollingHitObject where TaikoHitType : TaikoHitObject { /// @@ -38,30 +38,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables RelativeSizeAxes = Axes.Both; Size = new Vector2(HitObject.IsStrong ? TaikoHitObject.DEFAULT_STRONG_SIZE : TaikoHitObject.DEFAULT_SIZE); - RelativePositionAxes = Axes.X; - Add(MainPiece = CreateMainPiece()); MainPiece.KiaiMode = HitObject.Kiai; - - LifetimeStart = HitObject.StartTime - HitObject.ScrollTime * 2; } protected override TaikoJudgement CreateJudgement() => new TaikoJudgement(); protected virtual TaikoPiece CreateMainPiece() => new CirclePiece(); - /// - /// Sets the scroll position of the DrawableHitObject relative to the offset between - /// a time value and the HitObject's StartTime. - /// - /// - protected virtual void UpdateScrollPosition(double time) => X = (float)((HitObject.StartTime - time) / HitObject.ScrollTime); - - protected override void Update() - { - UpdateScrollPosition(Time.Current); - } - protected virtual bool HandleKeyPress(Key key) => false; protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs index 2f5b4eefd6..d3786a4324 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs @@ -8,16 +8,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces { public class ElongatedCirclePiece : CirclePiece { - /// - /// As we are being used to define the absolute size of hits, we need to be given a relative reference of our containing playfield container. - /// - public Func PlayfieldLengthReference; - - /// - /// The length of this piece as a multiple of the value returned by - /// - public float Length; - public ElongatedCirclePiece() { RelativeSizeAxes = Axes.Y; @@ -35,7 +25,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces Right = padding, }; - Width = (PlayfieldLengthReference?.Invoke() ?? 0) * Length + DrawHeight; + Width = Parent.DrawSize.X + DrawHeight; } } } diff --git a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs index fd9daa269c..526d23f51a 100644 --- a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs @@ -80,7 +80,6 @@ namespace osu.Game.Rulesets.Taiko.Objects ret.Add(new DrumRollTick { FirstTick = first, - ScrollTime = ScrollTime, TickSpacing = tickSpacing, StartTime = t, IsStrong = IsStrong, diff --git a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs index 7e7dc3662f..f1c0afc675 100644 --- a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs @@ -24,16 +24,6 @@ namespace osu.Game.Rulesets.Taiko.Objects /// public const float DEFAULT_STRONG_SIZE = DEFAULT_SIZE * STRONG_SCALE; - /// - /// The time taken from the initial (off-screen) spawn position to the centre of the hit target for a of 1000ms. - /// - private const double scroll_time = 6000; - - /// - /// Our adjusted taking into consideration local and other speed multipliers. - /// - public double ScrollTime; - /// /// Whether this HitObject is a "strong" type. /// Strong hit objects give more points for hitting the hit object with both keys. @@ -49,12 +39,8 @@ namespace osu.Game.Rulesets.Taiko.Objects { base.ApplyDefaults(controlPointInfo, difficulty); - TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); - DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime); - ScrollTime = scroll_time * (timingPoint.BeatLength * difficultyPoint.SpeedMultiplier / 1000) / difficulty.SliderMultiplier; - Kiai |= effectPoint.KiaiMode; } } diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs index 570b4be488..9c9c71ab46 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs @@ -21,7 +21,7 @@ using System.Linq; namespace osu.Game.Rulesets.Taiko.UI { - public class TaikoHitRenderer : HitRenderer + public class TaikoHitRenderer : ScrollingHitRenderer { public TaikoHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(beatmap, isForCurrentRuleset) @@ -72,7 +72,7 @@ namespace osu.Game.Rulesets.Taiko.UI barLine.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.Difficulty); bool isMajor = currentBeat % (int)currentPoint.TimeSignature == 0; - taikoPlayfield.AddBarLine(isMajor ? new DrawableBarLineMajor(barLine) : new DrawableBarLine(barLine)); + taikoPlayfield.Add(isMajor ? new DrawableBarLineMajor(barLine) : new DrawableBarLine(barLine)); double bl = currentPoint.BeatLength; if (bl < 800) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index dca339f734..d94b69f141 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -18,7 +18,7 @@ using osu.Game.Rulesets.Taiko.Objects.Drawables; namespace osu.Game.Rulesets.Taiko.UI { - public class TaikoPlayfield : Playfield + public class TaikoPlayfield : ScrollingPlayfield { /// /// Default height of a when inside a . @@ -35,14 +35,14 @@ namespace osu.Game.Rulesets.Taiko.UI /// private const float left_area_size = 240; - protected override Container Content => hitObjectContainer; private readonly Container hitExplosionContainer; private readonly Container kiaiExplosionContainer; - private readonly Container barLineContainer; private readonly Container judgementContainer; - private readonly Container hitObjectContainer; + protected override Container Content => content; + private readonly Container content; + private readonly Container topLevelHitContainer; private readonly Container overlayBackgroundContainer; @@ -52,6 +52,7 @@ namespace osu.Game.Rulesets.Taiko.UI private readonly Box background; public TaikoPlayfield() + : base(Axes.X) { AddRangeInternal(new Drawable[] { @@ -96,10 +97,6 @@ namespace osu.Game.Rulesets.Taiko.UI FillMode = FillMode.Fit, BlendingMode = BlendingMode.Additive, }, - barLineContainer = new Container - { - RelativeSizeAxes = Axes.Both, - }, new HitTarget { Anchor = Anchor.CentreLeft, @@ -107,7 +104,7 @@ namespace osu.Game.Rulesets.Taiko.UI RelativeSizeAxes = Axes.Both, FillMode = FillMode.Fit }, - hitObjectContainer = new Container + content = new Container { RelativeSizeAxes = Axes.Both, }, @@ -205,11 +202,6 @@ namespace osu.Game.Rulesets.Taiko.UI swell.OnStart += () => topLevelHitContainer.Add(swell.CreateProxy()); } - public void AddBarLine(DrawableBarLine barLine) - { - barLineContainer.Add(barLine); - } - public override void OnJudgement(DrawableHitObject judgedObject) { bool wasHit = judgedObject.Judgement.Result == HitResult.Hit; From 27e63eb7c4d2947e8acec044b189349102593bd4 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 10:54:00 +0900 Subject: [PATCH 02/83] Fix up sizing issues. --- osu-framework | 2 +- .../Objects/Drawables/DrawableBarLine.cs | 8 ++++++-- .../Objects/Drawables/DrawableDrumRoll.cs | 3 --- .../Objects/Drawables/DrawableDrumRollTick.cs | 8 ++++++++ osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs | 8 ++++++++ .../Objects/Drawables/DrawableSwell.cs | 8 ++++++++ 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/osu-framework b/osu-framework index dd0daafcfc..3b858d078c 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit dd0daafcfc0d625bb588c8e12d7db58bc00c255e +Subproject commit 3b858d078cf54465d9af8e2bb9e1a144bcfcdbf4 diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs index f6959fb426..28f0af4aba 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs @@ -8,13 +8,14 @@ using OpenTK; using osu.Game.Rulesets.Objects.Drawables; using System; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; +using osu.Game.Rulesets.Taiko.Judgements; namespace osu.Game.Rulesets.Taiko.Objects.Drawables { /// /// A line that scrolls alongside hit objects in the playfield and visualises control points. /// - public class DrawableBarLine : DrawableTaikoHitObject + public class DrawableBarLine : DrawableScrollingHitObject { /// /// The width of the line tracker. @@ -41,6 +42,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables { BarLine = barLine; + Anchor = Anchor.CentreLeft; + Origin = Anchor.Centre; + RelativeSizeAxes = Axes.Y; Width = tracker_width; @@ -57,7 +61,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables }; } - protected override TaikoPiece CreateMainPiece() => new TaikoPiece(); + protected override TaikoJudgement CreateJudgement() => new TaikoJudgement(); protected override void UpdateState(ArmedState state) { diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs index e9c50dacf8..425f87752f 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs @@ -32,9 +32,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables public DrawableDrumRoll(DrumRoll drumRoll) : base(drumRoll) { - RelativeSizeAxes = Axes.Y; - AutoSizeAxes = Axes.X; - Width = (float)HitObject.Duration; Container tickContainer; diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs index ad065395b9..5a6abd24b1 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs @@ -18,6 +18,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables FillMode = FillMode.Fit; } + protected override void LoadComplete() + { + base.LoadComplete(); + + // We need to set this here because RelativeSizeAxes won't/can't set our size by default with a different RelativeChildSize + Width *= Parent.RelativeChildSize.X; + } + protected override TaikoPiece CreateMainPiece() => new TickPiece { Filled = HitObject.FirstTick diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs index 5a17355cdb..0666d75083 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableHit.cs @@ -29,6 +29,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables FillMode = FillMode.Fit; } + protected override void LoadComplete() + { + base.LoadComplete(); + + // We need to set this here because RelativeSizeAxes won't/can't set our size by default with a different RelativeChildSize + Width *= Parent.RelativeChildSize.X; + } + protected override void CheckJudgement(bool userTriggered) { if (!userTriggered) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs index f704879f1a..2b1ed07da7 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableSwell.cs @@ -128,6 +128,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables targetRing.BorderColour = colours.YellowDark.Opacity(0.25f); } + protected override void LoadComplete() + { + base.LoadComplete(); + + // We need to set this here because RelativeSizeAxes won't/can't set our size by default with a different RelativeChildSize + Width *= Parent.RelativeChildSize.X; + } + protected override void CheckJudgement(bool userTriggered) { if (userTriggered) From d83c218e08155add50e570246f09e84ebdf0d6a5 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:19:09 +0900 Subject: [PATCH 03/83] Remove various scrolling container optimisations (removing when not alive). --- .../Drawables/DrawableScrollingHitObject.cs | 2 ++ osu.Game/Rulesets/Timing/ScrollingContainer.cs | 2 ++ .../Rulesets/Timing/SpeedAdjustmentContainer.cs | 2 ++ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 17 +++++++++-------- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index f67dd4dfea..a7c4dd0333 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -32,6 +32,8 @@ namespace osu.Game.Rulesets.Objects.Drawables } } + public override bool RemoveWhenNotAlive => false; + protected DrawableScrollingHitObject(TObject hitObject) : base(hitObject) { diff --git a/osu.Game/Rulesets/Timing/ScrollingContainer.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs index 843f307d0d..9bb32ead77 100644 --- a/osu.Game/Rulesets/Timing/ScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -27,6 +27,8 @@ namespace osu.Game.Rulesets.Timing /// internal Axes ScrollingAxes; + public override bool RemoveWhenNotAlive => false; + /// /// The control point that defines the speed adjustments for this container. This is set by the . /// diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 9d5f49e155..5d6c03b9de 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -34,6 +34,8 @@ namespace osu.Game.Rulesets.Timing /// public Axes ScrollingAxes { get; internal set; } + public override bool RemoveWhenNotAlive => false; + /// /// The that defines the speed adjustments. /// diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 66ca2dd7c4..f8e090d613 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -7,6 +7,7 @@ using System.Linq; using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Transforms; using osu.Framework.Input; using osu.Framework.MathUtils; @@ -154,7 +155,7 @@ namespace osu.Game.Rulesets.UI /// Hit objects that are to be re-processed on the next update. /// private readonly List queuedHitObjects = new List(); - private readonly List speedAdjustments = new List(); + private readonly Container speedAdjustments; private readonly Axes scrollingAxes; @@ -165,6 +166,8 @@ namespace osu.Game.Rulesets.UI public ScrollingHitObjectContainer(Axes scrollingAxes) { this.scrollingAxes = scrollingAxes; + + AddInternal(speedAdjustments = new Container { RelativeSizeAxes = Axes.Both }); } /// @@ -176,9 +179,7 @@ namespace osu.Game.Rulesets.UI speedAdjustment.ScrollingAxes = scrollingAxes; speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); speedAdjustment.Reversed.BindTo(Reversed); - speedAdjustments.Add(speedAdjustment); - AddInternal(speedAdjustment); } public override IEnumerable Objects => speedAdjustments.SelectMany(s => s.Children); @@ -210,11 +211,11 @@ namespace osu.Game.Rulesets.UI var hitObject = queuedHitObjects[i]; var target = adjustmentContainerFor(hitObject); - if (target != null) - { - target.Add(hitObject); - queuedHitObjects.RemoveAt(i); - } + if (target == null) + continue; + + target.Add(hitObject); + queuedHitObjects.RemoveAt(i); } } From 88cefa77bd69ec637afbfaf6dddf1614e9fd9e8d Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:19:20 +0900 Subject: [PATCH 04/83] Make TestCaseTaikoPlayfield work again. --- .../Visual/TestCaseTaikoPlayfield.cs | 64 +++++++++++++------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs index f6ee2a5bf3..1589ca8f9b 100644 --- a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs @@ -14,6 +14,9 @@ using osu.Game.Rulesets.Taiko.UI; using OpenTK; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps; +using osu.Desktop.Tests.Beatmaps; +using System.Collections.Generic; +using osu.Game.Rulesets.Objects; namespace osu.Desktop.Tests.Visual { @@ -27,7 +30,7 @@ namespace osu.Desktop.Tests.Visual protected override double TimePerAction => default_duration * 2; private readonly Random rng = new Random(1337); - private readonly TaikoPlayfield playfield; + private readonly TaikoRulesetContainer rulesetContainer; private readonly Container playfieldContainer; public TestCaseTaikoPlayfield() @@ -51,7 +54,29 @@ namespace osu.Desktop.Tests.Visual AddStep("Height test 5", () => changePlayfieldSize(5)); AddStep("Reset height", () => changePlayfieldSize(6)); - var rateAdjustClock = new StopwatchClock(true) { Rate = 1 }; + var controlPointInfo = new ControlPointInfo(); + controlPointInfo.TimingPoints.Add(new TimingControlPoint + { + BeatLength = 200 + }); + + WorkingBeatmap beatmap = new TestWorkingBeatmap(new Beatmap + { + HitObjects = new List { new CentreHit() }, + BeatmapInfo = new BeatmapInfo + { + Difficulty = new BeatmapDifficulty(), + Metadata = new BeatmapMetadata + { + Artist = @"Unknown", + Title = @"Sample Beatmap", + Author = @"peppy", + }, + }, + ControlPointInfo = controlPointInfo + }); + + var rateAdjustClock = new StopwatchClock(true) { Rate = 0.1 }; Add(playfieldContainer = new Container { @@ -60,10 +85,7 @@ namespace osu.Desktop.Tests.Visual RelativeSizeAxes = Axes.X, Height = TaikoPlayfield.DEFAULT_HEIGHT, Clock = new FramedClock(rateAdjustClock), - Children = new[] - { - playfield = new TaikoPlayfield() - } + Children = new[] { rulesetContainer = new TaikoRulesetContainer(null, beatmap, true) } }); } @@ -128,18 +150,18 @@ namespace osu.Desktop.Tests.Visual } }; - playfield.OnJudgement(h); + rulesetContainer.Playfield.OnJudgement(h); if (RNG.Next(10) == 0) { h.Judgement.SecondHit = true; - playfield.OnJudgement(h); + rulesetContainer.Playfield.OnJudgement(h); } } private void addMissJudgement() { - playfield.OnJudgement(new DrawableTestHit(new Hit()) + rulesetContainer.Playfield.OnJudgement(new DrawableTestHit(new Hit()) { Judgement = new TaikoJudgement { @@ -151,16 +173,16 @@ namespace osu.Desktop.Tests.Visual private void addBarLine(bool major, double delay = scroll_time) { - BarLine bl = new BarLine { StartTime = playfield.Time.Current + delay }; + BarLine bl = new BarLine { StartTime = rulesetContainer.Playfield.Time.Current + delay }; - playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl)); + rulesetContainer.Playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl)); } private void addSwell(double duration = default_duration) { - playfield.Add(new DrawableSwell(new Swell + rulesetContainer.Playfield.Add(new DrawableSwell(new Swell { - StartTime = playfield.Time.Current + scroll_time, + StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, Duration = duration, })); } @@ -172,40 +194,40 @@ namespace osu.Desktop.Tests.Visual var d = new DrumRoll { - StartTime = playfield.Time.Current + scroll_time, + StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, IsStrong = strong, Duration = duration, }; - playfield.Add(new DrawableDrumRoll(d)); + rulesetContainer.Playfield.Add(new DrawableDrumRoll(d)); } private void addCentreHit(bool strong) { Hit h = new Hit { - StartTime = playfield.Time.Current + scroll_time, + StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, IsStrong = strong }; if (strong) - playfield.Add(new DrawableCentreHitStrong(h)); + rulesetContainer.Playfield.Add(new DrawableCentreHitStrong(h)); else - playfield.Add(new DrawableCentreHit(h)); + rulesetContainer.Playfield.Add(new DrawableCentreHit(h)); } private void addRimHit(bool strong) { Hit h = new Hit { - StartTime = playfield.Time.Current + scroll_time, + StartTime = rulesetContainer.Playfield.Time.Current + scroll_time, IsStrong = strong }; if (strong) - playfield.Add(new DrawableRimHitStrong(h)); + rulesetContainer.Playfield.Add(new DrawableRimHitStrong(h)); else - playfield.Add(new DrawableRimHit(h)); + rulesetContainer.Playfield.Add(new DrawableRimHit(h)); } private class DrawableTestHit : DrawableHitObject From 8b4f28318f5e45a365f27efaad51e79ff39bc438 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:19:31 +0900 Subject: [PATCH 05/83] Fix drum roll ticks. --- osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs | 2 +- .../Objects/Drawables/DrawableDrumRollTick.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs index 425f87752f..8f81368a2c 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRoll.cs @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables foreach (var tick in drumRoll.Ticks) { - var newTick = new DrawableDrumRollTick(tick) { X = (float)tick.StartTime }; + var newTick = new DrawableDrumRollTick(tick); newTick.OnJudgement += onTickJudgement; AddNested(newTick); diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs index 5a6abd24b1..6e916aa9d5 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableDrumRollTick.cs @@ -15,6 +15,10 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables public DrawableDrumRollTick(DrumRollTick tick) : base(tick) { + // Because ticks aren't added by the ScrollingPlayfield, we need to set the following properties ourselves + RelativePositionAxes = Axes.X; + X = (float)tick.StartTime; + FillMode = FillMode.Fit; } From 7237f834c4e1144bef0c38627cc6b2d02dc49922 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:39:19 +0900 Subject: [PATCH 06/83] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 67d89a3601..9bad670471 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 67d89a36016f98c0ede576b859a2ccafe114fce8 +Subproject commit 9bad670471a03e299760315fd9d3fa9a726f6233 From 2334c109e5262514970e54ab34a626d94d0aff52 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:46:08 +0900 Subject: [PATCH 07/83] Set better TaikoPlayfield default VisibleTimeRange. --- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index e2823ccdfe..da86c31123 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -178,6 +178,8 @@ namespace osu.Game.Rulesets.Taiko.UI RelativeSizeAxes = Axes.Both, } }); + + VisibleTimeRange.Value = 6000; } [BackgroundDependencyLoader] From 0c1b68d7111a2e5da1d4bb073db1f3ccf374b2ff Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 16:46:22 +0900 Subject: [PATCH 08/83] Fix up TestCaseTaikoPlayfield. --- osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs index 1589ca8f9b..43148da512 100644 --- a/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseTaikoPlayfield.cs @@ -55,10 +55,7 @@ namespace osu.Desktop.Tests.Visual AddStep("Reset height", () => changePlayfieldSize(6)); var controlPointInfo = new ControlPointInfo(); - controlPointInfo.TimingPoints.Add(new TimingControlPoint - { - BeatLength = 200 - }); + controlPointInfo.TimingPoints.Add(new TimingControlPoint()); WorkingBeatmap beatmap = new TestWorkingBeatmap(new Beatmap { @@ -76,14 +73,14 @@ namespace osu.Desktop.Tests.Visual ControlPointInfo = controlPointInfo }); - var rateAdjustClock = new StopwatchClock(true) { Rate = 0.1 }; + var rateAdjustClock = new StopwatchClock(true) { Rate = 1 }; Add(playfieldContainer = new Container { Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.X, - Height = TaikoPlayfield.DEFAULT_HEIGHT, + Height = 768, Clock = new FramedClock(rateAdjustClock), Children = new[] { rulesetContainer = new TaikoRulesetContainer(null, beatmap, true) } }); From e9a98358b3d47ad6708e39a9ad9f0ea71adf7030 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 17:26:59 +0900 Subject: [PATCH 09/83] Don't move completed drum rolls above the playfield. --- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index da86c31123..eb9e41f771 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -224,7 +224,7 @@ namespace osu.Game.Rulesets.Taiko.UI if (!secondHit) { - if (judgedObject.X >= -0.05f && !(judgedObject is DrawableSwell)) + if (judgedObject.X >= -0.05f && judgedObject is DrawableHit) { // If we're far enough away from the left stage, we should bring outselves in front of it topLevelHitContainer.Add(judgedObject.CreateProxy()); From bb8c5338022cd6d1313ec64750930917cccb523e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 9 Aug 2017 17:34:09 +0900 Subject: [PATCH 10/83] Fix CI issues. --- .../Objects/Drawables/DrawableBarLine.cs | 3 --- .../Objects/Drawables/Pieces/ElongatedCirclePiece.cs | 1 - osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs | 7 +------ 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs index 28f0af4aba..06702e8141 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/DrawableBarLine.cs @@ -2,12 +2,9 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using OpenTK; using osu.Game.Rulesets.Objects.Drawables; -using System; -using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Judgements; namespace osu.Game.Rulesets.Taiko.Objects.Drawables diff --git a/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs b/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs index d3786a4324..4642e318c4 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Drawables/Pieces/ElongatedCirclePiece.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using osu.Framework.Graphics; namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs index 36ee0c2a1d..723af3e4e9 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs @@ -36,11 +36,6 @@ namespace osu.Game.Rulesets.Taiko.UI private void loadBarLines() { - var taikoPlayfield = Playfield as TaikoPlayfield; - - if (taikoPlayfield == null) - return; - TaikoHitObject lastObject = Beatmap.HitObjects[Beatmap.HitObjects.Count - 1]; double lastHitTime = 1 + (lastObject as IHasEndTime)?.EndTime ?? lastObject.StartTime; @@ -72,7 +67,7 @@ namespace osu.Game.Rulesets.Taiko.UI barLine.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.Difficulty); bool isMajor = currentBeat % (int)currentPoint.TimeSignature == 0; - taikoPlayfield.Add(isMajor ? new DrawableBarLineMajor(barLine) : new DrawableBarLine(barLine)); + Playfield.Add(isMajor ? new DrawableBarLineMajor(barLine) : new DrawableBarLine(barLine)); double bl = currentPoint.BeatLength; if (bl < 800) From 10321497cab231eecd6e20531330c8fb9af944a3 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Wed, 9 Aug 2017 21:21:43 -0500 Subject: [PATCH 11/83] Add decoder entries for v3/4 --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 433c23284f..b31e2adee3 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -27,7 +27,9 @@ namespace osu.Game.Beatmaps.Formats AddDecoder(@"osu file format v7"); AddDecoder(@"osu file format v6"); AddDecoder(@"osu file format v5"); - // TODO: Not sure how far back to go, or differences between versions + AddDecoder(@"osu file format v4"); + AddDecoder(@"osu file format v3"); + // TODO: differences between versions } private ConvertHitObjectParser parser; From a8cf7ff93a935138e2d3fb6118bbef7646c060ae Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Wed, 9 Aug 2017 23:27:13 -0500 Subject: [PATCH 12/83] Add a better error message for corrupt maps with no .osu files --- osu.Game/Beatmaps/BeatmapManager.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index bbb6c975d0..61cd2f0a2b 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -307,6 +307,16 @@ namespace osu.Game.Beatmaps /// The imported beatmap, or an existing instance if it is already present. private BeatmapSetInfo importToStorage(ArchiveReader reader) { + // let's make sure there are actually .osu files to import. + try + { + string mapName = reader.Filenames.First(f => f.EndsWith(".osu")); + } + catch + { + throw new InvalidOperationException("No beatmap files found in the map folder."); + } + // for now, concatenate all .osu files in the set to create a unique hash. MemoryStream hashable = new MemoryStream(); foreach (string file in reader.Filenames.Where(f => f.EndsWith(".osu"))) From 64d92c1557badd6e7c4a6e358a9b4b5d8ada13f3 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Wed, 9 Aug 2017 23:31:18 -0500 Subject: [PATCH 13/83] Fix infinite loop when importing maps that have storyboard elements with '$' in the filename --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index b31e2adee3..39f0a0378c 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -222,7 +222,7 @@ namespace osu.Game.Beatmaps.Formats /// The line which may contains variables. private void decodeVariables(ref string line) { - while (line.IndexOf('$') >= 0) + if (line.IndexOf('$') >= 0) { string[] split = line.Split(','); for (int i = 0; i < split.Length; i++) From c16dbc05aafc2881cce98f78ddf9afce210df474 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Wed, 9 Aug 2017 23:41:22 -0500 Subject: [PATCH 14/83] Add new error for malformed (too many variables) hit objects during import --- osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index a4c319291c..b02a582bec 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -20,6 +20,9 @@ namespace osu.Game.Rulesets.Objects.Legacy public override HitObject Parse(string text) { string[] split = text.Split(','); + if (split.Length > 11) + throw new InvalidOperationException("One or more hit objects were malformed."); + ConvertHitObjectType type = (ConvertHitObjectType)int.Parse(split[3]) & ~ConvertHitObjectType.ColourHax; bool combo = type.HasFlag(ConvertHitObjectType.NewCombo); type &= ~ConvertHitObjectType.NewCombo; From f819ffce2bbb64e2fdba83d130042d084304625c Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Thu, 10 Aug 2017 00:08:39 -0500 Subject: [PATCH 15/83] Make the legacy decoder more resilient against leading linebreaks --- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 1c3eadc91e..234d65eee4 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -19,7 +19,9 @@ namespace osu.Game.Beatmaps.Formats public static BeatmapDecoder GetDecoder(StreamReader stream) { - string line = stream.ReadLine()?.Trim(); + string line; + do { line = stream.ReadLine()?.Trim(); } + while (line != null && line.Length == 0); if (line == null || !decoders.ContainsKey(line)) throw new IOException(@"Unknown file format"); From 2e5a7374a8d6eb3a3bfc56f3c05fbccb8fddcff1 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Thu, 10 Aug 2017 01:49:34 -0500 Subject: [PATCH 16/83] Actually use mapName whoops --- osu.Game/Beatmaps/BeatmapManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 61cd2f0a2b..4b063adde0 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -307,10 +307,11 @@ namespace osu.Game.Beatmaps /// The imported beatmap, or an existing instance if it is already present. private BeatmapSetInfo importToStorage(ArchiveReader reader) { + string mapName; // let's make sure there are actually .osu files to import. try { - string mapName = reader.Filenames.First(f => f.EndsWith(".osu")); + mapName = reader.Filenames.First(f => f.EndsWith(".osu")); } catch { @@ -349,7 +350,7 @@ namespace osu.Game.Beatmaps BeatmapMetadata metadata; - using (var stream = new StreamReader(reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu"))))) + using (var stream = new StreamReader(reader.GetStream(mapName))) metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; beatmapSet = new BeatmapSetInfo From e42c279229cd64e43985ebfbdba6ef5256ab137f Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Thu, 10 Aug 2017 01:50:20 -0500 Subject: [PATCH 17/83] More generic catching for broken hitobject strings --- .../Objects/Legacy/ConvertHitObjectParser.cs | 237 +++++++++--------- 1 file changed, 121 insertions(+), 116 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index b02a582bec..b5e3f837fc 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -19,150 +19,155 @@ namespace osu.Game.Rulesets.Objects.Legacy { public override HitObject Parse(string text) { - string[] split = text.Split(','); - if (split.Length > 11) - throw new InvalidOperationException("One or more hit objects were malformed."); - - ConvertHitObjectType type = (ConvertHitObjectType)int.Parse(split[3]) & ~ConvertHitObjectType.ColourHax; - bool combo = type.HasFlag(ConvertHitObjectType.NewCombo); - type &= ~ConvertHitObjectType.NewCombo; - - var soundType = (LegacySoundType)int.Parse(split[4]); - var bankInfo = new SampleBankInfo(); - - HitObject result = null; - - if ((type & ConvertHitObjectType.Circle) > 0) + try { - result = CreateHit(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo); + string[] split = text.Split(','); - if (split.Length > 5) - readCustomSampleBanks(split[5], bankInfo); - } - else if ((type & ConvertHitObjectType.Slider) > 0) - { - CurveType curveType = CurveType.Catmull; - double length = 0; - var points = new List { new Vector2(int.Parse(split[0]), int.Parse(split[1])) }; + ConvertHitObjectType type = (ConvertHitObjectType)int.Parse(split[3]) & ~ConvertHitObjectType.ColourHax; + bool combo = type.HasFlag(ConvertHitObjectType.NewCombo); + type &= ~ConvertHitObjectType.NewCombo; - string[] pointsplit = split[5].Split('|'); - foreach (string t in pointsplit) + var soundType = (LegacySoundType)int.Parse(split[4]); + var bankInfo = new SampleBankInfo(); + + HitObject result = null; + + if ((type & ConvertHitObjectType.Circle) > 0) { - if (t.Length == 1) + result = CreateHit(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo); + + if (split.Length > 5) + readCustomSampleBanks(split[5], bankInfo); + } + else if ((type & ConvertHitObjectType.Slider) > 0) + { + CurveType curveType = CurveType.Catmull; + double length = 0; + var points = new List { new Vector2(int.Parse(split[0]), int.Parse(split[1])) }; + + string[] pointsplit = split[5].Split('|'); + foreach (string t in pointsplit) { - switch (t) + if (t.Length == 1) { - case @"C": - curveType = CurveType.Catmull; - break; - case @"B": - curveType = CurveType.Bezier; - break; - case @"L": - curveType = CurveType.Linear; - break; - case @"P": - curveType = CurveType.PerfectCurve; - break; + switch (t) + { + case @"C": + curveType = CurveType.Catmull; + break; + case @"B": + curveType = CurveType.Bezier; + break; + case @"L": + curveType = CurveType.Linear; + break; + case @"P": + curveType = CurveType.PerfectCurve; + break; + } + continue; } - continue; + + string[] temp = t.Split(':'); + points.Add(new Vector2((int)Convert.ToDouble(temp[0], CultureInfo.InvariantCulture), (int)Convert.ToDouble(temp[1], CultureInfo.InvariantCulture))); } - string[] temp = t.Split(':'); - points.Add(new Vector2((int)Convert.ToDouble(temp[0], CultureInfo.InvariantCulture), (int)Convert.ToDouble(temp[1], CultureInfo.InvariantCulture))); - } + int repeatCount = Convert.ToInt32(split[6], CultureInfo.InvariantCulture); - int repeatCount = Convert.ToInt32(split[6], CultureInfo.InvariantCulture); + if (repeatCount > 9000) + throw new ArgumentOutOfRangeException(nameof(repeatCount), @"Repeat count is way too high"); - if (repeatCount > 9000) - throw new ArgumentOutOfRangeException(nameof(repeatCount), @"Repeat count is way too high"); + if (split.Length > 7) + length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); - if (split.Length > 7) - length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); + if (split.Length > 10) + readCustomSampleBanks(split[10], bankInfo); - if (split.Length > 10) - readCustomSampleBanks(split[10], bankInfo); + // One node for each repeat + the start and end nodes + // Note that the first length of the slider is considered a repeat, but there are no actual repeats happening + int nodes = Math.Max(0, repeatCount - 1) + 2; - // One node for each repeat + the start and end nodes - // Note that the first length of the slider is considered a repeat, but there are no actual repeats happening - int nodes = Math.Max(0, repeatCount - 1) + 2; - - // Populate node sample bank infos with the default hit object sample bank - var nodeBankInfos = new List(); - for (int i = 0; i < nodes; i++) - nodeBankInfos.Add(bankInfo.Clone()); - - // Read any per-node sample banks - if (split.Length > 9 && split[9].Length > 0) - { - string[] sets = split[9].Split('|'); + // Populate node sample bank infos with the default hit object sample bank + var nodeBankInfos = new List(); for (int i = 0; i < nodes; i++) + nodeBankInfos.Add(bankInfo.Clone()); + + // Read any per-node sample banks + if (split.Length > 9 && split[9].Length > 0) { - if (i >= sets.Length) - break; + string[] sets = split[9].Split('|'); + for (int i = 0; i < nodes; i++) + { + if (i >= sets.Length) + break; - SampleBankInfo info = nodeBankInfos[i]; - readCustomSampleBanks(sets[i], info); + SampleBankInfo info = nodeBankInfos[i]; + readCustomSampleBanks(sets[i], info); + } } - } - // Populate node sound types with the default hit object sound type - var nodeSoundTypes = new List(); - for (int i = 0; i < nodes; i++) - nodeSoundTypes.Add(soundType); - - // Read any per-node sound types - if (split.Length > 8 && split[8].Length > 0) - { - string[] adds = split[8].Split('|'); + // Populate node sound types with the default hit object sound type + var nodeSoundTypes = new List(); for (int i = 0; i < nodes; i++) + nodeSoundTypes.Add(soundType); + + // Read any per-node sound types + if (split.Length > 8 && split[8].Length > 0) { - if (i >= adds.Length) - break; + string[] adds = split[8].Split('|'); + for (int i = 0; i < nodes; i++) + { + if (i >= adds.Length) + break; - int sound; - int.TryParse(adds[i], out sound); - nodeSoundTypes[i] = (LegacySoundType)sound; + int sound; + int.TryParse(adds[i], out sound); + nodeSoundTypes[i] = (LegacySoundType)sound; + } } + + // Generate the final per-node samples + var nodeSamples = new List(nodes); + for (int i = 0; i <= repeatCount; i++) + nodeSamples.Add(convertSoundType(nodeSoundTypes[i], nodeBankInfos[i])); + + result = CreateSlider(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, points, length, curveType, repeatCount, nodeSamples); } - - // Generate the final per-node samples - var nodeSamples = new List(nodes); - for (int i = 0; i <= repeatCount; i++) - nodeSamples.Add(convertSoundType(nodeSoundTypes[i], nodeBankInfos[i])); - - result = CreateSlider(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, points, length, curveType, repeatCount, nodeSamples); - } - else if ((type & ConvertHitObjectType.Spinner) > 0) - { - result = CreateSpinner(new Vector2(512, 384) / 2, Convert.ToDouble(split[5], CultureInfo.InvariantCulture)); - - if (split.Length > 6) - readCustomSampleBanks(split[6], bankInfo); - } - else if ((type & ConvertHitObjectType.Hold) > 0) - { - // Note: Hold is generated by BMS converts - - double endTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); - - if (split.Length > 5 && !string.IsNullOrEmpty(split[5])) + else if ((type & ConvertHitObjectType.Spinner) > 0) { - string[] ss = split[5].Split(':'); - endTime = Convert.ToDouble(ss[0], CultureInfo.InvariantCulture); - readCustomSampleBanks(string.Join(":", ss.Skip(1)), bankInfo); + result = CreateSpinner(new Vector2(512, 384) / 2, Convert.ToDouble(split[5], CultureInfo.InvariantCulture)); + + if (split.Length > 6) + readCustomSampleBanks(split[6], bankInfo); + } + else if ((type & ConvertHitObjectType.Hold) > 0) + { + // Note: Hold is generated by BMS converts + + double endTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); + + if (split.Length > 5 && !string.IsNullOrEmpty(split[5])) + { + string[] ss = split[5].Split(':'); + endTime = Convert.ToDouble(ss[0], CultureInfo.InvariantCulture); + readCustomSampleBanks(string.Join(":", ss.Skip(1)), bankInfo); + } + + result = CreateHold(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, endTime); } - result = CreateHold(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, endTime); + if (result == null) + throw new InvalidOperationException($@"Unknown hit object type {type}."); + + result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); + result.Samples = convertSoundType(soundType, bankInfo); + + return result; + } + catch (FormatException) + { + throw new FormatException("One or more hit objects were malformed."); } - - if (result == null) - throw new InvalidOperationException($@"Unknown hit object type {type}."); - - result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); - result.Samples = convertSoundType(soundType, bankInfo); - - return result; } private void readCustomSampleBanks(string str, SampleBankInfo bankInfo) From e48c5898bd8f59f98e95b92f28cd9a699ce56370 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 11 Aug 2017 17:26:30 +0930 Subject: [PATCH 18/83] Ensure the Track for the selected beatmap is added to the TrackManager. Fixes the problem where a beatmap would be stuck at 100% if it is replayed. --- osu.Game/Screens/Select/SongSelect.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 8f545240c8..f8423a90ed 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -372,6 +372,7 @@ namespace osu.Game.Screens.Select if (!track.IsRunning) { + Game.Audio.Track.AddItemToList(track); if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); track.Start(); } From 096e5744012fad381b3fbfa3d7b1fc9e64317765 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Sat, 12 Aug 2017 19:52:09 +0930 Subject: [PATCH 19/83] Selecting a beatmap set no longer updates the ruleset to the first map of that set (since it causes the carousel to refilter) --- osu.Game/Screens/Select/SongSelect.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 8f545240c8..6414365853 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -253,8 +253,6 @@ namespace osu.Game.Screens.Select } else { - Ruleset.Value = beatmap.Ruleset; - if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID) sampleChangeDifficulty.Play(); else From d19c8f56be69c913c95b72334b6cea5e9e7e71bf Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Sun, 13 Aug 2017 15:03:01 +0930 Subject: [PATCH 20/83] Make RulesetInfo implement IEquatable since EqualityComparer was sometimes giving false negatives and causing Bindable observers to fire --- osu.Game/Rulesets/RulesetInfo.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index bc23649ede..059f93645f 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -6,7 +6,7 @@ using SQLite.Net.Attributes; namespace osu.Game.Rulesets { - public class RulesetInfo + public class RulesetInfo : IEquatable { [PrimaryKey, AutoIncrement] public int? ID { get; set; } @@ -21,5 +21,10 @@ namespace osu.Game.Rulesets public bool Available { get; set; } public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this); + + public bool Equals(RulesetInfo other) + { + return this.ID == other.ID && this.Available == other.Available && this.Name == other.Name && this.InstantiationInfo == other.InstantiationInfo; + } } } \ No newline at end of file From e216bfcf105edf58e54369821722ab1b77c22c43 Mon Sep 17 00:00:00 2001 From: MillhioreF Date: Sun, 13 Aug 2017 00:40:05 -0500 Subject: [PATCH 21/83] Recommended fixes (obsolete try/catch, fix infinite loop during variable parsing in a better way) --- osu.Game/Beatmaps/BeatmapManager.cs | 10 ++-------- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 4 +++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 4b063adde0..e388f5b6d1 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -307,16 +307,10 @@ namespace osu.Game.Beatmaps /// The imported beatmap, or an existing instance if it is already present. private BeatmapSetInfo importToStorage(ArchiveReader reader) { - string mapName; // let's make sure there are actually .osu files to import. - try - { - mapName = reader.Filenames.First(f => f.EndsWith(".osu")); - } - catch - { + string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu")); + if (string.IsNullOrEmpty(mapName)) throw new InvalidOperationException("No beatmap files found in the map folder."); - } // for now, concatenate all .osu files in the set to create a unique hash. MemoryStream hashable = new MemoryStream(); diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 39f0a0378c..46cbad2487 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -222,8 +222,9 @@ namespace osu.Game.Beatmaps.Formats /// The line which may contains variables. private void decodeVariables(ref string line) { - if (line.IndexOf('$') >= 0) + while (line.IndexOf('$') >= 0) { + string origLine = line; string[] split = line.Split(','); for (int i = 0; i < split.Length; i++) { @@ -233,6 +234,7 @@ namespace osu.Game.Beatmaps.Formats } line = string.Join(",", split); + if (line == origLine) break; } } From 9e1ffa27dc1a5db38344a11159cdcdb8aab89583 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 12:51:52 +0900 Subject: [PATCH 22/83] Fix leaderboard icons not displaying correctly --- osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index ac3b0b5c3b..d7c85fff90 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -373,6 +373,7 @@ namespace osu.Game.Screens.Select.Leaderboards Icon = FontAwesome.fa_square, Colour = OsuColour.FromHex(@"3087ac"), Rotation = 45, + Size = new Vector2(20), Shadow = true, }, new SpriteIcon @@ -380,7 +381,7 @@ namespace osu.Game.Screens.Select.Leaderboards Origin = Anchor.Centre, Icon = icon, Colour = OsuColour.FromHex(@"a4edff"), - Scale = new Vector2(0.8f), + Size = new Vector2(14), }, new GlowingSpriteText(value, @"Exo2.0-Bold", 17, Color4.White, OsuColour.FromHex(@"83ccfa")) { From 66fa84a451e0b3afdbfd95fc0e1d87448cefe6be Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 10 Aug 2017 22:21:22 +0900 Subject: [PATCH 23/83] Make settings more modular --- .../Visual/TestCaseKeyConfiguration.cs | 44 +++++++++++++++++++ osu.Desktop.Tests/Visual/TestCaseSettings.cs | 2 +- osu.Desktop.Tests/osu.Desktop.Tests.csproj | 1 + osu.Game/OsuGame.cs | 2 +- osu.Game/Overlays/MainSettings.cs | 29 ++++++++++++ osu.Game/Overlays/Settings/SettingsHeader.cs | 13 +++++- osu.Game/Overlays/SettingsOverlay.cs | 30 ++++++------- osu.Game/osu.Game.csproj | 1 + 8 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs create mode 100644 osu.Game/Overlays/MainSettings.cs diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs new file mode 100644 index 0000000000..10a15d0a96 --- /dev/null +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Overlays; +using osu.Game.Overlays.Settings; +using System.Collections.Generic; +using osu.Game.Graphics; + +namespace osu.Desktop.Tests.Visual +{ + public class TestCaseKeyConfiguration : OsuTestCase + { + private readonly KeyConfiguration configuration; + + public override string Description => @"Key configuration"; + + public TestCaseKeyConfiguration() + { + Child = configuration = new KeyConfiguration(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + configuration.Show(); + } + } + + public class KeyConfiguration : SettingsOverlay + { + protected override IEnumerable CreateSections() => new[] + { + new BindingsSection(), + new BindingsSection() + }; + } + + public class BindingsSection : SettingsSection + { + public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; + public override string Header => "Header"; + } +} diff --git a/osu.Desktop.Tests/Visual/TestCaseSettings.cs b/osu.Desktop.Tests/Visual/TestCaseSettings.cs index 7b35009aef..1f4b88e9e3 100644 --- a/osu.Desktop.Tests/Visual/TestCaseSettings.cs +++ b/osu.Desktop.Tests/Visual/TestCaseSettings.cs @@ -13,7 +13,7 @@ namespace osu.Desktop.Tests.Visual public TestCaseSettings() { - Children = new[] { settings = new SettingsOverlay() }; + Children = new[] { settings = new MainSettings() }; } protected override void LoadComplete() diff --git a/osu.Desktop.Tests/osu.Desktop.Tests.csproj b/osu.Desktop.Tests/osu.Desktop.Tests.csproj index 3111088ff6..24d112a45c 100644 --- a/osu.Desktop.Tests/osu.Desktop.Tests.csproj +++ b/osu.Desktop.Tests/osu.Desktop.Tests.csproj @@ -81,6 +81,7 @@ + diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index f54fba4a0b..0d1e8396e4 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -182,7 +182,7 @@ namespace osu.Game LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); - LoadComponentAsync(settings = new SettingsOverlay { Depth = -1 }, overlayContent.Add); + LoadComponentAsync(settings = new MainSettings { Depth = -1 }, overlayContent.Add); LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add); LoadComponentAsync(musicController = new MusicController { diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs new file mode 100644 index 0000000000..86a1262a11 --- /dev/null +++ b/osu.Game/Overlays/MainSettings.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Game.Overlays.Settings; +using osu.Game.Overlays.Settings.Sections; + +namespace osu.Game.Overlays +{ + public class MainSettings : SettingsOverlay + { + protected override IEnumerable CreateSections() => new SettingsSection[] + { + new GeneralSection(), + new GraphicsSection(), + new GameplaySection(), + new AudioSection(), + new SkinSection(), + new InputSection(), + new OnlineSection(), + new MaintenanceSection(), + new DebugSection(), + }; + + protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves"); + protected override Drawable CreateFooter() => new SettingsFooter(); + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Settings/SettingsHeader.cs b/osu.Game/Overlays/Settings/SettingsHeader.cs index c554b54a87..80d60b6e5d 100644 --- a/osu.Game/Overlays/Settings/SettingsHeader.cs +++ b/osu.Game/Overlays/Settings/SettingsHeader.cs @@ -11,6 +11,15 @@ namespace osu.Game.Overlays.Settings { public class SettingsHeader : Container { + private readonly string heading; + private readonly string subheading; + + public SettingsHeader(string heading, string subheading) + { + this.heading = heading; + this.subheading = subheading; + } + [BackgroundDependencyLoader] private void load(OsuColour colours) { @@ -28,7 +37,7 @@ namespace osu.Game.Overlays.Settings { new OsuSpriteText { - Text = "settings", + Text = heading, TextSize = 40, Margin = new MarginPadding { @@ -39,7 +48,7 @@ namespace osu.Game.Overlays.Settings new OsuSpriteText { Colour = colours.Pink, - Text = "Change the way osu! behaves", + Text = subheading, TextSize = 18, Margin = new MarginPadding { diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index 1dcabbfa15..c4971fd4ac 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using System.Linq; using OpenTK.Graphics; using osu.Framework.Allocation; @@ -12,11 +13,10 @@ using osu.Framework.Input; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Settings; -using osu.Game.Overlays.Settings.Sections; namespace osu.Game.Overlays { - public class SettingsOverlay : OsuFocusedOverlayContainer + public abstract class SettingsOverlay : OsuFocusedOverlayContainer { internal const float CONTENT_MARGINS = 10; @@ -38,27 +38,19 @@ namespace osu.Game.Overlays private Func getToolbarHeight; - public SettingsOverlay() + protected SettingsOverlay() { RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; } + protected abstract IEnumerable CreateSections(); + [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game) { - var sections = new SettingsSection[] - { - new GeneralSection(), - new GraphicsSection(), - new GameplaySection(), - new AudioSection(), - new SkinSection(), - new InputSection(), - new OnlineSection(), - new MaintenanceSection(), - new DebugSection(), - }; + var sections = CreateSections().ToList(); + Children = new Drawable[] { new Box @@ -72,7 +64,7 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = SIDEBAR_WIDTH }, - ExpandableHeader = new SettingsHeader(), + ExpandableHeader = CreateHeader(), FixedHeader = searchTextBox = new SearchTextBox { RelativeSizeAxes = Axes.X, @@ -87,7 +79,7 @@ namespace osu.Game.Overlays Exit = Hide, }, Children = sections, - Footer = new SettingsFooter() + Footer = CreateFooter() }, sidebar = new Sidebar { @@ -121,6 +113,10 @@ namespace osu.Game.Overlays getToolbarHeight = () => game?.ToolbarOffset ?? 0; } + protected virtual Drawable CreateHeader() => new Container(); + + protected virtual Drawable CreateFooter() => new Container(); + protected override void PopIn() { base.PopIn(); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 7690a56378..13c4938850 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -102,6 +102,7 @@ + From dccefe1c0e1c926bdf424a8b2eef5ebe62813250 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 14:40:48 +0900 Subject: [PATCH 24/83] Make the settings sidebar optional Also removes an unnecessary secondary list of SidebarButtons by using generic containers. --- osu.Game/Overlays/MainSettings.cs | 4 + osu.Game/Overlays/Settings/SettingsSection.cs | 52 ++++++------ osu.Game/Overlays/Settings/Sidebar.cs | 8 +- osu.Game/Overlays/SettingsOverlay.cs | 79 +++++++++++-------- 4 files changed, 81 insertions(+), 62 deletions(-) diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index 86a1262a11..44c4d4ccdb 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -25,5 +25,9 @@ namespace osu.Game.Overlays protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves"); protected override Drawable CreateFooter() => new SettingsFooter(); + + public MainSettings() : base(true) + { + } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Settings/SettingsSection.cs b/osu.Game/Overlays/Settings/SettingsSection.cs index 68ebde6b28..f091192d27 100644 --- a/osu.Game/Overlays/Settings/SettingsSection.cs +++ b/osu.Game/Overlays/Settings/SettingsSection.cs @@ -7,7 +7,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using System.Collections.Generic; @@ -25,25 +24,38 @@ namespace osu.Game.Overlays.Settings public IEnumerable FilterableChildren => Children.OfType(); public string[] FilterTerms => new[] { Header }; + + private const int header_size = 26; + private const int header_margin = 25; + private const int border_size = 2; + public bool MatchingFilter { - set - { - this.FadeTo(value ? 1 : 0); - } + set { this.FadeTo(value ? 1 : 0); } } - private readonly SpriteText headerLabel; - protected SettingsSection() { Margin = new MarginPadding { Top = 20 }; AutoSizeAxes = Axes.Y; RelativeSizeAxes = Axes.X; - const int header_size = 26; - const int header_margin = 25; - const int border_size = 2; + FlowContent = new FillFlowContainer + { + Margin = new MarginPadding + { + Top = header_size + header_margin + }, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 30), + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { AddRangeInternal(new Drawable[] { new Box @@ -65,28 +77,16 @@ namespace osu.Game.Overlays.Settings AutoSizeAxes = Axes.Y, Children = new[] { - headerLabel = new OsuSpriteText + new OsuSpriteText { TextSize = header_size, Text = Header, + Colour = colours.Yellow }, - FlowContent = new FillFlowContainer - { - Margin = new MarginPadding { Top = header_size + header_margin }, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 30), - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - }, + FlowContent } }, }); } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - headerLabel.Colour = colours.Yellow; - } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Settings/Sidebar.cs b/osu.Game/Overlays/Settings/Sidebar.cs index 6eafc65d12..706e7ecc25 100644 --- a/osu.Game/Overlays/Settings/Sidebar.cs +++ b/osu.Game/Overlays/Settings/Sidebar.cs @@ -14,12 +14,12 @@ using osu.Game.Overlays.Toolbar; namespace osu.Game.Overlays.Settings { - public class Sidebar : Container, IStateful + public class Sidebar : Container, IStateful { - private readonly FillFlowContainer content; + private readonly FillFlowContainer content; internal const float DEFAULT_WIDTH = ToolbarButton.WIDTH; internal const int EXPANDED_WIDTH = 200; - protected override Container Content => content; + protected override Container Content => content; public Sidebar() { @@ -35,7 +35,7 @@ namespace osu.Game.Overlays.Settings { Children = new[] { - content = new FillFlowContainer + content = new FillFlowContainer { Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index c4971fd4ac..dfbcedd479 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using OpenTK.Graphics; using osu.Framework.Allocation; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -29,7 +30,6 @@ namespace osu.Game.Overlays private const float sidebar_padding = 10; private Sidebar sidebar; - private SidebarButton[] sidebarButtons; private SidebarButton selectedSidebarButton; private SettingsSectionsContainer sectionsContainer; @@ -38,19 +38,20 @@ namespace osu.Game.Overlays private Func getToolbarHeight; - protected SettingsOverlay() + private readonly bool showSidebar; + + protected SettingsOverlay(bool showSidebar) { + this.showSidebar = showSidebar; RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; } - protected abstract IEnumerable CreateSections(); + protected virtual IEnumerable CreateSections() => null; [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game) { - var sections = CreateSections().ToList(); - Children = new Drawable[] { new Box @@ -78,39 +79,53 @@ namespace osu.Game.Overlays }, Exit = Hide, }, - Children = sections, Footer = CreateFooter() - }, - sidebar = new Sidebar - { - Width = SIDEBAR_WIDTH, - Children = sidebarButtons = sections.Select(section => - new SidebarButton - { - Section = section, - Action = s => - { - sectionsContainer.ScrollTo(s); - sidebar.State = ExpandedState.Contracted; - }, - } - ).ToArray() } }; - selectedSidebarButton = sidebarButtons[0]; - selectedSidebarButton.Selected = true; - - sectionsContainer.SelectedSection.ValueChanged += section => + if (showSidebar) { - selectedSidebarButton.Selected = false; - selectedSidebarButton = sidebarButtons.Single(b => b.Section == section); - selectedSidebarButton.Selected = true; - }; + Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); + + sectionsContainer.SelectedSection.ValueChanged += section => + { + selectedSidebarButton.Selected = false; + selectedSidebarButton = sidebar.Children.Single(b => b.Section == section); + selectedSidebarButton.Selected = true; + }; + } searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue; getToolbarHeight = () => game?.ToolbarOffset ?? 0; + + CreateSections()?.ForEach(AddSection); + } + + protected void AddSection(SettingsSection section) + { + sectionsContainer.Add(section); + + if (sidebar != null) + { + var button = new SidebarButton + { + Section = section, + Action = s => + { + sectionsContainer.ScrollTo(s); + sidebar.State = ExpandedState.Contracted; + }, + }; + + sidebar.Add(button); + + if (selectedSidebarButton == null) + { + selectedSidebarButton = sidebar.Children.First(); + selectedSidebarButton.Selected = true; + } + } } protected virtual Drawable CreateHeader() => new Container(); @@ -122,7 +137,7 @@ namespace osu.Game.Overlays base.PopIn(); sectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); - sidebar.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); + sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(1, TRANSITION_LENGTH / 2); searchTextBox.HoldFocus = true; @@ -133,7 +148,7 @@ namespace osu.Game.Overlays base.PopOut(); sectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); - sidebar.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); + sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(0, TRANSITION_LENGTH / 2); searchTextBox.HoldFocus = false; @@ -155,7 +170,7 @@ namespace osu.Game.Overlays { base.UpdateAfterChildren(); - sectionsContainer.Margin = new MarginPadding { Left = sidebar.DrawWidth }; + sectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; } From 7c9d6c9c83a4f070d205527cc5d0bb852a030862 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 20:19:25 +0900 Subject: [PATCH 25/83] Initial refactoring of key binding logic --- osu.Game.Rulesets.Catch/CatchInputManager.cs | 12 ---------- osu.Game.Rulesets.Catch/CatchRuleset.cs | 11 ++++++++++ .../UI/CatchRulesetContainer.cs | 2 +- osu.Game.Rulesets.Osu/OsuInputManager.cs | 12 +++------- osu.Game.Rulesets.Osu/OsuRuleset.cs | 11 +++++++++- .../UI/OsuRulesetContainer.cs | 2 +- .../Input/Bindings/DatabasedKeyBinding.cs | 2 +- .../DatabasedKeyBindingInputManager.cs | 22 +++++++------------ .../Bindings/GlobalBindingInputManager.cs | 2 +- .../{BindingStore.cs => KeyBindingStore.cs} | 19 +++++++++++++--- osu.Game/OsuGameBase.cs | 10 ++++++--- osu.Game/Rulesets/Ruleset.cs | 13 +++++++++++ osu.Game/Rulesets/UI/RulesetContainer.cs | 4 ++-- osu.Game/osu.Game.csproj | 2 +- 14 files changed, 75 insertions(+), 49 deletions(-) rename osu.Game/Input/{BindingStore.cs => KeyBindingStore.cs} (61%) diff --git a/osu.Game.Rulesets.Catch/CatchInputManager.cs b/osu.Game.Rulesets.Catch/CatchInputManager.cs index 446f9b2787..683724b7b8 100644 --- a/osu.Game.Rulesets.Catch/CatchInputManager.cs +++ b/osu.Game.Rulesets.Catch/CatchInputManager.cs @@ -1,11 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using System.ComponentModel; using osu.Framework.Input.Bindings; using osu.Game.Input.Bindings; -using OpenTK.Input; namespace osu.Game.Rulesets.Catch { @@ -15,16 +13,6 @@ namespace osu.Game.Rulesets.Catch : base(ruleset, simultaneousMode: SimultaneousBindingMode.Unique) { } - - protected override IEnumerable CreateDefaultMappings() => new[] - { - new KeyBinding(Key.Z, CatchAction.MoveLeft), - new KeyBinding(Key.Left, CatchAction.MoveLeft), - new KeyBinding(Key.X, CatchAction.MoveRight), - new KeyBinding(Key.Right, CatchAction.MoveRight), - new KeyBinding(Key.LShift, CatchAction.Dash), - new KeyBinding(Key.RShift, CatchAction.Dash), - }; } public enum CatchAction diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8d45ea8fa2..b486566b7d 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; using osu.Game.Rulesets.Catch.Scoring; using osu.Game.Rulesets.Scoring; +using osu.Framework.Input.Bindings; namespace osu.Game.Rulesets.Catch { @@ -20,6 +21,16 @@ namespace osu.Game.Rulesets.Catch { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset); + public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] + { + new KeyBinding(Key.Z, CatchAction.MoveLeft), + new KeyBinding(Key.Left, CatchAction.MoveLeft), + new KeyBinding(Key.X, CatchAction.MoveRight), + new KeyBinding(Key.Right, CatchAction.MoveRight), + new KeyBinding(Key.LShift, CatchAction.Dash), + new KeyBinding(Key.RShift, CatchAction.Dash), + }; + public override IEnumerable GetModsFor(ModType type) { switch (type) diff --git a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs index 8469be24dd..1d037deaef 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs @@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.UI protected override Playfield CreatePlayfield() => new CatchPlayfield(); - protected override PassThroughInputManager CreateActionMappingInputManager() => new CatchInputManager(Ruleset?.RulesetInfo); + public override PassThroughInputManager CreateKeyBindingInputManager() => new CatchInputManager(Ruleset?.RulesetInfo); protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) { diff --git a/osu.Game.Rulesets.Osu/OsuInputManager.cs b/osu.Game.Rulesets.Osu/OsuInputManager.cs index c1ee19d8c5..06836994d2 100644 --- a/osu.Game.Rulesets.Osu/OsuInputManager.cs +++ b/osu.Game.Rulesets.Osu/OsuInputManager.cs @@ -1,7 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using osu.Framework.Input; using osu.Framework.Input.Bindings; @@ -33,19 +33,13 @@ namespace osu.Game.Rulesets.Osu keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 2 }); } } - - protected override IEnumerable CreateDefaultMappings() => new[] - { - new KeyBinding(Key.Z, OsuAction.LeftButton), - new KeyBinding(Key.X, OsuAction.RightButton), - new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton), - new KeyBinding(Key.LastKey + 2, OsuAction.RightButton), - }; } public enum OsuAction { + [Description("Left Button")] LeftButton, + [Description("Right Button")] RightButton } } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 212c634aaf..75b7be01a4 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -17,6 +17,7 @@ using osu.Framework.Graphics; using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Scoring; using osu.Game.Overlays.Settings; +using osu.Framework.Input.Bindings; namespace osu.Game.Rulesets.Osu { @@ -24,8 +25,16 @@ namespace osu.Game.Rulesets.Osu { public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset); - public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] + public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] { + new KeyBinding(Key.Z, OsuAction.LeftButton), + new KeyBinding(Key.X, OsuAction.RightButton), + new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton), + new KeyBinding(Key.LastKey + 2, OsuAction.RightButton), + }; + + public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] + { new BeatmapStatistic { Name = @"Circle count", diff --git a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs index 538b94603c..917322de44 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI protected override Playfield CreatePlayfield() => new OsuPlayfield(); - protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo); + public override PassThroughInputManager CreateKeyBindingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo); protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { diff --git a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs index 278033899c..3870cc5b04 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs @@ -27,7 +27,7 @@ namespace osu.Game.Input.Bindings [Column("Action")] public new int Action { - get { return base.Action; } + get { return (int)base.Action; } private set { base.Action = value; } } } diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index 5c62f1ddc8..52e5af152c 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Input.Bindings; using osu.Game.Rulesets; @@ -18,7 +19,9 @@ namespace osu.Game.Input.Bindings private readonly int? variant; - private BindingStore store; + private KeyBindingStore store; + + public override IEnumerable DefaultMappings => ruleset.CreateInstance().GetDefaultKeyBindings(); /// /// Create a new instance. @@ -34,24 +37,15 @@ namespace osu.Game.Input.Bindings } [BackgroundDependencyLoader] - private void load(BindingStore bindings) + private void load(KeyBindingStore keyBindings) { - store = bindings; + store = keyBindings; } protected override void ReloadMappings() { - // load defaults - base.ReloadMappings(); - - var rulesetId = ruleset?.ID; - - // load from database if present. - if (store != null) - { - foreach (var b in store.Query(b => b.RulesetID == rulesetId && b.Variant == variant)) - KeyBindings.Add(b); - } + KeyBindings.Clear(); + KeyBindings.AddRange(store.GetProcessedList(DefaultMappings, ruleset?.ID, variant)); } } } \ No newline at end of file diff --git a/osu.Game/Input/Bindings/GlobalBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalBindingInputManager.cs index 60a4faa8cd..d00ed588ae 100644 --- a/osu.Game/Input/Bindings/GlobalBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalBindingInputManager.cs @@ -21,7 +21,7 @@ namespace osu.Game.Input.Bindings handler = game; } - protected override IEnumerable CreateDefaultMappings() => new[] + public override IEnumerable DefaultMappings => new[] { new KeyBinding(Key.F8, GlobalAction.ToggleChat), new KeyBinding(Key.F9, GlobalAction.ToggleSocial), diff --git a/osu.Game/Input/BindingStore.cs b/osu.Game/Input/KeyBindingStore.cs similarity index 61% rename from osu.Game/Input/BindingStore.cs rename to osu.Game/Input/KeyBindingStore.cs index 25a997e29d..e26942a06c 100644 --- a/osu.Game/Input/BindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -2,6 +2,8 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; +using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Database; using osu.Game.Input.Bindings; @@ -9,9 +11,9 @@ using SQLite.Net; namespace osu.Game.Input { - public class BindingStore : DatabaseBackedStore + public class KeyBindingStore : DatabaseBackedStore { - public BindingStore(SQLiteConnection connection, Storage storage = null) + public KeyBindingStore(SQLiteConnection connection, Storage storage = null) : base(connection, storage) { } @@ -44,5 +46,16 @@ namespace osu.Game.Input typeof(DatabasedKeyBinding) }; + public List GetProcessedList(IEnumerable defaults, int? rulesetId, int? variant) + { + //todo: cache and share reference + List bindings = new List(defaults); + + // load from database if present. + foreach (var b in Query(b => b.RulesetID == rulesetId && b.Variant == variant)) + bindings.Add(b); + + return bindings; + } } -} \ No newline at end of file +} diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 344b23cca4..d72716b5d6 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -39,7 +39,7 @@ namespace osu.Game protected ScoreStore ScoreStore; - protected BindingStore BindingStore; + protected KeyBindingStore KeyBindingStore; protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -108,7 +108,7 @@ namespace osu.Game dependencies.Cache(FileStore = new FileStore(connection, Host.Storage)); dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager)); - dependencies.Cache(BindingStore = new BindingStore(connection)); + dependencies.Cache(KeyBindingStore = new KeyBindingStore(connection)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. @@ -183,12 +183,14 @@ namespace osu.Game { base.LoadComplete(); + GlobalBindingInputManager globalBinding; + base.Content.Add(new RatioAdjust { Children = new Drawable[] { Cursor = new MenuCursor(), - new GlobalBindingInputManager(this) + globalBinding = new GlobalBindingInputManager(this) { RelativeSizeAxes = Axes.Both, Child = new OsuTooltipContainer(Cursor) @@ -200,6 +202,8 @@ namespace osu.Game } }); + dependencies.Cache(globalBinding); + // TODO: This is temporary until we reimplement the local FPS display. // It's just to allow end-users to access the framework FPS display without knowing the shortcut key. fpsDisplayVisible = LocalConfig.GetBindable(OsuSetting.ShowFpsDisplay); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index ba040403ba..e5fa7117f3 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -8,6 +8,7 @@ using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; using System.Collections.Generic; using osu.Framework.Graphics; +using osu.Framework.Input.Bindings; using osu.Game.Rulesets.Scoring; using osu.Game.Overlays.Settings; @@ -53,5 +54,17 @@ namespace osu.Game.Rulesets /// Do not override this unless you are a legacy mode. /// public virtual int LegacyID => -1; + + /// + /// A list of available variant ids. + /// + public virtual IEnumerable AvailableVariants => new[] { 0 }; + + /// + /// Get a list of default keys for the specified variant. + /// + /// A variant. + /// A list of valid s. + public virtual IEnumerable GetDefaultKeyBindings(int variant = 0) => new KeyBinding[] { }; } } diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 387fa15191..8512d4b5e1 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -76,7 +76,7 @@ namespace osu.Game.Rulesets.UI internal RulesetContainer(Ruleset ruleset) { Ruleset = ruleset; - KeyConversionInputManager = CreateActionMappingInputManager(); + KeyConversionInputManager = CreateKeyBindingInputManager(); KeyConversionInputManager.RelativeSizeAxes = Axes.Both; } @@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.UI /// Creates a key conversion input manager. /// /// The input manager. - protected virtual PassThroughInputManager CreateActionMappingInputManager() => new PassThroughInputManager(); + public virtual PassThroughInputManager CreateKeyBindingInputManager() => new PassThroughInputManager(); protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 13c4938850..b324fb9f92 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -94,7 +94,7 @@ - + From 46bfa4db29da2bb501a98a97c4cd39ba74d1c355 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 22:31:23 +0900 Subject: [PATCH 26/83] Load defaults, pass around live IEnumerable, add PK for updating --- .../Input/Bindings/DatabasedKeyBinding.cs | 5 +- .../DatabasedKeyBindingInputManager.cs | 3 +- osu.Game/Input/KeyBindingStore.cs | 50 +++++++++++++++---- osu.Game/OsuGameBase.cs | 2 +- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs index 3870cc5b04..73896b5ffe 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs @@ -11,6 +11,9 @@ namespace osu.Game.Input.Bindings [Table("KeyBinding")] public class DatabasedKeyBinding : KeyBinding { + [PrimaryKey, AutoIncrement] + public int ID { get; set; } + [ForeignKey(typeof(RulesetInfo))] public int? RulesetID { get; set; } @@ -28,7 +31,7 @@ namespace osu.Game.Input.Bindings public new int Action { get { return (int)base.Action; } - private set { base.Action = value; } + set { base.Action = value; } } } } \ No newline at end of file diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index 52e5af152c..a02dd00a77 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -44,8 +44,7 @@ namespace osu.Game.Input.Bindings protected override void ReloadMappings() { - KeyBindings.Clear(); - KeyBindings.AddRange(store.GetProcessedList(DefaultMappings, ruleset?.ID, variant)); + KeyBindings = store.GetProcessedList(DefaultMappings, ruleset?.ID, variant); } } } \ No newline at end of file diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index e26942a06c..0cd556289f 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -3,22 +3,35 @@ using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Database; using osu.Game.Input.Bindings; +using osu.Game.Rulesets; using SQLite.Net; namespace osu.Game.Input { public class KeyBindingStore : DatabaseBackedStore { - public KeyBindingStore(SQLiteConnection connection, Storage storage = null) + public KeyBindingStore(SQLiteConnection connection, RulesetStore rulesets, Storage storage = null) : base(connection, storage) { + foreach (var info in rulesets.Query()) + { + var ruleset = info.CreateInstance(); + foreach (var variant in ruleset.AvailableVariants) + GetProcessedList(ruleset.GetDefaultKeyBindings(), info.ID, variant); + } } - protected override int StoreVersion => 2; + public void Register(KeyBindingInputManager manager) + { + GetProcessedList(manager.DefaultMappings); + } + + protected override int StoreVersion => 3; protected override void PerformMigration(int currentVersion, int targetVersion) { @@ -29,6 +42,8 @@ namespace osu.Game.Input switch (currentVersion) { case 1: + case 2: + case 3: // cannot migrate; breaking underlying changes. Reset(); break; @@ -38,6 +53,11 @@ namespace osu.Game.Input protected override void Prepare(bool reset = false) { + if (reset) + { + Connection.DropTable(); + } + Connection.CreateTable(); } @@ -46,16 +66,28 @@ namespace osu.Game.Input typeof(DatabasedKeyBinding) }; - public List GetProcessedList(IEnumerable defaults, int? rulesetId, int? variant) + public IEnumerable GetProcessedList(IEnumerable defaults, int? rulesetId = null, int? variant = null) { - //todo: cache and share reference - List bindings = new List(defaults); + var databaseEntries = Query(b => b.RulesetID == rulesetId && b.Variant == variant); - // load from database if present. - foreach (var b in Query(b => b.RulesetID == rulesetId && b.Variant == variant)) - bindings.Add(b); + if (!databaseEntries.Any()) + { + // if there are no entries for this category in the database, we should populate our defaults. + Connection.InsertAll(defaults.Select(k => new DatabasedKeyBinding + { + KeyCombination = k.KeyCombination, + Action = (int)k.Action, + RulesetID = rulesetId, + Variant = variant + })); + } - return bindings; + return databaseEntries; + } + + public void Update(KeyBinding keyBinding) + { + Connection.Update(keyBinding); } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index d72716b5d6..54b091d7d9 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -108,7 +108,7 @@ namespace osu.Game dependencies.Cache(FileStore = new FileStore(connection, Host.Storage)); dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager)); - dependencies.Cache(KeyBindingStore = new KeyBindingStore(connection)); + dependencies.Cache(KeyBindingStore = new KeyBindingStore(connection, RulesetStore)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. From 4da76cd98e8164155a21f7a0ab88954e8a1ffaaa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 22:31:35 +0900 Subject: [PATCH 27/83] Initial key configuration UI implementation --- .../Visual/TestCaseKeyConfiguration.cs | 355 +++++++++++++++++- 1 file changed, 348 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs index 10a15d0a96..077417577a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -1,10 +1,27 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using System.Collections.Generic; +using System.Linq; using osu.Game.Overlays; using osu.Game.Overlays.Settings; -using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Extensions; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Input; +using osu.Game.Rulesets; +using osu.Framework.Input.Bindings; +using osu.Game.Input.Bindings; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Input; +using OpenTK.Input; namespace osu.Desktop.Tests.Visual { @@ -29,16 +46,340 @@ namespace osu.Desktop.Tests.Visual public class KeyConfiguration : SettingsOverlay { - protected override IEnumerable CreateSections() => new[] + protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); + + [BackgroundDependencyLoader(permitNulls: true)] + private void load(RulesetStore rulesets, GlobalBindingInputManager global) { - new BindingsSection(), - new BindingsSection() - }; + AddSection(new GlobalBindingsSection(global, "Global")); + + foreach (var ruleset in rulesets.Query()) + AddSection(new RulesetBindingsSection(ruleset)); + } + + public KeyConfiguration() + : base(false) + { + } } - public class BindingsSection : SettingsSection + public class GlobalBindingsSection : KeyBindingsSection + { + private readonly string name; + + public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; + public override string Header => name; + + public GlobalBindingsSection(KeyBindingInputManager manager, string name) + { + this.name = name; + + Defaults = manager.DefaultMappings; + } + } + + public class RulesetBindingsSection : KeyBindingsSection { public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; - public override string Header => "Header"; + public override string Header => Ruleset.Name; + + public RulesetBindingsSection(RulesetInfo ruleset) + { + Ruleset = ruleset; + + Defaults = ruleset.CreateInstance().GetDefaultKeyBindings(); + } + } + + public abstract class KeyBindingsSection : SettingsSection + { + protected IEnumerable Defaults; + + protected RulesetInfo Ruleset; + + protected KeyBindingsSection() + { + FlowContent.Spacing = new Vector2(0, 1); + } + + [BackgroundDependencyLoader] + private void load(KeyBindingStore store) + { + var firstDefault = Defaults?.FirstOrDefault(); + + if (firstDefault == null) return; + + var actionType = firstDefault.Action.GetType(); + + var bindings = store.GetProcessedList(Defaults, Ruleset?.ID); + + foreach (Enum v in Enum.GetValues(actionType)) + { + Add(new KeyBindingRow(v, bindings.Where(b => (int)b.Action == (int)(object)v))); + } + } + } + + internal class KeyBindingRow : Container, IFilterable + { + private readonly Enum action; + private readonly IEnumerable bindings; + + private const float transition_time = 150; + + private const float height = 20; + + private const float padding = 5; + + private bool matchingFilter; + + public bool MatchingFilter + { + get { return matchingFilter; } + set + { + matchingFilter = value; + this.FadeTo(!matchingFilter ? 0 : 1); + } + } + + private OsuSpriteText text; + private OsuSpriteText pressAKey; + + private FillFlowContainer buttons; + + public string[] FilterTerms => new[] { text.Text }.Concat(bindings.Select(b => b.KeyCombination.ReadableString())).ToArray(); + + public KeyBindingRow(Enum action, IEnumerable bindings) + { + this.action = action; + this.bindings = bindings; + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + Masking = true; + CornerRadius = padding; + } + + private KeyBindingStore store; + + [BackgroundDependencyLoader] + private void load(OsuColour colours, KeyBindingStore store) + { + this.store = store; + + EdgeEffect = new EdgeEffectParameters + { + Radius = 2, + Colour = colours.YellowDark.Opacity(0), + Type = EdgeEffectType.Shadow, + Hollow = true, + }; + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.6f, + }, + text = new OsuSpriteText + { + Text = action.GetDescription(), + Margin = new MarginPadding(padding), + }, + buttons = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }, + pressAKey = new OsuSpriteText + { + Text = "Press a key to change the binding, or ESC to cancel.", + Y = height, + Margin = new MarginPadding(padding), + Alpha = 0, + Colour = colours.YellowDark + } + }; + + reloadBindings(); + } + + private void reloadBindings() + { + buttons.Clear(); + foreach (var b in bindings) + buttons.Add(new KeyButton(b)); + } + + protected override bool OnHover(InputState state) + { + this.FadeEdgeEffectTo(1, transition_time, Easing.OutQuint); + + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + this.FadeEdgeEffectTo(0, transition_time, Easing.OutQuint); + + base.OnHoverLost(state); + } + + public override bool AcceptsFocus => true; + + private KeyButton bindTarget; + + protected override void OnFocus(InputState state) + { + AutoSizeDuration = 500; + AutoSizeEasing = Easing.OutQuint; + + pressAKey.FadeIn(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding(); + + base.OnFocus(state); + } + + private bool isModifier(Key k) => k < Key.F1; + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (HasFocus) + { + if (!isModifier(args.Key)) + { + bindTarget.KeyBinding.KeyCombination = new KeyCombination(state.Keyboard.Keys); + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + } + return true; + } + + return base.OnKeyDown(state, args); + } + + protected override void OnFocusLost(InputState state) + { + bindTarget.IsBinding = false; + bindTarget = null; + reloadBindings(); + + pressAKey.FadeOut(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + base.OnFocusLost(state); + } + + protected override bool OnClick(InputState state) + { + bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); + if (bindTarget != null) bindTarget.IsBinding = true; + + return bindTarget != null; + } + + private class KeyButton : Container + { + public readonly KeyBinding KeyBinding; + + private readonly Box box; + public readonly OsuSpriteText Text; + + private Color4 hoverColour; + + private bool isBinding; + + public bool IsBinding + { + get { return isBinding; } + set + { + isBinding = value; + + if (value) + { + box.FadeColour(Color4.White, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + + } + else + { + box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); + } + } + } + + public KeyButton(KeyBinding keyBinding) + { + KeyBinding = keyBinding; + + Margin = new MarginPadding(padding); + + var isDefault = keyBinding.Action is Enum; + + Masking = true; + CornerRadius = padding; + + Height = height; + AutoSizeAxes = Axes.X; + + Children = new Drawable[] + { + new Container + { + AlwaysPresent = true, + Width = 80, + Height = height, + }, + box = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black + }, + Text = new OsuSpriteText + { + Font = "Venera", + TextSize = 10, + Margin = new MarginPadding(5), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = keyBinding.KeyCombination.ReadableString(), + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + hoverColour = colours.YellowDark; + } + + protected override bool OnHover(InputState state) + { + if (isBinding) + return false; + + box.FadeColour(hoverColour, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + if (isBinding) + return; + + box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); + + base.OnHoverLost(state); + } + } } } From 70f148f0b4ab7cc2eb7fc9a78cd4bb33fce082ed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 09:30:46 +0900 Subject: [PATCH 28/83] Fix icons on skip button --- osu.Game/Screens/Play/SkipButton.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/SkipButton.cs b/osu.Game/Screens/Play/SkipButton.cs index a67cf4e5ea..3cf371f1e1 100644 --- a/osu.Game/Screens/Play/SkipButton.cs +++ b/osu.Game/Screens/Play/SkipButton.cs @@ -227,9 +227,9 @@ namespace osu.Game.Screens.Play Direction = FillDirection.Horizontal, Children = new[] { - new SpriteIcon { Icon = FontAwesome.fa_chevron_right }, - new SpriteIcon { Icon = FontAwesome.fa_chevron_right }, - new SpriteIcon { Icon = FontAwesome.fa_chevron_right }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right }, } }, new OsuSpriteText From 97ac8e1a64b2bacf8697423ad124965ede65dbc6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Aug 2017 11:03:03 +0900 Subject: [PATCH 29/83] Update usages of IsAlive/IsLoaded in line with framework changes --- osu.Desktop.Tests/Visual/TestCaseNotificationOverlay.cs | 2 +- osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs | 2 +- osu.Game/Screens/BackgroundScreen.cs | 2 +- osu.Game/Screens/Play/KeyCounterCollection.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseNotificationOverlay.cs b/osu.Desktop.Tests/Visual/TestCaseNotificationOverlay.cs index b9e492593f..1e46fbda35 100644 --- a/osu.Desktop.Tests/Visual/TestCaseNotificationOverlay.cs +++ b/osu.Desktop.Tests/Visual/TestCaseNotificationOverlay.cs @@ -68,7 +68,7 @@ namespace osu.Desktop.Tests.Visual while (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3) { - var p = progressingNotifications.FirstOrDefault(n => n.IsLoaded && n.State == ProgressNotificationState.Queued); + var p = progressingNotifications.FirstOrDefault(n => n.IsAlive && n.State == ProgressNotificationState.Queued); if (p == null) break; diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs index 8b9441ea65..680f987274 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBody.cs @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces return; accentColour = value; - if (LoadState == LoadState.Loaded) + if (LoadState == LoadState.Ready) Schedule(reloadTexture); } } diff --git a/osu.Game/Screens/BackgroundScreen.cs b/osu.Game/Screens/BackgroundScreen.cs index c5bbf04075..5b07ca6020 100644 --- a/osu.Game/Screens/BackgroundScreen.cs +++ b/osu.Game/Screens/BackgroundScreen.cs @@ -37,7 +37,7 @@ namespace osu.Game.Screens } // Make sure the in-progress loading is complete before pushing the screen. - while (screen.LoadState < LoadState.Loaded) + while (screen.LoadState < LoadState.Ready) Thread.Sleep(1); base.Push(screen); diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index 01e20fdbd7..63c29a8f78 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -108,7 +108,7 @@ namespace osu.Game.Screens.Play } } - public override bool HandleInput => receptor?.IsAlive != true; + public override bool HandleInput => receptor == null; private Receptor receptor; From a74ebdfe568bfd94a20756ac880981279e2a159e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 14:30:25 +0900 Subject: [PATCH 30/83] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 2a56eb0619..4a213a02aa 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 2a56eb0619adf654ed4927af1a4b227596c87494 +Subproject commit 4a213a02aa09b0fd8bd119eb391549ca1fa00f95 From 6ded194c5317cc6bdae056c377433bb394c8f05e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 14:30:50 +0900 Subject: [PATCH 31/83] Remove all usage of DI to retrieve InputManager Uses GetContainingInputManager instead, as per framework changes. --- osu.Game/Graphics/Containers/ParallaxContainer.cs | 9 +++++++-- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 10 +--------- osu.Game/Overlays/Music/PlaylistOverlay.cs | 6 ++---- .../Settings/Sections/General/LoginSettings.cs | 15 +++++---------- osu.Game/Screens/Select/FilterControl.cs | 8 ++------ osu.Game/Screens/Select/SongSelect.cs | 8 ++++---- 6 files changed, 21 insertions(+), 35 deletions(-) diff --git a/osu.Game/Graphics/Containers/ParallaxContainer.cs b/osu.Game/Graphics/Containers/ParallaxContainer.cs index ec9d30f244..3e0ed4b059 100644 --- a/osu.Game/Graphics/Containers/ParallaxContainer.cs +++ b/osu.Game/Graphics/Containers/ParallaxContainer.cs @@ -34,9 +34,8 @@ namespace osu.Game.Graphics.Containers protected override Container Content => content; [BackgroundDependencyLoader] - private void load(UserInputManager input, OsuConfigManager config) + private void load(OsuConfigManager config) { - this.input = input; parallaxEnabled = config.GetBindable(OsuSetting.MenuParallax); parallaxEnabled.ValueChanged += delegate { @@ -48,6 +47,12 @@ namespace osu.Game.Graphics.Containers }; } + protected override void LoadComplete() + { + base.LoadComplete(); + input = GetContainingInputManager(); + } + private bool firstUpdate = true; protected override void Update() diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index 447daca75e..4817212f7a 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -28,18 +28,10 @@ namespace osu.Game.Graphics.UserInterface { focus = value; if (!focus && HasFocus) - inputManager.ChangeFocus(null); + GetContainingInputManager().ChangeFocus(null); } } - private InputManager inputManager; - - [BackgroundDependencyLoader] - private void load(UserInputManager inputManager) - { - this.inputManager = inputManager; - } - protected override void OnFocus(InputState state) { base.OnFocus(state); diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index 942633b35e..2681c8bbb8 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -31,12 +31,10 @@ namespace osu.Game.Overlays.Music private readonly Bindable beatmapBacking = new Bindable(); public IEnumerable BeatmapSets; - private InputManager inputManager; [BackgroundDependencyLoader] - private void load(OsuGameBase game, BeatmapManager beatmaps, OsuColour colours, UserInputManager inputManager) + private void load(OsuGameBase game, BeatmapManager beatmaps, OsuColour colours) { - this.inputManager = inputManager; this.beatmaps = beatmaps; Children = new Drawable[] @@ -102,7 +100,7 @@ namespace osu.Game.Overlays.Music protected override void PopIn() { filter.Search.HoldFocus = true; - Schedule(() => inputManager.ChangeFocus(filter.Search)); + Schedule(() => GetContainingInputManager().ChangeFocus(filter.Search)); this.ResizeTo(new Vector2(1, playlist_height), transition_duration, Easing.OutQuint); this.FadeIn(transition_duration, Easing.OutQuint); diff --git a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs index d07f156673..3f8b6186c4 100644 --- a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs @@ -57,12 +57,9 @@ namespace osu.Game.Overlays.Settings.Sections.General Spacing = new Vector2(0f, 5f); } - private InputManager inputManager; - [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuColour colours, APIAccess api, UserInputManager inputManager) + private void load(OsuColour colours, APIAccess api) { - this.inputManager = inputManager; this.colours = colours; api?.Register(this); @@ -174,7 +171,7 @@ namespace osu.Game.Overlays.Settings.Sections.General break; } - if (form != null) inputManager.ChangeFocus(form); + if (form != null) GetContainingInputManager().ChangeFocus(form); } public override bool AcceptsFocus => true; @@ -183,7 +180,7 @@ namespace osu.Game.Overlays.Settings.Sections.General protected override void OnFocus(InputState state) { - if (form != null) inputManager.ChangeFocus(form); + if (form != null) GetContainingInputManager().ChangeFocus(form); base.OnFocus(state); } @@ -192,7 +189,6 @@ namespace osu.Game.Overlays.Settings.Sections.General private TextBox username; private TextBox password; private APIAccess api; - private InputManager inputManager; private void performLogin() { @@ -201,9 +197,8 @@ namespace osu.Game.Overlays.Settings.Sections.General } [BackgroundDependencyLoader(permitNulls: true)] - private void load(APIAccess api, OsuConfigManager config, UserInputManager inputManager) + private void load(APIAccess api, OsuConfigManager config) { - this.inputManager = inputManager; this.api = api; Direction = FillDirection.Vertical; Spacing = new Vector2(0, 5); @@ -256,7 +251,7 @@ namespace osu.Game.Overlays.Settings.Sections.General protected override void OnFocus(InputState state) { - Schedule(() => { inputManager.ChangeFocus(string.IsNullOrEmpty(username.Text) ? username : password); }); + Schedule(() => { GetContainingInputManager().ChangeFocus(string.IsNullOrEmpty(username.Text) ? username : password); }); } } diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 838e6f7123..e83613125b 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -153,7 +153,7 @@ namespace osu.Game.Screens.Select { searchTextBox.HoldFocus = false; if (searchTextBox.HasFocus) - inputManager.ChangeFocus(searchTextBox); + GetContainingInputManager().ChangeFocus(searchTextBox); } public void Activate() @@ -163,13 +163,9 @@ namespace osu.Game.Screens.Select private readonly Bindable ruleset = new Bindable(); - private InputManager inputManager; - [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuColour colours, OsuGame osu, UserInputManager inputManager) + private void load(OsuColour colours, OsuGame osu) { - this.inputManager = inputManager; - sortTabs.AccentColour = colours.GreenLight; if (osu != null) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 8f545240c8..afab9e8746 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -156,11 +156,11 @@ namespace osu.Game.Screens.Select } [BackgroundDependencyLoader(permitNulls: true)] - private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours, UserInputManager input) + private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours) { if (Footer != null) { - Footer.AddButton(@"random", colours.Green, () => triggerRandom(input), Key.F2); + Footer.AddButton(@"random", colours.Green, triggerRandom, Key.F2); Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3); BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue); @@ -267,9 +267,9 @@ namespace osu.Game.Screens.Select } } - private void triggerRandom(UserInputManager input) + private void triggerRandom() { - if (input.CurrentState.Keyboard.ShiftPressed) + if (GetContainingInputManager().CurrentState.Keyboard.ShiftPressed) carousel.SelectPreviousRandom(); else carousel.SelectNextRandom(); From 9e5deb63d1bc7d8a409012d1c93f362e39caca09 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Tue, 15 Aug 2017 16:42:26 +0930 Subject: [PATCH 32/83] Fix spinner not handling left/right action bindings --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index cd808abe9d..99c287f6fb 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -5,13 +5,14 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; +using osu.Framework.Input.Bindings; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { - public class SpinnerDisc : CircularContainer, IHasAccentColour + public class SpinnerDisc : CircularContainer, IHasAccentColour, IKeyBindingHandler { private readonly Spinner spinner; @@ -66,26 +67,53 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces } } + private void updateTracking() + { + Tracking = mouseHasMainButtonPressed || actionLeftButtonPressed || actionRightButtonPressed; + } + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - Tracking |= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; + updateTracking(); return base.OnMouseDown(state, args); } protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) { - Tracking &= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed &= state.Mouse.HasMainButtonPressed; + updateTracking(); return base.OnMouseUp(state, args); } protected override bool OnMouseMove(InputState state) { - Tracking |= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; mousePosition = Parent.ToLocalSpace(state.Mouse.NativeState.Position); + updateTracking(); return base.OnMouseMove(state); } + public bool OnPressed(OsuAction action) + { + actionLeftButtonPressed |= action == OsuAction.LeftButton; + actionRightButtonPressed |= action == OsuAction.RightButton; + updateTracking(); + return false; + } + + public bool OnReleased(OsuAction action) + { + actionLeftButtonPressed &= action == OsuAction.LeftButton; + actionRightButtonPressed &= action == OsuAction.RightButton; + updateTracking(); + return false; + } + private Vector2 mousePosition; + private bool mouseHasMainButtonPressed; + private bool actionLeftButtonPressed; + private bool actionRightButtonPressed; private float lastAngle; private float currentRotation; From 143ff695efd03e163c558f5bebbbeb70cb0d81b1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 17:44:04 +0900 Subject: [PATCH 33/83] Remove unused using statements --- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 1 - osu.Game/Overlays/Music/PlaylistOverlay.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index 4817212f7a..dbbb069f7c 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -3,7 +3,6 @@ using OpenTK.Graphics; using OpenTK.Input; -using osu.Framework.Allocation; using osu.Framework.Input; using System; using System.Linq; diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index 2681c8bbb8..83e92c5554 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -6,7 +6,6 @@ using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Input; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; From 3bee36f6a2faf447cb863984b562013e93436a01 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 23:59:06 +0900 Subject: [PATCH 34/83] Add index to Action column Is used for default assignment --- osu.Game/Input/Bindings/DatabasedKeyBinding.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs index 73896b5ffe..c0197ce3dc 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs @@ -27,6 +27,7 @@ namespace osu.Game.Input.Bindings private set { KeyCombination = value; } } + [Indexed] [Column("Action")] public new int Action { From 2bd098173818718c533166d7da9805f86e4625b5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 15 Aug 2017 23:59:58 +0900 Subject: [PATCH 35/83] Improve default key binding logic Defaults will be added to the database as long as the database has unbalanced counts for any actions. --- .../DatabasedKeyBindingInputManager.cs | 2 +- osu.Game/Input/KeyBindingStore.cs | 51 ++++++++++--------- osu.Game/OsuGameBase.cs | 1 + 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index a02dd00a77..e565c13b31 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -44,7 +44,7 @@ namespace osu.Game.Input.Bindings protected override void ReloadMappings() { - KeyBindings = store.GetProcessedList(DefaultMappings, ruleset?.ID, variant); + KeyBindings = store.Query(ruleset?.ID, variant); } } } \ No newline at end of file diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 0cd556289f..057fa4d4e7 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -22,14 +22,11 @@ namespace osu.Game.Input { var ruleset = info.CreateInstance(); foreach (var variant in ruleset.AvailableVariants) - GetProcessedList(ruleset.GetDefaultKeyBindings(), info.ID, variant); + insertDefaults(ruleset.GetDefaultKeyBindings(), info.ID, variant); } } - public void Register(KeyBindingInputManager manager) - { - GetProcessedList(manager.DefaultMappings); - } + public void Register(KeyBindingInputManager manager) => insertDefaults(manager.DefaultMappings); protected override int StoreVersion => 3; @@ -61,29 +58,37 @@ namespace osu.Game.Input Connection.CreateTable(); } + private void insertDefaults(IEnumerable defaults, int? rulesetId = null, int? variant = null) + { + var query = Query(rulesetId, variant); + + // compare counts in database vs defaults + foreach (var group in defaults.GroupBy(k => k.Action)) + { + int count; + while (group.Count() > (count = query.Count(k => (int)k.Action == (int)group.Key))) + { + var insertable = group.Skip(count).First(); + + // insert any defaults which are missing. + Connection.Insert(new DatabasedKeyBinding + { + KeyCombination = insertable.KeyCombination, + Action = (int)insertable.Action, + RulesetID = rulesetId, + Variant = variant + }); + } + } + } + protected override Type[] ValidTypes => new[] { typeof(DatabasedKeyBinding) }; - public IEnumerable GetProcessedList(IEnumerable defaults, int? rulesetId = null, int? variant = null) - { - var databaseEntries = Query(b => b.RulesetID == rulesetId && b.Variant == variant); - - if (!databaseEntries.Any()) - { - // if there are no entries for this category in the database, we should populate our defaults. - Connection.InsertAll(defaults.Select(k => new DatabasedKeyBinding - { - KeyCombination = k.KeyCombination, - Action = (int)k.Action, - RulesetID = rulesetId, - Variant = variant - })); - } - - return databaseEntries; - } + public IEnumerable Query(int? rulesetId = null, int? variant = null) => + Query(b => b.RulesetID == rulesetId && b.Variant == variant); public void Update(KeyBinding keyBinding) { diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 54b091d7d9..571c75022e 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -202,6 +202,7 @@ namespace osu.Game } }); + KeyBindingStore.Register(globalBinding); dependencies.Cache(globalBinding); // TODO: This is temporary until we reimplement the local FPS display. From 9c75df884fe67c41b0d77b21bbe480119f88746b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 00:08:59 +0900 Subject: [PATCH 36/83] Add initial implementation of KeyConfiguration overlay --- .../Visual/TestCaseKeyConfiguration.cs | 362 +----------------- .../KeyConfiguration/GlobalBindingsSection.cs | 23 ++ .../KeyConfiguration/KeyBindingRow.cs | 284 ++++++++++++++ .../KeyConfiguration/KeyBindingsSection.cs | 51 +++ .../KeyConfiguration/KeyConfiguration.cs | 30 ++ .../RulesetBindingsSection.cs | 21 + osu.Game/osu.Game.csproj | 5 + 7 files changed, 415 insertions(+), 361 deletions(-) create mode 100644 osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs create mode 100644 osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs create mode 100644 osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs create mode 100644 osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs create mode 100644 osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs index 077417577a..69489c51a1 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -1,27 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using osu.Game.Overlays; -using osu.Game.Overlays.Settings; -using osu.Framework.Allocation; -using osu.Framework.Extensions; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Input; -using osu.Game.Rulesets; -using osu.Framework.Input.Bindings; -using osu.Game.Input.Bindings; -using OpenTK; -using OpenTK.Graphics; -using osu.Framework.Input; -using OpenTK.Input; +using osu.Game.Overlays.KeyConfiguration; namespace osu.Desktop.Tests.Visual { @@ -39,347 +19,7 @@ namespace osu.Desktop.Tests.Visual protected override void LoadComplete() { base.LoadComplete(); - configuration.Show(); } } - - public class KeyConfiguration : SettingsOverlay - { - protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); - - [BackgroundDependencyLoader(permitNulls: true)] - private void load(RulesetStore rulesets, GlobalBindingInputManager global) - { - AddSection(new GlobalBindingsSection(global, "Global")); - - foreach (var ruleset in rulesets.Query()) - AddSection(new RulesetBindingsSection(ruleset)); - } - - public KeyConfiguration() - : base(false) - { - } - } - - public class GlobalBindingsSection : KeyBindingsSection - { - private readonly string name; - - public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; - public override string Header => name; - - public GlobalBindingsSection(KeyBindingInputManager manager, string name) - { - this.name = name; - - Defaults = manager.DefaultMappings; - } - } - - public class RulesetBindingsSection : KeyBindingsSection - { - public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; - public override string Header => Ruleset.Name; - - public RulesetBindingsSection(RulesetInfo ruleset) - { - Ruleset = ruleset; - - Defaults = ruleset.CreateInstance().GetDefaultKeyBindings(); - } - } - - public abstract class KeyBindingsSection : SettingsSection - { - protected IEnumerable Defaults; - - protected RulesetInfo Ruleset; - - protected KeyBindingsSection() - { - FlowContent.Spacing = new Vector2(0, 1); - } - - [BackgroundDependencyLoader] - private void load(KeyBindingStore store) - { - var firstDefault = Defaults?.FirstOrDefault(); - - if (firstDefault == null) return; - - var actionType = firstDefault.Action.GetType(); - - var bindings = store.GetProcessedList(Defaults, Ruleset?.ID); - - foreach (Enum v in Enum.GetValues(actionType)) - { - Add(new KeyBindingRow(v, bindings.Where(b => (int)b.Action == (int)(object)v))); - } - } - } - - internal class KeyBindingRow : Container, IFilterable - { - private readonly Enum action; - private readonly IEnumerable bindings; - - private const float transition_time = 150; - - private const float height = 20; - - private const float padding = 5; - - private bool matchingFilter; - - public bool MatchingFilter - { - get { return matchingFilter; } - set - { - matchingFilter = value; - this.FadeTo(!matchingFilter ? 0 : 1); - } - } - - private OsuSpriteText text; - private OsuSpriteText pressAKey; - - private FillFlowContainer buttons; - - public string[] FilterTerms => new[] { text.Text }.Concat(bindings.Select(b => b.KeyCombination.ReadableString())).ToArray(); - - public KeyBindingRow(Enum action, IEnumerable bindings) - { - this.action = action; - this.bindings = bindings; - - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - - Masking = true; - CornerRadius = padding; - } - - private KeyBindingStore store; - - [BackgroundDependencyLoader] - private void load(OsuColour colours, KeyBindingStore store) - { - this.store = store; - - EdgeEffect = new EdgeEffectParameters - { - Radius = 2, - Colour = colours.YellowDark.Opacity(0), - Type = EdgeEffectType.Shadow, - Hollow = true, - }; - - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - Alpha = 0.6f, - }, - text = new OsuSpriteText - { - Text = action.GetDescription(), - Margin = new MarginPadding(padding), - }, - buttons = new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight - }, - pressAKey = new OsuSpriteText - { - Text = "Press a key to change the binding, or ESC to cancel.", - Y = height, - Margin = new MarginPadding(padding), - Alpha = 0, - Colour = colours.YellowDark - } - }; - - reloadBindings(); - } - - private void reloadBindings() - { - buttons.Clear(); - foreach (var b in bindings) - buttons.Add(new KeyButton(b)); - } - - protected override bool OnHover(InputState state) - { - this.FadeEdgeEffectTo(1, transition_time, Easing.OutQuint); - - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - this.FadeEdgeEffectTo(0, transition_time, Easing.OutQuint); - - base.OnHoverLost(state); - } - - public override bool AcceptsFocus => true; - - private KeyButton bindTarget; - - protected override void OnFocus(InputState state) - { - AutoSizeDuration = 500; - AutoSizeEasing = Easing.OutQuint; - - pressAKey.FadeIn(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding(); - - base.OnFocus(state); - } - - private bool isModifier(Key k) => k < Key.F1; - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - if (HasFocus) - { - if (!isModifier(args.Key)) - { - bindTarget.KeyBinding.KeyCombination = new KeyCombination(state.Keyboard.Keys); - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); - } - return true; - } - - return base.OnKeyDown(state, args); - } - - protected override void OnFocusLost(InputState state) - { - bindTarget.IsBinding = false; - bindTarget = null; - reloadBindings(); - - pressAKey.FadeOut(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; - base.OnFocusLost(state); - } - - protected override bool OnClick(InputState state) - { - bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); - if (bindTarget != null) bindTarget.IsBinding = true; - - return bindTarget != null; - } - - private class KeyButton : Container - { - public readonly KeyBinding KeyBinding; - - private readonly Box box; - public readonly OsuSpriteText Text; - - private Color4 hoverColour; - - private bool isBinding; - - public bool IsBinding - { - get { return isBinding; } - set - { - isBinding = value; - - if (value) - { - box.FadeColour(Color4.White, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - - } - else - { - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - } - } - } - - public KeyButton(KeyBinding keyBinding) - { - KeyBinding = keyBinding; - - Margin = new MarginPadding(padding); - - var isDefault = keyBinding.Action is Enum; - - Masking = true; - CornerRadius = padding; - - Height = height; - AutoSizeAxes = Axes.X; - - Children = new Drawable[] - { - new Container - { - AlwaysPresent = true, - Width = 80, - Height = height, - }, - box = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black - }, - Text = new OsuSpriteText - { - Font = "Venera", - TextSize = 10, - Margin = new MarginPadding(5), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Text = keyBinding.KeyCombination.ReadableString(), - }, - }; - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - hoverColour = colours.YellowDark; - } - - protected override bool OnHover(InputState state) - { - if (isBinding) - return false; - - box.FadeColour(hoverColour, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - if (isBinding) - return; - - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - - base.OnHoverLost(state); - } - } - } } diff --git a/osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs b/osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs new file mode 100644 index 0000000000..9d68b41045 --- /dev/null +++ b/osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Input.Bindings; +using osu.Game.Graphics; + +namespace osu.Game.Overlays.KeyConfiguration +{ + public class GlobalBindingsSection : KeyBindingsSection + { + private readonly string name; + + public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; + public override string Header => name; + + public GlobalBindingsSection(KeyBindingInputManager manager, string name) + { + this.name = name; + + Defaults = manager.DefaultMappings; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs b/osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs new file mode 100644 index 0000000000..a9ef10eae6 --- /dev/null +++ b/osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs @@ -0,0 +1,284 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Extensions; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Input; +using osu.Framework.Input.Bindings; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Input; +using OpenTK.Graphics; +using OpenTK.Input; + +namespace osu.Game.Overlays.KeyConfiguration +{ + internal class KeyBindingRow : Container, IFilterable + { + private readonly Enum action; + private readonly IEnumerable bindings; + + private const float transition_time = 150; + + private const float height = 20; + + private const float padding = 5; + + private bool matchingFilter; + + public bool MatchingFilter + { + get { return matchingFilter; } + set + { + matchingFilter = value; + this.FadeTo(!matchingFilter ? 0 : 1); + } + } + + private OsuSpriteText text; + private OsuSpriteText pressAKey; + + private FillFlowContainer buttons; + + public string[] FilterTerms => new[] { text.Text }.Concat(bindings.Select(b => b.KeyCombination.ReadableString())).ToArray(); + + public KeyBindingRow(Enum action, IEnumerable bindings) + { + this.action = action; + this.bindings = bindings; + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + Masking = true; + CornerRadius = padding; + } + + private KeyBindingStore store; + + [BackgroundDependencyLoader] + private void load(OsuColour colours, KeyBindingStore store) + { + this.store = store; + + EdgeEffect = new EdgeEffectParameters + { + Radius = 2, + Colour = colours.YellowDark.Opacity(0), + Type = EdgeEffectType.Shadow, + Hollow = true, + }; + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.6f, + }, + text = new OsuSpriteText + { + Text = action.GetDescription(), + Margin = new MarginPadding(padding), + }, + buttons = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }, + pressAKey = new OsuSpriteText + { + Text = "Press a key to change binding, DEL to delete, ESC to cancel.", + Y = height, + Margin = new MarginPadding(padding), + Alpha = 0, + Colour = colours.YellowDark + } + }; + + reloadBindings(); + } + + private void reloadBindings() + { + buttons.Clear(); + foreach (var b in bindings) + buttons.Add(new KeyButton(b)); + } + + protected override bool OnHover(InputState state) + { + this.FadeEdgeEffectTo(1, transition_time, Easing.OutQuint); + + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + this.FadeEdgeEffectTo(0, transition_time, Easing.OutQuint); + + base.OnHoverLost(state); + } + + public override bool AcceptsFocus => true; + + private KeyButton bindTarget; + + protected override void OnFocus(InputState state) + { + AutoSizeDuration = 500; + AutoSizeEasing = Easing.OutQuint; + + pressAKey.FadeIn(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding(); + + base.OnFocus(state); + } + + private bool isModifier(Key k) => k < Key.F1; + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (HasFocus && !isModifier(args.Key)) + { + bindTarget.KeyBinding.KeyCombination = args.Key == Key.Delete ? Key.Unknown : new KeyCombination(state.Keyboard.Keys); + + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + return true; + } + + return base.OnKeyDown(state, args); + } + + protected override void OnFocusLost(InputState state) + { + bindTarget.IsBinding = false; + bindTarget = null; + reloadBindings(); + + pressAKey.FadeOut(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + base.OnFocusLost(state); + } + + protected override bool OnClick(InputState state) + { + if (bindTarget != null) bindTarget.IsBinding = false; + bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); + if (bindTarget != null) bindTarget.IsBinding = true; + + return bindTarget != null; + } + + private class KeyButton : Container + { + public readonly KeyBinding KeyBinding; + + private readonly Box box; + public readonly OsuSpriteText Text; + + private Color4 hoverColour; + + private bool isBinding; + + public bool IsBinding + { + get { return isBinding; } + set + { + isBinding = value; + + if (value) + { + box.FadeColour(Color4.White, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + + } + else + { + box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); + } + } + } + + public KeyButton(KeyBinding keyBinding) + { + KeyBinding = keyBinding; + + Margin = new MarginPadding(padding); + + //var isDefault = keyBinding.Action is Enum; + + Masking = true; + CornerRadius = padding; + + Height = height; + AutoSizeAxes = Axes.X; + + Children = new Drawable[] + { + new Container + { + AlwaysPresent = true, + Width = 80, + Height = height, + }, + box = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black + }, + Text = new OsuSpriteText + { + Font = "Venera", + TextSize = 10, + Margin = new MarginPadding(5), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = keyBinding.KeyCombination.ReadableString(), + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + hoverColour = colours.YellowDark; + } + + protected override bool OnHover(InputState state) + { + if (isBinding) + return false; + + box.FadeColour(hoverColour, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + if (isBinding) + return; + + box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); + + base.OnHoverLost(state); + } + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs new file mode 100644 index 0000000000..1e574d5e55 --- /dev/null +++ b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs @@ -0,0 +1,51 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Input.Bindings; +using osu.Game.Input; +using osu.Game.Overlays.Settings; +using osu.Game.Rulesets; +using OpenTK; + +namespace osu.Game.Overlays.KeyConfiguration +{ + public abstract class KeyBindingsSection : SettingsSection + { + protected IEnumerable Defaults; + + protected RulesetInfo Ruleset; + + protected KeyBindingsSection() + { + FlowContent.Spacing = new Vector2(0, 1); + } + + [BackgroundDependencyLoader] + private void load(KeyBindingStore store) + { + var firstDefault = Defaults?.FirstOrDefault(); + + if (firstDefault == null) return; + + var actionType = firstDefault.Action.GetType(); + + int? variant = null; + + // for now let's just assume a variant of zero. + // this will need to be implemented in a better way in the future. + if (Ruleset != null) + variant = 0; + + var bindings = store.Query(Ruleset?.ID, variant); + + foreach (Enum v in Enum.GetValues(actionType)) + { + Add(new KeyBindingRow(v, bindings.Where(b => (int)b.Action == (int)(object)v))); + } + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs b/osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs new file mode 100644 index 0000000000..416f828495 --- /dev/null +++ b/osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Input.Bindings; +using osu.Game.Overlays.Settings; +using osu.Game.Rulesets; + +namespace osu.Game.Overlays.KeyConfiguration +{ + public class KeyConfiguration : SettingsOverlay + { + protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); + + [BackgroundDependencyLoader(permitNulls: true)] + private void load(RulesetStore rulesets, GlobalBindingInputManager global) + { + AddSection(new GlobalBindingsSection(global, "Global")); + + foreach (var ruleset in rulesets.Query()) + AddSection(new RulesetBindingsSection(ruleset)); + } + + public KeyConfiguration() + : base(false) + { + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs b/osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs new file mode 100644 index 0000000000..038df5e122 --- /dev/null +++ b/osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Graphics; +using osu.Game.Rulesets; + +namespace osu.Game.Overlays.KeyConfiguration +{ + public class RulesetBindingsSection : KeyBindingsSection + { + public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; + public override string Header => Ruleset.Name; + + public RulesetBindingsSection(RulesetInfo ruleset) + { + Ruleset = ruleset; + + Defaults = ruleset.CreateInstance().GetDefaultKeyBindings(); + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index b324fb9f92..6eb0ece6ed 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -102,6 +102,11 @@ + + + + + From 72eb082f916b849ad58041ecf27fa89e6da2251b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 01:14:37 +0900 Subject: [PATCH 37/83] Use .Equals --- osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs index 1e574d5e55..b7b07ab2f8 100644 --- a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs @@ -44,7 +44,7 @@ namespace osu.Game.Overlays.KeyConfiguration foreach (Enum v in Enum.GetValues(actionType)) { - Add(new KeyBindingRow(v, bindings.Where(b => (int)b.Action == (int)(object)v))); + Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v)))); } } } From c221472d6ee7e01c59bde8a085371c760a216ca2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 01:19:21 +0900 Subject: [PATCH 38/83] Code tidy-ups --- .../KeyConfiguration/KeyBindingsSection.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs index b7b07ab2f8..fe72c64edb 100644 --- a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs @@ -27,25 +27,21 @@ namespace osu.Game.Overlays.KeyConfiguration [BackgroundDependencyLoader] private void load(KeyBindingStore store) { - var firstDefault = Defaults?.FirstOrDefault(); + var enumType = Defaults?.FirstOrDefault()?.Action?.GetType(); - if (firstDefault == null) return; - - var actionType = firstDefault.Action.GetType(); - - int? variant = null; + if (enumType == null) return; // for now let's just assume a variant of zero. // this will need to be implemented in a better way in the future. + int? variant = null; if (Ruleset != null) variant = 0; var bindings = store.Query(Ruleset?.ID, variant); - foreach (Enum v in Enum.GetValues(actionType)) - { + foreach (Enum v in Enum.GetValues(enumType)) + // one row per valid action. Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v)))); - } } } } \ No newline at end of file From 6ee4716ec53e378da4e91a394dd7d1b0878cd61c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 12:39:18 +0900 Subject: [PATCH 39/83] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 2a56eb0619..e5b0f1c9d0 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 2a56eb0619adf654ed4927af1a4b227596c87494 +Subproject commit e5b0f1c9d0c98ee89563042071e516d5304a6d06 From a5007fc64fa3c661f29b5f7b4978af932252db9b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 13:07:18 +0900 Subject: [PATCH 40/83] Fix some remaining usage of local InputManager instances --- osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs | 2 +- osu.Game/Overlays/ChatOverlay.cs | 2 +- osu.Game/Overlays/LoginOverlay.cs | 2 +- osu.Game/Overlays/SearchableList/SearchableListOverlay.cs | 2 +- osu.Game/Overlays/SettingsOverlay.cs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs index 368d3cc5ef..4362b3f787 100644 --- a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs +++ b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs @@ -152,7 +152,7 @@ namespace osu.Game.Overlays.Chat protected override void OnFocus(InputState state) { - InputManager.ChangeFocus(search); + GetContainingInputManager().ChangeFocus(search); base.OnFocus(state); } diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 29b7548ada..e7a4c1c0ab 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -243,7 +243,7 @@ namespace osu.Game.Overlays protected override void OnFocus(InputState state) { //this is necessary as inputTextBox is masked away and therefore can't get focus :( - InputManager.ChangeFocus(inputTextBox); + GetContainingInputManager().ChangeFocus(inputTextBox); base.OnFocus(state); } diff --git a/osu.Game/Overlays/LoginOverlay.cs b/osu.Game/Overlays/LoginOverlay.cs index 95e0fef9aa..1bce31c789 100644 --- a/osu.Game/Overlays/LoginOverlay.cs +++ b/osu.Game/Overlays/LoginOverlay.cs @@ -69,7 +69,7 @@ namespace osu.Game.Overlays settingsSection.Bounding = true; this.FadeIn(transition_time, Easing.OutQuint); - InputManager.ChangeFocus(settingsSection); + GetContainingInputManager().ChangeFocus(settingsSection); } protected override void PopOut() diff --git a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs index c5b8b0cf85..d1d40388e1 100644 --- a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs +++ b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs @@ -103,7 +103,7 @@ namespace osu.Game.Overlays.SearchableList protected override void OnFocus(InputState state) { - InputManager.ChangeFocus(Filter.Search); + GetContainingInputManager().ChangeFocus(Filter.Search); } protected override void PopIn() diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index dfbcedd479..bd2212785a 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -153,7 +153,7 @@ namespace osu.Game.Overlays searchTextBox.HoldFocus = false; if (searchTextBox.HasFocus) - InputManager.ChangeFocus(null); + GetContainingInputManager().ChangeFocus(null); } public override bool AcceptsFocus => true; @@ -162,7 +162,7 @@ namespace osu.Game.Overlays protected override void OnFocus(InputState state) { - InputManager.ChangeFocus(searchTextBox); + GetContainingInputManager().ChangeFocus(searchTextBox); base.OnFocus(state); } From 7d00365154592294e2bb3be3ec6953e63df5bed3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 12:12:25 +0900 Subject: [PATCH 41/83] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 4a213a02aa..fc13a4c2f1 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 4a213a02aa09b0fd8bd119eb391549ca1fa00f95 +Subproject commit fc13a4c2f1eff443ffe7d5ff3ca5caa17b98ffbf From 9448e2f192bfee608ad6b620c495fcef2c22e09b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Wed, 16 Aug 2017 17:25:48 +0930 Subject: [PATCH 42/83] Remove unnecessary OnMouseDown/Up from SpinnerDisc --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 99c287f6fb..eda6334b7a 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -67,30 +67,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces } } - private void updateTracking() - { - Tracking = mouseHasMainButtonPressed || actionLeftButtonPressed || actionRightButtonPressed; - } - - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) - { - mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; - updateTracking(); - return base.OnMouseDown(state, args); - } - - protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) - { - mouseHasMainButtonPressed &= state.Mouse.HasMainButtonPressed; - updateTracking(); - return base.OnMouseUp(state, args); - } - protected override bool OnMouseMove(InputState state) { - mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; mousePosition = Parent.ToLocalSpace(state.Mouse.NativeState.Position); - updateTracking(); return base.OnMouseMove(state); } @@ -98,7 +77,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { actionLeftButtonPressed |= action == OsuAction.LeftButton; actionRightButtonPressed |= action == OsuAction.RightButton; - updateTracking(); + Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } @@ -106,12 +85,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { actionLeftButtonPressed &= action == OsuAction.LeftButton; actionRightButtonPressed &= action == OsuAction.RightButton; - updateTracking(); + Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } private Vector2 mousePosition; - private bool mouseHasMainButtonPressed; private bool actionLeftButtonPressed; private bool actionRightButtonPressed; From 25a3835c3c25ab89baed02a88a9bf104b5696920 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 16:59:16 +0900 Subject: [PATCH 43/83] Cancel pending sidebar expansion when a button is clicked --- osu.Game/Overlays/Settings/Sidebar.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Overlays/Settings/Sidebar.cs b/osu.Game/Overlays/Settings/Sidebar.cs index 6eafc65d12..bfb3b96cb7 100644 --- a/osu.Game/Overlays/Settings/Sidebar.cs +++ b/osu.Game/Overlays/Settings/Sidebar.cs @@ -87,6 +87,8 @@ namespace osu.Game.Overlays.Settings get { return state; } set { + expandEvent?.Cancel(); + if (state == value) return; state = value; From b1abf83fee82bfb3bdb6ab1d0a538d67b5f242ca Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Wed, 16 Aug 2017 17:50:24 +0930 Subject: [PATCH 44/83] Change spinner action checks to switches --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index eda6334b7a..1e56a2559a 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -75,16 +75,30 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces public bool OnPressed(OsuAction action) { - actionLeftButtonPressed |= action == OsuAction.LeftButton; - actionRightButtonPressed |= action == OsuAction.RightButton; + switch (action) + { + case OsuAction.LeftButton: + actionLeftButtonPressed = true; + break; + case OsuAction.RightButton: + actionRightButtonPressed = true; + break; + } Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } public bool OnReleased(OsuAction action) { - actionLeftButtonPressed &= action == OsuAction.LeftButton; - actionRightButtonPressed &= action == OsuAction.RightButton; + switch (action) + { + case OsuAction.LeftButton: + actionLeftButtonPressed = false; + break; + case OsuAction.RightButton: + actionRightButtonPressed = false; + break; + } Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } From dc82a88bb8ee6fa2983512bb1e532dd7e1965a26 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 17:19:27 +0900 Subject: [PATCH 45/83] Improve namespaces of key bindings --- .../Visual/TestCaseKeyConfiguration.cs | 6 ++--- .../GlobalBindingsSection.cs | 2 +- .../KeyBindingRow.cs | 10 ++++---- .../KeyBindingsSection.cs | 5 ++-- .../RulesetBindingsSection.cs | 2 +- ...yConfiguration.cs => KeyBindingOverlay.cs} | 7 +++--- osu.Game/Overlays/SettingsOverlay.cs | 24 +++++++++---------- osu.Game/osu.Game.csproj | 10 ++++---- 8 files changed, 32 insertions(+), 34 deletions(-) rename osu.Game/Overlays/{KeyConfiguration => KeyBinding}/GlobalBindingsSection.cs (90%) rename osu.Game/Overlays/{KeyConfiguration => KeyBinding}/KeyBindingRow.cs (92%) rename osu.Game/Overlays/{KeyConfiguration => KeyBinding}/KeyBindingsSection.cs (87%) rename osu.Game/Overlays/{KeyConfiguration => KeyBinding}/RulesetBindingsSection.cs (89%) rename osu.Game/Overlays/{KeyConfiguration/KeyConfiguration.cs => KeyBindingOverlay.cs} (81%) diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs index 69489c51a1..77db6e7b91 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -1,19 +1,17 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Game.Overlays.KeyConfiguration; - namespace osu.Desktop.Tests.Visual { public class TestCaseKeyConfiguration : OsuTestCase { - private readonly KeyConfiguration configuration; + private readonly KeyConfigurationOverlay configuration; public override string Description => @"Key configuration"; public TestCaseKeyConfiguration() { - Child = configuration = new KeyConfiguration(); + Child = configuration = new KeyConfigurationOverlay(); } protected override void LoadComplete() diff --git a/osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs b/osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs similarity index 90% rename from osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs rename to osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs index 9d68b41045..943fc4a416 100644 --- a/osu.Game/Overlays/KeyConfiguration/GlobalBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs @@ -4,7 +4,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Graphics; -namespace osu.Game.Overlays.KeyConfiguration +namespace osu.Game.Overlays.KeyBinding { public class GlobalBindingsSection : KeyBindingsSection { diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs similarity index 92% rename from osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs rename to osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index a9ef10eae6..4cc179aaf1 100644 --- a/osu.Game/Overlays/KeyConfiguration/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -18,12 +18,12 @@ using osu.Game.Input; using OpenTK.Graphics; using OpenTK.Input; -namespace osu.Game.Overlays.KeyConfiguration +namespace osu.Game.Overlays.KeyBinding { internal class KeyBindingRow : Container, IFilterable { private readonly Enum action; - private readonly IEnumerable bindings; + private readonly IEnumerable bindings; private const float transition_time = 150; @@ -50,7 +50,7 @@ namespace osu.Game.Overlays.KeyConfiguration public string[] FilterTerms => new[] { text.Text }.Concat(bindings.Select(b => b.KeyCombination.ReadableString())).ToArray(); - public KeyBindingRow(Enum action, IEnumerable bindings) + public KeyBindingRow(Enum action, IEnumerable bindings) { this.action = action; this.bindings = bindings; @@ -183,7 +183,7 @@ namespace osu.Game.Overlays.KeyConfiguration private class KeyButton : Container { - public readonly KeyBinding KeyBinding; + public readonly Framework.Input.Bindings.KeyBinding KeyBinding; private readonly Box box; public readonly OsuSpriteText Text; @@ -213,7 +213,7 @@ namespace osu.Game.Overlays.KeyConfiguration } } - public KeyButton(KeyBinding keyBinding) + public KeyButton(Framework.Input.Bindings.KeyBinding keyBinding) { KeyBinding = keyBinding; diff --git a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs similarity index 87% rename from osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs rename to osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs index fe72c64edb..19baeca771 100644 --- a/osu.Game/Overlays/KeyConfiguration/KeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs @@ -5,17 +5,16 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Input.Bindings; using osu.Game.Input; using osu.Game.Overlays.Settings; using osu.Game.Rulesets; using OpenTK; -namespace osu.Game.Overlays.KeyConfiguration +namespace osu.Game.Overlays.KeyBinding { public abstract class KeyBindingsSection : SettingsSection { - protected IEnumerable Defaults; + protected IEnumerable Defaults; protected RulesetInfo Ruleset; diff --git a/osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs b/osu.Game/Overlays/KeyBinding/RulesetBindingsSection.cs similarity index 89% rename from osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs rename to osu.Game/Overlays/KeyBinding/RulesetBindingsSection.cs index 038df5e122..20941115e3 100644 --- a/osu.Game/Overlays/KeyConfiguration/RulesetBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/RulesetBindingsSection.cs @@ -4,7 +4,7 @@ using osu.Game.Graphics; using osu.Game.Rulesets; -namespace osu.Game.Overlays.KeyConfiguration +namespace osu.Game.Overlays.KeyBinding { public class RulesetBindingsSection : KeyBindingsSection { diff --git a/osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs b/osu.Game/Overlays/KeyBindingOverlay.cs similarity index 81% rename from osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs rename to osu.Game/Overlays/KeyBindingOverlay.cs index 416f828495..e5061def77 100644 --- a/osu.Game/Overlays/KeyConfiguration/KeyConfiguration.cs +++ b/osu.Game/Overlays/KeyBindingOverlay.cs @@ -4,12 +4,13 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Input.Bindings; +using osu.Game.Overlays.KeyBinding; using osu.Game.Overlays.Settings; using osu.Game.Rulesets; -namespace osu.Game.Overlays.KeyConfiguration +namespace osu.Game.Overlays { - public class KeyConfiguration : SettingsOverlay + public class KeyConfigurationOverlay : SettingsOverlay { protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); @@ -22,7 +23,7 @@ namespace osu.Game.Overlays.KeyConfiguration AddSection(new RulesetBindingsSection(ruleset)); } - public KeyConfiguration() + public KeyConfigurationOverlay() : base(false) { } diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index bd2212785a..76f9ef3326 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -32,7 +32,7 @@ namespace osu.Game.Overlays private Sidebar sidebar; private SidebarButton selectedSidebarButton; - private SettingsSectionsContainer sectionsContainer; + protected SettingsSectionsContainer SectionsContainer; private SearchTextBox searchTextBox; @@ -60,7 +60,7 @@ namespace osu.Game.Overlays Colour = Color4.Black, Alpha = 0.6f, }, - sectionsContainer = new SettingsSectionsContainer + SectionsContainer = new SettingsSectionsContainer { RelativeSizeAxes = Axes.Y, Width = width, @@ -80,14 +80,14 @@ namespace osu.Game.Overlays Exit = Hide, }, Footer = CreateFooter() - } + }, }; if (showSidebar) { Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); - sectionsContainer.SelectedSection.ValueChanged += section => + SectionsContainer.SelectedSection.ValueChanged += section => { selectedSidebarButton.Selected = false; selectedSidebarButton = sidebar.Children.Single(b => b.Section == section); @@ -95,7 +95,7 @@ namespace osu.Game.Overlays }; } - searchTextBox.Current.ValueChanged += newValue => sectionsContainer.SearchContainer.SearchTerm = newValue; + searchTextBox.Current.ValueChanged += newValue => SectionsContainer.SearchContainer.SearchTerm = newValue; getToolbarHeight = () => game?.ToolbarOffset ?? 0; @@ -104,7 +104,7 @@ namespace osu.Game.Overlays protected void AddSection(SettingsSection section) { - sectionsContainer.Add(section); + SectionsContainer.Add(section); if (sidebar != null) { @@ -113,7 +113,7 @@ namespace osu.Game.Overlays Section = section, Action = s => { - sectionsContainer.ScrollTo(s); + SectionsContainer.ScrollTo(s); sidebar.State = ExpandedState.Contracted; }, }; @@ -136,7 +136,7 @@ namespace osu.Game.Overlays { base.PopIn(); - sectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); + SectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(1, TRANSITION_LENGTH / 2); @@ -147,7 +147,7 @@ namespace osu.Game.Overlays { base.PopOut(); - sectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); + SectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(0, TRANSITION_LENGTH / 2); @@ -170,11 +170,11 @@ namespace osu.Game.Overlays { base.UpdateAfterChildren(); - sectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; - sectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; + SectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; + SectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; } - private class SettingsSectionsContainer : SectionsContainer + protected class SettingsSectionsContainer : SectionsContainer { public SearchContainer SearchContainer; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 6eb0ece6ed..f21ce528ca 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -102,11 +102,11 @@ - - - - - + + + + + From 54698f2d8ff37071ec706d919add0010cf4b3845 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 17:27:09 +0900 Subject: [PATCH 46/83] Use IntAction instead of new --- osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs | 2 ++ osu.Game/Input/Bindings/DatabasedKeyBinding.cs | 6 +++--- osu.Game/Input/KeyBindingStore.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs index 77db6e7b91..41e0c25507 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Overlays; + namespace osu.Desktop.Tests.Visual { public class TestCaseKeyConfiguration : OsuTestCase diff --git a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs index c0197ce3dc..cbf74d6984 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBinding.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBinding.cs @@ -29,10 +29,10 @@ namespace osu.Game.Input.Bindings [Indexed] [Column("Action")] - public new int Action + public int IntAction { - get { return (int)base.Action; } - set { base.Action = value; } + get { return (int)Action; } + set { Action = value; } } } } \ No newline at end of file diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 057fa4d4e7..95fdaba339 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -74,7 +74,7 @@ namespace osu.Game.Input Connection.Insert(new DatabasedKeyBinding { KeyCombination = insertable.KeyCombination, - Action = (int)insertable.Action, + Action = insertable.Action, RulesetID = rulesetId, Variant = variant }); From 3df51540e19a39b0c8010d00153058ecf4ee0625 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 17:34:49 +0900 Subject: [PATCH 47/83] Code review fixes --- osu-framework | 2 +- .../Input/Bindings/DatabasedKeyBindingInputManager.cs | 2 +- ...ngInputManager.cs => GlobalKeyBindingInputManager.cs} | 6 +++--- osu.Game/Input/KeyBindingStore.cs | 9 ++------- osu.Game/OsuGameBase.cs | 4 ++-- ...balBindingsSection.cs => GlobalKeyBindingsSection.cs} | 6 +++--- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 3 ++- osu.Game/Overlays/KeyBindingOverlay.cs | 4 ++-- osu.Game/osu.Game.csproj | 4 ++-- 9 files changed, 18 insertions(+), 22 deletions(-) rename osu.Game/Input/Bindings/{GlobalBindingInputManager.cs => GlobalKeyBindingInputManager.cs} (88%) rename osu.Game/Overlays/KeyBinding/{GlobalBindingsSection.cs => GlobalKeyBindingsSection.cs} (68%) diff --git a/osu-framework b/osu-framework index fc13a4c2f1..acb9bfb084 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit fc13a4c2f1eff443ffe7d5ff3ca5caa17b98ffbf +Subproject commit acb9bfb084b5607ff31c6269cb7942fa02624b75 diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index e565c13b31..89aee7ca4d 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -21,7 +21,7 @@ namespace osu.Game.Input.Bindings private KeyBindingStore store; - public override IEnumerable DefaultMappings => ruleset.CreateInstance().GetDefaultKeyBindings(); + public override IEnumerable DefaultKeyBindings => ruleset.CreateInstance().GetDefaultKeyBindings(); /// /// Create a new instance. diff --git a/osu.Game/Input/Bindings/GlobalBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs similarity index 88% rename from osu.Game/Input/Bindings/GlobalBindingInputManager.cs rename to osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index d00ed588ae..4dff25d509 100644 --- a/osu.Game/Input/Bindings/GlobalBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -11,17 +11,17 @@ using osu.Framework.Input.Bindings; namespace osu.Game.Input.Bindings { - public class GlobalBindingInputManager : DatabasedKeyBindingInputManager + public class GlobalKeyBindingInputManager : DatabasedKeyBindingInputManager { private readonly Drawable handler; - public GlobalBindingInputManager(OsuGameBase game) + public GlobalKeyBindingInputManager(OsuGameBase game) { if (game is IKeyBindingHandler) handler = game; } - public override IEnumerable DefaultMappings => new[] + public override IEnumerable DefaultKeyBindings => new[] { new KeyBinding(Key.F8, GlobalAction.ToggleChat), new KeyBinding(Key.F9, GlobalAction.ToggleSocial), diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 95fdaba339..f50acb4802 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -26,7 +26,7 @@ namespace osu.Game.Input } } - public void Register(KeyBindingInputManager manager) => insertDefaults(manager.DefaultMappings); + public void Register(KeyBindingInputManager manager) => insertDefaults(manager.DefaultKeyBindings); protected override int StoreVersion => 3; @@ -51,9 +51,7 @@ namespace osu.Game.Input protected override void Prepare(bool reset = false) { if (reset) - { Connection.DropTable(); - } Connection.CreateTable(); } @@ -90,9 +88,6 @@ namespace osu.Game.Input public IEnumerable Query(int? rulesetId = null, int? variant = null) => Query(b => b.RulesetID == rulesetId && b.Variant == variant); - public void Update(KeyBinding keyBinding) - { - Connection.Update(keyBinding); - } + public void Update(KeyBinding keyBinding) => Connection.Update(keyBinding); } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 571c75022e..a5600d1ef7 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -183,14 +183,14 @@ namespace osu.Game { base.LoadComplete(); - GlobalBindingInputManager globalBinding; + GlobalKeyBindingInputManager globalBinding; base.Content.Add(new RatioAdjust { Children = new Drawable[] { Cursor = new MenuCursor(), - globalBinding = new GlobalBindingInputManager(this) + globalBinding = new GlobalKeyBindingInputManager(this) { RelativeSizeAxes = Axes.Both, Child = new OsuTooltipContainer(Cursor) diff --git a/osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs similarity index 68% rename from osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs rename to osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs index 943fc4a416..7dd9919e5d 100644 --- a/osu.Game/Overlays/KeyBinding/GlobalBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs @@ -6,18 +6,18 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.KeyBinding { - public class GlobalBindingsSection : KeyBindingsSection + public class GlobalKeyBindingsSection : KeyBindingsSection { private readonly string name; public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail; public override string Header => name; - public GlobalBindingsSection(KeyBindingInputManager manager, string name) + public GlobalKeyBindingsSection(KeyBindingInputManager manager, string name) { this.name = name; - Defaults = manager.DefaultMappings; + Defaults = manager.DefaultKeyBindings; } } } \ No newline at end of file diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 4cc179aaf1..082e1c0eec 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -219,7 +219,8 @@ namespace osu.Game.Overlays.KeyBinding Margin = new MarginPadding(padding); - //var isDefault = keyBinding.Action is Enum; + // todo: use this in a meaningful way + // var isDefault = keyBinding.Action is Enum; Masking = true; CornerRadius = padding; diff --git a/osu.Game/Overlays/KeyBindingOverlay.cs b/osu.Game/Overlays/KeyBindingOverlay.cs index e5061def77..ba45b3c812 100644 --- a/osu.Game/Overlays/KeyBindingOverlay.cs +++ b/osu.Game/Overlays/KeyBindingOverlay.cs @@ -15,9 +15,9 @@ namespace osu.Game.Overlays protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); [BackgroundDependencyLoader(permitNulls: true)] - private void load(RulesetStore rulesets, GlobalBindingInputManager global) + private void load(RulesetStore rulesets, GlobalKeyBindingInputManager global) { - AddSection(new GlobalBindingsSection(global, "Global")); + AddSection(new GlobalKeyBindingsSection(global, "Global")); foreach (var ruleset in rulesets.Query()) AddSection(new RulesetBindingsSection(ruleset)); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index f21ce528ca..07ab58bffc 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -95,14 +95,14 @@ - + - + From 7e1fc47b76d0fc6252549f0c65d51555b7d400ac Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 17:43:01 +0900 Subject: [PATCH 48/83] Fix forgotten rename --- osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs | 6 +++--- osu.Game/Overlays/KeyBindingOverlay.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs index 41e0c25507..cab285c72e 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyConfiguration.cs @@ -7,19 +7,19 @@ namespace osu.Desktop.Tests.Visual { public class TestCaseKeyConfiguration : OsuTestCase { - private readonly KeyConfigurationOverlay configuration; + private readonly KeyBindingOverlay overlay; public override string Description => @"Key configuration"; public TestCaseKeyConfiguration() { - Child = configuration = new KeyConfigurationOverlay(); + Child = overlay = new KeyBindingOverlay(); } protected override void LoadComplete() { base.LoadComplete(); - configuration.Show(); + overlay.Show(); } } } diff --git a/osu.Game/Overlays/KeyBindingOverlay.cs b/osu.Game/Overlays/KeyBindingOverlay.cs index ba45b3c812..7d6ef7ffa6 100644 --- a/osu.Game/Overlays/KeyBindingOverlay.cs +++ b/osu.Game/Overlays/KeyBindingOverlay.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets; namespace osu.Game.Overlays { - public class KeyConfigurationOverlay : SettingsOverlay + public class KeyBindingOverlay : SettingsOverlay { protected override Drawable CreateHeader() => new SettingsHeader("key configuration", "Customise your keys!"); @@ -23,7 +23,7 @@ namespace osu.Game.Overlays AddSection(new RulesetBindingsSection(ruleset)); } - public KeyConfigurationOverlay() + public KeyBindingOverlay() : base(false) { } From 7e21ddb5eb5ab0fbdc466fe1209bad805fe999b9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 19:17:29 +0900 Subject: [PATCH 49/83] Remove usage of HideOnEscape --- osu.Desktop/Overlays/VersionManager.cs | 2 -- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 9 +++++---- osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs | 2 -- osu.Game/Overlays/Toolbar/Toolbar.cs | 2 -- osu.Game/Screens/Play/MenuOverlay.cs | 5 ++--- osu.Game/Screens/Play/SongProgress.cs | 2 -- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 2 -- 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index 18fa43ab5c..b445340f50 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -27,8 +27,6 @@ namespace osu.Desktop.Overlays private UpdateManager updateManager; private NotificationOverlay notificationOverlay; - protected override bool HideOnEscape => false; - public override bool HandleInput => false; [BackgroundDependencyLoader] diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index dbbb069f7c..fe060f70f0 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -5,7 +5,6 @@ using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Input; using System; -using System.Linq; namespace osu.Game.Graphics.UserInterface { @@ -37,16 +36,18 @@ namespace osu.Game.Graphics.UserInterface BorderThickness = 0; } - protected override void OnFocusLost(InputState state) + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (state.Keyboard.Keys.Any(key => key == Key.Escape)) + if (args.Key == Key.Escape) { if (Text.Length > 0) Text = string.Empty; else Exit?.Invoke(); + return true; } - base.OnFocusLost(state); + + return base.OnKeyDown(state, args); } public override bool RequestsFocus => HoldFocus; diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs index fa192b0825..cd77fb9f5b 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs @@ -15,8 +15,6 @@ namespace osu.Game.Graphics.UserInterface.Volume { private readonly VolumeMeter volumeMeterMaster; - protected override bool HideOnEscape => false; - private void volumeChanged(double newVolume) { Show(); diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index 1ecfe90aa1..f9821782a7 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -22,8 +22,6 @@ namespace osu.Game.Overlays.Toolbar private readonly ToolbarUserArea userArea; - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughMouse => false; private const double transition_time = 500; diff --git a/osu.Game/Screens/Play/MenuOverlay.cs b/osu.Game/Screens/Play/MenuOverlay.cs index a0f867d248..0a8e172e57 100644 --- a/osu.Game/Screens/Play/MenuOverlay.cs +++ b/osu.Game/Screens/Play/MenuOverlay.cs @@ -22,8 +22,6 @@ namespace osu.Game.Screens.Play private const int button_height = 70; private const float background_alpha = 0.75f; - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughKeyboard => true; public Action OnRetry; @@ -95,7 +93,8 @@ namespace osu.Game.Screens.Play Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Height = button_height, - Action = delegate { + Action = delegate + { action?.Invoke(); Hide(); } diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index c513daf3d9..68f0cb3661 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -18,8 +18,6 @@ namespace osu.Game.Screens.Play { private const int bottom_bar_height = 5; - protected override bool HideOnEscape => false; - private static readonly Vector2 handle_size = new Vector2(14, 25); private const float transition_duration = 200; diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index 1fb9c707f0..872f7483b6 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -50,8 +50,6 @@ namespace osu.Game.Screens.Select AlwaysPresent = true; } - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughMouse => false; protected override void PopIn() From 5ebec53970a8e6a3b24ec401a65a9028ba928eab Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 19:17:42 +0900 Subject: [PATCH 50/83] Integrate key binding config with main settings --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 75 ++++++++++++------- osu.Game/Overlays/MainSettings.cs | 51 ++++++++++++- .../Sections/Input/KeyboardSettings.cs | 5 +- .../Settings/Sections/InputSection.cs | 4 +- osu.Game/Overlays/SettingsOverlay.cs | 69 +++++++++-------- 5 files changed, 139 insertions(+), 65 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 082e1c0eec..3415c22972 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; -using osu.Framework.Input.Bindings; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Input; @@ -106,12 +105,6 @@ namespace osu.Game.Overlays.KeyBinding } }; - reloadBindings(); - } - - private void reloadBindings() - { - buttons.Clear(); foreach (var b in bindings) buttons.Add(new KeyButton(b)); } @@ -149,23 +142,46 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (HasFocus && !isModifier(args.Key)) + if (args.Key == Key.Delete) { - bindTarget.KeyBinding.KeyCombination = args.Key == Key.Delete ? Key.Unknown : new KeyCombination(state.Keyboard.Keys); - + bindTarget.UpdateKeyCombination(Key.Unknown); store.Update(bindTarget.KeyBinding); GetContainingInputManager().ChangeFocus(null); return true; } + if (HasFocus) + { + bindTarget.UpdateKeyCombination(state.Keyboard.Keys.ToArray()); + if (!isModifier(args.Key)) + finalise(); + return true; + } + return base.OnKeyDown(state, args); } + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + if (HasFocus) + { + finalise(); + return true; + } + + return base.OnKeyUp(state, args); + } + + private void finalise() + { + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + } + protected override void OnFocusLost(InputState state) { bindTarget.IsBinding = false; bindTarget = null; - reloadBindings(); pressAKey.FadeOut(300, Easing.OutQuint); pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; @@ -197,19 +213,16 @@ namespace osu.Game.Overlays.KeyBinding get { return isBinding; } set { + if (value == isBinding) return; isBinding = value; - if (value) + if (isBinding) { box.FadeColour(Color4.White, transition_time, Easing.OutQuint); Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - } else - { - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - } + updateHoverState(); } } @@ -261,25 +274,29 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnHover(InputState state) { - if (isBinding) - return false; - - box.FadeColour(hoverColour, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - + if (!isBinding) + updateHoverState(); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - if (isBinding) - return; - - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - + if (!isBinding) + updateHoverState(); base.OnHoverLost(state); } + + private void updateHoverState() + { + box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + } + + public void UpdateKeyCombination(params Key[] newCombination) + { + KeyBinding.KeyCombination = newCombination; + Text.Text = KeyBinding.KeyCombination.ReadableString(); + } } } } \ No newline at end of file diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index 44c4d4ccdb..b040f5043b 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -2,7 +2,9 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; @@ -10,6 +12,8 @@ namespace osu.Game.Overlays { public class MainSettings : SettingsOverlay { + private readonly KeyBindingOverlay keyBindingOverlay; + protected override IEnumerable CreateSections() => new SettingsSection[] { new GeneralSection(), @@ -17,7 +21,7 @@ namespace osu.Game.Overlays new GameplaySection(), new AudioSection(), new SkinSection(), - new InputSection(), + new InputSection(keyBindingOverlay), new OnlineSection(), new MaintenanceSection(), new DebugSection(), @@ -26,8 +30,51 @@ namespace osu.Game.Overlays protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves"); protected override Drawable CreateFooter() => new SettingsFooter(); - public MainSettings() : base(true) + public MainSettings() + : base(true) { + keyBindingOverlay = new KeyBindingOverlay { Depth = 1 }; + keyBindingOverlay.StateChanged += keyBindingOverlay_StateChanged; + } + + public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible; + + private void keyBindingOverlay_StateChanged(VisibilityContainer container, Visibility visibility) + { + const float hidden_width = 120; + + switch (visibility) + { + case Visibility.Visible: + Background.FadeTo(0.9f, 500, Easing.OutQuint); + SectionsContainer.FadeOut(100); + ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint); + break; + case Visibility.Hidden: + Background.FadeTo(0.6f, 500, Easing.OutQuint); + SectionsContainer.FadeIn(500, Easing.OutQuint); + ContentContainer.MoveToX(0, 500, Easing.OutQuint); + break; + } + } + + protected override void PopOut() + { + base.PopOut(); + keyBindingOverlay.State = Visibility.Hidden; + } + + [BackgroundDependencyLoader] + private void load() + { + AddInternal(keyBindingOverlay); + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X }; } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs index 9ead4ca7a4..01e73d0168 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs @@ -10,14 +10,15 @@ namespace osu.Game.Overlays.Settings.Sections.Input { protected override string Header => "Keyboard"; - public KeyboardSettings() + public KeyboardSettings(KeyBindingOverlay keyConfig) { Children = new Drawable[] { new OsuButton { RelativeSizeAxes = Axes.X, - Text = "Key Configuration" + Text = "Key Configuration", + Action = () => keyConfig.ToggleVisibility() }, }; } diff --git a/osu.Game/Overlays/Settings/Sections/InputSection.cs b/osu.Game/Overlays/Settings/Sections/InputSection.cs index 65df3746b3..5ece8aad77 100644 --- a/osu.Game/Overlays/Settings/Sections/InputSection.cs +++ b/osu.Game/Overlays/Settings/Sections/InputSection.cs @@ -12,12 +12,12 @@ namespace osu.Game.Overlays.Settings.Sections public override string Header => "Input"; public override FontAwesome Icon => FontAwesome.fa_keyboard_o; - public InputSection() + public InputSection(KeyBindingOverlay keyConfig) { Children = new Drawable[] { new MouseSettings(), - new KeyboardSettings(), + new KeyboardSettings(keyConfig), }; } } diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index 76f9ef3326..f62087ee71 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -29,6 +29,10 @@ namespace osu.Game.Overlays private const float sidebar_padding = 10; + protected Container ContentContainer; + + protected override Container Content => ContentContainer; + private Sidebar sidebar; private SidebarButton selectedSidebarButton; @@ -40,6 +44,8 @@ namespace osu.Game.Overlays private readonly bool showSidebar; + protected Box Background; + protected SettingsOverlay(bool showSidebar) { this.showSidebar = showSidebar; @@ -52,40 +58,43 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game) { - Children = new Drawable[] + InternalChild = ContentContainer = new Container { - new Box + Width = width, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - Alpha = 0.6f, - }, - SectionsContainer = new SettingsSectionsContainer - { - RelativeSizeAxes = Axes.Y, - Width = width, - Margin = new MarginPadding { Left = SIDEBAR_WIDTH }, - ExpandableHeader = CreateHeader(), - FixedHeader = searchTextBox = new SearchTextBox + Background = new Box { - RelativeSizeAxes = Axes.X, - Origin = Anchor.TopCentre, - Anchor = Anchor.TopCentre, - Width = 0.95f, - Margin = new MarginPadding - { - Top = 20, - Bottom = 20 - }, - Exit = Hide, + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.6f, }, - Footer = CreateFooter() - }, + SectionsContainer = new SettingsSectionsContainer + { + RelativeSizeAxes = Axes.Both, + ExpandableHeader = CreateHeader(), + FixedHeader = searchTextBox = new SearchTextBox + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Width = 0.95f, + Margin = new MarginPadding + { + Top = 20, + Bottom = 20 + }, + Exit = Hide, + }, + Footer = CreateFooter() + }, + } }; if (showSidebar) { - Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); + AddInternal(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); SectionsContainer.SelectedSection.ValueChanged += section => { @@ -136,7 +145,7 @@ namespace osu.Game.Overlays { base.PopIn(); - SectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); + ContentContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(1, TRANSITION_LENGTH / 2); @@ -147,7 +156,7 @@ namespace osu.Game.Overlays { base.PopOut(); - SectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); + ContentContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(0, TRANSITION_LENGTH / 2); @@ -170,8 +179,8 @@ namespace osu.Game.Overlays { base.UpdateAfterChildren(); - SectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; - SectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; + ContentContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; + ContentContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; } protected class SettingsSectionsContainer : SectionsContainer From 71f83dbdfa606541b163d9cc17130bffb884560e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 20:16:40 +0900 Subject: [PATCH 51/83] Add null check for safety --- .../Settings/Sections/Audio/AudioDevicesSettings.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs index 47f7abf571..9b1c5e5e49 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs @@ -26,8 +26,11 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { base.Dispose(isDisposing); - audio.OnNewDevice -= onDeviceChanged; - audio.OnLostDevice -= onDeviceChanged; + if (audio != null) + { + audio.OnNewDevice -= onDeviceChanged; + audio.OnLostDevice -= onDeviceChanged; + } } private void updateItems() From c41ba7b7042eee8ac1d66839bbb5c6f0c6393451 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 22:55:13 +0900 Subject: [PATCH 52/83] Update with latest framework changes --- .../Bindings/GlobalKeyBindingInputManager.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index 4dff25d509..e9eab49c32 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using osu.Framework.Graphics; -using osu.Framework.Input; using osu.Framework.Input.Bindings; namespace osu.Game.Input.Bindings @@ -31,23 +30,7 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), }; - protected override bool PropagateKeyDown(IEnumerable drawables, InputState state, KeyDownEventArgs args) - { - if (handler != null) - drawables = new[] { handler }.Concat(drawables); - - // always handle ourselves before all children. - return base.PropagateKeyDown(drawables, state, args); - } - - protected override bool PropagateKeyUp(IEnumerable drawables, InputState state, KeyUpEventArgs args) - { - if (handler != null) - drawables = new[] { handler }.Concat(drawables); - - // always handle ourselves before all children. - return base.PropagateKeyUp(drawables, state, args); - } + protected override IEnumerable GetKeyboardInputQueue() => new[] { handler }.Concat(base.GetKeyboardInputQueue()); } public enum GlobalAction From e64f455ff74d14fcf31f417d8406cc0f86e24241 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:01:10 +0900 Subject: [PATCH 53/83] Escape to cancel, again --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 3415c22972..274619991c 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -142,12 +142,16 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (args.Key == Key.Delete) + switch (args.Key) { - bindTarget.UpdateKeyCombination(Key.Unknown); - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); - return true; + case Key.Escape: + GetContainingInputManager().ChangeFocus(null); + return true; + case Key.Delete: + bindTarget.UpdateKeyCombination(Key.Unknown); + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + return true; } if (HasFocus) From 09089a31260122e1385aa58acbdcbc6bb781731d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:20:08 +0900 Subject: [PATCH 54/83] Fix potential nullref --- osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index e9eab49c32..31be2e6adc 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -30,7 +30,8 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), }; - protected override IEnumerable GetKeyboardInputQueue() => new[] { handler }.Concat(base.GetKeyboardInputQueue()); + protected override IEnumerable GetKeyboardInputQueue() => + handler == null ? base.GetKeyboardInputQueue() : new[] { handler }.Concat(base.GetKeyboardInputQueue()); } public enum GlobalAction From 0c19202b9aff2371e5daef1f7d3d3e6236902b8f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:20:18 +0900 Subject: [PATCH 55/83] Add basic back button --- osu.Game/Overlays/MainSettings.cs | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index b040f5043b..6302c56018 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -5,14 +5,21 @@ using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; +using osu.Game.Screens.Ranking; +using OpenTK; namespace osu.Game.Overlays { public class MainSettings : SettingsOverlay { private readonly KeyBindingOverlay keyBindingOverlay; + private BackButton backButton; protected override IEnumerable CreateSections() => new SettingsSection[] { @@ -49,11 +56,15 @@ namespace osu.Game.Overlays Background.FadeTo(0.9f, 500, Easing.OutQuint); SectionsContainer.FadeOut(100); ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint); + + backButton.Delay(100).FadeIn(100); break; case Visibility.Hidden: Background.FadeTo(0.6f, 500, Easing.OutQuint); SectionsContainer.FadeIn(500, Easing.OutQuint); ContentContainer.MoveToX(0, 500, Easing.OutQuint); + + backButton.FadeOut(100); break; } } @@ -68,6 +79,14 @@ namespace osu.Game.Overlays private void load() { AddInternal(keyBindingOverlay); + AddInternal(backButton = new BackButton + { + Alpha = 0, + Height = 150, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Action = () => keyBindingOverlay.Hide() + }); } protected override void UpdateAfterChildren() @@ -75,6 +94,81 @@ namespace osu.Game.Overlays base.UpdateAfterChildren(); keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X }; + + backButton.Margin = new MarginPadding { Left = ContentContainer.Margin.Left }; + backButton.Width = ContentContainer.DrawWidth + ContentContainer.X; + } + + private class BackButton : OsuClickableContainer + { + private FillFlowContainer flow; + private AspectContainer aspect; + + [BackgroundDependencyLoader] + private void load() + { + Children = new Drawable[] + { + aspect = new AspectContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] + { + flow = new FillFlowContainer + { + Anchor = Anchor.TopCentre, + RelativePositionAxes = Axes.Y, + Y = 0.4f, + AutoSizeAxes = Axes.Both, + Origin = Anchor.Centre, + Direction = FillDirection.Horizontal, + Children = new[] + { + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + } + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + RelativePositionAxes = Axes.Y, + Y = 0.7f, + TextSize = 12, + Font = @"Exo2.0-Bold", + Origin = Anchor.Centre, + Text = @"back", + }, + } + } + }; + } + + protected override bool OnHover(InputState state) + { + flow.TransformSpacingTo(new Vector2(5), 500, Easing.OutQuint); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + flow.TransformSpacingTo(new Vector2(0), 500, Easing.OutQuint); + base.OnHoverLost(state); + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + aspect.ScaleTo(0.75f, 2000, Easing.OutQuint); + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + aspect.ScaleTo(1, 1000, Easing.OutElastic); + return base.OnMouseUp(state, args); + } } } } \ No newline at end of file From c6c9c5431fe19c4638d24877bb3c7cbced88b7c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:22:12 +0900 Subject: [PATCH 56/83] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index acb9bfb084..68e461df82 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit acb9bfb084b5607ff31c6269cb7942fa02624b75 +Subproject commit 68e461df82a608d5748e758101f99f9d3081f8b6 From 94d664a626c5e368d1e00b67e676f2dcf854cafd Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Wed, 16 Aug 2017 17:00:30 +0200 Subject: [PATCH 57/83] Swap the order of the social and chat toolbar buttons --- osu.Game/Overlays/Toolbar/Toolbar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index 1ecfe90aa1..aca1051c7c 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -60,8 +60,8 @@ namespace osu.Game.Overlays.Toolbar AutoSizeAxes = Axes.X, Children = new Drawable[] { - new ToolbarSocialButton(), new ToolbarChatButton(), + new ToolbarSocialButton(), new ToolbarMusicButton(), new ToolbarButton { From 8c05a40fbfd5decac27b45ecea116d6ce4c23dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 16 Aug 2017 01:10:09 +0900 Subject: [PATCH 58/83] Use SliderStep instead of TestCaseSliderBar This greatly simplifies TestCaseKeyCounter and TestCaseHitObject and allows more future automation. --- .../Visual/TestCaseHitObjects.cs | 27 ++----------------- .../Visual/TestCaseKeyCounter.cs | 27 +++---------------- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs index df5f9f65b8..8dfaa7ea3d 100644 --- a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs @@ -27,35 +27,13 @@ namespace osu.Desktop.Tests.Visual { var rateAdjustClock = new StopwatchClock(true); framedClock = new FramedClock(rateAdjustClock); - playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; - - playbackSpeed.TriggerChange(); AddStep(@"circles", () => loadHitobjects(HitObjectType.Circle)); AddStep(@"slider", () => loadHitobjects(HitObjectType.Slider)); AddStep(@"spinner", () => loadHitobjects(HitObjectType.Spinner)); - AddToggleStep(@"auto", state => { auto = state; loadHitobjects(mode); }); - - BasicSliderBar sliderBar; - Add(new Container - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SpriteText { Text = "Playback Speed" }, - sliderBar = new BasicSliderBar - { - Width = 150, - Height = 10, - SelectionColor = Color4.Orange, - } - } - }); - - sliderBar.Current.BindTo(playbackSpeed); + AddToggleStep("Auto", state => { auto = state; loadHitobjects(mode); }); + AddSliderStep("Playback speed", 0.0, 2.0, 0.5, v => rateAdjustClock.Rate = v); framedClock.ProcessFrame(); @@ -75,7 +53,6 @@ namespace osu.Desktop.Tests.Visual private HitObjectType mode = HitObjectType.Slider; - private readonly BindableNumber playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; private readonly Container playfieldContainer; private readonly Container approachContainer; diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs index efb662d3b9..f0c77659eb 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs @@ -34,34 +34,13 @@ namespace osu.Desktop.Tests.Visual new KeyCounterMouse(MouseButton.Right), }, }; - BindableInt bindable = new BindableInt { MinValue = 0, MaxValue = 200, Default = 50 }; - bindable.ValueChanged += delegate { kc.FadeTime = bindable.Value; }; - AddStep("Add Random", () => + + AddStep("Add random", () => { Key key = (Key)((int)Key.A + RNG.Next(26)); kc.Add(new KeyCounterKeyboard(key)); }); - - TestSliderBar sliderBar; - - Add(new Container - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SpriteText { Text = "FadeTime" }, - sliderBar = new TestSliderBar - { - Width = 150, - Height = 10, - SelectionColor = Color4.Orange, - } - } - }); - - sliderBar.Current.BindTo(bindable); + AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v); Add(kc); } From 55b159b976208e72c422d5353639ae8f7fb3628a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 16 Aug 2017 13:02:11 +0900 Subject: [PATCH 59/83] Remove unnecessary usings --- osu.Desktop.Tests/Visual/TestCaseHitObjects.cs | 4 ---- osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs | 3 --- 2 files changed, 7 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs index 8dfaa7ea3d..75e1a656de 100644 --- a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs @@ -2,18 +2,14 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; using osu.Framework.Timing; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using OpenTK; -using OpenTK.Graphics; namespace osu.Desktop.Tests.Visual { diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs index f0c77659eb..1861a77a3a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs @@ -1,11 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.MathUtils; using osu.Game.Screens.Play; From 118d0f09704483c7d8ba03735d1085891d1c3e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 17 Aug 2017 07:28:07 +0900 Subject: [PATCH 60/83] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index acb9bfb084..5c22092e59 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit acb9bfb084b5607ff31c6269cb7942fa02624b75 +Subproject commit 5c22092e590d589927962b8d0173dae5f9b1405c From 4ef1be308037af1d4775b9c0d8a491d5ab2aae00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 17 Aug 2017 08:43:45 +0900 Subject: [PATCH 61/83] More localised key binding hover colour logic --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 274619991c..44aee0e666 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -220,13 +220,7 @@ namespace osu.Game.Overlays.KeyBinding if (value == isBinding) return; isBinding = value; - if (isBinding) - { - box.FadeColour(Color4.White, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - } - else - updateHoverState(); + updateHoverState(); } } @@ -278,22 +272,28 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnHover(InputState state) { - if (!isBinding) - updateHoverState(); + updateHoverState(); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - if (!isBinding) - updateHoverState(); + updateHoverState(); base.OnHoverLost(state); } private void updateHoverState() { - box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + if (isBinding) + { + box.FadeColour(Color4.White, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + } + else + { + box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + } } public void UpdateKeyCombination(params Key[] newCombination) From cceeb864d505cb492284726d98a763bac2190d0c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 17 Aug 2017 12:16:33 +0900 Subject: [PATCH 62/83] Fix hitobjects in TestCaseHitObjects not receiving actions. --- osu.Desktop.Tests/Visual/TestCaseHitObjects.cs | 14 +++++++++----- .../Bindings/DatabasedKeyBindingInputManager.cs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs index 75e1a656de..13e05d6477 100644 --- a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs @@ -10,16 +10,20 @@ using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using OpenTK; +using osu.Game.Rulesets.Osu; +using osu.Framework.Allocation; +using osu.Game.Rulesets; namespace osu.Desktop.Tests.Visual { internal class TestCaseHitObjects : OsuTestCase { - private readonly FramedClock framedClock; + private FramedClock framedClock; private bool auto; - public TestCaseHitObjects() + [BackgroundDependencyLoader] + private void load(RulesetStore rulesets) { var rateAdjustClock = new StopwatchClock(true); framedClock = new FramedClock(rateAdjustClock); @@ -39,7 +43,7 @@ namespace osu.Desktop.Tests.Visual Clock = framedClock, Children = new[] { - playfieldContainer = new Container { RelativeSizeAxes = Axes.Both }, + playfieldContainer = new OsuInputManager(rulesets.GetRuleset(0)) { RelativeSizeAxes = Axes.Both }, approachContainer = new Container { RelativeSizeAxes = Axes.Both } } }; @@ -49,8 +53,8 @@ namespace osu.Desktop.Tests.Visual private HitObjectType mode = HitObjectType.Slider; - private readonly Container playfieldContainer; - private readonly Container approachContainer; + private Container playfieldContainer; + private Container approachContainer; private void loadHitobjects(HitObjectType mode) { diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index 89aee7ca4d..f739ba2a59 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -17,7 +17,7 @@ namespace osu.Game.Input.Bindings { private readonly RulesetInfo ruleset; - private readonly int? variant; + private readonly int variant; private KeyBindingStore store; @@ -29,7 +29,7 @@ namespace osu.Game.Input.Bindings /// A reference to identify the current . Used to lookup mappings. Null for global mappings. /// An optional variant for the specified . Used when a ruleset has more than one possible keyboard layouts. /// Specify how to deal with multiple matches of s and s. - protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int? variant = null, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None) + protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int variant = 0, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None) : base(simultaneousMode) { this.ruleset = ruleset; From a19fc28cffffa12cf8b44a2e42b73b62f7e1d29b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 17 Aug 2017 17:31:14 +0900 Subject: [PATCH 63/83] Visually improve settings transitions and back button --- osu.Game/OsuGame.cs | 6 +- osu.Game/Overlays/MainSettings.cs | 88 ++++++++++------------------ osu.Game/Overlays/SettingsOverlay.cs | 49 +++++++++------- 3 files changed, 66 insertions(+), 77 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0d1e8396e4..e3525e423c 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -182,7 +182,11 @@ namespace osu.Game LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); - LoadComponentAsync(settings = new MainSettings { Depth = -1 }, overlayContent.Add); + LoadComponentAsync(settings = new MainSettings + { + GetToolbarHeight = () => ToolbarOffset, + Depth = -1 + }, overlayContent.Add); LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add); LoadComponentAsync(musicController = new MusicController { diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index 6302c56018..f2011ae88e 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -13,6 +13,7 @@ using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; using osu.Game.Screens.Ranking; using OpenTK; +using OpenTK.Graphics; namespace osu.Game.Overlays { @@ -40,27 +41,34 @@ namespace osu.Game.Overlays public MainSettings() : base(true) { - keyBindingOverlay = new KeyBindingOverlay { Depth = 1 }; + keyBindingOverlay = new KeyBindingOverlay { + Depth = 1, + Anchor = Anchor.TopRight, + }; keyBindingOverlay.StateChanged += keyBindingOverlay_StateChanged; } public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible; + private const float hidden_width = 120; + private void keyBindingOverlay_StateChanged(VisibilityContainer container, Visibility visibility) { - const float hidden_width = 120; - switch (visibility) { case Visibility.Visible: - Background.FadeTo(0.9f, 500, Easing.OutQuint); - SectionsContainer.FadeOut(100); - ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint); + Background.FadeTo(0.9f, 300, Easing.OutQuint); + Sidebar?.FadeColour(Color4.DarkGray, 300, Easing.OutQuint); + + SectionsContainer.FadeOut(300, Easing.OutQuint); + ContentContainer.MoveToX(hidden_width - WIDTH, 500, Easing.OutQuint); backButton.Delay(100).FadeIn(100); break; case Visibility.Hidden: Background.FadeTo(0.6f, 500, Easing.OutQuint); + Sidebar?.FadeColour(Color4.White, 300, Easing.OutQuint); + SectionsContainer.FadeIn(500, Easing.OutQuint); ContentContainer.MoveToX(0, 500, Easing.OutQuint); @@ -69,39 +77,26 @@ namespace osu.Game.Overlays } } - protected override void PopOut() - { - base.PopOut(); - keyBindingOverlay.State = Visibility.Hidden; - } + protected override float ExpandedPosition => keyBindingOverlay.State == Visibility.Visible ? hidden_width - WIDTH : base.ExpandedPosition; [BackgroundDependencyLoader] private void load() { - AddInternal(keyBindingOverlay); - AddInternal(backButton = new BackButton + ContentContainer.Add(keyBindingOverlay); + + ContentContainer.Add(backButton = new BackButton { Alpha = 0, - Height = 150, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, + Width = hidden_width, + RelativeSizeAxes = Axes.Y, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, Action = () => keyBindingOverlay.Hide() }); } - protected override void UpdateAfterChildren() - { - base.UpdateAfterChildren(); - - keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X }; - - backButton.Margin = new MarginPadding { Left = ContentContainer.Margin.Left }; - backButton.Width = ContentContainer.DrawWidth + ContentContainer.X; - } - private class BackButton : OsuClickableContainer { - private FillFlowContainer flow; private AspectContainer aspect; [BackgroundDependencyLoader] @@ -116,29 +111,22 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Children = new Drawable[] { - flow = new FillFlowContainer + new SpriteIcon { - Anchor = Anchor.TopCentre, - RelativePositionAxes = Axes.Y, - Y = 0.4f, - AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, Origin = Anchor.Centre, - Direction = FillDirection.Horizontal, - Children = new[] - { - new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, - new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, - new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, - } + Y = -15, + Size = new Vector2(15), + Shadow = true, + Icon = FontAwesome.fa_chevron_left }, new OsuSpriteText { - Anchor = Anchor.TopCentre, - RelativePositionAxes = Axes.Y, - Y = 0.7f, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Y = 15, TextSize = 12, Font = @"Exo2.0-Bold", - Origin = Anchor.Centre, Text = @"back", }, } @@ -146,18 +134,6 @@ namespace osu.Game.Overlays }; } - protected override bool OnHover(InputState state) - { - flow.TransformSpacingTo(new Vector2(5), 500, Easing.OutQuint); - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - flow.TransformSpacingTo(new Vector2(0), 500, Easing.OutQuint); - base.OnHoverLost(state); - } - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { aspect.ScaleTo(0.75f, 2000, Easing.OutQuint); @@ -171,4 +147,4 @@ namespace osu.Game.Overlays } } } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index f62087ee71..43720e12b2 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Extensions.IEnumerableExtensions; @@ -25,7 +26,7 @@ namespace osu.Game.Overlays public const float SIDEBAR_WIDTH = Sidebar.DEFAULT_WIDTH; - private const float width = 400; + protected const float WIDTH = 400; private const float sidebar_padding = 10; @@ -33,14 +34,17 @@ namespace osu.Game.Overlays protected override Container Content => ContentContainer; - private Sidebar sidebar; + protected Sidebar Sidebar; private SidebarButton selectedSidebarButton; protected SettingsSectionsContainer SectionsContainer; private SearchTextBox searchTextBox; - private Func getToolbarHeight; + /// + /// Provide a source for the toolbar height. + /// + public Func GetToolbarHeight; private readonly bool showSidebar; @@ -60,12 +64,15 @@ namespace osu.Game.Overlays { InternalChild = ContentContainer = new Container { - Width = width, + Width = WIDTH, RelativeSizeAxes = Axes.Y, Children = new Drawable[] { Background = new Box { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Scale = new Vector2(2, 1), // over-extend to the left for transitions RelativeSizeAxes = Axes.Both, Colour = Color4.Black, Alpha = 0.6f, @@ -94,20 +101,18 @@ namespace osu.Game.Overlays if (showSidebar) { - AddInternal(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); + AddInternal(Sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); SectionsContainer.SelectedSection.ValueChanged += section => { selectedSidebarButton.Selected = false; - selectedSidebarButton = sidebar.Children.Single(b => b.Section == section); + selectedSidebarButton = Sidebar.Children.Single(b => b.Section == section); selectedSidebarButton.Selected = true; }; } searchTextBox.Current.ValueChanged += newValue => SectionsContainer.SearchContainer.SearchTerm = newValue; - getToolbarHeight = () => game?.ToolbarOffset ?? 0; - CreateSections()?.ForEach(AddSection); } @@ -115,7 +120,7 @@ namespace osu.Game.Overlays { SectionsContainer.Add(section); - if (sidebar != null) + if (Sidebar != null) { var button = new SidebarButton { @@ -123,15 +128,15 @@ namespace osu.Game.Overlays Action = s => { SectionsContainer.ScrollTo(s); - sidebar.State = ExpandedState.Contracted; + Sidebar.State = ExpandedState.Contracted; }, }; - sidebar.Add(button); + Sidebar.Add(button); if (selectedSidebarButton == null) { - selectedSidebarButton = sidebar.Children.First(); + selectedSidebarButton = Sidebar.Children.First(); selectedSidebarButton.Selected = true; } } @@ -145,20 +150,24 @@ namespace osu.Game.Overlays { base.PopIn(); - ContentContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); - sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); - this.FadeTo(1, TRANSITION_LENGTH / 2); + ContentContainer.MoveToX(ExpandedPosition, TRANSITION_LENGTH, Easing.OutQuint); + + Sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); + this.FadeTo(1, TRANSITION_LENGTH, Easing.OutQuint); searchTextBox.HoldFocus = true; } + protected virtual float ExpandedPosition => 0; + protected override void PopOut() { base.PopOut(); - ContentContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); - sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); - this.FadeTo(0, TRANSITION_LENGTH / 2); + ContentContainer.MoveToX(-WIDTH, TRANSITION_LENGTH, Easing.OutQuint); + + Sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); + this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint); searchTextBox.HoldFocus = false; if (searchTextBox.HasFocus) @@ -179,8 +188,8 @@ namespace osu.Game.Overlays { base.UpdateAfterChildren(); - ContentContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; - ContentContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; + ContentContainer.Margin = new MarginPadding { Left = Sidebar?.DrawWidth ?? 0 }; + ContentContainer.Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 }; } protected class SettingsSectionsContainer : SectionsContainer From a44ff5a2c2ed1ac3396e488df6812030a44bb1f2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 17 Aug 2017 17:47:44 +0900 Subject: [PATCH 64/83] Fix regression causing global hotkeys to no longer work --- osu.Game.Rulesets.Catch/CatchInputManager.cs | 2 +- osu.Game.Rulesets.Osu/OsuInputManager.cs | 2 +- .../Input/Bindings/DatabasedKeyBindingInputManager.cs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchInputManager.cs b/osu.Game.Rulesets.Catch/CatchInputManager.cs index 683724b7b8..2a913a77d3 100644 --- a/osu.Game.Rulesets.Catch/CatchInputManager.cs +++ b/osu.Game.Rulesets.Catch/CatchInputManager.cs @@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Catch public class CatchInputManager : DatabasedKeyBindingInputManager { public CatchInputManager(RulesetInfo ruleset) - : base(ruleset, simultaneousMode: SimultaneousBindingMode.Unique) + : base(ruleset, 0, SimultaneousBindingMode.Unique) { } } diff --git a/osu.Game.Rulesets.Osu/OsuInputManager.cs b/osu.Game.Rulesets.Osu/OsuInputManager.cs index 06836994d2..a29b128e07 100644 --- a/osu.Game.Rulesets.Osu/OsuInputManager.cs +++ b/osu.Game.Rulesets.Osu/OsuInputManager.cs @@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Osu { public class OsuInputManager : DatabasedKeyBindingInputManager { - public OsuInputManager(RulesetInfo ruleset) : base(ruleset, simultaneousMode: SimultaneousBindingMode.Unique) + public OsuInputManager(RulesetInfo ruleset) : base(ruleset, 0, SimultaneousBindingMode.Unique) { } diff --git a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs index f739ba2a59..0a4fcf4389 100644 --- a/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Input.Bindings; @@ -17,7 +18,7 @@ namespace osu.Game.Input.Bindings { private readonly RulesetInfo ruleset; - private readonly int variant; + private readonly int? variant; private KeyBindingStore store; @@ -29,11 +30,14 @@ namespace osu.Game.Input.Bindings /// A reference to identify the current . Used to lookup mappings. Null for global mappings. /// An optional variant for the specified . Used when a ruleset has more than one possible keyboard layouts. /// Specify how to deal with multiple matches of s and s. - protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int variant = 0, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None) + protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int? variant = null, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None) : base(simultaneousMode) { this.ruleset = ruleset; this.variant = variant; + + if (ruleset != null && variant == null) + throw new InvalidOperationException($"{nameof(variant)} can not be null when a non-null {nameof(ruleset)} is provided."); } [BackgroundDependencyLoader] From 58b1e9c95459b0ee7375db822ead8c74cb70b484 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 17 Aug 2017 17:47:55 +0900 Subject: [PATCH 65/83] Remove unused DI retrieval --- osu.Game/Overlays/SettingsOverlay.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index 43720e12b2..f9ec2f68b5 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -59,8 +59,8 @@ namespace osu.Game.Overlays protected virtual IEnumerable CreateSections() => null; - [BackgroundDependencyLoader(permitNulls: true)] - private void load(OsuGame game) + [BackgroundDependencyLoader] + private void load() { InternalChild = ContentContainer = new Container { From f459794665564d4b29d028dfd390a9daafee573e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 17 Aug 2017 18:11:15 +0900 Subject: [PATCH 66/83] Update MainSettings.cs --- osu.Game/Overlays/MainSettings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index f2011ae88e..b4d9cac045 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -41,7 +41,8 @@ namespace osu.Game.Overlays public MainSettings() : base(true) { - keyBindingOverlay = new KeyBindingOverlay { + keyBindingOverlay = new KeyBindingOverlay + { Depth = 1, Anchor = Anchor.TopRight, }; From df683d911480b987660233c11f322afd4d6b3832 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Thu, 17 Aug 2017 23:28:26 +0930 Subject: [PATCH 67/83] Fix multiple difficulty control points sharing the same time and thus confusing slider velocity calculations --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 46cbad2487..82f48d4361 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Legacy; @@ -331,6 +332,7 @@ namespace osu.Game.Beatmaps.Formats if (speedMultiplier != difficultyPoint.SpeedMultiplier) { + beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time); beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = time, From 61182092004e43ac597ef1492e29a7bc0acaf63a Mon Sep 17 00:00:00 2001 From: MrTheMake Date: Thu, 17 Aug 2017 18:46:16 +0200 Subject: [PATCH 68/83] Fix unlit initial state of the OnScreenDisplay --- osu.Game/Overlays/OnScreenDisplay.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index 746b6dd50f..dcab942522 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -258,7 +258,10 @@ namespace osu.Game.Overlays Type = EdgeEffectType.Glow, Radius = 8, }; + } + protected override void LoadComplete() + { updateGlow(); FinishTransforms(true); } From cc39aad7f8d05fc8f678d1763b998cb1abcab41c Mon Sep 17 00:00:00 2001 From: PoULkY Date: Fri, 18 Aug 2017 01:23:44 +0700 Subject: [PATCH 69/83] Fix OsuButton doesn't implement IFilterable --- osu.Game/Graphics/UserInterface/OsuButton.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterface/OsuButton.cs b/osu.Game/Graphics/UserInterface/OsuButton.cs index 3c454f2af2..5650fc6f48 100644 --- a/osu.Game/Graphics/UserInterface/OsuButton.cs +++ b/osu.Game/Graphics/UserInterface/OsuButton.cs @@ -7,6 +7,7 @@ using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; @@ -16,7 +17,7 @@ using osu.Game.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { - public class OsuButton : Button + public class OsuButton : Button, IFilterable { private Box hover; @@ -108,5 +109,15 @@ namespace osu.Game.Graphics.UserInterface Content.ScaleTo(1, 1000, Easing.OutElastic); return base.OnMouseUp(state, args); } + + public string[] FilterTerms => new[] { Text }; + + public bool MatchingFilter + { + set + { + this.FadeTo(value ? 1 : 0); + } + } } } \ No newline at end of file From e4b832e8a6be6ba801cec5d8e2d6228e86e7f9ed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Aug 2017 10:48:35 +0900 Subject: [PATCH 70/83] Fix a possible nullref when login fails --- osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs index 3f8b6186c4..7ae45159d9 100644 --- a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs @@ -171,7 +171,7 @@ namespace osu.Game.Overlays.Settings.Sections.General break; } - if (form != null) GetContainingInputManager().ChangeFocus(form); + if (form != null) GetContainingInputManager()?.ChangeFocus(form); } public override bool AcceptsFocus => true; From 243a6ca7745f59e256b531ca5034059ca55e644c Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 18 Aug 2017 13:27:16 +0900 Subject: [PATCH 71/83] Update OsuLegacyDecoder.cs --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 82f48d4361..093f607e0d 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Legacy; From a47b6526a2b7810d51adb2cc2f6d035b8e6d5cad Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 18 Aug 2017 14:40:36 +0900 Subject: [PATCH 72/83] Fix CI issues. --- osu.Game/Rulesets/RulesetInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 059f93645f..8d19b28a81 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets public bool Equals(RulesetInfo other) { - return this.ID == other.ID && this.Available == other.Available && this.Name == other.Name && this.InstantiationInfo == other.InstantiationInfo; + return ID == other?.ID && Available == other?.Available && Name == other?.Name && InstantiationInfo == other?.InstantiationInfo; } } -} \ No newline at end of file +} From 90885a31ae8f172fa89fa50279e2cde01ed3f9e7 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 18 Aug 2017 15:09:54 +0900 Subject: [PATCH 73/83] Round 2 of CI fixes. --- osu.Game/Rulesets/RulesetInfo.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 8d19b28a81..740369b1b6 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -22,9 +22,6 @@ namespace osu.Game.Rulesets public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this); - public bool Equals(RulesetInfo other) - { - return ID == other?.ID && Available == other?.Available && Name == other?.Name && InstantiationInfo == other?.InstantiationInfo; - } + public bool Equals(RulesetInfo other) => other != null && ID == other.ID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo; } } From 306c00e593089589c98ddeea266ffc87d4871037 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:26:48 +0930 Subject: [PATCH 74/83] Update framework to include PR #977 --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 5c22092e59..03b7608f21 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 5c22092e590d589927962b8d0173dae5f9b1405c +Subproject commit 03b7608f210b35dbcd3a811bda002e7a9334d081 From 9c6ca2d15928742fb2dbae1b56333d3656a2a7a9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:34:01 +0930 Subject: [PATCH 75/83] Add lazy weak property to DrawableOsuHitObject to find and cache the containing OsuInputManager, if it exists --- .../Objects/Drawables/DrawableOsuHitObject.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index ca1b44e1c7..c5d75f076b 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.ComponentModel; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; @@ -51,6 +52,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables protected virtual void UpdateCurrentState(ArmedState state) { } + + private WeakReference osuActionInputManager = new WeakReference(null); + internal OsuInputManager OsuActionInputManager + { + get + { + OsuInputManager target = null; + if (osuActionInputManager.TryGetTarget(out target)) return target; + target = GetContainingInputManager() as OsuInputManager; + osuActionInputManager.SetTarget(target); + return target; + } + } } public enum ComboResult From 9628c0b6d656a2a63a62b46f649344a80399a08b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:46:00 +0930 Subject: [PATCH 76/83] Change spinner to check currently pressed actions rather than implementing IKeyBindingHandler --- .../Objects/Drawables/DrawableSpinner.cs | 8 +++++ .../Objects/Drawables/Pieces/SpinnerDisc.cs | 34 +------------------ 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 4a0b8422f1..307ef5d636 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; @@ -165,6 +166,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables glow.Colour = colours.BlueDark; } + protected override void Update() + { + disc.Tracking = OsuActionInputManager.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton); + + base.Update(); + } + protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 1e56a2559a..80d4391718 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -12,7 +12,7 @@ using OpenTK.Graphics; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { - public class SpinnerDisc : CircularContainer, IHasAccentColour, IKeyBindingHandler + public class SpinnerDisc : CircularContainer, IHasAccentColour { private readonly Spinner spinner; @@ -73,39 +73,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces return base.OnMouseMove(state); } - public bool OnPressed(OsuAction action) - { - switch (action) - { - case OsuAction.LeftButton: - actionLeftButtonPressed = true; - break; - case OsuAction.RightButton: - actionRightButtonPressed = true; - break; - } - Tracking = actionLeftButtonPressed || actionRightButtonPressed; - return false; - } - - public bool OnReleased(OsuAction action) - { - switch (action) - { - case OsuAction.LeftButton: - actionLeftButtonPressed = false; - break; - case OsuAction.RightButton: - actionRightButtonPressed = false; - break; - } - Tracking = actionLeftButtonPressed || actionRightButtonPressed; - return false; - } - private Vector2 mousePosition; - private bool actionLeftButtonPressed; - private bool actionRightButtonPressed; private float lastAngle; private float currentRotation; From 90dacd9861809f715151bbcae699afc758914a3b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:49:10 +0930 Subject: [PATCH 77/83] Trim whitespace --- osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 307ef5d636..8473cc2453 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -169,7 +169,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables protected override void Update() { disc.Tracking = OsuActionInputManager.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton); - + base.Update(); } From 529732ea473093a5a7bbd4fcd27f94b09872fb83 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:58:01 +0930 Subject: [PATCH 78/83] More CI fixes --- .../Objects/Drawables/DrawableOsuHitObject.cs | 4 ++-- osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index c5d75f076b..cca91925f0 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -53,12 +53,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { } - private WeakReference osuActionInputManager = new WeakReference(null); + private readonly WeakReference osuActionInputManager = new WeakReference(null); internal OsuInputManager OsuActionInputManager { get { - OsuInputManager target = null; + OsuInputManager target; if (osuActionInputManager.TryGetTarget(out target)) return target; target = GetContainingInputManager() as OsuInputManager; osuActionInputManager.SetTarget(target); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 80d4391718..6577c7fd50 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -5,7 +5,6 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; -using osu.Framework.Input.Bindings; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; From 4901ac9e35f7c0cd4f23b15c30461e2593ea43df Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 18:01:18 +0930 Subject: [PATCH 79/83] Add some comments explaining why the Track is being forcefully added to the TrackManager --- osu.Game/Screens/Select/SongSelect.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index e20ddf1c09..aa554152f9 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -370,6 +370,8 @@ namespace osu.Game.Screens.Select if (!track.IsRunning) { + // Ensure the track is added to the TrackManager, since it is removed after the player finishes the map. + // Using AddItemToList rather than AddItem so that it doesn't attempt to register adjustment dependencies more than once. Game.Audio.Track.AddItemToList(track); if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); track.Start(); From 44feef78f14f4d13c7cd173cef22af6980e34bb9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 19:32:08 +0930 Subject: [PATCH 80/83] Simplify OsuActionInputManager property --- .../Objects/Drawables/DrawableOsuHitObject.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index cca91925f0..409244998e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -53,18 +53,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { } - private readonly WeakReference osuActionInputManager = new WeakReference(null); - internal OsuInputManager OsuActionInputManager - { - get - { - OsuInputManager target; - if (osuActionInputManager.TryGetTarget(out target)) return target; - target = GetContainingInputManager() as OsuInputManager; - osuActionInputManager.SetTarget(target); - return target; - } - } + private OsuInputManager osuActionInputManager; + internal OsuInputManager OsuActionInputManager => osuActionInputManager ?? (osuActionInputManager = GetContainingInputManager() as OsuInputManager); } public enum ComboResult From 9558d2a16185c5e1b3b2dd8e96f779970df100a9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 19:39:28 +0930 Subject: [PATCH 81/83] Remove unnecessary using --- osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index 409244998e..b3043d18f6 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.ComponentModel; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; From 7e0fe6cbcbafbe0fce0bd6ebaf1d814b5423f9e6 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 20:19:23 +0930 Subject: [PATCH 82/83] Fix slider tracking to use pressed actions rather than directly querying the mouse buttons --- osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs index dbfd9b291b..bdf67a48cc 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SliderBall.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -118,7 +119,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces base.Update(); if (Time.Current < slider.EndTime) - Tracking = canCurrentlyTrack && lastState != null && ReceiveMouseInputAt(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed; + Tracking = canCurrentlyTrack && lastState != null && ReceiveMouseInputAt(lastState.Mouse.NativeState.Position) && ((Parent as DrawableSlider)?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false); } public void UpdateProgress(double progress, int repeat) From d6249e7a633a4df5d504728c7af5404fd8d284d1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Aug 2017 18:22:00 +0900 Subject: [PATCH 83/83] Add support for binding mouse buttons to actions --- osu-framework | 2 +- osu.Game.Rulesets.Catch/CatchRuleset.cs | 12 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 8 +- .../Bindings/GlobalKeyBindingInputManager.cs | 17 ++- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 126 ++++++++++++------ .../Overlays/KeyBinding/KeyBindingsSection.cs | 5 +- 6 files changed, 111 insertions(+), 59 deletions(-) diff --git a/osu-framework b/osu-framework index 03b7608f21..825505e788 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 03b7608f210b35dbcd3a811bda002e7a9334d081 +Subproject commit 825505e788c4f093b269c61b485d38d50cd68096 diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index b486566b7d..f7662030fc 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -23,12 +23,12 @@ namespace osu.Game.Rulesets.Catch public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] { - new KeyBinding(Key.Z, CatchAction.MoveLeft), - new KeyBinding(Key.Left, CatchAction.MoveLeft), - new KeyBinding(Key.X, CatchAction.MoveRight), - new KeyBinding(Key.Right, CatchAction.MoveRight), - new KeyBinding(Key.LShift, CatchAction.Dash), - new KeyBinding(Key.RShift, CatchAction.Dash), + new KeyBinding(InputKey.Z, CatchAction.MoveLeft), + new KeyBinding(InputKey.Left, CatchAction.MoveLeft), + new KeyBinding(InputKey.X, CatchAction.MoveRight), + new KeyBinding(InputKey.Right, CatchAction.MoveRight), + new KeyBinding(InputKey.Shift, CatchAction.Dash), + new KeyBinding(InputKey.Shift, CatchAction.Dash), }; public override IEnumerable GetModsFor(ModType type) diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 75b7be01a4..aaa1dff820 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -27,10 +27,10 @@ namespace osu.Game.Rulesets.Osu public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] { - new KeyBinding(Key.Z, OsuAction.LeftButton), - new KeyBinding(Key.X, OsuAction.RightButton), - new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton), - new KeyBinding(Key.LastKey + 2, OsuAction.RightButton), + new KeyBinding(InputKey.Z, OsuAction.LeftButton), + new KeyBinding(InputKey.X, OsuAction.RightButton), + new KeyBinding(InputKey.LastKey + 1, OsuAction.LeftButton), + new KeyBinding(InputKey.LastKey + 2, OsuAction.RightButton), }; public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index 31be2e6adc..5ea66fa600 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using OpenTK.Input; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -22,16 +21,16 @@ namespace osu.Game.Input.Bindings public override IEnumerable DefaultKeyBindings => new[] { - new KeyBinding(Key.F8, GlobalAction.ToggleChat), - new KeyBinding(Key.F9, GlobalAction.ToggleSocial), - new KeyBinding(new[] { Key.LControl, Key.LAlt, Key.R }, GlobalAction.ResetInputSettings), - new KeyBinding(new[] { Key.LControl, Key.T }, GlobalAction.ToggleToolbar), - new KeyBinding(new[] { Key.LControl, Key.O }, GlobalAction.ToggleSettings), - new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), + new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), + new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), + new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), + new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), + new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings), + new KeyBinding(new[] { InputKey.Control, InputKey.D }, GlobalAction.ToggleDirect), }; - protected override IEnumerable GetKeyboardInputQueue() => - handler == null ? base.GetKeyboardInputQueue() : new[] { handler }.Concat(base.GetKeyboardInputQueue()); + protected override IEnumerable KeyBindingInputQueue => + handler == null ? base.KeyBindingInputQueue : new[] { handler }.Concat(base.KeyBindingInputQueue); } public enum GlobalAction diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 44aee0e666..a3361743a1 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; +using osu.Framework.Input.Bindings; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Input; @@ -123,46 +124,74 @@ namespace osu.Game.Overlays.KeyBinding base.OnHoverLost(state); } - public override bool AcceptsFocus => true; + public override bool AcceptsFocus => bindTarget == null; private KeyButton bindTarget; - protected override void OnFocus(InputState state) - { - AutoSizeDuration = 500; - AutoSizeEasing = Easing.OutQuint; - - pressAKey.FadeIn(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding(); - - base.OnFocus(state); - } + public bool AllowMainMouseButtons; private bool isModifier(Key k) => k < Key.F1; - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - switch (args.Key) - { - case Key.Escape: - GetContainingInputManager().ChangeFocus(null); - return true; - case Key.Delete: - bindTarget.UpdateKeyCombination(Key.Unknown); - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); - return true; - } + protected override bool OnClick(InputState state) => true; + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { if (HasFocus) { - bindTarget.UpdateKeyCombination(state.Keyboard.Keys.ToArray()); - if (!isModifier(args.Key)) + if (bindTarget.IsHovered) + { + if (!AllowMainMouseButtons) + { + switch (args.Button) + { + case MouseButton.Left: + case MouseButton.Right: + return true; + } + } + + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); + return true; + } + } + + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (HasFocus && !state.Mouse.Buttons.Any()) + { + if (bindTarget.IsHovered) finalise(); + else + updateBindTarget(); return true; } - return base.OnKeyDown(state, args); + return base.OnMouseUp(state, args); + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (!HasFocus) + return false; + + switch (args.Key) + { + case Key.Escape: + finalise(); + return true; + case Key.Delete: + bindTarget.UpdateKeyCombination(InputKey.None); + finalise(); + return true; + } + + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); + if (!isModifier(args.Key)) finalise(); + + return true; } protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) @@ -178,27 +207,48 @@ namespace osu.Game.Overlays.KeyBinding private void finalise() { - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); + if (bindTarget != null) + { + store.Update(bindTarget.KeyBinding); + + bindTarget.IsBinding = false; + Schedule(() => + { + // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) + bindTarget = null; + }); + } + + if (HasFocus) + GetContainingInputManager().ChangeFocus(null); + + pressAKey.FadeOut(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + } + + protected override void OnFocus(InputState state) + { + AutoSizeDuration = 500; + AutoSizeEasing = Easing.OutQuint; + + pressAKey.FadeIn(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding(); + + updateBindTarget(); + base.OnFocus(state); } protected override void OnFocusLost(InputState state) { - bindTarget.IsBinding = false; - bindTarget = null; - - pressAKey.FadeOut(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + finalise(); base.OnFocusLost(state); } - protected override bool OnClick(InputState state) + private void updateBindTarget() { if (bindTarget != null) bindTarget.IsBinding = false; bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); if (bindTarget != null) bindTarget.IsBinding = true; - - return bindTarget != null; } private class KeyButton : Container @@ -296,7 +346,7 @@ namespace osu.Game.Overlays.KeyBinding } } - public void UpdateKeyCombination(params Key[] newCombination) + public void UpdateKeyCombination(KeyCombination newCombination) { KeyBinding.KeyCombination = newCombination; Text.Text = KeyBinding.KeyCombination.ReadableString(); diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs index 19baeca771..44c28ee9c8 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs @@ -40,7 +40,10 @@ namespace osu.Game.Overlays.KeyBinding foreach (Enum v in Enum.GetValues(enumType)) // one row per valid action. - Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v)))); + Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v))) + { + AllowMainMouseButtons = Ruleset != null + }); } } } \ No newline at end of file