Browse Source

*** empty log message ***

gregw 25 years ago
parent
commit
b05779a68b
2 changed files with 172 additions and 23 deletions
  1. 119 0
      direct/src/gui/DialogBox.py
  2. 53 23
      direct/src/gui/OnscreenPanel.py

+ 119 - 0
direct/src/gui/DialogBox.py

@@ -0,0 +1,119 @@
+from DirectObject import *
+from ShowBaseGlobal import *
+from GuiGlobals import *
+
+import string
+import OnscreenText
+import Button
+import StateData
+import OnscreenPanel
+
+# just an OK button
+Acknowledge = 1
+
+# OK and CANCEL buttons
+TwoChoice = 2
+
+class DialogBox(OnscreenPanel.OnscreenPanel):
+
+    def __init__(self, doneEvent, message = "", style = Acknowledge,
+                 font = getDefaultFont(), wordwrap = 12):
+	"""___init___(self, Event, string="", int, model, int=12)"""
+
+        self.doneEvent = doneEvent
+        self.message = message
+        self.style = style
+        self.font = font
+        self.wordwrap = wordwrap
+	self.soundRollover = None
+	self.soundOk = None
+        self.isLoaded = 0
+
+        # initialize our OnscreenPanel essence
+        OnscreenPanel.OnscreenPanel.__init__(self, self.doneEvent)
+         
+	return None
+
+    def show(self):
+	"""show(self)
+	"""
+	if self.isLoaded == 0:
+	    self.load()
+
+        OnscreenPanel.OnscreenPanel.show(self)
+        
+	return None
+
+    def hide(self):
+	"""hide(self)
+	"""
+	if self.isLoaded == 0:
+	    return None
+        
+        OnscreenPanel.OnscreenPanel.hide(self)
+
+	return None
+	
+    def load(self):
+	"""load(self)
+	"""
+	if self.isLoaded == 1:
+	    return None
+
+        # make the panel
+        self.makePanel(rect = (-0.5, 0.5, -0.4, 0.4),
+                       font = self.font,
+                       bg = (0.8, 0.8, 0.8, 1.0))
+        
+	# create a message
+	self.makeText(self.message, wordwrap = self.wordwrap, scale = 0.08,
+                      pos = (0.0, 0.25))
+
+        if (self.style == TwoChoice):
+            # create OK and CANCEL buttons
+            self.makeButton("OK", pos = (-0.325, -0.25),
+                            func = self.__handleOk)
+            self.makeButton("CANCEL", pos = (0.2, -0.25),
+                            func = self.__handleCancel)
+        else:
+            # create a centered OK  button
+            self.makeButton("OK", pos = (0.0, -0.25), func = self.__handleOk)
+            
+	self.isLoaded = 1
+	return None
+	
+    def unload(self):
+	"""unload(self)
+	"""
+	if self.isLoaded == 0:
+	    return None
+	
+	self.hide()
+        self.cleanup()
+
+	self.isLoaded = 0
+	return None
+
+    def __handleRollover(self):
+	return None
+
+    def __handleOk(self):
+	self.doneStatus = "ok"	
+	messenger.send(self.doneEvent)
+
+    def __handleCancel(self):
+        self.doneStatus = "cancel"
+	messenger.send(self.doneEvent)
+
+    def setMessage(self, message):
+        """setMessage(self, string)
+        """
+        if self.isLoaded == 1:
+            self.panelText[0].setText(message)
+        
+        
+
+
+
+
+

+ 53 - 23
direct/src/gui/OnscreenPanel.py

@@ -35,7 +35,8 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
         
         
         # initialize our NodePath essence.
         # initialize our NodePath essence.
         NodePath.__init__(self, aspect2d.attachNewNode(panelName))
         NodePath.__init__(self, aspect2d.attachNewNode(panelName))
-
+        NodePath.hide(self)
+        
     def cleanupPanel(self, uniqueName):
     def cleanupPanel(self, uniqueName):
         """cleanupPanel(self, string uniqueName)
         """cleanupPanel(self, string uniqueName)
 
 
@@ -114,10 +115,6 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
         self.panelButtons = []
         self.panelButtons = []
         self.panelText = []
         self.panelText = []
 
 
-        centerX = (rect[0] + rect[1]) / 2.0
-        centerY = (rect[2] + rect[3]) / 2.0
-        self.setPos(centerX, 0, centerY)
-
         if isinstance(geom, types.StringType):
         if isinstance(geom, types.StringType):
             # If 'geom' is a string, it's the name of a model to load.
             # If 'geom' is a string, it's the name of a model to load.
             self.panelGeom = loader.loadModelCopy(geom)
             self.panelGeom = loader.loadModelCopy(geom)
