2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-09-21 05:43:17 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-26 04:31:49 +00:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-09-21 05:43:17 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
|
{
|
2019-03-26 04:31:49 +00:00
|
|
|
|
public partial class OsuPlayfieldAdjustmentContainer : PlayfieldAdjustmentContainer
|
2018-09-21 05:43:17 +00:00
|
|
|
|
{
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
2020-08-04 13:43:33 +00:00
|
|
|
|
private readonly ScalingContainer content;
|
2018-09-21 05:43:17 +00:00
|
|
|
|
|
2019-08-07 09:29:50 +00:00
|
|
|
|
private const float playfield_size_adjust = 0.8f;
|
|
|
|
|
|
2020-08-03 12:18:45 +00:00
|
|
|
|
/// <summary>
|
2020-08-04 13:43:33 +00:00
|
|
|
|
/// When true, an offset is applied to allow alignment with historical storyboards displayed in the same parent space.
|
|
|
|
|
/// This will shift the playfield downwards slightly.
|
2020-08-03 12:18:45 +00:00
|
|
|
|
/// </summary>
|
2020-08-04 13:43:33 +00:00
|
|
|
|
public bool AlignWithStoryboard
|
2020-08-03 12:18:45 +00:00
|
|
|
|
{
|
2020-08-04 13:43:33 +00:00
|
|
|
|
set => content.PlayfieldShift = value;
|
2020-08-03 12:18:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 04:31:49 +00:00
|
|
|
|
public OsuPlayfieldAdjustmentContainer()
|
2018-09-21 05:43:17 +00:00
|
|
|
|
{
|
2019-03-26 04:31:49 +00:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
2019-07-29 09:43:05 +00:00
|
|
|
|
// Calculated from osu!stable as 512 (default gamefield size) / 640 (default window size)
|
2019-08-07 09:29:50 +00:00
|
|
|
|
Size = new Vector2(playfield_size_adjust);
|
2019-03-26 04:31:49 +00:00
|
|
|
|
|
2018-09-21 05:43:17 +00:00
|
|
|
|
InternalChild = new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
FillAspectRatio = 4f / 3,
|
2018-09-21 06:01:58 +00:00
|
|
|
|
Child = content = new ScalingContainer { RelativeSizeAxes = Axes.Both }
|
2018-09-21 05:43:17 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="Container"/> which scales its content relative to a target width.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private partial class ScalingContainer : Container
|
|
|
|
|
{
|
2020-08-03 12:18:45 +00:00
|
|
|
|
internal bool PlayfieldShift { get; set; }
|
|
|
|
|
|
2018-09-21 05:43:17 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-08-07 09:29:50 +00:00
|
|
|
|
// The following calculation results in a constant of 1.6 when OsuPlayfieldAdjustmentContainer
|
|
|
|
|
// is consuming the full game_size. This matches the osu-stable "magic ratio".
|
|
|
|
|
//
|
|
|
|
|
// game_size = DrawSizePreservingFillContainer.TargetSize = new Vector2(1024, 768)
|
|
|
|
|
//
|
|
|
|
|
// Parent is a 4:3 aspect enforced, using height as the constricting dimension
|
2023-10-17 08:40:44 +00:00
|
|
|
|
// Parent!.ChildSize.X = min(game_size.X, game_size.Y * (4 / 3)) * playfield_size_adjust
|
|
|
|
|
// Parent!.ChildSize.X = 819.2
|
2019-08-07 09:29:50 +00:00
|
|
|
|
//
|
|
|
|
|
// Scale = 819.2 / 512
|
|
|
|
|
// Scale = 1.6
|
2023-10-17 08:40:44 +00:00
|
|
|
|
Scale = new Vector2(Parent!.ChildSize.X / OsuPlayfield.BASE_SIZE.X);
|
2020-08-04 13:43:33 +00:00
|
|
|
|
Position = new Vector2(0, (PlayfieldShift ? 8f : 0f) * Scale.X);
|
2019-08-07 09:29:50 +00:00
|
|
|
|
// Size = 0.625
|
2018-09-21 05:43:17 +00:00
|
|
|
|
Size = Vector2.Divide(Vector2.One, Scale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|