diff --git a/Source/Engine/Audio/AudioSource.h b/Source/Engine/Audio/AudioSource.h index ac15b5a4b..2b5b7e9d8 100644 --- a/Source/Engine/Audio/AudioSource.h +++ b/Source/Engine/Audio/AudioSource.h @@ -199,7 +199,7 @@ public: /// Gets the current state of the audio playback (playing/paused/stopped). /// /// The value. - API_PROPERTY() FORCE_INLINE States GetState() const + API_PROPERTY() FORCE_INLINE AudioSource::States GetState() const { return _state; } diff --git a/Source/Engine/Platform/BatteryInfo.h b/Source/Engine/Platform/BatteryInfo.h index 146f3f562..2ed6b5cac 100644 --- a/Source/Engine/Platform/BatteryInfo.h +++ b/Source/Engine/Platform/BatteryInfo.h @@ -5,43 +5,45 @@ #include "Engine/Core/Types/BaseTypes.h" /// -/// Power supply status. -/// -API_ENUM() enum class ACLineStatus : byte -{ - /// - /// Power supply is not connected. - /// - Offline = 0, - /// - /// Power supply is connected. - /// - Online = 1, - /// - /// Unknown status. - /// - Unknown = 255 -}; - -/// -/// Contains information about power supply (Battery). +/// Contains information about power supply (battery). /// API_STRUCT() struct BatteryInfo { DECLARE_SCRIPTING_TYPE_MINIMAL(BatteryInfo); - /// - /// Power supply status. - /// - API_FIELD() ACLineStatus ACLineStatus; + /// + /// Power supply status. + /// + API_ENUM() enum class States + { + /// + /// Unknown status. + /// + Unknown, + + /// + /// Power supply is connected and battery is charging. + /// + BatteryCharging, + + /// + /// Device is running on a battery. + /// + BatteryDischarging, + + /// + /// Device is connected to the stable power supply (AC). + /// + Connected, + }; /// - /// Battery percentage left. + /// Power supply state. /// - API_FIELD() byte BatteryLifePercent; + API_FIELD() BatteryInfo::States State = BatteryInfo::States::Unknown; /// - /// Remaining battery life time in second. + /// Battery percentage left (normalized to 0-1 range). /// - API_FIELD() uint32 BatteryLifeTime; + API_FIELD() float BatteryLifePercent = 1.0f; }; diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp index 5e2aa4598..129ff4249 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.cpp +++ b/Source/Engine/Platform/Win32/Win32Platform.cpp @@ -315,9 +315,13 @@ BatteryInfo Win32Platform::GetBatteryInfo() BatteryInfo info; SYSTEM_POWER_STATUS status; GetSystemPowerStatus(&status); - info.ACLineStatus = (ACLineStatus)status.ACLineStatus; - info.BatteryLifePercent = status.BatteryLifePercent; - info.BatteryLifeTime = status.BatteryLifeTime; + info.BatteryLifePercent = (float)status.BatteryLifePercent / 255.0f; + if (status.BatteryFlag & 8) + info.State = BatteryInfo::States::BatteryCharging; + else if (status.BatteryFlag & 1 || status.BatteryFlag & 2 || status.BatteryFlag & 4) + info.State = BatteryInfo::States::BatteryDischarging; + else if (status.ACLineStatus == 1 || status.BatteryFlag & 128) + info.State = BatteryInfo::States::Connected; return info; }