class PartyEditor(DirectObject, FSM): notify = directNotify.newCategory('PartyEditor') def __init__(self, partyPlanner, parent): FSM.__init__(self, self.__class__.__name__) self.partyPlanner = partyPlanner self.parent = parent self.partyEditorGrid = PartyEditorGrid(self) self.currentElement = None self.defaultTransitions = {'Hidden': ['Idle', 'Cleanup'], 'Idle': ['DraggingElement', 'Hidden', 'Cleanup'], 'DraggingElement': ['Idle', 'DraggingElement', 'Hidden', 'Cleanup'], 'Cleanup': []} self.initElementList() self.initPartyClock() self.initTrashCan() return def initElementList(self): self.activityIconsModel = loader.loadModel('phase_4/models/parties/eventSignIcons') self.decorationModels = loader.loadModel('phase_4/models/parties/partyDecorations') pos = self.partyPlanner.gui.find('**/step_05_activitiesIcon_locator').getPos() self.elementList = DirectScrolledList(parent=self.parent, relief=None, decButton_image=(self.partyPlanner.gui.find('**/activitiesButtonUp_up'), self.partyPlanner.gui.find('**/activitiesButtonUp_down'), self.partyPlanner.gui.find('**/activitiesButtonUp_rollover'), self.partyPlanner.gui.find('**/activitiesButtonUp_inactive')), decButton_relief=None, decButton_pos=(-0.05, 0.0, -0.38), incButton_image=(self.partyPlanner.gui.find('**/activitiesButtonDown_up'), self.partyPlanner.gui.find('**/activitiesButtonDown_down'), self.partyPlanner.gui.find('**/activitiesButtonDown_rollover'), self.partyPlanner.gui.find('**/activitiesButtonDown_inactive')), incButton_relief=None, incButton_pos=(-0.05, 0.0, -0.94), itemFrame_pos=(pos[0], pos[1], pos[2] + 0.04), itemFrame_relief=None, numItemsVisible=1, items=[]) holidayIds = base.cr.newsManager.getHolidayIdList() isWinter = ToontownGlobals.WINTER_DECORATIONS in holidayIds or ToontownGlobals.WACKY_WINTER_DECORATIONS in holidayIds isVictory = ToontownGlobals.VICTORY_PARTY_HOLIDAY in holidayIds isValentine = ToontownGlobals.VALENTINES_DAY in holidayIds for activityId in PartyGlobals.PartyEditorActivityOrder: if not isVictory and activityId in PartyGlobals.VictoryPartyActivityIds or not isWinter and activityId in PartyGlobals.WinterPartyActivityIds or not isValentine and activityId in PartyGlobals.ValentinePartyActivityIds: pass elif isVictory and activityId in PartyGlobals.VictoryPartyReplacementActivityIds or isWinter and activityId in PartyGlobals.WinterPartyReplacementActivityIds or isValentine and activityId in PartyGlobals.ValentinePartyReplacementActivityIds: pass else: pele = PartyEditorListElement(self, activityId) self.elementList.addItem(pele) if activityId == PartyGlobals.ActivityIds.PartyClock: self.partyClockElement = pele for decorationId in PartyGlobals.DecorationIds: if not isVictory and decorationId in PartyGlobals.VictoryPartyDecorationIds or not isWinter and decorationId in PartyGlobals.WinterPartyDecorationIds or not isValentine and decorationId in PartyGlobals.ValentinePartyDecorationIds: pass elif isVictory and decorationId in PartyGlobals.VictoryPartyReplacementDecorationIds or isValentine and decorationId in PartyGlobals.ValentinePartyReplacementDecorationIds: pass elif decorationId in PartyGlobals.TTIUnreleasedDecor: pass else: pele = PartyEditorListElement(self, decorationId, isDecoration=True) self.elementList.addItem(pele) self.elementList.refresh() self.elementList['command'] = self.scrollItemChanged return def initPartyClock(self): self.partyClockElement.buyButtonClicked((8, 7)) def initTrashCan(self): trashcanGui = loader.loadModel('phase_3/models/gui/trashcan_gui') self.trashCanButton = DirectButton(parent=self.parent, relief=None, pos=Point3(*PartyGlobals.TrashCanPosition), scale=PartyGlobals.TrashCanScale, geom=(trashcanGui.find('**/TrashCan_CLSD'), trashcanGui.find('**/TrashCan_OPEN'), trashcanGui.find('**/TrashCan_RLVR'), trashcanGui.find('**/TrashCan_RLVR')), command=self.trashCanClicked) self.trashCanButton.bind(DirectGuiGlobals.ENTER, self.mouseEnterTrash) self.trashCanButton.bind(DirectGuiGlobals.EXIT, self.mouseExitTrash) self.mouseOverTrash = False self.oldInstructionText = '' self.trashCanLastClickedTime = 0 return def scrollItemChanged(self): if not self.elementList['items']: return self.currentElement = self.elementList['items'][self.elementList.getSelectedIndex()] self.elementList['items'][self.elementList.getSelectedIndex()].elementSelectedFromList() if self.elementList['items'][self.elementList.getSelectedIndex()].isDecoration: self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsClickedElementDecoration else: self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsClickedElementActivity def listElementClicked(self): self.request('DraggingElement') def listElementReleased(self): self.request('Idle', True) def trashCanClicked(self): currentTime = time.time() if currentTime - self.trashCanLastClickedTime < 0.2: self.clearPartyGrounds() self.trashCanLastClickedTime = time.time() def clearPartyGrounds(self): for item in self.elementList['items']: item.clearPartyGrounds() self.initPartyClock() if self.currentElement: self.currentElement.checkSoldOutAndPaidStatusAndAffordability() def buyCurrentElement(self): if self.currentElement: purchaseSuccessful = self.currentElement.buyButtonClicked() if purchaseSuccessful: self.handleMutuallyExclusiveActivities() else: self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsNoRoom def mouseEnterTrash(self, mouseEvent): self.mouseOverTrash = True self.oldInstructionText = self.partyPlanner.instructionLabel['text'] self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsTrash def mouseExitTrash(self, mouseEvent): self.mouseOverTrash = False self.partyPlanner.instructionLabel['text'] = self.oldInstructionText def enterHidden(self): PartyEditor.notify.debug('Enter Hidden') def exitHidden(self): PartyEditor.notify.debug('Exit Hidden') def enterIdle(self, fromDragging = False): PartyEditor.notify.debug('Enter Idle') if not fromDragging: self.elementList.scrollTo(0) self.elementList['items'][0].elementSelectedFromList() self.currentElement = self.elementList['items'][self.elementList.getSelectedIndex()] self.currentElement.checkSoldOutAndPaidStatusAndAffordability() self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsIdle self.updateCostsAndBank() self.handleMutuallyExclusiveActivities() def handleMutuallyExclusiveActivities(self): mutSet = self.getMutuallyExclusiveActivities() if not mutSet: return currentActivities = self.partyEditorGrid.getActivitiesElementsOnGrid() lastActivity = self.partyEditorGrid.lastActivityIdPlaced for act in currentActivities: if act.id in mutSet and not lastActivity == act.id: act.removeFromGrid() removedName = TTLocalizer.PartyActivityNameDict[act.id]['editor'] addedName = TTLocalizer.PartyActivityNameDict[lastActivity]['editor'] instr = TTLocalizer.PartyPlannerEditorInstructionsRemoved % {'removed': removedName, 'added': addedName} self.partyPlanner.instructionLabel['text'] = instr self.updateCostsAndBank() def getMutuallyExclusiveActivities(self): currentActivities = self.partyEditorGrid.getActivitiesOnGrid() actSet = Set([]) for act in currentActivities: actSet.add(act[0]) result = None for mutuallyExclusiveTuples in PartyGlobals.MutuallyExclusiveActivities: mutSet = Set(mutuallyExclusiveTuples) inter = mutSet.intersection(actSet) if len(inter) > 1: result = inter break return result def updateCostsAndBank(self): currentActivities = self.partyEditorGrid.getActivitiesOnGrid() currentDecorations = self.partyEditorGrid.getDecorationsOnGrid() newCost = 0 for elementTuple in currentActivities: newCost += PartyGlobals.ActivityInformationDict[elementTuple[0]]['cost'] for elementTuple in currentDecorations: newCost += PartyGlobals.DecorationInformationDict[elementTuple[0]]['cost'] self.partyPlanner.costLabel['text'] = TTLocalizer.PartyPlannerTotalCost % newCost if len(currentActivities) > 0 or len(currentDecorations) > 0: self.partyPlanner.setNextButtonState(enabled=True) else: self.partyPlanner.setNextButtonState(enabled=False) self.partyPlanner.totalCost = newCost self.partyPlanner.beanBank['text'] = str(int(self.partyPlanner.totalMoney - self.partyPlanner.totalCost)) def exitIdle(self): PartyEditor.notify.debug('Exit Idle') def enterDraggingElement(self): PartyEditor.notify.debug('Enter DraggingElement') if self.currentElement.isDecoration: self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsDraggingDecoration else: self.partyPlanner.instructionLabel['text'] = TTLocalizer.PartyPlannerEditorInstructionsDraggingActivity def exitDraggingElement(self): PartyEditor.notify.debug('Exit DraggingElement') def enterCleanup(self): PartyEditor.notify.debug('Enter Cleanup') self.partyEditorGrid.destroy() self.elementList.removeAndDestroyAllItems() self.elementList.destroy() self.trashCanButton.unbind(DirectGuiGlobals.ENTER) self.trashCanButton.unbind(DirectGuiGlobals.EXIT) self.trashCanButton.destroy() def exitCleanup(self): PartyEditor.notify.debug('Exit Cleanup')
class PartyEditor(DirectObject, FSM): """ This class creates the grid and scrolled list needed for players to drag and drop activities and decorations onto their party grounds. """ notify = directNotify.newCategory("PartyEditor") def __init__(self, partyPlanner, parent): FSM.__init__(self, self.__class__.__name__) self.partyPlanner = partyPlanner self.parent = parent self.partyEditorGrid = PartyEditorGrid(self) self.currentElement = None self.defaultTransitions = { "Hidden": ["Idle", "Cleanup"], "Idle": ["DraggingElement", "Hidden", "Cleanup"], "DraggingElement": ["Idle", "DraggingElement", "Hidden", "Cleanup"], "Cleanup": [], } self.initElementList() self.initPartyClock() self.initTrashCan() def initElementList(self): self.activityIconsModel = loader.loadModel( "phase_4/models/parties/eventSignIcons") self.decorationModels = loader.loadModel( "phase_4/models/parties/partyDecorations") pos = self.partyPlanner.gui.find( "**/step_05_activitiesIcon_locator").getPos() self.elementList = DirectScrolledList( parent=self.parent, relief=None, # inc and dec are DirectButtons decButton_image=( self.partyPlanner.gui.find("**/activitiesButtonUp_up"), self.partyPlanner.gui.find("**/activitiesButtonUp_down"), self.partyPlanner.gui.find("**/activitiesButtonUp_rollover"), self.partyPlanner.gui.find("**/activitiesButtonUp_inactive"), ), decButton_relief=None, decButton_pos=(-0.05, 0.0, -0.38), incButton_image=( self.partyPlanner.gui.find("**/activitiesButtonDown_up"), self.partyPlanner.gui.find("**/activitiesButtonDown_down"), self.partyPlanner.gui.find("**/activitiesButtonDown_rollover"), self.partyPlanner.gui.find("**/activitiesButtonDown_inactive"), ), incButton_relief=None, incButton_pos=(-0.05, 0.0, -0.94), # itemFrame is a DirectFrame itemFrame_pos=(pos[0], pos[1], pos[2] + 0.04), itemFrame_relief=None, # each item is a button with text on it numItemsVisible=1, items=[], ) for activityId in PartyGlobals.PartyEditorActivityOrder: if activityId in PartyGlobals.VictoryPartyActivityIds: holidayIds = base.cr.newsManager.getHolidayIdList() if ToontownGlobals.VICTORY_PARTY_HOLIDAY in holidayIds: pele = PartyEditorListElement(self, activityId) self.elementList.addItem(pele) elif activityId in PartyGlobals.VictoryPartyReplacementActivityIds: holidayIds = base.cr.newsManager.getHolidayIdList() if not ToontownGlobals.VICTORY_PARTY_HOLIDAY in holidayIds: pele = PartyEditorListElement(self, activityId) self.elementList.addItem(pele) else: pele = PartyEditorListElement(self, activityId) self.elementList.addItem(pele) if activityId == PartyGlobals.ActivityIds.PartyClock: self.partyClockElement = pele for decorationId in PartyGlobals.DecorationIds: decorName = PartyGlobals.DecorationIds.getString(decorationId) if (decorName == "HeartTarget") \ or (decorName == "HeartBanner") \ or (decorName == "FlyingHeart"): holidayIds = base.cr.newsManager.getHolidayIdList() if ToontownGlobals.VALENTINES_DAY in holidayIds: pele = PartyEditorListElement(self, decorationId, isDecoration=True) self.elementList.addItem(pele) elif decorationId in PartyGlobals.VictoryPartyDecorationIds: holidayIds = base.cr.newsManager.getHolidayIdList() if ToontownGlobals.VICTORY_PARTY_HOLIDAY in holidayIds: pele = PartyEditorListElement(self, decorationId, isDecoration=True) self.elementList.addItem(pele) elif decorationId in PartyGlobals.VictoryPartyReplacementDecorationIds: holidayIds = base.cr.newsManager.getHolidayIdList() if not ToontownGlobals.VICTORY_PARTY_HOLIDAY in holidayIds: pele = PartyEditorListElement(self, decorationId, isDecoration=True) self.elementList.addItem(pele) else: pele = PartyEditorListElement(self, decorationId, isDecoration=True) self.elementList.addItem(pele) self.elementList.refresh() self.elementList['command'] = self.scrollItemChanged def initPartyClock(self): self.partyClockElement.buyButtonClicked((8, 7)) def initTrashCan(self): trashcanGui = loader.loadModel("phase_3/models/gui/trashcan_gui") self.trashCanButton = DirectButton( parent=self.parent, relief=None, pos=Point3(*PartyGlobals.TrashCanPosition), scale=PartyGlobals.TrashCanScale, geom=( trashcanGui.find("**/TrashCan_CLSD"), trashcanGui.find("**/TrashCan_OPEN"), trashcanGui.find("**/TrashCan_RLVR"), trashcanGui.find("**/TrashCan_RLVR"), ), command=self.trashCanClicked, ) self.trashCanButton.bind(DirectGuiGlobals.ENTER, self.mouseEnterTrash) self.trashCanButton.bind(DirectGuiGlobals.EXIT, self.mouseExitTrash) self.mouseOverTrash = False self.oldInstructionText = "" self.trashCanLastClickedTime = 0 def scrollItemChanged(self): if not self.elementList["items"]: # we are probably closing the gui, do nothing return self.currentElement = self.elementList["items"][ self.elementList.getSelectedIndex()] self.elementList["items"][ self.elementList.getSelectedIndex()].elementSelectedFromList() if self.elementList["items"][ self.elementList.getSelectedIndex()].isDecoration: self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsClickedElementDecoration else: self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsClickedElementActivity def listElementClicked(self): self.request("DraggingElement") def listElementReleased(self): self.request("Idle", True) def trashCanClicked(self): currentTime = time.time() # Check for double click, if so, clear the party grounds if currentTime - self.trashCanLastClickedTime < 0.2: self.clearPartyGrounds() self.trashCanLastClickedTime = time.time() def clearPartyGrounds(self): for item in self.elementList["items"]: item.clearPartyGrounds() self.initPartyClock() if self.currentElement: self.currentElement.checkSoldOutAndPaidStatusAndAffordability() def buyCurrentElement(self): if self.currentElement: purchaseSuccessful = self.currentElement.buyButtonClicked() if purchaseSuccessful: # The buying and placement of the item was successful self.handleMutuallyExclusiveActivities() pass else: # The buying and placement of the item was not successful self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsNoRoom def mouseEnterTrash(self, mouseEvent): self.mouseOverTrash = True self.oldInstructionText = self.partyPlanner.instructionLabel["text"] self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsTrash def mouseExitTrash(self, mouseEvent): self.mouseOverTrash = False self.partyPlanner.instructionLabel["text"] = self.oldInstructionText ### FSM Methods ### def enterHidden(self): PartyEditor.notify.debug("Enter Hidden") def exitHidden(self): PartyEditor.notify.debug("Exit Hidden") def enterIdle(self, fromDragging=False): PartyEditor.notify.debug("Enter Idle") if not fromDragging: self.elementList.scrollTo(0) self.elementList["items"][0].elementSelectedFromList() self.currentElement = self.elementList["items"][ self.elementList.getSelectedIndex()] self.currentElement.checkSoldOutAndPaidStatusAndAffordability() self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsIdle self.updateCostsAndBank() self.handleMutuallyExclusiveActivities() def handleMutuallyExclusiveActivities(self): """Smartly removed the older activity and inform the user.""" mutSet = self.getMutuallyExclusiveActivities() if not mutSet: return # our mutset doesn't tell us which one is older currentActivities = self.partyEditorGrid.getActivitiesElementsOnGrid() lastActivity = self.partyEditorGrid.lastActivityIdPlaced for act in currentActivities: if (act.id in mutSet) and not (lastActivity == act.id): act.removeFromGrid() removedName = TTLocalizer.PartyActivityNameDict[ act.id]["editor"] addedName = TTLocalizer.PartyActivityNameDict[lastActivity][ "editor"] instr = TTLocalizer.PartyPlannerEditorInstructionsRemoved % \ {"removed" : removedName, "added" : addedName} self.partyPlanner.instructionLabel["text"] = instr self.updateCostsAndBank() # deliberately no break here, in case they manage to # get 3 jukeboxes into the editor somehow def getMutuallyExclusiveActivities(self): """Return the set of activities on the grid that are mutually exclusive, None otherwise.""" # create a set of activity Ids currentActivities = self.partyEditorGrid.getActivitiesOnGrid() actSet = Set([]) for act in currentActivities: actSet.add(act[0]) result = None for mutuallyExclusiveTuples in PartyGlobals.MutuallyExclusiveActivities: mutSet = Set(mutuallyExclusiveTuples) inter = mutSet.intersection(actSet) if len(inter) > 1: result = inter break return result def updateCostsAndBank(self): """ We need to update the total cost of the party and what they will have left in their bank. """ currentActivities = self.partyEditorGrid.getActivitiesOnGrid() currentDecorations = self.partyEditorGrid.getDecorationsOnGrid() newCost = 0 for elementTuple in currentActivities: newCost += PartyGlobals.ActivityInformationDict[ elementTuple[0]]["cost"] for elementTuple in currentDecorations: newCost += PartyGlobals.DecorationInformationDict[ elementTuple[0]]["cost"] self.partyPlanner.costLabel[ "text"] = TTLocalizer.PartyPlannerTotalCost % newCost if len(currentActivities) > 0 or len(currentDecorations) > 0: self.partyPlanner.setNextButtonState(enabled=True) else: self.partyPlanner.setNextButtonState(enabled=False) self.partyPlanner.totalCost = newCost self.partyPlanner.beanBank["text"] = str( int(self.partyPlanner.totalMoney - self.partyPlanner.totalCost)) def exitIdle(self): PartyEditor.notify.debug("Exit Idle") def enterDraggingElement(self): PartyEditor.notify.debug("Enter DraggingElement") if self.currentElement.isDecoration: self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsDraggingDecoration else: self.partyPlanner.instructionLabel[ "text"] = TTLocalizer.PartyPlannerEditorInstructionsDraggingActivity def exitDraggingElement(self): PartyEditor.notify.debug("Exit DraggingElement") def enterCleanup(self): PartyEditor.notify.debug("Enter Cleanup") self.partyEditorGrid.destroy() self.elementList.removeAndDestroyAllItems() self.elementList.destroy() self.trashCanButton.unbind(DirectGuiGlobals.ENTER) self.trashCanButton.unbind(DirectGuiGlobals.EXIT) self.trashCanButton.destroy() def exitCleanup(self): PartyEditor.notify.debug("Exit Cleanup")
class CannonGui(DirectObject): notify = directNotify.newCategory('CannonGui') FIRE_KEY = base.JUMP UP_KEY = base.MOVE_UP DOWN_KEY = base.MOVE_DOWN LEFT_KEY = base.MOVE_LEFT RIGHT_KEY = base.MOVE_RIGHT FIRE_PRESSED = 'cannongui_fire_pressed' def __init__(self): self.__loaded = False self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.__aimPad = None self.__timerPad = None return def load(self): if self.__loaded: return self.__timerPad = PartyUtils.getNewToontownTimer() guiModel = 'phase_4/models/gui/cannon_game_gui' guiNode = loader.loadModel(guiModel) self.__aimPad = DirectFrame(image=guiNode.find('**/CannonFire_PAD'), relief=None, pos=(0.7, 0, -0.553333), scale=0.8) guiNode.removeNode() self.fireButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Fire_Btn_UP'), (guiModel, '**/Fire_Btn_DN'), (guiModel, '**/Fire_Btn_RLVR')), relief=None, pos=(0.0115741, 0, 0.00505051), scale=1.0, command=self.__firePressed) self.upButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0115741, 0, 0.221717)) self.downButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0136112, 0, -0.210101), image_hpr=(0, 0, 180)) self.leftButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(-0.199352, 0, -0.000505269), image_hpr=(0, 0, -90)) self.rightButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.219167, 0, -0.00101024), image_hpr=(0, 0, 90)) self.__aimPad.setColor(1, 1, 1, 0.9) def bindButton(button, upHandler, downHandler): button.bind(DGG.B1PRESS, lambda x, handler = upHandler: handler()) button.bind(DGG.B1RELEASE, lambda x, handler = downHandler: handler()) bindButton(self.upButton, self.__upPressed, self.__upReleased) bindButton(self.downButton, self.__downPressed, self.__downReleased) bindButton(self.leftButton, self.__leftPressed, self.__leftReleased) bindButton(self.rightButton, self.__rightPressed, self.__rightReleased) self.__loaded = True return def unload(self): self.ignoreAll() if not self.__loaded: return self.disable() self.upButton.unbind(DGG.B1PRESS) self.upButton.unbind(DGG.B1RELEASE) self.downButton.unbind(DGG.B1PRESS) self.downButton.unbind(DGG.B1RELEASE) self.leftButton.unbind(DGG.B1PRESS) self.leftButton.unbind(DGG.B1RELEASE) self.rightButton.unbind(DGG.B1PRESS) self.rightButton.unbind(DGG.B1RELEASE) self.fireButton.destroy() self.__aimPad.destroy() del self.__aimPad del self.fireButton del self.upButton del self.downButton del self.leftButton del self.rightButton self.__timerPad.destroy() del self.__timerPad self.__loaded = False def enable(self, timer = 0): self.__aimPad.show() base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0) base.setCellsAvailable([base.rightCells[1]], 0) if timer > 0: self.__timerPad.setTime(timer) self.__timerPad.countdown(timer) self.__timerPad.show() self.enableKeys() def disable(self): self.__aimPad.hide() base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1) base.setCellsAvailable([base.rightCells[1]], 1) self.__timerPad.hide() self.disableKeys() def enableKeys(self): self.enableAimKeys() self.enableFireKey() def disableKeys(self): self.__aimPad.hide() self.disableAimKeys() self.disableFireKey() def enableAimKeys(self): self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.accept(self.UP_KEY, self.__upKeyPressed) self.accept(self.DOWN_KEY, self.__downKeyPressed) self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.accept(self.RIGHT_KEY, self.__rightKeyPressed) def disableAimKeys(self): self.ignore(self.UP_KEY) self.ignore(self.DOWN_KEY) self.ignore(self.LEFT_KEY) self.ignore(self.RIGHT_KEY) messenger.send(self.UP_KEY + '-up') messenger.send(self.DOWN_KEY + '-up') messenger.send(self.LEFT_KEY + '-up') messenger.send(self.RIGHT_KEY + '-up') self.ignore(self.UP_KEY + '-up') self.ignore(self.DOWN_KEY + '-up') self.ignore(self.LEFT_KEY + '-up') self.ignore(self.RIGHT_KEY + '-up') def enableFireKey(self): self.accept(self.FIRE_KEY, self.__fireKeyPressed) def disableFireKey(self): self.ignore(self.FIRE_KEY) self.ignore(self.FIRE_KEY + '-up') def __fireKeyPressed(self): self.ignore(self.FIRE_KEY) self.accept(self.FIRE_KEY + '-up', self.__fireKeyReleased) self.__firePressed() def __upKeyPressed(self): self.ignore(self.UP_KEY) self.accept(self.UP_KEY + '-up', self.__upKeyReleased) self.__upPressed() def __downKeyPressed(self): self.ignore(self.DOWN_KEY) self.accept(self.DOWN_KEY + '-up', self.__downKeyReleased) self.__downPressed() def __leftKeyPressed(self): self.ignore(self.LEFT_KEY) self.accept(self.LEFT_KEY + '-up', self.__leftKeyReleased) self.__leftPressed() def __rightKeyPressed(self): self.ignore(self.RIGHT_KEY) self.accept(self.RIGHT_KEY + '-up', self.__rightKeyReleased) self.__rightPressed() def __fireKeyReleased(self): self.ignore(self.FIRE_KEY + '-up') self.accept(self.FIRE_KEY, self.__fireKeyPressed) def __leftKeyReleased(self): self.ignore(self.LEFT_KEY + '-up') self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.__leftReleased() def __rightKeyReleased(self): self.ignore(self.RIGHT_KEY + '-up') self.accept(self.RIGHT_KEY, self.__rightKeyPressed) self.__rightReleased() def __upKeyReleased(self): self.ignore(self.UP_KEY + '-up') self.accept(self.UP_KEY, self.__upKeyPressed) self.__upReleased() def __downKeyReleased(self): self.ignore(self.DOWN_KEY + '-up') self.accept(self.DOWN_KEY, self.__downKeyPressed) self.__downReleased() def __upPressed(self): self.notify.debug('up pressed') self.upPressed = self.__enterControlActive(self.upPressed) def __downPressed(self): self.notify.debug('down pressed') self.downPressed = self.__enterControlActive(self.downPressed) def __leftPressed(self): self.notify.debug('left pressed') self.leftPressed = self.__enterControlActive(self.leftPressed) def __rightPressed(self): self.notify.debug('right pressed') self.rightPressed = self.__enterControlActive(self.rightPressed) def __upReleased(self): self.notify.debug('up released') self.upPressed = self.__exitControlActive(self.upPressed) def __downReleased(self): self.notify.debug('down released') self.downPressed = self.__exitControlActive(self.downPressed) def __leftReleased(self): self.notify.debug('left released') self.leftPressed = self.__exitControlActive(self.leftPressed) def __rightReleased(self): self.notify.debug('right released') self.rightPressed = self.__exitControlActive(self.rightPressed) def __firePressed(self): self.notify.debug('fire pressed') messenger.send(CannonGui.FIRE_PRESSED) def __enterControlActive(self, control): return control + 1 def __exitControlActive(self, control): return max(0, control - 1)
def render(self): ''' traverse the tree and update the visuals according to it ''' for treeItem in self.treeStructure.getRec(): # create nodes that have no visual elements if not treeItem in self.treeStructureNodes: treeNode = self.childrenCanvas.attachNewNode('') hor=self.horizontalTreeLine.instanceUnderNode(treeNode,'') vert=self.verticalTreeLine.instanceUnderNode(treeNode,'') vert.setZ(0.007) hor.setPos(-1.5*self.itemIndent,0,self.itemScale*.25) vert.setX(-.5*self.itemIndent) nodeButton = DirectButton( parent=treeNode, scale=self.itemScale, relief=DGG.FLAT, text_scale=self.itemTextScale, text_align=TextNode.ALeft, text=treeItem.name, rolloverSound=None, #clickSound=None, ) nodeButton.bind(DGG.B1PRESS,treeItem.button1press) nodeButton.bind(DGG.B2PRESS,treeItem.button2press) nodeButton.bind(DGG.B3PRESS,treeItem.button3press) #treeButton = None #if len(treeItem.childrens) > 0: treeButton = DirectButton( parent=nodeButton, frameColor=(1,1,1,1), frameSize=(-.4,.4,-.4,.4), pos=(-.5*self.itemIndent/self.itemScale,0,.25), text='', text_pos=(-.1,-.22), text_scale=(1.6,1), text_fg=(0,0,0,1), enableEdit=0, command=treeItem.setOpen, sortOrder=1000, rolloverSound=None, #clickSound=None, ) self.treeStructureNodes[treeItem] = [treeNode, nodeButton, treeButton, hor, vert] # destroy nodes no more used for treeItem in self.treeStructureNodes.keys()[:]: #treeItem = self.treeStructureNodes[treeName] if treeItem not in self.treeStructure.getRec(): treeNode, nodeButton, treeButton, hor, vert = self.treeStructureNodes[treeItem] #nodeButton['text']='' nodeButton.unbind(DGG.B1PRESS) nodeButton.unbind(DGG.B2PRESS) nodeButton.unbind(DGG.B3PRESS) #nodeButton.detachNode() #nodeButton.removeNode() nodeButton.destroy() if treeButton: #treeButton['text']='' #treeButton['command']=None treeButton.detachNode() treeButton.removeNode() hor.detachNode() hor.removeNode() vert.detachNode() vert.removeNode() treeItem.destroy() #treeNode.detachNode() treeNode.removeNode() #treeNode.destroy() del self.treeStructureNodes[treeItem] frameHeight = len(self.treeStructureNodes) * self.verticalSpacing self.childrenFrame['canvasSize'] = (0, self.frameWidth-self.itemScale*2, 0, frameHeight) self.childrenCanvas.setZ(frameHeight-1)
class CannonGui(DirectObject): notify = directNotify.newCategory('CannonGui') FIRE_KEY = 'control' UP_KEY = 'arrow_up' DOWN_KEY = 'arrow_down' LEFT_KEY = 'arrow_left' RIGHT_KEY = 'arrow_right' FIRE_PRESSED = 'cannongui_fire_pressed' def __init__(self): self.__loaded = False self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.__aimPad = None self.__timerPad = None return def load(self): if self.__loaded: return self.__timerPad = PartyUtils.getNewToontownTimer() guiModel = 'phase_4/models/gui/cannon_game_gui' guiNode = loader.loadModel(guiModel) self.__aimPad = DirectFrame(image=guiNode.find('**/CannonFire_PAD'), relief=None, pos=(0.7, 0, -0.553333), scale=0.8) guiNode.removeNode() self.fireButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Fire_Btn_UP'), (guiModel, '**/Fire_Btn_DN'), (guiModel, '**/Fire_Btn_RLVR')), relief=None, pos=(0.0115741, 0, 0.00505051), scale=1.0, command=self.__firePressed) self.upButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0115741, 0, 0.221717)) self.downButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0136112, 0, -0.210101), image_hpr=(0, 0, 180)) self.leftButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(-0.199352, 0, -0.000505269), image_hpr=(0, 0, -90)) self.rightButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.219167, 0, -0.00101024), image_hpr=(0, 0, 90)) self.__aimPad.setColor(1, 1, 1, 0.9) def bindButton(button, upHandler, downHandler): button.bind(DGG.B1PRESS, lambda x, handler = upHandler: handler()) button.bind(DGG.B1RELEASE, lambda x, handler = downHandler: handler()) bindButton(self.upButton, self.__upPressed, self.__upReleased) bindButton(self.downButton, self.__downPressed, self.__downReleased) bindButton(self.leftButton, self.__leftPressed, self.__leftReleased) bindButton(self.rightButton, self.__rightPressed, self.__rightReleased) self.__loaded = True return def unload(self): self.ignoreAll() if not self.__loaded: return self.disable() self.upButton.unbind(DGG.B1PRESS) self.upButton.unbind(DGG.B1RELEASE) self.downButton.unbind(DGG.B1PRESS) self.downButton.unbind(DGG.B1RELEASE) self.leftButton.unbind(DGG.B1PRESS) self.leftButton.unbind(DGG.B1RELEASE) self.rightButton.unbind(DGG.B1PRESS) self.rightButton.unbind(DGG.B1RELEASE) self.fireButton.destroy() self.__aimPad.destroy() del self.__aimPad del self.fireButton del self.upButton del self.downButton del self.leftButton del self.rightButton self.__timerPad.destroy() del self.__timerPad self.__loaded = False def enable(self, timer = 0): self.__aimPad.show() base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0) base.setCellsAvailable([base.rightCells[1]], 0) if timer > 0: self.__timerPad.setTime(timer) self.__timerPad.countdown(timer) self.__timerPad.show() self.enableKeys() def disable(self): self.__aimPad.hide() base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1) base.setCellsAvailable([base.rightCells[1]], 1) self.__timerPad.hide() self.disableKeys() def enableKeys(self): self.enableAimKeys() self.enableFireKey() def disableKeys(self): self.__aimPad.hide() self.disableAimKeys() self.disableFireKey() def enableAimKeys(self): self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.accept(self.UP_KEY, self.__upKeyPressed) self.accept(self.DOWN_KEY, self.__downKeyPressed) self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.accept(self.RIGHT_KEY, self.__rightKeyPressed) def disableAimKeys(self): self.ignore(self.UP_KEY) self.ignore(self.DOWN_KEY) self.ignore(self.LEFT_KEY) self.ignore(self.RIGHT_KEY) messenger.send(self.UP_KEY + '-up') messenger.send(self.DOWN_KEY + '-up') messenger.send(self.LEFT_KEY + '-up') messenger.send(self.RIGHT_KEY + '-up') self.ignore(self.UP_KEY + '-up') self.ignore(self.DOWN_KEY + '-up') self.ignore(self.LEFT_KEY + '-up') self.ignore(self.RIGHT_KEY + '-up') def enableFireKey(self): self.accept(self.FIRE_KEY, self.__fireKeyPressed) def disableFireKey(self): self.ignore(self.FIRE_KEY) self.ignore(self.FIRE_KEY + '-up') def __fireKeyPressed(self): self.ignore(self.FIRE_KEY) self.accept(self.FIRE_KEY + '-up', self.__fireKeyReleased) self.__firePressed() def __upKeyPressed(self): self.ignore(self.UP_KEY) self.accept(self.UP_KEY + '-up', self.__upKeyReleased) self.__upPressed() def __downKeyPressed(self): self.ignore(self.DOWN_KEY) self.accept(self.DOWN_KEY + '-up', self.__downKeyReleased) self.__downPressed() def __leftKeyPressed(self): self.ignore(self.LEFT_KEY) self.accept(self.LEFT_KEY + '-up', self.__leftKeyReleased) self.__leftPressed() def __rightKeyPressed(self): self.ignore(self.RIGHT_KEY) self.accept(self.RIGHT_KEY + '-up', self.__rightKeyReleased) self.__rightPressed() def __fireKeyReleased(self): self.ignore(self.FIRE_KEY + '-up') self.accept(self.FIRE_KEY, self.__fireKeyPressed) def __leftKeyReleased(self): self.ignore(self.LEFT_KEY + '-up') self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.__leftReleased() def __rightKeyReleased(self): self.ignore(self.RIGHT_KEY + '-up') self.accept(self.RIGHT_KEY, self.__rightKeyPressed) self.__rightReleased() def __upKeyReleased(self): self.ignore(self.UP_KEY + '-up') self.accept(self.UP_KEY, self.__upKeyPressed) self.__upReleased() def __downKeyReleased(self): self.ignore(self.DOWN_KEY + '-up') self.accept(self.DOWN_KEY, self.__downKeyPressed) self.__downReleased() def __upPressed(self): self.notify.debug('up pressed') self.upPressed = self.__enterControlActive(self.upPressed) def __downPressed(self): self.notify.debug('down pressed') self.downPressed = self.__enterControlActive(self.downPressed) def __leftPressed(self): self.notify.debug('left pressed') self.leftPressed = self.__enterControlActive(self.leftPressed) def __rightPressed(self): self.notify.debug('right pressed') self.rightPressed = self.__enterControlActive(self.rightPressed) def __upReleased(self): self.notify.debug('up released') self.upPressed = self.__exitControlActive(self.upPressed) def __downReleased(self): self.notify.debug('down released') self.downPressed = self.__exitControlActive(self.downPressed) def __leftReleased(self): self.notify.debug('left released') self.leftPressed = self.__exitControlActive(self.leftPressed) def __rightReleased(self): self.notify.debug('right released') self.rightPressed = self.__exitControlActive(self.rightPressed) def __firePressed(self): self.notify.debug('fire pressed') messenger.send(CannonGui.FIRE_PRESSED) def __enterControlActive(self, control): return control + 1 def __exitControlActive(self, control): return max(0, control - 1)
class CannonGui(DirectObject): notify = directNotify.newCategory("CannonGui") # keyboard controls FIRE_KEY = "control" UP_KEY = "arrow_up" DOWN_KEY = "arrow_down" LEFT_KEY = "arrow_left" RIGHT_KEY = "arrow_right" FIRE_PRESSED = "cannongui_fire_pressed" def __init__(self): self.__loaded = False # since there are multiple inputs tied to each # of these (buttons and keypresses), they are # incremented for every button or keypress # that is active self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.__aimPad = None self.__timerPad = None def load(self): if self.__loaded: return # Load Timer self.__timerPad = PartyUtils.getNewToontownTimer() # set up the cannon aiming/firing gui guiModel = "phase_4/models/gui/cannon_game_gui" guiNode = loader.loadModel(guiModel) self.__aimPad = DirectFrame(image = guiNode.find("**/CannonFire_PAD"), relief = None, pos = (0.7, 0, -0.553333), scale = 0.8, ) guiNode.removeNode() # Set up the fire and arrow buttons self.fireButton = DirectButton(parent = self.__aimPad, image = ((guiModel, "**/Fire_Btn_UP"), (guiModel, "**/Fire_Btn_DN"), (guiModel, "**/Fire_Btn_RLVR"), ), relief = None, pos = (0.0115741,0,0.00505051), scale = 1., command = self.__firePressed, ) self.upButton = DirectButton(parent = self.__aimPad, image = ((guiModel, "**/Cannon_Arrow_UP"), (guiModel, "**/Cannon_Arrow_DN"), (guiModel, "**/Cannon_Arrow_RLVR"), ), relief = None, pos = (0.0115741,0,0.221717), ) self.downButton = DirectButton(parent = self.__aimPad, image = ((guiModel, "**/Cannon_Arrow_UP"), (guiModel, "**/Cannon_Arrow_DN"), (guiModel, "**/Cannon_Arrow_RLVR"), ), relief = None, pos = (0.0136112,0,-0.210101), image_hpr = (0,0,180), ) self.leftButton = DirectButton(parent = self.__aimPad, image = ((guiModel, "**/Cannon_Arrow_UP"), (guiModel, "**/Cannon_Arrow_DN"), (guiModel, "**/Cannon_Arrow_RLVR"), ), relief = None, pos = (-0.199352,0,-0.000505269), image_hpr = (0,0,-90), ) self.rightButton = DirectButton(parent = self.__aimPad, image = ((guiModel, "**/Cannon_Arrow_UP"), (guiModel, "**/Cannon_Arrow_DN"), (guiModel, "**/Cannon_Arrow_RLVR"), ), relief = None, pos = (0.219167,0,-0.00101024), image_hpr = (0,0,90), ) # Make the aim pad semi transparent self.__aimPad.setColor(1,1,1, 0.9) # Set up the button press/release handlers # Buttons have the ability send signal as long as they're pressed. def bindButton(button, upHandler, downHandler): button.bind(DGG.B1PRESS, lambda x, handler=upHandler : handler()) button.bind(DGG.B1RELEASE, lambda x, handler=downHandler : handler()) bindButton(self.upButton, self.__upPressed, self.__upReleased) bindButton(self.downButton, self.__downPressed, self.__downReleased) bindButton(self.leftButton, self.__leftPressed, self.__leftReleased) bindButton(self.rightButton, self.__rightPressed, self.__rightReleased) self.__loaded = True def unload(self): self.ignoreAll() if not self.__loaded: return self.disable() # Do we need to unbind? self.upButton.unbind(DGG.B1PRESS) self.upButton.unbind(DGG.B1RELEASE) self.downButton.unbind(DGG.B1PRESS) self.downButton.unbind(DGG.B1RELEASE) self.leftButton.unbind(DGG.B1PRESS) self.leftButton.unbind(DGG.B1RELEASE) self.rightButton.unbind(DGG.B1PRESS) self.rightButton.unbind(DGG.B1RELEASE) self.fireButton.destroy() self.__aimPad.destroy() del self.__aimPad del self.fireButton del self.upButton del self.downButton del self.leftButton del self.rightButton self.__timerPad.destroy() del self.__timerPad self.__loaded = False def enable(self, timer=0): self.__aimPad.show() # Free up two of the nametag cells on the bottom edge # of the screen to leave room for the cannon gui. base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0) base.setCellsAvailable([base.rightCells[1]], 0) if timer > 0: self.__timerPad.setTime(timer) self.__timerPad.countdown(timer) self.__timerPad.show() self.enableKeys() def disable(self): self.__aimPad.hide() # Restore the normal nametag cells. base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1) base.setCellsAvailable([base.rightCells[1]], 1) self.__timerPad.hide() self.disableKeys() def enableKeys(self): self.enableAimKeys() self.enableFireKey() def disableKeys(self): self.__aimPad.hide() self.disableAimKeys() self.disableFireKey() def enableAimKeys(self): self.leftPressed = 0 self.rightPressed = 0 self.upPressed = 0 self.downPressed = 0 self.accept(self.UP_KEY, self.__upKeyPressed) self.accept(self.DOWN_KEY, self.__downKeyPressed) self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.accept(self.RIGHT_KEY, self.__rightKeyPressed) def disableAimKeys(self): self.ignore(self.UP_KEY) self.ignore(self.DOWN_KEY) self.ignore(self.LEFT_KEY) self.ignore(self.RIGHT_KEY) messenger.send(self.UP_KEY + "-up") messenger.send(self.DOWN_KEY + "-up") messenger.send(self.LEFT_KEY + "-up") messenger.send(self.RIGHT_KEY + "-up") self.ignore(self.UP_KEY + "-up") self.ignore(self.DOWN_KEY + "-up") self.ignore(self.LEFT_KEY + "-up") self.ignore(self.RIGHT_KEY + "-up") def enableFireKey(self): self.accept(self.FIRE_KEY, self.__fireKeyPressed) def disableFireKey(self): self.ignore(self.FIRE_KEY) self.ignore(self.FIRE_KEY + "-up") #=============================================================================== # Button / Key Handlers #=============================================================================== # KEYS PRESSED def __fireKeyPressed(self): self.ignore(self.FIRE_KEY) self.accept(self.FIRE_KEY+"-up", self.__fireKeyReleased) self.__firePressed() def __upKeyPressed(self): self.ignore(self.UP_KEY) self.accept(self.UP_KEY+"-up", self.__upKeyReleased) self.__upPressed() def __downKeyPressed(self): self.ignore(self.DOWN_KEY) self.accept(self.DOWN_KEY+"-up", self.__downKeyReleased) self.__downPressed() def __leftKeyPressed(self): self.ignore(self.LEFT_KEY) self.accept(self.LEFT_KEY+"-up", self.__leftKeyReleased) self.__leftPressed() def __rightKeyPressed(self): self.ignore(self.RIGHT_KEY) self.accept(self.RIGHT_KEY+"-up", self.__rightKeyReleased) self.__rightPressed() # KEYS RELEASED def __fireKeyReleased(self): self.ignore(self.FIRE_KEY+"-up") self.accept(self.FIRE_KEY, self.__fireKeyPressed) #self.__fireReleased() def __leftKeyReleased(self): self.ignore(self.LEFT_KEY+"-up") self.accept(self.LEFT_KEY, self.__leftKeyPressed) self.__leftReleased() def __rightKeyReleased(self): self.ignore(self.RIGHT_KEY+"-up") self.accept(self.RIGHT_KEY, self.__rightKeyPressed) self.__rightReleased() def __upKeyReleased(self): self.ignore(self.UP_KEY+"-up") self.accept(self.UP_KEY, self.__upKeyPressed) self.__upReleased() def __downKeyReleased(self): self.ignore(self.DOWN_KEY+"-up") self.accept(self.DOWN_KEY, self.__downKeyPressed) self.__downReleased() # GENERAL HANDLERS def __upPressed(self): self.notify.debug("up pressed") self.upPressed = self.__enterControlActive(self.upPressed) def __downPressed(self): self.notify.debug("down pressed") self.downPressed = self.__enterControlActive(self.downPressed) def __leftPressed(self): self.notify.debug("left pressed") self.leftPressed = self.__enterControlActive(self.leftPressed) def __rightPressed(self): self.notify.debug("right pressed") self.rightPressed = self.__enterControlActive(self.rightPressed) def __upReleased(self): self.notify.debug("up released") self.upPressed = self.__exitControlActive(self.upPressed) def __downReleased(self): self.notify.debug("down released") self.downPressed = self.__exitControlActive(self.downPressed) def __leftReleased(self): self.notify.debug("left released") self.leftPressed = self.__exitControlActive(self.leftPressed) def __rightReleased(self): self.notify.debug("right released") self.rightPressed = self.__exitControlActive(self.rightPressed) # Unlike the other modes, fire only sends an event. It can not be held down. def __firePressed(self): self.notify.debug("fire pressed") messenger.send(CannonGui.FIRE_PRESSED) # __enterControlActive and __exitControlActive are used # to update the cannon control 'press reference counts' # leftPressed, rightPressed, upPressed, and downPressed # are all counts of how many devices (button, keys) are # activating that particular cannon control -- so if # someone is pressing 'right' on the keyboard and also # pressing on the 'right' button with the mouse, # rightPressed would be set to 2. A value of zero means # that the cannon control is inactive. def __enterControlActive(self, control): return control + 1 def __exitControlActive(self, control): return max(0, control-1)
def render(self): ''' traverse the tree and update the visuals according to it ''' for treeItem in self.treeStructure.getRec(): # create nodes that have no visual elements if not treeItem in self.treeStructureNodes: treeNode = self.childrenCanvas.attachNewNode('') hor = self.horizontalTreeLine.instanceUnderNode(treeNode, '') vert = self.verticalTreeLine.instanceUnderNode(treeNode, '') vert.setZ(0.007) hor.setPos(-1.5 * self.itemIndent, 0, self.itemScale * .25) vert.setX(-.5 * self.itemIndent) nodeButton = DirectButton( parent=treeNode, scale=self.itemScale, relief=DGG.FLAT, text_scale=self.itemTextScale, text_align=TextNode.ALeft, text=treeItem.name, rolloverSound=None, #clickSound=None, ) nodeButton.bind(DGG.B1PRESS, treeItem.button1press) nodeButton.bind(DGG.B2PRESS, treeItem.button2press) nodeButton.bind(DGG.B3PRESS, treeItem.button3press) #treeButton = None #if len(treeItem.childrens) > 0: treeButton = DirectButton( parent=nodeButton, frameColor=(1, 1, 1, 1), frameSize=(-.4, .4, -.4, .4), pos=(-.5 * self.itemIndent / self.itemScale, 0, .25), text='', text_pos=(-.1, -.22), text_scale=(1.6, 1), text_fg=(0, 0, 0, 1), enableEdit=0, command=treeItem.setOpen, sortOrder=1000, rolloverSound=None, #clickSound=None, ) self.treeStructureNodes[treeItem] = [ treeNode, nodeButton, treeButton, hor, vert ] # destroy nodes no more used for treeItem in self.treeStructureNodes.keys()[:]: #treeItem = self.treeStructureNodes[treeName] if treeItem not in self.treeStructure.getRec(): treeNode, nodeButton, treeButton, hor, vert = self.treeStructureNodes[ treeItem] #nodeButton['text']='' nodeButton.unbind(DGG.B1PRESS) nodeButton.unbind(DGG.B2PRESS) nodeButton.unbind(DGG.B3PRESS) #nodeButton.detachNode() #nodeButton.removeNode() nodeButton.destroy() if treeButton: #treeButton['text']='' #treeButton['command']=None treeButton.detachNode() treeButton.removeNode() hor.detachNode() hor.removeNode() vert.detachNode() vert.removeNode() treeItem.destroy() #treeNode.detachNode() treeNode.removeNode() #treeNode.destroy() del self.treeStructureNodes[treeItem] frameHeight = len(self.treeStructureNodes) * self.verticalSpacing self.childrenFrame['canvasSize'] = (0, self.frameWidth - self.itemScale * 2, 0, frameHeight) self.childrenCanvas.setZ(frameHeight - 1)