My idea was to be able to detect the type of control and thus show in pictures the corresponding icons on the menus instead of text.
Of course this code only works if the player already has the controller connected before running the game.
This code uses the pygame module that you are integrating into renpy
pygame joystick doc: https://www.pygame.org/docs/ref/joystick.html
Code: Select all
init python:
import pygame
discon = False
def GamePadType():
global discon
pygame.joystick.quit()
pygame.joystick.init()
joystick_count = pygame.joystick.get_count()
for i in range(joystick_count):
joystick = pygame.joystick.Joystick(i)
joystick.init()
name = joystick.get_name()
GAMEPAD = None
# Words to search for in the string
sony = "PS4"
wirl = "Wireless"
micr = "Microsoft"
xbox = "XBOX"
if sony in name or wirl in name:
# If True then the joystick is PS4
print "PS4"
GAMEPAD = True
elif micr in name or xbox in name:
# If False then the joystick is Xbox
print "XBOX"
GAMEPAD = False
else:
# If the joystick is not a PS4 or Xbox GAMEPAD it is set to None
GAMEPAD = None
if GAMEPAD:
#PS4
return True
elif GAMEPAD == None:
#Here returns error to show a message that the joystick is not a PS4 or XBOX
return "Error"
else:
#XBOX
return False
if not joystick_count:
if not discon:
print "joystick no connected"
discon = True
else:
discon = False
Code: Select all
screen gpad():
modal True
frame:
background Solid("#000")
left_padding 10
right_padding 10
top_padding 10
bottom_padding 10
has vbox
if GamePadType()==True:
text "ps4" color "#fff"
elif GamePadType()=="Error":
text "We do not detect the controller, this controller may not be XBOX or PS4" color "#fff"
elif GamePadType()==False:
text "xbox" color "#fff"
textbutton "Return" action Return()
Code: Select all
label start:
if GamePadType()==True:
e "ps4 controller"
elif GamePadType()=="Error":
e "We do not detect the controller, this controller may not be XBOX or PS4"
elif GamePadType()==False:
e "xbox controller"