From 5a694e0c9d20909d9265c57c6f1d8de307bf445a Mon Sep 17 00:00:00 2001 From: Jorolf Date: Mon, 3 Apr 2017 19:28:05 +0200 Subject: [PATCH] changed location of BarGraph to be more generic --- .../Tests/TestCaseBeatmapDetails.cs | 2 +- .../UserInterface/BarGraph.cs} | 45 ++++++++++++++++--- osu.Game/Screens/Select/BeatmapDetailArea.cs | 1 - .../Select/{Details => }/BeatmapDetails.cs | 35 ++++++++------- .../Select/Details/BeatmapDetailsGraph.cs | 41 ----------------- osu.Game/osu.Game.csproj | 9 ++-- 6 files changed, 63 insertions(+), 70 deletions(-) rename osu.Game/{Screens/Select/Details/BeatmapDetailsBar.cs => Graphics/UserInterface/BarGraph.cs} (66%) rename osu.Game/Screens/Select/{Details => }/BeatmapDetails.cs (92%) delete mode 100644 osu.Game/Screens/Select/Details/BeatmapDetailsGraph.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseBeatmapDetails.cs b/osu.Desktop.VisualTests/Tests/TestCaseBeatmapDetails.cs index 3a57c1bc87..1f7662306f 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseBeatmapDetails.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseBeatmapDetails.cs @@ -5,7 +5,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Framework.Testing; using osu.Game.Database; -using osu.Game.Screens.Select.Details; +using osu.Game.Screens.Select; using System; using System.Linq; diff --git a/osu.Game/Screens/Select/Details/BeatmapDetailsBar.cs b/osu.Game/Graphics/UserInterface/BarGraph.cs similarity index 66% rename from osu.Game/Screens/Select/Details/BeatmapDetailsBar.cs rename to osu.Game/Graphics/UserInterface/BarGraph.cs index d637903754..80412c41e5 100644 --- a/osu.Game/Screens/Select/Details/BeatmapDetailsBar.cs +++ b/osu.Game/Graphics/UserInterface/BarGraph.cs @@ -1,15 +1,48 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . +// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK; +using OpenTK.Graphics; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using System.Collections.Generic; +using System.Linq; -namespace osu.Game.Screens.Select.Details +namespace osu.Game.Graphics.UserInterface { - public class BeatmapDetailsBar : Container + public class BarGraph : FillFlowContainer + { + + public IEnumerable Values + { + set + { + List values = value.ToList(); + List graphBars = Children.ToList(); + for (int i = 0; i < values.Count; i++) + if (graphBars.Count > i) + { + graphBars[i].Length = values[i] / values.Max(); + graphBars[i].Width = 1.0f / values.Count; + } + else + Add(new Bar + { + RelativeSizeAxes = Axes.Both, + Width = 1.0f / values.Count, + Length = values[i] / values.Max(), + Direction = BarDirection.BottomToTop, + BackgroundColour = new Color4(0, 0, 0, 0), + }); + + } + } + + } + + public class Bar : Container { private readonly Box background; private readonly Box bar; @@ -27,7 +60,7 @@ namespace osu.Game.Screens.Select.Details } set { - length = MathHelper.Clamp(value,0,1); + length = MathHelper.Clamp(value, 0, 1); updateBarLength(); } } @@ -70,9 +103,9 @@ namespace osu.Game.Screens.Select.Details } } - public BeatmapDetailsBar() + public Bar() { - Children = new [] + Children = new[] { background = new Box { diff --git a/osu.Game/Screens/Select/BeatmapDetailArea.cs b/osu.Game/Screens/Select/BeatmapDetailArea.cs index c5dc7057bb..8387e39f67 100644 --- a/osu.Game/Screens/Select/BeatmapDetailArea.cs +++ b/osu.Game/Screens/Select/BeatmapDetailArea.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics.Primitives; using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Online.API.Requests; -using osu.Game.Screens.Select.Details; using osu.Game.Screens.Select.Leaderboards; namespace osu.Game.Screens.Select diff --git a/osu.Game/Screens/Select/Details/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs similarity index 92% rename from osu.Game/Screens/Select/Details/BeatmapDetails.cs rename to osu.Game/Screens/Select/BeatmapDetails.cs index cf50853691..6bc7fe5ca0 100644 --- a/osu.Game/Screens/Select/Details/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -12,11 +12,12 @@ using osu.Framework.Graphics.Sprites; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using System.Collections.Generic; using System.Globalization; using System.Linq; -namespace osu.Game.Screens.Select.Details +namespace osu.Game.Screens.Select { public class BeatmapDetails : Container { @@ -30,13 +31,13 @@ namespace osu.Game.Screens.Select.Details private readonly DifficultyRow approachRate; private readonly DifficultyRow stars; - private readonly BeatmapDetailsBar ratingsBar; + private readonly Bar ratingsBar; private readonly OsuSpriteText negativeRatings; private readonly OsuSpriteText positiveRatings; - private readonly BeatmapDetailsGraph ratingsGraph; + private readonly BarGraph ratingsGraph; - private readonly BeatmapDetailsGraph retryGraph; - private readonly BeatmapDetailsGraph failGraph; + private readonly BarGraph retryGraph; + private readonly BarGraph failGraph; private BeatmapInfo beatmap; public BeatmapInfo Beatmap @@ -267,7 +268,7 @@ namespace osu.Game.Screens.Select.Details Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, }, - ratingsBar = new BeatmapDetailsBar + ratingsBar = new Bar { RelativeSizeAxes = Axes.X, Height = 5, @@ -301,7 +302,7 @@ namespace osu.Game.Screens.Select.Details Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, }, - ratingsGraph = new BeatmapDetailsGraph + ratingsGraph = new BarGraph { RelativeSizeAxes = Axes.X, Direction = FillDirection.Horizontal, @@ -316,17 +317,17 @@ namespace osu.Game.Screens.Select.Details Text = "Points of Failure", Font = @"Exo2.0-Medium", }, - new Container + new Container { RelativeSizeAxes = Axes.X, Size = new Vector2(1/0.6f, 50), Children = new[] { - retryGraph = new BeatmapDetailsGraph + retryGraph = new BarGraph { RelativeSizeAxes = Axes.Both, }, - failGraph = new BeatmapDetailsGraph + failGraph = new BarGraph { RelativeSizeAxes = Axes.Both, }, @@ -357,7 +358,7 @@ namespace osu.Game.Screens.Select.Details private class DifficultyRow : Container { private readonly OsuSpriteText name; - private readonly BeatmapDetailsBar bar; + private readonly Bar bar; private readonly OsuSpriteText valueText; private float difficultyValue; @@ -421,7 +422,7 @@ namespace osu.Game.Screens.Select.Details { Font = @"Exo2.0-Medium", }, - bar = new BeatmapDetailsBar + bar = new Bar { Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, @@ -447,10 +448,10 @@ namespace osu.Game.Screens.Select.Details } } - private class RetryAndFailBar : Container + private class RetryAndFailBar : Container { - private readonly BeatmapDetailsBar retryBar; - private readonly BeatmapDetailsBar failBar; + private readonly Bar retryBar; + private readonly Bar failBar; public float RetryLength { @@ -480,14 +481,14 @@ namespace osu.Game.Screens.Select.Details { Children = new[] { - retryBar = new BeatmapDetailsBar + retryBar = new Bar { RelativeSizeAxes = Axes.Both, Direction = BarDirection.BottomToTop, Length = 0, BackgroundColour = new Color4(0,0,0,0), }, - failBar = new BeatmapDetailsBar + failBar = new Bar { RelativeSizeAxes = Axes.Both, Direction = BarDirection.BottomToTop, diff --git a/osu.Game/Screens/Select/Details/BeatmapDetailsGraph.cs b/osu.Game/Screens/Select/Details/BeatmapDetailsGraph.cs deleted file mode 100644 index 6a90ff60d1..0000000000 --- a/osu.Game/Screens/Select/Details/BeatmapDetailsGraph.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using OpenTK.Graphics; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using System.Collections.Generic; -using System.Linq; - -namespace osu.Game.Screens.Select.Details -{ - public class BeatmapDetailsGraph : FillFlowContainer - { - - public IEnumerable Values - { - set - { - List values = value.ToList(); - List graphBars = Children.ToList(); - for (int i = 0; i < values.Count; i++) - if (graphBars.Count > i) - { - graphBars[i].Length = values[i] / values.Max(); - graphBars[i].Width = 1.0f / values.Count; - } - else - Add(new BeatmapDetailsBar - { - RelativeSizeAxes = Axes.Both, - Width = 1.0f / values.Count, - Length = values[i] / values.Max(), - Direction = BarDirection.BottomToTop, - BackgroundColour = new Color4(0, 0, 0, 0), - }); - - } - } - - } -} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 360f8c9772..2e1ded6136 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -206,9 +206,8 @@ - - - + + @@ -391,7 +390,9 @@ - + + +