*** empty log message ***
This commit is contained in:
parent
3c20818f8d
commit
2d5494ee4c
|
|
@ -28,8 +28,8 @@ class DirectButton(DirectFrame):
|
|||
# Which mouse buttons can be used to click the button
|
||||
('commandButtons', (LMB,), self.setCommandButtons),
|
||||
# Sounds to be used for button events
|
||||
('rolloverSound', None, None),
|
||||
('clickSound', None, None),
|
||||
('rolloverSound', None, self.setRolloverSound),
|
||||
('clickSound', None, self.setClickSound),
|
||||
# Can only be specified at time of widget contruction
|
||||
# Do the text/graphics appear to move when the button is clicked
|
||||
('pressEffect', 1, INITOPT),
|
||||
|
|
@ -79,3 +79,27 @@ class DirectButton(DirectFrame):
|
|||
# Pass any extra args to command
|
||||
apply(self['command'], self['extraArgs'])
|
||||
|
||||
def setClickSound(self):
|
||||
if base.wantSfx:
|
||||
clickSound = self['clickSound']
|
||||
# Clear out sounds
|
||||
self.guiItem.clearSound(B1PRESS + self.guiId)
|
||||
self.guiItem.clearSound(B2PRESS + self.guiId)
|
||||
self.guiItem.clearSound(B3PRESS + self.guiId)
|
||||
if clickSound:
|
||||
if LMB in self['commandButtons']:
|
||||
self.guiItem.setSound(B1PRESS + self.guiId, clickSound)
|
||||
if MMB in self['commandButtons']:
|
||||
self.guiItem.setSound(B2PRESS + self.guiId, clickSound)
|
||||
if RMB in self['commandButtons']:
|
||||
self.guiItem.setSound(B3PRESS + self.guiId, clickSound)
|
||||
|
||||
def setRolloverSound(self):
|
||||
if base.wantSfx:
|
||||
rolloverSound = self['rolloverSound']
|
||||
if rolloverSound:
|
||||
self.guiItem.setSound(ENTER + self.guiId, rolloverSound)
|
||||
else:
|
||||
self.guiItem.clearSound(ENTER + self.guiId)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -664,6 +664,8 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
('frameSize', None, self.setFrameSize),
|
||||
('frameColor', (.8,.8,.8,1), self.setFrameColor),
|
||||
('pad', (.25,.15), self.resetFrameSize),
|
||||
# Override button id (beware! your name may not be unique!)
|
||||
('guiId', None, INITOPT),
|
||||
# Initial pos/scale of the widget
|
||||
('pos', None, INITOPT),
|
||||
('scale', None, INITOPT),
|
||||
|
|
@ -676,6 +678,9 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
|||
NodePath.__init__(self)
|
||||
# Create a button
|
||||
self.guiItem = self['pgFunc']()
|
||||
# Override automatically generated guiId
|
||||
if self['guiId']:
|
||||
self.guiItem.setId(self['guiId'])
|
||||
self.guiId = self.guiItem.getId()
|
||||
# Attach button to parent and make that self
|
||||
self.assign(parent.attachNewNode( self.guiItem ) )
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from DirectGui import *
|
||||
from whrandom import *
|
||||
from GuiGlobals import getDefaultClickSound
|
||||
from GuiGlobals import getDefaultRolloverSound
|
||||
|
||||
# EXAMPLE CODE
|
||||
# Load a model
|
||||
|
|
@ -48,6 +50,7 @@ dl.setScale(.5)
|
|||
# Create a button with a background image, smiley as a geometry element,
|
||||
# and a text overlay, set a different text for the four button states:
|
||||
# (normal, press, rollover, and disabled), set scale = .15, and relief raised
|
||||
dbArray = []
|
||||
for i in range(10):
|
||||
db = DirectButton(parent = dl,
|
||||
image = 'phase_4/maps/middayskyB.jpg',
|
||||
|
|
@ -57,7 +60,11 @@ for i in range(10):
|
|||
# Here we set an option for a component of the button
|
||||
geom1_color = Vec4(1,0,0,1),
|
||||
# Here is an example of a component group option
|
||||
text_pos = (.6, -.8))
|
||||
text_pos = (.6, -.8),
|
||||
# Set audio characteristics
|
||||
clickSound = getDefaultClickSound(),
|
||||
rolloverSound = getDefaultRolloverSound()
|
||||
)
|
||||
|
||||
# You can set component or component group options after a gui item
|
||||
# has been created
|
||||
|
|
@ -70,6 +77,8 @@ for i in range(10):
|
|||
db.bind(B1PRESS, lambda x, db = db: ouch(db))
|
||||
# Pop up placer when button 2 is pressed
|
||||
db.bind(B3PRESS, lambda x, db = db: db.place())
|
||||
|
||||
dbArray.append(db)
|
||||
|
||||
# To get rid of button and clear out hooks call:
|
||||
# db.destroy()
|
||||
|
|
|
|||
Loading…
Reference in New Issue