Browse Source

Added a new type of object replacement system and Band-Aided some crashes

Abhishek Nath 17 years ago
parent
commit
6aa5d76752

+ 67 - 5
direct/src/leveleditor/LevelEditor.py

@@ -8,6 +8,7 @@ from direct.showbase.TkGlobal import *
 from direct.directtools.DirectUtil import *
 from direct.directtools.DirectUtil import *
 from direct.directtools.DirectGeometry import *
 from direct.directtools.DirectGeometry import *
 from direct.tkwidgets.SceneGraphExplorer import *
 from direct.tkwidgets.SceneGraphExplorer import *
+from direct.directnotify import DirectNotifyGlobal
 from tkMessageBox import showinfo
 from tkMessageBox import showinfo
 from tkFileDialog import *
 from tkFileDialog import *
 from Tkinter import *
 from Tkinter import *
@@ -292,7 +293,8 @@ except NameError:
 
 
 class LevelEditor(NodePath, DirectObject):
 class LevelEditor(NodePath, DirectObject):
     """Class used to create a Toontown LevelEditor object"""
     """Class used to create a Toontown LevelEditor object"""
-
+    notify = DirectNotifyGlobal.directNotify.newCategory('LevelEditor')
+        
     # Init the list of callbacks:
     # Init the list of callbacks:
     selectedNodePathHookHooks=[]
     selectedNodePathHookHooks=[]
     deselectedNodePathHookHooks=[]
     deselectedNodePathHookHooks=[]
@@ -498,7 +500,7 @@ class LevelEditor(NodePath, DirectObject):
         self.innerBarricadeDict = {}
         self.innerBarricadeDict = {}
 
 
         # [gjeon] to find out currently moving camera in maya mode
         # [gjeon] to find out currently moving camera in maya mode
-        self.mouseMayaCamera = False
+        self.mouseMayaCamera = True
 
 
         # [gjeon] to find out drive mode stat
         # [gjeon] to find out drive mode stat
         self.fDrive = False
         self.fDrive = False
@@ -1105,13 +1107,19 @@ class LevelEditor(NodePath, DirectObject):
     def replace(self, nodePath, dnaNode):
     def replace(self, nodePath, dnaNode):
         """ Replace a node path with the results of a DNANode traversal """
         """ Replace a node path with the results of a DNANode traversal """
         # Find node path's parent
         # Find node path's parent
+        if not nodePath:
+            return None
         parent = nodePath.getParent()
         parent = nodePath.getParent()
         dnaParent = dnaNode.getParent()
         dnaParent = dnaNode.getParent()
         # Get rid of the old node path and remove its DNA and
         # Get rid of the old node path and remove its DNA and
         # node relations from the DNA Store
         # node relations from the DNA Store
         self.remove(dnaNode, nodePath)
         self.remove(dnaNode, nodePath)
         # Traverse the old (modified) dna to create the new node path
         # Traverse the old (modified) dna to create the new node path
-        newNodePath = dnaNode.traverse(parent, DNASTORE, 1)
+        try:
+            newNodePath = dnaNode.traverse(parent, DNASTORE, 1)
+        except Exception:
+            self.notify.debug("Couldn't traverse existing DNA! Do not trust replace")
+            return None
         # Add it back to the dna parent
         # Add it back to the dna parent
         dnaParent.add(dnaNode)
         dnaParent.add(dnaNode)
         # Update scene graph explorer
         # Update scene graph explorer
@@ -1725,6 +1733,7 @@ class LevelEditor(NodePath, DirectObject):
 
 
     # LEVEL-OBJECT MODIFICATION FUNCTIONS
     # LEVEL-OBJECT MODIFICATION FUNCTIONS
     def levelHandleMouse3(self, modifiers):
     def levelHandleMouse3(self, modifiers):
+        # import pdb; pdb.set_trace()
         if base.direct.cameraControl.useMayaCamControls and modifiers == 4: # alt is down, use maya controls
         if base.direct.cameraControl.useMayaCamControls and modifiers == 4: # alt is down, use maya controls
             self.mouseMayaCamera = True
             self.mouseMayaCamera = True
             return
             return
@@ -1936,6 +1945,53 @@ class LevelEditor(NodePath, DirectObject):
                 (objClass.eq(DNA_PROP))
                 (objClass.eq(DNA_PROP))
                 ):
                 ):
                 self.panel.setCurrentColor(self.DNATarget.getColor())
                 self.panel.setCurrentColor(self.DNATarget.getColor())
