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
|
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
|
|
|
[SettingSource("Counter direction")]
|
2022-12-12 07:33:28 +08:00
|
|
|
public Bindable<Flow> FlowDirection { get; set; } = new Bindable<Flow>();
|
2022-12-12 06:47:17 +08:00
|
|
|
|
|
|
|
[SettingSource("Show judgement names")]
|
|
|
|
public BindableBool ShowName { get; set; } = new BindableBool(true);
|
|
|
|
|
|
|
|
[SettingSource("Show max judgement")]
|
|
|
|
public BindableBool ShowMax { get; set; } = new BindableBool(true);
|
|
|
|
|
|
|
|
[SettingSource("Display mode")]
|
|
|
|
public Bindable<DisplayMode> Mode { get; set; } = new Bindable<DisplayMode>();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private JudgementTally tally { get; set; } = null!;
|
|
|
|
|
2022-12-12 17:52:55 +08:00
|
|
|
protected FillFlowContainer JudgementContainer;
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-12 17:52:55 +08:00
|
|
|
public JudgementCounterDisplay()
|
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
|
|
|
|
{
|
2022-12-12 07:33:28 +08:00
|
|
|
Direction = getFlow(FlowDirection.Value),
|
2022-12-12 06:47:17 +08:00
|
|
|
Spacing = new Vector2(10),
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
};
|
2022-12-12 17:52:55 +08:00
|
|
|
}
|
2022-12-12 06:47:17 +08:00
|
|
|
|
2022-12-12 17:52:55 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2022-12-12 22:10:10 +08:00
|
|
|
//Adding this in "load" will cause the component to not load in properly after the first beatmap attempt. Or after existing and reentering.
|
2022-12-12 17:52:55 +08:00
|
|
|
//this does not happen in tests, or in the skin editor component preview button.
|
2022-12-12 06:47:17 +08:00
|
|
|
foreach (var result in tally.Results)
|
|
|
|
{
|
|
|
|
JudgementContainer.Add(createCounter(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-12-12 07:33:28 +08:00
|
|
|
FlowDirection.BindValueChanged(direction =>
|
|
|
|
{
|
|
|
|
JudgementContainer.Direction = getFlow(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>())
|
|
|
|
{
|
|
|
|
counter.Direction.Value = getFlow(direction.NewValue);
|
|
|
|
}
|
2022-12-12 22:10:10 +08:00
|
|
|
}, true);
|
2022-12-12 07:33:28 +08:00
|
|
|
Mode.BindValueChanged(_ => updateCounter(), true);
|
2022-12-12 06:47:17 +08:00
|
|
|
ShowMax.BindValueChanged(value =>
|
|
|
|
{
|
|
|
|
var firstChild = JudgementContainer.Children.FirstOrDefault();
|
|
|
|
|
|
|
|
if (value.NewValue)
|
|
|
|
{
|
|
|
|
firstChild?.Show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstChild?.Hide();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCounter()
|
|
|
|
{
|
|
|
|
var counters = JudgementContainer.Children.OfType<JudgementCounter>().ToList();
|
|
|
|
|
|
|
|
switch (Mode.Value)
|
|
|
|
{
|
|
|
|
case DisplayMode.Simple:
|
2022-12-12 22:10:10 +08:00
|
|
|
foreach (var counter in counters.Where(counter => counter.Result.Type.IsBasic()))
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Show();
|
|
|
|
|
2022-12-12 22:10:10 +08:00
|
|
|
foreach (var counter in counters.Where(counter => !counter.Result.Type.IsBasic()))
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Hide();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DisplayMode.Normal:
|
2022-12-12 22:10:10 +08:00
|
|
|
foreach (var counter in counters.Where(counter => !counter.Result.Type.IsBonus()))
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Show();
|
|
|
|
|
2022-12-12 22:10:10 +08:00
|
|
|
foreach (var counter in counters.Where(counter => counter.Result.Type.IsBonus()))
|
2022-12-12 06:47:17 +08:00
|
|
|
counter.Hide();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DisplayMode.All:
|
|
|
|
foreach (JudgementCounter counter in counters.Where(counter => !counter.IsPresent))
|
|
|
|
counter.Show();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 07:33:28 +08:00
|
|
|
private FillDirection getFlow(Flow flow)
|
|
|
|
{
|
|
|
|
switch (flow)
|
|
|
|
{
|
2022-12-12 17:52:55 +08:00
|
|
|
case Flow.Horizontal:
|
2022-12-12 07:33:28 +08:00
|
|
|
return FillDirection.Horizontal;
|
|
|
|
|
|
|
|
case Flow.Vertical:
|
|
|
|
return FillDirection.Vertical;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(flow), flow, @"Unsupported direction");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Used to hide default full option in FillDirection
|
|
|
|
public enum Flow
|
|
|
|
{
|
2022-12-12 17:52:55 +08:00
|
|
|
Horizontal,
|
2022-12-12 07:33:28 +08:00
|
|
|
Vertical
|
|
|
|
}
|
|
|
|
|
2022-12-12 06:47:17 +08:00
|
|
|
public enum DisplayMode
|
|
|
|
{
|
|
|
|
Simple,
|
|
|
|
Normal,
|
|
|
|
All
|
|
|
|
}
|
|
|
|
|
|
|
|
private JudgementCounter createCounter(JudgementCounterInfo info)
|
|
|
|
{
|
|
|
|
JudgementCounter counter = new JudgementCounter(info)
|
|
|
|
{
|
|
|
|
ShowName = { BindTarget = ShowName },
|
|
|
|
};
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|