def __init__(self, parent = None, **kw): optiondefs = (('pgFunc', PGButton, None), ('numStates', 4, None), ('state', DGG.NORMAL, None), ('relief', DGG.RAISED, None), ('invertedFrames', (1,), None), ('command', None, None), ('extraArgs', [], None), ('commandButtons', (DGG.LMB,), self.setCommandButtons), ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), self.setClickSound), ('pressEffect', 1, DGG.INITOPT)) self.defineoptions(kw, optiondefs) DirectFrame.__init__(self, parent) pressEffectNP = None if self['pressEffect']: pressEffectNP = self.stateNodePath[1].attachNewNode('pressEffect', 1) self.stateNodePath[1] = pressEffectNP self.initialiseoptions(DirectButton) if pressEffectNP: bounds = self.getBounds() centerX = (bounds[0] + bounds[1]) / 2 centerY = (bounds[2] + bounds[3]) / 2 mat = Mat4.translateMat(-centerX, 0, -centerY) * Mat4.scaleMat(0.98) * Mat4.translateMat(centerX, 0, centerY) pressEffectNP.setMat(mat) return
def __init__(self, parent = None, **kw): optiondefs = (('pgFunc', PGEntry, None), ('numStates', 3, None), ('state', DGG.NORMAL, None), ('entryFont', None, DGG.INITOPT), ('width', 10, self.setup), ('numLines', 1, self.setup), ('focus', 0, self.setFocus), ('cursorKeys', 1, self.setCursorKeysActive), ('obscured', 0, self.setObscureMode), ('backgroundFocus', 0, self.setBackgroundFocus), ('initialText', '', DGG.INITOPT), ('command', None, None), ('extraArgs', [], None), ('failedCommand', None, None), ('failedExtraArgs', [], None), ('focusInCommand', None, None), ('focusInExtraArgs', [], None), ('focusOutCommand', None, None), ('focusOutExtraArgs', [], None), ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), self.setClickSound), ('autoCapitalize', 0, self.autoCapitalizeFunc), ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None), ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None)) self.defineoptions(kw, optiondefs) DirectFrame.__init__(self, parent) if self['entryFont'] == None: font = DGG.getDefaultFont() else: font = self['entryFont'] self.onscreenText = self.createcomponent('text', (), None, OnscreenText, (), parent=hidden, text='', align=TextNode.ALeft, font=font, scale=1, mayChange=1) self.onscreenText.removeNode() self.bind(DGG.ACCEPT, self.commandFunc) self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc) self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc) self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc) self._autoCapListener = DirectObject() self.initialiseoptions(DirectEntry) if not hasattr(self, 'autoCapitalizeAllowPrefixes'): self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes if not hasattr(self, 'autoCapitalizeForcePrefixes'): self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes for i in range(self['numStates']): self.guiItem.setTextDef(i, self.onscreenText.textNode) self.setup() self.unicodeText = 0 if self['initialText']: self.enterText(self['initialText']) return None
def initNametagGlobals(self): arrow = loader.loadModel('phase_3/models/props/arrow') card = loader.loadModel('phase_3/models/props/panel') speech3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox')) thought3d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_thought_cutout')) speech2d = ChatBalloon(loader.loadModelNode('phase_3/models/props/chatbox_noarrow')) chatButtonGui = loader.loadModelOnce('phase_3/models/gui/chat_button_gui') NametagGlobals.setCamera(base.cam) NametagGlobals.setArrowModel(arrow) NametagGlobals.setNametagCard(card, VBase4(-0.5, 0.5, -0.5, 0.5)) NametagGlobals.setMouseWatcher(base.mouseWatcherNode) NametagGlobals.setSpeechBalloon3d(speech3d) NametagGlobals.setThoughtBalloon3d(thought3d) NametagGlobals.setSpeechBalloon2d(speech2d) NametagGlobals.setThoughtBalloon2d(thought3d) NametagGlobals.setPageButton(PGButton.SReady, chatButtonGui.find('**/Horiz_Arrow_UP')) NametagGlobals.setPageButton(PGButton.SDepressed, chatButtonGui.find('**/Horiz_Arrow_DN')) NametagGlobals.setPageButton(PGButton.SRollover, chatButtonGui.find('**/Horiz_Arrow_Rllvr')) NametagGlobals.setQuitButton(PGButton.SReady, chatButtonGui.find('**/CloseBtn_UP')) NametagGlobals.setQuitButton(PGButton.SDepressed, chatButtonGui.find('**/CloseBtn_DN')) NametagGlobals.setQuitButton(PGButton.SRollover, chatButtonGui.find('**/CloseBtn_Rllvr')) arrow.removeNode() card.removeNode() chatButtonGui.removeNode() rolloverSound = DirectGuiGlobals.getDefaultRolloverSound() if rolloverSound: NametagGlobals.setRolloverSound(rolloverSound) clickSound = DirectGuiGlobals.getDefaultClickSound() if clickSound: NametagGlobals.setClickSound(clickSound) NametagGlobals.setToon(base.cam) self.marginManager = MarginManager() self.margins = base.aspect2d.attachNewNode(self.marginManager, DirectGuiGlobals.MIDGROUND_SORT_INDEX + 1) mm = self.marginManager self.leftCells = [ mm.addGridCell(0, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 3, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)] self.bottomCells = [ mm.addGridCell(0.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(1.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(2.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(3.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(4.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)] self.rightCells = [ mm.addGridCell(5, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(5, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop)]
def __init__(self, text = '', style = Plain, pos = (0, 0), roll = 0, scale = None, fg = None, bg = None, shadow = None, shadowOffset = (0.04, 0.04), frame = None, align = None, wordwrap = None, drawOrder = None, decal = 0, font = None, parent = None, sort = 0, mayChange = True): """ Make a text node from string, put it into the 2d sg and set it up with all the indicated parameters. The parameters are as follows: text: the actual text to display. This may be omitted and specified later via setText() if you don't have it available, but it is better to specify it up front. style: one of the pre-canned style parameters defined at the head of this file. This sets up the default values for many of the remaining parameters if they are unspecified; however, a parameter may still be specified to explicitly set it, overriding the pre-canned style. pos: the x, y position of the text on the screen. scale: the size of the text. This may either be a single float (and it will usually be a small number like 0.07) or it may be a 2-tuple of floats, specifying a different x, y scale. fg: the (r, g, b, a) foreground color of the text. This is normally a 4-tuple of floats or ints. bg: the (r, g, b, a) background color of the text. If the fourth value, a, is nonzero, a card is created to place behind the text and set to the given color. shadow: the (r, g, b, a) color of the shadow behind the text. If the fourth value, a, is nonzero, a little drop shadow is created and placed behind the text. frame: the (r, g, b, a) color of the frame drawn around the text. If the fourth value, a, is nonzero, a frame is created around the text. align: one of TextNode.ALeft, TextNode.ARight, or TextNode.ACenter. wordwrap: either the width to wordwrap the text at, or None to specify no automatic word wrapping. drawOrder: the drawing order of this text with respect to all other things in the 'fixed' bin within render2d. The text will actually use drawOrder through drawOrder + 2. decal: if this is True, the text is decalled onto its background card. Useful when the text will be parented into the 3-D scene graph. font: the font to use for the text. parent: the NodePath to parent the text to initially. mayChange: pass true if the text or its properties may need to be changed at runtime, false if it is static once created (which leads to better memory optimization). """ if parent == None: parent = aspect2d # make a text node textNode = TextNode('') self.textNode = textNode # We ARE a node path. Initially, we're an empty node path. NodePath.__init__(self) # Choose the default parameters according to the selected # style. if style == Plain: scale = scale or 0.07 fg = fg or (0, 0, 0, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 0) frame = frame or (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenTitle: scale = scale or 0.15 fg = fg or (1, 0.2, 0.2, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 1) frame = frame or (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenPrompt: scale = scale or 0.1 fg = fg or (1, 1, 0, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 1) frame = frame or (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == NameConfirm: scale = scale or 0.1 fg = fg or (0, 1, 0, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 0) frame = frame or (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == BlackOnWhite: scale = scale or 0.1 fg = fg or (0, 0, 0, 1) bg = bg or (1, 1, 1, 1) shadow = shadow or (0, 0, 0, 0) frame = frame or (0, 0, 0, 0) if align == None: align = TextNode.ACenter else: raise ValueError if not isinstance(scale, types.TupleType): # If the scale is already a tuple, it's a 2-d (x, y) scale. # Otherwise, it's a uniform scale--make it a tuple. scale = (scale, scale) # Save some of the parameters for posterity. self.scale = scale self.pos = pos self.roll = roll self.wordwrap = wordwrap if decal: textNode.setCardDecal(1) if font == None: font = DGG.getDefaultFont() textNode.setFont(font) textNode.setTextColor(fg[0], fg[1], fg[2], fg[3]) textNode.setAlign(align) if wordwrap: textNode.setWordwrap(wordwrap) if bg[3] != 0: # If we have a background color, create a card. textNode.setCardColor(bg[0], bg[1], bg[2], bg[3]) textNode.setCardAsMargin(0.1, 0.1, 0.1, 0.1) if shadow[3] != 0: # If we have a shadow color, create a shadow. # Can't use the *shadow interface because it might be a VBase4. #textNode.setShadowColor(*shadow) textNode.setShadowColor(shadow[0], shadow[1], shadow[2], shadow[3]) textNode.setShadow(*shadowOffset) if frame[3] != 0: # If we have a frame color, create a frame. textNode.setFrameColor(frame[0], frame[1], frame[2], frame[3]) textNode.setFrameAsMargin(0.1, 0.1, 0.1, 0.1) # Create a transform for the text for our scale and position. # We'd rather do it here, on the text itself, rather than on # our NodePath, so we have one fewer transforms in the scene # graph. self.updateTransformMat() if drawOrder != None: textNode.setBin('fixed') textNode.setDrawOrder(drawOrder) self.setText(text) if not text: # If we don't have any text, assume we'll be changing it later. self.mayChange = 1 else: self.mayChange = mayChange # Ok, now update the node. if not self.mayChange: # If we aren't going to change the text later, we can # throw away the TextNode. self.textNode = textNode.generate() self.isClean = 0 # Set ourselves up as the NodePath that points to this node. self.assign(parent.attachNewNode(self.textNode, sort))
def __init__(self, parent=None, **kw): # Inherits from DirectFrame # A Direct Frame can have: # - A background texture (pass in path to image, or Texture Card) # - A midground geometry item (pass in geometry) # - A foreground text Node (pass in text string or Onscreen Text) # For a direct entry: # Each button has 3 states (focus, noFocus, disabled) # The same image/geom/text can be used for all three states or each # state can have a different text/geom/image # State transitions happen automatically based upon mouse interaction optiondefs = ( # Define type of DirectGuiWidget ('pgFunc', PGEntry, None), ('numStates', 3, None), ('state', DGG.NORMAL, None), ('entryFont', None, DGG.INITOPT), ('width', 10, self.updateWidth), ('numLines', 1, self.updateNumLines), ('focus', 0, self.setFocus), ('cursorKeys', 1, self.setCursorKeysActive), ('obscured', 0, self.setObscureMode), # Setting backgroundFocus allows the entry box to get keyboard # events that are not handled by other things (i.e. events that # fall through to the background): ('backgroundFocus', 0, self.setBackgroundFocus), # Text used for the PGEntry text node # NOTE: This overrides the DirectFrame text option ('initialText', '', DGG.INITOPT), # Command to be called on hitting Enter ('command', None, None), ('extraArgs', [], None), # Command to be called when enter is hit but we fail to submit ('failedCommand', None, None), ('failedExtraArgs', [], None), # commands to be called when focus is gained or lost ('focusInCommand', None, None), ('focusInExtraArgs', [], None), ('focusOutCommand', None, None), ('focusOutExtraArgs', [], None), # Sounds to be used for button events ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), self.setClickSound), ('autoCapitalize', 0, self.autoCapitalizeFunc), ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None), ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs) # Initialize superclasses DirectFrame.__init__(self, parent) if self['entryFont'] == None: font = DGG.getDefaultFont() else: font = self['entryFont'] # Create Text Node Component self.onscreenText = self.createcomponent( 'text', (), None, OnscreenText, (), parent=hidden, # Pass in empty text to avoid extra work, since its really # The PGEntry which will use the TextNode to generate geometry text='', align=TextNode.ALeft, font=font, scale=1, # Don't get rid of the text node mayChange=1) # We can get rid of the node path since we're just using the # onscreenText as an easy way to access a text node as a # component self.onscreenText.removeNode() # Bind command function self.bind(DGG.ACCEPT, self.commandFunc) self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc) self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc) self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc) # listen for auto-capitalize events on a separate object to prevent # clashing with other parts of the system self._autoCapListener = DirectObject() # Call option initialization functions self.initialiseoptions(DirectEntry) if not hasattr(self, 'autoCapitalizeAllowPrefixes'): self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes if not hasattr(self, 'autoCapitalizeForcePrefixes'): self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes # Update TextNodes for each state for i in range(self['numStates']): self.guiItem.setTextDef(i, self.onscreenText.textNode) # Now we should call setup() again to make sure it has the # right font def. self.setup() # Update initial text self.unicodeText = 0 if self['initialText']: self.enterText(self['initialText'])
def __init__(self, parent = None, **kw): """ DirectDialog(kw) Creates a popup dialog to alert and/or interact with user. Some of the main keywords that can be used to customize the dialog: Keyword Definition ------- ---------- text Text message/query displayed to user geom Geometry to be displayed in dialog buttonTextList List of text to show on each button buttonGeomList List of geometry to show on each button buttonImageList List of images to show on each button buttonValueList List of values sent to dialog command for each button. If value is [] then the ordinal rank of the button is used as its value buttonHotKeyList List of hotkeys to bind to each button. Typing hotkey is equivalent to pressing the corresponding button. suppressKeys Set to true if you wish to suppress keys (i.e. Dialog eats key event), false if you wish Dialog to pass along key event buttonSize 4-tuple used to specify custom size for each button (to make bigger then geom/text for example) pad Space between border and interior graphics topPad Extra space added above text/geom/image midPad Extra space added between text/buttons sidePad Extra space added to either side of text/buttons buttonPadSF Scale factor used to expand/contract button horizontal spacing command Callback command used when a button is pressed. Value supplied to command depends on values in buttonValueList Note: Number of buttons on the dialog depends upon the maximum length of any button[Text|Geom|Image|Value]List specified. Values of None are substituted for lists that are shorter than the max length """ # Inherits from DirectFrame optiondefs = ( # Define type of DirectGuiWidget ('dialogName', 'DirectDialog_' + `DirectDialog.PanelIndex`, DGG.INITOPT), # Default position is slightly forward in Y, so as not to # intersect the near plane, which is incorrectly set to 0 # in DX for some reason. ('pos', (0, 0.1, 0), None), ('pad', (0.1, 0.1), None), ('text', '', None), ('text_align', TextNode.ALeft, None), ('text_scale', 0.06, None), ('image', DGG.getDefaultDialogGeom(), None), ('relief', None, None), ('buttonTextList', [], DGG.INITOPT), ('buttonGeomList', [], DGG.INITOPT), ('buttonImageList', [], DGG.INITOPT), ('buttonValueList', [], DGG.INITOPT), ('buttonHotKeyList', [], DGG.INITOPT), ('button_borderWidth', (.01, .01), None), ('button_pad', (.01, .01), None), ('button_relief', DGG.RAISED, None), ('button_text_scale', 0.06, None), ('buttonSize', None, DGG.INITOPT), ('topPad', 0.06, DGG.INITOPT), ('midPad', 0.12, DGG.INITOPT), ('sidePad', 0., DGG.INITOPT), ('buttonPadSF', 1.1, DGG.INITOPT), # Alpha of fade screen behind dialog ('fadeScreen', 0, None), ('command', None, None), ('extraArgs', [], None), ('sortOrder', NO_FADE_SORT_INDEX, None), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs, dynamicGroups = ("button",)) # Initialize superclasses DirectFrame.__init__(self, parent) #if not self['dialogName']: # self['dialogName'] = 'DirectDialog_' + `DirectDialog.PanelIndex` # Clean up any previously existing panel with the same unique # name. We don't allow any two panels with the same name to # coexist. cleanupDialog(self['dialogName']) # Store this panel in our map of all open panels. DirectDialog.AllDialogs[self['dialogName']] = self DirectDialog.PanelIndex += 1 # Determine number of buttons self.numButtons = max(len(self['buttonTextList']), len(self['buttonGeomList']), len(self['buttonImageList']), len(self['buttonValueList'])) # Create buttons self.buttonList = [] index = 0 for i in range(self.numButtons): name = 'Button' + `i` try: text = self['buttonTextList'][i] except IndexError: text = None try: geom = self['buttonGeomList'][i] except IndexError: geom = None try: image = self['buttonImageList'][i] except IndexError: image = None try: value = self['buttonValueList'][i] except IndexError: value = i self['buttonValueList'].append(i) try: hotKey = self['buttonHotKeyList'][i] except IndexError: hotKey = None button = self.createcomponent( name, (), "button", DirectButton, (self,), text = text, geom = geom, image = image, suppressKeys = self['suppressKeys'], frameSize = self['buttonSize'], command = lambda s = self, v = value: s.buttonCommand(v) ) self.buttonList.append(button) # Update dialog when everything has been initialised self.postInitialiseFuncList.append(self.configureDialog) self.initialiseoptions(DirectDialog)
def __init__(self, parent=None, **kw): optiondefs = ( ( 'pgFunc', PGEntry, None), ('numStates', 3, None), ( 'state', DGG.NORMAL, None), ( 'entryFont', None, DGG.INITOPT), ( 'width', 10, self.setup), ( 'numLines', 1, self.setup), ( 'focus', 0, self.setFocus), ( 'cursorKeys', 1, self.setCursorKeysActive), ( 'obscured', 0, self.setObscureMode), ( 'backgroundFocus', 0, self.setBackgroundFocus), ( 'initialText', '', DGG.INITOPT), ('command', None, None), ( 'extraArgs', [], None), ('failedCommand', None, None), ( 'failedExtraArgs', [], None), ('focusInCommand', None, None), ( 'focusInExtraArgs', [], None), ('focusOutCommand', None, None), ( 'focusOutExtraArgs', [], None), ( 'rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ( 'clickSound', DGG.getDefaultClickSound(), self.setClickSound), ( 'autoCapitalize', 0, self.autoCapitalizeFunc), ( 'autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None), ( 'autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None)) self.defineoptions(kw, optiondefs) DirectFrame.__init__(self, parent) if self['entryFont'] == None: font = DGG.getDefaultFont() else: font = self['entryFont'] self.onscreenText = self.createcomponent('text', (), None, OnscreenText, (), parent=hidden, text='', align=TextNode.ALeft, font=font, scale=1, mayChange=1) self.onscreenText.removeNode() self.bind(DGG.ACCEPT, self.commandFunc) self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc) self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc) self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc) self._autoCapListener = DirectObject() self.initialiseoptions(DirectEntry) if not hasattr(self, 'autoCapitalizeAllowPrefixes'): self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes if not hasattr(self, 'autoCapitalizeForcePrefixes'): self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes for i in range(self['numStates']): self.guiItem.setTextDef(i, self.onscreenText.textNode) self.setup() self.unicodeText = 0 if self['initialText']: self.enterText(self['initialText']) return
pollingDelay = 0.5 if launcher: print 'ToontownStart: Polling for game2 to finish...' while not launcher.getGame2Done(): time.sleep(pollingDelay) print 'ToontownStart: Game2 is finished.' print 'ToontownStart: Starting the game.' from PandaModules import * tempLoader = PandaLoader() backgroundNode = tempLoader.loadSync( Filename('phase_3/models/gui/loading-background')) import DirectGuiGlobals print 'ToontownStart: setting default font' import ToontownGlobals DirectGuiGlobals.setDefaultFontFunc(ToontownGlobals.getInterfaceFont) if launcher: launcher.setPandaErrorCode(7) from ShowBaseGlobal import * if base.win == None: print 'Unable to open window; aborting.' sys.exit() if launcher: launcher.setPandaErrorCode(0) launcher.setPandaWindowOpen() backgroundNodePath = aspect2d.attachNewNode(backgroundNode, 0) backgroundNodePath.setPos(0.0, 0.0, 0.0) backgroundNodePath.setScale(render2d, VBase3(1)) backgroundNodePath.find('**/fg').setBin('fixed', 20) backgroundNodePath.find('**/bg').setBin('fixed', 10) base.graphicsEngine.renderFrame()
# (normal, press, rollover, and disabled), set scale = .15, and relief raised dbArray = [] for i in range(10): db = DirectButton( parent=dl, image='models/maps/noise.rgb', geom=smiley, text=('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'), scale=.15, relief='raised', # Here we set an option for a component of the button geom1_color=(1, 0, 0, 1), # Here is an example of a component group option text_pos=(.6, -.8), # Set audio characteristics clickSound=DirectGuiGlobals.getDefaultClickSound(), rolloverSound=DirectGuiGlobals.getDefaultRolloverSound()) # You can set component or component group options after a gui item # has been created db['text_scale'] = 0.5 db['command'] = lambda i=i: dummyCmd(i) # Bind the commands db.bind(DirectGuiGlobals.ENTER, lambda x, db=db: shrink(db)) db.bind(DirectGuiGlobals.EXIT, lambda x, db=db: expand(db)) db.bind(DirectGuiGlobals.B1PRESS, lambda x, db=db: ouch(db)) # Pop up placer when button 2 is pressed db.bind(DirectGuiGlobals.B3PRESS, lambda x, db=db: db.place()) dbArray.append(db)
def __init__(self, parent=None, **kw): """ DirectDialog(kw) Creates a popup dialog to alert and/or interact with user. Some of the main keywords that can be used to customize the dialog: Keyword Definition ------- ---------- text Text message/query displayed to user geom Geometry to be displayed in dialog buttonTextList List of text to show on each button buttonGeomList List of geometry to show on each button buttonImageList List of images to show on each button buttonValueList List of values sent to dialog command for each button. If value is [] then the ordinal rank of the button is used as its value buttonHotKeyList List of hotkeys to bind to each button. Typing hotkey is equivalent to pressing the corresponding button. suppressKeys Set to true if you wish to suppress keys (i.e. Dialog eats key event), false if you wish Dialog to pass along key event buttonSize 4-tuple used to specify custom size for each button (to make bigger then geom/text for example) pad Space between border and interior graphics topPad Extra space added above text/geom/image midPad Extra space added between text/buttons sidePad Extra space added to either side of text/buttons buttonPadSF Scale factor used to expand/contract button horizontal spacing command Callback command used when a button is pressed. Value supplied to command depends on values in buttonValueList Note: Number of buttons on the dialog depends upon the maximum length of any button[Text|Geom|Image|Value]List specified. Values of None are substituted for lists that are shorter than the max length """ # Inherits from DirectFrame optiondefs = ( # Define type of DirectGuiWidget ('dialogName', 'DirectDialog_' + repr(DirectDialog.PanelIndex), DGG.INITOPT), # Default position is slightly forward in Y, so as not to # intersect the near plane, which is incorrectly set to 0 # in DX for some reason. ('pos', (0, 0.1, 0), None), ('pad', (0.1, 0.1), None), ('text', '', None), ('text_align', TextNode.ALeft, None), ('text_scale', 0.06, None), ('image', DGG.getDefaultDialogGeom(), None), ('relief', None, None), ('buttonTextList', [], DGG.INITOPT), ('buttonGeomList', [], DGG.INITOPT), ('buttonImageList', [], DGG.INITOPT), ('buttonValueList', [], DGG.INITOPT), ('buttonHotKeyList', [], DGG.INITOPT), ('button_borderWidth', (.01, .01), None), ('button_pad', (.01, .01), None), ('button_relief', DGG.RAISED, None), ('button_text_scale', 0.06, None), ('buttonSize', None, DGG.INITOPT), ('topPad', 0.06, DGG.INITOPT), ('midPad', 0.12, DGG.INITOPT), ('sidePad', 0., DGG.INITOPT), ('buttonPadSF', 1.1, DGG.INITOPT), # Alpha of fade screen behind dialog ('fadeScreen', 0, None), ('command', None, None), ('extraArgs', [], None), ('sortOrder', NO_FADE_SORT_INDEX, None), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs, dynamicGroups=("button", )) # Initialize superclasses DirectFrame.__init__(self, parent) #if not self['dialogName']: # self['dialogName'] = 'DirectDialog_' + repr(DirectDialog.PanelIndex) # Clean up any previously existing panel with the same unique # name. We don't allow any two panels with the same name to # coexist. cleanupDialog(self['dialogName']) # Store this panel in our map of all open panels. DirectDialog.AllDialogs[self['dialogName']] = self DirectDialog.PanelIndex += 1 # Determine number of buttons self.numButtons = max(len(self['buttonTextList']), len(self['buttonGeomList']), len(self['buttonImageList']), len(self['buttonValueList'])) # Create buttons self.buttonList = [] index = 0 for i in range(self.numButtons): name = 'Button' + repr(i) try: text = self['buttonTextList'][i] except IndexError: text = None try: geom = self['buttonGeomList'][i] except IndexError: geom = None try: image = self['buttonImageList'][i] except IndexError: image = None try: value = self['buttonValueList'][i] except IndexError: value = i self['buttonValueList'].append(i) try: hotKey = self['buttonHotKeyList'][i] except IndexError: hotKey = None button = self.createcomponent( name, (), "button", DirectButton, (self, ), text=text, geom=geom, image=image, suppressKeys=self['suppressKeys'], frameSize=self['buttonSize'], command=lambda s=self, v=value: s.buttonCommand(v)) self.buttonList.append(button) # Update dialog when everything has been initialised self.postInitialiseFuncList.append(self.configureDialog) self.initialiseoptions(DirectDialog)
def __init__(self, text='', style=Plain, pos=(0, 0), scale=None, fg=None, bg=None, shadow=None, shadowOffset=(0.040000000000000001, 0.040000000000000001), frame=None, align=None, wordwrap=None, drawOrder=None, font=None, parent=None, sort=0, mayChange=0): if parent == None: parent = aspect2d textNode = TextNode('') self.textNode = textNode NodePath.__init__(self) if style == Plain: if not scale: pass scale = 0.070000000000000007 if not fg: pass fg = (0, 0, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenTitle: if not scale: pass scale = 0.14999999999999999 if not fg: pass fg = (1, 0.20000000000000001, 0.20000000000000001, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 1) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenPrompt: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (1, 1, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 1) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == NameConfirm: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (0, 1, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == BlackOnWhite: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (0, 0, 0, 1) if not bg: pass bg = (1, 1, 1, 1) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter else: raise ValueError if not isinstance(scale, types.TupleType): scale = (scale, scale) self.scale = scale self.pos = pos if font == None: font = DirectGuiGlobals.getDefaultFont() textNode.freeze() textNode.setFont(font) textNode.setTextColor(fg[0], fg[1], fg[2], fg[3]) textNode.setAlign(align) if wordwrap: textNode.setWordwrap(wordwrap) if bg[3] != 0: textNode.setCardColor(bg[0], bg[1], bg[2], bg[3]) textNode.setCardAsMargin(0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001) if shadow[3] != 0: textNode.setShadowColor(shadow[0], shadow[1], shadow[2], shadow[3]) textNode.setShadow(*shadowOffset) if frame[3] != 0: textNode.setFrameColor(frame[0], frame[1], frame[2], frame[3]) textNode.setFrameAsMargin(0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001) mat = Mat4.scaleMat(scale[0], 1, scale[1]) * Mat4.translateMat( pos[0], 0, pos[1]) textNode.setTransform(mat) if drawOrder != None: textNode.setBin('fixed') textNode.setDrawOrder(drawOrder) textNode.setText(text) if not text: self.mayChange = 1 else: self.mayChange = mayChange if self.mayChange: textNode.thaw() else: self.textNode = textNode.generate() self.isClean = 0 self.assign(parent.attachNewNode(self.textNode, sort))
def __init__(self, parent=None, **kw): # Inherits from DirectFrame # A Direct Frame can have: # - A background texture (pass in path to image, or Texture Card) # - A midground geometry item (pass in geometry) # - A foreground text Node (pass in text string or Onscreen Text) # For a direct button: # Each button has 4 states (ready, press, rollover, disabled) # The same image/geom/text can be used for all four states or each # state can have a different text/geom/image # State transitions happen automatically based upon mouse interaction # Responds to click event and calls command if None optiondefs = ( # Define type of DirectGuiWidget ('pgFunc', PGButton, None), ('numStates', 4, None), ('state', DGG.NORMAL, None), ('relief', DGG.RAISED, None), ('invertedFrames', (1, ), None), # Command to be called on button click ('command', None, None), ('extraArgs', [], None), # Which mouse buttons can be used to click the button ('commandButtons', (DGG.LMB, ), self.setCommandButtons), # Sounds to be used for button events ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), 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, DGG.INITOPT), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs) # Initialize superclasses DirectFrame.__init__(self, parent) # If specifed, add scaling to the pressed state to make it # look like the button is moving when you press it. We have # to set up the node first, before we call initialise options; # but we can't actually apply the scale until we have the # bounding volume (which happens during initialise options). pressEffectNP = None if self['pressEffect']: pressEffectNP = self.stateNodePath[1].attachNewNode( 'pressEffect', 1) self.stateNodePath[1] = pressEffectNP # Call option initialization functions self.initialiseoptions(DirectButton) # Now apply the scale. if pressEffectNP: bounds = self.getBounds() centerX = (bounds[0] + bounds[1]) / 2 centerY = (bounds[2] + bounds[3]) / 2 # Make a matrix that scales about the point mat = Mat4.translateMat(-centerX, 0, -centerY) * \ Mat4.scaleMat(0.98) * \ Mat4.translateMat(centerX, 0, centerY) pressEffectNP.setMat(mat)
# 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 = 'models/maps/noise.rgb', geom = smiley, text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'), scale = .15, relief = 'raised', # Here we set an option for a component of the button geom1_color = (1, 0, 0, 1), # Here is an example of a component group option text_pos = (.6, -.8), # Set audio characteristics clickSound = DirectGuiGlobals.getDefaultClickSound(), rolloverSound = DirectGuiGlobals.getDefaultRolloverSound() ) # You can set component or component group options after a gui item # has been created db['text_scale'] = 0.5 db['command'] = lambda i = i: dummyCmd(i) # Bind the commands db.bind(DirectGuiGlobals.ENTER, lambda x, db = db: shrink(db)) db.bind(DirectGuiGlobals.EXIT, lambda x, db = db: expand(db)) db.bind(DirectGuiGlobals.B1PRESS, lambda x, db = db: ouch(db)) # Pop up placer when button 2 is pressed db.bind(DirectGuiGlobals.B3PRESS, lambda x, db = db: db.place())
def initNametagGlobals(self): arrow = loader.loadModel('phase_3/models/props/arrow') card = loader.loadModel('phase_3/models/props/panel') speech3d = ChatBalloon( loader.loadModelNode('phase_3/models/props/chatbox')) thought3d = ChatBalloon( loader.loadModelNode( 'phase_3/models/props/chatbox_thought_cutout')) speech2d = ChatBalloon( loader.loadModelNode('phase_3/models/props/chatbox_noarrow')) chatButtonGui = loader.loadModelOnce( 'phase_3/models/gui/chat_button_gui') NametagGlobals.setCamera(base.cam) NametagGlobals.setArrowModel(arrow) NametagGlobals.setNametagCard(card, VBase4(-0.5, 0.5, -0.5, 0.5)) NametagGlobals.setMouseWatcher(base.mouseWatcherNode) NametagGlobals.setSpeechBalloon3d(speech3d) NametagGlobals.setThoughtBalloon3d(thought3d) NametagGlobals.setSpeechBalloon2d(speech2d) NametagGlobals.setThoughtBalloon2d(thought3d) NametagGlobals.setPageButton(PGButton.SReady, chatButtonGui.find('**/Horiz_Arrow_UP')) NametagGlobals.setPageButton(PGButton.SDepressed, chatButtonGui.find('**/Horiz_Arrow_DN')) NametagGlobals.setPageButton( PGButton.SRollover, chatButtonGui.find('**/Horiz_Arrow_Rllvr')) NametagGlobals.setQuitButton(PGButton.SReady, chatButtonGui.find('**/CloseBtn_UP')) NametagGlobals.setQuitButton(PGButton.SDepressed, chatButtonGui.find('**/CloseBtn_DN')) NametagGlobals.setQuitButton(PGButton.SRollover, chatButtonGui.find('**/CloseBtn_Rllvr')) arrow.removeNode() card.removeNode() chatButtonGui.removeNode() rolloverSound = DirectGuiGlobals.getDefaultRolloverSound() if rolloverSound: NametagGlobals.setRolloverSound(rolloverSound) clickSound = DirectGuiGlobals.getDefaultClickSound() if clickSound: NametagGlobals.setClickSound(clickSound) NametagGlobals.setToon(base.cam) self.marginManager = MarginManager() self.margins = base.aspect2d.attachNewNode( self.marginManager, DirectGuiGlobals.MIDGROUND_SORT_INDEX + 1) mm = self.marginManager self.leftCells = [ mm.addGridCell(0, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(0, 3, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop) ] self.bottomCells = [ mm.addGridCell(0.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(1.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(2.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(3.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(4.5, 0, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop) ] self.rightCells = [ mm.addGridCell(5, 2, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), mm.addGridCell(5, 1, base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop) ]
def __init__( self, text="", style=Plain, pos=(0, 0), scale=None, fg=None, bg=None, shadow=None, shadowOffset=(0.040000000000000001, 0.040000000000000001), frame=None, align=None, wordwrap=None, drawOrder=None, font=None, parent=None, sort=0, mayChange=0, ): if parent == None: parent = aspect2d textNode = TextNode("") self.textNode = textNode NodePath.__init__(self) if style == Plain: if not scale: pass scale = 0.070000000000000007 if not fg: pass fg = (0, 0, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenTitle: if not scale: pass scale = 0.14999999999999999 if not fg: pass fg = (1, 0.20000000000000001, 0.20000000000000001, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 1) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenPrompt: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (1, 1, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 1) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == NameConfirm: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (0, 1, 0, 1) if not bg: pass bg = (0, 0, 0, 0) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == BlackOnWhite: if not scale: pass scale = 0.10000000000000001 if not fg: pass fg = (0, 0, 0, 1) if not bg: pass bg = (1, 1, 1, 1) if not shadow: pass shadow = (0, 0, 0, 0) if not frame: pass frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter else: raise ValueError if not isinstance(scale, types.TupleType): scale = (scale, scale) self.scale = scale self.pos = pos if font == None: font = DirectGuiGlobals.getDefaultFont() textNode.freeze() textNode.setFont(font) textNode.setTextColor(fg[0], fg[1], fg[2], fg[3]) textNode.setAlign(align) if wordwrap: textNode.setWordwrap(wordwrap) if bg[3] != 0: textNode.setCardColor(bg[0], bg[1], bg[2], bg[3]) textNode.setCardAsMargin(0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001) if shadow[3] != 0: textNode.setShadowColor(shadow[0], shadow[1], shadow[2], shadow[3]) textNode.setShadow(*shadowOffset) if frame[3] != 0: textNode.setFrameColor(frame[0], frame[1], frame[2], frame[3]) textNode.setFrameAsMargin( 0.10000000000000001, 0.10000000000000001, 0.10000000000000001, 0.10000000000000001 ) mat = Mat4.scaleMat(scale[0], 1, scale[1]) * Mat4.translateMat(pos[0], 0, pos[1]) textNode.setTransform(mat) if drawOrder != None: textNode.setBin("fixed") textNode.setDrawOrder(drawOrder) textNode.setText(text) if not text: self.mayChange = 1 else: self.mayChange = mayChange if self.mayChange: textNode.thaw() else: self.textNode = textNode.generate() self.isClean = 0 self.assign(parent.attachNewNode(self.textNode, sort))
def __init__(self, parent=None, **kw): optiondefs = (('dialogName', 'DirectDialog_' + repr(DirectDialog.PanelIndex), DGG.INITOPT), ('pos', (0, 0.1, 0), None), ('pad', (0.1, 0.1), None), ('text', '', None), ('text_align', TextNode.ALeft, None), ('text_scale', 0.06, None), ('image', DGG.getDefaultDialogGeom(), None), ('relief', None, None), ('buttonTextList', [], DGG.INITOPT), ('buttonGeomList', [], DGG.INITOPT), ('buttonImageList', [], DGG.INITOPT), ('buttonValueList', [], DGG.INITOPT), ('buttonHotKeyList', [], DGG.INITOPT), ('button_borderWidth', (0.01, 0.01), None), ('button_pad', (0.01, 0.01), None), ('button_relief', DGG.RAISED, None), ('button_text_scale', 0.06, None), ('buttonSize', None, DGG.INITOPT), ('topPad', 0.06, DGG.INITOPT), ('midPad', 0.12, DGG.INITOPT), ('sidePad', 0.0, DGG.INITOPT), ('buttonPadSF', 1.1, DGG.INITOPT), ('fadeScreen', 0, None), ('command', None, None), ('extraArgs', [], None), ('sortOrder', NO_FADE_SORT_INDEX, None)) self.defineoptions(kw, optiondefs, dynamicGroups=('button', )) DirectFrame.__init__(self, parent) cleanupDialog(self['dialogName']) DirectDialog.AllDialogs[self['dialogName']] = self DirectDialog.PanelIndex += 1 self.numButtons = max(len(self['buttonTextList']), len(self['buttonGeomList']), len(self['buttonImageList']), len(self['buttonValueList'])) self.buttonList = [] index = 0 for i in range(self.numButtons): name = 'Button' + repr(i) try: text = self['buttonTextList'][i] except IndexError: text = None try: geom = self['buttonGeomList'][i] except IndexError: geom = None try: image = self['buttonImageList'][i] except IndexError: image = None try: value = self['buttonValueList'][i] except IndexError: value = i self['buttonValueList'].append(i) try: hotKey = self['buttonHotKeyList'][i] except IndexError: hotKey = None button = self.createcomponent( name, (), 'button', DirectButton, (self, ), text=text, geom=geom, image=image, suppressKeys=self['suppressKeys'], frameSize=self['buttonSize'], command=lambda s=self, v=value: s.buttonCommand(v)) self.buttonList.append(button) self.postInitialiseFuncList.append(self.configureDialog) self.initialiseoptions(DirectDialog)
def __init__(self, parent = None, **kw): # Inherits from DirectFrame # A Direct Frame can have: # - A background texture (pass in path to image, or Texture Card) # - A midground geometry item (pass in geometry) # - A foreground text Node (pass in text string or Onscreen Text) # For a direct entry: # Each button has 3 states (focus, noFocus, disabled) # The same image/geom/text can be used for all three states or each # state can have a different text/geom/image # State transitions happen automatically based upon mouse interaction optiondefs = ( # Define type of DirectGuiWidget ('pgFunc', PGEntry, None), ('numStates', 3, None), ('state', DGG.NORMAL, None), ('entryFont', None, DGG.INITOPT), ('width', 10, self.setup), ('numLines', 1, self.setup), ('focus', 0, self.setFocus), ('cursorKeys', 1, self.setCursorKeysActive), ('obscured', 0, self.setObscureMode), # Setting backgroundFocus allows the entry box to get keyboard # events that are not handled by other things (i.e. events that # fall through to the background): ('backgroundFocus', 0, self.setBackgroundFocus), # Text used for the PGEntry text node # NOTE: This overrides the DirectFrame text option ('initialText', '', DGG.INITOPT), # Command to be called on hitting Enter ('command', None, None), ('extraArgs', [], None), # Command to be called when enter is hit but we fail to submit ('failedCommand', None, None), ('failedExtraArgs',[], None), # commands to be called when focus is gained or lost ('focusInCommand', None, None), ('focusInExtraArgs', [], None), ('focusOutCommand', None, None), ('focusOutExtraArgs', [], None), # Sounds to be used for button events ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), self.setClickSound), ('autoCapitalize', 0, self.autoCapitalizeFunc), ('autoCapitalizeAllowPrefixes', DirectEntry.AllowCapNamePrefixes, None), ('autoCapitalizeForcePrefixes', DirectEntry.ForceCapNamePrefixes, None), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs) # Initialize superclasses DirectFrame.__init__(self, parent) if self['entryFont'] == None: font = DGG.getDefaultFont() else: font = self['entryFont'] # Create Text Node Component self.onscreenText = self.createcomponent( 'text', (), None, OnscreenText, (), parent = hidden, # Pass in empty text to avoid extra work, since its really # The PGEntry which will use the TextNode to generate geometry text = '', align = TextNode.ALeft, font = font, scale = 1, # Don't get rid of the text node mayChange = 1) # We can get rid of the node path since we're just using the # onscreenText as an easy way to access a text node as a # component self.onscreenText.removeNode() # Bind command function self.bind(DGG.ACCEPT, self.commandFunc) self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc) self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc) self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc) # listen for auto-capitalize events on a separate object to prevent # clashing with other parts of the system self._autoCapListener = DirectObject() # Call option initialization functions self.initialiseoptions(DirectEntry) if not hasattr(self, 'autoCapitalizeAllowPrefixes'): self.autoCapitalizeAllowPrefixes = DirectEntry.AllowCapNamePrefixes if not hasattr(self, 'autoCapitalizeForcePrefixes'): self.autoCapitalizeForcePrefixes = DirectEntry.ForceCapNamePrefixes # Update TextNodes for each state for i in range(self['numStates']): self.guiItem.setTextDef(i, self.onscreenText.textNode) # Now we should call setup() again to make sure it has the # right font def. self.setup() # Update initial text self.unicodeText = 0 if self['initialText']: self.enterText(self['initialText'])
def __init__(self, parent = None, **kw): # Inherits from DirectFrame # A Direct Frame can have: # - A background texture (pass in path to image, or Texture Card) # - A midground geometry item (pass in geometry) # - A foreground text Node (pass in text string or Onscreen Text) # For a direct button: # Each button has 4 states (ready, press, rollover, disabled) # The same image/geom/text can be used for all four states or each # state can have a different text/geom/image # State transitions happen automatically based upon mouse interaction # Responds to click event and calls command if None optiondefs = ( # Define type of DirectGuiWidget ('pgFunc', PGButton, None), ('numStates', 4, None), ('state', DGG.NORMAL, None), ('relief', DGG.RAISED, None), ('invertedFrames', (1,), None), # Command to be called on button click ('command', None, None), ('extraArgs', [], None), # Which mouse buttons can be used to click the button ('commandButtons', (DGG.LMB,), self.setCommandButtons), # Sounds to be used for button events ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound), ('clickSound', DGG.getDefaultClickSound(), 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, DGG.INITOPT), ) # Merge keyword options with default options self.defineoptions(kw, optiondefs) # Initialize superclasses DirectFrame.__init__(self, parent) # If specifed, add scaling to the pressed state to make it # look like the button is moving when you press it. We have # to set up the node first, before we call initialise options; # but we can't actually apply the scale until we have the # bounding volume (which happens during initialise options). pressEffectNP = None if self['pressEffect']: pressEffectNP = self.stateNodePath[1].attachNewNode('pressEffect', 1) self.stateNodePath[1] = pressEffectNP # Call option initialization functions self.initialiseoptions(DirectButton) # Now apply the scale. if pressEffectNP: bounds = self.getBounds() centerX = (bounds[0] + bounds[1]) / 2 centerY = (bounds[2] + bounds[3]) / 2 # Make a matrix that scales about the point mat = Mat4.translateMat(-centerX, 0, -centerY) * \ Mat4.scaleMat(0.98) * \ Mat4.translateMat(centerX, 0, centerY) pressEffectNP.setMat(mat)
def __init__(self, text = '', style = Plain, pos = (0, 0), roll = 0, scale = None, fg = None, bg = None, shadow = None, shadowOffset = (0.04, 0.04), frame = None, align = None, wordwrap = None, drawOrder = None, decal = 0, font = None, parent = None, sort = 0, mayChange = True): if parent == None: parent = aspect2d textNode = TextNode('') self.textNode = textNode NodePath.__init__(self) if style == Plain: if not scale: scale = 0.07 if not fg: fg = (0, 0, 0, 1) if not bg: bg = (0, 0, 0, 0) if not shadow: shadow = (0, 0, 0, 0) if not frame: frame = (0, 0, 0, 0) if align == None: align = TextNode.ACenter elif style == ScreenTitle: if not scale: scale = 0.15 fg = fg or (1, 0.2, 0.2, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 1) frame = frame or (0, 0, 0, 0) align = align == None and TextNode.ACenter elif style == ScreenPrompt: if not scale: scale = 0.1 fg = fg or (1, 1, 0, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 1) frame = frame or (0, 0, 0, 0) align = align == None and TextNode.ACenter elif style == NameConfirm: if not scale: scale = 0.1 fg = fg or (0, 1, 0, 1) bg = bg or (0, 0, 0, 0) shadow = shadow or (0, 0, 0, 0) frame = frame or (0, 0, 0, 0) align = align == None and TextNode.ACenter elif style == BlackOnWhite: if not scale: scale = 0.1 fg = fg or (0, 0, 0, 1) bg = bg or (1, 1, 1, 1) shadow = shadow or (0, 0, 0, 0) frame = frame or (0, 0, 0, 0) align = align == None and TextNode.ACenter else: raise ValueError if not isinstance(scale, types.TupleType): scale = (scale, scale) self.scale = scale self.pos = pos self.roll = roll self.wordwrap = wordwrap if decal: textNode.setCardDecal(1) if font == None: font = DGG.getDefaultFont() textNode.setFont(font) textNode.setTextColor(fg[0], fg[1], fg[2], fg[3]) textNode.setAlign(align) if wordwrap: textNode.setWordwrap(wordwrap) if bg[3] != 0: textNode.setCardColor(bg[0], bg[1], bg[2], bg[3]) textNode.setCardAsMargin(0.1, 0.1, 0.1, 0.1) shadow[3] != 0 and textNode.setShadowColor(shadow[0], shadow[1], shadow[2], shadow[3]) textNode.setShadow(*shadowOffset) frame[3] != 0 and textNode.setFrameColor(frame[0], frame[1], frame[2], frame[3]) textNode.setFrameAsMargin(0.1, 0.1, 0.1, 0.1) self.updateTransformMat() drawOrder != None and textNode.setBin('fixed') textNode.setDrawOrder(drawOrder) self.setText(text) self.mayChange = text or 1 else: self.mayChange = mayChange self.textNode = self.mayChange or textNode.generate() self.isClean = 0 self.assign(parent.attachNewNode(self.textNode, sort)) return
pollingDelay = 0.5 if launcher: print 'ToontownStart: Polling for game2 to finish...' while not launcher.getGame2Done(): time.sleep(pollingDelay) print 'ToontownStart: Game2 is finished.' print 'ToontownStart: Starting the game.' from PandaModules import * tempLoader = PandaLoader() backgroundNode = tempLoader.loadSync(Filename('phase_3/models/gui/loading-background')) import DirectGuiGlobals print 'ToontownStart: setting default font' import ToontownGlobals DirectGuiGlobals.setDefaultFontFunc(ToontownGlobals.getInterfaceFont) if launcher: launcher.setPandaErrorCode(7) from ShowBaseGlobal import * if base.win == None: print 'Unable to open window; aborting.' sys.exit() if launcher: launcher.setPandaErrorCode(0) launcher.setPandaWindowOpen() backgroundNodePath = aspect2d.attachNewNode(backgroundNode, 0) backgroundNodePath.setPos(0.0, 0.0, 0.0) backgroundNodePath.setScale(render2d, VBase3(1))