1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Merge pull request #2090 from smoogipoo/editor-hitobject-movement

Fix editor layers not respecting playfield aspect ratios + scales
This commit is contained in:
Dean Herbert 2018-02-22 14:12:35 +09:00 committed by GitHub
commit 8111d7b2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 173 additions and 95 deletions

View File

@ -2,10 +2,12 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.Edit namespace osu.Game.Rulesets.Osu.Edit
@ -25,5 +27,7 @@ namespace osu.Game.Rulesets.Osu.Edit
new HitObjectCompositionTool<Slider>(), new HitObjectCompositionTool<Slider>(),
new HitObjectCompositionTool<Spinner>() new HitObjectCompositionTool<Spinner>()
}; };
protected override ScalableContainer CreateLayerContainer() => new ScalableContainer(OsuPlayfield.BASE_SIZE.X) { RelativeSizeAxes = Axes.Both };
} }
} }

View File

@ -5,15 +5,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using OpenTK; using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit.Layers.Selection; using osu.Game.Rulesets.Edit.Layers.Selection;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Edit; using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -27,44 +25,31 @@ namespace osu.Game.Tests.Visual
}; };
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuGameBase osuGame)
{ {
var playfield = new OsuEditPlayfield(); osuGame.Beatmap.Value = new TestWorkingBeatmap(new Beatmap
Children = new Drawable[]
{ {
new Container HitObjects = new List<HitObject>
{ {
RelativeSizeAxes = Axes.Both, new HitCircle { Position = new Vector2(256, 192), Scale = 0.5f },
Clock = new FramedClock(new StopwatchClock()), new HitCircle { Position = new Vector2(344, 148), Scale = 0.5f },
Child = playfield new Slider
{
ControlPoints = new List<Vector2>
{
new Vector2(128, 256),
new Vector2(344, 256),
},
Distance = 400,
Position = new Vector2(128, 256),
Velocity = 1,
TickDistance = 100,
Scale = 0.5f,
}
}, },
new SelectionLayer(playfield) });
};
var hitCircle1 = new HitCircle { Position = new Vector2(256, 192), Scale = 0.5f }; Child = new OsuHitObjectComposer(new OsuRuleset());
var hitCircle2 = new HitCircle { Position = new Vector2(344, 148), Scale = 0.5f };
var slider = new Slider
{
ControlPoints = new List<Vector2>
{
new Vector2(128, 256),
new Vector2(344, 256),
},
Distance = 400,
Position = new Vector2(128, 256),
Velocity = 1,
TickDistance = 100,
Scale = 0.5f,
};
hitCircle1.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
hitCircle2.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
playfield.Add(new DrawableHitCircle(hitCircle1));
playfield.Add(new DrawableHitCircle(hitCircle2));
playfield.Add(new DrawableSlider(slider));
} }
} }
} }

View File

