1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Move cross-component layout dependencies for legacy skin to LegacySkin

This commit is contained in:
Dean Herbert 2021-05-11 13:12:24 +09:00
parent 4c4d75e6f9
commit 117d6d731d
4 changed files with 54 additions and 22 deletions

View File

@ -32,16 +32,5 @@ namespace osu.Game.Skinning
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
};
protected override void Update()
{
base.Update();
if (hud?.ScoreCounter?.Drawable is LegacyScoreCounter score)
{
// for now align with the score counter. eventually this will be user customisable.
Y = Parent.ToLocalSpace(score.ScreenSpaceDrawQuad.BottomRight).Y;
}
}
}
}

View File

@ -327,11 +327,20 @@ namespace osu.Game.Skinning
switch (component)
{
case SkinnableTargetComponent target:
switch (target.Target)
{
case SkinnableTarget.MainHUDComponents:
return new SkinnableTargetWrapper
var skinnableTargetWrapper = new SkinnableTargetWrapper(container =>
{
var score = container.OfType<LegacyScoreCounter>().FirstOrDefault();
var accuracy = container.OfType<GameplayAccuracyCounter>().FirstOrDefault();
if (score != null && accuracy != null)
{
accuracy.Y = container.ToLocalSpace(score.ScreenSpaceDrawQuad.BottomRight).Y;
}
})
{
Children = new[]
{
@ -342,6 +351,8 @@ namespace osu.Game.Skinning
GetDrawableComponent(new HUDSkinComponent(HUDSkinComponents.HealthDisplay)) ?? new DefaultHealthDisplay(),
}
};
return skinnableTargetWrapper;
}
return null;

View File

@ -9,7 +9,6 @@ using Newtonsoft.Json;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
@ -120,12 +119,4 @@ namespace osu.Game.Skinning
#endregion
}
public class SkinnableTargetWrapper : Container, ISkinSerialisable
{
public SkinnableTargetWrapper()
{
RelativeSizeAxes = Axes.Both;
}
}
}

View File

@ -0,0 +1,41 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Skinning
{
/// <summary>
/// A container which is serialised and can encapsulate multiple skinnable elements into a single return type.
/// Will also optionally apply default cross-element layout dependencies when initialised from a non-deserialised source.
/// </summary>
public class SkinnableTargetWrapper : Container, ISkinSerialisable
{
private readonly Action<Container> applyDefaults;
/// <summary>
/// Construct a wrapper with defaults that should be applied once.
/// </summary>
/// <param name="applyDefaults">A function with default to apply after the initial layout (ie. consuming autosize)</param>
public SkinnableTargetWrapper(Action<Container> applyDefaults)
: this()
{
this.applyDefaults = applyDefaults;
}
public SkinnableTargetWrapper()
{
RelativeSizeAxes = Axes.Both;
}
protected override void LoadComplete()
{
base.LoadComplete();
// schedule is required to allow children to run their LoadComplete and take on their correct sizes.
Schedule(() => applyDefaults?.Invoke(this));
}
}
}