Skip to content

Commit

Permalink
coin animation
Browse files Browse the repository at this point in the history
  • Loading branch information
cdwcgt committed Oct 18, 2024
1 parent 2907244 commit 8a7fb9c
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 78 deletions.
54 changes: 54 additions & 0 deletions osu.Game.Tournament/Components/RollingSignNumberContainer.cs
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),
};
}
}
}
}
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);
}
}
}
30 changes: 27 additions & 3 deletions osu.Game.Tournament/Screens/Gameplay/Components/TeamDisplay.cs
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;
Expand All @@ -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
{
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -112,6 +134,7 @@ protected override void LoadComplete()
base.LoadComplete();

updateDisplay();

FinishTransforms(true);

if (Team != null)
Expand All @@ -121,6 +144,7 @@ protected override void LoadComplete()
private void updateDisplay()
{
score.FadeTo(ShowScore ? 1 : 0, 200);
coinDiff.FadeTo(ShowScore ? 1 : 0, 200);
}
}
}
Loading

0 comments on commit 8a7fb9c

Please sign in to comment.