def spawnTitleText(self): def getDescription(zoneNum, self=self): ent = self.entities.get(zoneNum) if ent and hasattr(ent, "description"): return ent.description description = getDescription(self.lastCamZone) if description and description != "": taskMgr.remove(self.uniqueName("titleText")) self.smallTitleText.setText(description) self.titleText.setText(description) self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.setFg(self.titleColor) titleSeq = None if self.lastCamZone not in self.zonesEnteredList: self.zonesEnteredList.append(self.lastCamZone) titleSeq = Task.sequence( Task.Task(self.hideSmallTitleTextTask), Task.Task(self.showTitleTextTask), Task.pause(0.10000000000000001), Task.pause(6.0), self.titleText.lerpColor( Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], self.titleColor[3]), Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], 0.0), 0.5, ), ) smallTitleSeq = Task.sequence(Task.Task(self.hideTitleTextTask), Task.Task(self.showSmallTitleTask)) if titleSeq: seq = Task.sequence(titleSeq, smallTitleSeq) else: seq = smallTitleSeq taskMgr.add(seq, self.uniqueName("titleText"))
def spawnTitleText(self): def getDescription(zoneNum, self=self): ent = self.entities.get(zoneNum) if ent and hasattr(ent, 'description'): return ent.description return None description = getDescription(self.lastCamZone) if description and description != '': taskMgr.remove(self.uniqueName('titleText')) self.smallTitleText.setText(description) self.titleText.setText(description) self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.setFg(self.titleColor) titleSeq = None if self.lastCamZone not in self.zonesEnteredList: self.zonesEnteredList.append(self.lastCamZone) titleSeq = Task.sequence( Task.Task(self.hideSmallTitleTextTask), Task.Task(self.showTitleTextTask), Task.pause(0.1), Task.pause(6.0), self.titleText.lerpColor( Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], self.titleColor[3]), Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], 0.0), 0.5)) smallTitleSeq = Task.sequence(Task.Task(self.hideTitleTextTask), Task.Task(self.showSmallTitleTask)) if titleSeq: seq = Task.sequence(titleSeq, smallTitleSeq) else: seq = smallTitleSeq taskMgr.add(seq, self.uniqueName('titleText')) return
def showInfoText(self, text="hello world"): description = text if description and description != '': taskMgr.remove(self.uniqueName("titleText")) self.smallTitleText.setText(description) self.titleText.setText(description) self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.setFg(self.titleColor) # Only show the big title once per session. # If we've already seen it, just show the small title titleSeq = None titleSeq = Task.sequence( Task.Task(self.hideSmallTitleTextTask), Task.Task(self.showTitleTextTask), Task.pause(0.1), Task.pause(3.0), self.titleText.lerpColor( Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], self.titleColor[3]), Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], 0.0), 0.5), ) if titleSeq: seq = Task.sequence(titleSeq) taskMgr.add(seq, self.uniqueName("titleText"))
def showInfoText(self, text = 'hello world'): description = text if description and description != '': taskMgr.remove(self.uniqueName('titleText')) self.smallTitleText.setText(description) self.titleText.setText(description) self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.setFg(self.titleColor) titleSeq = None titleSeq = Task.sequence(Task.Task(self.hideSmallTitleTextTask), Task.Task(self.showTitleTextTask), Task.pause(0.10000000000000001), Task.pause(3.0), self.titleText.lerpColor(Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], self.titleColor[3]), Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], 0.0), 0.5)) if titleSeq: seq = Task.sequence(titleSeq) taskMgr.add(seq, self.uniqueName('titleText'))
def showHitScore(self, number, scale = 1): if number <= 0: return if self.hpText: self.hideHitScore() self.HpTextGenerator.setFont(ToontownGlobals.getSignFont()) if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText('+' + str(number)) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) r = 1 g = 1 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = render.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardPointEye() self.hpText.setBin('fixed', 100) self.hpText.setPos(self.root, 0, 0, self.height / 2) seq = Task.sequence(self.hpText.lerpPos(Point3(self.root.getX(render), self.root.getY(render), self.root.getZ(render) + self.height + 1.0), 0.25, blendType='easeOut'), Task.pause(0.25), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), Task.Task(self.__hideHitScoreTask)) taskMgr.add(seq, 'PartyCogHpText' + str(self.id))
def irisIn(self, t=0.5, block=0): """ Play an iris in transition over t seconds. Places a polygon on the aspect2d plane then lerps the scale of the iris polygon up so it looks like we iris in. When the scale lerp is finished, it parents the iris polygon to hidden. If block is true, does not execute lerp, but returns the sequence. """ self.noTransitions() self.loadIris() if (t == 0): self.iris.reparentTo(hidden) else: self.iris.reparentTo(aspect2d, FADE_SORT_INDEX) self.iris.setScale(0.015) # Create a sequence that scales the iris up, # then parents the fade to hidden task = Task.sequence( self.iris.lerpScale(0.18, 0.18, 0.18, t, blendType="noBlend"), Task.Task(self.__irisInLerpDone)) # Spawn the sequence if not block: taskMgr.add(task, self.irisTaskName) else: return task
def showHitScore(self, number, scale=1): if number <= 0: return if self.hpText: self.hideHitScore() self.HpTextGenerator.setFont(ToontownGlobals.getSignFont()) if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText('+' + str(number)) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) r = 1 g = 1 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = render.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardPointEye() self.hpText.setBin('fixed', 100) self.hpText.setPos(self.root, 0, 0, self.height / 2) seq = Task.sequence( self.hpText.lerpPos(Point3( self.root.getX(render), self.root.getY(render), self.root.getZ(render) + self.height + 1.0), 0.25, blendType='easeOut'), Task.pause(0.25), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), Task.Task(self.__hideHitScoreTask)) taskMgr.add(seq, 'PartyCogHpText' + str(self.id))
def showHpString(self, text, duration=0.85, scale=0.7): if self.HpTextEnabled and not self.ghostMode: if text != '': if self.hpText: self.hideHpText() self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) self.HpTextGenerator.setText(text) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) r = a = 1.0 g = b = 0.0 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardAxis() self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), Task.pause(duration), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName('hpText'))
def irisOut(self, t=0.5, block=0): """ Play an iris out transition over t seconds. Places a polygon on the aspect2d plane then lerps the scale of the iris down so it looks like we iris out. When the scale lerp is finished, it leaves the iris polygon covering the aspect2d plane until you irisIn or call noIris. """ self.noTransitions() self.loadIris() self.loadFade() # we need this to cover up the hole. if (t == 0): self.iris.reparentTo(hidden) else: self.iris.reparentTo(aspect2d, FADE_SORT_INDEX) self.iris.setScale(0.18) # Create a sequence that scales the iris up, # then parents the fade to hidden task = Task.sequence( self.iris.lerpScale(0.015, 0.015, 0.015, t, blendType="noBlend"), Task.Task(self.irisOutLerpDone)) # Spawn the sequence if not block: taskMgr.add(task, self.irisTaskName) else: return task
def fadeIn(self, t=0.5, block=0): """ Play a fade in transition over t seconds. Places a polygon on the aspect2d plane then lerps the color from black to transparent. When the color lerp is finished, it parents the fade polygon to hidden. If block is set, return the sequence instead of spawning it. """ self.noTransitions() self.loadFade() self.fade.reparentTo(aspect2d, FADE_SORT_INDEX) if (t == 0): # Fade in immediately with no lerp self.fade.reparentTo(hidden) else: # Create a sequence that lerps the color out, then # parents the fade to hidden r = self.fadeColor[0] g = self.fadeColor[1] b = self.fadeColor[2] task = Task.sequence( self.fade.lerpColor(r, g, b, 1, r, g, b, 0, t), Task.Task(self.__fadeInLerpDone)) # Spawn the sequence if not block: taskMgr.add(task, self.fadeTaskName) else: return task
def fadeIn(self, t=0.5, block=0): """ Play a fade in transition over t seconds. Places a polygon on the aspect2d plane then lerps the color from black to transparent. When the color lerp is finished, it parents the fade polygon to hidden. If block is set, return the sequence instead of spawning it. """ self.noTransitions() self.loadFade() self.fade.reparentTo(aspect2d, FADE_SORT_INDEX) if (t == 0): # Fade in immediately with no lerp self.fade.reparentTo(hidden) else: # Create a sequence that lerps the color out, then # parents the fade to hidden r = self.fadeColor[0] g = self.fadeColor[1] b = self.fadeColor[2] task = Task.sequence( self.fade.lerpColor(r,g,b,1, r,g,b,0, t), Task.Task(self.__fadeInLerpDone)) # Spawn the sequence if not block: taskMgr.add(task, self.fadeTaskName) else: return task
def showHpString(self, text, duration=0.84999999999999998, scale=0.69999999999999996): if self.HpTextEnabled and not (self.ghostMode): if text != "": if self.hpText: self.hideHpText() self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) self.HpTextGenerator.setText(text) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) r = 1.0 a = 1.0 g = 0.0 b = 0.0 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardAxis() self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType="easeOut"), Task.pause(duration), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.10000000000000001), Task.Task(self.hideHpTextTask), ) taskMgr.add(seq, self.uniqueName("hpText"))
def fadeOutTask(self, task, time=0.3, noFade=1): """ As a sequence: Fade out, execute the given task, then do a noFade if requested """ if noFade: def noFadeTask(task): task.noFade() return Task.done nft = Task.Task(noFadeTask) nft.noFade = self.noFade seq = Task.sequence(self.fadeOut(time, block=1), task, nft) else: seq = Task.sequence(self.fadeOut(time, block=1), task) # do it taskMgr.add(seq, 'fadeOutTaskSeq')
def irisOutTask(self, task, time=0.5, noIris=1): """ As a sequence: iris out, execute the given task, then do a noIris if requested """ if noIris: def noIrisTask(task): task.noIris() return Task.done nit = Task.Task(noIrisTask) nit.noIris = self.noIris seq = Task.sequence(self.irisOut(time, block=1), task, nit) else: seq = Task.sequence(self.irisOut(time, block=1), task) # do it taskMgr.add(seq, 'irisOutTaskSeq')
def showHpString(self, text, duration=0.85, scale=0.7): if self.HpTextEnabled and not self.ghostMode: # We don't show empty strings if text != '': # Get rid of text if it is already there. if self.hpText: self.hideHpText() # Set the font self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) # Write the text self.HpTextGenerator.setText(text) # No shadow self.HpTextGenerator.clearShadow() # Put a shadow on there #self.HpTextGenerator.setShadow(0.05, 0.05) #self.HpTextGenerator.setShadowColor(0, 0, 0, 1) # Center the text self.HpTextGenerator.setAlign(TextNode.ACenter) # Set the color and alpha scale (a) r = a = 1.0 g = b = 0.0 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() # Put the hpText over the head of the avatar self.hpText = self.attachNewNode(self.hpTextNode) # Set its scale self.hpText.setScale(scale) # Make sure it is a billboard self.hpText.setBillboardAxis() # Initial position ... Center of the body... the "tan tien" self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( # Fly the number out of the character self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), # Wait 2 seconds Task.pause(duration), # Fade the number self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), # Get rid of the number Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName("hpText")) else: # Just play the sound effect. # TODO: Put in the sound effect! pass
def showInfoText(self, text='hello world'): description = text if description and description != '': taskMgr.remove(self.uniqueName('titleText')) self.smallTitleText.setText(description) self.titleText.setText(description) self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.setFg(self.titleColor) titleSeq = None titleSeq = Task.sequence( Task.Task(self.hideSmallTitleTextTask), Task.Task(self.showTitleTextTask), Task.pause(0.1), Task.pause(3.0), self.titleText.lerpColor( Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], self.titleColor[3]), Vec4(self.titleColor[0], self.titleColor[1], self.titleColor[2], 0.0), 0.5)) if titleSeq: seq = Task.sequence(titleSeq) taskMgr.add(seq, self.uniqueName('titleText')) return
def showHpText(self, number, bonus=0, scale=1): if self.HpTextEnabled and not (self.ghostMode): if number != 0: if self.hpText: self.hideHpText() self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText('+' + str(number)) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) if bonus == 1: r = 1.0 g = 1.0 b = 0 a = 1 elif bonus == 2: r = 1.0 g = 0.5 b = 0 a = 1 elif number < 0: r = 0.90000000000000002 g = 0 b = 0 a = 1 else: r = 0 g = 0.90000000000000002 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardPointEye() self.hpText.setBin('fixed', 100) self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), Task.pause(0.84999999999999998), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.10000000000000001), Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName('hpText'))
def showHpText(self, number, bonus=0, scale=1): if self.HpTextEnabled and not (self.ghostMode): if number != 0: if self.hpText: self.hideHpText() self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText("+" + str(number)) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) if bonus == 1: r = 1.0 g = 1.0 b = 0 a = 1 elif bonus == 2: r = 1.0 g = 0.5 b = 0 a = 1 elif number < 0: r = 0.90000000000000002 g = 0 b = 0 a = 1 else: r = 0 g = 0.90000000000000002 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardPointEye() self.hpText.setBin("fixed", 100) self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType="easeOut"), Task.pause(0.84999999999999998), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.10000000000000001), Task.Task(self.hideHpTextTask), ) taskMgr.add(seq, self.uniqueName("hpText"))
def __fireCannonTask(self, task): launchTime = 0.0 toonId = task.toonId cannon = task.cannon toon = cannon.getToonInside() self.notify.debug(str(self.doId) + ' FIRING CANNON FOR TOON ' + str(toonId)) if not cannon.isToonInside(): return Task.done if self.isLocalToonId(toonId): self.inWater = 0 startPos, startHpr, startVel, trajectory = self.__calcFlightResults(cannon, toonId, launchTime) self.notify.debug('start position: ' + str(startPos)) self.notify.debug('start velocity: ' + str(startVel)) self.notify.debug('time of launch: ' + str(launchTime)) cannon.removeToonReadyToFire() shootTask = Task.Task(self.__shootTask, self.taskNameShoot) shootTask.info = {'toonId': toonId, 'cannon': cannon} if self.isLocalToonId(toonId): self.flyingToonOffsetRotation = 0 self.flyingToonOffsetAngle = 0 self.flyingToonOffsetX = 0 self.flyingToonOffsetY = 0 self.hitCloud = 0 self.initialFlyVel = INITIAL_VELOCITY self.camNode = NodePath(self.uniqueName('flyingCamera')) self.camNode.setScale(0.5) self.camNode.setPos(self.localFlyingToon.getPos()) self.camNode.setHpr(self.localFlyingToon.getHpr()) self.camNode.reparentTo(render) self.lastStartVel = startVel place = base.cr.playGame.getPlace() place.fsm.request('activity') toon.dropShadow.hide() self.localFlyingDropShadow = self.shadowNode.copyTo(hidden) vel = startVel toon.lookAt(toon.getPos() + Vec3(vel[0], vel[1], vel[2])) toon.setP(localAvatar, -90) hpr = toon.getHpr() toon.d_setPosHpr(startPos[0], startPos[1], startPos[2], hpr[0], hpr[1], hpr[2]) self.localFlyingToon.wrtReparentTo(render) info = {} info['toonId'] = toonId info['trajectory'] = trajectory info['launchTime'] = launchTime info['toon'] = self.localFlyingToon info['hRot'] = cannon.getRotation() base.camera.wrtReparentTo(self.localFlyingToon) flyTask = Task.Task(self.__localFlyTask, self.taskNameFly) flyTask.info = info seqTask = Task.sequence(shootTask, flyTask) self.__startCollisionHandler() self.notify.debug('Disable standard local toon controls.') base.localAvatar.disableAvatarControls() frameTime = globalClock.getFrameTime() netLaunchTime = globalClockDelta.localToNetworkTime(launchTime + frameTime, bits=31) self.sendUpdate('setToonTrajectoryAi', [netLaunchTime, startPos[0], startPos[1], startPos[2], startHpr[0], startHpr[1], startHpr[2], startVel[0], startVel[1], startVel[2]]) else: seqTask = shootTask taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(toonId)) toon.startSmooth() return Task.done
def showHitScore(self, number, scale=1): """ Shows the hit score. Borrowed from otp.avatar.DistributedAvatar.showHpText """ if number <= 0: return # Get rid of the number if it is already there. if self.hpText: self.hideHitScore() # Set the font self.HpTextGenerator.setFont(ToontownGlobals.getSignFont()) # Show both negative and positive signs if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText("+" + str(number)) # No shadow self.HpTextGenerator.clearShadow() # Center the number self.HpTextGenerator.setAlign(TextNode.ACenter) # Red, always #if number < 0: r = 1 #0.9 g = 1 #0 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() # Put the hpText over the head of the avatar self.hpText = render.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) # Make sure it is a billboard self.hpText.setBillboardPointEye() # Render it after other things in the scene. self.hpText.setBin('fixed', 100) # Initial position ... Center of the body... the "tan tien" self.hpText.setPos(self.root, 0, 0, self.height / 2) # Black magic from the early days of Panda3D, later replaced by a Sequence seq = Task.sequence( # Fly the number out of the character self.hpText.lerpPos(Point3( self.root.getX(render), self.root.getY(render), self.root.getZ(render) + self.height + 1.0), 0.25, blendType='easeOut'), Task.pause(0.25), # Fade the number self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), # Get rid of the number Task.Task(self.__hideHitScoreTask)) taskMgr.add(seq, "PartyCogHpText" + str(self.id))
def fadeInTask(self, task, time=0.5): """ As a sequence: Fade in, execute the given task """ seq = Task.sequence(self.fadeIn(time, block=1), task) taskMgr.add(seq, 'fadeInTaskSeq')
def showHpText(self, number, bonus = 0, scale = 1, attackTrack = -1): if self.HpTextEnabled and not self.ghostMode: if number != 0: if self.hpText: self.hideHpText() self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) if number < 0: self.HpTextGenerator.setText(str(number)) if base.cr.newsManager.isHolidayRunning(ToontownGlobals.SILLY_SURGE_HOLIDAY): self.sillySurgeText = True absNum = abs(number) if absNum > 0 and absNum <= 10: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[1]) elif absNum > 10 and absNum <= 20: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[2]) elif absNum > 20 and absNum <= 30: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[3]) elif absNum > 30 and absNum <= 40: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[4]) elif absNum > 40 and absNum <= 50: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[5]) elif absNum > 50 and absNum <= 60: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[6]) elif absNum > 60 and absNum <= 70: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[7]) elif absNum > 70 and absNum <= 80: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[8]) elif absNum > 80 and absNum <= 90: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[9]) elif absNum > 90 and absNum <= 100: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[10]) elif absNum > 100 and absNum <= 110: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[11]) else: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.SillySurgeTerms[12]) if self.interactivePropTrackBonus > -1 and self.interactivePropTrackBonus == attackTrack: self.sillySurgeText = True if attackTrack in TTLocalizer.InteractivePropTrackBonusTerms: self.HpTextGenerator.setText(str(number) + '\n' + TTLocalizer.InteractivePropTrackBonusTerms[attackTrack]) else: self.HpTextGenerator.setText('+' + str(number)) self.HpTextGenerator.clearShadow() self.HpTextGenerator.setAlign(TextNode.ACenter) if bonus == 1: r = 1.0 g = 1.0 b = 0 a = 1 elif bonus == 2: r = 1.0 g = 0.5 b = 0 a = 1 elif number < 0: r = 0.9 g = 0 b = 0 a = 1 if self.interactivePropTrackBonus > -1 and self.interactivePropTrackBonus == attackTrack: r = 0 g = 0 b = 1 a = 1 else: r = 0 g = 0.9 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) self.hpText.setBillboardPointEye() self.hpText.setBin('fixed', 100) if self.sillySurgeText: self.nametag3d.setDepthTest(0) self.nametag3d.setBin('fixed', 99) self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence(self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), Task.pause(0.85), self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName('hpText'))
def showHpText(self, number, bonus=0, scale=1, attackTrack=-1): if self.HpTextEnabled and not self.ghostMode: # We don't show zero change. if number != 0: # Get rid of the number if it is already there. if self.hpText: self.hideHpText() # Set the font self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) # Show both negative and positive signs if number < 0: self.HpTextGenerator.setText(str(number)) # If we're doing the Silly Holiday word additions if base.cr.newsManager.isHolidayRunning( ToontownGlobals.SILLY_SURGE_HOLIDAY): self.sillySurgeText = True absNum = abs(number) if absNum > 0 and absNum <= 10: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[1]) elif absNum > 10 and absNum <= 20: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[2]) elif absNum > 20 and absNum <= 30: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[3]) elif absNum > 30 and absNum <= 40: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[4]) elif absNum > 40 and absNum <= 50: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[5]) elif absNum > 50 and absNum <= 60: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[6]) elif absNum > 60 and absNum <= 70: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[7]) elif absNum > 70 and absNum <= 80: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[8]) elif absNum > 80 and absNum <= 90: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[9]) elif absNum > 90 and absNum <= 100: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[10]) elif absNum > 100 and absNum <= 110: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[11]) else: # greater than 110 self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer.SillySurgeTerms[12]) # check for interactive prop gag track bonus if self.interactivePropTrackBonus > -1 and self.interactivePropTrackBonus == attackTrack: self.sillySurgeText = True if attackTrack in TTLocalizer.InteractivePropTrackBonusTerms: self.HpTextGenerator.setText( str(number) + "\n" + TTLocalizer. InteractivePropTrackBonusTerms[attackTrack]) else: self.HpTextGenerator.setText("+" + str(number)) # No shadow self.HpTextGenerator.clearShadow() # Put a shadow on there #self.HpTextGenerator.setShadow(0.05, 0.05) #self.HpTextGenerator.setShadowColor(0, 0, 0, 1) # Center the number self.HpTextGenerator.setAlign(TextNode.ACenter) # Red for negative, green for positive, yellow for bonus if bonus == 1: r = 1.0 g = 1.0 b = 0 a = 1 elif bonus == 2: r = 1.0 g = 0.5 b = 0 a = 1 elif number < 0: r = 0.9 g = 0 b = 0 a = 1 # if we have a track bonus, for now make it blue if self.interactivePropTrackBonus > -1 and self.interactivePropTrackBonus == attackTrack: r = 0 g = 0 b = 1 a = 1 else: r = 0 g = 0.9 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() # Put the hpText over the head of the avatar self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) # Make sure it is a billboard self.hpText.setBillboardPointEye() # Render it after other things in the scene. self.hpText.setBin('fixed', 100) if self.sillySurgeText: self.nametag3d.setDepthTest(0) self.nametag3d.setBin('fixed', 99) # Initial position ... Center of the body... the "tan tien" self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( # Fly the number out of the character self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), # Wait 2 seconds Task.pause(0.85), # Fade the number self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), # Get rid of the number Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName("hpText")) else: # Just play the sound effect. # TODO: Put in the sound effect! pass
def showHpText(self, number, bonus=0, scale=1): # WARNING if this changes please also change DistributedToon.py if self.HpTextEnabled and not self.ghostMode: # We don't show zero change. if number != 0: # Get rid of the number if it is already there. if self.hpText: self.hideHpText() # Set the font self.HpTextGenerator.setFont(OTPGlobals.getSignFont()) # Show both negative and positive signs if number < 0: self.HpTextGenerator.setText(str(number)) else: self.HpTextGenerator.setText("+" + str(number)) # No shadow self.HpTextGenerator.clearShadow() # Put a shadow on there #self.HpTextGenerator.setShadow(0.05, 0.05) #self.HpTextGenerator.setShadowColor(0, 0, 0, 1) # Center the number self.HpTextGenerator.setAlign(TextNode.ACenter) # Red for negative, green for positive, yellow for bonus if bonus == 1: r = 1.0 g = 1.0 b = 0 a = 1 elif bonus == 2: r = 1.0 g = 0.5 b = 0 a = 1 elif number < 0: r = 0.9 g = 0 b = 0 a = 1 else: r = 0 g = 0.9 b = 0 a = 1 self.HpTextGenerator.setTextColor(r, g, b, a) self.hpTextNode = self.HpTextGenerator.generate() # Put the hpText over the head of the avatar self.hpText = self.attachNewNode(self.hpTextNode) self.hpText.setScale(scale) # Make sure it is a billboard self.hpText.setBillboardPointEye() # Render it after other things in the scene. self.hpText.setBin('fixed', 100) # Initial position ... Center of the body... the "tan tien" self.hpText.setPos(0, 0, self.height / 2) seq = Task.sequence( # Fly the number out of the character self.hpText.lerpPos(Point3(0, 0, self.height + 1.5), 1.0, blendType='easeOut'), # Wait 2 seconds Task.pause(0.85), # Fade the number self.hpText.lerpColor(Vec4(r, g, b, a), Vec4(r, g, b, 0), 0.1), # Get rid of the number Task.Task(self.hideHpTextTask)) taskMgr.add(seq, self.uniqueName("hpText")) else: # Just play the sound effect. # TODO: Put in the sound effect! pass
def irisInTask(self, task, time=0.5): """ As a sequence: iris in, execute the given task """ seq = Task.sequence(self.irisIn(time, block=1), task) taskMgr.add(seq, 'irisInTaskSeq')
def __fireCannonTask(self, task): launchTime = 0.0 toonId = task.toonId cannon = task.cannon toon = cannon.getToonInside() self.notify.debug( str(self.doId) + ' FIRING CANNON FOR TOON ' + str(toonId)) if not cannon.isToonInside(): return Task.done if self.isLocalToonId(toonId): self.inWater = 0 startPos, startHpr, startVel, trajectory = self.__calcFlightResults( cannon, toonId, launchTime) self.notify.debug('start position: ' + str(startPos)) self.notify.debug('start velocity: ' + str(startVel)) self.notify.debug('time of launch: ' + str(launchTime)) cannon.removeToonReadyToFire() shootTask = Task.Task(self.__shootTask, self.taskNameShoot) shootTask.info = {'toonId': toonId, 'cannon': cannon} if self.isLocalToonId(toonId): self.flyingToonOffsetRotation = 0 self.flyingToonOffsetAngle = 0 self.flyingToonOffsetX = 0 self.flyingToonOffsetY = 0 self.hitCloud = 0 self.initialFlyVel = INITIAL_VELOCITY self.camNode = NodePath(self.uniqueName('flyingCamera')) self.camNode.setScale(0.5) self.camNode.setPos(self.localFlyingToon.getPos()) self.camNode.setHpr(self.localFlyingToon.getHpr()) self.camNode.reparentTo(render) self.lastStartVel = startVel place = base.cr.playGame.getPlace() place.fsm.request('activity') toon.dropShadow.hide() self.localFlyingDropShadow = self.shadowNode.copyTo(hidden) vel = startVel toon.lookAt(toon.getPos() + Vec3(vel[0], vel[1], vel[2])) toon.setP(localAvatar, -90) hpr = toon.getHpr() toon.d_setPosHpr(startPos[0], startPos[1], startPos[2], hpr[0], hpr[1], hpr[2]) self.localFlyingToon.wrtReparentTo(render) info = {} info['toonId'] = toonId info['trajectory'] = trajectory info['launchTime'] = launchTime info['toon'] = self.localFlyingToon info['hRot'] = cannon.getRotation() base.camera.wrtReparentTo(self.localFlyingToon) flyTask = Task.Task(self.__localFlyTask, self.taskNameFly) flyTask.info = info seqTask = Task.sequence(shootTask, flyTask) self.__startCollisionHandler() self.notify.debug('Disable standard local toon controls.') base.localAvatar.disableAvatarControls() frameTime = globalClock.getFrameTime() netLaunchTime = globalClockDelta.localToNetworkTime(launchTime + frameTime, bits=31) self.sendUpdate('setToonTrajectoryAi', [ netLaunchTime, startPos[0], startPos[1], startPos[2], startHpr[0], startHpr[1], startHpr[2], startVel[0], startVel[1], startVel[2] ]) else: seqTask = shootTask taskMgr.add(seqTask, self.taskName('flyingToon') + '-' + str(toonId)) toon.startSmooth() return Task.done