mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
More bindables!
This commit is contained in:
parent
f44fa56646
commit
cd1717c42f
@ -29,7 +29,6 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
TextSize = 40,
|
TextSize = 40,
|
||||||
Count = 0,
|
|
||||||
Margin = new MarginPadding(20),
|
Margin = new MarginPadding(20),
|
||||||
};
|
};
|
||||||
Add(score);
|
Add(score);
|
||||||
@ -72,7 +71,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
|
|
||||||
AddButton(@"Reset all", delegate
|
AddButton(@"Reset all", delegate
|
||||||
{
|
{
|
||||||
score.Count = 0;
|
score.Current.Value = 0;
|
||||||
comboCounter.Count = 0;
|
comboCounter.Count = 0;
|
||||||
numerator = denominator = 0;
|
numerator = denominator = 0;
|
||||||
accuracyCounter.SetFraction(0, 0);
|
accuracyCounter.SetFraction(0, 0);
|
||||||
@ -82,7 +81,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
|
|
||||||
AddButton(@"Hit! :D", delegate
|
AddButton(@"Hit! :D", delegate
|
||||||
{
|
{
|
||||||
score.Count += 300 + (ulong)(300.0 * (comboCounter.Count > 0 ? comboCounter.Count - 1 : 0) / 25.0);
|
score.Current.Value += 300 + (ulong)(300.0 * (comboCounter.Count > 0 ? comboCounter.Count - 1 : 0) / 25.0);
|
||||||
comboCounter.Count++;
|
comboCounter.Count++;
|
||||||
numerator++; denominator++;
|
numerator++; denominator++;
|
||||||
accuracyCounter.SetFraction(numerator, denominator);
|
accuracyCounter.SetFraction(numerator, denominator);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Transforms;
|
using osu.Framework.Graphics.Transforms;
|
||||||
|
using osu.Framework.MathUtils;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
@ -10,7 +11,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used as an accuracy counter. Represented visually as a percentage.
|
/// Used as an accuracy counter. Represented visually as a percentage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PercentageCounter : RollingCounter<float>
|
public class PercentageCounter : RollingCounter<double>
|
||||||
{
|
{
|
||||||
protected override Type TransformType => typeof(TransformAccuracy);
|
protected override Type TransformType => typeof(TransformAccuracy);
|
||||||
|
|
||||||
@ -20,32 +21,44 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
public void SetFraction(float numerator, float denominator)
|
public void SetFraction(float numerator, float denominator)
|
||||||
{
|
{
|
||||||
Count = Math.Abs(denominator) < epsilon ? 1.0f : numerator / denominator;
|
Current.Value = Math.Abs(denominator) < epsilon ? 1.0f : numerator / denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentageCounter()
|
public PercentageCounter()
|
||||||
{
|
{
|
||||||
DisplayedCountSpriteText.FixedWidth = true;
|
DisplayedCountSpriteText.FixedWidth = true;
|
||||||
Count = DisplayedCount = 1.0f;
|
Current.Value = DisplayedCount = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string FormatCount(float count)
|
protected override string FormatCount(double count)
|
||||||
{
|
{
|
||||||
return $@"{count:P2}";
|
return $@"{count:P2}";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double GetProportionalDuration(float currentValue, float newValue)
|
protected override double GetProportionalDuration(double currentValue, double newValue)
|
||||||
{
|
{
|
||||||
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
|
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Increment(float amount)
|
public override void Increment(double amount)
|
||||||
{
|
{
|
||||||
Count = Count + amount;
|
Current.Value = Current + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class TransformAccuracy : TransformFloat
|
protected class TransformAccuracy : Transform<double>
|
||||||
{
|
{
|
||||||
|
protected override double CurrentValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
double time = Time?.Current ?? 0;
|
||||||
|
if (time < StartTime) return StartValue;
|
||||||
|
if (time >= EndTime) return EndValue;
|
||||||
|
|
||||||
|
return Interpolation.ValueAt(time, (float)StartValue, (float)EndValue, StartTime, EndTime, Easing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Apply(Drawable d)
|
public override void Apply(Drawable d)
|
||||||
{
|
{
|
||||||
base.Apply(d);
|
base.Apply(d);
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// 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;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Transforms;
|
using osu.Framework.Graphics.Transforms;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public abstract class RollingCounter<T> : Container
|
public abstract class RollingCounter<T> : Container
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The current value.
|
||||||
|
/// </summary>
|
||||||
|
public Bindable<T> Current = new Bindable<T>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Type of the Transform to use.
|
/// Type of the Transform to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -60,32 +66,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private T count;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Actual value of counter.
|
|
||||||
/// </summary>
|
|
||||||
public virtual T Count
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
count = value;
|
|
||||||
if (IsLoaded)
|
|
||||||
{
|
|
||||||
TransformCount(displayedCount, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Set(T value)
|
|
||||||
{
|
|
||||||
Count = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Increment(T amount);
|
public abstract void Increment(T amount);
|
||||||
|
|
||||||
private float textSize;
|
private float textSize;
|
||||||
@ -116,7 +96,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
TextSize = 40;
|
TextSize = 40;
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
DisplayedCount = Count;
|
DisplayedCount = Current;
|
||||||
|
|
||||||
|
Current.ValueChanged += currentChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void currentChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (IsLoaded)
|
||||||
|
TransformCount(displayedCount, Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -125,7 +113,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
Flush(false, TransformType);
|
Flush(false, TransformType);
|
||||||
|
|
||||||
DisplayedCountSpriteText.Text = FormatCount(count);
|
DisplayedCountSpriteText.Text = FormatCount(Current);
|
||||||
DisplayedCountSpriteText.Anchor = Anchor;
|
DisplayedCountSpriteText.Anchor = Anchor;
|
||||||
DisplayedCountSpriteText.Origin = Origin;
|
DisplayedCountSpriteText.Origin = Origin;
|
||||||
}
|
}
|
||||||
@ -136,7 +124,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <param name="count">New count value.</param>
|
/// <param name="count">New count value.</param>
|
||||||
public virtual void SetCountWithoutRolling(T count)
|
public virtual void SetCountWithoutRolling(T count)
|
||||||
{
|
{
|
||||||
Count = count;
|
Current.Value = count;
|
||||||
StopRolling();
|
StopRolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +134,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
public virtual void StopRolling()
|
public virtual void StopRolling()
|
||||||
{
|
{
|
||||||
Flush(false, TransformType);
|
Flush(false, TransformType);
|
||||||
DisplayedCount = Count;
|
DisplayedCount = Current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -211,7 +199,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
if (RollingDuration < 1)
|
if (RollingDuration < 1)
|
||||||
{
|
{
|
||||||
DisplayedCount = Count;
|
DisplayedCount = Current;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ using System;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class ScoreCounter : RollingCounter<ulong>
|
public class ScoreCounter : RollingCounter<double>
|
||||||
{
|
{
|
||||||
protected override Type TransformType => typeof(TransformScore);
|
protected override Type TransformType => typeof(TransformScore);
|
||||||
|
|
||||||
@ -34,24 +34,24 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
LeadingZeroes = leading;
|
LeadingZeroes = leading;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double GetProportionalDuration(ulong currentValue, ulong newValue)
|
protected override double GetProportionalDuration(double currentValue, double newValue)
|
||||||
{
|
{
|
||||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string FormatCount(ulong count)
|
protected override string FormatCount(double count)
|
||||||
{
|
{
|
||||||
return count.ToString("D" + LeadingZeroes);
|
return ((long)count).ToString("D" + LeadingZeroes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Increment(ulong amount)
|
public override void Increment(double amount)
|
||||||
{
|
{
|
||||||
Count = Count + amount;
|
Current.Value = Current + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class TransformScore : Transform<ulong>
|
protected class TransformScore : Transform<double>
|
||||||
{
|
{
|
||||||
protected override ulong CurrentValue
|
protected override double CurrentValue
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (time < StartTime) return StartValue;
|
if (time < StartTime) return StartValue;
|
||||||
if (time >= EndTime) return EndValue;
|
if (time >= EndTime) return EndValue;
|
||||||
|
|
||||||
return (ulong)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
|
return Interpolation.ValueAt(time, (float)StartValue, (float)EndValue, StartTime, EndTime, Easing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Game.Modes.Objects.Drawables;
|
using osu.Game.Modes.Objects.Drawables;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game.Modes
|
namespace osu.Game.Modes
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Transforms;
|
using osu.Framework.Graphics.Transforms;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Modes.UI
|
namespace osu.Game.Modes.UI
|
||||||
{
|
{
|
||||||
@ -31,7 +31,7 @@ namespace osu.Game.Modes.UI
|
|||||||
|
|
||||||
public override void Increment(ulong amount)
|
public override void Increment(ulong amount)
|
||||||
{
|
{
|
||||||
Count = Count + amount;
|
Current.Value = Current + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class TransformComboResult : Transform<ulong>
|
protected class TransformComboResult : Transform<ulong>
|
||||||
|
@ -34,13 +34,17 @@ namespace osu.Game.Modes.UI
|
|||||||
{
|
{
|
||||||
ComboCounter?.Increment();
|
ComboCounter?.Increment();
|
||||||
ScoreCounter?.Increment(300);
|
ScoreCounter?.Increment(300);
|
||||||
AccuracyCounter?.Set(Math.Min(1, AccuracyCounter.Count + 0.01f));
|
|
||||||
|
if (AccuracyCounter != null)
|
||||||
|
AccuracyCounter.Current.Value = Math.Min(1, AccuracyCounter.Current + 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnMiss(HitObject h)
|
public virtual void OnMiss(HitObject h)
|
||||||
{
|
{
|
||||||
ComboCounter?.Roll();
|
ComboCounter?.Roll();
|
||||||
AccuracyCounter?.Set(AccuracyCounter.Count - 0.01f);
|
|
||||||
|
if (AccuracyCounter != null)
|
||||||
|
AccuracyCounter.Current.Value = AccuracyCounter.Current - 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HudOverlay(Ruleset ruleset)
|
protected HudOverlay(Ruleset ruleset)
|
||||||
@ -77,8 +81,8 @@ namespace osu.Game.Modes.UI
|
|||||||
{
|
{
|
||||||
//bind processor bindables to combocounter, score display etc.
|
//bind processor bindables to combocounter, score display etc.
|
||||||
//TODO: these should be bindable binds, not events!
|
//TODO: these should be bindable binds, not events!
|
||||||
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
|
ScoreCounter?.Current.BindTo(processor.TotalScore);
|
||||||
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
|
AccuracyCounter?.Current.BindTo(processor.Accuracy);
|
||||||
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
||||||
HealthDisplay?.Current.BindTo(processor.Health);
|
HealthDisplay?.Current.BindTo(processor.Health);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user