1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 11:47:24 +08:00
osu-lazer/osu.Game.Tournament/Screens/Gameplay/Components/TournamentMatchScoreDisplay.cs

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

184 lines
6.4 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +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.
2018-11-15 20:28:42 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2018-11-15 20:28:42 +08:00
using System;
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
2018-11-15 20:28:42 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2019-03-04 11:06:41 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2018-11-15 20:28:42 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.IPC;
using osuTK;
2018-11-15 20:28:42 +08:00
namespace osu.Game.Tournament.Screens.Gameplay.Components
{
// TODO: Update to derive from osu-side class?
public partial class TournamentMatchScoreDisplay : CompositeDrawable
2018-11-15 20:28:42 +08:00
{
2020-03-07 15:22:52 +08:00
private const float bar_height = 18;
2018-11-15 20:28:42 +08:00
private readonly BindableInt score1 = new BindableInt();
private readonly BindableInt score2 = new BindableInt();
private readonly MatchScoreCounter score1Text;
private readonly MatchScoreCounter score2Text;
private readonly MatchScoreDiffCounter scoreDiffText;
2020-03-07 15:22:52 +08:00
private readonly Drawable score1Bar;
private readonly Drawable score2Bar;
2018-11-15 20:28:42 +08:00
public TournamentMatchScoreDisplay()
2018-11-15 20:28:42 +08:00
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
2018-11-15 20:28:42 +08:00
2020-03-07 15:22:52 +08:00
InternalChildren = new[]
2018-11-15 20:28:42 +08:00
{
2020-03-07 15:22:52 +08:00
new Box
{
Name = "top bar red (static)",
RelativeSizeAxes = Axes.X,
Height = bar_height / 4,
Width = 0.5f,
Colour = TournamentGame.COLOUR_RED,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopRight
},
new Box
{
Name = "top bar blue (static)",
RelativeSizeAxes = Axes.X,
Height = bar_height / 4,
Width = 0.5f,
Colour = TournamentGame.COLOUR_BLUE,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopLeft
},
score1Bar = new Box
2018-11-15 20:28:42 +08:00
{
Name = "top bar red",
RelativeSizeAxes = Axes.X,
Height = bar_height,
Width = 0,
2020-03-07 15:22:52 +08:00
Colour = TournamentGame.COLOUR_RED,
2018-11-15 20:28:42 +08:00
Anchor = Anchor.TopCentre,
Origin = Anchor.TopRight
},
score1Text = new MatchScoreCounter
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
},
2020-03-07 15:22:52 +08:00
score2Bar = new Box
2018-11-15 20:28:42 +08:00
{
Name = "top bar blue",
RelativeSizeAxes = Axes.X,
Height = bar_height,
Width = 0,
2020-03-07 15:22:52 +08:00
Colour = TournamentGame.COLOUR_BLUE,
2018-11-15 20:28:42 +08:00
Anchor = Anchor.TopCentre,
Origin = Anchor.TopLeft
},
score2Text = new MatchScoreCounter
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
},
scoreDiffText = new MatchScoreDiffCounter
{
Anchor = Anchor.TopCentre,
Alpha = 0
}
2018-11-15 20:28:42 +08:00
};
}
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(MatchIPCInfo ipc)
2018-11-15 20:28:42 +08:00
{
score1.BindValueChanged(_ => updateScores());
score1.BindTo(ipc.Score1);
score2.BindValueChanged(_ => updateScores());
score2.BindTo(ipc.Score2);
}
private void updateScores()
{
score1Text.Current.Value = score1.Value;
score2Text.Current.Value = score2.Value;
var winningText = score1.Value > score2.Value ? score1Text : score2Text;
var losingText = score1.Value <= score2.Value ? score1Text : score2Text;
winningText.Winning = true;
losingText.Winning = false;
var winningBar = score1.Value > score2.Value ? score1Bar : score2Bar;
var losingBar = score1.Value <= score2.Value ? score1Bar : score2Bar;
int diff = Math.Max(score1.Value, score2.Value) - Math.Min(score1.Value, score2.Value);
2018-11-15 20:28:42 +08:00
losingBar.ResizeWidthTo(0, 400, Easing.OutQuint);
winningBar.ResizeWidthTo(Math.Min(0.4f, MathF.Pow(diff / 1500000f, 0.5f) / 2), 400, Easing.OutQuint);
scoreDiffText.Alpha = diff != 0 ? 1 : 0;
scoreDiffText.Current.Value = -diff;
scoreDiffText.Origin = score1.Value > score2.Value ? Anchor.TopLeft : Anchor.TopRight;
2018-11-15 20:28:42 +08:00
}
2020-03-07 15:22:52 +08:00
protected override void UpdateAfterChildren()
2018-11-15 20:28:42 +08:00
{
2020-03-07 15:22:52 +08:00
base.UpdateAfterChildren();
2018-11-16 11:20:21 +08:00
score1Text.X = -Math.Max(5 + score1Text.DrawWidth / 2, score1Bar.DrawWidth);
score2Text.X = Math.Max(5 + score2Text.DrawWidth / 2, score2Bar.DrawWidth);
2018-11-15 20:28:42 +08:00
}
private partial class MatchScoreCounter : CommaSeparatedScoreCounter
2018-11-15 20:28:42 +08:00
{
private OsuSpriteText displayedSpriteText;
2018-11-15 20:28:42 +08:00
public MatchScoreCounter()
{
2020-03-07 15:22:52 +08:00
Margin = new MarginPadding { Top = bar_height, Horizontal = 10 };
2018-11-15 20:28:42 +08:00
}
public bool Winning
{
set => updateFont(value);
2018-11-15 20:28:42 +08:00
}
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
{
displayedSpriteText = s;
displayedSpriteText.Spacing = new Vector2(-6);
updateFont(false);
});
private void updateFont(bool winning)
=> displayedSpriteText.Font = winning
? OsuFont.Torus.With(weight: FontWeight.Bold, size: 50, fixedWidth: true)
: OsuFont.Torus.With(weight: FontWeight.Regular, size: 40, fixedWidth: true);
2018-11-15 20:28:42 +08:00
}
private partial class MatchScoreDiffCounter : CommaSeparatedScoreCounter
{
public MatchScoreDiffCounter()
{
Margin = new MarginPadding { Top = bar_height / 4, Horizontal = 10 };
}
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
{
s.Spacing = new Vector2(-1);
s.Font = OsuFont.Torus.With(weight: FontWeight.Regular, size: bar_height, fixedWidth: true);
});
}
2018-11-15 20:28:42 +08:00
}
}