mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Add team and star displays
This commit is contained in:
parent
0003a9310f
commit
160984719d
@ -11,7 +11,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Graphics;
|
||||
@ -47,11 +46,6 @@ namespace osu.Game.Tournament.Screens.Drawings
|
||||
|
||||
public ITeamList TeamList;
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
||||
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures, Storage storage)
|
||||
{
|
||||
@ -59,14 +53,6 @@ namespace osu.Game.Tournament.Screens.Drawings
|
||||
|
||||
this.storage = storage;
|
||||
|
||||
TextureStore flagStore = new TextureStore();
|
||||
// Local flag store
|
||||
flagStore.AddStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), "Drawings")));
|
||||
// Default texture store
|
||||
flagStore.AddStore(textures);
|
||||
|
||||
dependencies.Cache(flagStore);
|
||||
|
||||
if (TeamList == null)
|
||||
TeamList = new StorageBackedTeamList(storage);
|
||||
|
||||
|
@ -1,10 +1,218 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Gameplay
|
||||
{
|
||||
public class GameplayScreen : BeatmapInfoScreen
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder, TextureStore textures)
|
||||
{
|
||||
Add(new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 100,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Sprite
|
||||
{
|
||||
Y = 5,
|
||||
Texture = textures.Get("game-screen-logo"),
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
FillMode = FillMode.Fit,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One
|
||||
},
|
||||
new RoundDisplay
|
||||
{
|
||||
Y = 10,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
},
|
||||
new TeamScoreDisplay(TeamColour.Red)
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
},
|
||||
new TeamScoreDisplay(TeamColour.Blue)
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private class TeamScoreDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly TeamColour teamColour;
|
||||
|
||||
private readonly Color4 red = new Color4(129, 68, 65, 255);
|
||||
private readonly Color4 blue = new Color4(41, 91, 97, 255);
|
||||
|
||||
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
||||
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
|
||||
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
|
||||
|
||||
public TeamScoreDisplay(TeamColour teamColour)
|
||||
{
|
||||
this.teamColour = teamColour;
|
||||
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Width = 300;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder)
|
||||
{
|
||||
currentMatch.BindValueChanged(matchChanged);
|
||||
currentMatch.BindTo(ladder.CurrentMatch);
|
||||
}
|
||||
|
||||
private void matchChanged(MatchPairing match)
|
||||
{
|
||||
currentTeamScore.UnbindBindings();
|
||||
currentTeamScore.BindTo(teamColour == TeamColour.Red ? match.Team1Score : match.Team2Score);
|
||||
|
||||
currentTeam.UnbindBindings();
|
||||
currentTeam.BindTo(teamColour == TeamColour.Red ? match.Team1 : match.Team2);
|
||||
|
||||
// team may change to same team, which means score is not in a good state.
|
||||
// thus we handle this manually.
|
||||
teamChanged(currentTeam.Value);
|
||||
}
|
||||
|
||||
private void teamChanged(TournamentTeam team)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new TeamDisplay(team, teamColour == TeamColour.Red ? red : blue, teamColour != TeamColour.Red),
|
||||
new ScoreDisplay(currentTeamScore, teamColour != TeamColour.Red, currentMatch.Value.Grouping.Value.BestOf / 2 + 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class ScoreDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
|
||||
private readonly StarCounter counter;
|
||||
|
||||
public ScoreDisplay(Bindable<int?> score, bool flip, int count)
|
||||
{
|
||||
var anchor = flip ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
|
||||
Anchor = anchor;
|
||||
Origin = anchor;
|
||||
|
||||
InternalChild = counter = new StarCounter(count)
|
||||
{
|
||||
Anchor = anchor,
|
||||
X = (flip ? -1 : 1) * 90,
|
||||
Y = 5,
|
||||
Scale = flip ? new Vector2(-1, 1) : Vector2.One,
|
||||
Colour = new Color4(95, 41, 60, 255),
|
||||
};
|
||||
|
||||
currentTeamScore.BindValueChanged(scoreChanged);
|
||||
currentTeamScore.BindTo(score);
|
||||
}
|
||||
|
||||
private void scoreChanged(int? score) => counter.CountStars = score ?? 0;
|
||||
}
|
||||
|
||||
private class TeamDisplay : DrawableTournamentTeam
|
||||
{
|
||||
public TeamDisplay(TournamentTeam team, Color4 colour, bool flip)
|
||||
: base(team)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
var anchor = flip ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
|
||||
Anchor = Origin = anchor;
|
||||
|
||||
Flag.Anchor = Flag.Origin = anchor;
|
||||
Flag.RelativeSizeAxes = Axes.None;
|
||||
Flag.Size = new Vector2(60, 40);
|
||||
Flag.Margin = new MarginPadding(20);
|
||||
|
||||
InternalChild = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Flag,
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = team?.FullName.ToUpper() ?? "???",
|
||||
X = (flip ? -1 : 1) * 90,
|
||||
Y = -10,
|
||||
TextSize = 20,
|
||||
Colour = colour,
|
||||
Font = "Aquatico-Regular",
|
||||
Origin = anchor,
|
||||
Anchor = anchor,
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class RoundDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
||||
|
||||
public RoundDisplay()
|
||||
{
|
||||
CornerRadius = 10;
|
||||
Masking = true;
|
||||
Width = 200;
|
||||
Height = 20;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder)
|
||||
{
|
||||
currentMatch.BindValueChanged(matchChanged);
|
||||
currentMatch.BindTo(ladder.CurrentMatch);
|
||||
}
|
||||
|
||||
private void matchChanged(MatchPairing match)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = new Color4(95, 41, 60, 255),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = Color4.White,
|
||||
Text = match.Grouping.Value?.Name.Value ?? "Unknown Grouping",
|
||||
Font = "Aquatico-Regular",
|
||||
TextSize = 18,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using Newtonsoft.Json;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -49,6 +50,8 @@ namespace osu.Game.Tournament
|
||||
Fonts.AddStore(new GlyphStore(Resources, @"Resources/Fonts/Aquatico-Regular"));
|
||||
Fonts.AddStore(new GlyphStore(Resources, @"Resources/Fonts/Aquatico-Light"));
|
||||
|
||||
Textures.AddStore(new TextureLoaderStore(new ResourceStore<byte[]>(new StorageBackedResourceStore(storage))));
|
||||
|
||||
this.storage = storage;
|
||||
|
||||
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
|
||||
@ -125,7 +128,6 @@ namespace osu.Game.Tournament
|
||||
addedInfo = true;
|
||||
}
|
||||
|
||||
|
||||
List<TournamentTeam> countries;
|
||||
using (Stream stream = Resources.GetStream("Resources/countries.json"))
|
||||
using (var sr = new StreamReader(stream))
|
||||
|
Loading…
Reference in New Issue
Block a user