2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
2017-03-10 10:59:08 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-03-10 10:59:08 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2016-11-14 17:03:20 +08:00
|
|
|
|
using osu.Game.Modes.Objects;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2017-03-10 10:59:08 +08:00
|
|
|
|
using System;
|
2017-03-10 12:40:44 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
2016-11-14 17:54:24 +08:00
|
|
|
|
namespace osu.Game.Modes.UI
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2017-03-10 12:02:50 +08:00
|
|
|
|
internal abstract class HudOverlay : Container
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2017-03-10 11:26:46 +08:00
|
|
|
|
public readonly KeyCounterCollection KeyCounter;
|
|
|
|
|
public readonly ComboCounter ComboCounter;
|
|
|
|
|
public readonly ScoreCounter ScoreCounter;
|
|
|
|
|
public readonly PercentageCounter AccuracyCounter;
|
|
|
|
|
public readonly HealthDisplay HealthDisplay;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
2017-03-01 18:22:01 +08:00
|
|
|
|
private Bindable<bool> showKeyCounter;
|
|
|
|
|
|
2017-03-10 12:40:44 +08:00
|
|
|
|
protected abstract KeyCounterCollection CreateKeyCounter(IEnumerable<KeyCounter> keyCounters);
|
2017-03-10 11:26:46 +08:00
|
|
|
|
protected abstract ComboCounter CreateComboCounter();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
protected abstract PercentageCounter CreateAccuracyCounter();
|
|
|
|
|
protected abstract ScoreCounter CreateScoreCounter();
|
2017-03-10 11:26:46 +08:00
|
|
|
|
protected abstract HealthDisplay CreateHealthDisplay();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
|
|
|
|
public virtual void OnHit(HitObject h)
|
|
|
|
|
{
|
|
|
|
|
ComboCounter?.Increment();
|
|
|
|
|
ScoreCounter?.Increment(300);
|
2017-03-10 12:08:59 +08:00
|
|
|
|
|
|
|
|
|
if (AccuracyCounter != null)
|
|
|
|
|
AccuracyCounter.Current.Value = Math.Min(1, AccuracyCounter.Current + 0.01f);
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnMiss(HitObject h)
|
|
|
|
|
{
|
|
|
|
|
ComboCounter?.Roll();
|
2017-03-10 12:08:59 +08:00
|
|
|
|
|
|
|
|
|
if (AccuracyCounter != null)
|
|
|
|
|
AccuracyCounter.Current.Value = AccuracyCounter.Current - 0.01f;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 12:02:50 +08:00
|
|
|
|
protected HudOverlay(Ruleset ruleset)
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2017-03-10 10:59:08 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-10 12:40:44 +08:00
|
|
|
|
KeyCounter = CreateKeyCounter(ruleset.CreateGameplayKeys),
|
2016-10-19 18:44:03 +08:00
|
|
|
|
ComboCounter = CreateComboCounter(),
|
|
|
|
|
ScoreCounter = CreateScoreCounter(),
|
|
|
|
|
AccuracyCounter = CreateAccuracyCounter(),
|
2017-01-18 11:08:16 +08:00
|
|
|
|
HealthDisplay = CreateHealthDisplay(),
|
2016-10-19 18:44:03 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2016-11-29 19:30:16 +08:00
|
|
|
|
|
2017-03-01 18:22:01 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
showKeyCounter = config.GetBindable<bool>(OsuConfig.KeyOverlay);
|
|
|
|
|
showKeyCounter.ValueChanged += visibilityChanged;
|
2017-03-01 18:36:53 +08:00
|
|
|
|
showKeyCounter.TriggerChange();
|
2017-03-01 18:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void visibilityChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (showKeyCounter)
|
|
|
|
|
KeyCounter.Show();
|
2017-03-01 18:36:53 +08:00
|
|
|
|
else
|
|
|
|
|
KeyCounter.Hide();
|
2017-03-01 18:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 19:30:16 +08:00
|
|
|
|
public void BindProcessor(ScoreProcessor processor)
|
|
|
|
|
{
|
2017-03-07 18:30:39 +08:00
|
|
|
|
//bind processor bindables to combocounter, score display etc.
|
|
|
|
|
//TODO: these should be bindable binds, not events!
|
2017-03-10 12:08:59 +08:00
|
|
|
|
ScoreCounter?.Current.BindTo(processor.TotalScore);
|
|
|
|
|
AccuracyCounter?.Current.BindTo(processor.Accuracy);
|
2016-11-29 20:28:43 +08:00
|
|
|
|
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
2017-02-27 14:55:34 +08:00
|
|
|
|
HealthDisplay?.Current.BindTo(processor.Health);
|
2016-11-29 19:30:16 +08:00
|
|
|
|
}
|
2017-03-07 18:30:39 +08:00
|
|
|
|
|
|
|
|
|
public void BindHitRenderer(HitRenderer hitRenderer)
|
|
|
|
|
{
|
|
|
|
|
hitRenderer.InputManager.Add(KeyCounter.GetReceptor());
|
|
|
|
|
}
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|