Skip to content

Commit

Permalink
Added missing Utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gramps committed Oct 28, 2019
1 parent 0287265 commit b5eefb3
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 50 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a fuller (yet outdated) tutorial, with images, on SteamworksPy please read o
There is now an experimental branch for converting the project to match my [Godot Engine module](https://github.com/Gramps/GodotSteam) in functionality and fix some problems with the original. Once completed, it will move to the master branch.

# Latest Updates
- Added: missing Utils functions
- Removed: docs folder as docs are now their own branch

# Some Notes
Expand Down
117 changes: 101 additions & 16 deletions SteamworksPy.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//===============================================
// STEAMWORKS FOR PYTHON
//===============================================
//-----------------------------------------------
/////////////////////////////////////////////////
// STEAMWORKSPY - STEAMWORKS FOR PYTHON
/////////////////////////////////////////////////
//
// Modify SW_PY based on operating system and include the proper Steamworks API file
//-----------------------------------------------
//
// Include the Steamworks API header
#if defined( _WIN32 )
#include "steam\steam_api.h"
#define SW_PY extern "C" __declspec(dllexport)
Expand All @@ -17,6 +18,9 @@
#else
#error "Unsupported platform"
#endif

#include <iostream>

//-----------------------------------------------
// Definitions
//-----------------------------------------------
Expand Down Expand Up @@ -546,15 +550,40 @@ SW_PY bool StoreStats(){
//SW_PY void UpdateLeaderboardHandle()
//SW_PY uint64 GetLeaderboardHandle()
//SW_PY void GetLeaderBoardEntries()
//-----------------------------------------------
// Steam Utilities
//-----------------------------------------------
SW_PY uint8 GetCurrentBatteryPower(){

////////////////////////////////////////////////
///// 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 "None";
Expand All @@ -579,36 +608,92 @@ SW_PY uint32 GetServerRealTime(){
}
return SteamUtils()->GetServerRealTime();
}
// Get the Steam user interface language.
SW_PY const char* GetSteamUILanguage(){
if(SteamUtils() == NULL){
return "None";
}
return SteamUtils()->GetSteamUILanguage();
}
// Returns true/false if Steam overlay is enabled.
SW_PY bool IsOverlayEnabled(){
if(SteamUtils() == NULL){
return false;
}
return SteamUtils()->IsOverlayEnabled();
}
SW_PY bool IsSteamRunningInVR(){
// 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();
}
SW_PY const char* GetSteamUILanguage(){
// Checks if the HMD view will be streamed via Steam In-Home Streaming.
SW_PY bool IsVRHeadsetStreamingEnabled(){
if(SteamUtils() == NULL){
return "None";
return false;
}
return SteamUtils()->GetSteamUILanguage();
return SteamUtils()->IsVRHeadsetStreamingEnabled();
}
SW_PY uint32 GetAppID(){
// 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 0;
return;
}
return SteamUtils()->GetAppID();
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();
}

//-----------------------------------------------
// Steam Workshop
//-----------------------------------------------
Expand Down
125 changes: 91 additions & 34 deletions steamworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,25 @@ def Init():
# Steam.cdll.UpdateLeaderboardHandle.restype = None
# Steam.cdll.GetLeadboardHandle.restype = c_uint64
# Steam.cdll.GetLeaderboardEntries.restype = None
# Set restype for Utilities functions
# 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.GetSteamUILanguage.restype = c_char_p
Steam.cdll.GetAppID.restype = int
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
# Set argtypes and restype for Workshop functions
Steam.cdll.Workshop_StartItemUpdate.restype = c_uint64
Steam.cdll.Workshop_SetItemTitle.restype = bool
Expand Down Expand Up @@ -618,79 +626,128 @@ def FindLeaderboard(name, callback = None):
else:
return False
#------------------------------------------------
# Class for Steam Utilities
# Class for Steam Utils
#------------------------------------------------
class SteamUtilities:
# Get the amount of battery power, clearly for laptops
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():
if Steam.IsSteamLoaded():
return Steam.cdll.GetCurrentBatteryPower()
else:
return 0
# Get the user's country by IP
# 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():
if Steam.IsSteamLoaded():
return Steam.cdll.GetIPCountry()
else:
return "None"
# Returns seconds since application/game was started
return ""
# Return amount of time, in seconds, user has spent in this session.
@staticmethod
def GetSecondsSinceAppActive():
if Steam.isSteamLoaded():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSecondsSinceAppActive()
else:
return 0
# Return seconds since computer was started
# Returns the number of seconds since the user last moved the mouse.
@staticmethod
def GetSecondsSinceComputerActive():
if Steam.isSteamLoaded():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSecondsSinceComputerActive()
else:
return 0
# Get the actual time
# Get the actual time.
@staticmethod
def GetServerRealTime():
if Steam.isSteamLoaded():
if Steam.IsSteamLoaded():
return Steam.cdll.GetServerRealTime()
else:
return 0
# Returns true/false if Steam overlay is enabled
# 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():
if Steam.IsSteamLoaded():
return Steam.cdll.IsOverlayEnabled()
else:
return False
# Is Steam running in VR?
# Returns true if Steam & the Steam Overlay are running in Big Picture mode.
@staticmethod
def IsSteamRunningInVR():
if Steam.isSteamLoaded():
return Steam.cdll.IsSteamRunningInVR()
def IsSteamInBigPictureMode():
if Steam.IsSteamLoaded():
return Steam.cdll.IsSteamInBigPictureMode()
else:
return False
# Get the Steam user interface language
# Is Steam running in VR?
@staticmethod
def GetSteamUILanguage():
if Steam.isSteamLoaded():
return Steam.cdll.GetSteamUILanguage()
def IsVRHeadsetStreamingEnabled():
if Steam.IsSteamLoaded():
return Steam.cdll.IsVRHeadsetStreamingEnabled()
else:
return "None"
# Get the Steam ID of the running application/game
return False
# Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
@staticmethod
def GetAppID():
if Steam.isSteamLoaded():
return Steam.cdll.GetAppID()
def SetOverlayNotificationInset(horizontal, vertical):
if Steam.IsSteamLoaded():
return Steam.cdll.SetOverlayNotificationInset(horizontal, vertical)
else:
return 0
# Set the position where overlay shows notifications
return
# Set the position where overlay shows notifications.
@staticmethod
def SetOverlayNotificationPosition(pos):
if Steam.isSteamLoaded():
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
#------------------------------------------------
# Class for Steam Workshop
#------------------------------------------------
Expand Down

0 comments on commit b5eefb3

Please sign in to comment.