1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 05:33:21 +08:00
osu-lazer/osu.Game.Tournament/Screens/TeamIntro/SeedingScreen.cs

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

347 lines
13 KiB
C#
Raw Normal View History

2020-03-03 17:12:42 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Diagnostics;
2020-03-03 17:12:42 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
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.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
namespace osu.Game.Tournament.Screens.TeamIntro
{
public partial class SeedingScreen : TournamentMatchScreen
2020-03-03 17:12:42 +08:00
{
private Container mainContainer;
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
private TourneyButton showFirstTeamButton;
private TourneyButton showSecondTeamButton;
2020-03-03 17:12:42 +08:00
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load()
2020-03-03 17:12:42 +08:00
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new TourneyVideo("seeding")
2020-03-03 17:12:42 +08:00
{
RelativeSizeAxes = Axes.Both,
Loop = true,
},
mainContainer = new Container
{
RelativeSizeAxes = Axes.Both,
},
new ControlPanel
{
Children = new Drawable[]
{
showFirstTeamButton = new TourneyButton
2020-03-03 17:12:42 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Show first team",
Action = () => currentTeam.Value = CurrentMatch.Value.Team1.Value,
2020-03-03 17:12:42 +08:00
},
showSecondTeamButton = new TourneyButton
2020-03-03 17:12:42 +08:00
{
RelativeSizeAxes = Axes.X,
Text = "Show second team",
Action = () => currentTeam.Value = CurrentMatch.Value.Team2.Value,
2020-03-03 17:12:42 +08:00
},
new SettingsTeamDropdown(LadderInfo.Teams)
{
LabelText = "Show specific team",
Current = currentTeam,
2020-03-03 17:12:42 +08:00
}
}
}
};
currentTeam.BindValueChanged(teamChanged, true);
}
private void teamChanged(ValueChangedEvent<TournamentTeam> team) => updateTeamDisplay();
public override void Show()
2020-03-03 17:12:42 +08:00
{
base.Show();
2020-03-03 17:12:42 +08:00
// Changes could have been made on editor screen.
// Rather than trying to track all the possibilities (teams / players / scores) just force a full refresh.
updateTeamDisplay();
}
2020-03-03 17:12:42 +08:00
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);
if (match.NewValue == null)
{
showFirstTeamButton.Enabled.Value = false;
showSecondTeamButton.Enabled.Value = false;
return;
}
showFirstTeamButton.Enabled.Value = true;
showSecondTeamButton.Enabled.Value = true;
currentTeam.Value = match.NewValue.Team1.Value;
}
2020-03-03 17:12:42 +08:00
private void updateTeamDisplay() => Scheduler.AddOnce(() =>
2020-03-03 17:12:42 +08:00
{
if (currentTeam.Value == null)
{
mainContainer.Clear();
return;
}
2020-03-03 17:12:42 +08:00
mainContainer.Children = new Drawable[]
{
new LeftInfo(currentTeam.Value) { Position = new Vector2(55, 150), },
new RightInfo(currentTeam.Value) { Position = new Vector2(500, 150), },
2020-03-03 17:12:42 +08:00
};
});
2020-03-03 17:12:42 +08:00
private partial class RightInfo : CompositeDrawable
{
public RightInfo(TournamentTeam team)
{
FillFlowContainer fill;
Width = 400;
InternalChildren = new Drawable[]
{
fill = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
};
foreach (var seeding in team.SeedingResults)
{
fill.Add(new ModRow(seeding.Mod.Value, seeding.Seed.Value));
2020-03-03 17:12:42 +08:00
foreach (var beatmap in seeding.Beatmaps)
{
if (beatmap.Beatmap == null)
continue;
2020-03-03 17:12:42 +08:00
fill.Add(new BeatmapScoreRow(beatmap));
}
2020-03-03 17:12:42 +08:00
}
}
private partial class BeatmapScoreRow : CompositeDrawable
{
public BeatmapScoreRow(SeedingBeatmap beatmap)
{
Debug.Assert(beatmap.Beatmap != null);
2020-03-03 17:12:42 +08:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new TournamentSpriteText { Text = beatmap.Beatmap.Metadata.Title, Colour = TournamentGame.TEXT_COLOUR, },
new TournamentSpriteText { Text = "by", Colour = TournamentGame.TEXT_COLOUR, Font = OsuFont.Torus.With(weight: FontWeight.Regular) },
new TournamentSpriteText { Text = beatmap.Beatmap.Metadata.Artist, Colour = TournamentGame.TEXT_COLOUR, Font = OsuFont.Torus.With(weight: FontWeight.Regular) },
2020-03-03 17:12:42 +08:00
}
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(40),
Children = new Drawable[]
{
new TournamentSpriteText { Text = beatmap.Score.ToString("#,0"), Colour = TournamentGame.TEXT_COLOUR, Width = 80 },
new TournamentSpriteText
{ Text = "#" + beatmap.Seed.Value.ToString("#,0"), Colour = TournamentGame.TEXT_COLOUR, Font = OsuFont.Torus.With(weight: FontWeight.Regular) },
2020-03-03 17:12:42 +08:00
}
},
};
}
}
private partial class ModRow : CompositeDrawable
{
private readonly string mods;
private readonly int seeding;
public ModRow(string mods, int seeding)
{
this.mods = mods;
this.seeding = seeding;
Padding = new MarginPadding { Vertical = 10 };
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
FillFlowContainer row;
2020-03-03 17:12:42 +08:00
InternalChildren = new Drawable[]
{
row = new FillFlowContainer
2020-03-03 17:12:42 +08:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
},
};
if (!string.IsNullOrEmpty(mods))
{
row.Add(new Sprite
{
Texture = textures.Get($"Mods/{mods.ToLowerInvariant()}"),
Scale = new Vector2(0.5f)
});
}
row.Add(new Container
{
Size = new Vector2(50, 16),
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = TournamentGame.ELEMENT_BACKGROUND_COLOUR,
},
new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = seeding.ToString("#,0"),
Colour = TournamentGame.ELEMENT_FOREGROUND_COLOUR
},
}
});
2020-03-03 17:12:42 +08:00
}
}
}
private partial class LeftInfo : CompositeDrawable
{
public LeftInfo(TournamentTeam team)
{
FillFlowContainer fill;
Width = 200;
if (team == null) return;
InternalChildren = new Drawable[]
{
fill = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new TeamDisplay(team) { Margin = new MarginPadding { Bottom = 30 } },
new RowDisplay("Average Rank:", $"#{team.AverageRank:#,0}"),
new RowDisplay("Seed:", team.Seed.Value),
new RowDisplay("Last year's placing:", team.LastYearPlacing.Value > 0 ? $"#{team.LastYearPlacing:#,0}" : "0"),
new Container { Margin = new MarginPadding { Bottom = 30 } },
}
},
};
foreach (var p in team.Players)
fill.Add(new RowDisplay(p.Username, p.Rank?.ToString("\\##,0") ?? "-"));
2020-03-03 17:12:42 +08:00
}
internal partial class RowDisplay : CompositeDrawable
{
public RowDisplay(string left, string right)
{
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
InternalChildren = new Drawable[]
{
new TournamentSpriteText
{
Text = left,
Colour = TournamentGame.TEXT_COLOUR,
Font = OsuFont.Torus.With(size: 22, weight: FontWeight.SemiBold),
2020-03-03 17:12:42 +08:00
},
new TournamentSpriteText
{
Text = right,
Colour = TournamentGame.TEXT_COLOUR,
2020-03-03 17:12:42 +08:00
Anchor = Anchor.TopRight,
Origin = Anchor.TopLeft,
Font = OsuFont.Torus.With(size: 22, weight: FontWeight.Regular),
},
};
}
}
private partial class TeamDisplay : DrawableTournamentTeam
{
public TeamDisplay(TournamentTeam team)
: base(team)
{
AutoSizeAxes = Axes.Both;
Flag.RelativeSizeAxes = Axes.None;
Flag.Scale = new Vector2(1.2f);
2020-03-03 17:12:42 +08:00
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
Flag,
new OsuSpriteText
{
Text = team?.FullName.Value ?? "???",
Font = OsuFont.Torus.With(size: 32, weight: FontWeight.SemiBold),
Colour = TournamentGame.TEXT_COLOUR,
2020-03-03 17:12:42 +08:00
},
}
};
}
}
}
}
}