1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 18:12:56 +08:00

Finish it up, slightly hackishly, but that's ok.

This commit is contained in:
smoogipooo 2017-02-27 22:50:34 +09:00
parent 5f3e484353
commit 9d731af01b
4 changed files with 402 additions and 168 deletions

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Tournament.Components; using osu.Game.Screens.Tournament.Components;
using System; using System;
@ -13,6 +14,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Input;
using System.IO;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
namespace osu.Game.Screens.Tournament namespace osu.Game.Screens.Tournament
{ {
@ -20,48 +25,175 @@ namespace osu.Game.Screens.Tournament
{ {
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
private ScrollingTeamContainer teamsContainer;
private GroupsContainer groupsContainer;
public Drawings() public Drawings()
{ {
GroupsContainer gc; }
ScrollingTeamContainer stc;
[BackgroundDependencyLoader]
private void load(Framework.Game game)
{
Container visualiserContainer; Container visualiserContainer;
SpriteText st;
Children = new Drawable[] Children = new Drawable[]
{ {
// Visualiser new FlowContainer()
visualiserContainer = new Container()
{ {
Anchor = Anchor.Centre, RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre, Direction = FlowDirections.Horizontal,
RelativeSizeAxes = Axes.X, Children = new Drawable[]
Size = new Vector2(1, 10),
Colour = new Color4(255, 204, 34, 255)
},
// Groups
gc = new GroupsContainer(8)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Padding = new MarginPadding()
{ {
Top = 35f, // Main container
Bottom = 35f new Container()
} {
}, RelativeSizeAxes = Axes.Both,
stc = new ScrollingTeamContainer() Width = 0.85f,
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, Children = new Drawable[]
Width = 0.75f {
}, // Visualiser
visualiserContainer = new Container()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 10),
Colour = new Color4(255, 204, 34, 255)
},
// Groups
groupsContainer = new GroupsContainer(8)
{
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
st = new SpriteText()
{
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 SpriteText()
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = "Control Panel",
TextSize = 22f,
Font = "Exo2.0-Boldd"
},
new FlowContainer()
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.75f,
Position = new Vector2(0, 35f),
Direction = FlowDirections.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
new OsuButton()
{
RelativeSizeAxes = Axes.X,
Text = "Begin random",
Action = teamsContainer.StartScrolling,
},
new OsuButton()
{
RelativeSizeAxes = Axes.X,
Text = "Stop random",
Action = teamsContainer.StopScrolling,
},
new OsuButton()
{
RelativeSizeAxes = Axes.X,
Text = "Reload",
Action = reloadTeams
}
}
},
new FlowContainer()
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.75f,
Position = new Vector2(0, -5f),
Direction = FlowDirections.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
new OsuButton()
{
RelativeSizeAxes = Axes.X,
Text = "Reset",
Action = reset
}
}
}
}
}
}
}
}; };
float offset = 0; float offset = 0;
@ -75,26 +207,55 @@ namespace osu.Game.Screens.Tournament
offset += (float)Math.PI / 6f; offset += (float)Math.PI / 6f;
} }
teamsContainer.OnSelected += t =>
Team t = new Team()
{ {
FullName = "Australia", groupsContainer.AddTeam(t.Team);
Acronym = "AUS",
FlagName = "AU" st.Text = t.Team.FullName;
st.FadeIn(200);
}; };
List<Team> teams = new List<Team>(); teamsContainer.OnScrollStarted += () => st.FadeOut(200);
for (int i = 0; i < 17; i++) reloadTeams();
}
private void reloadTeams()
{
teamsContainer.ClearTeams();
try
{ {
gc.AddTeam(t); foreach (string s in File.ReadAllLines("drawings.txt"))
teams.Add(t); {
string[] split = s.Split(':');
string flagName = split[0].Trim();
string name = split[1].Trim();
string acronym = name.Substring(0, Math.Min(3, name.Length));
if (split.Length >= 3)
acronym = split[2].Trim();
if (groupsContainer.ContainsTeam(name))
continue;
teamsContainer.AddTeam(new Team()
{
FlagName = flagName,
FullName = name,
Acronym = acronym
});
}
} }
catch { }
}
stc.AvailableTeams = teams; private void reset()
{
groupsContainer.ClearTeams();
teamsContainer.ClearTeams();
stc.StartScrolling(); reloadTeams();
Delay(3000).Schedule(() => stc.StopScrolling());
} }
} }
} }

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,6 +24,8 @@ namespace osu.Game.Screens.Tournament
private FlowContainer<GroupTeam> topTeams; private FlowContainer<GroupTeam> topTeams;
private FlowContainer<GroupTeam> bottomTeams; private FlowContainer<GroupTeam> bottomTeams;
private List<GroupTeam> allTeams = new List<GroupTeam>();
private int topTeamsCount; private int topTeamsCount;
private int bottomTeamsCount; private int bottomTeamsCount;
@ -95,20 +98,31 @@ namespace osu.Game.Screens.Tournament
public void AddTeam(Team team) public void AddTeam(Team team)
{ {
GroupTeam gt = new GroupTeam(team);
if (topTeamsCount < 4) if (topTeamsCount < 4)
{ {
topTeams.Add(new GroupTeam(team)); topTeams.Add(gt);
allTeams.Add(gt);
topTeamsCount++; topTeamsCount++;
} }
else if (bottomTeamsCount < 4) else if (bottomTeamsCount < 4)
{ {
bottomTeams.Add(new GroupTeam(team)); bottomTeams.Add(gt);
allTeams.Add(gt);
bottomTeamsCount++; bottomTeamsCount++;
} }
} }
public bool ContainsTeam(string fullName)
{
return allTeams.Any(t => t.Team.FullName == fullName);
}
public bool RemoveTeam(Team team) public bool RemoveTeam(Team team)
{ {
allTeams.RemoveAll(gt => gt.Team == team);
if (topTeams.RemoveAll(gt => gt.Team == team) > 0) if (topTeams.RemoveAll(gt => gt.Team == team) > 0)
{ {
topTeamsCount--; topTeamsCount--;
@ -125,6 +139,7 @@ namespace osu.Game.Screens.Tournament
public void ClearTeams() public void ClearTeams()
{ {
allTeams.Clear();
topTeams.Clear(); topTeams.Clear();
bottomTeams.Clear(); bottomTeams.Clear();
@ -132,10 +147,11 @@ namespace osu.Game.Screens.Tournament
bottomTeamsCount = 0; bottomTeamsCount = 0;
} }
class GroupTeam : FlowContainer class GroupTeam : Container
{ {
public Team Team; public Team Team;
private FlowContainer innerContainer;
private Sprite flagSprite; private Sprite flagSprite;
public GroupTeam(Team team) public GroupTeam(Team team)
@ -144,31 +160,51 @@ namespace osu.Game.Screens.Tournament
Size = new Vector2(36, 0); Size = new Vector2(36, 0);
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Direction = FlowDirections.Vertical;
Spacing = new Vector2(0, 5f);
Children = new Drawable[] Children = new Drawable[]
{ {
flagSprite = new Sprite() innerContainer = new FlowContainer()
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.Centre,
Origin = Anchor.TopCentre, Origin = Anchor.Centre,
FillMode = FillMode.Fit RelativeSizeAxes = Axes.X,
}, AutoSizeAxes = Axes.Y,
new SpriteText()
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = team.Acronym.ToUpper(), Direction = FlowDirections.Vertical,
TextSize = 10f, Spacing = new Vector2(0, 5f),
Font = @"Exo2.0-Bold"
Scale = new Vector2(1.5f),
Children = new Drawable[]
{
flagSprite = new Sprite()
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
FillMode = FillMode.Fit
},
new SpriteText()
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = team.Acronym.ToUpper(),
TextSize = 10f,
Font = @"Exo2.0-Bold"
}
}
} }
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
innerContainer.ScaleTo(1f, 200);
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore textures) private void load(TextureStore textures)
{ {

View File

@ -68,6 +68,11 @@ namespace osu.Game.Screens.Tournament
} }
} }
public bool ContainsTeam(string fullName)
{
return allGroups.Any(g => g.ContainsTeam(fullName));
}
public bool RemoveTeam(Team team) public bool RemoveTeam(Team team)
{ {
for (int i = 0; i < allGroups.Count; i++) for (int i = 0; i < allGroups.Count; i++)

View File

@ -21,8 +21,10 @@ namespace osu.Game.Screens.Tournament
{ {
public class ScrollingTeamContainer : Container public class ScrollingTeamContainer : Container
{ {
public Action<ScrollingTeam> OnSelected; public event Action OnScrollStarted;
public List<Team> AvailableTeams; public event Action<ScrollingTeam> OnSelected;
private readonly List<Team> availableTeams = new List<Team>();
private Container tracker; private Container tracker;
@ -35,14 +37,54 @@ namespace osu.Game.Screens.Tournament
private double lastTime; private double lastTime;
private ScheduledDelegate idleDelegate;
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),
ColourInfo = ColourInfo.GradientVertical(Color4.Transparent, Color4.White)
},
new Box()
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Size = new Vector2(2, 55),
ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.Transparent)
}
}
}
};
}
private ScrollState _scrollState; private ScrollState _scrollState;
private ScrollState scrollState private ScrollState scrollState
{ {
get { return _scrollState; } get { return _scrollState; }
set set
{ {
if (_scrollState == value)
return;
_scrollState = value; _scrollState = value;
switch (value) switch (value)
@ -52,7 +94,9 @@ namespace osu.Game.Screens.Tournament
resetSelected(); resetSelected();
speedTo(600f, 200); OnScrollStarted?.Invoke();
speedTo(1000f, 200);
tracker.FadeOut(100); tracker.FadeOut(100);
break; break;
case ScrollState.Stopping: case ScrollState.Stopping:
@ -60,7 +104,6 @@ namespace osu.Game.Screens.Tournament
tracker.FadeIn(200); tracker.FadeIn(200);
Delay(2300).Schedule(() => scrollState = ScrollState.Stopped); Delay(2300).Schedule(() => scrollState = ScrollState.Stopped);
DelayReset();
break; break;
case ScrollState.Stopped: case ScrollState.Stopped:
// Find closest to center // Find closest to center
@ -85,14 +128,20 @@ namespace osu.Game.Screens.Tournament
offset += DrawWidth / 2f - (closest.Position.X + closest.DrawWidth / 2f); offset += DrawWidth / 2f - (closest.Position.X + closest.DrawWidth / 2f);
(closest as ScrollingTeam).Selected = true; ScrollingTeam st = closest as ScrollingTeam;
OnSelected?.Invoke(closest as ScrollingTeam);
availableTeams.RemoveAll(at => at == st.Team);
st.Selected = true;
OnSelected?.Invoke(st);
idleDelegate = Delay(10000).Schedule(() => scrollState = ScrollState.Idle); idleDelegate = Delay(10000).Schedule(() => scrollState = ScrollState.Idle);
break; break;
case ScrollState.Idle: case ScrollState.Idle:
resetSelected(); resetSelected();
OnScrollStarted?.Invoke();
speedTo(40f, 200); speedTo(40f, 200);
tracker.FadeOut(100); tracker.FadeOut(100);
break; break;
@ -100,111 +149,22 @@ namespace osu.Game.Screens.Tournament
} }
} }
private ScheduledDelegate idleDelegate; public void AddTeam(Team team)
public ScrollingTeamContainer()
{ {
Masking = true; if (availableTeams.Contains(team))
Clock = new FramedClock(); return;
AutoSizeAxes = Axes.Y; availableTeams.Add(team);
Children = new Drawable[]
{
tracker = new Container()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
CornerRadius = 10f,
AutoSizeAxes = Axes.Both,
Children = new[]
{
new Box()
{
Anchor = Anchor.Centre,
Origin = Anchor.BottomCentre,
Size = new Vector2(2, 100),
ColourInfo = ColourInfo.GradientVertical(Color4.Transparent, Color4.White)
},
new Box()
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Size = new Vector2(2, 100),
ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.Transparent)
}
}
}
};
RemoveAll(c => c is ScrollingTeam);
scrollState = ScrollState.Idle; scrollState = ScrollState.Idle;
} }
protected override void UpdateAfterChildren() public void ClearTeams()
{ {
base.Update(); availableTeams.Clear();
RemoveAll(c => c is ScrollingTeam);
if ((AvailableTeams?.Count ?? 0) == 0) scrollState = ScrollState.Idle;
return;
timeOffset -= (float)(Time.Current - lastTime) / 1000 * speed;
lastTime = Time.Current;
// 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);
pos += ScrollingTeam.WIDTH;
}
}
private void addFlags()
{
for (int i = 0; i < AvailableTeams.Count; i++)
{
Add(new ScrollingTeam(AvailableTeams[i])
{
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);
AvailableTeams.Remove(st.Team);
}
} }
public void RemoveTeam(Team team) public void RemoveTeam(Team team)
@ -234,6 +194,76 @@ namespace osu.Game.Screens.Tournament
scrollState = ScrollState.Stopping; scrollState = ScrollState.Stopping;
} }
protected override void LoadComplete()
{
base.LoadComplete();
scrollState = ScrollState.Idle;
}
protected override void UpdateAfterChildren()
{
base.Update();
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()
{
for (int i = 0; i < availableTeams.Count; i++)
{
Add(new ScrollingTeam(availableTeams[i])
{
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, EasingTypes easing = EasingTypes.None) private void speedTo(float value, double duration = 0, EasingTypes easing = EasingTypes.None)
{ {
DelayReset(); DelayReset();
@ -295,6 +325,8 @@ namespace osu.Game.Screens.Tournament
Masking = true; Masking = true;
CornerRadius = 8f; CornerRadius = 8f;
Alpha = 0;
Children = new Drawable[] Children = new Drawable[]
{ {
outline = new Box() outline = new Box()