1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +08:00

Merge branch 'master' of git://github.com/ppy/osu into tooltips

This commit is contained in:
Jorolf 2017-04-17 14:45:46 +02:00
commit dd26f9fcac
26 changed files with 723 additions and 69 deletions

@ -1 +1 @@
Subproject commit 2234013e59a99116ee9f9e56a95ff8a6667db2a7
Subproject commit 979fb1ffdfaa08c39ff4f0cdda42e5b313d70534

@ -1 +1 @@
Subproject commit 0cba3cbc167cfe94e07fe5b629c925e190be939e
Subproject commit ce76f812d3e059233e1dea395b125352f638b2da

View File

@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -21,6 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -0,0 +1,49 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Modes.Objects;
using osu.Game.Screens.Play;
namespace osu.Desktop.VisualTests.Tests
{
internal class TestCaseSongProgress : TestCase
{
public override string Description => @"With fake data";
private SongProgress progress;
public override void Reset()
{
base.Reset();
Add(progress = new SongProgress
{
AudioClock = new StopwatchClock(true),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
});
AddStep("Toggle Bar", progress.ToggleBar);
AddWaitStep(5);
AddStep("Toggle Bar", progress.ToggleBar);
AddWaitStep(2);
AddRepeatStep("New Values", displayNewValues, 5);
displayNewValues();
}
private void displayNewValues()
{
List<HitObject> objects = new List<HitObject>();
for (double i = 0; i < 5000; i += RNG.NextDouble() * 10 + i / 1000)
objects.Add(new HitObject { StartTime = i });
progress.Objects = objects;
}
}
}

View File

@ -61,6 +61,7 @@
<RunCodeAnalysis>false</RunCodeAnalysis>
<Prefer32Bit>false</Prefer32Bit>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -208,6 +209,7 @@
<Compile Include="VisualTestGame.cs" />
<Compile Include="Platform\TestStorage.cs" />
<Compile Include="Tests\TestCaseOptions.cs" />
<Compile Include="Tests\TestCaseSongProgress.cs" />
<Compile Include="Tests\TestCaseModSelectOverlay.cs" />
<Compile Include="Tests\TestCaseDialogOverlay.cs" />
<Compile Include="Tests\TestCaseBeatmapOptionsOverlay.cs" />

View File

@ -63,6 +63,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Commandlineparameters>
</Commandlineparameters>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>

View File

@ -21,6 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -21,6 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -21,6 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -19,6 +19,7 @@
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>

View File

@ -10,10 +10,11 @@ using osu.Game.Graphics.Sprites;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using OpenTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public abstract class RollingCounter<T> : Container
public abstract class RollingCounter<T> : Container, IHasAccentColour
{
/// <summary>
/// The current value.
@ -80,6 +81,12 @@ namespace osu.Game.Graphics.UserInterface
}
}
public Color4 AccentColour
{
get { return DisplayedCountSpriteText.Colour; }
set { DisplayedCountSpriteText.Colour = value; }
}
/// <summary>
/// Skeleton of a numeric counter which value rolls over time.
/// </summary>
@ -109,8 +116,6 @@ namespace osu.Game.Graphics.UserInterface
base.LoadComplete();
DisplayedCountSpriteText.Text = FormatCount(Current);
DisplayedCountSpriteText.Anchor = Anchor;
DisplayedCountSpriteText.Origin = Origin;
}
/// <summary>

View File

@ -15,6 +15,8 @@ namespace osu.Game.Graphics.UserInterface
protected override double RollingDuration => 1000;
protected override EasingTypes RollingEasing => EasingTypes.Out;
public bool UseCommaSeparator;
/// <summary>
/// How many leading zeroes the counter has.
/// </summary>
@ -41,7 +43,12 @@ namespace osu.Game.Graphics.UserInterface
protected override string FormatCount(double count)
{
return ((long)count).ToString("D" + LeadingZeroes);
string format = new string('0', (int)LeadingZeroes);
if (UseCommaSeparator)
for (int i = format.Length - 3; i > 0; i -= 3)
format = format.Insert(i, @",");
return ((long)count).ToString(format);
}
public override void Increment(double amount)

View File

