1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 06:23:20 +08:00

Merge branch 'fix_text_orientation' into fix_progress_bar_info

This commit is contained in:
HiddenNode 2022-08-02 19:00:43 +01:00
commit dbb77705da
3 changed files with 97 additions and 19 deletions

View File

@ -8,6 +8,7 @@ using osu.Game.Configuration;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
using System;
namespace osu.Game.Extensions namespace osu.Game.Extensions
{ {
@ -79,5 +80,46 @@ namespace osu.Game.Extensions
container.Add(child.CreateInstance()); container.Add(child.CreateInstance());
} }
} }
/// <summary>
/// Keeps the drawable upright and prevents it from being scaled or flipped with its Parent.
/// </summary>
/// <param name="drawable">The drawable.</param>
public static void KeepUprightAndUnstretched(this Drawable drawable)
{
// Fix the rotation
var result = drawable.Parent.DrawInfo;
var scale = result.Matrix.ExtractScale();
var rotation = new Matrix3(
result.Matrix.Row0 / scale.X,
result.Matrix.Row1 / scale.Y,
new Vector3(0.0f, 0.0f, 1.0f)
);
rotation.Invert();
float angle = MathF.Atan(rotation.M12 / rotation.M11);
angle *= (360 / (2 * MathF.PI));
drawable.Rotation = angle;
// Fix the scale (includes flip)
var containerOriginToSpaceOrigin = new Matrix3(
new Vector3(1.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f),
new Vector3(drawable.DrawSize.X / 2, drawable.DrawSize.Y / 2, 1.0f)
);
var containerOriginToSpaceOriginInverse = containerOriginToSpaceOrigin;
containerOriginToSpaceOriginInverse.Invert();
Matrix3 rotatedBack = (containerOriginToSpaceOriginInverse * (rotation * (containerOriginToSpaceOrigin * result.Matrix)));
bool xFliped = rotation.M11 < 0;
bool yFliped = rotation.M22 < 0;
var rotatedBackScale = rotatedBack.ExtractScale();
drawable.Scale = new Vector2(
(xFliped ? -1 : 1) / rotatedBackScale.X,
(yFliped ? -1 : 1) / rotatedBackScale.Y
);
}
} }
} }

View File

@ -16,7 +16,6 @@ namespace osu.Game.Screens.Play.HUD
{ {
public class DefaultSongProgress : SongProgress public class DefaultSongProgress : SongProgress
{ {
private const float info_height = 20;
private const float bottom_bar_height = 5; private const float bottom_bar_height = 5;
private const float graph_height = SquareGraph.Column.WIDTH * 6; private const float graph_height = SquareGraph.Column.WIDTH * 6;
private const float handle_height = 18; private const float handle_height = 18;
@ -67,7 +66,6 @@ namespace osu.Game.Screens.Play.HUD
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = info_height,
}, },
graph = new SongProgressGraph graph = new SongProgressGraph
{ {
@ -180,7 +178,7 @@ namespace osu.Game.Screens.Play.HUD
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
Height = bottom_bar_height + graph_height + handle_size.Y + info_height - graph.Y; Height = bottom_bar_height + graph_height + handle_size.Y + info.Height - graph.Y;
} }
private void updateBarVisibility() private void updateBarVisibility()

View File

@ -46,40 +46,70 @@ namespace osu.Game.Screens.Play.HUD
if (clock != null) if (clock != null)
gameplayClock = clock; gameplayClock = clock;
AutoSizeAxes = Axes.Y;
Children = new Drawable[] Children = new Drawable[]
{ {
timeCurrent = new OsuSpriteText new Container
{ {
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Colour = colours.BlueLighter, Origin = Anchor.BottomLeft,
Font = OsuFont.Numeric, AutoSizeAxes = Axes.Both,
Margin = new MarginPadding Children = new Drawable[]
{ {
Left = margin, timeCurrent = new OsuSpriteText
}, {
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = colours.BlueLighter,
Font = OsuFont.Numeric,
}
}
}, },
progress = new OsuSpriteText new Container
{ {
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Colour = colours.BlueLighter, AutoSizeAxes = Axes.Both,
Font = OsuFont.Numeric, Children = new Drawable[]
{
progress = new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = colours.BlueLighter,
Font = OsuFont.Numeric,
}
}
}, },
timeLeft = new OsuSpriteText new Container
{ {
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Colour = colours.BlueLighter, AutoSizeAxes = Axes.Both,
Font = OsuFont.Numeric, Children = new Drawable[]
Margin = new MarginPadding
{ {
Right = margin, timeLeft = new OsuSpriteText
}, {
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Colour = colours.BlueLighter,
Font = OsuFont.Numeric,
Margin = new MarginPadding
{
Right = margin,
},
}
}
} }
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
keepTextSpritesUpright();
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -106,5 +136,13 @@ namespace osu.Game.Screens.Play.HUD
} }
private string formatTime(TimeSpan timeSpan) => $"{(timeSpan < TimeSpan.Zero ? "-" : "")}{Math.Floor(timeSpan.Duration().TotalMinutes)}:{timeSpan.Duration().Seconds:D2}"; private string formatTime(TimeSpan timeSpan) => $"{(timeSpan < TimeSpan.Zero ? "-" : "")}{Math.Floor(timeSpan.Duration().TotalMinutes)}:{timeSpan.Duration().Seconds:D2}";
private void keepTextSpritesUpright()
{
timeCurrent.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
progress.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
timeLeft.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
}
} }
} }