Skip to content

Commit

Permalink
Added Utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gramps committed Oct 28, 2019
1 parent ab2bcde commit a8920f1
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 1 deletion.
146 changes: 146 additions & 0 deletions SteamworksPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,150 @@ SW_PY int GetGameBadgeLevel(int series, bool foil){
return 0;
}
return SteamUser()->GetGameBadgeLevel(series, foil);
}

/////////////////////////////////////////////////
///// UTILS /////////////////////////////////////
/////////////////////////////////////////////////
//
// Checks if the Overlay needs a present. Only required if using event driven render updates.
SW_PY bool OverlayNeedsPresent(){
if(SteamUtils() == NULL){
return false;
}
return SteamUtils()->BOverlayNeedsPresent();
}
// Get the Steam ID of the running application/game.
SW_PY int GetAppID(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetAppID();
}
// Get the amount of battery power, clearly for laptops.
SW_PY int GetCurrentBatteryPower(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetCurrentBatteryPower();
}
// Returns the number of IPC calls made since the last time this function was called.
SW_PY uint32 GetIPCCallCount(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetIPCCallCount();
}
// Get the user's country by IP.
SW_PY const char* GetIPCountry(){
if(SteamUtils() == NULL){
return "";
}
return SteamUtils()->GetIPCountry();
}
// Return amount of time, in seconds, user has spent in this session.
SW_PY int GetSecondsSinceAppActive(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetSecondsSinceAppActive();
}
// Returns the number of seconds since the user last moved the mouse.
SW_PY int GetSecondsSinceComputerActive(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetSecondsSinceComputerActive();
}
// Get the actual time.
SW_PY int GetServerRealTime(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->GetServerRealTime();
}
// Get the Steam user interface language.
SW_PY const char* GetSteamUILanguage(){
if(SteamUtils() == NULL){
return "";
}
return SteamUtils()->GetSteamUILanguage();
}
// Returns true/false if Steam overlay is enabled.
SW_PY bool IsOverlayEnabled(){
if(SteamUtils() == NULL){
return false;
}
return SteamUtils()->IsOverlayEnabled();
}
// Returns true if Steam & the Steam Overlay are running in Big Picture mode.
SW_PY bool IsSteamInBigPictureMode(){
if(SteamUtils() == NULL){
return false;
}
return SteamUtils()->IsSteamInBigPictureMode();
}
// Is Steam running in VR?
SW_PY bool IsSteamRunningInVR(){
if(SteamUtils() == NULL){
return 0;
}
return SteamUtils()->IsSteamRunningInVR();
}
// Checks if the HMD view will be streamed via Steam In-Home Streaming.
SW_PY bool IsVRHeadsetStreamingEnabled(){
if(SteamUtils() == NULL){
return false;
}
return SteamUtils()->IsVRHeadsetStreamingEnabled();
}
// Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
SW_PY void SetOverlayNotificationInset(int horizontal, int vertical){
if(SteamUtils() == NULL){
return;
}
SteamUtils()->SetOverlayNotificationInset(horizontal, vertical);
}
// Set the position where overlay shows notifications.
SW_PY void SetOverlayNotificationPosition(int pos){
if((pos < 0) || (pos > 3) || (SteamUtils() == NULL)){
return;
}
SteamUtils()->SetOverlayNotificationPosition(ENotificationPosition(pos));
}
// Set whether the HMD content will be streamed via Steam In-Home Streaming.
SW_PY void SetVRHeadsetStreamingEnabled(bool enabled){
if(SteamUtils() == NULL){
return;
}
SteamUtils()->SetVRHeadsetStreamingEnabled(enabled);
}
// Activates the Big Picture text input dialog which only supports gamepad input.
SW_PY bool ShowGamepadTextInput(int inputMode, int lineInputMode, const char* description, uint32 maxText, const char* presetText){
if(SteamUtils() == NULL){
return false;
}
// Convert modes
EGamepadTextInputMode mode;
if(inputMode == 0){
mode = k_EGamepadTextInputModeNormal;
}
else{
mode = k_EGamepadTextInputModePassword;
}
EGamepadTextInputLineMode lineMode;
if(lineInputMode == 0){
lineMode = k_EGamepadTextInputLineModeSingleLine;
}
else{
lineMode = k_EGamepadTextInputLineModeMultipleLines;
}
return SteamUtils()->ShowGamepadTextInput(mode, lineMode, description, maxText, presetText);
}
// Ask SteamUI to create and render its OpenVR dashboard.
SW_PY void StartVRDashboard(){
if(SteamUtils() == NULL){
return;
}
SteamUtils()->StartVRDashboard();
}
144 changes: 143 additions & 1 deletion steamworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ def Init():
Steam.cdll.GetPlayerSteamLevel.restype = int
Steam.cdll.GetUserDataFolder.restype = c_char_p
Steam.cdll.GetGameBadgeLevel.restype = int
# Set restype for Utils functions
Steam.cdll.OverlayNeedsPresent.restype = bool
Steam.cdll.GetAppID.restype = int
Steam.cdll.GetCurrentBatteryPower.restype = int
Steam.cdll.GetIPCCallCount.restype = c_uint32
Steam.cdll.GetIPCountry.restype = c_char_p
Steam.cdll.GetSecondsSinceAppActive.restype = int
Steam.cdll.GetSecondsSinceComputerActive.restype = int
Steam.cdll.GetServerRealTime.restype = int
Steam.cdll.GetSteamUILanguage.restype = c_char_p
Steam.cdll.IsOverlayEnabled.restype = bool
Steam.cdll.IsSteamInBigPictureMode.restype = bool
Steam.cdll.IsSteamRunningInVR.restype = bool
Steam.cdll.IsVRHeadsetStreamingEnabled.restype = bool
Steam.cdll.SetOverlayNotificationInset.restype = None
Steam.cdll.SetOverlayNotificationPosition.restype = None
Steam.cdll.SetVRHeadsetStreamingEnabled.restype = None
Steam.cdll.ShowGamepadTextInput.restype = bool
Steam.cdll.StartVRDashboard.restype = None