@ -25,20 +25,24 @@ namespace osu.Game.Rulesets.Edit
protected ICompositionTool CurrentTool { get; private set; } protected ICompositionTool CurrentTool { get; private set; }
private RulesetContainer rulesetContainer;
private readonly List<Container> layerContainers = new List<Container>();
protected HitObjectComposer(Ruleset ruleset) protected HitObjectComposer(Ruleset ruleset)
{ {
this.ruleset = ruleset; this.ruleset = ruleset;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osuGame) private void load(OsuGameBase osuGame)
{ {
RulesetContainer rulesetContainer;
try try
{ {
rulesetContainer = CreateRulesetContainer(ruleset, osuGame.Beatmap.Value); rulesetContainer = CreateRulesetContainer(ruleset, osuGame.Beatmap.Value);
// TODO: should probably be done at a RulesetContainer level to share logic with Player.
rulesetContainer.Clock = new InterpolatingFramedClock((IAdjustableClock)osuGame.Beatmap.Value.Track ?? new StopwatchClock());
} }
catch (Exception e) catch (Exception e)
{ {
@ -46,6 +50,14 @@ namespace osu.Game.Rulesets.Edit
return; return;
} }
ScalableContainer createLayerContainerWithContent(Drawable content)
{
var container = CreateLayerContainer();
container.Child = content;
layerContainers.Add(container);
return container;
}
RadioButtonCollection toolboxCollection; RadioButtonCollection toolboxCollection;
InternalChild = new GridContainer InternalChild = new GridContainer
{ {
@ -66,20 +78,21 @@ namespace osu.Game.Rulesets.Edit
}, },
new Container new Container
{ {
Name = "Content",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true,
BorderColour = Color4.White,
BorderThickness = 2,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box createLayerContainerWithContent(new Container
{ {
Name = "Border",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0, Masking = true,
AlwaysPresent = true, BorderColour = Color4.White,
}, BorderThickness = 2,
Child = new Box { RelativeSizeAxes = Axes.Both, Alpha = 0, AlwaysPresent = true }
}),
rulesetContainer, rulesetContainer,
new SelectionLayer(rulesetContainer.Playfield) createLayerContainerWithContent(new SelectionLayer(rulesetContainer.Playfield))
} }
} }
}, },
@ -90,8 +103,6 @@ namespace osu.Game.Rulesets.Edit
} }
}; };
rulesetContainer.Clock = new InterpolatingFramedClock((IAdjustableClock)osuGame.Beatmap.Value.Track ?? new StopwatchClock());
toolboxCollection.Items = toolboxCollection.Items =
new[] { new RadioButton("Select", () => setCompositionTool(null)) } new[] { new RadioButton("Select", () => setCompositionTool(null)) }
.Concat( .Concat(
@ -102,10 +113,28 @@ namespace osu.Game.Rulesets.Edit
toolboxCollection.Items[0].Select(); toolboxCollection.Items[0].Select();
} }
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
layerContainers.ForEach(l =>
{
l.Anchor = rulesetContainer.Playfield.Anchor;
l.Origin = rulesetContainer.Playfield.Origin;
l.Position = rulesetContainer.Playfield.Position;
l.Size = rulesetContainer.Playfield.Size;
});
}
private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool; private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool;
protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap, true); protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap, true);
protected abstract IReadOnlyList<ICompositionTool> CompositionTools { get; } protected abstract IReadOnlyList<ICompositionTool> CompositionTools { get; }
/// <summary>
/// Creates a <see cref="ScalableContainer"/> which provides a layer above or below the <see cref="Playfield"/>.
/// </summary>
protected virtual ScalableContainer CreateLayerContainer() => new ScalableContainer { RelativeSizeAxes = Axes.Both };
} }
} }

View File

@ -3,52 +3,37 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using OpenTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
public abstract class Playfield : Container public abstract class Playfield : ScalableContainer
{ {
/// <summary> /// <summary>
/// The HitObjects contained in this Playfield. /// The HitObjects contained in this Playfield.
/// </summary> /// </summary>
public HitObjectContainer HitObjects { get; private set; } public HitObjectContainer HitObjects { get; private set; }
public Container<Drawable> ScaledContent;
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content;
private List<Playfield> nestedPlayfields;
/// <summary> /// <summary>
/// All the <see cref="Playfield"/>s nested inside this playfield. /// All the <see cref="Playfield"/>s nested inside this playfield.
/// </summary> /// </summary>
public IReadOnlyList<Playfield> NestedPlayfields => nestedPlayfields; public IReadOnlyList<Playfield> NestedPlayfields => nestedPlayfields;
private List<Playfield> nestedPlayfields;
/// <summary> /// <summary>
/// A container for keeping track of DrawableHitObjects. /// A container for keeping track of DrawableHitObjects.
/// </summary> /// </summary>
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width.</param> /// <param name="customWidth">The width to scale the internal coordinate space to.
protected Playfield(float? customWidth = null) /// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
/// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
protected Playfield(float? customWidth = null, float? customHeight = null)
: base(customWidth, customHeight)
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
AddInternal(ScaledContent = new ScaledContainer
{
CustomWidth = customWidth,
RelativeSizeAxes = Axes.Both,
Children = new[]
{
content = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
});
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -94,22 +79,5 @@ namespace osu.Game.Rulesets.UI
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s. /// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
/// </summary> /// </summary>
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer(); protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
private class ScaledContainer : Container
{
/// <summary>
/// A value (in game pixels that we should scale our content to match).
/// </summary>
public float? CustomWidth;
//dividing by the customwidth will effectively scale our content to the required container size.
protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale;
protected override void Update()
{
base.Update();
RelativeChildSize = new Vector2(DrawScale.X, RelativeChildSize.Y);
}
}
} }
} }

