mirror of
https://github.com/ppy/osu.git
synced 2025-02-06 12:03:21 +08:00
Abstractify ready button and add a timeshift implementation
This commit is contained in:
parent
e4a54dc6cd
commit
4e0113afbf
@ -13,26 +13,20 @@ using osu.Game.Online.Multiplayer;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Components
|
namespace osu.Game.Screens.Multi.Components
|
||||||
{
|
{
|
||||||
public class ReadyButton : TriangleButton
|
public abstract class ReadyButton : TriangleButton
|
||||||
{
|
{
|
||||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||||
|
|
||||||
[Resolved(typeof(Room), nameof(Room.EndDate))]
|
public new readonly BindableBool Enabled = new BindableBool();
|
||||||
private Bindable<DateTimeOffset> endDate { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
|
protected IBindable<WorkingBeatmap> GameBeatmap { get; private set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
private bool hasBeatmap;
|
private bool hasBeatmap;
|
||||||
|
|
||||||
public ReadyButton()
|
|
||||||
{
|
|
||||||
Text = "Start";
|
|
||||||
}
|
|
||||||
|
|
||||||
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
||||||
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
||||||
|
|
||||||
@ -45,10 +39,6 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
managerRemoved.BindValueChanged(beatmapRemoved);
|
managerRemoved.BindValueChanged(beatmapRemoved);
|
||||||
|
|
||||||
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
||||||
|
|
||||||
BackgroundColour = colours.Green;
|
|
||||||
Triangles.ColourDark = colours.Green;
|
|
||||||
Triangles.ColourLight = colours.GreenLight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectedItem(PlaylistItem item)
|
private void updateSelectedItem(PlaylistItem item)
|
||||||
@ -94,15 +84,13 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
|
|
||||||
private void updateEnabledState()
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasEnoughTime = DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
|
base.Enabled.Value = hasBeatmap && Enabled.Value;
|
||||||
|
|
||||||
Enabled.Value = hasBeatmap && hasEnoughTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Screens.Multi.Components;
|
using osu.Game.Screens.Multi.Timeshift;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Match.Components
|
namespace osu.Game.Screens.Multi.Match.Components
|
||||||
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
InternalChildren = new[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
background = new Box { RelativeSizeAxes = Axes.Both },
|
background = new Box { RelativeSizeAxes = Axes.Both },
|
||||||
new ReadyButton
|
new TimeshiftReadyButton
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
38
osu.Game/Screens/Multi/Timeshift/TimeshiftReadyButton.cs
Normal file
38
osu.Game/Screens/Multi/Timeshift/TimeshiftReadyButton.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user