1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 03:02:54 +08:00

Implement the overlay

This commit is contained in:
normalid 2024-07-23 19:05:14 +08:00
parent 15220f3bf4
commit ad1a86ebdc
3 changed files with 191 additions and 9 deletions

View File

@ -0,0 +1,101 @@
// 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;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
namespace osu.Game.Skinning
{
public partial class LegacyKeyCounter : KeyCounter
{
public bool UsesFixedAnchor { get; set; }
public float TransitionDuration { get; set; } = 150f;
public Colour4 KeyTextColour { get; set; } = Colour4.White;
public Colour4 KeyDownBackgroundColour { get; set; } = Colour4.Yellow;
public Colour4 KeyUpBackgroundColour { get; set; } = Colour4.White;
private Container keyContainer = null!;
private SkinnableSprite overlayKey = null!;
private OsuSpriteText overlayKeyText = null!;
public LegacyKeyCounter(InputTrigger trigger)
: base(trigger)
{
Origin = Anchor.Centre;
Anchor = Anchor.Centre;
Child = keyContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
overlayKey = new SkinnableSprite
{
Blending = Multiplicative,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BypassAutoSizeAxes = Axes.Both,
SpriteName = { Value = "inputoverlay-key" },
Rotation = -90,
},
overlayKeyText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = trigger.Name,
Colour = KeyTextColour,
Font = OsuFont.Default.With(fixedWidth: true),
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Width = Math.Max(overlayKey.Width, 43 * 1.05f);
Height = Math.Max(overlayKey.Height, 43 * 1.05f);
}
protected override void Activate(bool forwardPlayback = true)
{
base.Activate(forwardPlayback);
keyContainer.ScaleTo(0.75f, TransitionDuration);
keyContainer.FadeColour(KeyDownBackgroundColour, TransitionDuration);
overlayKeyText.Text = CountPresses.Value.ToString();
}
protected override void Deactivate(bool forwardPlayback = true)
{
base.Deactivate(forwardPlayback);
keyContainer.ScaleTo(1f, TransitionDuration);
keyContainer.FadeColour(KeyUpBackgroundColour, TransitionDuration);
}
public static BlendingParameters Multiplicative
{
get
{
BlendingParameters result = default(BlendingParameters);
result.Source = BlendingType.SrcAlpha;
result.Destination = BlendingType.OneMinusSrcAlpha;
result.SourceAlpha = BlendingType.One;
result.DestinationAlpha = BlendingType.One;
result.RGBEquation = BlendingEquation.Add;
result.AlphaEquation = BlendingEquation.Add;
return result;
}
}
}
}

View File

@ -0,0 +1,79 @@
// 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 osuTK.Graphics;
using osu.Framework.Allocation;
namespace osu.Game.Skinning
{
public partial class LegacyKeyCounterDisplay : KeyCounterDisplay
{
private const float key_transition_time = 50;
protected override FillFlowContainer<KeyCounter> KeyFlow { get; } = null!;
private SkinnableSprite overlayBackground = null!;
public LegacyKeyCounterDisplay()
{
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
overlayBackground = new SkinnableSprite
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
//BypassAutoSizeAxes = Axes.Both,
SpriteName = { Value= "inputoverlay-background" },
},
KeyFlow = new FillFlowContainer<KeyCounter>
{
Padding = new MarginPadding
{
Horizontal = 7f * 1.05f,
},
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
},
});
}
[BackgroundDependencyLoader]
private void load(ISkinSource source)
{
source.GetConfig<string, Colour4>("InputOverlayText")?.BindValueChanged(v =>
{
KeyTextColor = v.NewValue;
}, true);
}
protected override KeyCounter CreateCounter(InputTrigger trigger) => new LegacyKeyCounter(trigger)
{
TransitionDuration = key_transition_time,
KeyTextColour = keyTextColor,
};
private Color4 keyTextColor = Color4.White;
public Color4 KeyTextColor
{
get => keyTextColor;
set
{
if (value != keyTextColor)
{
keyTextColor = value;
foreach (var child in KeyFlow.Cast<LegacyKeyCounter>())
child.KeyTextColour = value;
}
}
}
}
}

View File

@ -15,6 +15,7 @@ using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
using osu.Game.Extensions;
@ -381,22 +382,22 @@ namespace osu.Game.Skinning
}
var hitError = container.OfType<HitErrorMeter>().FirstOrDefault();
var keyCounter = container.OfType<DefaultKeyCounterDisplay>().FirstOrDefault();
if (hitError != null)
{
hitError.Anchor = Anchor.BottomCentre;
hitError.Origin = Anchor.CentreLeft;
hitError.Rotation = -90;
}
if (keyCounter != null)
{
const float padding = 10;
var keyCounter = container.OfType<LegacyKeyCounterDisplay>().FirstOrDefault();
keyCounter.Anchor = Anchor.BottomRight;
keyCounter.Origin = Anchor.BottomRight;
keyCounter.Position = new Vector2(-padding, -(padding + hitError.Width));
}
if (keyCounter != null)
{
keyCounter.Rotation = 90f;
keyCounter.Anchor = Anchor.CentreRight;
keyCounter.Origin = Anchor.TopCentre;
keyCounter.Position = new Vector2(0);
}
})
{
@ -408,7 +409,8 @@ namespace osu.Game.Skinning
new LegacySongProgress(),
new LegacyHealthDisplay(),
new BarHitErrorMeter(),
new DefaultKeyCounterDisplay()
//new DefaultKeyCounterDisplay(),
new LegacyKeyCounterDisplay(),
}
};
}