@ -0,0 +1,61 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
using osu.Framework.MathUtils;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// Used as an accuracy counter. Represented visually as a percentage.
/// </summary>
public class SimpleComboCounter : RollingCounter<int>
{
protected override Type TransformType => typeof(TransformCounterCount);
protected override double RollingDuration => 750;
public SimpleComboCounter()
{
Current.Value = DisplayedCount = 0;
}
protected override string FormatCount(int count)
{
return $@"{count}x";
}
protected override double GetProportionalDuration(int currentValue, int newValue)
{
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
}
public override void Increment(int amount)
{
Current.Value = Current + amount;
}
private class TransformCounterCount : Transform<int>
{
public override int CurrentValue
{
get
{
double time = Time?.Current ?? 0;
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;
return (int)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}
}
public override void Apply(Drawable d)
{
base.Apply(d);
((SimpleComboCounter)d).DisplayedCount = CurrentValue;
}
}
}
}

View File

@ -58,6 +58,8 @@ namespace osu.Game.Modes.UI
/// </summary>
public bool HasReplayLoaded => InputManager.ReplayInputHandler != null;
public abstract IEnumerable<HitObject> Objects { get; }
/// <summary>
/// Whether all the HitObjects have been judged.
/// </summary>
@ -185,6 +187,8 @@ namespace osu.Game.Modes.UI
private readonly Container content;
public override IEnumerable<HitObject> Objects => Beatmap.HitObjects;
protected HitRenderer(WorkingBeatmap beatmap)
: base(beatmap)
{

View File

@ -22,10 +22,11 @@ namespace osu.Game.Modes.UI
private readonly Container content;
public readonly KeyCounterCollection KeyCounter;
public readonly ComboCounter ComboCounter;
public readonly RollingCounter<int> ComboCounter;
public readonly ScoreCounter ScoreCounter;
public readonly PercentageCounter AccuracyCounter;
public readonly RollingCounter<double> AccuracyCounter;
public readonly HealthDisplay HealthDisplay;
public readonly SongProgress Progress;
private Bindable<bool> showKeyCounter;
private Bindable<bool> showHud;
@ -33,10 +34,11 @@ namespace osu.Game.Modes.UI
private static bool hasShownNotificationOnce;
protected abstract KeyCounterCollection CreateKeyCounter();
protected abstract ComboCounter CreateComboCounter();
protected abstract PercentageCounter CreateAccuracyCounter();
protected abstract RollingCounter<int> CreateComboCounter();
protected abstract RollingCounter<double> CreateAccuracyCounter();
protected abstract ScoreCounter CreateScoreCounter();
protected abstract HealthDisplay CreateHealthDisplay();
protected abstract SongProgress CreateProgress();
protected HudOverlay()
{
@ -53,6 +55,7 @@ namespace osu.Game.Modes.UI
ScoreCounter = CreateScoreCounter(),
AccuracyCounter = CreateAccuracyCounter(),
HealthDisplay = CreateHealthDisplay(),
Progress = CreateProgress(),
}
});
}

View File

@ -3,8 +3,6 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -12,10 +10,35 @@ using osu.Game.Graphics;
namespace osu.Game.Modes.UI
{
public class StandardHealthDisplay : HealthDisplay
public class StandardHealthDisplay : HealthDisplay, IHasAccentColour
{
private readonly Container fill;
public Color4 AccentColour
{
get { return fill.Colour; }
set { fill.Colour = value; }
}
private Color4 glowColour;
public Color4 GlowColour
{
get { return glowColour; }
set
{
if (glowColour == value)
return;
glowColour = value;
fill.EdgeEffect = new EdgeEffect
{
Colour = glowColour,
Radius = 8,
Type = EdgeEffectType.Glow
};
}
}
public StandardHealthDisplay()
{
Children = new Drawable[]
@ -41,18 +64,6 @@ namespace osu.Game.Modes.UI
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
fill.Colour = colours.BlueLighter;
fill.EdgeEffect = new EdgeEffect
{
Colour = colours.BlueDarker.Opacity(0.6f),
Radius = 8,
Type = EdgeEffectType.Glow
};
}
protected override void SetHealth(float value) => fill.ScaleTo(new Vector2(value, 1), 200, EasingTypes.OutQuint);
}
}

View File

