mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 04:53:52 +08:00
Apply nullability to SkinnableDrawable
This commit is contained in:
parent
bf26dbffc2
commit
d4251271d8
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Caching;
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -19,7 +17,7 @@ namespace osu.Game.Skinning
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The displayed component.
|
/// The displayed component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Drawable Drawable { get; private set; }
|
public Drawable Drawable { get; private set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the drawable component should be centered in available space.
|
/// Whether the drawable component should be centered in available space.
|
||||||
@ -43,7 +41,7 @@ namespace osu.Game.Skinning
|
|||||||
/// <param name="component">The namespace-complete resource name for this skinnable element.</param>
|
/// <param name="component">The namespace-complete resource name for this skinnable element.</param>
|
||||||
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
||||||
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
|
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
|
||||||
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable>? defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
|
||||||
: this(component, confineMode)
|
: this(component, confineMode)
|
||||||
{
|
{
|
||||||
createDefault = defaultImplementation;
|
createDefault = defaultImplementation;
|
||||||
@ -62,7 +60,7 @@ namespace osu.Game.Skinning
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ResetAnimation() => (Drawable as IFramedAnimation)?.GotoFrame(0);
|
public void ResetAnimation() => (Drawable as IFramedAnimation)?.GotoFrame(0);
|
||||||
|
|
||||||
private readonly Func<ISkinComponent, Drawable> createDefault;
|
private readonly Func<ISkinComponent, Drawable>? createDefault;
|
||||||
|
|
||||||
private readonly Cached scaling = new Cached();
|
private readonly Cached scaling = new Cached();
|
||||||
|
|
||||||
@ -77,18 +75,19 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
protected override void SkinChanged(ISkinSource skin)
|
protected override void SkinChanged(ISkinSource skin)
|
||||||
{
|
{
|
||||||
Drawable = skin.GetDrawableComponent(Component);
|
var retrieved = skin.GetDrawableComponent(Component);
|
||||||
|
|
||||||
isDefault = false;
|
if (retrieved == null)
|
||||||
|
|
||||||
if (Drawable == null)
|
|
||||||
{
|
{
|
||||||
Drawable = CreateDefault(Component);
|
Drawable = CreateDefault(Component);
|
||||||
isDefault = true;
|
isDefault = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (Drawable != null)
|
|
||||||
{
|
{
|
||||||
|
Drawable = retrieved;
|
||||||
|
isDefault = false;
|
||||||
|
}
|
||||||
|
|
||||||
scaling.Invalidate();
|
scaling.Invalidate();
|
||||||
|
|
||||||
if (CentreComponent)
|
if (CentreComponent)
|
||||||
@ -99,9 +98,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
InternalChild = Drawable;
|
InternalChild = Drawable;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
ClearInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
@ -111,7 +107,7 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Drawable == null || (isDefault && !ApplySizeRestrictionsToDefault)) return;
|
if (isDefault && !ApplySizeRestrictionsToDefault) return;
|
||||||
|
|
||||||
switch (confineMode)
|
switch (confineMode)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user