@@ -126,9 +123,20 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
             # Otherwise, it's a model to instance.
             # Otherwise, it's a model to instance.
             self.panelGeom = geom.instanceTo(self)
             self.panelGeom = geom.instanceTo(self)
 
 
+        # Set up the panel as its own mouse region so mouse clicks on
+        # the panel don't inadvertently drive the toon around.
+        self.geomRect = geomRect
+        self.panelRegion = MouseWatcherRegion(uniqueName, 0, 0, 0, 0)
+        self.panelRegion.setRelative(self.panelGeom,
+                                     geomRect[0], geomRect[1],
+                                     geomRect[2], geomRect[3])
+
+        centerX = (rect[0] + rect[1]) / 2.0
+        centerY = (rect[2] + rect[3]) / 2.0
+        self.setPos(centerX, 0, centerY)
+
         # Scale and position the geometry to fill up our desired
         # Scale and position the geometry to fill up our desired
         # rectangle.
         # rectangle.
-
         gCenterX = (geomRect[0] + geomRect[1]) / 2.0
         gCenterX = (geomRect[0] + geomRect[1]) / 2.0
         gCenterY = (geomRect[2] + geomRect[3]) / 2.0
         gCenterY = (geomRect[2] + geomRect[3]) / 2.0
 
 
@@ -151,14 +159,6 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
             self.panelGeom.setY(100)
             self.panelGeom.setY(100)
             self.panelGeom.arc().setTransition(dw, 2)
             self.panelGeom.arc().setTransition(dw, 2)
 
 
-        # Set up the panel as its own mouse region so mouse clicks on
-        # the panel don't inadvertently drive the toon around.
-        self.panelRegion = MouseWatcherRegion(uniqueName, 0, 0, 0, 0)
-        self.panelRegion.setRelative(self.panelGeom,
-                                     geomRect[0], geomRect[1],
-                                     geomRect[2], geomRect[3])
-        base.mouseWatcher.node().addRegion(self.panelRegion)
-
     def cleanup(self):
     def cleanup(self):
         """cleanup(self):
         """cleanup(self):
 
 
@@ -173,21 +173,49 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
         if not self.panelSetup:
         if not self.panelSetup:
             return 0
             return 0
 
 
+        self.hide()
+        
         for button in self.panelButtons:
         for button in self.panelButtons:
             button.cleanup()
             button.cleanup()
-            self.ignore(button.getName() + '-down-rollover')
 
 
         for text in self.panelText:
         for text in self.panelText:
             text.cleanup()
             text.cleanup()
 
 
-        base.mouseWatcher.node().removeRegion(self.panelRegion)
-
         if not self.isEmpty():
         if not self.isEmpty():
             self.removeNode()
             self.removeNode()
 
 
         self.panelSetup = 0
         self.panelSetup = 0
         return 1
         return 1
 
 
+    def show(self):
+        """show(self):
+        Show everything and hang hooks
+        """
+        NodePath.show(self)
+
+        # show the buttons that are meant to be shown
+        for button in self.panelButtons:
+            if button.func != None:
+                self.accept(button.getName() + '-down-rollover', button.func)
+            if button.panelManage:
+                button.manage(self)
+                
+        base.mouseWatcher.node().addRegion(self.panelRegion)
+        
+    def hide(self):
+        """hide(self):
+        Hide everything and remove hooks
+        """
+        NodePath.hide(self)
+
+        # hide the shown buttons and remove all hooks
+        for button in self.panelButtons:        
+            self.ignore(button.getName() + '-down-rollover')
+            if button.panelManage:
+                button.unmanage()
+                
+        base.mouseWatcher.node().removeRegion(self.panelRegion)
+
     def makeButton(self, name,
     def makeButton(self, name,
                    func = None,
                    func = None,
                    manage = 1,
                    manage = 1,
@@ -233,12 +261,9 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
 
 
         self.panelButtons.append(button)
         self.panelButtons.append(button)
         
         
-        if manage:
-            button.manage(self)
-
-        if func != None:
-            self.accept(buttonName + '-down-rollover', func)
-
+        button.panelManage = manage
+        button.func = func
+        
         return button
         return button
 
 
     def makeText(self, text = '',
     def makeText(self, text = '',
@@ -312,9 +337,14 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
         
         
         """
         """
         NodePath.setPos(self, x, y, z)
         NodePath.setPos(self, x, y, z)
+
         for button in self.panelButtons:
         for button in self.panelButtons:
             if button.managed:
             if button.managed:
                 button.unmanage()
                 button.unmanage()
                 button.manage(self)
                 button.manage(self)
 
 
+        self.panelRegion.setRelative(self.panelGeom,
+                                     self.geomRect[0], self.geomRect[1],
+                                     self.geomRect[2], self.geomRect[3])
+