+                
+##        b1 = DirectButton(text = ("Button1", "click!", "roll", "disabled"),
+##                  text_scale=0.1, borderWidth = (0.01, 0.01),
+##                  relief=2)
+##
+##        b2 = DirectButton(text = ("Button2", "click!", "roll", "disabled"),
+##                  text_scale=0.1, borderWidth = (0.01, 0.01),
+##                  relief=2)
+##
+##        l1 = DirectLabel(text = "Test1", text_scale=0.1)
+##        l2 = DirectLabel(text = "Test2", text_scale=0.1)
+##        l3 = DirectLabel(text = "Test3", text_scale=0.1)
+##
+##        numItemsVisible = 4
+##        itemHeight = 0.11
+##
+##        myScrolledList = DirectScrolledList(
+##                decButton_pos= (0.35, 0, 0.53),
+##                decButton_text = "Dec",
+##                decButton_text_scale = 0.04,
+##                decButton_borderWidth = (0.005, 0.005),
+##
+##                incButton_pos= (0.35, 0, -0.02),
+##                incButton_text = "Inc",
+##                incButton_text_scale = 0.04,
+##                incButton_borderWidth = (0.005, 0.005),
+##
+##                frameSize = (0.0, 0.7, -0.05, 0.59),
+##                frameColor = (1,0,0,0.5),
+##                pos = (-1, 0, 0),
+##                items = [b1, b2],
+##                numItemsVisible = numItemsVisible,
+##                forceHeight = itemHeight,
+##                itemFrame_frameSize = (-0.2, 0.2, -0.37, 0.11),
+##                itemFrame_pos = (0.35, 0, 0.4),
+##        )
+##
+##        myScrolledList.addItem(l1)
+##        myScrolledList.addItem(l2)
+##        myScrolledList.addItem(l3)
+##
+##        for fruit in ['apple', 'pear', 'banana', 'orange']:
+##            l = DirectLabel(text = fruit, text_scale=0.1)
+##            myScrolledList.addItem(l)
+##
+##        myScrolledList.reparentTo(aspect2d)
+
 
 
     def setDNATargetColor(self, color):
     def setDNATargetColor(self, color):
         if self.DNATarget:
         if self.DNATarget:
@@ -2643,7 +2699,10 @@ class LevelEditor(NodePath, DirectObject):
         # Now load in new file
         # Now load in new file
         if fUseCVS:
         if fUseCVS:
             self.cvsUpdate(filename)
             self.cvsUpdate(filename)
-        node = loadDNAFile(DNASTORE, Filename.fromOsSpecific(filename).cStr(), CSDefault, 1)
+        try:
+            node = loadDNAFile(DNASTORE, Filename.fromOsSpecific(filename).cStr(), CSDefault, 1)
+        except Exception:
+            self.notify.debug("Couldn't load specified DNA file. Please make sure storage code has been specified in Config.prc file")
         if node.getNumParents() == 1:
         if node.getNumParents() == 1:
             # If the node already has a parent arc when it's loaded, we must
             # If the node already has a parent arc when it's loaded, we must
             # be using the level editor and we want to preserve that arc.
             # be using the level editor and we want to preserve that arc.
@@ -4698,13 +4757,16 @@ class LevelEditorPanel(Pmw.MegaToplevel):
         base.direct.gridButton.pack(side = LEFT, expand = 1, fill = X)
         base.direct.gridButton.pack(side = LEFT, expand = 1, fill = X)
 
 
         self.fMaya = IntVar()
         self.fMaya = IntVar()
-        self.fMaya.set(0)
+        self.fMaya.set(1)
         self.mayaButton = Checkbutton(buttonFrame,
         self.mayaButton = Checkbutton(buttonFrame,
                                       text = 'Maya Cam',
                                       text = 'Maya Cam',
                                       width = 6,
                                       width = 6,
                                       variable = self.fMaya,
                                       variable = self.fMaya,
                                       command = self.toggleMaya)
                                       command = self.toggleMaya)
         self.mayaButton.pack(side = LEFT, expand = 1, fill = X)
         self.mayaButton.pack(side = LEFT, expand = 1, fill = X)
+        
+        #Make maya mode on by default
+        self.toggleMaya()
 
 
         buttonFrame.pack(fill = X)
         buttonFrame.pack(fill = X)
 
 

+ 10 - 1
direct/src/leveleditor/LevelStyleManager.py

@@ -1,8 +1,10 @@
 import sys, string, math, types
 import sys, string, math, types
 from pandac.PandaModules import *
 from pandac.PandaModules import *
 import direct.gui.DirectGuiGlobals as DGG
 import direct.gui.DirectGuiGlobals as DGG
+from direct.gui.DirectGui import *
 
 
 from PieMenu import *
 from PieMenu import *
+from ScrollMenu import *
 
 
 dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
 dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
 
 
@@ -1010,7 +1012,9 @@ class LevelStyleManager:
             # Prepend None to allow option of no item
             # Prepend None to allow option of no item
             if ((dnaType == 'street') or (dnaType == 'prop') or
             if ((dnaType == 'street') or (dnaType == 'prop') or
                 (dnaType == 'toon_landmark')):
                 (dnaType == 'toon_landmark')):
