class TTStreet(Street.Street): def __init__(self, loader, parentFSM, doneEvent): Street.Street.__init__(self, loader, parentFSM, doneEvent) cm = CardMaker('card') cm.setFrameFullscreenQuad() self.explosionCard = render2d.attachNewNode(cm.generate()) self.explosionCard.setTransparency(1) self.explosionCard.setColorScale(0, 0, 0, 0) self.title = OnscreenText(text='Chapter One - Operations Collide', pos=(0, -0.6), scale=0.169, font=ToontownGlobals.getSuitFont(), fg=(1, 1, 1, 1), shadow=(0.1, 0.1, 0.1, 1)) self.title.setColorScale(1, 1, 1, 0) self.laffMeter = base.localAvatar.laffMeter self.book = base.localAvatar.book.bookOpenButton self.book2 = base.localAvatar.book.bookCloseButton base.localAvatar.cameraFollow = 1 def resetCameraFollow(self): base.localAvatar.cameraFollow = 0 def load(self): Street.Street.load(self) if hasattr(base.cr, 'inEvToonHall') and base.cr.inEvToonHall: sillyMeterSign = self.loader.geom.find('**/sillyOMeterSign') if sillyMeterSign: sillyMeterSign.removeNode() self.cinematicTitle = Sequence( self.title.colorScaleInterval(1.969, (1, 1, 1, 1)), Wait(4.5), self.title.colorScaleInterval(2, (1, 1, 1, 0))) evToonHallSeq = Sequence( Func(self.explosionCard.setColorScale, 0, 0, 0, 1), Func(base.localAvatar.disableAvatarControls), Func(NodePath(self.laffMeter).hide), Func(NodePath(base.marginManager).hide), Func(base.localAvatar.disableSleeping), Func(NodePath(self.book).hide), Func(base.camera.wrtReparentTo, render), Func(base.localAvatar.stopUpdateSmartCamera), Func(base.localAvatar.shutdownSmartCamera), Func(base.camera.setPosHpr, 24, -26, 6, 45, 0, 0), Wait(2), self.explosionCard.colorScaleInterval(2, (0, 0, 0, 0)), Wait(1), Func(self.cinematicTitle.start), Func(self.resetCameraFollow)) evToonHallSeq.start() if hasattr(base.cr, 'inEvAftermathToonHall') and base.cr.inEvAftermathToonHall: sillyMeterSign = self.loader.geom.find('**/sillyOMeterSign') if sillyMeterSign: sillyMeterSign.removeNode() def unload(self): Street.Street.unload(self) def doRequestLeave(self, requestStatus): self.fsm.request('trialerFA', [requestStatus])
class KeyCodesGui(DirectObject): notify = directNotify.newCategory("KeyCodesGui") TIMEOUT_TASK = "KeyCodeGui_TIMEOUT_TASK" def __init__(self, keyCodes, yOffset=.55, keyToIndex=KEY_TO_INDEX): self._keyCodes = keyCodes # KeyCodes instance reference self._keyToIndex = keyToIndex self._arrowWidth = .18 self._arrowSpaceInBetween = .05 self._yOffset = yOffset self._danceMoveLabel = None self._arrowNodes = [] self.timeoutTask = None def load(self): """ Loads an initializes arrow nodes and dance move label. """ matchingGameGui = loader.loadModel("phase_3.5/models/gui/matching_game_gui") minnieArrow = matchingGameGui.find("**/minnieArrow") minnieArrow.setScale(0.6) minnieArrow.setZ(self._yOffset + 0.2) maxLength = self._keyCodes.getLargestPatternLength() for i in range(maxLength): arrow = minnieArrow.copyTo(hidden) self._arrowNodes.append(arrow) matchingGameGui.removeNode() self._danceMoveLabel = OnscreenText(parent = aspect2d, text = "", pos = (0, self._yOffset), scale = 0.15, align = TextNode.ACenter, font = ToontownGlobals.getSignFont(), fg = Vec4(1, 1, 1, 1), #shadow = Vec4(0, 0, 0, 1), mayChange = True, ) self._danceMoveLabel.hide() self.enable() def unload(self): self.disable() for arrow in self._arrowNodes: arrow.removeNode() arrow = None self._arrowNodes = [] if self._danceMoveLabel is not None: self._danceMoveLabel.removeNode() self._danceMoveLabel = None def enable(self): self.notify.debug("KeyCodeGui enabled.") self.accept(KeyCodes.KEY_DOWN_EVENT, self.__handleKeyDown) self.accept(KeyCodes.CLEAR_CODE_EVENT, self.hideAll) def disable(self): self.notify.debug("KeyCodeGui disabled.") self.__stopTimeout() self.ignoreAll() #=============================================================================== # Functions #=============================================================================== def hideArrows(self, startIndex=0): """ Hides arrows. Parameters: startIndex (optional): sets from what index start hiding the arrows. """ length = len(self._arrowNodes) if startIndex < length: for i in range(startIndex, length): self._arrowNodes[i].reparentTo(hidden) def hideAll(self, startIndex=0): self.hideArrows(startIndex) if self._danceMoveLabel: self._danceMoveLabel.hide() def showArrow(self, index, key): """ Shows arrow at a specific index, and hides all of the arrows after that index. """ # set rotation to the right rotation self._arrowNodes[index].setR(-(90 - 90 * self._keyToIndex[key])) self._arrowNodes[index].setColor(1, 1, 1, 1) self.__centerArrows() self._arrowNodes[index].reparentTo(aspect2d) self.hideAll(index + 1) self.__startTimeout() def showText(self, text=""): """ Shows label text. """ self.notify.debug('"Showing text "%s"' % text) self._danceMoveLabel["text"] = text self._danceMoveLabel.show() def setColor(self, r, g, b): """ Changes text and arrow color to a particular rgb value. """ for arrow in self._arrowNodes: arrow.setColor(r, g, b) self._danceMoveLabel.setColorScale(r, g, b, 1) #=============================================================================== # Helpers #=============================================================================== def __startTimeout(self): """ Starts timeout task to hide the gui elements. """ self.__stopTimeout() self.timeoutTask = taskMgr.doMethodLater(KEYCODE_TIMEOUT_SECONDS, self.__handleTimeoutTask, KeyCodesGui.TIMEOUT_TASK) def __stopTimeout(self): """ Stops a previously-set timeout from expiring. """ if self.timeoutTask is not None: taskMgr.remove(self.timeoutTask) self.timeoutTask = None def __handleTimeoutTask(self, task): """ Called after timing out. Hides all the keys and text label. """ self.hideAll() return Task.done def __centerArrows(self): """ Centers horizontally all visible arrows """ length = self._keyCodes.getCurrentInputLength() for i in range(length): x = -(length * self._arrowWidth * 0.5) + (self._arrowWidth * (i + 0.5)) self._arrowNodes[i].setX(x) def __handleKeyDown(self, key, index): """ Shows arrow when a keycode key is pressed down. """ if index >= 0: self.showArrow(index, key)
class KeyCodesGui(DirectObject): __module__ = __name__ notify = directNotify.newCategory('KeyCodesGui') TIMEOUT_TASK = 'KeyCodeGui_TIMEOUT_TASK' def __init__(self, keyCodes, yOffset=0.55, keyToIndex=KEY_TO_INDEX): self._keyCodes = keyCodes self._keyToIndex = keyToIndex self._arrowWidth = 0.18 self._arrowSpaceInBetween = 0.05 self._yOffset = yOffset self._danceMoveLabel = None self._arrowNodes = [] self.timeoutTask = None return def load(self): matchingGameGui = loader.loadModel( 'phase_3.5/models/gui/matching_game_gui') minnieArrow = matchingGameGui.find('**/minnieArrow') minnieArrow.setScale(0.6) minnieArrow.setZ(self._yOffset + 0.2) maxLength = self._keyCodes.getLargestPatternLength() for i in range(maxLength): arrow = minnieArrow.copyTo(hidden) self._arrowNodes.append(arrow) matchingGameGui.removeNode() self._danceMoveLabel = OnscreenText(parent=aspect2d, text='', pos=(0, self._yOffset), scale=0.15, align=TextNode.ACenter, font=ToontownGlobals.getSignFont(), fg=Vec4(1, 1, 1, 1), mayChange=True) self._danceMoveLabel.hide() self.enable() def unload(self): self.disable() for arrow in self._arrowNodes: arrow.removeNode() arrow = None self._arrowNodes = [] if self._danceMoveLabel is not None: self._danceMoveLabel.removeNode() self._danceMoveLabel = None return def enable(self): self.notify.debug('KeyCodeGui enabled.') self.accept(KeyCodes.KEY_DOWN_EVENT, self.__handleKeyDown) self.accept(KeyCodes.CLEAR_CODE_EVENT, self.hideAll) def disable(self): self.notify.debug('KeyCodeGui disabled.') self.__stopTimeout() self.ignoreAll() def hideArrows(self, startIndex=0): length = len(self._arrowNodes) if startIndex < length: for i in range(startIndex, length): self._arrowNodes[i].reparentTo(hidden) def hideAll(self, startIndex=0): self.hideArrows(startIndex) if self._danceMoveLabel: self._danceMoveLabel.hide() def showArrow(self, index, key): self._arrowNodes[index].setR(-(90 - 90 * self._keyToIndex[key])) self._arrowNodes[index].setColor(1, 1, 1, 1) self.__centerArrows() self._arrowNodes[index].reparentTo(aspect2d) self.hideAll(index + 1) self.__startTimeout() def showText(self, text=''): self.notify.debug('"Showing text "%s"' % text) self._danceMoveLabel['text'] = text self._danceMoveLabel.show() def setColor(self, r, g, b): for arrow in self._arrowNodes: arrow.setColor(r, g, b) self._danceMoveLabel.setColorScale(r, g, b, 1) def __startTimeout(self): self.__stopTimeout() self.timeoutTask = taskMgr.doMethodLater(KEYCODE_TIMEOUT_SECONDS, self.__handleTimeoutTask, KeyCodesGui.TIMEOUT_TASK) def __stopTimeout(self): if self.timeoutTask is not None: taskMgr.remove(self.timeoutTask) self.timeoutTask = None return def __handleTimeoutTask(self, task): self.hideAll() return Task.done def __centerArrows(self): length = self._keyCodes.getCurrentInputLength() for i in range(length): x = -(length * self._arrowWidth * 0.5) + self._arrowWidth * (i + 0.5) self._arrowNodes[i].setX(x) def __handleKeyDown(self, key, index): if index >= 0: self.showArrow(index, key)
class KeyCodesGui(DirectObject): __module__ = __name__ notify = directNotify.newCategory('KeyCodesGui') TIMEOUT_TASK = 'KeyCodeGui_TIMEOUT_TASK' def __init__(self, keyCodes, yOffset = 0.55, keyToIndex = KEY_TO_INDEX): self._keyCodes = keyCodes self._keyToIndex = keyToIndex self._arrowWidth = 0.18 self._arrowSpaceInBetween = 0.05 self._yOffset = yOffset self._danceMoveLabel = None self._arrowNodes = [] self.timeoutTask = None return def load(self): matchingGameGui = loader.loadModel('phase_3.5/models/gui/matching_game_gui') minnieArrow = matchingGameGui.find('**/minnieArrow') minnieArrow.setScale(0.6) minnieArrow.setZ(self._yOffset + 0.2) maxLength = self._keyCodes.getLargestPatternLength() for i in range(maxLength): arrow = minnieArrow.copyTo(hidden) self._arrowNodes.append(arrow) matchingGameGui.removeNode() self._danceMoveLabel = OnscreenText(parent=aspect2d, text='', pos=(0, self._yOffset), scale=0.15, align=TextNode.ACenter, font=ToontownGlobals.getSignFont(), fg=Vec4(1, 1, 1, 1), mayChange=True) self._danceMoveLabel.hide() self.enable() def unload(self): self.disable() for arrow in self._arrowNodes: arrow.removeNode() arrow = None self._arrowNodes = [] if self._danceMoveLabel is not None: self._danceMoveLabel.removeNode() self._danceMoveLabel = None return def enable(self): self.notify.debug('KeyCodeGui enabled.') self.accept(KeyCodes.KEY_DOWN_EVENT, self.__handleKeyDown) self.accept(KeyCodes.CLEAR_CODE_EVENT, self.hideAll) def disable(self): self.notify.debug('KeyCodeGui disabled.') self.__stopTimeout() self.ignoreAll() def hideArrows(self, startIndex = 0): length = len(self._arrowNodes) if startIndex < length: for i in range(startIndex, length): self._arrowNodes[i].reparentTo(hidden) def hideAll(self, startIndex = 0): self.hideArrows(startIndex) if self._danceMoveLabel: self._danceMoveLabel.hide() def showArrow(self, index, key): self._arrowNodes[index].setR(-(90 - 90 * self._keyToIndex[key])) self._arrowNodes[index].setColor(1, 1, 1, 1) self.__centerArrows() self._arrowNodes[index].reparentTo(aspect2d) self.hideAll(index + 1) self.__startTimeout() def showText(self, text = ''): self.notify.debug('"Showing text "%s"' % text) self._danceMoveLabel['text'] = text self._danceMoveLabel.show() def setColor(self, r, g, b): for arrow in self._arrowNodes: arrow.setColor(r, g, b) self._danceMoveLabel.setColorScale(r, g, b, 1) def __startTimeout(self): self.__stopTimeout() self.timeoutTask = taskMgr.doMethodLater(KEYCODE_TIMEOUT_SECONDS, self.__handleTimeoutTask, KeyCodesGui.TIMEOUT_TASK) def __stopTimeout(self): if self.timeoutTask is not None: taskMgr.remove(self.timeoutTask) self.timeoutTask = None return def __handleTimeoutTask(self, task): self.hideAll() return Task.done def __centerArrows(self): length = self._keyCodes.getCurrentInputLength() for i in range(length): x = -(length * self._arrowWidth * 0.5) + self._arrowWidth * (i + 0.5) self._arrowNodes[i].setX(x) def __handleKeyDown(self, key, index): if index >= 0: self.showArrow(index, key)
class SBHood(ToonHood.ToonHood): def __init__(self, parentFSM, doneEvent, dnaStore, hoodId): ToonHood.ToonHood.__init__(self, parentFSM, doneEvent, dnaStore, hoodId) self.id = ScroogeBank self.townLoaderClass = SBTownLoader.SBTownLoader self.safeZoneLoaderClass = SBSafeZoneLoader.SBSafeZoneLoader self.storageDNAFile = 'phase_8/dna/storage_ODG.jazz' self.holidayStorageDNADict = { WINTER_DECORATIONS: ['phase_8/dna/winter_storage_SB.jazz'], WACKY_WINTER_DECORATIONS: ['phase_8/dna/winter_storage_SB.jazz'], HALLOWEEN_PROPS: None, SPOOKY_PROPS: None } self.skyFile = 'phase_3.5/models/props/TT_sky' self.spookySkyFile = self.skyFile self.titleColor = (0.8, 0.6, 1.0, 1.0) cm = CardMaker('card') cm.setFrameFullscreenQuad() self.explosionCard = render2d.attachNewNode(cm.generate()) self.explosionCard.setTransparency(1) self.explosionCard.setColorScale(0, 0, 0, 0) self.laffMeter = base.localAvatar.laffMeter self.book = base.localAvatar.book.bookOpenButton self.book2 = base.localAvatar.book.bookCloseButton self.warning = OnscreenText(text='You need a key to enter.', pos=(0, -0.6), scale=0.1, font=ToontownGlobals.getSignFont(), fg=(1, 1, 1, 1), shadow=(0.1, 0.1, 0.1, 1)) self.warning.setColorScale(1, 1, 1, 0) self.warningInterval = Sequence( self.warning.colorScaleInterval(1.969, (1, 1, 1, 1)), Wait(1.5), self.warning.colorScaleInterval(2, (1, 1, 1, 0))) self.enterSfx = loader.loadSfx( 'phase_3/audio/sfx/tt_s_ara_mat_crash_woodGlass.ogg') self.col = loader.loadModel('phase_9/models/cogHQ/CogDoor_Button') self.col.setPosHpr(-19.69, 0, 25.385, 90, -90, 0) self.col.setScale(3) self.col.reparentTo(render) self.colNode = None return def teleportToBankInterior(self): hoodId = ZoneUtil.getTrueZoneId(21000, 21000) zoneId = ZoneUtil.getTrueZoneId(21401, 21000) how = 'teleportIn' tunnelOriginPlaceHolder = render.attachNewNode('toph_21000_21401') tutorialFlag = 0 requestStatus = { 'loader': ZoneUtil.getLoaderName(zoneId), 'where': ZoneUtil.getToonWhereName(zoneId), 'how': how, 'hoodId': hoodId, 'zoneId': zoneId, 'shardId': None, 'tunnelOrigin': tunnelOriginPlaceHolder, 'tutorial': tutorialFlag, 'avId': -1 } place = base.cr.playGame.getPlace() if place: place.requestLeave(requestStatus) return def startCollDetect(self): if not self.colNode: cs = CollisionSphere(0, 0, 0, 2) self.colNode = self.col.attachNewNode(CollisionNode('cnode4')) self.colNode.node().addSolid(cs) self.accept('enter' + self.colNode.node().getName(), self.handleCollision) def stopCollDetect(self): if self.colNode: self.ignore('enter' + self.colNode.node().getName()) def handleCollision(self, collEntry): self.walkin = Sequence( Func(base.playSfx, self.enterSfx, volume=1), self.col.colorScaleInterval(1, (0, 1, 0, 1)), Wait(1), Func(self.teleportToBankInterior), Func(NodePath(self.laffMeter).hide), Func(base.camera.wrtReparentTo, render), Func(base.localAvatar.stopUpdateSmartCamera), Func(base.localAvatar.shutdownSmartCamera), Func(base.camera.setPosHpr, -190.877, 0, 30, 270, 12, 0), base.camera.posHprInterval(2.69, (-50.877, 0, 119), (270, 0, 0), blendType='easeInOut')) self.stopforasec = Sequence(Func(self.stopCollDetect), Wait(6), Func(self.startCollDetect)) if base.cr.scroogeKey == 0: self.warningInterval.start() self.stopforasec.start() else: self.stopCollDetect() base.cr.scroogeKey = 2 self.walkin.start() def load(self): ToonHood.ToonHood.load(self) self.parentFSM.getStateNamed('SBHood').addChild(self.fsm) def unload(self): self.parentFSM.getStateNamed('SBHood').removeChild(self.fsm) ToonHood.ToonHood.unload(self) def enter(self, *args): ToonHood.ToonHood.enter(self, *args) localAvatar.setCameraFov(CogHQCameraFov) base.camLens.setNearFar(CogHQCameraNear, CogHQCameraFar) proEvSeq = Sequence( Func(NodePath(self.book).hide), Func(NodePath(self.laffMeter).hide), Func(base.localAvatar.disableSleeping), Func(base.localAvatar.obscureFriendsListButton, 1), Func(base.localAvatar.hideClarabelleGui), Func(base.localAvatar.chatMgr.obscure, 1, 1), Func(self.explosionCard.setColorScale, 0, 0, 0, 1), Wait(3), Func(localAvatar.sendUpdate, 'startProEv', []), Func(self.startCollDetect), self.explosionCard.colorScaleInterval(2, (0, 0, 0, 0))) proEvSeq.start() def exit(self): localAvatar.setCameraFov(DefaultCameraFov) base.camLens.setNearFar(DefaultCameraNear, DefaultCameraFar) ToonHood.ToonHood.exit(self) base.localAvatar.attachCamera() base.localAvatar.initializeSmartCamera() base.localAvatar.startUpdateSmartCamera() self.stopCollDetect() self.col.removeNode() del self.col def skyTrack(self, task): return SkyUtil.cloudSkyTrack(task) def startSky(self): if not self.sky.getTag('sky') == 'Regular': self.startSpookySky() return SkyUtil.startCloudSky(self) def startSpookySky(self): SkyUtil.startCloudSky(self)