Move existing tournament resources to new project

This commit is contained in:
Dean Herbert
2018-08-25 21:40:40 +09:00
parent 1eb0277ba3
commit 51dcfeee92
18 changed files with 202 additions and 89 deletions

View File

@ -0,0 +1,30 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Platform;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class DrawingsConfigManager : IniConfigManager<DrawingsConfig>
{
protected override string Filename => @"drawings.ini";
protected override void InitialiseDefaults()
{
Set(DrawingsConfig.Groups, 8, 1, 8);
Set(DrawingsConfig.TeamsPerGroup, 8, 1, 8);
}
public DrawingsConfigManager(Storage storage)
: base(storage)
{
}
}
public enum DrawingsConfig
{
Groups,
TeamsPerGroup
}
}

View File

@ -0,0 +1,29 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class TournamentTeam
{
/// <summary>
/// The name of this team.
/// </summary>
public string FullName;
/// <summary>
/// Name of the file containing the flag.
/// </summary>
public string FlagName;
private string acronym;
/// <summary>
/// Short acronym which appears in the group boxes post-selection.
/// </summary>
public string Acronym
{
get { return acronym ?? FullName.Substring(0, 3); }
set { acronym = value; }
}
}
}

View File

@ -0,0 +1,186 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using osu.Framework.Allocation;
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.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class Group : Container
{
public readonly string GroupName;
public int TeamsCount { get; private set; }
private readonly FlowContainer<GroupTeam> teams;
private readonly List<GroupTeam> allTeams = new List<GroupTeam>();
public Group(string name)
{
GroupName = name;
Size = new Vector2(176, 128);
Masking = true;
CornerRadius = 4;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(54, 54, 54, 255)
},
// Group name
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Position = new Vector2(0, 7f),
Text = $"GROUP {name.ToUpperInvariant()}",
TextSize = 8f,
Font = @"Exo2.0-Bold",
Colour = new Color4(255, 204, 34, 255),
},
teams = new FillFlowContainer<GroupTeam>
{
RelativeSizeAxes = Axes.Both,
Spacing = new Vector2(6f, 22),
Margin = new MarginPadding
{
Top = 21f,
Bottom = 7f,
Left = 7f,
Right = 7f
}
}
};
}
public void AddTeam(TournamentTeam team)
{
GroupTeam gt = new GroupTeam(team);
if (TeamsCount < 8)
{
teams.Add(gt);
allTeams.Add(gt);
TeamsCount++;
}
}
public bool ContainsTeam(string fullName)
{
return allTeams.Any(t => t.Team.FullName == fullName);
}
public bool RemoveTeam(TournamentTeam team)
{
allTeams.RemoveAll(gt => gt.Team == team);
if (teams.RemoveAll(gt => gt.Team == team) > 0)
{
TeamsCount--;
return true;
}
return false;
}
public void ClearTeams()
{
allTeams.Clear();
teams.Clear();
TeamsCount = 0;
}
public string GetStringRepresentation()
{
StringBuilder sb = new StringBuilder();
foreach (GroupTeam gt in allTeams)
sb.AppendLine(gt.Team.FullName);
return sb.ToString();
}
private class GroupTeam : Container
{
public readonly TournamentTeam Team;
private readonly FillFlowContainer innerContainer;
private readonly Sprite flagSprite;
public GroupTeam(TournamentTeam team)
{
Team = team;
Width = 36;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
innerContainer = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
flagSprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
FillMode = FillMode.Fit
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = team.Acronym.ToUpperInvariant(),
TextSize = 10f,
Font = @"Exo2.0-Bold"
}
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
innerContainer.ScaleTo(1.5f);
innerContainer.ScaleTo(1f, 200);
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
flagSprite.Texture = textures.Get($@"Flags/{Team.FlagName}");
}
}
}
}

View File

