mirror of
https://github.com/ppy/osu.git
synced 2025-01-29 12:22:54 +08:00
Merge pull request #14425 from frenzibyte/fix-screen-offsetting-on-scaling
Fix screen offsetting not handling scaled game content properly
This commit is contained in:
commit
c2c0ff3327
@ -1,8 +1,12 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Menus
|
||||
@ -21,21 +25,48 @@ namespace osu.Game.Tests.Visual.Menus
|
||||
[Test]
|
||||
public void TestScreenOffsettingOnSettingsOverlay()
|
||||
{
|
||||
AddStep("open settings", () => Game.Settings.Show());
|
||||
AddUntilStep("right screen offset applied", () => Game.ScreenOffsetContainer.X == SettingsPanel.WIDTH * TestOsuGame.SIDE_OVERLAY_OFFSET_RATIO);
|
||||
foreach (var scalingMode in Enum.GetValues(typeof(ScalingMode)).Cast<ScalingMode>())
|
||||
{
|
||||
AddStep($"set scaling mode to {scalingMode}", () =>
|
||||
{
|
||||
Game.LocalConfig.SetValue(OsuSetting.Scaling, scalingMode);
|
||||
|
||||
AddStep("hide settings", () => Game.Settings.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
if (scalingMode != ScalingMode.Off)
|
||||
{
|
||||
Game.LocalConfig.SetValue(OsuSetting.ScalingSizeX, 0.5f);
|
||||
Game.LocalConfig.SetValue(OsuSetting.ScalingSizeY, 0.5f);
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("open settings", () => Game.Settings.Show());
|
||||
AddUntilStep("right screen offset applied", () => Precision.AlmostEquals(Game.ScreenOffsetContainer.X, SettingsPanel.WIDTH * TestOsuGame.SIDE_OVERLAY_OFFSET_RATIO));
|
||||
|
||||
AddStep("hide settings", () => Game.Settings.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScreenOffsettingOnNotificationOverlay()
|
||||
{
|
||||
AddStep("open notifications", () => Game.Notifications.Show());
|
||||
AddUntilStep("right screen offset applied", () => Game.ScreenOffsetContainer.X == -NotificationOverlay.WIDTH * TestOsuGame.SIDE_OVERLAY_OFFSET_RATIO);
|
||||
foreach (var scalingMode in Enum.GetValues(typeof(ScalingMode)).Cast<ScalingMode>())
|
||||
{
|
||||
if (scalingMode != ScalingMode.Off)
|
||||
{
|
||||
AddStep($"set scaling mode to {scalingMode}", () =>
|
||||
{
|
||||
Game.LocalConfig.SetValue(OsuSetting.Scaling, scalingMode);
|
||||
Game.LocalConfig.SetValue(OsuSetting.ScalingSizeX, 0.5f);
|
||||
Game.LocalConfig.SetValue(OsuSetting.ScalingSizeY, 0.5f);
|
||||
});
|
||||
}
|
||||
|
||||
AddStep("hide notifications", () => Game.Notifications.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
AddStep("open notifications", () => Game.Notifications.Show());
|
||||
AddUntilStep("right screen offset applied", () => Precision.AlmostEquals(Game.ScreenOffsetContainer.X, -NotificationOverlay.WIDTH * TestOsuGame.SIDE_OVERLAY_OFFSET_RATIO));
|
||||
|
||||
AddStep("hide notifications", () => Game.Notifications.Hide());
|
||||
AddUntilStep("screen offset removed", () => Game.ScreenOffsetContainer.X == 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1018,10 +1018,13 @@ namespace osu.Game
|
||||
|
||||
var horizontalOffset = 0f;
|
||||
|
||||
// Content.ToLocalSpace() is used instead of this.ToLocalSpace() to correctly calculate the offset with scaling modes active.
|
||||
// Content is a child of a scaling container with ScalingMode.Everything set, while the game itself is never scaled.
|
||||
// this avoids a visible jump in the positioning of the screen offset container.
|
||||
if (Settings.IsLoaded && Settings.IsPresent)
|
||||
horizontalOffset += ToLocalSpace(Settings.ScreenSpaceDrawQuad.TopRight).X * SIDE_OVERLAY_OFFSET_RATIO;
|
||||
horizontalOffset += Content.ToLocalSpace(Settings.ScreenSpaceDrawQuad.TopRight).X * SIDE_OVERLAY_OFFSET_RATIO;
|
||||
if (Notifications.IsLoaded && Notifications.IsPresent)
|
||||
horizontalOffset += (ToLocalSpace(Notifications.ScreenSpaceDrawQuad.TopLeft).X - DrawWidth) * SIDE_OVERLAY_OFFSET_RATIO;
|
||||
horizontalOffset += (Content.ToLocalSpace(Notifications.ScreenSpaceDrawQuad.TopLeft).X - Content.DrawWidth) * SIDE_OVERLAY_OFFSET_RATIO;
|
||||
|
||||
ScreenOffsetContainer.X = horizontalOffset;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user