@ -2,8 +2,11 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play;
@ -11,19 +14,22 @@ namespace osu.Game.Modes.UI
{
public class StandardHudOverlay : HudOverlay
{
protected override PercentageCounter CreateAccuracyCounter() => new PercentageCounter
protected override RollingCounter<double> CreateAccuracyCounter() => new PercentageCounter
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Position = new Vector2(0, 65),
Origin = Anchor.TopRight,
Position = new Vector2(0, 35),
TextSize = 20,
Margin = new MarginPadding { Right = 5 },
Margin = new MarginPadding { Right = 140 },
};
protected override ComboCounter CreateComboCounter() => new StandardComboCounter
protected override RollingCounter<int> CreateComboCounter() => new SimpleComboCounter
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopLeft,
Position = new Vector2(0, 35),
Margin = new MarginPadding { Left = 140 },
TextSize = 20,
};
protected override HealthDisplay CreateHealthDisplay() => new StandardHealthDisplay
@ -49,7 +55,28 @@ namespace osu.Game.Modes.UI
Origin = Anchor.TopCentre,
TextSize = 40,
Position = new Vector2(0, 30),
Margin = new MarginPadding { Right = 5 },
};
protected override SongProgress CreateProgress() => new SongProgress()
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
};
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
ComboCounter.AccentColour = colours.BlueLighter;
AccuracyCounter.AccentColour = colours.BlueLighter;
ScoreCounter.AccentColour = colours.BlueLighter;
var shd = HealthDisplay as StandardHealthDisplay;
if (shd != null)
{
shd.AccentColour = colours.BlueLighter;
shd.GlowColour = colours.BlueDarker.Opacity(0.6f);
}
}
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Overlays
{
public class DragBar : Container
{
private readonly Box fill;
protected readonly Container Fill;
public Action<float> SeekRequested;
@ -27,7 +27,7 @@ namespace osu.Game.Overlays
{
enabled = value;
if (!enabled)
fill.Width = 0;
Fill.Width = 0;
}
}
@ -37,12 +37,20 @@ namespace osu.Game.Overlays
Children = new Drawable[]
{
fill = new Box
Fill = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Name = "FillContainer",
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Width = 0
Width = 0,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both
}
}
}
};
}
@ -51,21 +59,23 @@ namespace osu.Game.Overlays
{
if (IsSeeking || !IsEnabled) return;
updatePosition(position);
updatePosition(position, false);
}
private void seek(InputState state)
{
if (!IsEnabled) return;
float seekLocation = state.Mouse.Position.X / DrawWidth;
if (!IsEnabled) return;
SeekRequested?.Invoke(seekLocation);
updatePosition(seekLocation);
}
private void updatePosition(float position)
private void updatePosition(float position, bool easing = true)
{
position = MathHelper.Clamp(position, 0, 1);
fill.TransformTo(() => fill.Width, position, 200, EasingTypes.OutQuint, new TransformSeek());
Fill.TransformTo(() => Fill.Width, position, easing ? 200 : 0, EasingTypes.OutQuint, new TransformSeek());
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)

View File

