mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Merge pull request #12330 from Cublibre/master
Send a warning notification if device is unplugged and at low battery
This commit is contained in:
@ -24,6 +24,7 @@ using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Screens.Play.PlayerSettings;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -112,6 +113,9 @@ namespace osu.Game.Screens.Play
|
||||
[Resolved]
|
||||
private AudioManager audioManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private BatteryInfo batteryInfo { get; set; }
|
||||
|
||||
public PlayerLoader(Func<Player> createPlayer)
|
||||
{
|
||||
this.createPlayer = createPlayer;
|
||||
@ -121,6 +125,7 @@ namespace osu.Game.Screens.Play
|
||||
private void load(SessionStatics sessionStatics)
|
||||
{
|
||||
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
|
||||
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce);
|
||||
|
||||
InternalChild = (content = new LogoTrackingContainer
|
||||
{
|
||||
@ -196,6 +201,7 @@ namespace osu.Game.Screens.Play
|
||||
Scheduler.Add(new ScheduledDelegate(pushWhenLoaded, Clock.CurrentTime + 1800, 0));
|
||||
|
||||
showMuteWarningIfNeeded();
|
||||
showBatteryWarningIfNeeded();
|
||||
}
|
||||
|
||||
public override void OnResuming(IScreen last)
|
||||
@ -470,5 +476,48 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Low battery warning
|
||||
|
||||
private Bindable<bool> batteryWarningShownOnce;
|
||||
|
||||
private void showBatteryWarningIfNeeded()
|
||||
{
|
||||
if (batteryInfo == null) return;
|
||||
|
||||
if (!batteryWarningShownOnce.Value)
|
||||
{
|
||||
if (!batteryInfo.IsCharging && batteryInfo.ChargeLevel <= 0.25)
|
||||
{
|
||||
notificationOverlay?.Post(new BatteryWarningNotification());
|
||||
batteryWarningShownOnce.Value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class BatteryWarningNotification : SimpleNotification
|
||||
{
|
||||
public override bool IsImportant => true;
|
||||
|
||||
public BatteryWarningNotification()
|
||||
{
|
||||
Text = "Your battery level is low! Charge your device to prevent interruptions during gameplay.";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay)
|
||||
{
|
||||
Icon = FontAwesome.Solid.BatteryQuarter;
|
||||
IconBackgound.Colour = colours.RedDark;
|
||||
|
||||
Activated = delegate
|
||||
{
|
||||
notificationOverlay.Hide();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user