Merge branch 'skin-serialisation' into remove-skinnable-hud-classes

This commit is contained in:
Dean Herbert
2021-05-13 19:05:08 +09:00
68 changed files with 1910 additions and 409 deletions

View File

@ -1,6 +1,7 @@
// 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.Framework.Graphics;
@ -12,7 +13,7 @@ namespace osu.Game.Screens.Play
/// <summary>
/// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> via DI for gameplay components to use.
/// </summary>
public abstract class GameplayClockContainer : Container
public abstract class GameplayClockContainer : Container, IAdjustableClock
{
/// <summary>
/// The final clock which is exposed to gameplay components.
@ -157,5 +158,33 @@ namespace osu.Game.Screens.Play
/// <param name="source">The <see cref="IFrameBasedClock"/> providing the source time.</param>
/// <returns>The final <see cref="GameplayClock"/>.</returns>
protected abstract GameplayClock CreateGameplayClock(IFrameBasedClock source);
#region IAdjustableClock
bool IAdjustableClock.Seek(double position)
{
Seek(position);
return true;
}
void IAdjustableClock.Reset() => Reset();
public void ResetSpeedAdjustments()
{
}
double IAdjustableClock.Rate
{
get => GameplayClock.Rate;
set => throw new NotSupportedException();
}
double IClock.Rate => GameplayClock.Rate;
public double CurrentTime => GameplayClock.CurrentTime;
public bool IsRunning => GameplayClock.IsRunning;
#endregion
}
}

View File

@ -7,7 +7,7 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{
public class DefaultAccuracyCounter : GameplayAccuracyCounter, ISkinnableComponent
public class DefaultAccuracyCounter : GameplayAccuracyCounter, ISkinnableDrawable
{
[Resolved(canBeNull: true)]
private HUDOverlay hud { get; set; }

View File

@ -12,7 +12,7 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{
public class DefaultComboCounter : RollingCounter<int>, ISkinnableComponent
public class DefaultComboCounter : RollingCounter<int>, ISkinnableDrawable
{
[Resolved(canBeNull: true)]
private HUDOverlay hud { get; set; }

View File

@ -17,7 +17,7 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{
public class DefaultHealthDisplay : HealthDisplay, IHasAccentColour, ISkinnableComponent
public class DefaultHealthDisplay : HealthDisplay, IHasAccentColour, ISkinnableDrawable
{
/// <summary>
/// The base opacity of the glow.

View File

@ -8,7 +8,7 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Play.HUD
{
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableComponent
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableDrawable
{
public DefaultScoreCounter()
: base(6)

View File

@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// Uses the 'x' symbol and has a pop-out effect while rolling over.
/// </summary>
public class LegacyComboCounter : CompositeDrawable, ISkinnableComponent
public class LegacyComboCounter : CompositeDrawable, ISkinnableDrawable
{
public Bindable<int> Current { get; } = new BindableInt { MinValue = 0, };

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Extensions;
@ -14,7 +15,7 @@ using osuTK;
namespace osu.Game.Screens.Play.HUD
{
/// <summary>
/// Serialised information governing custom changes to an <see cref="ISkinSerialisable"/>.
/// Serialised information governing custom changes to an <see cref="ISkinnableDrawable"/>.
/// </summary>
[Serializable]
public class SkinnableInfo : IJsonSerializable
@ -33,10 +34,15 @@ namespace osu.Game.Screens.Play.HUD
public List<SkinnableInfo> Children { get; } = new List<SkinnableInfo>();
[JsonConstructor]
public SkinnableInfo()
{
}
/// <summary>
/// Construct a new instance populating all attributes from the provided drawable.
/// </summary>
/// <param name="component">The drawable which attributes should be sourced from.</param>
public SkinnableInfo(Drawable component)
{
Type = component.GetType();
@ -47,17 +53,21 @@ namespace osu.Game.Screens.Play.HUD
Anchor = component.Anchor;
Origin = component.Origin;
if (component is Container container)
if (component is Container<Drawable> container)
{
foreach (var child in container.Children.OfType<ISkinSerialisable>().OfType<Drawable>())
Children.Add(child.CreateSerialisedInformation());
foreach (var child in container.OfType<ISkinnableDrawable>().OfType<Drawable>())
Children.Add(child.CreateSkinnableInfo());
}
}
/// <summary>
/// Construct an instance of the drawable with all attributes applied.
/// </summary>
/// <returns>The new instance.</returns>
public Drawable CreateInstance()
{
Drawable d = (Drawable)Activator.CreateInstance(Type);
d.ApplySerialisedInformation(this);
d.ApplySkinnableInfo(this);
return d;
}
}

View File

@ -68,7 +68,7 @@ namespace osu.Game.Screens.Play
private bool holdingForHUD;
private readonly SkinnableElementTargetContainer mainComponents;
private readonly SkinnableTargetContainer mainComponents;
private IEnumerable<Drawable> hideTargets => new Drawable[] { visibilityContainer, KeyCounter, topRightElements };
@ -97,7 +97,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
mainComponents = new SkinnableElementTargetContainer(SkinnableTarget.MainHUDComponents)
mainComponents = new SkinnableTargetContainer(SkinnableTarget.MainHUDComponents)
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -12,7 +12,12 @@ namespace osu.Game.Screens.Play
public readonly ScoreInfo Score;
public SpectatorPlayerLoader(Score score)
: base(() => new SpectatorPlayer(score))
: this(score, () => new SpectatorPlayer(score))
{
}
public SpectatorPlayerLoader(Score score, Func<Player> createPlayer)
: base(createPlayer)
{
if (score.Replay == null)
throw new ArgumentException($"{nameof(score)} must have a non-null {nameof(score.Replay)}.", nameof(score));