mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Remove setters, cache CreatePowerStatus() and use a dummy LocalPowerStatus class in test scene
This commit is contained in:
@ -16,7 +16,7 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
SetDefault(Static.LoginOverlayDisplayed, false);
|
||||
SetDefault(Static.MutedAudioNotificationShownOnce, false);
|
||||
SetDefault(Static.BatteryLowNotificationShownOnce, false);
|
||||
SetDefault(Static.LowBatteryNotificationShownOnce, false);
|
||||
SetDefault(Static.LastHoverSoundPlaybackTime, (double?)null);
|
||||
SetDefault<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
||||
}
|
||||
@ -26,7 +26,7 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
LoginOverlayDisplayed,
|
||||
MutedAudioNotificationShownOnce,
|
||||
BatteryLowNotificationShownOnce,
|
||||
LowBatteryNotificationShownOnce,
|
||||
|
||||
/// <summary>
|
||||
/// Info about seasonal backgrounds available fetched from API - see <see cref="APISeasonalBackgrounds"/>.
|
||||
|
@ -694,6 +694,11 @@ namespace osu.Game
|
||||
loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true);
|
||||
loadComponentSingleFile(new DialogOverlay(), topMostOverlayContent.Add, true);
|
||||
|
||||
if (CreatePowerStatus() != null)
|
||||
{
|
||||
dependencies.CacheAs(CreatePowerStatus());
|
||||
}
|
||||
|
||||
chatOverlay.State.ValueChanged += state => channelManager.HighPollRate.Value = state.NewValue == Visibility.Visible;
|
||||
|
||||
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||
|
@ -96,7 +96,7 @@ namespace osu.Game
|
||||
|
||||
protected Storage Storage { get; set; }
|
||||
|
||||
protected PowerStatus PowerStatus;
|
||||
protected virtual PowerStatus CreatePowerStatus() => null;
|
||||
|
||||
[Cached]
|
||||
[Cached(typeof(IBindable<RulesetInfo>))]
|
||||
@ -332,8 +332,6 @@ namespace osu.Game
|
||||
dependencies.CacheAs(MusicController);
|
||||
|
||||
Ruleset.BindValueChanged(onRulesetChanged);
|
||||
|
||||
dependencies.CacheAs(PowerStatus);
|
||||
}
|
||||
|
||||
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
|
||||
|
@ -113,7 +113,7 @@ namespace osu.Game.Screens.Play
|
||||
[Resolved]
|
||||
private AudioManager audioManager { get; set; }
|
||||
|
||||
[Resolved]
|
||||
[Resolved(CanBeNull = true)]
|
||||
private PowerStatus powerStatus { get; set; }
|
||||
|
||||
public PlayerLoader(Func<Player> createPlayer)
|
||||
@ -125,7 +125,7 @@ namespace osu.Game.Screens.Play
|
||||
private void load(SessionStatics sessionStatics)
|
||||
{
|
||||
muteWarningShownOnce = sessionStatics.GetBindable<bool>(Static.MutedAudioNotificationShownOnce);
|
||||
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.BatteryLowNotificationShownOnce);
|
||||
batteryWarningShownOnce = sessionStatics.GetBindable<bool>(Static.LowBatteryNotificationShownOnce);
|
||||
|
||||
InternalChild = (content = new LogoTrackingContainer
|
||||
{
|
||||
@ -483,10 +483,11 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private void showBatteryWarningIfNeeded()
|
||||
{
|
||||
if (powerStatus == null) return;
|
||||
|
||||
if (!batteryWarningShownOnce.Value)
|
||||
{
|
||||
// Checks if the notification has not been shown yet, device is unplugged and if device battery is at or below the cutoff
|
||||
if (!powerStatus.IsCharging && powerStatus.ChargeLevel <= powerStatus.BatteryCutoff)
|
||||
if (powerStatus.IsLowBattery)
|
||||
{
|
||||
notificationOverlay?.Post(new BatteryWarningNotification());
|
||||
batteryWarningShownOnce.Value = true;
|
||||
@ -500,7 +501,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public BatteryWarningNotification()
|
||||
{
|
||||
Text = "Your battery level is low! Charge your device to prevent interruptions.";
|
||||
Text = "Your battery level is low! Charge your device to prevent interruptions during gameplay.";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -7,17 +7,11 @@ using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Tests
|
||||
{
|
||||
public class OsuTestBrowser : OsuGameBase
|
||||
{
|
||||
public OsuTestBrowser()
|
||||
{
|
||||
PowerStatus = new DefaultPowerStatus();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
@ -3,21 +3,27 @@
|
||||
|
||||
namespace osu.Game.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the system's power status.
|
||||
/// Currently implemented on iOS and Android only.
|
||||
/// </summary>
|
||||
public abstract class PowerStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum battery level before a warning notification
|
||||
/// is sent.
|
||||
/// The maximum battery level considered as low, from 0 to 1.
|
||||
/// </summary>
|
||||
public virtual double BatteryCutoff { get; } = 0.2;
|
||||
public virtual double BatteryCutoff { get; } = 0;
|
||||
|
||||
public virtual double ChargeLevel { get; set; }
|
||||
public virtual bool IsCharging { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The charge level of the battery, from 0 to 1.
|
||||
/// </summary>
|
||||
public virtual double ChargeLevel { get; } = 0;
|
||||
|
||||
public class DefaultPowerStatus : PowerStatus
|
||||
{
|
||||
public override double ChargeLevel { get; set; } = 1;
|
||||
public override bool IsCharging { get; set; } = true;
|
||||
public virtual bool IsCharging { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if <see cref="IsCharging"/> = false and <see cref="ChargeLevel"/> <= <see cref="BatteryCutoff"/>.
|
||||
/// </summary>
|
||||
public bool IsLowBattery => !IsCharging && ChargeLevel <= BatteryCutoff;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user