1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 01:17:27 +08:00
osu-lazer/osu.Game/Skinning/LegacyKeyCounterDisplay.cs

98 lines
3.2 KiB
C#
Raw Normal View History

2024-07-23 19:05:14 +08:00
// 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.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2024-07-24 12:39:36 +08:00
using osuTK;
2024-07-23 19:05:14 +08:00
namespace osu.Game.Skinning
{
public partial class LegacyKeyCounterDisplay : KeyCounterDisplay
{
2024-07-24 12:30:08 +08:00
private const float key_transition_time = 100;
2024-07-23 19:05:14 +08:00
protected override FillFlowContainer<KeyCounter> KeyFlow { get; } = null!;
private Sprite backgroundSprite = null!;
2024-07-23 19:05:14 +08:00
public LegacyKeyCounterDisplay()
{
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
backgroundSprite = new Sprite
2024-07-23 19:05:14 +08:00
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
KeyFlow = new FillFlowContainer<KeyCounter>
{
2024-07-23 19:45:53 +08:00
// https://osu.ppy.sh/wiki/en/Skinning/Interface#input-overlay
// 24px away from the container, there're 4 counter in legacy, so divide by 4
// "inputoverlay-background.png" are 1.05x in-game. so *1.05f to the X coordinate
2024-07-24 12:39:36 +08:00
X = (24 / 4) * 1f,
2024-07-23 19:05:14 +08:00
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
},
});
}
2024-07-23 23:35:25 +08:00
[Resolved]
private ISkinSource source { get; set; } = null!;
protected override void LoadComplete()
2024-07-23 19:05:14 +08:00
{
2024-07-23 23:35:25 +08:00
base.LoadComplete();
source.GetConfig<SkinConfiguration.LegacySetting, Colour4>(SkinConfiguration.LegacySetting.InputOverlayText)?.BindValueChanged(v =>
2024-07-23 19:05:14 +08:00
{
KeyTextColor = v.NewValue;
}, true);
Texture? backgroundTexture = source.GetTexture($"inputoverlay-background");
if (backgroundTexture != null)
backgroundSprite.Texture = backgroundTexture;
2024-07-23 19:05:14 +08:00
}
protected override KeyCounter CreateCounter(InputTrigger trigger) => new LegacyKeyCounter(trigger)
{
TransitionDuration = key_transition_time,
KeyTextColour = keyTextColor,
2024-07-23 19:56:43 +08:00
KeyTextRotation = -Rotation,
2024-07-23 19:05:14 +08:00
};
2024-07-23 19:56:43 +08:00
protected override void Update()
{
base.Update();
2024-07-23 23:35:25 +08:00
2024-07-23 19:56:43 +08:00
// keep the text are always horizontal
foreach (var child in KeyFlow.Cast<LegacyKeyCounter>())
child.KeyTextRotation = -Rotation;
}
2024-07-23 23:35:25 +08:00
private Colour4 keyTextColor = Colour4.White;
2024-07-23 19:05:14 +08:00
2024-07-23 23:35:25 +08:00
public Colour4 KeyTextColor
2024-07-23 19:05:14 +08:00
{
get => keyTextColor;
set
{
if (value != keyTextColor)
{
keyTextColor = value;
foreach (var child in KeyFlow.Cast<LegacyKeyCounter>())
child.KeyTextColour = value;
}
}
}
}
}