Is there a simple way to create what is in effect a modal dialog?
There are pts in my game where the user has the option to stop/pause and select an option from a frame I will put up.
I just want to prevent the possibility of the user clicking something outside the frame which should not be allowed.
Never tried that in Panda, but in HTML you usually make a 100% x 100% big half-transparent plane.
This should work in Panda as well. Make a big plane, put it in front of all other GUI elements and place your modal dialog in front of that veil.
drwr
4
Note that DirectDialog (and its related classes OkDialog and so on) does this by default if you specify fadeScreen = True to the constructor.
David
Trying out fadeScreen, but I can still click the button behind the dialog . Am I not using it correctly?
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
def click():
print "clicked"
dialog = DirectDialog(fadeScreen=True)
b = DirectButton(text = ("OK", "click!", "rolling over", "disabled"), frameSize=(-.5,.5,-.5,.5), scale=.1, command=click)
run()
drwr
6
You need to call dialog.show() to activate it. And you probably want to have some text and/or buttons on your dialog:
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
def click():
print "clicked"
dialog = OkDialog(fadeScreen=True, text = 'this dialog')
dialog.show()
b = DirectButton(text = ("OK", "click!", "rolling over", "disabled"), frameSize=(-.5,.5,-.5,.5), scale=.1, command=click)
run()
Thanks!
.show() was what I was missing.
It seems to make everything behind the dialog black, though, can I control this, i.e. make it grayed-out rather than completely dark?
drwr
8
Oh, my mistake. Instead of specifying fadeScreen = True, you should specify fadeScreen = 0.5, or whatever level of black you want it to have.
David