Skip to content

Commit b5eefb3

Browse files
committed
Added missing Utils functions
1 parent 0287265 commit b5eefb3

File tree

3 files changed

+193
-50
lines changed

3 files changed

+193
-50
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For a fuller (yet outdated) tutorial, with images, on SteamworksPy please read o
1212
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.
1313

1414
# Latest Updates
15+
- Added: missing Utils functions
1516
- Removed: docs folder as docs are now their own branch
1617

1718
# Some Notes

SteamworksPy.cpp

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//===============================================
2-
// STEAMWORKS FOR PYTHON
3-
//===============================================
4-
//-----------------------------------------------
1+
/////////////////////////////////////////////////
2+
// STEAMWORKSPY - STEAMWORKS FOR PYTHON
3+
/////////////////////////////////////////////////
4+
//
55
// Modify SW_PY based on operating system and include the proper Steamworks API file
6-
//-----------------------------------------------
6+
//
7+
// Include the Steamworks API header
78
#if defined( _WIN32 )
89
#include "steam\steam_api.h"
910
#define SW_PY extern "C" __declspec(dllexport)
@@ -17,6 +18,9 @@
1718
#else
1819
#error "Unsupported platform"
1920
#endif
21+
22+
#include <iostream>
23+
2024
//-----------------------------------------------
2125
// Definitions
2226
//-----------------------------------------------
@@ -546,15 +550,40 @@ SW_PY bool StoreStats(){
546550
//SW_PY void UpdateLeaderboardHandle()
547551
//SW_PY uint64 GetLeaderboardHandle()
548552
//SW_PY void GetLeaderBoardEntries()
549-
//-----------------------------------------------
550-
// Steam Utilities
551-
//-----------------------------------------------
552-
SW_PY uint8 GetCurrentBatteryPower(){
553+
554+
////////////////////////////////////////////////
555+
///// UTILS /////////////////////////////////////
556+
/////////////////////////////////////////////////
557+
//
558+
// Checks if the Overlay needs a present. Only required if using event driven render updates.
559+
SW_PY bool OverlayNeedsPresent(){
560+
if(SteamUtils() == NULL){
561+
return false;
562+
}
563+
return SteamUtils()->BOverlayNeedsPresent();
564+
}
565+
// Get the Steam ID of the running application/game.
566+
SW_PY int GetAppID(){
567+
if(SteamUtils() == NULL){
568+
return 0;
569+
}
570+
return SteamUtils()->GetAppID();
571+
}
572+
// Get the amount of battery power, clearly for laptops.
573+
SW_PY int GetCurrentBatteryPower(){
553574
if(SteamUtils() == NULL){
554575
return 0;
555576
}
556577
return SteamUtils()->GetCurrentBatteryPower();
557578
}
579+
// Returns the number of IPC calls made since the last time this function was called.
580+
SW_PY uint32 GetIPCCallCount(){
581+
if(SteamUtils() == NULL){
582+
return 0;
583+
}
584+
return SteamUtils()->GetIPCCallCount();
585+
}
586+
// Get the user's country by IP.
558587
SW_PY const char* GetIPCountry(){
559588
if(SteamUtils() == NULL){
560589
return "None";
@@ -579,36 +608,92 @@ SW_PY uint32 GetServerRealTime(){
579608
}
580609
return SteamUtils()->GetServerRealTime();
581610
}
611+
// Get the Steam user interface language.
612+
SW_PY const char* GetSteamUILanguage(){
613+
if(SteamUtils() == NULL){
614+
return "None";
615+
}
616+
return SteamUtils()->GetSteamUILanguage();
617+
}
618+
// Returns true/false if Steam overlay is enabled.
582619
SW_PY bool IsOverlayEnabled(){
583620
if(SteamUtils() == NULL){
584621
return false;
585622
}
586623
return SteamUtils()->IsOverlayEnabled();
587624
}
588-
SW_PY bool IsSteamRunningInVR(){
625+
// Returns true if Steam & the Steam Overlay are running in Big Picture mode.
626+
SW_PY bool IsSteamInBigPictureMode(){
589627
if(SteamUtils() == NULL){
590628
return false;
591629
}
630+
return SteamUtils()->IsSteamInBigPictureMode();
631+
}
632+
// Is Steam running in VR?
633+
SW_PY bool IsSteamRunningInVR(){
634+
if(SteamUtils() == NULL){
635+
return 0;
636+
}
592637
return SteamUtils()->IsSteamRunningInVR();
593638
}
594-
SW_PY const char* GetSteamUILanguage(){
639+
// Checks if the HMD view will be streamed via Steam In-Home Streaming.
640+
SW_PY bool IsVRHeadsetStreamingEnabled(){
595641
if(SteamUtils() == NULL){
596-
return "None";
642+
return false;
597643
}
598-
return SteamUtils()->GetSteamUILanguage();
644+
return SteamUtils()->IsVRHeadsetStreamingEnabled();
599645
}
600-
SW_PY uint32 GetAppID(){
646+
// Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
647+
SW_PY void SetOverlayNotificationInset(int horizontal, int vertical){
601648
if(SteamUtils() == NULL){
602-
return 0;
649+
return;
603650
}
604-
return SteamUtils()->GetAppID();
651+
SteamUtils()->SetOverlayNotificationInset(horizontal, vertical);
605652
}
653+
// Set the position where overlay shows notifications.
606654
SW_PY void SetOverlayNotificationPosition(int pos){
607655
if((pos < 0) || (pos > 3) || (SteamUtils() == NULL)){
608656
return;
609657
}
610658
SteamUtils()->SetOverlayNotificationPosition(ENotificationPosition(pos));
611659
}
660+
// Set whether the HMD content will be streamed via Steam In-Home Streaming.
661+
SW_PY void SetVRHeadsetStreamingEnabled(bool enabled){
662+
if(SteamUtils() == NULL){
663+
return;
664+
}
665+
SteamUtils()->SetVRHeadsetStreamingEnabled(enabled);
666+
}
667+
// Activates the Big Picture text input dialog which only supports gamepad input.
668+
SW_PY bool ShowGamepadTextInput(int inputMode, int lineInputMode, const char* description, uint32 maxText, const char* presetText){
669+
if(SteamUtils() == NULL){
670+
return false;
671+
}
672+
// Convert modes
673+
EGamepadTextInputMode mode;
674+
if(inputMode == 0){
675+
mode = k_EGamepadTextInputModeNormal;
676+
}
677+
else{
678+
mode = k_EGamepadTextInputModePassword;
679+
}
680+
EGamepadTextInputLineMode lineMode;
681+
if(lineInputMode == 0){
682+
lineMode = k_EGamepadTextInputLineModeSingleLine;
683+
}
684+
else{
685+
lineMode = k_EGamepadTextInputLineModeMultipleLines;
686+
}
687+
return SteamUtils()->ShowGamepadTextInput(mode, lineMode, description, maxText, presetText);
688+
}
689+
// Ask SteamUI to create and render its OpenVR dashboard.
690+
SW_PY void StartVRDashboard(){
691+
if(SteamUtils() == NULL){
692+
return;
693+
}
694+
SteamUtils()->StartVRDashboard();
695+
}
696+
612697
//-----------------------------------------------
613698
// Steam Workshop
614699
//-----------------------------------------------

steamworks.py

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,25 @@ def Init():
178178
# Steam.cdll.UpdateLeaderboardHandle.restype = None
179179
# Steam.cdll.GetLeadboardHandle.restype = c_uint64
180180
# Steam.cdll.GetLeaderboardEntries.restype = None
181-
# Set restype for Utilities functions
181+
# Set restype for Utils functions
182+
Steam.cdll.OverlayNeedsPresent.restype = bool
183+
Steam.cdll.GetAppID.restype = int
182184
Steam.cdll.GetCurrentBatteryPower.restype = int
185+
Steam.cdll.GetIPCCallCount.restype = c_uint32
183186
Steam.cdll.GetIPCountry.restype = c_char_p
184187
Steam.cdll.GetSecondsSinceAppActive.restype = int
185188
Steam.cdll.GetSecondsSinceComputerActive.restype = int
186189
Steam.cdll.GetServerRealTime.restype = int
190+
Steam.cdll.GetSteamUILanguage.restype = c_char_p
187191
Steam.cdll.IsOverlayEnabled.restype = bool
192+
Steam.cdll.IsSteamInBigPictureMode.restype = bool
188193
Steam.cdll.IsSteamRunningInVR.restype = bool
189-
Steam.cdll.GetSteamUILanguage.restype = c_char_p
190-
Steam.cdll.GetAppID.restype = int
194+
Steam.cdll.IsVRHeadsetStreamingEnabled.restype = bool
195+
Steam.cdll.SetOverlayNotificationInset.restype = None
191196
Steam.cdll.SetOverlayNotificationPosition.restype = None
197+
Steam.cdll.SetVRHeadsetStreamingEnabled.restype = None
198+
Steam.cdll.ShowGamepadTextInput.restype = bool
199+
Steam.cdll.StartVRDashboard.restype = None
192200
# Set argtypes and restype for Workshop functions
193201
Steam.cdll.Workshop_StartItemUpdate.restype = c_uint64
194202
Steam.cdll.Workshop_SetItemTitle.restype = bool
@@ -618,79 +626,128 @@ def FindLeaderboard(name, callback = None):
618626
else:
619627
return False
620628
#------------------------------------------------
621-
# Class for Steam Utilities
629+
# Class for Steam Utils
622630
#------------------------------------------------
623-
class SteamUtilities:
624-
# Get the amount of battery power, clearly for laptops
631+
class SteamUtils:
632+
# Checks if the Overlay needs a present. Only required if using event driven render updates.
633+
@staticmethod
634+
def OverlayNeedsPresent():
635+
if Steam.IsSteamLoaded():
636+
return Steam.cdll.OverlayNeedsPresent()
637+
else:
638+
return False
639+
# Get the Steam ID of the running application/game.
640+
@staticmethod
641+
def GetAppID():
642+
if Steam.IsSteamLoaded():
643+
return Steam.cdll.GetAppID()
644+
else:
645+
return 0
646+
# Get the amount of battery power, clearly for laptops.
625647
@staticmethod
626648
def GetCurrentBatteryPower():
627-
if Steam.isSteamLoaded():
649+
if Steam.IsSteamLoaded():
628650
return Steam.cdll.GetCurrentBatteryPower()
629651
else:
630652
return 0
631-
# Get the user's country by IP
653+
# Returns the number of IPC calls made since the last time this function was called.
654+
@staticmethod
655+
def GetIPCCallCount():
656+
if Steam.IsSteamLoaded():
657+
return Steam.cdll.GetIPCCallCount()
658+
else:
659+
return 0
660+
# Get the user's country by IP.
632661
@staticmethod
633662
def GetIPCountry():
634-
if Steam.isSteamLoaded():
663+
if Steam.IsSteamLoaded():
635664
return Steam.cdll.GetIPCountry()
636665
else:
637-
return "None"
638-
# Returns seconds since application/game was started
666+
return ""
667+
# Return amount of time, in seconds, user has spent in this session.
639668
@staticmethod
640669
def GetSecondsSinceAppActive():
641-
if Steam.isSteamLoaded():
670+
if Steam.IsSteamLoaded():
642671
return Steam.cdll.GetSecondsSinceAppActive()
643672
else:
644673
return 0
645-
# Return seconds since computer was started
674+
# Returns the number of seconds since the user last moved the mouse.
646675
@staticmethod
647676
def GetSecondsSinceComputerActive():
648-
if Steam.isSteamLoaded():
677+
if Steam.IsSteamLoaded():
649678
return Steam.cdll.GetSecondsSinceComputerActive()
650679
else:
651680
return 0
652-
# Get the actual time
681+
# Get the actual time.
653682
@staticmethod
654683
def GetServerRealTime():
655-
if Steam.isSteamLoaded():
684+
if Steam.IsSteamLoaded():
656685
return Steam.cdll.GetServerRealTime()
657686
else:
658687
return 0
659-
# Returns true/false if Steam overlay is enabled
688+
# Get the Steam user interface language.
689+
@staticmethod
690+
def GetSteamUILanguage():
691+
if Steam.IsSteamLoaded():
692+
return Steam.cdll.GetSteamUILanguage()
693+
else:
694+
return ""
695+
# Returns true/false if Steam overlay is enabled.
660696
@staticmethod
661697
def IsOverlayEnabled():
662-
if Steam.isSteamLoaded():
698+
if Steam.IsSteamLoaded():
663699
return Steam.cdll.IsOverlayEnabled()
664700
else:
665701
return False
666-
# Is Steam running in VR?
702+
# Returns true if Steam & the Steam Overlay are running in Big Picture mode.
667703
@staticmethod
668-
def IsSteamRunningInVR():
669-
if Steam.isSteamLoaded():
670-
return Steam.cdll.IsSteamRunningInVR()
704+
def IsSteamInBigPictureMode():
705+
if Steam.IsSteamLoaded():
706+
return Steam.cdll.IsSteamInBigPictureMode()
671707
else:
672708
return False
673-
# Get the Steam user interface language
709+
# Is Steam running in VR?
674710
@staticmethod
675-
def GetSteamUILanguage():
676-
if Steam.isSteamLoaded():
677-
return Steam.cdll.GetSteamUILanguage()
711+
def IsVRHeadsetStreamingEnabled():
712+
if Steam.IsSteamLoaded():
713+
return Steam.cdll.IsVRHeadsetStreamingEnabled()
678714
else:
679-
return "None"
680-
# Get the Steam ID of the running application/game
715+
return False
716+
# Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition.
681717
@staticmethod
682-
def GetAppID():
683-
if Steam.isSteamLoaded():
684-
return Steam.cdll.GetAppID()
718+
def SetOverlayNotificationInset(horizontal, vertical):
719+
if Steam.IsSteamLoaded():
720+
return Steam.cdll.SetOverlayNotificationInset(horizontal, vertical)
685721
else:
686-
return 0
687-
# Set the position where overlay shows notifications
722+
return
723+
# Set the position where overlay shows notifications.
688724
@staticmethod
689725
def SetOverlayNotificationPosition(pos):
690-
if Steam.isSteamLoaded():
726+
if Steam.IsSteamLoaded():
691727
return Steam.cdll.SetOverlayNotificationPosition(pos)
728+
else:
729+
return
730+
# Set whether the HMD content will be streamed via Steam In-Home Streaming.
731+
@staticmethod
732+
def SetVRHeadsetStreamingEnabled(enabled):
733+
if Steam.IsSteamLoaded():
734+
return Steam.cdll.SetVRHeadsetStreamingEnabled(enabled)
735+
else:
736+
return
737+
# Activates the Big Picture text input dialog which only supports gamepad input.
738+
@staticmethod
739+
def ShowGamepadTextInput(inputMode, lineInputMode, description, maxText, presetText):
740+
if Steam.IsSteamLoaded():
741+
return Steam.cdll.ShowGamepadTextInput()
692742
else:
693743
return False
744+
# Ask SteamUI to create and render its OpenVR dashboard.
745+
@staticmethod
746+
def StartVRDashboard():
747+
if Steam.IsSteamLoaded():
748+
return Steam.cdll.StartVRDashboard()
749+
else:
750+
return
694751
#------------------------------------------------
695752
# Class for Steam Workshop
696753
#------------------------------------------------

0 commit comments

Comments
 (0)