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 System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD.JudgementCounter
|
|
|
|
{
|
|
|
|
public partial class JudgementCounterDisplay : CompositeDrawable, ISkinnableDrawable
|
|
|
|
{
|
2022-12-17 00:40:39 +08:00
|
|
|
public const int TRANSFORM_DURATION = 500;
|
2022-12-12 06:47:17 +08:00
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2022-12-12 22:10:45 +08:00
|
|
|
[SettingSource("Display mode")]
|
|
|
|
public Bindable<DisplayMode> Mode { get; set; } = new Bindable<DisplayMode>();
|
|
|
|
|
2022-12-12 06:47:17 +08:00
|
|
|
[SettingSource("Counter direction")]
|
2023-01-17 17:21:30 +08:00
|
|
|
public Bindable<Direction> FlowDirection { get; set; } = new Bindable<Direction>();
|
2022-12-12 06:47:17 +08:00
|
|
|
|
|
|
|
[SettingSource("Show judgement names")]
|
2023-01-17 17:24:55 +08:00
|
|
|
public BindableBool ShowJudgementNames { get; set; } = new BindableBool(true);
|
2022-12-12 06:47:17 +08:00
|
|
|
|
|
|
|
[SettingSource("Show max judgement")]
|
2023-01-17 17:24:55 +08:00
|
|
|
public BindableBool ShowMaxJudgement { get; set; } = new BindableBool(true);
|
2022-12-12 06:47:17 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private JudgementTally tally { get; set; } = null!;
|
|
|
|
|
2022-12-15 06:00:34 +08:00
|
|
|
protected FillFlowContainer JudgementContainer = null!;
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-15 06:00:34 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2022-12-12 06:47:17 +08:00
|
|
|
{
|
2022-12-12 17:52:55 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2022-12-12 06:47:17 +08:00
|
|
|
InternalChild = JudgementContainer = new FillFlowContainer
|
|
|
|
{
|
2023-01-17 17:21:30 +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)
|
|
|
|
JudgementContainer.Add(createCounter(result));
|
2022-12-15 06:00:34 +08:00
|
|
|
}
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-15 06:00:34 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2022-12-12 06:47:17 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-12-12 07:33:28 +08:00
|
|
|
FlowDirection.BindValueChanged(direction =>
|
|
|
|
{
|
2023-01-17 17:21:30 +08:00
|
|
|
JudgementContainer.Direction = getFillDirection(direction.NewValue);
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-12 07:33:28 +08:00
|
|
|
//Can't pass directly due to Enum conversion
|
|
|
|
foreach (var counter in JudgementContainer.Children.OfType<JudgementCounter>())
|
2023-01-17 17:21:30 +08:00
|
|
|
counter.Direction.Value = getFillDirection(direction.NewValue);
|
2022-12-12 22:10:10 +08:00
|
|
|
}, true);
|
2022-12-15 23:12:34 +08:00
|
|
|
Mode.BindValueChanged(_ => updateMode(), true);
|
2023-01-17 17:24:55 +08:00
|
|
|
ShowMaxJudgement.BindValueChanged(value =>
|
2022-12-12 06:47:17 +08:00
|
|
|
{
|
|
|
|
var firstChild = JudgementContainer.Children.FirstOrDefault();
|
2022-12-17 00:40:39 +08:00
|
|
|
firstChild.FadeTo(value.NewValue ? 1 : 0, TRANSFORM_DURATION, Easing.OutQuint);
|
2022-12-12 06:47:17 +08:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2022-12-15 23:12:34 +08:00
|
|
|
private void updateMode()
|
2022-12-12 06:47:17 +08:00
|
|
|
{
|
2022-12-15 23:12:34 +08:00
|
|
|
foreach (var counter in JudgementContainer.Children.OfType<JudgementCounter>().Where(counter => !counter.Result.Type.IsBasic()))
|
2022-12-12 06:47:17 +08:00
|
|
|
{
|
2022-12-15 23:12:34 +08:00
|
|
|
switch (Mode.Value)
|
|
|
|
{
|
|
|
|
case DisplayMode.Simple:
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Hide();
|
2022-12-15 23:12:34 +08:00
|
|
|
break;
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-15 23:12:34 +08:00
|
|
|
case DisplayMode.Normal:
|
2022-12-17 00:40:39 +08:00
|
|
|
counter.FadeTo(counter.Result.Type.IsBonus() ? 0 : 1);
|
2022-12-15 23:12:34 +08:00
|
|
|
break;
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-15 23:12:34 +08:00
|
|
|
case DisplayMode.All:
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Show();
|
2022-12-15 23:12:34 +08:00
|
|
|
break;
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-15 23:12:34 +08:00
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
2022-12-12 06:47:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:21:30 +08:00
|
|
|
private FillDirection getFillDirection(Direction flow)
|
2022-12-12 07:33:28 +08:00
|
|
|
{
|
|
|
|
switch (flow)
|
|
|
|
{
|
2023-01-17 17:21:30 +08:00
|
|
|
case Direction.Horizontal:
|
2022-12-12 07:33:28 +08:00
|
|
|
return FillDirection.Horizontal;
|
|
|
|
|
2023-01-17 17:21:30 +08:00
|
|
|
case Direction.Vertical:
|
2022-12-12 07:33:28 +08:00
|
|
|
return FillDirection.Vertical;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(flow), flow, @"Unsupported direction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:16:46 +08:00
|
|
|
private JudgementCounter createCounter(JudgementTally.JudgementCount info)
|
2022-12-12 06:47:17 +08:00
|
|
|
{
|
|
|
|
JudgementCounter counter = new JudgementCounter(info)
|
|
|
|
{
|
2022-12-15 23:12:34 +08:00
|
|
|
State = { Value = Visibility.Visible },
|
2023-01-17 17:24:55 +08:00
|
|
|
ShowName = { BindTarget = ShowJudgementNames }
|
2022-12-12 06:47:17 +08:00
|
|
|
};
|
|
|
|
return counter;
|
|
|
|
}
|
2023-01-17 17:21:30 +08:00
|
|
|
|
|
|
|
public enum DisplayMode
|
|
|
|
{
|
|
|
|
Simple,
|
|
|
|
Normal,
|
|
|
|
All
|
|
|
|
}
|
2022-12-12 06:47:17 +08:00
|
|
|
}
|
|
|
|
}
|