-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
294 additions
and
78 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
osu.Game.Tournament/Components/RollingSignNumberContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Localisation; | ||
using osu.Game.Graphics; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Graphics.UserInterface; | ||
|
||
namespace osu.Game.Tournament.Components | ||
{ | ||
public partial class RollingSignNumberContainer : CommaSeparatedScoreCounter | ||
{ | ||
protected override double RollingDuration => 500; | ||
|
||
protected override IHasText CreateText() => new SignNumberContainer(); | ||
|
||
public partial class SignNumberContainer : CompositeDrawable, IHasText | ||
{ | ||
private readonly OsuSpriteText text; | ||
|
||
public LocalisableString Text | ||
{ | ||
get => text.Text; | ||
set | ||
{ | ||
if (!int.TryParse(value.ToString().Replace(",", ""), out int result)) | ||
{ | ||
text.Text = "+0"; | ||
} | ||
|
||
char sign = Math.Sign(result) == -1 ? '-' : '+'; | ||
|
||
text.Text = $"{sign}{Math.Abs(result)}"; | ||
} | ||
} | ||
|
||
public SignNumberContainer() | ||
{ | ||
RelativeSizeAxes = Axes.Both; | ||
|
||
InternalChild = text = new OsuSpriteText | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Font = OsuFont.Torus.With(size: 20), | ||
}; | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
osu.Game.Tournament/Screens/Gameplay/Components/TeamCoinDIffDisplay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Game.Tournament.Components; | ||
using osu.Game.Tournament.Models; | ||
using osuTK; | ||
|
||
namespace osu.Game.Tournament.Screens.Gameplay.Components | ||
{ | ||
public partial class TeamCoinDIffDisplay : CompositeDrawable | ||
{ | ||
private readonly TeamColour teamColour; | ||
|
||
private readonly Bindable<double?> currentTeamCoin = new Bindable<double?>(); | ||
private readonly Bindable<double?> opponentTeamCoin = new Bindable<double?>(); | ||
private readonly RollingSignNumberContainer coinDiffContainer; | ||
|
||
public TeamCoinDIffDisplay(TeamColour colour) | ||
{ | ||
teamColour = colour; | ||
|
||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChild = new Container | ||
{ | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
CornerRadius = 10f, | ||
Size = new Vector2(60, 20), | ||
Masking = true, | ||
Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = TournamentGame.GetTeamColour(colour) | ||
}, | ||
coinDiffContainer = new RollingSignNumberContainer | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre | ||
} | ||
} | ||
}; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(LadderInfo ladder) | ||
{ | ||
var currentMatch = ladder.CurrentMatch.Value; | ||
|
||
if (currentMatch == null) | ||
return; | ||
|
||
currentTeamCoin.BindTo(teamColour == TeamColour.Red ? currentMatch.Team1Coin : currentMatch.Team2Coin); | ||
opponentTeamCoin.BindTo(teamColour == TeamColour.Blue ? currentMatch.Team1Coin : currentMatch.Team2Coin); | ||
|
||
currentTeamCoin.BindValueChanged(_ => updateDisplay(), true); | ||
opponentTeamCoin.BindValueChanged(_ => updateDisplay(), true); | ||
} | ||
|
||
private void updateDisplay() | ||
{ | ||
FinishTransforms(true); | ||
using (BeginDelayedSequence(1000)) | ||
coinDiffContainer.Current.Value = (currentTeamCoin.Value ?? 0) - (opponentTeamCoin.Value ?? 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
|
@@ -17,6 +18,10 @@ public partial class TeamDisplay : DrawableTournamentTeam | |
private readonly Bindable<string> teamName = new Bindable<string>("???"); | ||
|
||
private bool showScore; | ||
private readonly TeamCoinDIffDisplay coinDiff; | ||
|
||
[Resolved] | ||
private LadderInfo ladderInfo { get; set; } = null!; | ||
|
||
public bool ShowScore | ||
{ | ||
|
@@ -33,9 +38,10 @@ public bool ShowScore | |
} | ||
} | ||
|
||
public TeamDisplay(TournamentTeam? team, TeamColour colour, Bindable<double?> currentTeamScore, int pointsToWin) | ||
public TeamDisplay(TournamentTeam? team, TeamColour colour, Bindable<double?> currentTeamCoin, int pointsToWin) | ||
: base(team) | ||
{ | ||
this.coinDiff = coinDiff; | ||
AutoSizeAxes = Axes.Both; | ||
|
||
bool flip = colour == TeamColour.Red; | ||
|
@@ -61,7 +67,23 @@ public TeamDisplay(TournamentTeam? team, TeamColour colour, Bindable<double?> cu | |
Spacing = new Vector2(5), | ||
Children = new Drawable[] | ||
{ | ||
Flag, | ||
new FillFlowContainer | ||
{ | ||
Direction = FillDirection.Vertical, | ||
Origin = anchor, | ||
Anchor = anchor, | ||
AutoSizeAxes = Axes.Both, | ||
Spacing = new Vector2(0, 3), | ||
Children = new Drawable[] | ||
{ | ||
Flag.With(f => | ||
{ | ||
f.Anchor = Anchor.TopCentre; | ||
f.Origin = Anchor.TopCentre; | ||
}), | ||
coinDiff = new TeamCoinDIffDisplay(colour) | ||
} | ||
}, | ||
new FillFlowContainer | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
|
@@ -86,7 +108,7 @@ public TeamDisplay(TournamentTeam? team, TeamColour colour, Bindable<double?> cu | |
Origin = anchor, | ||
Anchor = anchor, | ||
}, | ||
score = new TeamMultCoin(currentTeamScore, colour) | ||
score = new TeamMultCoin(currentTeamCoin, colour) | ||
{ | ||
Origin = anchor, | ||
Anchor = anchor, | ||
|
@@ -112,6 +134,7 @@ protected override void LoadComplete() | |
base.LoadComplete(); | ||
|
||
updateDisplay(); | ||
|
||
FinishTransforms(true); | ||
|
||
if (Team != null) | ||
|
@@ -121,6 +144,7 @@ protected override void LoadComplete() | |
private void updateDisplay() | ||
{ | ||
score.FadeTo(ShowScore ? 1 : 0, 200); | ||
coinDiff.FadeTo(ShowScore ? 1 : 0, 200); | ||
} | ||
} | ||
} |
Oops, something went wrong.