mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Merge branch 'add-offset-adjust-tooltip-text' into combine-time-slider-implementation
This commit is contained in:
@ -5,6 +5,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Screens;
|
||||
@ -38,24 +39,24 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
private BackgroundScreenStack backgroundStack;
|
||||
|
||||
private bool allowScaling = true;
|
||||
private RectangleF? customRect;
|
||||
private bool customRectIsRelativePosition;
|
||||
|
||||
/// <summary>
|
||||
/// Whether user scaling preferences should be applied. Enabled by default.
|
||||
/// Set a custom position and scale which overrides any user specification.
|
||||
/// </summary>
|
||||
public bool AllowScaling
|
||||
/// <param name="rect">A rectangle with positional and sizing information for this container to conform to. <c>null</c> will clear the custom rect and revert to user settings.</param>
|
||||
/// <param name="relativePosition">Whether the position portion of the provided rect is in relative coordinate space or not.</param>
|
||||
public void SetCustomRect(RectangleF? rect, bool relativePosition = false)
|
||||
{
|
||||
get => allowScaling;
|
||||
set
|
||||
{
|
||||
if (value == allowScaling)
|
||||
return;
|
||||
customRect = rect;
|
||||
customRectIsRelativePosition = relativePosition;
|
||||
|
||||
allowScaling = value;
|
||||
if (IsLoaded) Scheduler.AddOnce(updateSize);
|
||||
}
|
||||
if (IsLoaded) Scheduler.AddOnce(updateSize);
|
||||
}
|
||||
|
||||
private const float corner_radius = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance.
|
||||
/// </summary>
|
||||
@ -69,7 +70,7 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
CornerRadius = 10,
|
||||
CornerRadius = corner_radius,
|
||||
Child = content = new ScalingDrawSizePreservingFillContainer(targetMode != ScalingMode.Gameplay)
|
||||
};
|
||||
}
|
||||
@ -137,7 +138,7 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
private void updateSize()
|
||||
{
|
||||
const float fade_time = 500;
|
||||
const float duration = 500;
|
||||
|
||||
if (targetMode == ScalingMode.Everything)
|
||||
{
|
||||
@ -156,17 +157,31 @@ namespace osu.Game.Graphics.Containers
|
||||
backgroundStack.Push(new ScalingBackgroundScreen());
|
||||
}
|
||||
|
||||
backgroundStack.FadeIn(fade_time);
|
||||
backgroundStack.FadeIn(duration);
|
||||
}
|
||||
else
|
||||
backgroundStack?.FadeOut(fade_time);
|
||||
backgroundStack?.FadeOut(duration);
|
||||
}
|
||||
|
||||
bool scaling = AllowScaling && (targetMode == null || scalingMode.Value == targetMode);
|
||||
RectangleF targetRect = new RectangleF(Vector2.Zero, Vector2.One);
|
||||
|
||||
var targetSize = scaling ? new Vector2(sizeX.Value, sizeY.Value) : Vector2.One;
|
||||
var targetPosition = scaling ? new Vector2(posX.Value, posY.Value) * (Vector2.One - targetSize) : Vector2.Zero;
|
||||
bool requiresMasking = (scaling && targetSize != Vector2.One)
|
||||
if (customRect != null)
|
||||
{
|
||||
sizableContainer.RelativePositionAxes = customRectIsRelativePosition ? Axes.Both : Axes.None;
|
||||
|
||||
targetRect = customRect.Value;
|
||||
}
|
||||
else if (targetMode == null || scalingMode.Value == targetMode)
|
||||
{
|
||||
sizableContainer.RelativePositionAxes = Axes.Both;
|
||||
|
||||
Vector2 scale = new Vector2(sizeX.Value, sizeY.Value);
|
||||
Vector2 pos = new Vector2(posX.Value, posY.Value) * (Vector2.One - scale);
|
||||
|
||||
targetRect = new RectangleF(pos, scale);
|
||||
}
|
||||
|
||||
bool requiresMasking = targetRect.Size != Vector2.One
|
||||
// For the top level scaling container, for now we apply masking if safe areas are in use.
|
||||
// In the future this can likely be removed as more of the actual UI supports overflowing into the safe areas.
|
||||
|| (targetMode == ScalingMode.Everything && safeAreaPadding.Value.Total != Vector2.Zero);
|
||||
@ -174,8 +189,14 @@ namespace osu.Game.Graphics.Containers
|
||||
if (requiresMasking)
|
||||
sizableContainer.Masking = true;
|
||||
|
||||
sizableContainer.MoveTo(targetPosition, 500, Easing.OutQuart);
|
||||
sizableContainer.ResizeTo(targetSize, 500, Easing.OutQuart).OnComplete(_ => { sizableContainer.Masking = requiresMasking; });
|
||||
sizableContainer.MoveTo(targetRect.Location, duration, Easing.OutQuart);
|
||||
sizableContainer.ResizeTo(targetRect.Size, duration, Easing.OutQuart);
|
||||
|
||||
// Of note, this will not work great in the case of nested ScalingContainers where multiple are applying corner radius.
|
||||
// Masking and corner radius should likely only be applied at one point in the full game stack to fix this.
|
||||
// An example of how this can occur is when the skin editor is visible and the game screen scaling is set to "Everything".
|
||||
sizableContainer.TransformTo(nameof(CornerRadius), requiresMasking ? corner_radius : 0, duration, requiresMasking ? Easing.OutQuart : Easing.None)
|
||||
.OnComplete(_ => { sizableContainer.Masking = requiresMasking; });
|
||||
}
|
||||
|
||||
private class ScalingBackgroundScreen : BackgroundScreenDefault
|
||||
|
@ -140,6 +140,7 @@ namespace osu.Game.Graphics.Cursor
|
||||
// Scale to [-0.75, 0.75] so that the sample isn't fully panned left or right (sounds weird)
|
||||
channel.Balance.Value = ((activeCursor.X / DrawWidth) * 2 - 1) * 0.75;
|
||||
channel.Frequency.Value = baseFrequency - (random_range / 2f) + RNG.NextDouble(random_range);
|
||||
channel.Volume.Value = baseFrequency;
|
||||
|
||||
channel.Play();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private readonly Box rightBox;
|
||||
private readonly Container nubContainer;
|
||||
|
||||
public LocalisableString TooltipText { get; private set; }
|
||||
public virtual LocalisableString TooltipText { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to format the tooltip as a percentage or the actual value.
|
||||
@ -148,7 +148,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
CurrentNumber.BindValueChanged(current => TooltipText = GetTooltipText(current.NewValue), true);
|
||||
CurrentNumber.BindValueChanged(current => TooltipText = getTooltipText(current.NewValue), true);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
@ -178,7 +178,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
base.OnUserChange(value);
|
||||
playSample(value);
|
||||
TooltipText = GetTooltipText(value);
|
||||
TooltipText = getTooltipText(value);
|
||||
}
|
||||
|
||||
private void playSample(T value)
|
||||
@ -203,7 +203,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
channel.Play();
|
||||
}
|
||||
|
||||
protected virtual LocalisableString GetTooltipText(T value)
|
||||
private LocalisableString getTooltipText(T value)
|
||||
{
|
||||
if (CurrentNumber.IsInteger)
|
||||
return value.ToInt32(NumberFormatInfo.InvariantInfo).ToString("N0");
|
||||
|
@ -10,6 +10,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public class TimeSlider : OsuSliderBar<double>
|
||||
{
|
||||
protected override LocalisableString GetTooltipText(double value) => $"{value:N0} ms";
|
||||
public override LocalisableString TooltipText => $"{Current.Value:N0} ms";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user