-                attribute.setMenu(self.createTextPieMenu(dnaType, dnaList))
+                # attribute.setMenu(self.createTextPieMenu(dnaType, dnaList))
+                attribute.setMenu(self.createScrollMenu(dnaType, dnaList))
+                attribute.getMenu().createScrolledList()
             elif (dnaType == 'wall'):
             elif (dnaType == 'wall'):
                 attribute.setMenu(self.createDNAPieMenu(dnaType, dnaList,
                 attribute.setMenu(self.createDNAPieMenu(dnaType, dnaList,
                                                          sf = 0.25))
                                                          sf = 0.25))
@@ -1106,6 +1110,11 @@ class LevelStyleManager:
         newMenu.setScale(0.5)
         newMenu.setScale(0.5)
         # Create and return a pie menu
         # Create and return a pie menu
         return PieMenu(newMenu, textList)
         return PieMenu(newMenu, textList)
+    
+    def createScrollMenu(self, dnaType, textList):
+        newMenu = hidden.attachNewNode(dnaType+'ScrollMenu')
+        
+        return ScrollMenu(newMenu, textList)
 
 
     # MISCELLANEOUS MENUS
     # MISCELLANEOUS MENUS
     def createMiscAttributes(self):
     def createMiscAttributes(self):

+ 96 - 0
direct/src/leveleditor/ScrollMenu.py

@@ -0,0 +1,96 @@
+###########################################################
+# Class to create and maintain a scrolled list
+# that can be embedded in a LevelAttribute instance
+###########################################################
+
+from direct.gui.DirectGui import *
+from toontown.toonbase import ToontownGlobals
+
+class ScrollMenu:
+    def __init__(self, nodePath, textList):
+        self.action = None              #Call back fucntion
+        self.textList = textList
+        
+        self.parent = nodePath
+        self.frame = None
+
+        self.initialState = None        # To maintain backward compatibility
+        
+    def createScrolledList(self):
+        # First create a frame in which direct elements maybe placed
+        self.frame = DirectFrame(scale = 1.1, relief = 1.0,
+                                 frameSize = (-0.5,0.2,-0.05,0.59),
+                                 frameColor = (0.737, 0.573, 0.345, 0.000))
+
+        numItemsVisible = 4
+        itemHeight = 0.08
+
+        myScrolledList = DirectScrolledList(
+            decButton_pos= (0.35, 0, 0.53),
+            decButton_text = "Dec",
+            decButton_text_scale = 0.04,
+            decButton_borderWidth = (0.005, 0.005),
+
+            incButton_pos= (0.35, 0, -0.02),
+            incButton_text = "Inc",
+            incButton_text_scale = 0.04,
+            incButton_borderWidth = (0.005, 0.005),
+
+            frameSize = (0.0, 0.8, -0.05, 0.59),
+            frameColor = (0,0,1,0.5),
+            pos = (-0.5, 0, 0),
+            items = [],
+            numItemsVisible = numItemsVisible,
+            forceHeight = itemHeight,
+            itemFrame_frameSize = (-0.35, 0.35, -0.37, 0.11),
+            itemFrame_pos = (0.4, 0, 0.4),
+        )
+        
+        for t in self.textList:
+            myScrolledList.addItem(DirectButton(text = (t, t, t),
+                                    text_scale = 0.05, command = self.__selected,
+                                    extraArgs = [t], relief = None,
+                                    # text_font = ToontownGlobals.getSignFont(),
+                                    text0_fg = (0.152, 0.750, 0.258, 1),
+                                    text1_fg = (0.152, 0.750, 0.258, 1),
+                                    text2_fg = (0.977, 0.816, 0.133, 1), ))
+        myScrolledList.reparentTo(self.frame)
+        
+        #An exit button
+        b1 = DirectButton(parent = self.frame, text  = "Exit",
+                  text_scale=0.05, borderWidth = (0.01, 0.01),
+                  relief=1, command = self.__hide)
+        b1.setPos(0.15, 0, -0.025)
+        
+        self.frame.reparentTo(self.parent)
+        
+        
+    def __selected(self, text):
+        if(self.action):
+            self.action(text)
+            
+    def __hide(self):
+        self.frame.reparentTo(self.parent)
+
+
+    #######################################################
+    # Functions that allow compaitibility with the
+    # existing architecture that is tied into pie menu's
+    #######################################################
+    def spawnPieMenuTask(self):
+         # Where did the user press the button?
+        originX = base.direct.dr.mouseX
+        originY = base.direct.dr.mouseY
+
+        # Pop up menu
+        self.frame.reparentTo(aspect2d)
+        self.frame.setPos(originX, 0.0, originY)
+        
+    def removePieMenuTask(self):
+        pass
+    
+    def setInitialState(self, state):
+        self.initialState = state
+
+    def getInitialState(self):
+        return self.initialState