changed location of BarGraph to be more generic

This commit is contained in:
Jorolf
2017-04-03 19:28:05 +02:00
parent f3946bebb4
commit 5a694e0c9d
6 changed files with 63 additions and 70 deletions

View File

@ -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

View File

@ -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<BeatmapDetailsGraph>
new Container<BarGraph>
{
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<BeatmapDetailsBar>
private class RetryAndFailBar : Container<Bar>
{
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,

View File

@ -1,125 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Screens.Select.Details
{
public class BeatmapDetailsBar : Container
{
private readonly Box background;
private readonly Box bar;
private const int resize_duration = 250;
private const EasingTypes easing = EasingTypes.InOutCubic;
private float length;
public float Length
{
get
{
return length;
}
set
{
length = MathHelper.Clamp(value,0,1);
updateBarLength();
}
}
public SRGBColour BackgroundColour
{
get
{
return background.Colour;
}
set
{
background.Colour = value;
}
}
public SRGBColour BarColour
{
get
{
return bar.Colour;
}
set
{
bar.Colour = value;
}
}
private BarDirection direction = BarDirection.LeftToRight;
public BarDirection Direction
{
get
{
return direction;
}
set
{
direction = value;
updateBarLength();
}
}
public BeatmapDetailsBar()
{
Children = new []
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
bar = new Box
{
RelativeSizeAxes = Axes.Both,
}
};
}
private void updateBarLength()
{
switch (direction)
{
case BarDirection.LeftToRight:
case BarDirection.RightToLeft:
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
break;
case BarDirection.TopToBottom:
case BarDirection.BottomToTop:
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
break;
}
switch (direction)
{
case BarDirection.LeftToRight:
case BarDirection.TopToBottom:
bar.Anchor = Anchor.TopLeft;
bar.Origin = Anchor.TopLeft;
break;
case BarDirection.RightToLeft:
case BarDirection.BottomToTop:
bar.Anchor = Anchor.BottomRight;
bar.Origin = Anchor.BottomRight;
break;
}
}
}
public enum BarDirection
{
LeftToRight,
RightToLeft,
TopToBottom,
BottomToTop,
}
}

View File

@ -1,41 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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<BeatmapDetailsBar>
{
public IEnumerable<float> Values
{
set
{
List<float> values = value.ToList();
List<BeatmapDetailsBar> 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),
});
}
}
}
}