2019-03-04 04:24:19 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
|
using osu.Framework.Platform;
|
2018-11-03 19:58:35 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2018-08-25 16:24:19 +00:00
|
|
|
|
using osu.Game.Tournament.Components;
|
2019-06-18 05:51:48 +00:00
|
|
|
|
using osu.Game.Tournament.Models;
|
2018-08-25 12:40:40 +00:00
|
|
|
|
using osu.Game.Tournament.Screens.Drawings.Components;
|
2018-11-22 01:25:30 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-11-08 08:56:11 +00:00
|
|
|
|
public class DrawingsScreen : TournamentScreen
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private const string results_filename = "drawings_results.txt";
|
|
|
|
|
|
|
|
|
|
private ScrollingTeamContainer teamsContainer;
|
|
|
|
|
private GroupContainer groupsContainer;
|
2020-03-03 10:14:44 +00:00
|
|
|
|
private TournamentSpriteText fullTeamNameText;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
private readonly List<TournamentTeam> allTeams = new List<TournamentTeam>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private DrawingsConfigManager drawingsConfig;
|
|
|
|
|
|
|
|
|
|
private Task writeOp;
|
|
|
|
|
|
|
|
|
|
private Storage storage;
|
|
|
|
|
|
|
|
|
|
public ITeamList TeamList;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-30 22:04:40 +00:00
|
|
|
|
private void load(TextureStore textures, Storage storage)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-03 19:58:35 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
this.storage = storage;
|
|
|
|
|
|
2020-06-03 07:48:44 +00:00
|
|
|
|
TeamList ??= new StorageBackedTeamList(storage);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
if (!TeamList.Teams.Any())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawingsConfig = new DrawingsConfigManager(storage);
|
|
|
|
|
|
2019-02-02 09:29:20 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-03 19:58:35 +00:00
|
|
|
|
// Main container
|
|
|
|
|
new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-11-03 19:58:35 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(1, 10),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
Colour = new Color4(255, 204, 34, 255),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 35f,
|
|
|
|
|
Bottom = 35f
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Scrolling teams
|
|
|
|
|
teamsContainer = new ScrollingTeamContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
// Scrolling team name
|
2020-03-03 10:14:44 +00:00
|
|
|
|
fullTeamNameText = new TournamentSpriteText
|
2018-11-03 19:58:35 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
Position = new Vector2(0, 45f),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-03 10:14:44 +00:00
|
|
|
|
Colour = OsuColour.Gray(0.95f),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-03 19:58:35 +00:00
|
|
|
|
Alpha = 0,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-03-03 10:14:44 +00:00
|
|
|
|
Font = OsuFont.Torus.With(weight: FontWeight.Light, size: 42),
|
2018-11-03 19:58:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Control panel container
|
2018-11-07 18:51:39 +00:00
|
|
|
|
new ControlPanel
|
2018-11-03 19:58:35 +00:00
|
|
|
|
{
|
2019-11-08 08:00:47 +00:00
|
|
|
|
new TourneyButton
|
2018-11-03 19:58:35 +00:00
|
|
|
|
{
|
2018-11-07 18:51:39 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-11-03 19:58:35 +00:00
|
|
|
|
|
2018-11-07 18:51:39 +00:00
|
|
|
|
Text = "Begin random",
|
|
|
|
|
Action = teamsContainer.StartScrolling,
|
|
|
|
|
},
|
2019-11-08 08:00:47 +00:00
|
|
|
|
new TourneyButton
|
2018-11-07 18:51:39 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-07 18:51:39 +00:00
|
|
|
|
Text = "Stop random",
|
|
|
|
|
Action = teamsContainer.StopScrolling,
|
|
|
|
|
},
|
2019-11-08 08:00:47 +00:00
|
|
|
|
new TourneyButton
|
2018-11-07 18:51:39 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-07 18:51:39 +00:00
|
|
|
|
Text = "Reload",
|
|
|
|
|
Action = reloadTeams
|
|
|
|
|
},
|
|
|
|
|
new ControlPanel.Spacer(),
|
2019-11-08 08:00:47 +00:00
|
|
|
|
new TourneyButton
|
2018-11-07 18:51:39 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-07 18:51:39 +00:00
|
|
|
|
Text = "Reset",
|
|
|
|
|
Action = () => reset()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
teamsContainer.OnSelected += onTeamSelected;
|
|
|
|
|
teamsContainer.OnScrollStarted += () => fullTeamNameText.FadeOut(200);
|
|
|
|
|
|
|
|
|
|
reset(true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
private void onTeamSelected(TournamentTeam team)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
groupsContainer.AddTeam(team);
|
|
|
|
|
|
2019-06-17 07:28:58 +00:00
|
|
|
|
fullTeamNameText.Text = team.FullName.Value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
fullTeamNameText.FadeIn(200);
|
|
|
|
|
|
|
|
|
|
writeResults(groupsContainer.GetStringRepresentation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void writeResults(string text)
|
|
|
|
|
{
|
|
|
|
|
void writeAction()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Write to drawings_results
|
|
|
|
|
using (Stream stream = storage.GetStream(results_filename, FileAccess.Write, FileMode.Create))
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(stream))
|
|
|
|
|
{
|
|
|
|
|
sw.Write(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "Failed to write results.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 15:09:08 +00:00
|
|
|
|
writeOp = writeOp?.ContinueWith(t => { writeAction(); }) ?? Task.Run(writeAction);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reloadTeams()
|
|
|
|
|
{
|
|
|
|
|
teamsContainer.ClearTeams();
|
|
|
|
|
allTeams.Clear();
|
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
foreach (TournamentTeam t in TeamList.Teams)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-17 07:28:58 +00:00
|
|
|
|
if (groupsContainer.ContainsTeam(t.FullName.Value))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
allTeams.Add(t);
|
|
|
|
|
teamsContainer.AddTeam(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reset(bool loadLastResults = false)
|
|
|
|
|
{
|
|
|
|
|
groupsContainer.ClearTeams();
|
|
|
|
|
|
|
|
|
|
reloadTeams();
|
|
|
|
|
|
|
|
|
|
if (!storage.Exists(results_filename))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (loadLastResults)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Read from drawings_results
|
|
|
|
|
using (Stream stream = storage.GetStream(results_filename, FileAccess.Read, FileMode.Open))
|
|
|
|
|
using (StreamReader sr = new StreamReader(stream))
|
|
|
|
|
{
|
|
|
|
|
string line;
|
2019-05-15 03:08:23 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
while ((line = sr.ReadLine()?.Trim()) != null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-07-24 12:42:06 +00:00
|
|
|
|
if (line.ToUpperInvariant().StartsWith("GROUP"))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once AccessToModifiedClosure
|
2019-06-17 07:28:58 +00:00
|
|
|
|
TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName.Value == line);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
if (teamToAdd == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
groupsContainer.AddTeam(teamToAdd);
|
|
|
|
|
teamsContainer.RemoveTeam(teamToAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(ex, "Failed to read last drawings results.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
writeResults(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|