Skip to content

Commit

Permalink
Merge branch 'master' into daily-challenge-intro-audio-auto-download
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy authored Aug 9, 2024
2 parents 0cb3b6a + 4dc779a commit d2c1d83
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 81 deletions.
2 changes: 1 addition & 1 deletion osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.802.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.809.2" />
</ItemGroup>
<PropertyGroup>
<!-- Fody does not handle Android build well, and warns when unchanged.
Expand Down
10 changes: 5 additions & 5 deletions osu.Game.Rulesets.Osu/Edit/OsuHitObjectInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace osu.Game.Rulesets.Osu.Edit
{
public partial class OsuHitObjectInspector : HitObjectInspector
{
protected override void AddInspectorValues()
protected override void AddInspectorValues(HitObject[] objects)
{
base.AddInspectorValues();
base.AddInspectorValues(objects);

if (EditorBeatmap.SelectedHitObjects.Count > 0)
if (objects.Length > 0)
{
var firstInSelection = (OsuHitObject)EditorBeatmap.SelectedHitObjects.MinBy(ho => ho.StartTime)!;
var lastInSelection = (OsuHitObject)EditorBeatmap.SelectedHitObjects.MaxBy(ho => ho.GetEndTime())!;
var firstInSelection = (OsuHitObject)objects.MinBy(ho => ho.StartTime)!;
var lastInSelection = (OsuHitObject)objects.MaxBy(ho => ho.GetEndTime())!;

Debug.Assert(firstInSelection != null && lastInSelection != null);

Expand Down
34 changes: 34 additions & 0 deletions osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,40 @@ public void TestDecodeBeatmapComboOffsetsCatch()
}
}

[Test]
public void TestDecodeBeatmapHitObjectCoordinatesLegacy()
{
var decoder = new LegacyBeatmapDecoder();

using (var resStream = TestResources.OpenResource("hitobject-coordinates-legacy.osu"))
using (var stream = new LineBufferedReader(resStream))
{
var hitObjects = decoder.Decode(stream).HitObjects;

var positionData = hitObjects[0] as IHasPosition;

Assert.IsNotNull(positionData);
Assert.AreEqual(new Vector2(256, 256), positionData!.Position);
}
}

[Test]
public void TestDecodeBeatmapHitObjectCoordinatesLazer()
{
var decoder = new LegacyBeatmapDecoder(LegacyBeatmapEncoder.FIRST_LAZER_VERSION);

using (var resStream = TestResources.OpenResource("hitobject-coordinates-lazer.osu"))
using (var stream = new LineBufferedReader(resStream))
{
var hitObjects = decoder.Decode(stream).HitObjects;

var positionData = hitObjects[0] as IHasPosition;

Assert.IsNotNull(positionData);
Assert.AreEqual(new Vector2(256.99853f, 256.001f), positionData!.Position);
}
}

[Test]
public void TestDecodeBeatmapHitObjects()
{
Expand Down
9 changes: 7 additions & 2 deletions osu.Game.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ public static string GetTestBeatmapForImport(bool virtualTrack = false)

private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz");

private static int importId;
private static int testId = 1;

/// <summary>
/// Get a unique int value which is incremented each call.
/// </summary>
public static int GetNextTestID() => Interlocked.Increment(ref testId);

/// <summary>
/// Create a test beatmap set model.
Expand All @@ -88,7 +93,7 @@ public static BeatmapSetInfo CreateTestBeatmapSetInfo(int? difficultyCount = nul

RulesetInfo getRuleset() => rulesets?[j++ % rulesets.Length];

int setId = Interlocked.Increment(ref importId);
int setId = GetNextTestID();

var metadata = new BeatmapMetadata
{
Expand Down
6 changes: 6 additions & 0 deletions osu.Game.Tests/Resources/hitobject-coordinates-lazer.osu
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
osu file format v128

[HitObjects]
// Coordinates should be preserves in lazer beatmaps.

256.99853,256.001,1000,49,0,0:0:0:0:
5 changes: 5 additions & 0 deletions osu.Game.Tests/Resources/hitobject-coordinates-legacy.osu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
osu file format v14

[HitObjects]
// Coordinates should be truncated to int values in legacy beatmaps.
256.99853,256.001,1000,49,0,0:0:0:0:
4 changes: 2 additions & 2 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public void TestLobbyEvents()

private void addRandomPlayer()
{
int randomUser = RNG.Next(200000, 500000);
multiplayerClient.AddUser(new APIUser { Id = randomUser, Username = $"user {randomUser}" });
int id = TestResources.GetNextTestID();
multiplayerClient.AddUser(new APIUser { Id = id, Username = $"user {id}" });
}

private void removeLastUser()
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Tests/Visual/Online/TestSceneChannelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat.ChannelList;
using osu.Game.Overlays.Chat.Listing;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.Visual.Online
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public void TestVisual()

private Channel createRandomPublicChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel
{
Name = $"#channel-{id}",
Expand All @@ -171,7 +171,7 @@ private Channel createRandomPublicChannel()

private Channel createRandomPrivateChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel(new APIUser
{
Id = id,
Expand All @@ -181,7 +181,7 @@ private Channel createRandomPrivateChannel()

private Channel createRandomAnnounceChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel
{
Name = $"Announce {id}",
Expand Down
7 changes: 4 additions & 3 deletions osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using osu.Framework.Input;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
Expand All @@ -33,6 +32,7 @@
using osuTK;
using osuTK.Input;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.Visual.Online
{
Expand Down Expand Up @@ -122,7 +122,7 @@ public void SetUpSteps()
return true;
case PostMessageRequest postMessage:
postMessage.TriggerSuccess(new Message(RNG.Next(0, 10000000))
postMessage.TriggerSuccess(new Message(TestResources.GetNextTestID())
{
Content = postMessage.Message.Content,
ChannelId = postMessage.Message.ChannelId,
Expand Down Expand Up @@ -719,7 +719,8 @@ private List<Message> createChannelMessages(Channel channel)

private Channel createPrivateChannel()
{
int id = RNG.Next(0, DummyAPIAccess.DUMMY_USER_ID - 1);
int id = TestResources.GetNextTestID();

return new Channel(new APIUser
{
Id = id,
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Beatmaps/Formats/LegacyDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public abstract class LegacyDecoder<T> : Decoder<T>
{
public const int LATEST_VERSION = 14;

/// <summary>
/// The .osu format (beatmap) version.
///
/// osu!stable's versions end at <see cref="LATEST_VERSION"/>.
/// osu!lazer's versions starts at <see cref="LegacyBeatmapEncoder.FIRST_LAZER_VERSION"/>.
/// </summary>
protected readonly int FormatVersion;

protected LegacyDecoder(int version)
Expand Down
16 changes: 15 additions & 1 deletion osu.Game/Online/Multiplayer/MultiplayerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,21 @@ public Task PlaylistItemChanged(MultiplayerPlaylistItem item)
}
catch (Exception ex)
{
throw new AggregateException($"Item: {JsonConvert.SerializeObject(createPlaylistItem(item))}\n\nRoom:{JsonConvert.SerializeObject(APIRoom)}", ex);
// Temporary code to attempt to figure out long-term failing tests.
bool success = true;
int indexOf = -1234;
try
{
indexOf = Room.Playlist.IndexOf(Room.Playlist.Single(existing => existing.ID == item.ID));
Room.Playlist[indexOf] = item;
}
catch
{
success = false;
}
throw new AggregateException($"Index: {indexOf} Length: {Room.Playlist.Count} Retry success: {success} Item: {JsonConvert.SerializeObject(createPlaylistItem(item))}\n\nRoom:{JsonConvert.SerializeObject(APIRoom)}", ex);
}
ItemChanged?.Invoke(item);
Expand Down
54 changes: 54 additions & 0 deletions osu.Game/Overlays/Volume/MasterVolumeMeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osuTK.Graphics;

namespace osu.Game.Overlays.Volume
{
public partial class MasterVolumeMeter : VolumeMeter
{
private MuteButton muteButton = null!;

public Bindable<bool> IsMuted { get; } = new Bindable<bool>();

private readonly BindableDouble muteAdjustment = new BindableDouble();

[Resolved]
private VolumeOverlay volumeOverlay { get; set; } = null!;

public MasterVolumeMeter(string name, float circleSize, Color4 meterColour)
: base(name, circleSize, meterColour)
{
}

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
IsMuted.BindValueChanged(muted =>
{
if (muted.NewValue)
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
else
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
});

Add(muteButton = new MuteButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
Blending = BlendingParameters.Additive,
X = CircleSize / 2,
Y = CircleSize * 0.23f,
Current = { BindTarget = IsMuted }
});

muteButton.Current.ValueChanged += _ => volumeOverlay.Show();
}

public void ToggleMute() => muteButton.Current.Value = !muteButton.Current.Value;
}
}
42 changes: 27 additions & 15 deletions osu.Game/Overlays/Volume/MuteButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Overlays.Volume
{
Expand All @@ -33,29 +33,28 @@ public Bindable<bool> Current
}
}

private Color4 hoveredColour, unhoveredColour;

private const float width = 100;
public const float HEIGHT = 35;
private ColourInfo hoveredBorderColour;
private ColourInfo unhoveredBorderColour;
private CompositeDrawable border = null!;

public MuteButton()
{
Content.BorderThickness = 3;
Content.CornerRadius = HEIGHT / 2;
Content.CornerExponent = 2;
const float width = 30;
const float height = 30;

Size = new Vector2(width, HEIGHT);
Size = new Vector2(width, height);
Content.CornerRadius = height / 2;
Content.CornerExponent = 2;

Action = () => Current.Value = !Current.Value;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
hoveredColour = colours.YellowDark;

Content.BorderColour = unhoveredColour = colours.Gray1;
BackgroundColour = colours.Gray1;
hoveredBorderColour = colours.PinkLight;
unhoveredBorderColour = colours.Gray1;

SpriteIcon icon;

Expand All @@ -65,26 +64,39 @@ private void load(OsuColour colours)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
border = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = 3,
BorderColour = unhoveredBorderColour,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
});

Current.BindValueChanged(muted =>
{
icon.Icon = muted.NewValue ? FontAwesome.Solid.VolumeMute : FontAwesome.Solid.VolumeUp;
icon.Size = new Vector2(muted.NewValue ? 18 : 20);
icon.Size = new Vector2(muted.NewValue ? 12 : 16);
icon.Margin = new MarginPadding { Right = muted.NewValue ? 2 : 0 };
}, true);
}

protected override bool OnHover(HoverEvent e)
{
Content.TransformTo<Container<Drawable>, ColourInfo>("BorderColour", hoveredColour, 500, Easing.OutQuint);
border.TransformTo(nameof(BorderColour), hoveredBorderColour, 500, Easing.OutQuint);
return false;
}

protected override void OnHoverLost(HoverLostEvent e)
{
Content.TransformTo<Container<Drawable>, ColourInfo>("BorderColour", unhoveredColour, 500, Easing.OutQuint);
border.TransformTo(nameof(BorderColour), unhoveredBorderColour, 500, Easing.OutQuint);
}

protected override bool OnMouseDown(MouseDownEvent e)
Expand Down
Loading

0 comments on commit d2c1d83

Please sign in to comment.