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
|
|
|
|
|
|
|
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;
|
2020-08-04 01:14:17 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-15 20:28:42 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-03-12 01:22:02 +08:00
|
|
|
using osuTK;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
|
|
|
public class MatchScoreDisplay : CompositeDrawable
|
|
|
|
{
|
2020-03-07 15:22:52 +08:00
|
|
|
private const float bar_height = 18;
|
2021-08-09 18:45:16 +08:00
|
|
|
private const float font_size = 50;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
public BindableInt Team1Score = new BindableInt();
|
|
|
|
public BindableInt Team2Score = new BindableInt();
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-09 17:13:28 +08:00
|
|
|
protected MatchScoreCounter Score1Text;
|
|
|
|
protected MatchScoreCounter Score2Text;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
private Drawable score1Bar;
|
|
|
|
private Drawable score2Bar;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-11-17 14:44:56 +08:00
|
|
|
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,
|
2021-08-05 16:53:38 +08:00
|
|
|
Colour = colours.TeamColourRed,
|
2020-03-07 15:22:52 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopRight
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Name = "top bar blue (static)",
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = bar_height / 4,
|
|
|
|
Width = 0.5f,
|
2021-08-05 16:53:38 +08:00
|
|
|
Colour = colours.TeamColourBlue,
|
2020-03-07 15:22:52 +08:00
|
|
|
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,
|
2021-08-05 16:53:38 +08:00
|
|
|
Colour = colours.TeamColourRed,
|
2018-11-15 20:28:42 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopRight
|
|
|
|
},
|
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,
|
2021-08-05 16:53:38 +08:00
|
|
|
Colour = colours.TeamColourBlue,
|
2018-11-15 20:28:42 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopLeft
|
|
|
|
},
|
2021-08-09 17:13:28 +08:00
|
|
|
new Container
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
2021-08-09 17:13:28 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-08-09 18:45:16 +08:00
|
|
|
Height = font_size + bar_height,
|
2018-11-15 20:28:42 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
2021-08-09 17:13:28 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
Score1Text = new MatchScoreCounter
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
},
|
|
|
|
Score2Text = new MatchScoreCounter
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
},
|
|
|
|
}
|
2018-11-15 20:28:42 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
protected override void LoadComplete()
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
2021-08-05 16:53:38 +08:00
|
|
|
base.LoadComplete();
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
Team1Score.BindValueChanged(_ => updateScores());
|
2021-08-11 13:43:01 +08:00
|
|
|
Team2Score.BindValueChanged(_ => updateScores(), true);
|
2018-11-15 20:28:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateScores()
|
|
|
|
{
|
2021-08-09 17:13:28 +08:00
|
|
|
Score1Text.Current.Value = Team1Score.Value;
|
|
|
|
Score2Text.Current.Value = Team2Score.Value;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-11 13:48:37 +08:00
|
|
|
int comparison = Team1Score.Value.CompareTo(Team2Score.Value);
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-11 13:48:37 +08:00
|
|
|
if (comparison > 0)
|
|
|
|
{
|
|
|
|
Score1Text.Winning = true;
|
|
|
|
Score2Text.Winning = false;
|
|
|
|
}
|
|
|
|
else if (comparison < 0)
|
|
|
|
{
|
|
|
|
Score1Text.Winning = false;
|
|
|
|
Score2Text.Winning = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Score1Text.Winning = false;
|
|
|
|
Score2Text.Winning = false;
|
|
|
|
}
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
var winningBar = Team1Score.Value > Team2Score.Value ? score1Bar : score2Bar;
|
|
|
|
var losingBar = Team1Score.Value <= Team2Score.Value ? score1Bar : score2Bar;
|
2018-11-15 20:28:42 +08:00
|
|
|
|
2021-08-05 16:53:38 +08:00
|
|
|
var diff = Math.Max(Team1Score.Value, Team2Score.Value) - Math.Min(Team1Score.Value, Team2Score.Value);
|
2018-11-15 20:28:42 +08:00
|
|
|
|
|
|
|
losingBar.ResizeWidthTo(0, 400, Easing.OutQuint);
|
2019-11-25 07:45:42 +08:00
|
|
|
winningBar.ResizeWidthTo(Math.Min(0.4f, MathF.Pow(diff / 1500000f, 0.5f) / 2), 400, Easing.OutQuint);
|
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();
|
2021-08-09 17:13:28 +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
|
|
|
}
|
|
|
|
|
2021-08-09 17:13:28 +08:00
|
|
|
protected class MatchScoreCounter : ScoreCounter
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
2020-08-04 01:14:17 +08:00
|
|
|
private OsuSpriteText displayedSpriteText;
|
|
|
|
|
2018-11-15 20:28:42 +08:00
|
|
|
public MatchScoreCounter()
|
2021-10-10 15:06:12 +08:00
|
|
|
: base(useCommaSeparator: true)
|
2018-11-15 20:28:42 +08:00
|
|
|
{
|
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
|
|
|
|
{
|
2020-08-19 12:47:02 +08:00
|
|
|
set => updateFont(value);
|
2018-11-15 20:28:42 +08:00
|
|
|
}
|
2020-08-04 01:14:17 +08:00
|
|
|
|
2020-08-19 12:47:02 +08:00
|
|
|
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
|
2020-08-04 01:14:17 +08:00
|
|
|
{
|
2020-08-19 12:47:02 +08:00
|
|
|
displayedSpriteText = s;
|
2020-08-04 01:14:17 +08:00
|
|
|
displayedSpriteText.Spacing = new Vector2(-6);
|
2020-08-19 12:47:02 +08:00
|
|
|
updateFont(false);
|
|
|
|
});
|
2020-08-04 01:14:17 +08:00
|
|
|
|
2020-08-19 12:47:02 +08:00
|
|
|
private void updateFont(bool winning)
|
|
|
|
=> displayedSpriteText.Font = winning
|
2021-08-09 18:45:16 +08:00
|
|
|
? OsuFont.Torus.With(weight: FontWeight.Bold, size: font_size, fixedWidth: true)
|
|
|
|
: OsuFont.Torus.With(weight: FontWeight.Regular, size: font_size * 0.8f, fixedWidth: true);
|
2018-11-15 20:28:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|