2017-03-03 12:17:24 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
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;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
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;
|
2017-03-03 19:27:53 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
|
using osu.Game.Screens.Tournament.Components;
|
2017-03-03 19:42:22 +08:00
|
|
|
|
using osu.Game.Screens.Tournament.Teams;
|
2017-03-03 19:21:11 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Tournament
|
|
|
|
|
{
|
|
|
|
|
public class Drawings : OsuScreen
|
|
|
|
|
{
|
2017-03-03 11:59:58 +08:00
|
|
|
|
private const string results_filename = "drawings_results.txt";
|
|
|
|
|
|
2017-02-27 22:38:29 +08:00
|
|
|
|
internal override bool ShowOverlays => false;
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
|
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
private ScrollingTeamContainer teamsContainer;
|
2017-03-03 19:46:07 +08:00
|
|
|
|
private GroupContainer groupsContainer;
|
2017-03-03 19:27:53 +08:00
|
|
|
|
private OsuSpriteText fullTeamNameText;
|
2017-02-27 21:50:34 +08:00
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
private List<Team> allTeams = new List<Team>();
|
|
|
|
|
|
2017-02-27 22:09:26 +08:00
|
|
|
|
private DrawingsConfigManager drawingsConfig;
|
|
|
|
|
|
2017-03-02 11:02:50 +08:00
|
|
|
|
private Task writeOp;
|
2017-02-27 21:50:34 +08:00
|
|
|
|
|
2017-03-03 11:59:58 +08:00
|
|
|
|
private Storage storage;
|
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
public ITeamList TeamList;
|
2017-03-03 17:47:56 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-03-03 13:11:47 +08:00
|
|
|
|
private void load(TextureStore textures, Storage storage)
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
2017-03-03 11:59:58 +08:00
|
|
|
|
this.storage = storage;
|
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
if (TeamList == null)
|
2017-03-03 19:42:22 +08:00
|
|
|
|
TeamList = new StorageBackedTeamList(storage);
|
2017-03-03 19:21:11 +08:00
|
|
|
|
|
|
|
|
|
if (!TeamList.Teams.Any())
|
2017-03-03 11:43:48 +08:00
|
|
|
|
{
|
|
|
|
|
Exit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 11:59:58 +08:00
|
|
|
|
drawingsConfig = new DrawingsConfigManager(storage);
|
2017-02-27 22:09:26 +08:00
|
|
|
|
|
2017-02-27 14:02:38 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new Box
|
2017-02-28 09:26:37 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(77, 77, 77, 255)
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new Sprite
|
2017-02-28 09:26:37 +08:00
|
|
|
|
{
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
Texture = textures.Get(@"Backgrounds/Drawings/background.png")
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-27 14:02:38 +08:00
|
|
|
|
{
|
2017-02-27 21:50:34 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-03-03 12:17:06 +08:00
|
|
|
|
Direction = FillDirection.Right,
|
2017-02-27 14:02:38 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
// Main container
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new Container
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.85f,
|
2017-02-27 14:02:38 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
// Visualiser
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new VisualiserContainer
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(1, 10),
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-03-03 14:43:16 +08:00
|
|
|
|
Colour = new Color4(255, 204, 34, 255),
|
|
|
|
|
|
|
|
|
|
Lines = 6
|
2017-02-27 21:50:34 +08:00
|
|
|
|
},
|
|
|
|
|
// Groups
|
2017-03-03 19:46:07 +08:00
|
|
|
|
groupsContainer = new GroupContainer(drawingsConfig.Get<int>(DrawingsConfig.Groups), drawingsConfig.Get<int>(DrawingsConfig.TeamsPerGroup))
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
Padding = new MarginPadding
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Top = 35f,
|
|
|
|
|
Bottom = 35f
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Scrolling teams
|
2017-03-03 19:21:11 +08:00
|
|
|
|
teamsContainer = new ScrollingTeamContainer
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
// Scrolling team name
|
2017-03-03 19:27:53 +08:00
|
|
|
|
fullTeamNameText = new OsuSpriteText
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
|
|
|
|
|
Position = new Vector2(0, 45f),
|
|
|
|
|
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
|
|
|
|
|
Font = "Exo2.0-Light",
|
|
|
|
|
TextSize = 42f
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Control panel container
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new Container
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.15f,
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new Box
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(54, 54, 54, 255)
|
|
|
|
|
},
|
2017-03-03 19:27:53 +08:00
|
|
|
|
new OsuSpriteText
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
|
|
|
|
|
Text = "Control Panel",
|
|
|
|
|
TextSize = 22f,
|
|
|
|
|
Font = "Exo2.0-Boldd"
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Width = 0.75f,
|
|
|
|
|
|
|
|
|
|
Position = new Vector2(0, 35f),
|
|
|
|
|
|
2017-03-03 12:17:06 +08:00
|
|
|
|
Direction = FillDirection.Down,
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Spacing = new Vector2(0, 5f),
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new OsuButton
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-02-27 14:02:38 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Text = "Begin random",
|
|
|
|
|
Action = teamsContainer.StartScrolling,
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new OsuButton
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
|
|
|
|
|
Text = "Stop random",
|
|
|
|
|
Action = teamsContainer.StopScrolling,
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new OsuButton
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
|
|
|
|
|
Text = "Reload",
|
|
|
|
|
Action = reloadTeams
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Width = 0.75f,
|
|
|
|
|
|
|
|
|
|
Position = new Vector2(0, -5f),
|
|
|
|
|
|
2017-03-03 12:17:06 +08:00
|
|
|
|
Direction = FillDirection.Down,
|
2017-02-27 21:50:34 +08:00
|
|
|
|
Spacing = new Vector2(0, 5f),
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-03 19:21:11 +08:00
|
|
|
|
new OsuButton
|
2017-02-27 21:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
|
|
|
|
|
Text = "Reset",
|
2017-03-02 11:02:50 +08:00
|
|
|
|
Action = () => reset(false)
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-27 13:19:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
teamsContainer.OnSelected += onTeamSelected;
|
|
|
|
|
teamsContainer.OnScrollStarted += () => fullTeamNameText.FadeOut(200);
|
2017-02-27 21:50:34 +08:00
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
reset(true);
|
|
|
|
|
}
|
2017-03-02 11:02:50 +08:00
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
private void onTeamSelected(Team team)
|
|
|
|
|
{
|
|
|
|
|
groupsContainer.AddTeam(team);
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-03-03 13:51:19 +08:00
|
|
|
|
fullTeamNameText.Text = team.FullName;
|
|
|
|
|
fullTeamNameText.FadeIn(200);
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-03-03 19:42:22 +08:00
|
|
|
|
writeResults(groupsContainer.GetStringRepresentation());
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void writeResults(string text)
|
|
|
|
|
{
|
2017-03-03 13:51:19 +08:00
|
|
|
|
Action 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
|
|
|
|
|
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.");
|
2017-03-02 11:02:50 +08:00
|
|
|
|
}
|
2017-03-03 13:51:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (writeOp == null)
|
|
|
|
|
writeOp = Task.Run(writeAction);
|
|
|
|
|
else
|
|
|
|
|
writeOp = writeOp.ContinueWith(t => { writeAction(); });
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reloadTeams()
|
|
|
|
|
{
|
|
|
|
|
teamsContainer.ClearTeams();
|
2017-03-02 11:02:50 +08:00
|
|
|
|
allTeams.Clear();
|
2017-02-27 21:50:34 +08:00
|
|
|
|
|
2017-03-03 19:21:11 +08:00
|
|
|
|
foreach (Team t in TeamList.Teams)
|
2017-02-27 13:19:07 +08:00
|
|
|
|
{
|
2017-03-03 17:47:56 +08:00
|
|
|
|
if (groupsContainer.ContainsTeam(t.FullName))
|
|
|
|
|
continue;
|
2017-03-03 14:59:33 +08:00
|
|
|
|
|
2017-03-03 17:47:56 +08:00
|
|
|
|
allTeams.Add(t);
|
|
|
|
|
teamsContainer.AddTeam(t);
|
2017-02-27 13:19:07 +08:00
|
|
|
|
}
|
2017-02-27 21:50:34 +08:00
|
|
|
|
}
|
2017-02-27 13:19:07 +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();
|
2017-02-27 13:19:07 +08:00
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
reloadTeams();
|
2017-03-02 11:02: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;
|
|
|
|
|
while ((line = sr.ReadLine()?.Trim()) != null)
|
2017-03-02 11:02:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (line.ToUpper().StartsWith("GROUP"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Team teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line);
|
|
|
|
|
|
|
|
|
|
if (teamToAdd == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|