2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
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;
|
2018-08-25 20:40:40 +08:00
|
|
|
|
using osu.Framework.IO.Stores;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
|
using osu.Framework.Platform;
|
2018-11-04 03:58:35 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-08-25 20:40:40 +08:00
|
|
|
|
using osu.Game.Screens;
|
2018-08-26 00:24:19 +08:00
|
|
|
|
using osu.Game.Tournament.Components;
|
2018-08-25 20:40:40 +08:00
|
|
|
|
using osu.Game.Tournament.Screens.Drawings.Components;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-25 20:40:40 +08:00
|
|
|
|
public class DrawingsScreen : OsuScreen
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private const string results_filename = "drawings_results.txt";
|
|
|
|
|
|
2018-05-21 21:53:50 +08:00
|
|
|
|
protected override bool HideOverlaysOnEnter => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
protected override BackgroundScreen CreateBackground() => null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private ScrollingTeamContainer teamsContainer;
|
|
|
|
|
private GroupContainer groupsContainer;
|
|
|
|
|
private OsuSpriteText fullTeamNameText;
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
private readonly List<TournamentTeam> allTeams = new List<TournamentTeam>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private DrawingsConfigManager drawingsConfig;
|
|
|
|
|
|
|
|
|
|
private Task writeOp;
|
|
|
|
|
|
|
|
|
|
private Storage storage;
|
|
|
|
|
|
|
|
|
|
public ITeamList TeamList;
|
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
|
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(TextureStore textures, Storage storage)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-04 03:58:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
this.storage = storage;
|
|
|
|
|
|
|
|
|
|
TextureStore flagStore = new TextureStore();
|
|
|
|
|
// Local flag store
|
2018-09-07 17:56:08 +08:00
|
|
|
|
flagStore.AddStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), "Drawings")));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
// Default texture store
|
|
|
|
|
flagStore.AddStore(textures);
|
|
|
|
|
|
|
|
|
|
dependencies.Cache(flagStore);
|
|
|
|
|
|
|
|
|
|
if (TeamList == null)
|
|
|
|
|
TeamList = new StorageBackedTeamList(storage);
|
|
|
|
|
|
|
|
|
|
if (!TeamList.Teams.Any())
|
|
|
|
|
{
|
|
|
|
|
Exit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawingsConfig = new DrawingsConfigManager(storage);
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-11-04 03:58:35 +08:00
|
|
|
|
// Main container
|
|
|
|
|
new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
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
|
|
|
|
|
fullTeamNameText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.33f),
|
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
|
|
|
|
|
2018-11-04 03:58:35 +08:00
|
|
|
|
Font = "Exo2.0-Light",
|
|
|
|
|
TextSize = 42f
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Control panel container
|
2018-11-08 02:51:39 +08:00
|
|
|
|
new ControlPanel
|
2018-11-04 03:58:35 +08:00
|
|
|
|
{
|
2018-11-08 02:51:39 +08:00
|
|
|
|
new TriangleButton
|
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,
|
|
|
|
|
},
|
|
|
|
|
new TriangleButton
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
new TriangleButton
|
|
|
|
|
{
|
|
|
|
|
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(),
|
|
|
|
|
new TriangleButton
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-08 02:51:39 +08:00
|
|
|
|
Text = "Reset",
|
|
|
|
|
Action = () => reset()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
teamsContainer.OnSelected += onTeamSelected;
|
|
|
|
|
teamsContainer.OnScrollStarted += () => fullTeamNameText.FadeOut(200);
|
|
|
|
|
|
|
|
|
|
reset(true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
private void onTeamSelected(TournamentTeam team)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
groupsContainer.AddTeam(team);
|
|
|
|
|
|
|
|
|
|
fullTeamNameText.Text = team.FullName;
|
|
|
|
|
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.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writeOp = writeOp?.ContinueWith(t => { writeAction(); }) ?? Task.Run((Action)writeAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reloadTeams()
|
|
|
|
|
{
|
|
|
|
|
teamsContainer.ClearTeams();
|
|
|
|
|
allTeams.Clear();
|
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
foreach (TournamentTeam t in TeamList.Teams)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (groupsContainer.ContainsTeam(t.FullName))
|
|
|
|
|
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;
|
|
|
|
|
while ((line = sr.ReadLine()?.Trim()) != null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-07-24 20:42:06 +08:00
|
|
|
|
if (line.ToUpperInvariant().StartsWith("GROUP"))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once AccessToModifiedClosure
|
2018-08-25 20:40:40 +08:00
|
|
|
|
TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line);
|
2018-04-13 17:19:50 +08: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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|