2022-12-11 23:47:17 +01: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;
|
2023-02-01 23:44:00 +00:00
|
|
|
using osu.Framework.Localisation;
|
2022-12-11 23:47:17 +01:00
|
|
|
using osu.Game.Configuration;
|
2023-02-03 15:34:57 +09:00
|
|
|
using osu.Game.Localisation.HUD;
|
2022-12-11 23:47:17 +01:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD.JudgementCounter
|
|
|
|
{
|
2023-02-15 16:01:26 +09:00
|
|
|
public partial class JudgementCounterDisplay : CompositeDrawable, ISerialisableDrawable
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2023-01-17 18:38:29 +09:00
|
|
|
public const int TRANSFORM_DURATION = 250;
|
|
|
|
|
2022-12-11 23:47:17 +01:00
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2023-02-01 23:44:00 +00:00
|
|
|
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayMode))]
|
2023-10-06 16:51:24 +09:00
|
|
|
public Bindable<DisplayMode> Mode { get; } = new Bindable<DisplayMode>();
|
2022-12-12 15:10:45 +01:00
|
|
|
|
2023-02-01 23:44:00 +00:00
|
|
|
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.FlowDirection))]
|
2023-10-06 16:51:24 +09:00
|
|
|
public Bindable<Direction> FlowDirection { get; } = new Bindable<Direction>();
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2023-02-01 23:44:00 +00:00
|
|
|
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowJudgementNames))]
|
2023-10-06 16:51:24 +09:00
|
|
|
public BindableBool ShowJudgementNames { get; } = new BindableBool(true);
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2023-02-01 23:44:00 +00:00
|
|
|
[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowMaxJudgement))]
|
2023-10-06 16:51:24 +09:00
|
|
|
public BindableBool ShowMaxJudgement { get; } = new BindableBool(true);
|
2022-12-11 23:47:17 +01:00
|
|
|
|
|
|
|
[Resolved]
|
2023-06-26 19:30:04 +02:00
|
|
|
private JudgementCountController judgementCountController { get; set; } = null!;
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2023-01-17 18:28:08 +09:00
|
|
|
protected FillFlowContainer<JudgementCounter> CounterFlow = null!;
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2022-12-14 23:00:34 +01:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2022-12-12 10:52:55 +01:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2023-01-17 18:28:08 +09:00
|
|
|
InternalChild = CounterFlow = new FillFlowContainer<JudgementCounter>
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2023-01-17 18:21:30 +09:00
|
|
|
Direction = getFillDirection(FlowDirection.Value),
|
2022-12-11 23:47:17 +01:00
|
|
|
Spacing = new Vector2(10),
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
};
|
|
|
|
|
2023-06-26 19:30:04 +02:00
|
|
|
foreach (var result in judgementCountController.Results)
|
2023-01-17 18:28:08 +09:00
|
|
|
CounterFlow.Add(createCounter(result));
|
2022-12-14 23:00:34 +01:00
|
|
|
}
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2022-12-14 23:00:34 +01:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2022-12-11 23:47:17 +01:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-12-12 00:33:28 +01:00
|
|
|
FlowDirection.BindValueChanged(direction =>
|
|
|
|
{
|
2023-01-17 18:31:08 +09:00
|
|
|
var convertedDirection = getFillDirection(direction.NewValue);
|
|
|
|
|
|
|
|
CounterFlow.Direction = convertedDirection;
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2023-01-17 18:28:08 +09:00
|
|
|
foreach (var counter in CounterFlow.Children)
|
2023-01-17 18:31:08 +09:00
|
|
|
counter.Direction.Value = convertedDirection;
|
2022-12-12 15:10:10 +01:00
|
|
|
}, true);
|
2023-01-17 18:31:08 +09:00
|
|
|
|
2023-01-19 19:27:05 +09:00
|
|
|
Mode.BindValueChanged(_ => updateDisplay());
|
|
|
|
ShowMaxJudgement.BindValueChanged(_ => updateDisplay(), true);
|
2022-12-11 23:47:17 +01:00
|
|
|
}
|
|
|
|
|
2023-01-19 19:27:05 +09:00
|
|
|
private void updateDisplay()
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2023-01-19 19:27:05 +09:00
|
|
|
for (int i = 0; i < CounterFlow.Children.Count; i++)
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2023-01-19 19:27:05 +09:00
|
|
|
JudgementCounter counter = CounterFlow.Children[i];
|
|
|
|
|
|
|
|
if (shouldShow(i, counter))
|
2023-01-17 18:31:25 +09:00
|
|
|
counter.Show();
|
2023-01-17 18:35:30 +09:00
|
|
|
else
|
|
|
|
counter.Hide();
|
|
|
|
}
|
|
|
|
|
2023-01-19 19:27:05 +09:00
|
|
|
bool shouldShow(int index, JudgementCounter counter)
|
2023-01-17 18:35:30 +09:00
|
|
|
{
|
2023-01-19 19:27:05 +09:00
|
|
|
if (index == 0 && !ShowMaxJudgement.Value)
|
|
|
|
return false;
|
|
|
|
|
2023-01-17 18:35:30 +09:00
|
|
|
if (counter.Result.Type.IsBasic())
|
|
|
|
return true;
|
2023-01-17 18:31:25 +09:00
|
|
|
|
2022-12-15 16:12:34 +01:00
|
|
|
switch (Mode.Value)
|
|
|
|
{
|
|
|
|
case DisplayMode.Simple:
|
2023-01-17 18:35:30 +09:00
|
|
|
return false;
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2022-12-15 16:12:34 +01:00
|
|
|
case DisplayMode.Normal:
|
2023-01-17 18:35:30 +09:00
|
|
|
return !counter.Result.Type.IsBonus();
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2022-12-15 16:12:34 +01:00
|
|
|
case DisplayMode.All:
|
2023-01-17 18:35:30 +09:00
|
|
|
return true;
|
2022-12-11 23:47:17 +01:00
|
|
|
|
2022-12-15 16:12:34 +01:00
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
2022-12-11 23:47:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 18:21:30 +09:00
|
|
|
private FillDirection getFillDirection(Direction flow)
|
2022-12-12 00:33:28 +01:00
|
|
|
{
|
|
|
|
switch (flow)
|
|
|
|
{
|
2023-01-17 18:21:30 +09:00
|
|
|
case Direction.Horizontal:
|
2022-12-12 00:33:28 +01:00
|
|
|
return FillDirection.Horizontal;
|
|
|
|
|
2023-01-17 18:21:30 +09:00
|
|
|
case Direction.Vertical:
|
2022-12-12 00:33:28 +01:00
|
|
|
return FillDirection.Vertical;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(flow), flow, @"Unsupported direction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 19:30:04 +02:00
|
|
|
private JudgementCounter createCounter(JudgementCountController.JudgementCount info) =>
|
2023-01-17 18:27:33 +09:00
|
|
|
new JudgementCounter(info)
|
2022-12-11 23:47:17 +01:00
|
|
|
{
|
2023-01-17 18:31:25 +09:00
|
|
|
State = { Value = Visibility.Hidden },
|
2023-01-17 18:24:55 +09:00
|
|
|
ShowName = { BindTarget = ShowJudgementNames }
|
2022-12-11 23:47:17 +01:00
|
|
|
};
|
2023-01-17 18:21:30 +09:00
|
|
|
|
|
|
|
public enum DisplayMode
|
|
|
|
{
|
2023-02-01 23:44:00 +00:00
|
|
|
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeSimple))]
|
2023-01-17 18:21:30 +09:00
|
|
|
Simple,
|
2023-02-01 23:44:00 +00:00
|
|
|
|
|
|
|
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeNormal))]
|
2023-01-17 18:21:30 +09:00
|
|
|
Normal,
|
2023-02-01 23:44:00 +00:00
|
|
|
|
|
|
|
[LocalisableDescription(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayModeAll))]
|
2023-01-17 18:21:30 +09:00
|
|
|
All
|
|
|
|
}
|
2022-12-11 23:47:17 +01:00
|
|
|
}
|
|
|
|
}
|