# Is Steam loaded
@staticmethod
Expand Down Expand Up @@ -430,4 +449,127 @@ def GetGameBadgeLevel(series, foil):
if Steam.IsSteamLoaded():
return Steam.cdll.GetGameBadgeLevel(series, foil)
else:
return 0
return 0
#------------------------------------------------
# Class for Steam Utils
#------------------------------------------------
class SteamUtils:
# Checks if the Overlay needs a present. Only required if using event driven render updates.
@staticmethod
def OverlayNeedsPresent():
if Steam.IsSteamLoaded():
return Steam.cdll.OverlayNeedsPresent()
else:
return False
# Get the Steam ID of the running application/game.
@staticmethod
def GetAppID():
if Steam.IsSteamLoaded():
return Steam.cdll.GetAppID()
else:
return 0
# Get the amount of battery power, clearly for laptops.
@staticmethod
def GetCurrentBatteryPower():
if Steam.IsSteamLoaded():
return Steam.cdll.GetCurrentBatteryPower()
else:
return 0
# Returns the number of IPC calls made since the last time this function was called.
@staticmethod
def GetIPCCallCount():
if Steam.IsSteamLoaded():
return Steam.cdll.GetIPCCallCount()
else:
return 0
# Get the user's country by IP.
@staticmethod
def GetIPCountry():
if Steam.IsSteamLoaded():
return Steam.cdll.GetIPCountry()
else:
return ""
# Return amount of time, in seconds, user has spent in this session.
@staticmethod
def GetSecondsSinceAppActive():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSecondsSinceAppActive()
else:
return 0
# Returns the number of seconds since the user last moved the mouse.
@staticmethod
def GetSecondsSinceComputerActive():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSecondsSinceComputerActive()
else:
return 0
# Get the actual time.
@staticmethod
def GetServerRealTime():
if Steam.IsSteamLoaded():
return Steam.cdll.GetServerRealTime()
else:
return 0
# Get the Steam user interface language.
@staticmethod
def GetSteamUILanguage():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSteamUILanguage()
else:
return ""
# Returns true/false if Steam overlay is enabled.
@staticmethod
def IsOverlayEnabled():
if Steam.IsSteamLoaded():
return Steam.cdll.IsOverlayEnabled()
else:
return False
# Returns true if Steam & the Steam Overlay are running in Big Picture mode.
@staticmethod
def IsSteamInBigPictureMode():
if Steam.IsSteamLoaded():
return Steam.cdll.IsSteamInBigPictureMode()
else:
return False
# Is Steam running in VR?
@staticmethod
def IsVRHeadsetStreamingEnabled():
if Steam.IsSteamLoaded():
return Steam.cdll.IsVRHeadsetStreamingEnabled()
else:
return False
# Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
@staticmethod
def SetOverlayNotificationInset(horizontal, vertical):
if Steam.IsSteamLoaded():
return Steam.cdll.SetOverlayNotificationInset(horizontal, vertical)
else:
return
# Set the position where overlay shows notifications.
@staticmethod
def SetOverlayNotificationPosition(pos):
if Steam.IsSteamLoaded():
return Steam.cdll.SetOverlayNotificationPosition(pos)
else:
return
# Set whether the HMD content will be streamed via Steam In-Home Streaming.
@staticmethod
def SetVRHeadsetStreamingEnabled(enabled):
if Steam.IsSteamLoaded():
return Steam.cdll.SetVRHeadsetStreamingEnabled(enabled)
else:
return
# Activates the Big Picture text input dialog which only supports gamepad input.
@staticmethod
def ShowGamepadTextInput(inputMode, lineInputMode, description, maxText, presetText):
if Steam.IsSteamLoaded():
return Steam.cdll.ShowGamepadTextInput()
else:
return False
# Ask SteamUI to create and render its OpenVR dashboard.
@staticmethod
def StartVRDashboard():
if Steam.IsSteamLoaded():
return Steam.cdll.StartVRDashboard()
else:
return

0 comments on commit a8920f1

Please sign in to comment.