directgui: Add default release sounds for buttons

This commit is contained in:
DTM1218 2025-07-11 23:47:03 -07:00 committed by rdb
parent 429af9ae57
commit 062e3365fd
3 changed files with 31 additions and 7 deletions

View File

@ -44,6 +44,7 @@ class DirectButton(DirectFrame):
# Sounds to be used for button events
('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
('releaseSound', DGG.getDefaultReleaseSound(), self.setReleaseSound),
# Can only be specified at time of widget contruction
# Do the text/graphics appear to move when the button is clicked
('pressEffect', 1, DGG.INITOPT),
@ -108,6 +109,13 @@ class DirectButton(DirectFrame):
# Pass any extra args to command
self['command'](*self['extraArgs'])
def setRolloverSound(self):
rolloverSound = self['rolloverSound']
if rolloverSound:
self.guiItem.setSound(DGG.ENTER + self.guiId, rolloverSound)
else:
self.guiItem.clearSound(DGG.ENTER + self.guiId)
def setClickSound(self):
clickSound = self['clickSound']
# Clear out sounds
@ -122,9 +130,16 @@ class DirectButton(DirectFrame):
if DGG.RMB in self['commandButtons']:
self.guiItem.setSound(DGG.B3PRESS + self.guiId, clickSound)
def setRolloverSound(self):
rolloverSound = self['rolloverSound']
if rolloverSound:
self.guiItem.setSound(DGG.ENTER + self.guiId, rolloverSound)
else:
self.guiItem.clearSound(DGG.ENTER + self.guiId)
def setReleaseSound(self):
releaseSound = self['releaseSound']
# Clear out sounds
self.guiItem.clearSound(DGG.B1RELEASE + self.guiId)
self.guiItem.clearSound(DGG.B2RELEASE + self.guiId)
self.guiItem.clearSound(DGG.B3RELEASE + self.guiId)
if releaseSound:
if DGG.LMB in self['commandButtons']:
self.guiItem.setSound(DGG.B1RELEASE + self.guiId, releaseSound)
if DGG.MMB in self['commandButtons']:
self.guiItem.setSound(DGG.B2RELEASE + self.guiId, releaseSound)
if DGG.RMB in self['commandButtons']:
self.guiItem.setSound(DGG.B3RELEASE + self.guiId, releaseSound)

View File

@ -28,6 +28,7 @@ class DirectCheckBox(DirectButton):
# Sounds to be used for button events
('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
('releaseSound', DGG.getDefaultReleaseSound(), self.setReleaseSound),
# Can only be specified at time of widget contruction
# Do the text/graphics appear to move when the button is clicked
('pressEffect', 1, DGG.INITOPT),

View File

@ -17,8 +17,9 @@ from panda3d.core import (
defaultFont = None
defaultFontFunc = TextNode.getDefaultFont
defaultClickSound = None
defaultRolloverSound = None
defaultClickSound = None
defaultReleaseSound = None
defaultDialogGeom = None
defaultDialogRelief = PGFrameStyle.TBevelOut
drawOrder = 100
@ -129,6 +130,13 @@ def setDefaultClickSound(newSound):
global defaultClickSound
defaultClickSound = newSound
def getDefaultReleaseSound():
return defaultReleaseSound
def setDefaultReleaseSound(newSound):
global defaultReleaseSound
defaultReleaseSound = newSound
def getDefaultFont():
global defaultFont
if defaultFont is None: