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-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-02-27 13:19:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using System.IO;
|
2017-02-27 13:19:07 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-02-27 21:50:34 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-07-30 12:21:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-02-28 09:26:37 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-03-03 14:59:33 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2018-11-04 03:58:35 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2021-07-30 12:21:50 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-08-26 00:24:19 +08:00
|
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 13:51:48 +08:00
|
|
|
|
using osu.Game.Tournament.Models;
|
2018-08-25 20:40:40 +08:00
|
|
|
|
using osu.Game.Tournament.Screens.Drawings.Components;
|
2018-11-22 09:25:30 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2019-11-08 16:56:11 +08:00
|
|
|
|
public class DrawingsScreen : TournamentScreen
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2017-03-03 11:59:58 +08:00
|
|
|
|
private const string results_filename = "drawings_results.txt";
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
private ScrollingTeamContainer teamsContainer;
|
2017-03-03 19:46:07 +08:00
|
|
|
|
private GroupContainer groupsContainer;
|
2020-03-03 18:14:44 +08:00
|
|
|
|
private TournamentSpriteText fullTeamNameText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
private readonly List<TournamentTeam> allTeams = new List<TournamentTeam>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-27 22:09:26 +08:00
|
|
|
|
private DrawingsConfigManager drawingsConfig;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
private Task writeOp;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 11:59:58 +08:00
|
|
|
|
private Storage storage;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
public ITeamList TeamList;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(TextureStore textures, Storage storage)
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
2018-11-04 03:58:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2017-03-03 11:59:58 +08:00
|
|
|
|
this.storage = storage;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-06-03 15:48:44 +08:00
|
|
|
|
TeamList ??= new StorageBackedTeamList(storage);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
if (!TeamList.Teams.Any())
|
2017-03-03 11:43:48 +08:00
|
|
|
|
{
|
2021-07-30 12:21:50 +08:00
|
|
|
|
LinkFlowContainer links;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Height = 0.3f,
|
|
|
|
|
},
|
|
|
|
|
new WarningBox("No drawings.txt file found. Please create one and restart the client."),
|
|
|
|
|
links = new LinkFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Y = 60,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
links.AddLink("Click for details on the file format", "https://osu.ppy.sh/wiki/en/Tournament_Drawings", t => t.Colour = Color4.White);
|
2017-03-03 11:43:48 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 11:59:58 +08:00
|
|
|
|
drawingsConfig = new DrawingsConfigManager(storage);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-02 17:29:20 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2018-11-04 03:58:35 +08:00
|
|
|
|
// Main container
|
|
|
|
|
new Container
|
2017-02-28 09:26:37 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-11-04 03:58:35 +08:00
|
|
|
|
new Sprite
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Texture = textures.Get(@"Backgrounds/Drawings/background.png")
|
|
|
|
|
},
|
|
|
|
|
// Visualiser
|
|
|
|
|
new VisualiserContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(1, 10),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Colour = new Color4(255, 204, 34, 255),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Lines = 6
|
|
|
|
|
},
|
|
|
|
|
// Groups
|
|
|
|
|
groupsContainer = new GroupContainer(drawingsConfig.Get<int>(DrawingsConfig.Groups), drawingsConfig.Get<int>(DrawingsConfig.TeamsPerGroup))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 35f,
|
|
|
|
|
Bottom = 35f
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Scrolling teams
|
|
|
|
|
teamsContainer = new ScrollingTeamContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
// Scrolling team name
|
2020-03-03 18:14:44 +08:00
|
|
|
|
fullTeamNameText = new TournamentSpriteText
|
2018-11-04 03:58:35 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Position = new Vector2(0, 45f),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-03 18:14:44 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.95f),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Alpha = 0,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-03 18:14:44 +08:00
|
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Light, size: 42),
|
2018-11-04 03:58:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Control panel container
|
2018-11-08 02:51:39 +08:00
|
|
|
|
new ControlPanel
|
2018-11-04 03:58:35 +08:00
|
|
|
|
{
|
2019-11-08 16:00:47 +08:00
|
|
|
|
new TourneyButton
|
2018-11-04 03:58:35 +08:00
|
|
|
|
{
|
2018-11-08 02:51:39 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-11-04 03:58:35 +08:00
|
|
|
|
|
2018-11-08 02:51:39 +08:00
|
|
|
|
Text = "Begin random",
|
|
|
|
|
Action = teamsContainer.StartScrolling,
|
|
|
|
|
},
|
2019-11-08 16:00:47 +08:00
|
|
|
|
new TourneyButton
|
2018-11-08 02:51:39 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-08 02:51:39 +08:00
|
|
|
|
Text = "Stop random",
|
|
|
|
|
Action = teamsContainer.StopScrolling,
|
|
|
|
|
},
|
2019-11-08 16:00:47 +08:00
|
|
|
|
new TourneyButton
|
2018-11-08 02:51:39 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-08 02:51:39 +08:00
|
|
|
|
Text = "Reload",
|
|
|
|
|
Action = reloadTeams
|
|
|
|
|
},
|
|
|
|
|
new ControlPanel.Spacer(),
|
2019-11-08 16:00:47 +08:00
|
|
|
|
new TourneyButton
|
2018-11-08 02:51:39 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-08 02:51:39 +08:00
|
|
|
|
Text = "Reset",
|
|
|
|
|
Action = () => reset()
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-27 13:19:07 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
teamsContainer.OnSelected += onTeamSelected;
|
|
|
|
|
teamsContainer.OnScrollStarted += () => fullTeamNameText.FadeOut(200);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
reset(true);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
private void onTeamSelected(TournamentTeam team)
|
2017-03-03 13:51:19 +08:00
|
|
|
|
{
|
|
|
|
|
groupsContainer.AddTeam(team);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-17 15:28:58 +08:00
|
|
|
|
fullTeamNameText.Text = team.FullName.Value;
|
2017-03-03 13:51:19 +08:00
|
|
|
|
fullTeamNameText.FadeIn(200);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 19:42:22 +08:00
|
|
|
|
writeResults(groupsContainer.GetStringRepresentation());
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
private void writeResults(string text)
|
|
|
|
|
{
|
2018-01-16 02:42:17 +08:00
|
|
|
|
void writeAction()
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 14:59:33 +08:00
|
|
|
|
try
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 14:59:33 +08:00
|
|
|
|
// Write to drawings_results
|
2022-05-16 17:03:53 +08:00
|
|
|
|
using (Stream stream = storage.CreateFileSafely(results_filename))
|
2017-03-03 14:59:33 +08:00
|
|
|
|
using (StreamWriter sw = new StreamWriter(stream))
|
|
|
|
|
{
|
|
|
|
|
sw.Write(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "Failed to write results.");
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
2018-01-16 02:42:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
writeOp = writeOp?.ContinueWith(_ => { writeAction(); }) ?? Task.Run(writeAction);
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
private void reloadTeams()
|
|
|
|
|
{
|
|
|
|
|
teamsContainer.ClearTeams();
|
2017-03-02 11:02:50 +08:00
|
|
|
|
allTeams.Clear();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
foreach (TournamentTeam t in TeamList.Teams)
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2019-06-17 15:28:58 +08:00
|
|
|
|
if (groupsContainer.ContainsTeam(t.FullName.Value))
|
2017-03-03 17:47:56 +08:00
|
|
|
|
continue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-18 05:16:59 +08:00
|
|
|
|
allTeams.Add(t);
|
|
|
|
|
teamsContainer.AddTeam(t);
|
2017-02-27 13:19:07 +08:00
|
|
|
|
}
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
private void reset(bool loadLastResults = false)
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
groupsContainer.ClearTeams();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
reloadTeams();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-04 22:24:32 +08:00
|
|
|
|
if (!storage.Exists(results_filename))
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 14:59:33 +08:00
|
|
|
|
if (loadLastResults)
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 14:59:33 +08:00
|
|
|
|
try
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
|
|
|
|
// Read from drawings_results
|
2017-03-03 11:59:58 +08:00
|
|
|
|
using (Stream stream = storage.GetStream(results_filename, FileAccess.Read, FileMode.Open))
|
|
|
|
|
using (StreamReader sr = new StreamReader(stream))
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 19:24:34 +08:00
|
|
|
|
string line;
|
2019-05-15 11:08:23 +08:00
|
|
|
|
|
2017-03-03 19:24:34 +08:00
|
|
|
|
while ((line = sr.ReadLine()?.Trim()) != null)
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-16 11:49:31 +08:00
|
|
|
|
if (line.ToUpperInvariant().StartsWith("GROUP", StringComparison.Ordinal))
|
2017-03-02 11:02:50 +08:00
|
|
|
|
continue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-11-20 17:55:48 +08:00
|
|
|
|
// ReSharper disable once AccessToModifiedClosure
|
2019-06-17 15:28:58 +08:00
|
|
|
|
TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName.Value == line);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
if (teamToAdd == null)
|
|
|
|
|
continue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
groupsContainer.AddTeam(teamToAdd);
|
|
|
|
|
teamsContainer.RemoveTeam(teamToAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-03 14:59:33 +08:00
|
|
|
|
catch (Exception ex)
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 14:59:33 +08:00
|
|
|
|
Logger.Error(ex, "Failed to read last drawings results.");
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-03 14:59:33 +08:00
|
|
|
|
else
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
2017-03-03 14:59:33 +08:00
|
|
|
|
writeResults(string.Empty);
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
2017-02-27 13:19:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|