mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Add score display
This commit is contained in:
parent
54b87e9c93
commit
46e163ec5e
40
osu.Game.Tournament.Tests/TestCaseMatchScoreDisplay.cs
Normal file
40
osu.Game.Tournament.Tests/TestCaseMatchScoreDisplay.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Gameplay.Components;
|
||||
|
||||
namespace osu.Game.Tournament.Tests
|
||||
{
|
||||
public class TestCaseMatchScoreDisplay : LadderTestCase
|
||||
{
|
||||
[Cached(Type = typeof(MatchIPCInfo))]
|
||||
private MatchIPCInfo matchInfo = new MatchIPCInfo();
|
||||
|
||||
public TestCaseMatchScoreDisplay()
|
||||
{
|
||||
Add(new MatchScoreDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Scheduler.AddDelayed(() =>
|
||||
{
|
||||
int amount = (int)((RNG.NextDouble() - 0.5) * 10000);
|
||||
if (amount < 0)
|
||||
matchInfo.Score1.Value -= amount;
|
||||
else
|
||||
matchInfo.Score2.Value += amount;
|
||||
}, 100, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform.Windows;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -16,16 +14,7 @@ using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Tournament.IPC
|
||||
{
|
||||
public enum TourneyState
|
||||
{
|
||||
Initialising,
|
||||
Idle,
|
||||
WaitingForClients,
|
||||
Playing,
|
||||
Ranking
|
||||
}
|
||||
|
||||
public class FileBasedIPC : Component
|
||||
public class FileBasedIPC : MatchIPCInfo
|
||||
{
|
||||
[Resolved]
|
||||
protected APIAccess API { get; private set; }
|
||||
@ -33,15 +22,7 @@ namespace osu.Game.Tournament.IPC
|
||||
[Resolved]
|
||||
protected RulesetStore Rulesets { get; private set; }
|
||||
|
||||
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||
|
||||
public readonly Bindable<LegacyMods> Mods = new Bindable<LegacyMods>();
|
||||
|
||||
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
|
||||
|
||||
private int lastBeatmapId;
|
||||
public int Score1;
|
||||
public int Score2;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -97,8 +78,8 @@ namespace osu.Game.Tournament.IPC
|
||||
using (var stream = stable.GetStream(file_ipc_scores_filename))
|
||||
using (var sr = new StreamReader(stream))
|
||||
{
|
||||
Score1 = int.Parse(sr.ReadLine());
|
||||
Score2 = int.Parse(sr.ReadLine());
|
||||
Score1.Value = int.Parse(sr.ReadLine());
|
||||
Score2.Value = int.Parse(sr.ReadLine());
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
19
osu.Game.Tournament/IPC/MatchIPCInfo.cs
Normal file
19
osu.Game.Tournament/IPC/MatchIPCInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Legacy;
|
||||
|
||||
namespace osu.Game.Tournament.IPC
|
||||
{
|
||||
public class MatchIPCInfo : Component
|
||||
{
|
||||
public Bindable<BeatmapInfo> Beatmap { get; } = new Bindable<BeatmapInfo>();
|
||||
public Bindable<LegacyMods> Mods { get; } = new Bindable<LegacyMods>();
|
||||
public Bindable<TourneyState> State { get; } = new Bindable<TourneyState>();
|
||||
public BindableInt Score1 { get; } = new BindableInt();
|
||||
public BindableInt Score2 { get; } = new BindableInt();
|
||||
}
|
||||
}
|
14
osu.Game.Tournament/IPC/TourneyState.cs
Normal file
14
osu.Game.Tournament/IPC/TourneyState.cs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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.IPC
|
||||
{
|
||||
public enum TourneyState
|
||||
{
|
||||
Initialising,
|
||||
Idle,
|
||||
WaitingForClients,
|
||||
Playing,
|
||||
Ranking
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace osu.Game.Tournament.Screens
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FileBasedIPC ipc)
|
||||
private void load(MatchIPCInfo ipc)
|
||||
{
|
||||
ipc.Beatmap.BindValueChanged(beatmapChanged, true);
|
||||
ipc.Mods.BindValueChanged(modsChanged, true);
|
||||
|
@ -17,7 +17,7 @@ using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Gameplay
|
||||
namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
{
|
||||
public class MatchHeader : Container
|
||||
{
|
||||
@ -113,7 +113,7 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new TeamDisplay(team, colour, flip),
|
||||
new ScoreDisplay(currentTeamScore, flip, currentMatch.Value.PointsToWin)
|
||||
new TeamScore(currentTeamScore, flip, currentMatch.Value.PointsToWin)
|
||||
{
|
||||
Colour = colour
|
||||
}
|
||||
@ -121,12 +121,12 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
}
|
||||
}
|
||||
|
||||
private class ScoreDisplay : CompositeDrawable
|
||||
private class TeamScore : CompositeDrawable
|
||||
{
|
||||
private readonly Bindable<int?> currentTeamScore = new Bindable<int?>();
|
||||
private readonly StarCounter counter;
|
||||
|
||||
public ScoreDisplay(Bindable<int?> score, bool flip, int count)
|
||||
public TeamScore(Bindable<int?> score, bool flip, int count)
|
||||
{
|
||||
var anchor = flip ? Anchor.CentreRight : Anchor.CentreLeft;
|
||||
|
@ -0,0 +1,144 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Gameplay.Components
|
||||
{
|
||||
public class MatchScoreDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly Color4 red = new Color4(186, 0, 18, 255);
|
||||
private readonly Color4 blue = new Color4(17, 136, 170, 255);
|
||||
|
||||
private const float bar_height = 20;
|
||||
|
||||
private readonly Bindable<MatchPairing> currentMatch = new Bindable<MatchPairing>();
|
||||
|
||||
private readonly BindableInt score1 = new BindableInt();
|
||||
private readonly BindableInt score2 = new BindableInt();
|
||||
|
||||
private readonly MatchScoreCounter score1Text;
|
||||
private readonly MatchScoreCounter score2Text;
|
||||
|
||||
private readonly Circle score1Bar;
|
||||
private readonly Circle score2Bar;
|
||||
|
||||
public MatchScoreDisplay()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
score1Bar = new Circle
|
||||
{
|
||||
Name = "top bar red",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = bar_height,
|
||||
Width = 0,
|
||||
Colour = red,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopRight
|
||||
},
|
||||
score1Text = new MatchScoreCounter
|
||||
{
|
||||
Colour = red,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
},
|
||||
score2Bar = new Circle
|
||||
{
|
||||
Name = "top bar blue",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = bar_height,
|
||||
Width = 0,
|
||||
Colour = blue,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopLeft
|
||||
},
|
||||
score2Text = new MatchScoreCounter
|
||||
{
|
||||
Colour = blue,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder, MatchIPCInfo ipc)
|
||||
{
|
||||
currentMatch.BindTo(ladder.CurrentMatch);
|
||||
|
||||
score1.BindValueChanged(_ => updateScores());
|
||||
score1.BindTo(ipc.Score1);
|
||||
|
||||
score2.BindValueChanged(_ => updateScores());
|
||||
score2.BindTo(ipc.Score2);
|
||||
}
|
||||
|
||||
private void updateScores()
|
||||
{
|
||||
score1Text.Current.Value = score1.Value;
|
||||
score2Text.Current.Value = score2.Value;
|
||||
|
||||
var winningText = score1.Value > score2.Value ? score1Text : score2Text;
|
||||
var losingText = score1.Value <= score2.Value ? score1Text : score2Text;
|
||||
|
||||
winningText.Winning = true;
|
||||
losingText.Winning = false;
|
||||
|
||||
var winningBar = score1.Value > score2.Value ? score1Bar : score2Bar;
|
||||
var losingBar = score1.Value <= score2.Value ? score1Bar : score2Bar;
|
||||
|
||||
var diff = Math.Max(score1.Value, score2.Value) - Math.Min(score1.Value, score2.Value);
|
||||
|
||||
losingBar.ResizeWidthTo(0, 400, Easing.OutQuint);
|
||||
winningBar.ResizeWidthTo((float)Math.Pow(diff / 1000000f, 0.5), 400, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
|
||||
score1Text.X = -Math.Max(score1Text.DrawWidth / 2, score1Bar.DrawWidth);
|
||||
score2Text.X = Math.Max(score2Text.DrawWidth / 2, score2Bar.DrawWidth);
|
||||
}
|
||||
|
||||
private class MatchScoreCounter : ScoreCounter
|
||||
{
|
||||
public MatchScoreCounter()
|
||||
{
|
||||
Margin = new MarginPadding { Top = bar_height + 5, Horizontal = 10 };
|
||||
Winning = false;
|
||||
|
||||
DisplayedCountSpriteText.FixedWidth = false;
|
||||
}
|
||||
|
||||
public bool Winning
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
DisplayedCountSpriteText.Font = "Aquatico-Regular";
|
||||
DisplayedCountSpriteText.TextSize = 60;
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayedCountSpriteText.Font = "Aquatico-Light";
|
||||
DisplayedCountSpriteText.TextSize = 40;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,12 +4,14 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Gameplay.Components;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
@ -23,23 +25,62 @@ namespace osu.Game.Tournament.Screens.Gameplay
|
||||
|
||||
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
|
||||
private TriangleButton warmupButton;
|
||||
private FileBasedIPC ipc;
|
||||
private MatchIPCInfo ipc;
|
||||
|
||||
private readonly Color4 red = new Color4(186, 0, 18, 255);
|
||||
private readonly Color4 blue = new Color4(17, 136, 170, 255);
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder, TextureStore textures, FileBasedIPC ipc)
|
||||
private void load(LadderInfo ladder, TextureStore textures, MatchIPCInfo ipc)
|
||||
{
|
||||
this.ipc = ipc;
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new MatchHeader(),
|
||||
new Box
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 718 / 1080f,
|
||||
Colour = new Color4(0, 255, 0, 255),
|
||||
Y = 14,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin= Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Circle
|
||||
{
|
||||
Name = "top bar red",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 10,
|
||||
Width = 0.5f,
|
||||
Colour = red,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Name = "top bar blue",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 10,
|
||||
Width = 0.5f,
|
||||
Colour = blue,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
},
|
||||
}
|
||||
},
|
||||
new Box
|
||||
{
|
||||
// chroma key area for stable gameplay
|
||||
Name = "chroma",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 480,
|
||||
Colour = new Color4(0, 255, 0, 255),
|
||||
},
|
||||
}
|
||||
},
|
||||
new ControlPanel
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Gameplay;
|
||||
using osu.Game.Tournament.Screens.Gameplay.Components;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
@ -92,7 +92,7 @@ namespace osu.Game.Tournament.Screens.MapPool
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LadderInfo ladder, FileBasedIPC ipc)
|
||||
private void load(LadderInfo ladder, MatchIPCInfo ipc)
|
||||
{
|
||||
currentMatch.BindValueChanged(matchChanged);
|
||||
currentMatch.BindTo(ladder.CurrentMatch);
|
||||
|
@ -72,7 +72,7 @@ namespace osu.Game.Tournament
|
||||
|
||||
dependencies.Cache(Ladder);
|
||||
|
||||
dependencies.Cache(ipc = new FileBasedIPC());
|
||||
dependencies.CacheAs<MatchIPCInfo>(ipc = new FileBasedIPC());
|
||||
Add(ipc);
|
||||
|
||||
bool addedInfo = false;
|
||||
|
Loading…
Reference in New Issue
Block a user