1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 07:43:22 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/JudgementCounter/JudgementCounterDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
5.0 KiB
C#
Raw Normal View History

2022-12-12 06:47:17 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
2022-12-12 06:47:17 +08:00
using osu.Game.Configuration;
using osu.Game.Localisation.HUD;
2022-12-12 06:47:17 +08:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
public partial class JudgementCounterDisplay : CompositeDrawable, ISkinnableDrawable
{
public const int TRANSFORM_DURATION = 250;
2022-12-12 06:47:17 +08:00
public bool UsesFixedAnchor { get; set; }
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayMode))]
2022-12-12 22:10:45 +08:00
public Bindable<DisplayMode> Mode { get; set; } = new Bindable<DisplayMode>();
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.FlowDirection))]
public Bindable<Direction> FlowDirection { get; set; } = new Bindable<Direction>();
2022-12-12 06:47:17 +08:00
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowJudgementNames))]
public BindableBool ShowJudgementNames { get; set; } = new BindableBool(true);
2022-12-12 06:47:17 +08:00
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowMaxJudgement))]
public BindableBool ShowMaxJudgement { get; set; } = new BindableBool(true);
2022-12-12 06:47:17 +08:00
[Resolved]
private JudgementTally tally { get; set; } = null!;
protected FillFlowContainer<JudgementCounter> CounterFlow = null!;
2022-12-12 06:47:17 +08:00
[BackgroundDependencyLoader]
private void load()
2022-12-12 06:47:17 +08:00
{
AutoSizeAxes = Axes.Both;
InternalChild = CounterFlow = new FillFlowContainer<JudgementCounter>
2022-12-12 06:47:17 +08:00
{
Direction = getFillDirection(FlowDirection.Value),
2022-12-12 06:47:17 +08:00
Spacing = new Vector2(10),
AutoSizeAxes = Axes.Both
};
foreach (var result in tally.Results)
CounterFlow.Add(createCounter(result));
}
2022-12-12 06:47:17 +08:00
protected override void LoadComplete()
{
2022-12-12 06:47:17 +08:00
base.LoadComplete();
FlowDirection.BindValueChanged(direction =>
{
2023-01-17 17:31:08 +08:00
var convertedDirection = getFillDirection(direction.NewValue);
CounterFlow.Direction = convertedDirection;
2022-12-12 06:47:17 +08:00
foreach (var counter in CounterFlow.Children)
2023-01-17 17:31:08 +08:00
counter.Direction.Value = convertedDirection;
}, true);
2023-01-17 17:31:08 +08:00
Mode.BindValueChanged(_ => updateDisplay());
ShowMaxJudgement.BindValueChanged(_ => updateDisplay(), true);
2022-12-12 06:47:17 +08:00
}
private void updateDisplay()
2022-12-12 06:47:17 +08:00
{
for (int i = 0; i < CounterFlow.Children.Count; i++)
2022-12-12 06:47:17 +08:00
{
JudgementCounter counter = CounterFlow.Children[i];
if (shouldShow(i, counter))
counter.Show();
else
counter.Hide();
}
bool shouldShow(int index, JudgementCounter counter)
{
if (index == 0 && !ShowMaxJudgement.Value)
return false;
if (counter.Result.Type.IsBasic())
return true;
switch (Mode.Value)
{
case DisplayMode.Simple:
return false;
2022-12-12 06:47:17 +08:00
case DisplayMode.Normal:
return !counter.Result.Type.IsBonus();
2022-12-12 06:47:17 +08:00
case DisplayMode.All:
return true;
2022-12-12 06:47:17 +08:00
default:
throw new ArgumentOutOfRangeException();
}
2022-12-12 06:47:17 +08:00
}
}
private FillDirection getFillDirection(Direction flow)
{
switch (flow)
{
case Direction.Horizontal:
return FillDirection.Horizontal;
case Direction.Vertical:
return FillDirection.Vertical;
default:
throw new ArgumentOutOfRangeException(nameof(flow), flow, @"Unsupported direction");
}
}
private JudgementCounter createCounter(JudgementTally.JudgementCount info) =>
new JudgementCounter(info)
2022-12-12 06:47:17 +08:00
{
State = { Value = Visibility.Hidden },
ShowName = { BindTarget = ShowJudgementNames }
2022-12-12 06:47:17 +08:00
};
public enum DisplayMode
{
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeSimple))]
Simple,
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeNormal))]
Normal,
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeAll))]
All
}
2022-12-12 06:47:17 +08:00
}
}