@ -0,0 +1,104 @@
// 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.Linq;
using System.Text;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using OpenTK;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class GroupContainer : Container
{
private readonly List<Group> groups = new List<Group>();
private readonly int maxTeams;
private int currentGroup;
public GroupContainer(int numGroups, int teamsPerGroup)
{
FlowContainer<Group> bottomGroups;
FlowContainer<Group> topGroups;
maxTeams = teamsPerGroup;
char nextGroupName = 'A';
Children = new[]
{
topGroups = new FillFlowContainer<Group>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(7f, 0)
},
bottomGroups = new FillFlowContainer<Group>
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(7f, 0)
}
};
for (int i = 0; i < numGroups; i++)
{
Group g = new Group(nextGroupName.ToString());
groups.Add(g);
nextGroupName++;
if (i < (int)Math.Ceiling(numGroups / 2f))
topGroups.Add(g);
else
bottomGroups.Add(g);
}
}
public void AddTeam(TournamentTeam team)
{
if (groups[currentGroup].TeamsCount == maxTeams)
return;
groups[currentGroup].AddTeam(team);
currentGroup = (currentGroup + 1) % groups.Count;
}
public bool ContainsTeam(string fullName)
{
return groups.Any(g => g.ContainsTeam(fullName));
}
public void ClearTeams()
{
foreach (Group g in groups)
g.ClearTeams();
currentGroup = 0;
}
public string GetStringRepresentation()
{
StringBuilder sb = new StringBuilder();
foreach (Group g in groups)
{
if (g != groups.First())
sb.AppendLine();
sb.AppendLine($"Group {g.GroupName}");
sb.Append(g.GetStringRepresentation());
}
return sb.ToString();
}
}
}

View File

@ -0,0 +1,12 @@
// 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.Collections.Generic;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public interface ITeamList
{
IEnumerable<TournamentTeam> Teams { get; }
}
}

View File

@ -0,0 +1,382 @@
// 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.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Threading;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class ScrollingTeamContainer : Container
{
public event Action OnScrollStarted;
public event Action<TournamentTeam> OnSelected;
private readonly List<TournamentTeam> availableTeams = new List<TournamentTeam>();
private readonly Container tracker;
#pragma warning disable 649
// set via reflection.
private float speed;
#pragma warning restore 649
private int expiredCount;
private float offset;
private float timeOffset;
private float leftPos => offset + timeOffset + expiredCount * ScrollingTeam.WIDTH;
private double lastTime;
private ScheduledDelegate delayedStateChangeDelegate;
public ScrollingTeamContainer()
{
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
tracker = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 10f,
Alpha = 0,
Children = new[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.BottomCentre,
Size = new Vector2(2, 55),
Colour = ColourInfo.GradientVertical(Color4.Transparent, Color4.White)
},
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Size = new Vector2(2, 55),
Colour = ColourInfo.GradientVertical(Color4.White, Color4.Transparent)
}
}
}
};
}
private ScrollState _scrollState;
private ScrollState scrollState
{
get { return _scrollState; }
set
{
if (_scrollState == value)
return;
_scrollState = value;
delayedStateChangeDelegate?.Cancel();
switch (value)
{
case ScrollState.Scrolling:
resetSelected();
OnScrollStarted?.Invoke();
speedTo(1000f, 200);
tracker.FadeOut(100);
break;
case ScrollState.Stopping:
speedTo(0f, 2000);
tracker.FadeIn(200);
delayedStateChangeDelegate = Scheduler.AddDelayed(() => scrollState = ScrollState.Stopped, 2300);
break;
case ScrollState.Stopped:
// Find closest to center
if (!Children.Any())
break;
ScrollingTeam closest = null;
foreach (var c in Children)
{
var stc = c as ScrollingTeam;
if (stc == null)
continue;
if (closest == null)
{
closest = stc;
continue;
}
float o = Math.Abs(c.Position.X + c.DrawWidth / 2f - DrawWidth / 2f);
float lastOffset = Math.Abs(closest.Position.X + closest.DrawWidth / 2f - DrawWidth / 2f);
if (o < lastOffset)
closest = stc;
}
Trace.Assert(closest != null, "closest != null");
// ReSharper disable once PossibleNullReferenceException
offset += DrawWidth / 2f - (closest.Position.X + closest.DrawWidth / 2f);
ScrollingTeam st = closest;
availableTeams.RemoveAll(at => at == st.Team);
st.Selected = true;
OnSelected?.Invoke(st.Team);
delayedStateChangeDelegate = Scheduler.AddDelayed(() => scrollState = ScrollState.Idle, 10000);
break;
case ScrollState.Idle:
resetSelected();
OnScrollStarted?.Invoke();
speedTo(40f, 200);
tracker.FadeOut(100);
break;
}
}
}
public void AddTeam(TournamentTeam team)
{
if (availableTeams.Contains(team))
return;
availableTeams.Add(team);
RemoveAll(c => c is ScrollingTeam);
scrollState = ScrollState.Idle;
}
public void AddTeams(IEnumerable<TournamentTeam> teams)
{
if (teams == null)
return;
foreach (TournamentTeam t in teams)
AddTeam(t);
}
public void ClearTeams()
{
availableTeams.Clear();
RemoveAll(c => c is ScrollingTeam);
scrollState = ScrollState.Idle;
}
public void RemoveTeam(TournamentTeam team)
{
availableTeams.Remove(team);
foreach (var c in Children)
{
ScrollingTeam st = c as ScrollingTeam;
if (st == null)
continue;
if (st.Team == team)
{
st.FadeOut(200);
st.Expire();
}
}
}
public void StartScrolling()
{
if (availableTeams.Count == 0)
return;
scrollState = ScrollState.Scrolling;
}
public void StopScrolling()
{
if (availableTeams.Count == 0)
return;
switch (scrollState)
{
case ScrollState.Stopped:
case ScrollState.Idle:
return;
}
scrollState = ScrollState.Stopping;
}
protected override void LoadComplete()
{
base.LoadComplete();
scrollState = ScrollState.Idle;
}
protected override void UpdateAfterChildren()
{
timeOffset -= (float)(Time.Current - lastTime) / 1000 * speed;
lastTime = Time.Current;
if (availableTeams.Count > 0)
{
// Fill more than required to account for transformation + scrolling speed
while (Children.Count(c => c is ScrollingTeam) < DrawWidth * 2 / ScrollingTeam.WIDTH)
addFlags();
}
float pos = leftPos;
foreach (var c in Children)
{
if (!(c is ScrollingTeam))
continue;
if (c.Position.X + c.DrawWidth < 0)
{
c.ClearTransforms();
c.Expire();
expiredCount++;
}
else
{
c.MoveToX(pos, 100);
c.FadeTo(1.0f - Math.Abs(pos - DrawWidth / 2f) / (DrawWidth / 2.5f), 100);
}
pos += ScrollingTeam.WIDTH;
}
}
private void addFlags()
{
foreach (TournamentTeam t in availableTeams)
{
Add(new ScrollingTeam(t)
{
X = leftPos + DrawWidth
});
}
}
private void resetSelected()
{
foreach (var c in Children)
{
ScrollingTeam st = c as ScrollingTeam;
if (st == null)
continue;
if (st.Selected)
{
st.Selected = false;
RemoveTeam(st.Team);
}
}
}
private void speedTo(float value, double duration = 0, Easing easing = Easing.None) =>
this.TransformTo(nameof(speed), value, duration, easing);
private enum ScrollState
{
None,
Idle,
Stopping,
Stopped,
Scrolling
}
public class ScrollingTeam : Container
{
public const float WIDTH = 58;
public const float HEIGHT = 41;
public TournamentTeam Team;
private readonly Sprite flagSprite;
private readonly Box outline;
private bool selected;
public bool Selected
{
get { return selected; }
set
{
selected = value;
if (selected)
outline.FadeIn(100);
else
outline.FadeOut(100);
}
}
public ScrollingTeam(TournamentTeam team)
{
Team = team;
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
Size = new Vector2(WIDTH, HEIGHT);
Masking = true;
CornerRadius = 8f;
Alpha = 0;
Children = new Drawable[]
{
outline = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0
},
flagSprite = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(WIDTH, HEIGHT) - new Vector2(8)
}
};
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
flagSprite.Texture = textures.Get($@"Flags/{Team.FlagName}");
}
}
}
}

