mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 13:23:05 +08:00
Show new daily challenge notification globally
This commit is contained in:
parent
a05f810724
commit
1b57a2a136
@ -80,44 +80,6 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
|||||||
AddStep("push screen", () => LoadScreen(screen = new Screens.OnlinePlay.DailyChallenge.DailyChallenge(room)));
|
AddStep("push screen", () => LoadScreen(screen = new Screens.OnlinePlay.DailyChallenge.DailyChallenge(room)));
|
||||||
AddUntilStep("wait for screen", () => screen.IsCurrentScreen());
|
AddUntilStep("wait for screen", () => screen.IsCurrentScreen());
|
||||||
AddStep("daily challenge ended", () => metadataClient.DailyChallengeInfo.Value = null);
|
AddStep("daily challenge ended", () => metadataClient.DailyChallengeInfo.Value = null);
|
||||||
|
|
||||||
Func<APIRequest, bool>? previousHandler = null;
|
|
||||||
|
|
||||||
AddStep("install custom handler", () =>
|
|
||||||
{
|
|
||||||
previousHandler = ((DummyAPIAccess)API).HandleRequest;
|
|
||||||
((DummyAPIAccess)API).HandleRequest = req =>
|
|
||||||
{
|
|
||||||
switch (req)
|
|
||||||
{
|
|
||||||
case GetRoomRequest r:
|
|
||||||
{
|
|
||||||
r.TriggerSuccess(new Room
|
|
||||||
{
|
|
||||||
RoomID = { Value = 1235, },
|
|
||||||
Name = { Value = "Daily Challenge: June 5, 2024" },
|
|
||||||
Playlist =
|
|
||||||
{
|
|
||||||
new PlaylistItem(CreateAPIBeatmapSet().Beatmaps.First())
|
|
||||||
{
|
|
||||||
RequiredMods = [new APIMod(new OsuModTraceable())],
|
|
||||||
AllowedMods = [new APIMod(new OsuModDoubleTime())]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
|
|
||||||
Category = { Value = RoomCategory.DailyChallenge }
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
AddStep("next daily challenge started", () => metadataClient.DailyChallengeInfo.Value = new DailyChallengeInfo { RoomID = 1235 });
|
|
||||||
|
|
||||||
AddStep("restore previous handler", () => ((DummyAPIAccess)API).HandleRequest = previousHandler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -10,6 +11,7 @@ using osu.Game.Localisation;
|
|||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Metadata;
|
using osu.Game.Online.Metadata;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using Color4 = osuTK.Graphics.Color4;
|
using Color4 = osuTK.Graphics.Color4;
|
||||||
@ -39,8 +41,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDailyChallengeButton()
|
public void TestDailyChallengeButton()
|
||||||
{
|
{
|
||||||
AddStep("beatmap of the day not active", () => metadataClient.DailyChallengeUpdated(null));
|
|
||||||
|
|
||||||
AddStep("set up API", () => dummyAPI.HandleRequest = req =>
|
AddStep("set up API", () => dummyAPI.HandleRequest = req =>
|
||||||
{
|
{
|
||||||
switch (req)
|
switch (req)
|
||||||
@ -67,17 +67,45 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("add button", () => Child = new DailyChallengeButton(@"button-default-select", new Color4(102, 68, 204, 255), _ => { }, 0, Key.D)
|
NotificationOverlay notificationOverlay = null!;
|
||||||
{
|
DependencyProvidingContainer buttonContainer = null!;
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
ButtonSystemState = ButtonSystemState.TopLevel,
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
||||||
{
|
{
|
||||||
RoomID = 1234,
|
RoomID = 1234,
|
||||||
}));
|
}));
|
||||||
|
AddStep("add content", () =>
|
||||||
|
{
|
||||||
|
notificationOverlay = new NotificationOverlay();
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
notificationOverlay,
|
||||||
|
buttonContainer = new DependencyProvidingContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
CachedDependencies = [(typeof(INotificationOverlay), notificationOverlay)],
|
||||||
|
Child = new DailyChallengeButton(@"button-default-select", new Color4(102, 68, 204, 255), _ => { }, 0, Key.D)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
ButtonSystemState = ButtonSystemState.TopLevel,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
|
||||||
|
|
||||||
|
AddStep("beatmap of the day not active", () => metadataClient.DailyChallengeUpdated(null));
|
||||||
|
AddAssert("no notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.Zero);
|
||||||
|
|
||||||
|
AddStep("hide button's parent", () => buttonContainer.Hide());
|
||||||
|
AddStep("beatmap of the day active", () => metadataClient.DailyChallengeUpdated(new DailyChallengeInfo
|
||||||
|
{
|
||||||
|
RoomID = 1234,
|
||||||
|
}));
|
||||||
|
AddAssert("notification posted", () => notificationOverlay.AllNotifications.Count(), () => Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ using osu.Game.Online.API.Requests.Responses;
|
|||||||
using osu.Game.Online.Metadata;
|
using osu.Game.Online.Metadata;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Screens.OnlinePlay.DailyChallenge;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -44,6 +45,9 @@ namespace osu.Game.Screens.Menu
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private INotificationOverlay? notificationOverlay { get; set; }
|
||||||
|
|
||||||
public DailyChallengeButton(string sampleName, Color4 colour, Action<MainMenuButton>? clickAction = null, params Key[] triggerKeys)
|
public DailyChallengeButton(string sampleName, Color4 colour, Action<MainMenuButton>? clickAction = null, params Key[] triggerKeys)
|
||||||
: base(ButtonSystemStrings.DailyChallenge, sampleName, OsuIcon.DailyChallenge, colour, clickAction, triggerKeys)
|
: base(ButtonSystemStrings.DailyChallenge, sampleName, OsuIcon.DailyChallenge, colour, clickAction, triggerKeys)
|
||||||
{
|
{
|
||||||
@ -100,7 +104,8 @@ namespace osu.Game.Screens.Menu
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
info.BindValueChanged(updateDisplay, true);
|
info.BindValueChanged(_ => dailyChallengeChanged(postNotification: true));
|
||||||
|
dailyChallengeChanged(postNotification: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -126,27 +131,30 @@ namespace osu.Game.Screens.Menu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisplay(ValueChangedEvent<DailyChallengeInfo?> info)
|
private void dailyChallengeChanged(bool postNotification)
|
||||||
{
|
{
|
||||||
UpdateState();
|
UpdateState();
|
||||||
|
|
||||||
scheduledCountdownUpdate?.Cancel();
|
scheduledCountdownUpdate?.Cancel();
|
||||||
scheduledCountdownUpdate = null;
|
scheduledCountdownUpdate = null;
|
||||||
|
|
||||||
if (info.NewValue == null)
|
if (info.Value == null)
|
||||||
{
|
{
|
||||||
Room = null;
|
Room = null;
|
||||||
cover.OnlineInfo = TooltipContent = null;
|
cover.OnlineInfo = TooltipContent = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var roomRequest = new GetRoomRequest(info.NewValue.Value.RoomID);
|
var roomRequest = new GetRoomRequest(info.Value.Value.RoomID);
|
||||||
|
|
||||||
roomRequest.Success += room =>
|
roomRequest.Success += room =>
|
||||||
{
|
{
|
||||||
Room = room;
|
Room = room;
|
||||||
cover.OnlineInfo = TooltipContent = room.Playlist.FirstOrDefault()?.Beatmap.BeatmapSet as APIBeatmapSet;
|
cover.OnlineInfo = TooltipContent = room.Playlist.FirstOrDefault()?.Beatmap.BeatmapSet as APIBeatmapSet;
|
||||||
|
|
||||||
|
if (postNotification)
|
||||||
|
notificationOverlay?.Post(new NewDailyChallengeNotification(room));
|
||||||
|
|
||||||
updateCountdown();
|
updateCountdown();
|
||||||
Scheduler.AddDelayed(updateCountdown, 1000, true);
|
Scheduler.AddDelayed(updateCountdown, 1000, true);
|
||||||
};
|
};
|
||||||
|
@ -424,18 +424,6 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|||||||
Text = "Today's daily challenge has concluded. Thanks for playing! The next one should appear in a few minutes."
|
Text = "Today's daily challenge has concluded. Thanks for playing! The next one should appear in a few minutes."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change.NewValue != null && change.NewValue.Value.RoomID != room.RoomID.Value)
|
|
||||||
{
|
|
||||||
var roomRequest = new GetRoomRequest(change.NewValue.Value.RoomID);
|
|
||||||
|
|
||||||
roomRequest.Success += room =>
|
|
||||||
{
|
|
||||||
waitForNextChallengeNotification?.Close(false);
|
|
||||||
notificationOverlay?.Post(new NewDailyChallengeNotification(room));
|
|
||||||
};
|
|
||||||
API.Queue(roomRequest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forcefullyExit()
|
private void forcefullyExit()
|
||||||
|
Loading…
Reference in New Issue
Block a user