1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-29 02:12:57 +08:00

Abstractify ready button and add a timeshift implementation

This commit is contained in:
smoogipoo 2020-12-19 02:55:48 +09:00
parent e4a54dc6cd
commit 4e0113afbf
3 changed files with 46 additions and 20 deletions

View File

@ -13,26 +13,20 @@ using osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.Multi.Components
{
public class ReadyButton : TriangleButton
public abstract class ReadyButton : TriangleButton
{
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset> endDate { get; set; }
public new readonly BindableBool Enabled = new BindableBool();
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
protected IBindable<WorkingBeatmap> GameBeatmap { get; private set; }
[Resolved]
private BeatmapManager beatmaps { get; set; }
private bool hasBeatmap;
public ReadyButton()
{
Text = "Start";
}
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
@ -45,10 +39,6 @@ namespace osu.Game.Screens.Multi.Components
managerRemoved.BindValueChanged(beatmapRemoved);
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
BackgroundColour = colours.Green;
Triangles.ColourDark = colours.Green;
Triangles.ColourLight = colours.GreenLight;
}
private void updateSelectedItem(PlaylistItem item)
@ -94,15 +84,13 @@ namespace osu.Game.Screens.Multi.Components
private void updateEnabledState()
{
if (gameBeatmap.Value == null || SelectedItem.Value == null)
if (GameBeatmap.Value == null || SelectedItem.Value == null)
{
Enabled.Value = false;
base.Enabled.Value = false;
return;
}
bool hasEnoughTime = DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
Enabled.Value = hasBeatmap && hasEnoughTime;
base.Enabled.Value = hasBeatmap && Enabled.Value;
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Multi.Timeshift;
using osuTK;
namespace osu.Game.Screens.Multi.Match.Components
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Match.Components
InternalChildren = new[]
{
background = new Box { RelativeSizeAxes = Axes.Both },
new ReadyButton
new TimeshiftReadyButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -0,0 +1,38 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
namespace osu.Game.Screens.Multi.Timeshift
{
public class TimeshiftReadyButton : ReadyButton
{
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset?> endDate { get; set; }
public TimeshiftReadyButton()
{
Text = "Start";
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Green;
Triangles.ColourDark = colours.Green;
Triangles.ColourLight = colours.GreenLight;
}
protected override void Update()
{
base.Update();
Enabled.Value = endDate.Value == null || DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(GameBeatmap.Value.Track.Length) < endDate.Value;
}
}
}