View File

@ -0,0 +1,68 @@
// 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 osu.Framework.Logging;
using osu.Framework.Platform;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class StorageBackedTeamList : ITeamList
{
private const string teams_filename = "drawings.txt";
private readonly Storage storage;
public StorageBackedTeamList(Storage storage)
{
this.storage = storage;
}
public IEnumerable<TournamentTeam> Teams
{
get
{
var teams = new List<TournamentTeam>();
try
{
using (Stream stream = storage.GetStream(teams_filename, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
{
while (sr.Peek() != -1)
{
string line = sr.ReadLine()?.Trim();
if (string.IsNullOrEmpty(line))
continue;
// ReSharper disable once PossibleNullReferenceException
string[] split = line.Split(':');
if (split.Length < 2)
{
Logger.Log($"Invalid team definition: {line}. Expected \"flag_name : team_name : team_acronym\".");
continue;
}
teams.Add(new TournamentTeam
{
FlagName = split[0].Trim(),
FullName = split[1].Trim(),
Acronym = split.Length >= 3 ? split[2].Trim() : null
});
}
}
}
catch (Exception ex)
{
Logger.Error(ex, "Failed to read teams.");
}
return teams;
}
}
}
}

View File

@ -0,0 +1,124 @@
// 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.Collections.Generic;
using System.Linq;
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.MathUtils;
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public class VisualiserContainer : Container
{
/// <summary>
/// Number of lines in the visualiser.
/// </summary>
public int Lines
{
get { return allLines.Count; }
set
{
while (value > allLines.Count)
addLine();
while (value < allLines.Count)
removeLine();
}
}
private readonly List<VisualiserLine> allLines = new List<VisualiserLine>();
private float offset;
private void addLine()
{
VisualiserLine newLine = new VisualiserLine
{
RelativeSizeAxes = Axes.Both,
Offset = offset,
CycleTime = RNG.Next(10000, 12000),
};
allLines.Add(newLine);
Add(newLine);
offset += RNG.Next(100, 5000);
}
private void removeLine()
{
if (allLines.Count == 0)
return;
Remove(allLines.First());
allLines.Remove(allLines.First());
}
private class VisualiserLine : Container
{
/// <summary>
/// Time offset.
/// </summary>
public float Offset;
public double CycleTime;
private float leftPos => -(float)((Time.Current + Offset) / CycleTime) + expiredCount;
private Texture texture;
private int expiredCount;
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
texture = textures.Get("Drawings/visualiser-line");
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
while (Children.Count < 3)
addLine();
float pos = leftPos;
foreach (var c in Children)
{
if (c.Position.X < -1)
{
c.ClearTransforms();
c.Expire();
expiredCount++;
}
else
c.MoveToX(pos, 100);
pos += 1;
}
}
private void addLine()
{
Add(new Sprite
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Texture = texture,
X = leftPos + 1
});
}
}
}
}

