1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +08:00

Merge branch 'master' into remove-column-padding

This commit is contained in:
Bartłomiej Dach 2020-08-27 13:33:02 +02:00 committed by GitHub
commit d6a1f1343e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 293 additions and 9 deletions

View File

@ -169,17 +169,17 @@ namespace osu.Game.Tests.Editing
[Test]
public void GetSnappedDistanceFromDistance()
{
assertSnappedDistance(50, 100);
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 100);
assertSnappedDistance(150, 200);
assertSnappedDistance(150, 100);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 300);
assertSnappedDistance(250, 200);
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 2);
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 200);
assertSnappedDistance(150, 200);
assertSnappedDistance(100, 0);
assertSnappedDistance(150, 0);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 200);
@ -190,8 +190,8 @@ namespace osu.Game.Tests.Editing
});
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 200);
assertSnappedDistance(150, 200);
assertSnappedDistance(100, 0);
assertSnappedDistance(150, 0);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 200);
assertSnappedDistance(400, 400);

View File

@ -0,0 +1,68 @@
// 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.Linq;
using Humanizer;
using NUnit.Framework;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Tests.Visual.Ranking
{
public class TestSceneSimpleStatisticRow : OsuTestScene
{
private Container container;
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = new Container
{
AutoSizeAxes = Axes.Y,
Width = 700,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333"),
},
container = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(20)
}
}
};
});
[Test]
public void TestEmpty()
{
AddStep("create with no items",
() => container.Add(new SimpleStatisticRow(2, Enumerable.Empty<SimpleStatisticItem>())));
}
[Test]
public void TestManyItems(
[Values(1, 2, 3, 4, 12)] int itemCount,
[Values(1, 3, 5)] int columnCount)
{
AddStep($"create with {"item".ToQuantity(itemCount)}", () =>
{
var items = Enumerable.Range(1, itemCount)
.Select(i => new SimpleStatisticItem<int>($"Statistic #{i}")
{
Value = RNG.Next(100)
});
container.Add(new SimpleStatisticRow(columnCount, items));
});
}
}
}

View File

@ -25,7 +25,7 @@ using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
using Key = osuTK.Input.Key;
using osuTK.Input;
namespace osu.Game.Rulesets.Edit
{
@ -293,7 +293,16 @@ namespace osu.Game.Rulesets.Edit
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
{
var snappedEndTime = BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime);
double actualDuration = referenceTime + DistanceToDuration(referenceTime, distance);
double snappedEndTime = BeatSnapProvider.SnapTime(actualDuration, referenceTime);
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
// we don't want to exceed the actual duration and snap to a point in the future.
// as we are snapping to beat length via SnapTime (which will round-to-nearest), check for snapping in the forward direction and reverse it.
if (snappedEndTime > actualDuration + 1)
snappedEndTime -= beatLength;
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
}

View File

@ -47,6 +47,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// Converts an unsnapped distance to a snapped distance.
/// The returned distance will always be floored (as to never exceed the provided <paramref name="distance"/>.
/// </summary>
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
/// <param name="distance">The distance to convert.</param>

View File

@ -0,0 +1,80 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Ranking.Statistics
{
/// <summary>
/// Represents a simple statistic item (one that only needs textual display).
/// Richer visualisations should be done with <see cref="StatisticItem"/>s.
/// </summary>
public abstract class SimpleStatisticItem : Container
{
/// <summary>
/// The text to display as the statistic's value.
/// </summary>
protected string Value
{
set => this.value.Text = value;
}
private readonly OsuSpriteText value;
/// <summary>
/// Creates a new simple statistic item.
/// </summary>
/// <param name="name">The name of the statistic.</param>
protected SimpleStatisticItem(string name)
{
Name = name;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddRange(new[]
{
new OsuSpriteText
{
Text = Name,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
value = new OsuSpriteText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Font = OsuFont.Torus.With(weight: FontWeight.Bold)
}
});
}
}
/// <summary>
/// Strongly-typed generic specialisation for <see cref="SimpleStatisticItem"/>.
/// </summary>
public class SimpleStatisticItem<TValue> : SimpleStatisticItem
{
/// <summary>
/// The statistic's value to be displayed.
/// </summary>
public new TValue Value
{
set => base.Value = DisplayValue(value);
}
/// <summary>
/// Used to convert <see cref="Value"/> to a text representation.
/// Defaults to using <see cref="object.ToString"/>.
/// </summary>
protected virtual string DisplayValue(TValue value) => value.ToString();
public SimpleStatisticItem(string name)
: base(name)
{
}
}
}

