How to specify soundfiles for buttons on dialogs??

Hi,

I need to define a soundfile to be played when clicking (and mouse-overing) a button of a custom DirectDialog.

Everywhere else in the game I can define soundfiles for a DirectButton object using the keywords when creating objects:

rolloverSound = loader.loadSfx("audio/rollover.wav")
clickSound = loader.loadSfx("audio/click.wav")

Is there a similar way to define sounds for buttons on dialogs?

I am creating dialogs like this:

dialog = DirectDialog(dialogName="CustomDialog",
                        buttonTextList = ("End Turn", "Cancel"), 
                        buttonValueList = (1,0),
                        text="End your turn?", 
                        command=itemSel)

/srehder

https://www.panda3d.org/manual/index.php/DirectButton
there are keywords for roll-over and click sounds. those need to be sound-instances if i read it right.
so you can set them just like you would do text= or command=

yea thanks, I know the keywords for the DirectButton already though but my problem is that the buttons on DirectDialog are not specified the same way as a normal DirectButton.

So I dont know where to specify the keywords for the buttons on the DirectDialog since it is just created using this snip of code:

dialog = DirectDialog(dialogName="CustomDialog", 
                        buttonTextList = ("End Turn", "Cancel"), 
                        buttonValueList = (1,0), 
                        text="End your turn?", 
                        command=itemSel) 

oh. sory didnt read that it was direct dialog.
you could try

yourDirectWidget.bind(DGG.ENTER, yourFunction) 

where you can use yourfunction to play the sound
i think simmilar things for leaving the widget was postet on the forum recently.

I think that would work but there is a small problem.

When there is no sound specified to a button Panda3d is getting a default sound… So if I use your method I will hear 2 sounds when clicking a button on the DirectDialog (The default sound and the sound specified in yourFunction)

ThomasEgi: That sounds like the hacky solution.
IMHO, this would be a better solution: (after you created the dialog)

for button in dialog.buttonList:
  button["rolloverSound"] = loader.loadSfx("audio/rollover.wav") 

For the record, it’s also possible to set the default sound:

DGG.setDefaultRolloverSound(None)
DGG.setDefaultClickSound(yoursound)

Thanks a lot for the help :slight_smile:

It works!

Here’s a sneaky DirectGui trick. You can do this:

dialog = DirectDialog(dialogName="CustomDialog",
                        buttonTextList = ("End Turn", "Cancel"),
                        buttonValueList = (1,0),
                        text="End your turn?",
                        command=itemSel,
                        button0_rolloverSound = blahblahblah,
                        button0_clickSound = blahblahblah,
                        button1_rolloverSound = blahblahblah,
                        button1_clickSound = blahblahblah)

In general, you can do this sort of thing to pass attributes in to sub-components: you assign the attribute componentN_attribute. This works for other kinds of DirectGui elements too:

b = DirectButton(text = ('click me?', 'clicked', 'rollover', 'disabled'),
                 text0_fg = (1, 0, 0, 1),
                 text1_fg = (0, 1, 0, 1),
                 text2_fg = (0, 0, 1, 1),
                 text3_fg = (0, 0, 0, 1),
                 scale = 0.1,
                 )

David