View File

@ -0,0 +1,351 @@
// 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.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
using osu.Game.Screens.Backgrounds;
using osu.Game.Tournament.Screens.Drawings.Components;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Tournament.Screens.Drawings
{
public class DrawingsScreen : OsuScreen
{
private const string results_filename = "drawings_results.txt";
protected override bool HideOverlaysOnEnter => true;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
private ScrollingTeamContainer teamsContainer;
private GroupContainer groupsContainer;
private OsuSpriteText fullTeamNameText;
private readonly List<TournamentTeam> allTeams = new List<TournamentTeam>();
private DrawingsConfigManager drawingsConfig;
private Task writeOp;
private Storage storage;
public ITeamList TeamList;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
[BackgroundDependencyLoader]
private void load(TextureStore textures, Storage storage)
{
this.storage = storage;
TextureStore flagStore = new TextureStore();
// Local flag store
flagStore.AddStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), "Drawings")));
// 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[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(77, 77, 77, 255)
},
new Sprite
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Texture = textures.Get(@"Backgrounds/Drawings/background.png")
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
// Main container
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.85f,
Children = new Drawable[]
{
// Visualiser
new VisualiserContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 10),
Colour = new Color4(255, 204, 34, 255),
Lines = 6
},
// Groups
groupsContainer = new GroupContainer(drawingsConfig.Get<int>(DrawingsConfig.Groups), drawingsConfig.Get<int>(DrawingsConfig.TeamsPerGroup))
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Padding = new MarginPadding
{
Top = 35f,
Bottom = 35f
}
},
// Scrolling teams
teamsContainer = new ScrollingTeamContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
},
// Scrolling team name
fullTeamNameText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Position = new Vector2(0, 45f),
Alpha = 0,
Font = "Exo2.0-Light",
TextSize = 42f
}
}
},
// Control panel container
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.15f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(54, 54, 54, 255)
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = "Control Panel",
TextSize = 22f,
Font = "Exo2.0-Bold"
},
new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.75f,
Position = new Vector2(0, 35f),
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Begin random",
Action = teamsContainer.StartScrolling,
},
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Stop random",
Action = teamsContainer.StopScrolling,
},
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Reload",
Action = reloadTeams
}
}
},
new FillFlowContainer
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.75f,
Position = new Vector2(0, -5f),
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Reset",
Action = () => reset()
}
}
}
}
}
}
}
};
teamsContainer.OnSelected += onTeamSelected;
teamsContainer.OnScrollStarted += () => fullTeamNameText.FadeOut(200);
reset(true);
}
private void onTeamSelected(TournamentTeam team)
{
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();
foreach (TournamentTeam t in TeamList.Teams)
{
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;
if (line.ToUpperInvariant().StartsWith("GROUP"))
continue;
// ReSharper disable once AccessToModifiedClosure
TournamentTeam teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line);
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);
}
}
}
}