@ -35,7 +35,7 @@ namespace osu.Game.Screens.Play
public BeatmapInfo BeatmapInfo;
public bool IsPaused { get; private set; }
public bool IsPaused => !interpolatedSourceClock.IsRunning;
public bool HasFailed { get; private set; }
@ -44,7 +44,7 @@ namespace osu.Game.Screens.Play
private const double pause_cooldown = 1000;
private double lastPauseActionTime;
private bool canPause => Time.Current >= lastPauseActionTime + pause_cooldown;
private bool canPause => ValidForResume && !HasFailed && Time.Current >= lastPauseActionTime + pause_cooldown;
private IAdjustableClock sourceClock;
private IFrameBasedClock interpolatedSourceClock;
@ -63,9 +63,7 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader]
private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager config)
{
var beatmap = Beatmap.Beatmap;
if (beatmap.BeatmapInfo?.Mode > PlayMode.Taiko)
if (Beatmap.Beatmap.BeatmapInfo?.Mode > PlayMode.Taiko)
{
//we only support osu! mode for now because the hitobject parsing is crappy and needs a refactor.
Exit();
@ -126,6 +124,9 @@ namespace osu.Game.Screens.Play
hudOverlay.BindProcessor(scoreProcessor);
hudOverlay.BindHitRenderer(HitRenderer);
hudOverlay.Progress.Objects = HitRenderer.Objects;
hudOverlay.Progress.AudioClock = interpolatedSourceClock;
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
HitRenderer.OnAllJudged += onCompletion;
@ -204,34 +205,40 @@ namespace osu.Game.Screens.Play
public void Pause(bool force = false)
{
if (canPause || force)
if (!canPause && !force) return;
// the actual pausing is potentially happening on a different thread.
// we want to wait for the source clock to stop so we can be sure all components are in a stable state.
if (!IsPaused)
{
sourceClock.Stop();
Schedule(() => Pause(force));
return;
}
// we need to do a final check after all of our children have processed up to the paused clock time.
// this is to cover cases where, for instance, the player fails in the last processed frame (which would change canPause).
// as the scheduler runs before children updates, let's schedule for the next frame.
Schedule(() =>
{
if (!canPause) return;
lastPauseActionTime = Time.Current;
hudOverlay.KeyCounter.IsCounting = false;
hudOverlay.Progress.Show();
pauseOverlay.Retries = RestartCount;
pauseOverlay.Show();
sourceClock.Stop();
IsPaused = true;
}
else
{
IsPaused = false;
}
});
}
public void Resume()
{
lastPauseActionTime = Time.Current;
hudOverlay.KeyCounter.IsCounting = true;
hudOverlay.Progress.Hide();
pauseOverlay.Hide();
sourceClock.Start();
IsPaused = false;
}
public void TogglePaused()
{
IsPaused = !IsPaused;
if (IsPaused) Pause(); else Resume();
}
public void Restart()
@ -240,11 +247,11 @@ namespace osu.Game.Screens.Play
var newPlayer = new Player();
ValidForResume = false;
LoadComponentAsync(newPlayer, delegate
{
newPlayer.RestartCount = RestartCount + 1;
ValidForResume = false;
if (!Push(newPlayer))
{
// Error(?)
@ -260,10 +267,11 @@ namespace osu.Game.Screens.Play
if (scoreProcessor.HasFailed || onCompletionEvent != null)
return;
ValidForResume = false;
Delay(1000);
onCompletionEvent = Schedule(delegate
{
ValidForResume = false;
Push(new Results
{
Score = scoreProcessor.CreateScore()
@ -275,8 +283,6 @@ namespace osu.Game.Screens.Play
{
sourceClock.Stop();
Delay(500);
HasFailed = true;
failOverlay.Retries = RestartCount;
failOverlay.Show();
@ -321,12 +327,15 @@ namespace osu.Game.Screens.Play
protected override bool OnExiting(Screen next)
{
if (HasFailed || !ValidForResume)
return false;
if (pauseOverlay != null && !HitRenderer.HasReplayLoaded)
{
//pause screen override logic.
if (pauseOverlay?.State == Visibility.Hidden && !canPause) return true;
if (!IsPaused && sourceClock.IsRunning) // For if the user presses escape quickly when entering the map
if (!IsPaused) // For if the user presses escape quickly when entering the map
{
Pause();
return true;

View File

@ -0,0 +1,142 @@
// 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.Containers;
using osu.Framework.Graphics.Primitives;
using System;
using System.Collections.Generic;
using osu.Game.Graphics;
using osu.Framework.Allocation;
using System.Linq;
using osu.Framework.Timing;
using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Types;
namespace osu.Game.Screens.Play
{
public class SongProgress : OverlayContainer
{
private const int progress_height = 5;
protected override bool HideOnEscape => false;
private static readonly Vector2 handle_size = new Vector2(14, 25);
private const float transition_duration = 200;
private readonly SongProgressBar bar;
private readonly SongProgressGraph graph;
public Action<double> OnSeek;
public IClock AudioClock;
private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
private IEnumerable<HitObject> objects;
public IEnumerable<HitObject> Objects
{
set
{
objects = value;
const int granularity = 200;
var interval = lastHitTime / granularity;
var values = new int[granularity];
foreach (var h in objects)
{
IHasEndTime end = h as IHasEndTime;
int startRange = (int)(h.StartTime / interval);
int endRange = (int)((end?.EndTime ?? h.StartTime) / interval);
for (int i = startRange; i <= endRange; i++)
values[i]++;
}
graph.Values = values;
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
graph.FillColour = bar.FillColour = colours.BlueLighter;
}
public SongProgress()
{
RelativeSizeAxes = Axes.X;
Height = progress_height + SongProgressGraph.Column.HEIGHT + handle_size.Y;
Y = progress_height;
Children = new Drawable[]
{
graph = new SongProgressGraph
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Height = SongProgressGraph.Column.HEIGHT,
Margin = new MarginPadding { Bottom = progress_height },
},
bar = new SongProgressBar(progress_height, SongProgressGraph.Column.HEIGHT, handle_size)
{
Alpha = 0,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
SeekRequested = delegate (float position)
{
OnSeek?.Invoke(position);
},
},
};
}
protected override void LoadComplete()
{
State = Visibility.Visible;
}
private bool barVisible;
public void ToggleBar()
{
barVisible = !barVisible;
updateBarVisibility();
}
private void updateBarVisibility()
{
bar.FadeTo(barVisible ? 1 : 0, transition_duration, EasingTypes.In);
MoveTo(new Vector2(0, barVisible ? 0 : progress_height), transition_duration, EasingTypes.In);
}
protected override void PopIn()
{
updateBarVisibility();
FadeIn(500, EasingTypes.OutQuint);
}
protected override void PopOut()
{
FadeOut(100);
}
protected override void Update()
{
base.Update();
double progress = (AudioClock?.CurrentTime ?? Time.Current) / lastHitTime;
bar.UpdatePosition((float)progress);
graph.Progress = (int)(graph.ColumnCount * progress);
}
}
}

View File

@ -0,0 +1,74 @@
// 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 OpenTK.Graphics;
using osu.Game.Overlays;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Screens.Play
{
public class SongProgressBar : DragBar
{
public Color4 FillColour
{
get { return Fill.Colour; }
set { Fill.Colour = value; }
}
public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize)
{
Height = barHeight + handleBarHeight + handleSize.Y;
Fill.RelativeSizeAxes = Axes.X;
Fill.Height = barHeight;
Add(new Box
{
Name = "Background",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = barHeight,
Colour = Color4.Black,
Alpha = 0.5f,
Depth = 1
});
Fill.Add(new Container
{
Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight,
Width = 2,
Height = barHeight + handleBarHeight,
Colour = Color4.White,
Position = new Vector2(2, 0),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.TopCentre,
Size = handleSize,
CornerRadius = 5,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White
}
}
}
}
});
}
}
}

View File

@ -0,0 +1,235 @@
// 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 OpenTK.Graphics;
using System.Linq;
using System.Collections.Generic;
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Screens.Play
{
public class SongProgressGraph : BufferedContainer
{
private Column[] columns = { };
public int ColumnCount => columns.Length;
public override bool HandleInput => false;
private int progress;
public int Progress
{
get { return progress; }
set
{
if (value == progress) return;
progress = value;
redrawProgress();
}
}
private int[] calculatedValues = { }; // values but adjusted to fit the amount of columns
private int[] values;
public int[] Values
{
get { return values; }
set
{
if (value == values) return;
values = value;
recreateGraph();
}
}
private Color4 fillColour;
public Color4 FillColour
{
get { return fillColour; }
set
{
if (value == fillColour) return;
fillColour = value;
redrawFilled();
}
}
public SongProgressGraph()
{
CacheDrawnFrameBuffer = true;
PixelSnapping = true;
}
private float lastDrawWidth;
protected override void Update()
{
base.Update();
// todo: Recreating in update is probably not the best idea
if (DrawWidth == lastDrawWidth) return;
recreateGraph();
lastDrawWidth = DrawWidth;
}
/// <summary>
/// Redraws all the columns to match their lit/dimmed state.
/// </summary>
private void redrawProgress()
{
for (int i = 0; i < columns.Length; i++)
{
columns[i].State = i <= progress ? ColumnState.Lit : ColumnState.Dimmed;
}
ForceRedraw();
}
/// <summary>
/// Redraws the filled amount of all the columns.
/// </summary>
private void redrawFilled()
{
for (int i = 0; i < ColumnCount; i++)
{
columns[i].Filled = calculatedValues.ElementAtOrDefault(i);
}
}
/// <summary>
/// Takes <see cref="Values"/> and adjusts it to fit the amount of columns.
/// </summary>
private void recalculateValues()
{
var newValues = new List<int>();
if (values == null)
{
for (float i = 0; i < ColumnCount; i++)
newValues.Add(0);
return;
}
float step = values.Length / (float)ColumnCount;
for (float i = 0; i < values.Length; i += step)
{
newValues.Add(values[(int)i]);
}
calculatedValues = newValues.ToArray();
}
/// <summary>
/// Recreates the entire graph.
/// </summary>
private void recreateGraph()
{
var newColumns = new List<Column>();
for (float x = 0; x < DrawWidth; x += Column.WIDTH)
{
newColumns.Add(new Column(fillColour)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Position = new Vector2(x, 0),
State = ColumnState.Dimmed,
});
}
columns = newColumns.ToArray();
Children = columns;
recalculateValues();
redrawFilled();
redrawProgress();
}
public class Column : Container, IStateful<ColumnState>
{
private readonly Color4 emptyColour = Color4.White.Opacity(100);
private readonly Color4 litColour;
private readonly Color4 dimmedColour = Color4.White.Opacity(175);
private const float cube_count = 6;
private const float cube_size = 4;
private const float padding = 2;
public const float WIDTH = cube_size + padding;
public const float HEIGHT = cube_count * WIDTH + padding;
private readonly List<Box> drawableRows = new List<Box>();
private int filled;
public int Filled
{
get { return filled; }
set
{
if (value == filled) return;
filled = value;
fillActive();
}
}
private ColumnState state;
public ColumnState State
{
get { return state; }
set
{
if (value == state) return;
state = value;
fillActive();
}
}
public Column(Color4 litColour)
{
Size = new Vector2(WIDTH, HEIGHT);
this.litColour = litColour;
for (int r = 0; r < cube_count; r++)
{
drawableRows.Add(new Box
{
EdgeSmoothness = new Vector2(padding / 4),
Size = new Vector2(cube_size),
Position = new Vector2(0, r * WIDTH + padding),
});
}
Children = drawableRows;
// Reverse drawableRows so when iterating through them they start at the bottom
drawableRows.Reverse();
}
private void fillActive()
{
Color4 colour = State == ColumnState.Lit ? litColour : dimmedColour;
for (int i = 0; i < drawableRows.Count; i++)
{
if (Filled == 0) // i <= Filled doesn't work for zero fill
drawableRows[i].Colour = emptyColour;
else
drawableRows[i].Colour = i <= Filled ? colour : emptyColour;
}
}
}
public enum ColumnState
{
Lit,
Dimmed
}
}
}

View File

@ -47,6 +47,8 @@ namespace osu.Game.Screens.Select
protected override bool HideOnEscape => false;
protected override bool BlockPassThroughInput => false;
protected override void PopIn()
{
MoveToX(0, 800, EasingTypes.OutQuint);

View File

@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -93,6 +94,7 @@
<Compile Include="Graphics\UserInterface\OsuPasswordTextBox.cs" />
<Compile Include="Graphics\UserInterface\OsuSliderBar.cs" />
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
<Compile Include="Graphics\UserInterface\SimpleComboCounter.cs" />
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />
<Compile Include="Graphics\Cursor\Tooltip.cs" />
<Compile Include="Input\Handlers\ReplayInputHandler.cs" />
@ -338,6 +340,9 @@
<Compile Include="Screens\Select\SearchTextBox.cs" />
<Compile Include="Screens\Select\FooterButton.cs" />
<Compile Include="Screens\Select\Footer.cs" />
<Compile Include="Screens\Play\SongProgress.cs" />
<Compile Include="Screens\Play\SongProgressGraph.cs" />
<Compile Include="Screens\Play\SongProgressBar.cs" />
<Compile Include="Screens\Play\Pause\PauseProgressBar.cs" />
<Compile Include="Screens\Play\Pause\PauseProgressGraph.cs" />
<Compile Include="Overlays\Mods\ModSelectOverlay.cs" />