View File

@ -0,0 +1,86 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using OpenTK;
namespace osu.Game.Rulesets.UI
{
/// <summary>
/// A <see cref="Container"/> which can have its internal coordinate system scaled to a specific size.
/// </summary>
public class ScalableContainer : Container
{
/// <summary>
/// The scaled content.
/// </summary>
public readonly Container ScaledContent;
protected override Container<Drawable> Content => content;
private readonly Container content;
/// <summary>
/// A <see cref="Container"/> which can have its internal coordinate system scaled to a specific size.
/// </summary>
/// <param name="customWidth">The width to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
/// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
public ScalableContainer(float? customWidth = null, float? customHeight = null)
{
AddInternal(ScaledContent = new ScaledContainer
{
CustomWidth = customWidth,
CustomHeight = customHeight,
RelativeSizeAxes = Axes.Both,
Child = content = new Container { RelativeSizeAxes = Axes.Both }
});
}
public class ScaledContainer : Container
{
/// <summary>
/// The value to scale the width of the content to match.
/// If null, <see cref="CustomHeight"/> is used.
/// </summary>
public float? CustomWidth;
/// <summary>
/// The value to scale the height of the content to match.
/// if null, <see cref="CustomWidth"/> is used.
/// </summary>
public float? CustomHeight;
/// <summary>
/// The scale that is required for the size of the content to match <see cref="CustomWidth"/> and <see cref="CustomHeight"/>.
/// </summary>
private Vector2 sizeScale
{
get
{
if (CustomWidth.HasValue && CustomHeight.HasValue)
return Vector2.Divide(DrawSize, new Vector2(CustomWidth.Value, CustomHeight.Value));
if (CustomWidth.HasValue)
return new Vector2(DrawSize.X / CustomWidth.Value);
if (CustomHeight.HasValue)
return new Vector2(DrawSize.Y / CustomHeight.Value);
return Vector2.One;
}
}
/// <summary>
/// Scale the content to the required container size by multiplying by <see cref="sizeScale"/>.
/// </summary>
protected override Vector2 DrawScale => sizeScale * base.DrawScale;
protected override void Update()
{
base.Update();
RelativeChildSize = new Vector2(CustomWidth.HasValue ? sizeScale.X : RelativeChildSize.X, CustomHeight.HasValue ? sizeScale.Y : RelativeChildSize.Y);
}
}
}
}

View File

@ -62,9 +62,14 @@ namespace osu.Game.Rulesets.UI.Scrolling
/// Creates a new <see cref="ScrollingPlayfield"/>. /// Creates a new <see cref="ScrollingPlayfield"/>.
/// </summary> /// </summary>
/// <param name="direction">The direction in which <see cref="DrawableHitObject"/>s in this container should scroll.</param> /// <param name="direction">The direction in which <see cref="DrawableHitObject"/>s in this container should scroll.</param>
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width</param> /// <param name="customWidth">The width to scale the internal coordinate space to.
protected ScrollingPlayfield(ScrollingDirection direction, float? customWidth = null) /// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
: base(customWidth) /// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
protected ScrollingPlayfield(ScrollingDirection direction, float? customWidth = null, float? customHeight = null)
: base(customWidth, customHeight)
{ {
this.direction = direction; this.direction = direction;
} }

View File

@ -357,6 +357,7 @@
<Compile Include="Overlays\Social\SocialPanel.cs" /> <Compile Include="Overlays\Social\SocialPanel.cs" />
<Compile Include="Rulesets\Mods\IApplicableToDrawableHitObject.cs" /> <Compile Include="Rulesets\Mods\IApplicableToDrawableHitObject.cs" />
<Compile Include="Rulesets\Objects\HitWindows.cs" /> <Compile Include="Rulesets\Objects\HitWindows.cs" />
<Compile Include="Rulesets\UI\ScalableContainer.cs" />
<Compile Include="Screens\Play\PlayerSettings\VisualSettings.cs" /> <Compile Include="Screens\Play\PlayerSettings\VisualSettings.cs" />
<Compile Include="Rulesets\Objects\CatmullApproximator.cs" /> <Compile Include="Rulesets\Objects\CatmullApproximator.cs" />
<Compile Include="Rulesets\UI\HitObjectContainer.cs" /> <Compile Include="Rulesets\UI\HitObjectContainer.cs" />