View File

@ -0,0 +1,122 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Screens.Ranking.Statistics
{
/// <summary>
/// Represents a statistic row with simple statistics (ones that only need textual display).
/// Richer visualisations should be done with <see cref="StatisticRow"/>s and <see cref="StatisticItem"/>s.
/// </summary>
public class SimpleStatisticRow : CompositeDrawable
{
private readonly SimpleStatisticItem[] items;
private readonly int columnCount;
private FillFlowContainer[] columns;
/// <summary>
/// Creates a statistic row for the supplied <see cref="SimpleStatisticItem"/>s.
/// </summary>
/// <param name="columnCount">The number of columns to layout the <paramref name="items"/> into.</param>
/// <param name="items">The <see cref="SimpleStatisticItem"/>s to display in this row.</param>
public SimpleStatisticRow(int columnCount, IEnumerable<SimpleStatisticItem> items)
{
if (columnCount < 1)
throw new ArgumentOutOfRangeException(nameof(columnCount));
this.columnCount = columnCount;
this.items = items.ToArray();
}
[BackgroundDependencyLoader]
private void load()
{
columns = new FillFlowContainer[columnCount];
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
ColumnDimensions = createColumnDimensions().ToArray(),
Content = new[] { createColumns().ToArray() }
};
for (int i = 0; i < items.Length; ++i)
columns[i % columnCount].Add(items[i]);
}
private IEnumerable<Dimension> createColumnDimensions()
{
for (int column = 0; column < columnCount; ++column)
{
if (column > 0)
yield return new Dimension(GridSizeMode.Absolute, 30);
yield return new Dimension();
}
}
private IEnumerable<Drawable> createColumns()
{
for (int column = 0; column < columnCount; ++column)
{
if (column > 0)
{
yield return new Spacer
{
Alpha = items.Length > column ? 1 : 0
};
}
yield return columns[column] = createColumn();
}
}
private FillFlowContainer createColumn() => new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
};
private class Spacer : CompositeDrawable
{
public Spacer()
{
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding { Vertical = 4 };
InternalChild = new CircularContainer
{
RelativeSizeAxes = Axes.Y,
Width = 3,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
CornerRadius = 2,
Masking = true,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#222")
}
};
}
}
}
}

View File

@ -116,6 +116,7 @@ namespace osu.Game.Skinning
case string _ when pair.Key.StartsWith("KeyImage"):
case string _ when pair.Key.StartsWith("Hit"):
case string _ when pair.Key.StartsWith("Stage"):
case string _ when pair.Key.StartsWith("Lighting"):
currentConfig.ImageLookups[pair.Key] = pair.Value;
break;
}

View File

@ -173,6 +173,9 @@ namespace osu.Game.Skinning
case LegacyManiaSkinConfigurationLookups.ShowJudgementLine:
return SkinUtils.As<TValue>(new Bindable<bool>(existing.ShowJudgementLine));
case LegacyManiaSkinConfigurationLookups.ExplosionImage:
return SkinUtils.As<TValue>(getManiaImage(existing, "LightingN"));
case LegacyManiaSkinConfigurationLookups.ExplosionScale:
Debug.Assert(maniaLookup.TargetColumn != null);