mirror of
https://github.com/osukey/osukey.git
synced 2025-05-26 07:57:32 +09:00
Refactor drawable hierarchy to center properly
* Use FillFlowContainer.Spacing instead of manually applying margins. * Use Update() for calculating button padding to preserve it after mod button expansion and adjust FooterButtonRandom to use this method while avoiding flickering. * Expose mod display margin to clear it in the footer button.
This commit is contained in:
parent
ddec59ec91
commit
c9dda78ded
@ -41,7 +41,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly FillFlowContainer<ModIcon> iconsContainer;
|
protected readonly FillFlowContainer<ModIcon> IconsContainer;
|
||||||
private readonly OsuSpriteText unrankedText;
|
private readonly OsuSpriteText unrankedText;
|
||||||
|
|
||||||
public ModDisplay()
|
public ModDisplay()
|
||||||
@ -50,7 +50,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
iconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
|
IconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
@ -69,11 +69,11 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
Current.ValueChanged += mods =>
|
Current.ValueChanged += mods =>
|
||||||
{
|
{
|
||||||
iconsContainer.Clear();
|
IconsContainer.Clear();
|
||||||
|
|
||||||
foreach (Mod mod in mods.NewValue)
|
foreach (Mod mod in mods.NewValue)
|
||||||
{
|
{
|
||||||
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
|
IconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsLoaded)
|
if (IsLoaded)
|
||||||
@ -92,7 +92,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
appearTransform();
|
appearTransform();
|
||||||
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
|
IconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appearTransform()
|
private void appearTransform()
|
||||||
@ -104,17 +104,17 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
expand();
|
expand();
|
||||||
|
|
||||||
using (iconsContainer.BeginDelayedSequence(1200))
|
using (IconsContainer.BeginDelayedSequence(1200))
|
||||||
contract();
|
contract();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expand()
|
private void expand()
|
||||||
{
|
{
|
||||||
if (AllowExpand)
|
if (AllowExpand)
|
||||||
iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
|
IconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void contract() => iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
private void contract() => IconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
|
@ -92,15 +92,17 @@ namespace osu.Game.Screens.Select
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
Shear = -SHEAR,
|
Shear = -SHEAR,
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.X,
|
||||||
Margin = new MarginPadding { Horizontal = SHEAR_WIDTH / 4 },
|
Height = 50,
|
||||||
|
Margin = new MarginPadding { Right = -SHEAR_WIDTH / 2 },
|
||||||
|
Spacing = new Vector2(15, 0),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
TextContainer = new Container
|
TextContainer = new Container
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(100 - SHEAR_WIDTH, 50),
|
AutoSizeAxes = Axes.Both,
|
||||||
Child = SpriteText = new OsuSpriteText
|
Child = SpriteText = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -118,6 +120,19 @@ namespace osu.Game.Screens.Select
|
|||||||
public Action HoverLost;
|
public Action HoverLost;
|
||||||
public Key? Hotkey;
|
public Key? Hotkey;
|
||||||
|
|
||||||
|
protected override void UpdateAfterChildren()
|
||||||
|
{
|
||||||
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
|
float horizontalMargin = (100 - TextContainer.Width) / 2;
|
||||||
|
ButtonContentContainer.Padding = new MarginPadding
|
||||||
|
{
|
||||||
|
Left = horizontalMargin,
|
||||||
|
// right side margin offset to compensate for shear
|
||||||
|
Right = horizontalMargin - SHEAR_WIDTH / 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
Hovered?.Invoke();
|
Hovered?.Invoke();
|
||||||
|
@ -46,7 +46,6 @@ namespace osu.Game.Screens.Select
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
||||||
Margin = new MarginPadding { Right = 10 }
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +93,7 @@ namespace osu.Game.Screens.Select
|
|||||||
public FooterModDisplay()
|
public FooterModDisplay()
|
||||||
{
|
{
|
||||||
AllowExpand = false;
|
AllowExpand = false;
|
||||||
|
IconsContainer.Margin = new MarginPadding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,11 @@ namespace osu.Game.Screens.Select
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Text = @"rewind",
|
Text = @"rewind",
|
||||||
Alpha = 0
|
Alpha = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// force both text sprites to always be present to avoid width flickering while they're being swapped out
|
||||||
|
SpriteText.AlwaysPresent = secondaryText.AlwaysPresent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user