class DirectionalDamageIndicator(NodePath): def __init__(self, damagePos): NodePath.__init__(self, 'dir-damage-indicator') self.reparentTo(aspect2d) self.damagePos = damagePos self.task = taskMgr.add(self.__update, 'ddi-update') self.img = OnscreenImage(image='materials/ui/damage_indicator.png', parent=self) self.setTransparency(True) self.setColorScale((1, 1, 1, 0.5)) self.setScale(0.25) self.time = globalClock.getFrameTime() self.track = Sequence( Wait(1.5), LerpColorScaleInterval(self, 0.5, (1, 1, 1, 0), (1, 1, 1, 0.5)), Func(self.removeNode)) self.track.start() DDIByPos[self.damagePos] = self @staticmethod def make(damagePos): if damagePos in DDIByPos: DDIByPos[damagePos].removeNode() DirectionalDamageIndicator(damagePos) def removeNode(self): del DDIByPos[self.damagePos] self.track.pause() self.track = None self.img.destroy() self.img = None self.time = None self.damagePos = None self.task.remove() self.task = None NodePath.removeNode(self) def __update(self, task): camSpacePos = base.cam.getRelativePoint(render, self.damagePos) arrowRadians = math.atan2(camSpacePos[0], camSpacePos[1]) arrowDegrees = (arrowRadians / math.pi) * 180 self.setR(arrowDegrees) return task.cont
class WaterBar(NodePath): def __init__(self): NodePath.__init__(self, 'waterBar') self.range = 100 self.value = 100 self.back = OnscreenImage("phase_14/maps/backv2.png", scale=(0.289, 1, 0.813), parent=self) self.bar = OnscreenImage("phase_14/maps/frontv2.png", scale=(0.233, 1, 0.740), parent=self) self.setTransparency(1) barSh = loader.loadShader("phase_14/models/shaders/progress_bar.sha") self.bar.setShader(barSh) self.bar.setShaderInput( "tex", loader.loadTexture("phase_14/maps/frontv2.png")) self.bar.setShaderInput("perct", float(self.value) / float(self.range)) self.bar.setShaderInput("dir", 0) self.bar.setShaderInput("alpha", 1.0) self.task = taskMgr.add(self.__update, "WaterBar.update") def removeNode(self): self.task.remove() self.task = None self.back.destroy() self.back = None self.bar.destroy() self.bar = None self.range = None self.value = None NodePath.removeNode(self) def setDirection(self, dir): self.bar.setShaderInput("dir", dir) def setBarAlpha(self, alpha): self.bar.setShaderInput("alpha", alpha) def __update(self, task): self.bar.setShaderInput("perct", float(self.value) / float(self.range)) return task.cont
class MoneyGUI: def createGui(self): self.deleteGui() self.root = base.a2dBottomLeft.attachNewNode('moneyroot') self.root.setScale(0.8) self.root.setBin('gui-popup', 60) self.frame = DirectFrame(parent=self.root, pos=(0.43, 0, 0.16)) gui = loader.loadModel("phase_3.5/models/gui/jar_gui.bam") self.jar = OnscreenImage(image=gui, scale=0.5, parent=self.frame) mf = loader.loadFont("phase_3/models/fonts/MickeyFont.bam") self.money_lbl = DirectLabel(text="", text_font=mf, text_fg=(1,1,0,1), parent=self.jar, text_scale=0.2, relief=None, pos=(0, 0, -0.1)) gui.remove_node() def deleteGui(self): if hasattr(self, 'jar'): self.jar.destroy() del self.jar if hasattr(self, 'money_lbl'): self.money_lbl.destroy() del self.money_lbl if hasattr(self, 'frame'): self.frame.destroy() del self.frame def update(self, newMoney, oldMoney = 0): delta = newMoney - oldMoney if delta != 0: CIGlobals.makeDeltaTextEffect(delta, base.a2dBottomLeft, (0.173, 0, 0.12)) if delta > 0: ToontownIntervals.start(ToontownIntervals.getPulseLargerIval(self.frame, 'money-effect')) else: ToontownIntervals.start(ToontownIntervals.getPulseSmallerIval(self.frame, 'money-effect')) if hasattr(self, 'money_lbl'): if newMoney <= 0: self.money_lbl['text_fg'] = (1, 0, 0, 1) else: self.money_lbl['text_fg'] = (1, 1, 0, 1) self.money_lbl['text'] = str(newMoney)
class MoneyGui: def createGui(self): self.deleteGui() self.frame = DirectFrame(parent=base.a2dBottomLeft, pos=(0.45, 0, 0.155)) gui = loader.loadModel("phase_3.5/models/gui/jar_gui.bam") self.jar = OnscreenImage(image=gui, scale=0.5, parent=self.frame) mf = loader.loadFont("phase_3/models/fonts/MickeyFont.bam") self.money_lbl = DirectLabel(text="", text_font=mf, text_fg=(1, 1, 0, 1), parent=self.jar, text_scale=0.2, relief=None, pos=(0, 0, -0.1)) gui.remove_node() def deleteGui(self): if hasattr(self, 'jar'): self.jar.destroy() del self.jar if hasattr(self, 'money_lbl'): self.money_lbl.destroy() del self.money_lbl if hasattr(self, 'frame'): self.frame.destroy() del self.frame return def update(self, moneyAmt): if hasattr(self, 'money_lbl'): if moneyAmt <= 0: self.money_lbl['text_fg'] = (0.9, 0, 0, 1) else: self.money_lbl['text_fg'] = (1, 1, 0, 1) self.money_lbl['text'] = str(moneyAmt)
class SplashScreen: def __init__(self, doneCallback): self.cioimg = OnscreenImage( image='materials/engine/coginvasiononline.png') self.cioimg.hide() self.cioimg.setColorScale(0, 0, 0, 1) self.pandaimg = OnscreenImage( image='materials/engine/powered_by_panda3d.png') self.pandaimg.hide() self.pandaimg.setColorScale(0, 0, 0, 1) self.discimg = OnscreenImage(image='materials/engine/disclaimer.png') self.discimg.hide() self.discimg.setColorScale(0, 0, 0, 1) self.doneCallback = doneCallback self.splashIval = Sequence( Func(self.cioimg.show), Wait(1.0), Func(base.playMusic, "encntr_suit_HQ_nbrhood"), LerpColorScaleInterval(self.cioimg, 1.0, (1, 1, 1, 1), (0, 0, 0, 1)), Wait(3), LerpColorScaleInterval(self.cioimg, 1.0, (0, 0, 0, 1), (1, 1, 1, 1)), Func(self.cioimg.hide), Func(self.pandaimg.show), LerpColorScaleInterval(self.pandaimg, 1.0, (1, 1, 1, 1), (0, 0, 0, 1)), Wait(1.0), LerpColorScaleInterval(self.pandaimg, 1.0, (0, 0, 0, 1), (1, 1, 1, 1)), Func(self.pandaimg.hide), Func(self.discimg.show), LerpColorScaleInterval(self.discimg, 1.0, (1, 1, 1, 1), (0, 0, 0, 1)), Wait(3.5), LerpColorScaleInterval(self.discimg, 1.0, (0, 0, 0, 1), (1, 1, 1, 1)), Func(self.discimg.hide), Func(self.cleanup), Func(self.doneCallback)) self.splashIval.start() base.accept('space', self.splashIval.finish) def cleanup(self): base.ignore('space') self.splashIval.finish() self.splashIval = None self.pandaimg.destroy() self.pandaimg = None self.cioimg.destroy() self.cioimg = None self.discimg.destroy() self.discimg = None
class CIProgressScreen: def __init__(self): self.defaultLogoScale = 0.85 self.defaultLogoZ = 0.65 self.bgm = loader.loadModel('phase_3/models/gui/progress-background.bam') self.bgm.find('**/logo').stash() self.bg = self.bgm.find('**/bg') self.logo = loader.loadTexture('phase_3/maps/CogInvasion_Logo.png') self.logoNode = hidden.attachNewNode('logoNode') self.logoNode.setScale(self.defaultLogoScale) self.logoNode.setPos(0, self.defaultLogoZ, 0) self.logoImg = OnscreenImage(image=self.logo, scale=(0.685, 0, 0.3), parent=self.logoNode) self.logoImg.setTransparency(True) self.bg_img = OnscreenImage(image=self.bg, parent=hidden) self.bg_img.setSx(1.35) self.bg_img.hide() self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0, 0, 0.2)) self.progress_bar.setSx(1.064) self.progress_bar.setSz(0.38) toontipgui = loader.loadModel('phase_3.5/models/gui/stickerbook_gui.bam') poster = toontipgui.find('**/questCard') self.toontipFrame = DirectFrame(image=poster, image_scale=(1.4, 1, 1), parent=hidden, relief=None, pos=(0, 0, -0.1), scale=0.85) self.toontipLbl = OnscreenText(text='', parent=self.toontipFrame, fg=(0.35, 0.35, 0.35, 1), font=CIGlobals.getToonFont(), wordwrap=14.5, pos=(-0.59, 0.25), align=TextNode.ALeft, scale=0.08) self.loading_lbl = DirectLabel(text='', relief=None, scale=0.08, pos=(-1.0725, 0, -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(0.343, 0.343, 0.343, 1.0), text_font=CIGlobals.getMinnieFont(), parent=hidden, text_shadow=(0, 0, 0, 1)) return def begin(self, hood, range, wantGui): render.hide() self.renderFrames() base.setBackgroundColor(0, 0, 0) if hood == 'localAvatarEnterGame': self.loading_lbl['text'] = 'Entering...' else: if hood == 'init': self.loading_lbl['text'] = 'Loading...' else: self.loading_lbl['text'] = 'Heading to %s...' % hood self.progress_bar['barColor'] = (0.343, 0.343, 0.343, 1.0) self.progress_bar['range'] = range self.bgm.reparentTo(aspect2d) self.bg.reparentTo(render2d) self.bg_img.reparentTo(hidden) self.loading_lbl.reparentTo(aspect2d) self.logoNode.reparentTo(aspect2d) self.progress_bar.reparentTo(aspect2d) tip = random.choice(CIGlobals.ToonTips) self.toontipLbl.setText('TOON TIP:\n' + tip) self.toontipFrame.reparentTo(aspect2d) self.__count = 0 self.__expectedCount = range self.progress_bar.update(self.__count) def renderFramesTask(self, task): self.renderFrames() return task.cont def end(self): base.setBackgroundColor(CIGlobals.DefaultBackgroundColor) taskMgr.remove('renderFrames') render.show() self.progress_bar.finish() self.bg_img.reparentTo(hidden) self.logoNode.reparentTo(hidden) self.bg.reparentTo(hidden) self.bgm.reparentTo(hidden) self.loading_lbl.reparentTo(hidden) self.progress_bar.reparentTo(hidden) self.toontipFrame.reparentTo(hidden) self.renderFrames() def destroy(self): self.bg.removeNode() del self.bg self.bgm.removeNode() del self.bgm self.bg_img.destroy() self.loading_lbl.destroy() self.progress_bar.destroy() self.bgm.destroy() del self.bg_img del self.loading_lbl del self.progress_bar del self.bgm def renderFrames(self): base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() def tick(self): self.__count += 1 self.progress_bar.update(self.__count)
class CameraShyFirstPerson(FirstPerson): notify = directNotify.newCategory("CameraShyFirstPerson") defaultColor = VBase4(1.0, 1.0, 1.0, 1.0) toonInFocusColor = VBase4(0.0, 0.7, 0.0, 1.0) toonOutOfFocusColor = VBase4(0.25, 1.0, 0.25, 1.0) redColor = VBase4(0.8, 0.0, 0.0, 1.0) batteryLevelTwoColor = VBase4(0.9, 0.36, 0.0, 1.0) batteryLevelThreeColor = VBase4(0.9, 0.9, 0.0, 1.0) batteryLevelFourColor = VBase4(1.0, 1.0, 0.0, 1.0) batteryLevelFiveColor = VBase4(0.0, 1.0, 0.0, 1.0) fullyChargedState = 5 def __init__(self, mg): self.mg = mg self.batteryFrame = None self.batteryBg = None self.batteryBar = None self.rechargeSound = None self.fullyChargedSound = None self.hasToonInFocus = False self.toonToTakePicOf = None self.cameraRechargeState = None self.cameraRechargingLabel = None self.cameraFlashSeq = None self.viewfinder = None self.camFSM = ClassicFSM('CameraFSM', [ State('off', self.enterOff, self.exitOff), State('ready', self.enterCameraReady, self.exitCameraReady), State('recharge', self.enterCameraRecharge, self.exitCameraRecharge) ], 'off', 'off') self.camFSM.enterInitialState() FirstPerson.__init__(self) def enterOff(self): pass def exitOff(self): pass def enterCameraReady(self): self.acceptOnce("mouse1", self.__mouse1Pressed) def stopCameraFlash(self): if self.cameraFlashSeq: self.cameraFlashSeq.finish() self.cameraFlashSeq = None def __mouse1Pressed(self): self.cameraFlashSeq = Sequence( Func(base.transitions.setFadeColor, 1, 1, 1), Func(base.transitions.fadeOut, 0.1), Wait(0.1), Func(base.transitions.fadeIn, 0.1), Wait(0.1), Func(base.transitions.setFadeColor, 0, 0, 0)) self.cameraFlashSeq.start() self.mg.sendUpdate('remoteAvatarTakePicture', [base.localAvatar.doId]) self.mg.myRemoteAvatar.takePicture() self.viewfinder['image'].setColorScale(self.defaultColor) picData = self.viewfinder.takePictureRaw() if self.hasToonInFocus and self.toonToTakePicOf: self.mg.sendUpdate('tookPictureOfToon', [self.toonToTakePicOf.doId]) self.camFSM.request('recharge') def exitCameraReady(self): self.ignore("mouse1") def enterCameraRecharge(self): self.batteryBar.update(0) taskMgr.add(self.__rechargeNextState, "rechargeCamera") def __rechargeNextState(self, task): if self.cameraRechargeState is None: self.cameraRechargeState = -1 self.cameraRechargeState += 1 if self.cameraRechargeState > 0: base.playSfx(self.rechargeSound) if self.cameraRechargeState <= 1: self.batteryBar.setColorScale(self.redColor) elif self.cameraRechargeState == 2: self.batteryBar.setColorScale(self.batteryLevelTwoColor) elif self.cameraRechargeState == 3: self.batteryBar.setColorScale(self.batteryLevelThreeColor) elif self.cameraRechargeState == 4: self.batteryBar.setColorScale(self.batteryLevelFourColor) else: self.batteryBar.setColorScale(self.batteryLevelFiveColor) self.batteryBar.update(self.cameraRechargeState) if self.cameraRechargeState == self.fullyChargedState: base.playSfx(self.fullyChargedSound) self.camFSM.request('ready') return task.done task.delayTime = 1.0 return task.again def exitCameraRecharge(self): taskMgr.remove("rechargeCamera") self.cameraRechargeState = None def __traverse(self, task): if not base.mouseWatcherNode.hasMouse(): return task.cont toonInFoc = False avatar = None for av in self.mg.remoteAvatars: if av.avId != base.localAvatar.doId: if self.viewfinder.isInView(av): self.notify.info("{0} is in our view finder".format( av.avId)) avatar = self.mg.cr.doId2do.get(av.avId) break if avatar: remoteAvatar = self.mg.getRemoteAvatar(avatar.doId) if remoteAvatar: toonInFoc = True self.notify.info("We've got an avatar in focus ({0})".format( avatar.doId)) self.__handleToonInFocus(avatar) if not toonInFoc: self.toonToTakePicOf = None self.hasToonInFocus = False self.notify.info("No avatar in focus") if self.viewfinder['image'].getColorScale( ) == self.toonInFocusColor: self.viewfinder['image'].setColorScale( self.toonOutOfFocusColor) return task.cont def __handleToonInFocus(self, toon): if not self.hasToonInFocus or self.toonToTakePicOf is not None or self.toonToTakePicOf.doId != toon.doId: self.toonToTakePicOf = toon self.hasToonInFocus = True self.viewfinder['image'].setColorScale(self.toonInFocusColor) def start(self): self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/ring_get.ogg') self.rechargeSound = base.loadSfx( 'phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.ogg') self.batteryFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.2, 0, 0.1), scale=(0.8, 0, 1)) self.batteryBg = OnscreenImage( image='phase_4/maps/battery_charge_frame.png', parent=self.batteryFrame) self.batteryBg.setTransparency(1) self.batteryBg.setX(0.03) self.batteryBg.setScale(0.17, 0, 0.05) self.batteryBg.setColorScale(0, 0, 0, 1) self.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame) self.viewfinder = Viewfinder(1.0) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) FirstPerson.start(self) def reallyStart(self): taskMgr.add(self.__traverse, "CSFP.__traverse") self.camFSM.request('recharge') #taskMgr.add(self.movementTask, "movementTask") base.localAvatar.startTrackAnimToSpeed() FirstPerson.reallyStart(self) def end(self): self.camFSM.request('off') taskMgr.remove("movementTask") taskMgr.remove("CSFP.__traverse") FirstPerson.end(self) def reallyEnd(self): self.batteryBar.destroy() self.batteryBar = None self.batteryBg.destroy() self.batteryBg = None self.batteryFrame.destroy() self.batteryFrame = None self.hasToonInFocus = None self.toonToTakePicOf = None self.fullyChargedSound = None self.rechargeSound = None self.viewfinder.cleanup() self.viewfinder = None self.stopCameraFlash() FirstPerson.reallyEnd(self) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, CIGlobals.ToonJumpForce, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) def cleanup(self): self.camFSM.requestFinalState() self.camFSM = None FirstPerson.cleanup(self)
class ShopWindow(DirectFrame): def __init__(self, shop, image, wantTurretCount): DirectFrame.__init__(self, sortOrder=1) self.shop = shop self.wantTurretCount = wantTurretCount self.bgImage = image self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.turretLabel = None self.turretImg = None self.isSetup = False self.turretCount = 0 # New variables for optimized shop. self.firstItemIndex = -1 self.btnPositions = [(-0.45, 0, 0), (-0.15, 0, 0), (0.15, 0, 0), (0.45, 0, 0)] self.page = Page(self.shop, self) self.itemButtons = [] self.itemButtons.append(ItemButton(self.page, self.btnPositions[0])) self.itemButtons.append(ItemButton(self.page, self.btnPositions[1])) self.itemButtons.append(ItemButton(self.page, self.btnPositions[2])) self.itemButtons.append(ItemButton(self.page, self.btnPositions[3])) self.newItems = None def setup(self, title='CHOOSE WHAT YOU WANT TO BUY'): font = CIGlobals.getMickeyFont() txtFg = (0, 0, 0, 1) txtScale = 0.05 txtPos = (0, -0.1) buttons = loader.loadModel('phase_3.5/models/gui/QT_buttons.bam') self.window = OnscreenImage(image=self.bgImage, scale=(0.9, 1, 0.7), parent=self) self.title = DirectLabel(text=title, relief=None, pos=(0, 0, 0.5), text_wordwrap=10, text_font=font, text_fg=(1, 1, 0, 1), scale=0.1, parent=self) # Let's update the turret count. self.updateTurretCount() self.infoLbl = DirectLabel(text='Welcome!', relief=None, text_scale=0.075, text_fg=txtFg, text_shadow=(0, 0, 0, 0), pos=(0, 0, 0.215)) self.okBtn = DirectButton(geom=CIGlobals.getOkayBtnGeom(), relief=None, text='OK', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(-0.1, 0, -0.5), parent=self) self.clBtn = DirectButton(geom=CIGlobals.getCancelBtnGeom(), relief=None, text='Cancel', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(0.1, 0, -0.5), parent=self) buttonGeom = (buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back')) self.backBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(-0.3, 0, -0.25), parent=self, command=self.changePage, extraArgs=[0]) self.nextBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(0.3, 0, -0.25), hpr=(0, 0, 180), command=self.changePage, extraArgs=[1], parent=self) self.hideInfo() def setTurrets(self, amount): if self.shop.upgradesPurchased: amount += 1 self.turretCount = amount self.updatePage() def updateTurretCount(self): if self.turretLabel: self.turretLabel.destroy() if self.wantTurretCount: maxTurrets = CogBattleGlobals.MAX_TURRETS if not self.turretImg: self.turretImg = OnscreenImage( image="phase_3.5/maps/cannon-icon.png", scale=(0.05, 1, 0.05), pos=(-0.22, 0, 0.275)) self.turretImg.setTransparency(TransparencyAttrib.MAlpha) self.turretLabel = DirectLabel( text='Turrets: %s/%s' % (str(self.turretCount), str(maxTurrets)), relief=None, text_scale=0.07, text_fg=(0, 0, 0, 1), text_shadow=(0, 0, 0, 0), pos=(0, 0, 0.265)) def changePage(self, direction): var = (self.firstItemIndex - 4) if direction == 1: var = (self.firstItemIndex + 4) self.setBackBtn(True) self.setNextBtn(True) if (var - 4) < 0: self.setBackBtn(False) elif (var + 4) >= len(self.newItems): self.setNextBtn(False) self.firstItemIndex = var self.setupItems(begin=self.firstItemIndex) def initializeShop(self, items): newItems = dict(items) loadout = base.localAvatar.backpack.loadout # Let's show the loadout gags first in a full shop. if self.shop.wantFullShop: crcGags = OrderedDict(newItems) for item, values in newItems.items(): if values and values.get('type') == ItemType.GAG: gagId = base.cr.attackMgr.getAttackIDByName(item) hasGag = base.localAvatar.getBackpack().hasGag(gagId) if gagId not in loadout or not hasGag: del crcGags[item] if not hasGag: del newItems[item] else: del newItems[item] # Let's add back the other gags. crcGags.update(newItems) newItems = crcGags else: for item, values in newItems.items(): if values and values.get('type') == ItemType.GAG: gagId = base.localAvatar.getBackpack().hasGag(gagId) if gagId not in loadout or not base.localAvatar.getBackpack( ).hasGag(gagId): del newItems[item] self.newItems = newItems self.firstItemIndex = 0 self.setupItems() if len(newItems.keys()) <= 4: self.backBtn.hide() self.nextBtn.hide() self.setBackBtn(False) self.isSetup = True def setupItems(self, begin=0): for button in self.itemButtons: button.hide() button.label.hide() for i in xrange(4): item = self.newItems.keys()[begin + i] if (begin + i) < len( self.newItems.keys()) else None values = self.newItems.get(item) if item else None if item: button = self.itemButtons[i] button.setItem(item, values) button.update() def updatePage(self): battle = base.localAvatar.getBattleZone() if battle and self.wantTurretCount: self.shop.distShop.sendUpdate('requestTurretCount', []) self.updateTurretCount() for button in self.itemButtons: button.update() def setBackBtn(self, enabled): if self.backBtn: if enabled == False: self.backBtn.setColorScale(GRAYED_OUT_COLOR) self.backBtn['state'] = DGG.DISABLED else: self.backBtn.setColorScale(NORMAL_COLOR) self.backBtn['state'] = DGG.NORMAL def setNextBtn(self, enabled): if self.nextBtn: if enabled == False: self.nextBtn.setColorScale(GRAYED_OUT_COLOR) self.nextBtn['state'] = DGG.DISABLED else: self.nextBtn.setColorScale(NORMAL_COLOR) self.nextBtn['state'] = DGG.NORMAL def setOKCommand(self, command): if self.okBtn: self.okBtn['command'] = command def setCancelCommand(self, command): if self.clBtn: self.clBtn['command'] = command def showInfo(self, text, negative=0, duration=-1): self.infoLbl.show() if negative: self.infoLbl['text_fg'] = (0.9, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 1) else: self.infoLbl['text_fg'] = (0, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 0) self.infoLbl['text'] = text if duration > -1: Sequence(Wait(duration), Func(self.hideInfo)).start() def hideInfo(self): if self.infoLbl: self.infoLbl.hide() def delete(self): elements = [ self.title, self.okBtn, self.clBtn, self.infoLbl, self.backBtn, self.nextBtn, self.turretLabel, self.turretImg, self.page ] for element in elements: if element: element.destroy() del elements del self.page for button in self.itemButtons: button.destroy() self.itemButtons = None del self.itemButtons self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.backBtn = None self.nextBtn = None self.bgImage = None self.turretLabel = None self.turretCount = None if self.window: self.window.destroy() self.window = None self.destroy()
class UnoGameCardDeck(DirectFrame): def __init__(self, ug): DirectFrame.__init__(self, relief=None, sortOrder=50, parent=base.a2dBottomCenter) self.initialiseoptions(UnoGameCardDeck) self.container = DirectFrame(parent=self, relief=None) self.title = None self.cards = [] self.cardBtns = [] self.numCards = 0 self.unoGame = ug self.deck = None self.cardToFollowGui = None self.holiday = base.cr.holidayManager.getHoliday() self.gui = None self.loadCards() return def loadCards(self): self.gui = loader.loadModel( "phase_4/models/minigames/mg_uno_game_cards.egg") if self.holiday == HolidayType.CHRISTMAS: cards = self.gui.find( '**/mg_uno_numcards_green_7').getParent().getChildren() for child in cards: child.setTexture( loader.loadTexture('winter/maps/uno/%s.png' % (child.getName())), 1) def updateCardToFollowGui(self): self.deleteCardToFollowGui() if self.unoGame.cardToFollow[-2:] == str(UGG.CARD_BLUE): self.cardToFollowGui = OnscreenImage( image=self.getCard('mg_uno_numcards_blue_blank'), parent=base.a2dRightCenter) elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_RED): self.cardToFollowGui = OnscreenImage( image=self.getCard('mg_uno_numcards_red_blank'), parent=base.a2dRightCenter) elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_GREEN): self.cardToFollowGui = OnscreenImage( image=self.getCard('mg_uno_numcards_green_blank'), parent=base.a2dRightCenter) elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_YELLOW): self.cardToFollowGui = OnscreenImage( image=self.getCard('mg_uno_numcards_yellow_blank'), parent=base.a2dRightCenter) if self.cardToFollowGui: self.cardToFollowGui.setScale(0.25, 0.3, 0.3) self.cardToFollowGui.setPos(-0.175, 0, -0.75) def deleteCardToFollowGui(self): if self.cardToFollowGui: self.cardToFollowGui.destroy() self.cardToFollowGui = None def getCard(self, cardType): cards = loader.loadModel( "phase_4/models/minigames/mg_uno_game_cards.egg") card = cards.find('**/' + cardType) if self.holiday == HolidayType.CHRISTMAS: holidayTexture = loader.loadTexture('winter/maps/uno/%s.png' % (card.getName())) card.setTexture(holidayTexture, 1) return card def generate(self): self.container["image"] = "phase_4/maps/mg_uno_card_deck.png" self.container.setTransparency(True) self.container.setZ(-0.456) self.container.setSx(2) self.container.setSz(1) gui = loader.loadModel("phase_3.5/models/gui/friendslist_gui.bam") numItemsVisible = 5 itemHeight = -0.25 self.deck = DirectScrolledList( itemFrame_relief=DGG.SUNKEN, decButton_pos=(0.35, 0, -0.02), decButton_geom=(gui.find('**/Horiz_Arrow_UP'), gui.find('**/Horiz_Arrow_DN'), gui.find('**/Horiz_Arrow_Rllvr'), gui.find('**/Horiz_Arrow_UP')), decButton_relief=None, decButton_hpr=(0, 0, 90), incButton_pos=(0.35, 0, 1.95), incButton_geom=(gui.find('**/Horiz_Arrow_UP'), gui.find('**/Horiz_Arrow_DN'), gui.find('**/Horiz_Arrow_Rllvr'), gui.find('**/Horiz_Arrow_UP')), incButton_hpr=(0, 0, -90), incButton_relief=None, pos=(-0.936, 0, -0.41), hpr=(0, 0, 90), scale=0.97, numItemsVisible=numItemsVisible, forceHeight=itemHeight, itemFrame_frameSize=(-0.2, 0.2, -0.37, 1.5), itemFrame_pos=(0.35, 0, 0.4), itemFrame_borderWidth=(0.02, 0.02), ) def disable(self): if self.deck: self.deck.destroy() self.deck = None for btn in self.cardBtns: btn.destroy() del btn self.deleteCardToFollowGui() return def delete(self): DirectFrame.destroy(self) self.disable() self.gui.removeNode() self.gui = None self.cards = None self.title = None self.container = None self.cardBtns = None self.numCards = None self.unoGame = None self.deck = None return def drawCard(self, id): card = self.getCard(UGG.cardId2cardTex[id]) card.setScale(0.225, 0.3, 0.3) card.setR(-90) cardBtn = DirectButton(geom=card, relief=None, scale=(0.3, 0.3, 0.23), command=self.placeCard) cardBtn.setPythonTag('id', id) cardBtn['extraArgs'] = [id, cardBtn] cardBtn['state'] = DGG.DISABLED if not self.deck: self.generate() self.deck.addItem(cardBtn) self.cardBtns.append(cardBtn) self.enableAll(self.unoGame.cardToFollow) # Scroll to the card we just added to the deck. self.deck.scrollTo(len(self.cardBtns)) card.removeNode() del card def enableAll(self, cardToFollow=None): for btn in self.cardBtns: if cardToFollow != None: if (cardToFollow == btn.getPythonTag('id') or cardToFollow[:2] == btn.getPythonTag('id')[:2] or cardToFollow[-2:] == btn.getPythonTag('id')[-2:] or btn.getPythonTag('id') == str(UGG.CARD_WILD) or btn.getPythonTag('id') == str( UGG.CARD_WILD_DRAW_FOUR)): btn['state'] = DGG.NORMAL else: btn['state'] = DGG.DISABLED else: btn['state'] = DGG.NORMAL def disableAll(self): for btn in self.cardBtns: btn['state'] = DGG.DISABLED def placeCard(self, id, btn): self.deck.removeItem(btn) self.cardBtns.remove(btn) self.disableAll() self.unoGame.d_requestPlaceCard(id)
class PickAToon: name_hpr = [ Point3(0, 0, 352), Point3(0, 0, 4), Point3(0, 0, 4), Point3(0, 0, -4), Point3(0, 0, -4), Point3(0, 0, 1) ] name_pos = [ Point3(-0.03, 0, 0.22), Point3(0, 0, 0.235), Point3(0, 0, 0.235), Point3(0, 0, 0.24), Point3(-0.04, 0, 0.235), Point3(0, 0, 0.25) ] trash_pos = [ Point3(0.29, 0, -0.18), Point3(0.22, 0, -0.22), Point3(0.18, 0, -0.24), Point3(0.27, 0, -0.21), Point3(0.30, 0, -0.18), Point3(0.21, 0, -0.23) ] BgColor = (0.1450980392156863, 0.3686274509803922, 0.7803921568627451) def __init__(self, avChooser): self.title = None self.avChooser = avChooser self.dna = ToonDNA() #self.tutorial = Tutorial.Tutorial(self) def createGui(self): base.cr.renderFrame() self.m = loader.loadFont("phase_3/models/fonts/MickeyFont.bam") self.bg = loader.loadModel( "phase_3/models/gui/tt_m_gui_pat_mainGui.bam") self.qtbtn = loader.loadModel("phase_3/models/gui/quit_button.bam") self.trash_gui = loader.loadModel( "phase_3/models/gui/trashcan_gui.bam") self.bg_img = OnscreenImage( image=self.bg.find('**/tt_t_gui_pat_background')) self.setTitle("Pick A Toon To Play") base.setBackgroundColor(self.BgColor) self.btn1 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareGreen'), relief=None, pos=(0.012, 0, 0.306), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn2 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePink'), relief=None, pos=(0.01, 0, -0.515), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn3 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareRed'), relief=None, pos=(-0.84, 0, 0.36), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn4 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareYellow'), relief=None, pos=(0.865, 0, -0.45), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn5 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareBlue'), relief=None, pos=(-0.87, 0, -0.44), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn6 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePurple'), relief=None, pos=(0.873, 0, 0.335), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.quit_btn = DirectButton(geom=(self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR')), relief=None, text="Quit", text_font=self.m, text_scale=0.105, text_pos=(0, -0.035), pos=(1.05, 0, -0.9), text_fg=(1, 0.9, 0.1, 1), geom1_scale=(1.02, 1, 1), geom2_scale=(1.02, 1, 1), command=self.quitGame) self.btnList = [] self.btnList.append(self.btn1) self.btnList.append(self.btn2) self.btnList.append(self.btn3) self.btnList.append(self.btn4) self.btnList.append(self.btn5) self.btnList.append(self.btn6) self.headList = [] #datafiler = open("toons/data.txt", "r") #if datafiler.read() == "-": # for btn in self.btnList: # btn['state'] = DGG.DISABLED # self.quit_btn['state'] = DGG.DISABLED # self.tutorial.askTutorial() # datafilew = open("toons/data.txt", "w") # datafilew.write("+") # datafilew.flush() # datafilew.close() #datafiler.close() for slot in range(6): if self.avChooser.hasToonInSlot(slot): notify.info("found existing Toon in slot %s" % (str(slot))) frame = DirectFrame(relief=None, parent=self.btnList[slot], pos=(0, 0, -0.1)) headframe = hidden.attachNewNode('head') headframe.setPosHprScale(0, 5, -0.1, 180, 0, 0, 0.24, 0.24, 0.24) headframe.reparentTo(self.btnList[slot].stateNodePath[0], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[1], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[2], 20) toon = ToonHead(base.cr) self.headList.append(toon) gender, animal, head, headcolor = self.avChooser.getHeadInfo( slot) toon.generateHead(gender, animal, head, 1) toon.getGeomNode().setDepthWrite(1) toon.getGeomNode().setDepthTest(1) toon.startBlink() toon.startLookAround() toon.reparentTo(headframe) toon.setHeadColor(headcolor) toon.flattenLight() name_lbl = DirectLabel(text=self.avChooser.getNameInSlot(slot), text_scale=0.08, text_fg=(1, 1, 1, 1), text_wordwrap=7, relief=None, text_shadow=(0, 0, 0, 1)) name_lbl.reparentTo(self.btnList[slot].stateNodePath[0], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[1], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[2], 20) name_lbl.setPos(self.name_pos[slot]) name_lbl.setHpr(self.name_hpr[slot]) self.btnList[slot]['text'] = ("", "Play This Toon", "Play This Toon", "") self.btnList[slot]['text_scale'] = 0.1 self.btnList[slot]['text_pos'] = (0, 0) self.btnList[slot]['text_fg'] = (1, 0.9, 0, 1) self.btnList[slot]['text_wordwrap'] = 6 self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["playGame", slot] delBtn = DirectButton( text=("", "Delete", "Delete", ""), text_scale=0.15, scale=0.5, text_pos=(0, -0.1), text_fg=(1, 1, 1, 1), relief=None, geom=(self.trash_gui.find('**/TrashCan_CLSD'), self.trash_gui.find('**/TrashCan_OPEN'), self.trash_gui.find('**/TrashCan_RLVR')), pos=self.trash_pos[slot], command=self.deleteToon, extraArgs=[ self.avChooser.getAvChoiceBySlot(slot).getAvId() ], text_shadow=(0, 0, 0, 1)) delBtn.reparentTo(self.btnList[slot].stateNodePath[0], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[1], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[2], 20) else: self.btnList[slot]['text'] = "Make A Toon" self.btnList[slot]['text_font'] = self.m self.btnList[slot]['text0_scale'] = 0.1 self.btnList[slot]['text1_scale'] = 0.12 self.btnList[slot]['text2_scale'] = 0.12 self.btnList[slot]['text3_scale'] = 0.1 self.btnList[slot]['text0_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text1_fg'] = (0, 1, 0.8, 1) self.btnList[slot]['text2_fg'] = (0.3, 1, 0.9, 1) self.btnList[slot]['text3_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["mat", slot] self.btnList[slot]['text_wordwrap'] = 6 def quitGame(self): base.cr.disconnect() base.cr.shutdown() base.shutdown() sys.exit() def deleteToon(self, avId): notify.warning("deleting Toon with avId %s" % (avId)) base.transitions.fadeOut(0.3) Sequence(Wait(0.31), Func(self.callDeleteToon, avId)).start() def callDeleteToon(self, avId): self.avChooser.avChooseFSM.request("waitForToonDelResponse", [avId]) def setTitle(self, title): if self.title: self.title.destroy() self.title = None self.title = DirectLabel(text=title, text_font=self.m, text_fg=(1, 0.9, 0.1, 1), relief=None, text_scale=0.13, pos=(0, 0, 0.82)) def resetMenu(self, task): self.removeGui() self.createGui() return task.done def fadeMenu(self, direction, slot): base.transitions.fadeOut(0.5) self.slot = slot if direction == "mat": notify.info("Toon selected for creation on slot %s" % (self.slot)) taskMgr.doMethodLater(0.51, self.enterMAT, "enterMAT") elif direction == "playGame": notify.info("Playing game as Toon on slot %s" % (self.slot)) taskMgr.doMethodLater(0.51, self.playGame, "playGame") def enterMAT(self, task): messenger.send("enterMakeAToon") return task.done def handleMATUnavailable(self): base.transitions.fadeIn(0) self.matNAMsg = GlobalDialog(message=CIGlobals.MatNAMsg, doneEvent="matNAEvent", style=1) self.acceptOnce("matNAEvent", self.removeMatNAMsg) def removeMatNAMsg(self, value): self.matNAMsg.destroy() if value: random_gender = random.randint(0, 1) if random_gender == 0: gender = "boy" elif random_gender == 1: gender = "girl" MAT = MakeAToon(self.slot, self.cr) MAT.toonGen.generateToon(gender, 1) MAT.exit("finished") return self.createGui(1) def playGame(self, task): self.removeGui() messenger.send("avChooseDone", [self.avChooser.getAvChoiceBySlot(self.slot)]) def removeGui(self): self.bg.removeNode() self.bg_img.destroy() self.quit_btn.destroy() self.title.destroy() for toon in range(len(self.headList) - 1): self.headList[toon].delete() for button in range(6): self.btnList[button].removeNode() base.setBackgroundColor(CIGlobals.DefaultBackgroundColor) base.transitions.fadeIn(0)
class KOTHGui(DirectFrame): notify = directNotify.newCategory('KOTHGui') pointsSfx = None points = None def __init__(self): DirectFrame.__init__(self, parent=base.a2dTopLeft, relief=None, pos=(0.275, 1, -0.7), sortOrder=0) self.pointsSfx = loader.loadSfx('phase_4/audio/sfx/MG_maze_pickup.ogg') self.points = 0 gui = loader.loadModel('phase_4/models/gui/purchase_gui.bam') panel = gui.find('**/yellowPanel') self.bg = OnscreenImage(image=panel, parent=self) self.title = OnscreenText(text='Capture Points', font=CIGlobals.getMinnieFont(), parent=self, scale=0.0475, pos=(0, 0.18), fg=(1, 0, 0, 1), shadow=(0.2, 0.2, 0.2, 1)) self.amt_label = OnscreenText(text=str(self.points), font=CIGlobals.getToonFont(), parent=self, scale=0.15, pos=(0, 0.03525), shadow=(0.5, 0.5, 0.5, 0.6)) self.info = OnscreenText( text= 'First Toon to 100 points wins!\nEarn points by standing on the\nhill after capturing it.', parent=self, font=CIGlobals.getToonFont(), scale=0.035, pos=(0, -0.05), fg=(1.5, 0, 0, 1), shadow=(0.2, 0.2, 0.2, 1)) self.hide() return def show(self): self.title.show() self.amt_label.show() self.info.show() self.bg.show() def hide(self): self.title.hide() self.amt_label.hide() self.info.hide() self.bg.hide() def destroy(self): self.title.destroy() self.amt_label.destroy() self.info.destroy() self.bg.destroy() self.title = None self.amt_label = None self.info = None self.bg = None self.pointsSfx.stop() self.pointsSfx = None self.points = None DirectFrame.destroy(self) return def setPoints(self, points): self.points = points self.amt_label.setText(str(self.points)) self.pointsSfx.play() def getPoints(self): return self.points
class Timer(DirectFrame): def __init__(self): try: self.Timer_initialized return except: self.Timer_initialized = 1 DirectFrame.__init__(self, pos=(-0.15, 0, -0.15), scale=0.4, parent=base.a2dTopRight) self.setBin('gui-popup', 60) self.timer = None self.timeLbl = None self.initTime = 0 self.zeroCommand = None self.time = 0 self.timerSeq = None return def setInitialTime(self, initTime): self.initTime = initTime def getInitialTime(self): return self.initTime def setZeroCommand(self, command): self.zeroCommand = command def getZeroCommand(self): return self.zeroCommand def startTiming(self): seq = Sequence() for second in range(self.initTime): seq.append(Func(self.setTime, self.initTime - second)) seq.append(Wait(1.0)) if self.zeroCommand != None: seq.append(Func(self.zeroCommand)) seq.start() self.timerSeq = seq def stopTiming(self): if self.timerSeq: self.timerSeq.pause() self.timerSeq = None def load(self): self.unload() timer = loader.loadModel("phase_3.5/models/gui/clock_gui.bam") self.timer = OnscreenImage(image=timer.find('**/alarm_clock'), parent=self) self.timeLbl = DirectLabel(text="0", parent=self, text_scale=0.3, text_pos=(-0.05, -0.13), text_fg=(0, 0, 0, 1), relief=None, text_align=TextNode.ACenter) timer.removeNode() del timer def unload(self): self.stopTiming() if self.timer: self.timer.destroy() self.timer = None if self.timeLbl: self.timeLbl.destroy() self.timeLbl = None def cleanup(self): self.zeroCommand = None self.initTime = None self.time = None DirectFrame.destroy(self) def setTime(self, time): self.time = time if self.timeLbl: if time <= 10: self.timeLbl['text_fg'] = (1, 0, 0, 1) self.timeLbl['text'] = str(time) if len(str(time)) > 2: self.timeLbl['text_scale'] = 0.2 self.timeLbl['text_pos'] = (-0.02, -0.11) else: self.timeLbl['text_scale'] = 0.3 self.timeLbl['text_pos'] = (-0.02, -0.125)
class TeamMinigame: """An abstract class for any minigame that is team-based.""" notify = directNotify.newCategory("TeamMinigame") def __init__(self, team1Name, team1BtnImg, team2Name, team2BtnImg): """ team1Name - A string name of the first playable team. team1BtnImg - A tuple of textures for the team 1 selection button. team2Name - A string name of the second playable team. team2BtnImg - A tuple of textures for the team 2 selection button. """ self.team1Name = team1Name self.team1BtnImg = team1BtnImg self.team2Name = team2Name self.team2BtnImg = team2BtnImg self.teamNameById = {TEAM1: self.team1Name, TEAM2: self.team2Name} # The team we are part of. self.team = None # Both teams have 0 players to start. self.playersByTeam = {TEAM1: 0, TEAM2: 0} ##### TEAM SELECTION STUFF!!! ##### self.container = None self.bg = None self.title = None self.btnFrame = None self.team1Frame = None self.team1Btn = None self.team1Plyrs_Lbl = None self.team2Frame = None self.team2Btn = None self.team2Plyrs_Lbl = None self.teamFull_Lbl = None def makeSelectionGUI(self): font = CIGlobals.getMickeyFont() box = loader.loadModel('phase_3/models/gui/dialog_box_gui.bam') imp = CIGlobals.getToonFont() geom = CIGlobals.getDefaultBtnGeom() self.container = DirectFrame() self.bg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(1.9, 1.4, 1.4), parent=self.container) self.title = OnscreenText(text="Join a Team", pos=(0, 0.5, 0), font=font, scale=(0.12), parent=self.container, fg=(1, 0.9, 0.3, 1)) self.btnFrame = DirectFrame(parent=self.container, pos=(0.14, 0, 0)) self.team1BtnFrame = DirectFrame(parent=self.btnFrame, pos=(-0.5, 0, 0)) self.team2BtnFrame = DirectFrame(parent=self.btnFrame, pos=(0.22, 0, 0)) self.team1Btn = DirectButton(parent=self.team1BtnFrame, relief=None, pressEffect=0, image=self.team1BtnImg, image_scale=(0.9, 1, 1), scale=0.4, command=self.choseTeam, extraArgs=[TEAM1]) self.team1Plyrs_Lbl = OnscreenText(parent=self.team1BtnFrame, text=str(self.playersByTeam[TEAM1]), pos=(0, -0.46, 0), font=imp) self.team2Btn = DirectButton(parent=self.team2BtnFrame, relief=None, pressEffect=0, image=self.team2BtnImg, image_scale=(0.9, 1, 1), scale=0.4, command=self.choseTeam, extraArgs=[TEAM2]) self.team2Plyrs_Lbl = OnscreenText(parent=self.team2BtnFrame, text=str(self.playersByTeam[TEAM2]), pos=(0, -0.46, 0), font=imp) self.teamFull_Lbl = OnscreenText(parent=self.container, text="", pos=(0, -0.6, 0), font=imp) def destroySelectionGUI(self): if self.teamFull_Lbl: self.teamFull_Lbl.destroy() self.teamFull_Lbl = None if self.team2Plyrs_Lbl: self.team2Plyrs_Lbl.destroy() self.team2Plyrs_Lbl = None if self.team1Plyrs_Lbl: self.team1Plyrs_Lbl.destroy() self.team1Plyrs_Lbl = None if self.team2Btn: self.team2Btn.destroy() self.team2Btn = None if self.team1Btn: self.team1Btn.destroy() self.team1Btn = None if self.team2BtnFrame: self.team2BtnFrame.destroy() self.team2BtnFrame = None if self.team1BtnFrame: self.team1BtnFrame.destroy() self.team1BtnFrame = None if self.title: self.title.destroy() self.title = None if self.bg: self.bg.destroy() self.bg = None if self.container: self.container.destroy() self.container = None def choseTeam(self, team): self.team = team self.team1Btn['state'] = DGG.DISABLED self.team2Btn['state'] = DGG.DISABLED self.sendUpdate('choseTeam', [team]) def acceptedIntoTeam(self): message = MSG_WELCOME.format(self.teamNameById[self.team]) whisper = WhisperPopup(message, CIGlobals.getToonFont(), ChatGlobals.WTSystem) whisper.manage(base.marginManager) def teamFull(self): # Oh, man, the team is full. Let's try again. self.teamFull_Lbl.setText('Sorry, that team is full.') self.team = None self.team1Btn['state'] = DGG.NORMAL self.team2Btn['state'] = DGG.NORMAL def incrementTeamPlayers(self, team): self.playersByTeam[team] += 1 if self.fsm.getCurrentState().getName() == 'chooseTeam': if team == TEAM2: lbl = self.team2Plyrs_Lbl elif team == TEAM1: lbl = self.team1Plyrs_Lbl lbl.setText(str(self.playersByTeam[team])) def setTeamOfPlayer(self, avId, team): if not hasattr(self, 'getRemoteAvatar'): self.notify.error('Minigame must have remote avatars!!') remoteAvatar = self.getRemoteAvatar(avId) if remoteAvatar: print "setting team of {0}".format(avId) remoteAvatar.setTeam(team) def cleanup(self): self.destroySelectionGUI() del self.team1Name del self.teamNameById del self.team2Name del self.team1BtnImg del self.team2BtnImg del self.team del self.playersByTeam
class ShopWindow(DirectFrame): def __init__(self, shop, image, wantTurretCount): DirectFrame.__init__(self) self.shop = shop self.wantTurretCount = wantTurretCount self.bgImage = image self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.turretLabel = None self.turretImg = None self.nPage = -1 self.nPages = 0 self.nextPage = 0 self.prevPage = -1 self.pages = [] self.isSetup = False self.turretCount = 0 def setup(self, title='CHOOSE WHAT YOU WANT TO BUY'): font = CIGlobals.getMickeyFont() txtFg = (0, 0, 0, 1) txtScale = 0.05 txtPos = (0, -0.1) buttons = loader.loadModel('phase_3.5/models/gui/QT_buttons.bam') self.window = OnscreenImage(image=self.bgImage, scale=(0.9, 1, 0.7), parent=self) self.title = DirectLabel(text=title, relief=None, pos=(0, 0, 0.5), text_wordwrap=10, text_font=font, text_fg=(1, 1, 0, 1), scale=0.1, parent=self) # Let's update the turret count. self.updateTurretCount() self.infoLbl = DirectLabel(text='Welcome!', relief=None, text_scale=0.075, text_fg=txtFg, text_shadow=(0, 0, 0, 0), pos=(0, 0, 0.215)) self.okBtn = DirectButton(geom=CIGlobals.getOkayBtnGeom(), relief=None, text='OK', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(-0.1, 0, -0.5), parent=self) self.clBtn = DirectButton(geom=CIGlobals.getCancelBtnGeom(), relief=None, text='Cancel', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(0.1, 0, -0.5), parent=self) buttonGeom = (buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back')) self.backBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(-0.3, 0, -0.25), parent=self, command=self.changePage, extraArgs=[0]) self.nextBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(0.3, 0, -0.25), hpr=(0, 0, 180), command=self.changePage, extraArgs=[1], parent=self) self.hideInfo() def setTurrets(self, amount): if self.shop.upgradesPurchased: amount += 1 self.turretCount = amount self.updatePages() def updateTurretCount(self): if self.turretLabel: self.turretLabel.destroy() if self.wantTurretCount: maxTurrets = CogBattleGlobals.MAX_TURRETS if not self.turretImg: self.turretImg = OnscreenImage( image="phase_3.5/maps/cannon-icon.png", scale=(0.05, 1, 0.05), pos=(-0.22, 0, 0.275)) self.turretImg.setTransparency(TransparencyAttrib.MAlpha) self.turretLabel = DirectLabel( text='Turrets: %s/%s' % (str(self.turretCount), str(maxTurrets)), relief=None, text_scale=0.07, text_fg=(0, 0, 0, 1), text_shadow=(0, 0, 0, 0), pos=(0, 0, 0.265)) def changePage(self, direction): var = self.prevPage if direction == 1: var = self.nextPage self.setPage(var) def __makeGagEntry(self, pos, item, values, page): itemImage = values.get('image') button = DirectButton(geom=(itemImage), scale=1.3, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item, page]) supply = base.localAvatar.getBackpack().getSupply(item().getName()) maxSupply = base.localAvatar.getBackpack().getMaxSupply( item().getName()) buttonLabel = DirectLabel( text='%s/%s\n%s JBS' % (str(supply), str(maxSupply), str(values.get('price'))), relief=None, parent=button, text_scale=0.05, pos=(0, 0, -0.11)) self.addEntryToPage(page, item, values, button, buttonLabel) def __makeUpgradeEntry(self, pos, item, values, page): itemImage = values.get('image') button = DirectButton(image=(itemImage), scale=0.15, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item, page]) button.setTransparency(TransparencyAttrib.MAlpha) upgradeID = values.get('upgradeID') avID = base.localAvatar.getPUInventory()[1] supply = 0 battle = base.localAvatar.getMyBattle() if battle and battle.getTurretManager(): turret = battle.getTurretManager().getTurret() if turret and turret.getGagID() == upgradeID: supply = 1 if avID == upgradeID: dataSupply = base.localAvatar.getPUInventory()[0] if dataSupply > 0: supply = dataSupply maxSupply = values.get('maxUpgrades') buttonLabel = DirectLabel( text='%s\n%s/%s\n%s JBS' % (item, str(supply), str(maxSupply), str(values.get('price'))), relief=None, parent=button, text_scale=0.3, pos=(0, 0, -1.2)) self.addEntryToPage(page, item, values, button, buttonLabel) def __makeHealEntry(self, pos, item, values, page): label = '%s' % (item) itemImage = values.get('image') if 'showTitle' in values: label = '%s\n%s JBS' % (item, values.get('price')) button = DirectButton(image=(itemImage), scale=0.105, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item, page]) button.setTransparency(TransparencyAttrib.MAlpha) buttonLabel = DirectLabel(text=label, relief=None, parent=button, text_scale=0.55, pos=(0, 0, -1.6)) self.addEntryToPage(page, item, values, button, buttonLabel) def addEntryToPage(self, page, item, values, button, buttonLabel): page.addItemEntry(item, [button, buttonLabel]) page.addItem({item: values}) def makePages(self, items): newItems = dict(items) loadout = base.localAvatar.getBackpack().getLoadoutInIds() # Let's show the loadout gags first in a full shop. if self.shop.wantFullShop: crcGags = OrderedDict(newItems) for item, values in newItems.items(): if values.get('type') == ItemType.GAG: gag = item() hasGag = base.localAvatar.getBackpack().hasGag(gag.getID()) if gag.getID() not in loadout or not hasGag: del crcGags[item] if not hasGag: del newItems[item] else: del newItems[item] # Let's add back the other gags. crcGags.update(newItems) newItems = crcGags print len(newItems) else: for item, values in newItems.items(): if values.get('type') == ItemType.GAG: gag = item() if gag.getID( ) not in loadout or not base.localAvatar.getBackpack( ).hasGag(gag.getID()): del newItems[item] self.nPages = int(math.ceil((float(len(newItems)) / float(4)))) if self.nPages % 4 != 0 and len(newItems) > 4: self.nPages += 1 elif self.nPages == 0: self.nPages = 1 itemPos = [(-0.45, 0, 0), (-0.15, 0, 0), (0.15, 0, 0), (0.45, 0, 0)] pageIndex = 0 itemIndex = 0 index = 0 for _ in range(self.nPages): page = Page(self.shop, self) self.pages.append(page) for item, values in newItems.iteritems(): pos = itemPos[itemIndex] page = self.pages[pageIndex] itemType = values.get('type') if itemType == ItemType.GAG: self.__makeGagEntry(pos, item, values, page) elif itemType == ItemType.UPGRADE: self.__makeUpgradeEntry(pos, item, values, page) elif itemType == ItemType.HEAL: self.__makeHealEntry(pos, item, values, page) if index == 3: pageIndex += 1 itemIndex = 0 index = 0 else: itemIndex += 1 index += 1 if self.nPages == 1: self.backBtn.hide() self.nextBtn.hide() for page in self.pages: if len(page.getItems()) == 0: page.destroy() self.pages.remove(page) else: page.hide() page.update() self.nPages = len(self.pages) self.isSetup = True def updatePage(self, page): battle = base.localAvatar.getMyBattle() if battle and self.wantTurretCount: self.shop.distShop.sendUpdate('requestTurretCount', []) self.updateTurretCount() page.update() def updatePages(self): battle = base.localAvatar.getMyBattle() if battle and self.wantTurretCount: self.shop.distShop.sendUpdate('requestTurretCount', []) self.updateTurretCount() for page in self.pages: page.update() def setPage(self, page): if self.nPage > -1: self.pages[self.nPage].hide() self.setBackBtn(True) self.setNextBtn(True) if (page - 1) < 0: self.setBackBtn(False) elif (page + 1) == self.nPages: self.setNextBtn(False) if page < 0 or page > self.nPages: return self.prevPage = (page - 1) self.nextPage = (page + 1) self.nPage = page self.pages[page].show() def getPage(self, index): return self.pages[index] def setBackBtn(self, enabled): if self.backBtn: if enabled == False: self.backBtn.setColorScale(GRAYED_OUT_COLOR) self.backBtn['state'] = DGG.DISABLED else: self.backBtn.setColorScale(NORMAL_COLOR) self.backBtn['state'] = DGG.NORMAL def setNextBtn(self, enabled): if self.nextBtn: if enabled == False: self.nextBtn.setColorScale(GRAYED_OUT_COLOR) self.nextBtn['state'] = DGG.DISABLED else: self.nextBtn.setColorScale(NORMAL_COLOR) self.nextBtn['state'] = DGG.NORMAL def setOKCommand(self, command): if self.okBtn: self.okBtn['command'] = command def setCancelCommand(self, command): if self.clBtn: self.clBtn['command'] = command def showInfo(self, text, negative=0, duration=-1): self.infoLbl.show() if negative: self.infoLbl['text_fg'] = (0.9, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 1) else: self.infoLbl['text_fg'] = (0, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 0) self.infoLbl['text'] = text if duration > -1: Sequence(Wait(duration), Func(self.hideInfo)).start() def hideInfo(self): if self.infoLbl: self.infoLbl.hide() def delete(self): elements = [ self.title, self.okBtn, self.clBtn, self.infoLbl, self.backBtn, self.nextBtn, self.turretLabel, self.turretImg ] for element in elements: if element: element.destroy() del elements for page in self.pages: page.destroy() self.pages.remove(page) self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.backBtn = None self.nextBtn = None self.bgImage = None self.turretLabel = None self.turretCount = None if self.window: self.window.destroy() self.window = None self.destroy()
class MinimapCapturePoint(MinimapObject): SORT = 4 def __init__(self, worldNode, holiday, zone): MinimapObject.__init__(self, 'capturePoint-%d' % zone, worldNode, NodePath('capturePoint')) self.holidayId = holiday self.zone = zone self.hpMeter = None self.barricadeIcon = None self.barricadeDestroyed = None self.blinker = None self.sentRemove = False self.hp = 0 self.maxHp = 0 whiteColor = (1.0, 1.0, 1.0, 1.0) self.blinker = Sequence(Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor), Wait(0.20000000000000001), Func(self.setBarColor, whiteColor), Wait(0.20000000000000001), Func(self.setBarColor)) def setHp(self, hp, maxHp): if self.hpMeter: if hp != self.hpMeter.meter['value']: pass hpMismatch = hp != maxHp self.hp = hp self.maxHp = hp self.hpMeter.update(hp, maxHp) if hpMismatch: if self.blinker: self.blinker.finish() self.blinker.start() if hp <= 0 and maxHp >= 0 and not (self.sentRemove): self.sentRemove = True if self.hpMeter: self.hpMeter.destroy() self.hpMeter = None if self.blinker: self.blinker.pause() self.blinker = None if self.barricadeIcon: self.barricadeIcon.destroy() self.barricadeIcon = None if self.barricadeDestroyed and self.zone != InvasionGlobals.getTotalCapturePoints(self.holidayId): self.barricadeDestroyed.show() return True else: return False def setBarColor(self, color = None): if self.barricadeIcon: if color: barricadeColor = color else: barricadeColor = (1.0, 0.5, 0.0, 1) self.barricadeIcon.setColor(barricadeColor) if self.hpMeter: if not color: if self.maxHp <= 0: hpFraction = 0 else: hpFraction = float(self.hp) / float(self.maxHp) if hpFraction >= 0.5: color = (0.10000000000000001, 0.69999999999999996, 0.10000000000000001, 1) elif hpFraction >= 0.25: color = (1.0, 1.0, 0.10000000000000001, 1) else: color = (1.0, 0.0, 0.0, 1) self.hpMeter.meter['barColor'] = color if color == PiratesGuiGlobals.TextFG2: self.hpMeter.categoryLabel['text_fg'] = color else: self.hpMeter.categoryLabel['text_fg'] = PiratesGuiGlobals.TextFG1 def _addedToMap(self, map): self.mapGeom.setScale(aspect2d, 0.29999999999999999) overlayNode = map.getOverlayNode() worldNode = map.getWorldNode() transform = self.mapGeom.getTransform(overlayNode) self.hpMeter = HpMeter(width = 0.40000000000000002, parent = overlayNode) self.hpMeter.setP(-90) if self.zone != InvasionGlobals.getTotalCapturePoints(self.holidayId): self.hpMeter.setPos(transform.getPos() + (50, 0, 0)) else: self.hpMeter.setPos(InvasionGlobals.getMainCapturePointHpPos(self.holidayId)) self.hpMeter.setScale(transform.getScale()) self.hpMeter['sortOrder'] = MinimapCapturePoint.SORT self.hpMeter.setAlphaScale(1, 1) self.hpMeter.categoryLabel['text_scale'] = 0.10000000000000001 self.hpMeter.update(1, 1) topGui = loader.loadModel('models/gui/toplevel_gui') if self.zone != InvasionGlobals.getTotalCapturePoints(self.holidayId): self.barricadeIcon = OnscreenImage(parent = self.mapGeom, image = topGui.find('**/pir_t_gui_gen_barricade'), scale = 1.5, hpr = (0, 90, 0), color = (1.0, 0.5, 0.0, 1)) self.barricadeDestroyed = OnscreenImage(parent = overlayNode, image = topGui.find('**/pir_t_gui_gen_Xred'), scale = transform.getScale() * 4.0, pos = transform.getPos(), hpr = (0, -90, 0)) self.barricadeDestroyed.hide() topGui.removeNode() self.mouseOver = GuiButton(parent = self.hpMeter, relief = None, state = DGG.NORMAL, scale = 3.0, image = None, frameSize = (-0.10000000000000001, 0.14999999999999999, -0.029999999999999999, 0.029999999999999999), helpText = PLocalizer.CapturePointNames[self.holidayId][self.zone], helpPos = (0.10000000000000001, 0, -0.080000000000000002), helpDelay = 0, helpOpaque = True, sortOrder = MinimapShop.SORT) def _removedFromMap(self, map): if self.blinker: self.blinker.pause() self.blinker = None if self.hpMeter: self.hpMeter.destroy() self.hpMeter = None if self.barricadeIcon: self.barricadeIcon.destroy() self.barricadeIcon = None if self.barricadeDestroyed: self.barricadeDestroyed.destroy() self.barricadeDestroyed = None def getZone(self): return self.zone
class KOTHKingGui(DirectFrame): notify = directNotify.newCategory('KOTHKingGui') def __init__(self, mg, king, points): DirectFrame.__init__(self, parent = aspect2d) self.setBin('gui-popup', 60) self.mg = mg # Let's create the background box = DGG.getDefaultDialogGeom() self.bg = OnscreenImage(image = box, color = (1, 1, 0.75, 1), scale = (1.9, 1.4, 1.4), parent = self) # Let's create the header toonFont = CIGlobals.getToonFont() minnieFont = CIGlobals.getMinnieFont() name = 'Nobody' if king: name = king.getName() self.kingId = king.doId else: king = base.localAvatar self.kingId = 0 self.title = OnscreenText(text = '%s is King!' % name, pos = (0, 0.5, 0), font = toonFont, scale = 0.12, parent = self, shadow = (0.5, 0.5, 0.5, 0.6)) # Let's create the Toon head headFrame = self.attachNewNode('head') headFrame.setPosHprScale(0, 0, -0.1, 180, 0, 0, 0.3, 0.3, 0.3) head = ToonGlobals.generateGuiHead(king) head.reparentTo(headFrame) # Let's create the points text self.amt_label = OnscreenText(text = 'Your Points: 0', pos = (-0.012, -0.4, 0), font = toonFont, scale = 0.12, parent = self, shadow = (0.5, 0.5, 0.5, 0.6)) self.amt_label.hide() # Let's create the bad news text self.motivator = OnscreenText(text = 'Better luck next time!', pos = (0, -0.6, 0), font = minnieFont, scale = 0.125, parent = self, fg = (1, 0, 0, 1), shadow = (0.2, 0.2, 0.2, 1)) self.motivator.hide() self.easterEgg = False if 50 < points != 100: self.motivator['fg'] = (0, 1, 0, 1) self.motivator.setText('Great job!') elif points == 100: self.motivator['fg'] = (0, 1, 0, 1) if random.randint(0, 100) <= 10: self.motivator.setText('YOU THE REAL MVP!') self.easterEgg = True else: self.motivator.setText('AMAZING!') # Let's create the sound effects self.zeroPointsSfx = loader.loadSfx('phase_4/audio/sfx/MG_neg_buzzer.ogg') self.poorScoreSfx = loader.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_no_bonus.ogg') self.goodScoreSfx = loader.loadSfx('phase_4/audio/sfx/MG_pairing_match_bonus_both.ogg') self.stomperSfx = loader.loadSfx('phase_4/audio/sfx/CHQ_FACT_stomper_small.ogg') self.fireworkSfx = loader.loadSfx('phase_4/audio/sfx/firework_explosion_02.ogg') self.perfectSfx = loader.loadSfx('phase_5/audio/sfx/SZ_MM_fanfare.ogg') self.tick_fastSfx = loader.loadSfx('phase_4/audio/sfx/MG_maze_pickup.ogg') self.tick_slowSfx = loader.loadSfx('phase_3.5/audio/sfx/tick_counter.ogg') self.easterEggSfx = loader.loadSfx('phase_4/audio/sfx/avatar_emotion_very_sad.ogg') # Let's create the basic sequence self.pointsSeq = Sequence(Func(self.amt_label.show), Wait(0.25)) self.seqLevel = 0 self.fakeNumber = 0 self.points = points def start(self): base.transitions.fadeScreen(0.5) if self.points == 0: self.__doZero() else: self.__doRegular() def destroy(self): # Let's stop the sequence. if self.pointsSeq: self.pointsSeq.finish() self.pointsSeq = None # Let's stop and destroy all the sounds. if self.zeroPointsSfx: self.zeroPointsSfx.stop() self.poorScoreSfx.stop() self.goodScoreSfx.stop() self.stomperSfx.stop() self.fireworkSfx.stop() self.perfectSfx.stop() self.tick_fastSfx.stop() self.tick_slowSfx.stop() self.easterEggSfx.stop() self.zeroPointsSfx = None self.poorScoreSfx = None self.goodScoreSfx = None self.stomperSfx = None self.fireworkSfx = None self.perfectSfx = None self.tick_fastSfx = None self.tick_slowSfx = None self.easterEggSfx = None # Let's destroy all the variables. self.points = None self.easterEgg = None self.seqLevel = None self.fakeNumber = None self.kingId = None self.mg = None # Let's destroy all the frames. if self.bg: self.bg.destroy() self.title.destroy() self.amt_label.destroy() self.motivator.destroy() self.bg = None self.title = None self.amt_label = None self.motivator = None DirectFrame.destroy(self) def unload(self): pass def hideFinalScores(self): base.transitions.noTransitions() self.hide() def handleExit(self): winner = 0 if self.kingId != 0: winner = 1 self.pointsSeq.append(Sequence(Wait(5), Func(self.mg.gameOver, winner, [self.kingId]))) return def __doZeroEffect(self, task): if self.seqLevel == 0: task.delayTime = 0.2 self.tick_fastSfx.play() self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.fakeNumber += 1 if self.fakeNumber == 3: self.seqLevel = 1 elif self.seqLevel == 1: task.delayTime = 0.35 self.tick_slowSfx.play() self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.fakeNumber += 1 if self.fakeNumber == 6: self.seqLevel = 2 task.delayTime = 0.35 elif self.seqLevel == 2: task.delayTime = 0.10 self.tick_fastSfx.play() self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.fakeNumber -= 1 if self.fakeNumber == -1: self.stomperSfx.play() ToontownIntervals.start(ToontownIntervals.getPulseLargerIval(self.amt_label, 'effect')) self.pointsSeq = Sequence(Wait(0.25), Func(self.zeroPointsSfx.play), Func(self.motivator.show)) self.handleExit() self.pointsSeq.start() return task.done return task.again def __doRegularEffect(self, task): if self.points <= 5 and self.seqLevel == 0: self.seqLevel = 2 if self.seqLevel == 0: task.delayTime = 0.35 self.fakeNumber += 1 self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.tick_slowSfx.play() if self.fakeNumber == 2: task.delayTime = 0.25 self.seqLevel = 1 elif self.seqLevel == 1: if self.points <= 50: task.delayTime = 0.12 elif 50 < self.points != 100: task.delayTime = 0.075 else: task.delayTime = 0.065 self.fakeNumber += 1 self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.tick_fastSfx.play() if self.fakeNumber == self.points - 5: task.delayTime = 0.25 self.seqLevel = 2 elif self.seqLevel == 2: task.delayTime = 0.35 self.fakeNumber += 1 self.amt_label.setText('Your Points: %s' % str(self.fakeNumber)) self.tick_slowSfx.play() if self.fakeNumber == self.points: if self.points <= 50: self.pointsSeq = Sequence(Wait(0.25), Func(self.poorScoreSfx.play), Func(self.motivator.show)) elif 50 < self.points != 100: pulse = ToontownIntervals.getPulseLargerIval(self.amt_label, 'effect') self.pointsSeq = Sequence(Wait(0.25), Func(self.goodScoreSfx.play), Func(ToontownIntervals.start, pulse), Func(self.motivator.show)) elif self.points == 100: pulse = ToontownIntervals.getPulseLargerIval(self.amt_label, 'effect') self.pointsSeq = Sequence(Wait(0.25), Func(ToontownIntervals.start, pulse), Func(self.fireworkSfx.play), Wait(0.25), Func(self.perfectSfx.play), Func(self.motivator.show)) if self.easterEgg: self.pointsSeq.append(Sequence(Wait(0.30), Func(self.easterEggSfx.play))) self.handleExit() self.pointsSeq.start() return task.done return task.again def __doZero(self): self.pointsSeq.append(Sequence( Func(taskMgr.add, self.__doZeroEffect, 'Point Effect') )) self.pointsSeq.start() def __doRegular(self): self.pointsSeq.append(Sequence( Func(taskMgr.add, self.__doRegularEffect, 'Point Effect') )) self.pointsSeq.start()
class DMenuScreen(DirectObject): notify = directNotify.newCategory('DMenuScreen') def __init__(self):#, avatarList, parentFSM, doneEvent): DirectObject.__init__(self) base.disableMouse() #base.cr.avChoice = None fadeSequence = Sequence( Wait(.5), Func(base.transitions.fadeIn, .5), Wait(1)).start()#, #base.camera.posHprInterval(1, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut')).start() #self.background = loader.loadModel('phase_4/models/neighborhoods/toontown_central_full') #self.background.reparentTo(render) #for frame in render.findAllMatches('*/doorFrame*'): # frame.removeNode() #self.sky = loader.loadModel('phase_3.5/models/props/TT_sky') #SkyUtil.startCloudSky(self) #base.camera.setPosHpr(INIT_POS, INIT_HPR) self.background = OnscreenImage(image = DMenuResources.MenuBackground, parent = aspect2d) self.background.setBin('background', 1) self.background.reparentTo(aspect2d) self.background.setScale(2, 1, 1) self.logo = OnscreenImage(image = DMenuResources.GameLogo, scale = (1, 1, .5)) self.logo.reparentTo(aspect2d) self.logo.setTransparency(TransparencyAttrib.MAlpha) scale = self.logo.getScale() self.logo.setPos(0, 0, .5) self.logo.setColorScale(Vec4(0, 0, 0, 0)) #fadeInBackground = (LerpColorScaleInterval(self.background, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() self.createButtons() self.fadeOut = None self.optionsMgr = DMenuOptions.DMenuOptions() self.quitConfirmation = DMenuQuit.DMenuQuit() # TT: We need these to run the Pick A Toon screen #self.patAvList = avatarList #self.patFSM = parentFSM #self.patDoneEvent = doneEvent self.transcircle = Resources.transcircle self.transcircle.setTransparency(TransparencyAttrib.MAlpha) self.transcircle.setScale(VBase3(0.01, 0.01, 0.01)) self.transcircle.setBin('background', 3) self.savemgr = LOTASaveMgr.LOTASaveMgr() # Get the save data self.savePos = self.savemgr.loadSaveData() self.titleMusic = Resources.titleMusic self.titleMusic.setLoop(1) self.setMusicNormal() def skyTrack(self, task): # return SkyUtil.cloudSkyTrack(task) pass def createButtons(self): self.PlayButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.PlayGame, text_scale = .1, scale = 0.95, command = self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Options, text_scale = .1, scale = 0.95, command = self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Quit, text_scale = .1, scale = 0.95, command = self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show() # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95) # self.BRButton.reparentTo(aspect2d) # self.BRButton.setPos(-.9, 0, -.9) # self.BRButton.show() self.buttonInAnimation() # Slap on the saves menu from the old main menu until a proper implementation to DMENU is made self.SavesButton = DirectButton(relief = None, text = AmdLocalizerEnglish.LOTA_SAVES, image_scale = 2, text_scale = .1, scale = 0.95, command = self.openSavesMenu) self.SavesButton.reparentTo(aspect2d) self.SavesButton.setPos(0, 0, -.5) self.SavesButton.show() def murder(self): if self.logo is not None: self.logo.destroy() self.logo = None if self.background is not None: self.background.hide() self.background.reparentTo(hidden) self.background.removeNode() self.background = None if self.PlayButton is not None: self.PlayButton.destroy() self.PlayButton = None if self.OptionsButton is not None: self.OptionsButton.destroy() self.OptionsButton = None if self.QuitButton is not None: self.QuitButton.destroy() self.QuitButton = None if self.SavesButton is not None: self.SavesButton.destroy() self.SavesButton = None if self.titleMusic is not None: self.titleMusic.stop() #taskMgr.remove('skyTrack') #self.sky.reparentTo(hidden) def openOptions(self): self.optionsMgr.showOptions() self.closeOptionsButton = DirectButton(relief = None, text = "< Back", text_fg = (0.977, 0.816, 0.133, 1), text_pos = (0, -0.035), scale = .1, command = self.hideOptions) self.closeOptionsButton.reparentTo(base.a2dTopLeft) self.closeOptionsButton.setPos(0.5, 0, -0.07) Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnHidePos), blendType = 'easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnHidePos), blendType = 'easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnHidePos), blendType = 'easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start() #base.camera.posHprInterval(0.5, Point3(HQ_POS), VBase3(HQ_HPR), blendType = 'easeInOut').start() #self.setMusicCalm() def hideOptions(self): self.optionsMgr.hideOptions() self.closeOptionsButton.hide() Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut'), self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut')).start() base.camera.posHprInterval(0.5, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut').start() #self.setMusicNormal() def playGame(self): if self.fadeOut is not None: self.fadeOut.finish() self.fadeOut = None self.fadeOut = base.transitions.getFadeOutIval(t = 1) #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start() Sequence( Func(self.doPlayButton), #Func(self.fadeOut.start), Wait(1), Func(self.murder), Wait(1), Func(self.enterGame)).start()#, #Func(base.transitions.fadeIn, 1)).start() def enterOptions(self): pass def enterGame(self): #base.cr.avChoice = AvatarChooser.AvatarChooser(self.patAvList, self.patFSM, self.patDoneEvent) #base.cr.avChoice.load(1) #base.cr.avChoice.enter() from Game.NewGame.Scenes import SceneOne # Hamburger Menu Button #self.hbButton = DirectButton(image = "phase_3/maps/dmenu/dmhbmenu.png", relief = None, text = ' ', command=self.showHamburgerMenu) #self.hbButton.reparentTo(base.a2dTopLeft) #self.hbButton.setPos(0.05, 0, -0.05) #self.hbButton.setScale(0.04) # Hamburger Menu Hide Button #self.hbHideButton = DirectButton(image = "phase_3/maps/dmenu/close_window.png", relief = None, text = ' ', command=self.hideHamburgerMenu) #self.hbHideButton.reparentTo(base.a2dTopLeft) #self.hbHideButton.setPos(0.05, 0, -0.05) #self.hbHideButton.setScale(0.04) #self.hbHideButton.hide() # TODO: Add options and stuff to the hamburger menu def doPlayButton(self): Parallel( self.PlayButton.posInterval(1, Point3(PlayBtnHidePos), blendType = 'easeInOut'), self.OptionsButton.posInterval(1, Point3(OptionsBtnHidePos), blendType = 'easeInOut'), self.QuitButton.posInterval(1, Point3(QuitBtnHidePos), blendType = 'easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start() def quitGame(self): self.showQuitConfirmation() def showQuitConfirmation(self): self.quitConfirmation.showConfirmation() #base.exitFunc() def setMusicNormal(self): #LerpFunctionInterval(base.cr.music.setVolume, fromData = 0, toData = .9, duration = 1).start() #LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = .9, toData = 0, duration = 1).start() self.titleMusic.play() def setMusicCalm(self): LerpFunctionInterval(base.cr.music.setVolume, fromData = .9, toData = 0, duration = 1).start() LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = 0, toData = .9, duration = 1).start() def openSavesMenu(self): self.saveOne = DirectButton(relief=None, text = 'Save One: ' + '(Scene ' + str(self.savePos) + ')', scale=0.3, command=self.saveLoader, parent=aspect2d, pos=(0, 0, -.6), text_scale = .5) self.saveOne.hide() self.transcircle.show() self.exitLoadButton = DirectButton(relief=None, text = '< Back', scale=0.3, command=self.closeSavesMenu, parent=base.a2dBottomCenter, pos=(0, 0, -.4), text_scale = .5) self.exitLoadButton.show() self.openSavesMenuSequence = Parallel( self.transcircle.scaleInterval(0.5, VBase3(3, 3, 3), blendType = 'easeInOut'), self.exitLoadButton.posInterval(0.5, Point3(0, 0, .4), blendType = 'easeInOut'), Func(self.saveOne.show), self.saveOne.posInterval(0.5, Point3(0, 0, .2), blendType = 'easeInOut')) self.openSavesMenuSequence.start() def closeSavesMenu(self): self.hideThings = Sequence( Wait(0.5), Func(self.saveOne.hide), Func(self.transcircle.hide)) self.closeSavesMenuSequence = Parallel( self.saveOne.posInterval(0.5, Point3(0, 0, -.6), blendType = 'easeInOut'), self.transcircle.scaleInterval(0.5, VBase3(0.01, 0.01, 0.01), blendType = 'easeInOut'), self.exitLoadButton.posInterval(0.5, Point3(0, 0, -.4), blendType = 'easeInOut'), Func(self.hideThings.start)) self.closeSavesMenuSequence.start() self.exitLoadButton.removeNode() del self.exitLoadButton def saveLoader(self): # this was thrown together in like 10 seconds. how the f**k does this work # TODO: Make this save to a file thats not easily editable self.saveOne.hide() self.background.hide() self.transcircle.hide() if self.savePos == '1': from Game.NewGame.Scenes import SceneOne elif self.savePos == '2': from Game import SceneTwo elif self.savePos == '3': from Game import SceneThree elif self.savePos == '4': from Game import SceneFour elif self.savePos == '5': from Game import SceneFive else: print ("\n\n Save data is set to an unknown scene!!\n\n") def buttonInAnimation(self): logo = self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut') play = self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut') opt = self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut') quit = self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut') Sequence( Func(logo.start), Wait(0.1), Func(play.start), Wait(0.2), Func(opt.start), Wait(0.2), Func(quit.start)).start() def showHamburgerMenu(self): self.hbButton.hide() self.hbHideButton.show() def hideHamburgerMenu(self): self.hbButton.show() self.hbHideButton.hide()
class DistributedPieTurretManager(DistributedObject): notify = directNotify.newCategory("DistributedPieTurretManager") def __init__(self, cr): DistributedObject.__init__(self, cr) self.myTurret = None self.guiFrame = None self.guiLabel = None self.guiBar = None self.guiBg = None self.turretGag = None return def announceGenerate(self): DistributedObject.announceGenerate(self) base.taskMgr.add(self.__pollMyBattle, "__pollMyBattle") def disable(self): base.taskMgr.remove("DPTM.pollTurret") base.taskMgr.remove("__pollMyBattle") if hasattr(self, "makeTurretBtn"): self.makeTurretBtn.destroy() del self.makeTurretBtn self.destroyGui() self.myTurret = None if base.localAvatar.getMyBattle(): base.localAvatar.getMyBattle().setTurretManager(None) DistributedObject.disable(self) return def __pollTurret(self, turretId, task): turret = self.cr.doId2do.get(turretId) if turret != None: self.myTurret = turret self.turretGag = None self.makeGui() return Task.done else: return Task.cont def setGag(self, upgradeId): self.turretGag = upgradeId def d_requestPlace(self, posHpr): self.sendUpdate("requestPlace", [posHpr]) def turretPlaced(self, turretId): turret = self.cr.doId2do.get(turretId) turret.b_setGag(self.turretGag) self.turretGag = None base.taskMgr.add(self.__pollTurret, "DPTM.pollTurret", extraArgs=[turretId], appendTask=True) return def yourTurretIsDead(self): base.taskMgr.remove("DPTM.pollTurret") self.destroyGui() self.myTurret = None if base.localAvatar.getPUInventory()[0] > 0: self.createTurretButton() return def makeGui(self): self.destroyGui() self.guiFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.55, 0, 0.15)) self.guiBg = OnscreenImage(image="phase_4/maps/turret_gui_bg.png", scale=(0.15, 0, 0.075), parent=self.guiFrame) self.guiBg.setTransparency(True) self.guiLabel = DirectLabel( text="Turret", text_fg=(1, 0, 0, 1), relief=None, text_scale=0.05, text_font=loader.loadFont("phase_3/models/fonts/ImpressBT.ttf"), pos=(0, 0, 0.025), parent=self.guiFrame, ) self.guiBar = DirectWaitBar( range=self.myTurret.getMaxHealth(), value=self.myTurret.getHealth(), scale=0.125, parent=self.guiFrame, pos=(0, 0, -0.01), ) return def createTurretButton(self): self.makeTurretBtn = DirectButton( relief=None, geom=CIGlobals.getDefaultBtnGeom(), text="Turret", text_scale=0.055, command=self.handleMakeTurretBtn, pos=(-0.47, 0, 0.1), geom_scale=(0.5, 1.0, 1.0), text_pos=(0, -0.01), parent=base.a2dBottomRight, ) return def handleMakeTurretBtn(self): self.makeTurretBtn.destroy() del self.makeTurretBtn x, y, z = base.localAvatar.getPos() h, p, r = base.localAvatar.getHpr() self.d_requestPlace([x, y, z, h, p, r]) base.localAvatar.sendUpdate("usedPU", [0]) def __pollMyBattle(self, task): if base.localAvatar.getMyBattle(): base.localAvatar.getMyBattle().setTurretManager(self) if base.localAvatar.getPUInventory()[0] > 0: self.createTurretButton() return Task.done return Task.cont def destroyGui(self): if self.guiBar: self.guiBar.destroy() self.guiBar = None if self.guiLabel: self.guiLabel.destroy() self.guiLabel = None if self.guiBg: self.guiBg.destroy() self.guiBg = None if self.guiFrame: self.guiFrame.destroy() self.guiFrame = None return def updateTurretGui(self): if self.guiBar: self.guiBar.update(self.myTurret.getHealth())
class Credits(DirectObject): developers = {'Game Development': ['DuckyDuck1553', 'DecodedLogic']} webDevelopers = { 'Web Development': ['totok', 'DuckyDuck1553', 'DecodedLogic'] } artists = { 'Artists': [ 'John L. (supertricky)', 'DuckyDuck1553', 'DecodedLogic', 'Baru (fatigue)', 'Isabel (allyjean)', 'Colorblind', 'loonatic' ] } composers = {'Composers': ['Dylan J.', 'Doc. Dynamite', 'CBiard']} communityManager = {'Community Manager': ['Leo (Bradley)']} moderators = { 'Moderation Team': ['Mark (Black & White)', 'Jackson M.', 'Gabriel A.', 'Davon M.'] } specialThanks = { 'Special Thanks': [ 'Jesse Schell', 'rdb', 'Baribal', 'ThomasEgi', 'tobspr', 'jjkoletar', 'mmavipc', 'CFSWorks', 'loblao', 'HarvTarv', 'Hawkheart', 'TheRandomDog', 'Joey Z. (joey19982)', 'Disney Interactive', 'Microsoft', 'YorkeTheMouse', 'Disyer', '\n\n\nAnd of course, YOU!\n\n\n' ] } def __init__(self): DirectObject.__init__(self) base.setBackgroundColor(0, 0, 0) self.textParent = base.credits2d.attachNewNode('textParent') self.textParent.setBin("gui-popup", 61) self.textParent.setDepthWrite(False) self.textParent.setTransparency(True) self.logoImage = OnscreenImage('phase_3/maps/CogInvasion_Logo.png', parent=self.textParent, scale=(0.685, 1.0, 0.325)) self.logoImage.setTransparency(1) text = self.buildCreditsText() self.creditsText = OnscreenText(parent=self.textParent, font=CIGlobals.getToonFont(), fg=(1, 1, 1, 1), scale=0.065, pos=(0, -0.5, 0), text=text, shadow=(0, 0, 0, 1)) self.posInterval = None self.backgroundImg = OnscreenImage('phase_3/maps/credits_fade.png', parent=render2d) self.backgroundImg.setTransparency(True) self.backgroundImg.setColor(0, 0, 0, 1.0) self.backgroundImg.setBin("gui-popup", 62) self.backgroundImg.setDepthWrite(False) self.exitText = OnscreenText(parent=base.credits2d, font=CIGlobals.getToonFont(), fg=(1.0, 0, 0, 1.0), shadow=(0, 0, 0, 1), scale=0.085, pos=(0, -0.96, 0), text='Press any key to exit') self.exitText.hide() self.exitText.setBin("gui-popup", 63) self.exitText.setDepthWrite(False) self.exitText.setTransparency(True) self.creditsAudioMgr = AudioManager.createAudioManager() self.creditsAudioMgr.setVolume(0.65) self.bgm = self.creditsAudioMgr.getSound( 'phase_4/audio/bgm/new_years_fireworks_music.ogg') def buildCreditsText(self): def writeNames(message, namesList): for name in namesList: message = '%s%s\n' % (message, name) return message message = 'Cog Invasion Online\n{0}\n'.format( metadata.getBuildInformation()) message += '\nCREDITS\n\n' # Write the game developers' names message += 'Programming\n\n' message += '%s\n' % self.developers.keys()[0] message = writeNames(message, self.developers.values()[0]) message += '\n\n' # Write the web developers' names message += '%s\n' % self.webDevelopers.keys()[0] message = writeNames(message, self.webDevelopers.values()[0]) # Let's begin the art section message += '\n\nArt\n\n' # Write the artists' names message += '%s\n' % self.artists.keys()[0] message = writeNames(message, self.artists.values()[0]) message += '\n\n' # Write the composers' names message += '%s\n' % self.composers.keys()[0] message = writeNames(message, self.composers.values()[0]) ########################################## # Let's begin the community section. message += '\n\nCommunity\n\n' # Write the community manager names message += '%s\n' % self.communityManager.keys()[0] message = writeNames(message, self.communityManager.values()[0]) message += '\n\n' # Write the moderators' names message += '%s\n' % self.moderators.keys()[0] message = writeNames(message, self.moderators.values()[0]) # Let's begin the Special Thanks section. message += '\n\n' # Write the special thanks' names message += '%s\n' % self.specialThanks.keys()[0] message = writeNames(message, self.specialThanks.values()[0]) message += '\nWe thank the original Toontown Online team.\nNot only for the game, but for the memories.' message += "\n\n\n\n\"Don't cry because it's over.\nSmile because it happened.\"\n - Dr. Seuss" return message def exit(self, key): self.__fadeOut() base.taskMgr.doMethodLater(1.1, self.__exitTask, "exitTask") def __exitTask(self, task): messenger.send('credits-Complete') self.ignoreAll() self.destroy() base.unMuteMusic() base.unMuteSfx() base.setBackgroundColor(0.05, 0.15, 0.4) base.transitions.fadeIn(1.0) return task.done def watchTextPosition(self, task): if self.textParent.getZ() >= 5.187: self.exitText.show() self.acceptOnce('button', self.exit) return task.done return task.cont def __fadeIn(self): Parallel( LerpColorScaleInterval(self.textParent, 1.0, (1, 1, 1, 1), (1, 1, 1, 0)), LerpColorScaleInterval(self.backgroundImg, 1.0, (1, 1, 1, 1), (1, 1, 1, 0)), LerpColorScaleInterval(self.exitText, 1.0, (1, 1, 1, 1), (1, 1, 1, 0))).start() def __fadeOut(self): Parallel( LerpColorScaleInterval(self.textParent, 1.0, (1, 1, 1, 0), (1, 1, 1, 1)), LerpColorScaleInterval(self.backgroundImg, 1.0, (1, 1, 1, 0), (1, 1, 1, 1)), LerpColorScaleInterval(self.exitText, 1.0, (1, 1, 1, 0), (1, 1, 1, 1))).start() def setup(self): self.__fadeIn() b3 = self.textParent.getTightBounds() dimensions = b3[1] - b3[0] self.posInterval = self.textParent.posInterval( 50, Point3(0, 0, dimensions[2] + 2), Point3(0, 0, 0)) self.posInterval.start() self.bgm.setLoop(1) self.bgm.play() base.buttonThrowers[0].node().setButtonDownEvent('button') taskMgr.add(self.watchTextPosition, 'Watch Text Position') def destroy(self): if self.posInterval: self.posInterval.pause() self.posInterval = None if self.bgm: self.bgm.stop() self.bgm = None if self.backgroundImg: self.backgroundImg.destroy() self.backgroundImg = None if self.creditsText: self.creditsText.destroy() self.creditsText = None if self.exitText: self.exitText.destroy() self.exitText = None if self.logoImage: self.logoImage.destroy() self.logoImage = None if self.textParent: self.textParent.removeNode() self.textParent = None if self.creditsAudioMgr: self.creditsAudioMgr.stopAllSounds() self.creditsAudioMgr = None self.developers = None self.webDevelopers = None self.artists = None self.specialThanks = None self.composers = None self.communityManager = None self.moderators = None self.prevMusic = None
class CameraShyFirstPerson(FirstPerson): toonInFocusColor = VBase4(0.25, 1.0, 0.25, 1.0) toonOutOfFocusColor = VBase4(1.0, 1.0, 1.0, 1.0) fullyChargedState = 5 def __init__(self, mg): self.mg = mg self.cameraFocus = None self.batteryFrame = None self.batteryBg = None self.batteryBar = None self.rechargeSound = None self.fullyChargedSound = None self.hasToonInFocus = False self.toonToTakePicOf = None self.cameraRechargeState = None self.cameraRechargingLabel = None self.cameraFlashSeq = None self.camFSM = ClassicFSM('CameraFSM', [ State('off', self.enterOff, self.exitOff), State('ready', self.enterCameraReady, self.exitCameraReady), State('recharge', self.enterCameraRecharge, self.exitCameraRecharge) ], 'off', 'off') self.camFSM.enterInitialState() FirstPerson.__init__(self) return def enterOff(self): pass def exitOff(self): pass def enterCameraReady(self): self.acceptOnce('mouse1', self.__mouse1Pressed) def stopCameraFlash(self): if self.cameraFlashSeq: self.cameraFlashSeq.finish() self.cameraFlashSeq = None return def __mouse1Pressed(self): self.cameraFlashSeq = Sequence( Func(base.transitions.setFadeColor, 1, 1, 1), Func(base.transitions.fadeOut, 0.1), Wait(0.1), Func(base.transitions.fadeIn, 0.1), Wait(0.1), Func(base.transitions.setFadeColor, 0, 0, 0)) self.cameraFlashSeq.start() self.mg.sendUpdate('remoteAvatarTakePicture', [base.localAvatar.doId]) self.mg.myRemoteAvatar.takePicture() if self.hasToonInFocus and self.toonToTakePicOf: self.mg.sendUpdate('tookPictureOfToon', [self.toonToTakePicOf.doId]) self.camFSM.request('recharge') def exitCameraReady(self): self.ignore('mouse1') def enterCameraRecharge(self): self.batteryBar.update(0) taskMgr.add(self.__rechargeNextState, 'rechargeCamera') def __rechargeNextState(self, task): if self.cameraRechargeState == None: self.cameraRechargeState = -1 self.cameraRechargeState += 1 if self.cameraRechargeState > 0: base.playSfx(self.rechargeSound) self.batteryBar.update(self.cameraRechargeState) if self.cameraRechargeState == self.fullyChargedState: base.playSfx(self.fullyChargedSound) self.camFSM.request('ready') return task.done task.delayTime = 1.0 return task.again def exitCameraRecharge(self): taskMgr.remove('rechargeCamera') self.cameraRechargeState = None return def __traverse(self, task): if not base.mouseWatcherNode.hasMouse(): return task.cont mpos = base.mouseWatcherNode.getMouse() self.focusRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.focusTrav.traverse(render) if self.focusHandler.getNumEntries() > 0: self.focusHandler.sortEntries() firstObj = self.focusHandler.getEntry(0).getIntoNodePath() avId = firstObj.getParent().getPythonTag('player') avatar = self.mg.cr.doId2do.get(avId) toonInFoc = False if avatar: remoteAvatar = self.mg.getRemoteAvatar(avatar.doId) if remoteAvatar: toonInFoc = True self.__handleToonInFocus(avatar) if not toonInFoc: self.toonToTakePicOf = None self.hasToonInFocus = False if self.cameraFocus.getColorScale() == self.toonInFocusColor: self.cameraFocus.setColorScale(self.toonOutOfFocusColor) return task.cont def __handleToonInFocus(self, toon): if not self.hasToonInFocus or self.toonToTakePicOf is not None or self.toonToTakePicOf.doId != toon.doId: self.toonToTakePicOf = toon self.hasToonInFocus = True self.cameraFocus.setColorScale(self.toonInFocusColor) return def start(self): self.fullyChargedSound = base.loadSfx( 'phase_4/audio/sfx/MG_pairing_match.ogg') self.rechargeSound = base.loadSfx( 'phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.ogg') self.batteryFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.2, 0, 0.1), scale=(0.8, 0, 1)) self.batteryBg = OnscreenImage( image='phase_4/maps/battery_charge_frame.png', parent=self.batteryFrame) self.batteryBg.setTransparency(1) self.batteryBg.setX(0.03) self.batteryBg.setScale(0.17, 0, 0.05) self.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame) self.cameraFocus = loader.loadModel( 'phase_4/models/minigames/photo_game_viewfinder.bam') self.cameraFocus.reparentTo(base.aspect2d) self.focusTrav = CollisionTraverser('CSFP.focusTrav') ray = CollisionRay() rayNode = CollisionNode('CSFP.rayNode') rayNode.addSolid(ray) rayNode.setCollideMask(BitMask32(0)) rayNode.setFromCollideMask(CIGlobals.WallBitmask) self.focusRay = ray self.focusRayNode = base.camera.attachNewNode(rayNode) self.focusHandler = CollisionHandlerQueue() self.focusTrav.addCollider(self.focusRayNode, self.focusHandler) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) FirstPerson.start(self) return def reallyStart(self): taskMgr.add(self.__traverse, 'CSFP.__traverse') self.camFSM.request('recharge') base.localAvatar.startTrackAnimToSpeed() FirstPerson.reallyStart(self) def end(self): self.camFSM.request('off') taskMgr.remove('movementTask') taskMgr.remove('CSFP.__traverse') FirstPerson.end(self) def reallyEnd(self): self.batteryBar.destroy() self.batteryBar = None self.batteryBg.destroy() self.batteryBg = None self.batteryFrame.destroy() self.batteryFrame = None self.cameraFocus.removeNode() self.cameraFocus = None self.focusHandler = None self.focusRay = None self.focusRayNode.removeNode() self.focusRayNode = None self.focusTrav = None self.hasToonInFocus = None self.toonToTakePicOf = None self.fullyChargedSound = None self.rechargeSound = None self.stopCameraFlash() FirstPerson.reallyEnd(self) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, CIGlobals.ToonJumpForce, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) return def cleanup(self): self.camFSM.requestFinalState() self.camFSM = None FirstPerson.cleanup(self) return
class CIProgressScreen: Color = (118 / 255.0, 121 / 255.0, 127 / 255.0, 1.0) BarColor = (152 / 255.0, 129 / 255.0, 64 / 255.0, 1.0) def __init__(self): self.defaultLogoScale = 1 self.defaultLogoZ = 0.65 self.bgm = loader.loadModel( "phase_3/models/gui/progress-background.bam") self.bgm.find('**/logo').stash() self.barShadow = OnscreenImage(image=self.bgm.find("**/bar_shadow"), parent=hidden) self.bgm.find("**/bar_shadow").removeNode() self.bg = self.bgm.find('**/bg') self.defaultBgTexture = self.bg.findTexture('*') self.logoNode, self.logoImg = CIGlobals.getLogoImage( hidden, self.defaultLogoScale, (0, 0, self.defaultLogoZ)) self.bg_img = OnscreenImage(image=self.bg, parent=hidden) self.bg_img.setSx(1.35) self.bg_img.hide() self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0, 0, 0.2)) self.progress_bar.setSx(1.064) self.progress_bar.setSz(0.38) toontipgui = loader.loadModel( 'phase_3.5/models/gui/stickerbook_gui.bam') poster = toontipgui.find('**/questCard') self.toontipFrame = DirectFrame(image=poster, image_scale=(1.4, 1, 1), parent=hidden, relief=None, pos=(0, 0, -0.1), scale=0.85) self.toontipLbl = OnscreenText(text="", parent=self.toontipFrame, fg=(89.0 / 255, 95.0 / 255, 98.0 / 255, 1), font=CIGlobals.getToonFont(), wordwrap=13, pos=(-0.59, 0.25), align=TextNode.ALeft, scale=0.08) self.loading_lbl = DirectLabel(text="", relief=None, scale=0.08, pos=(-1.0725, 0, -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(1, 1, 1, 1), text_font=CIGlobals.getMinnieLogoFont(), parent=hidden, text_shadow=(0, 0, 0, 0)) # This is useful when the user has chosen to hide aspect2d before the loading screen. # However, we want to show the loading screen all the time, so we need to restore the # previous state after the loading screen ends. self.mustRestoreHiddenAspect2d = False def begin(self, hood, range, wantGui): render.hide() NametagGlobals.setWant2dNametags(False) if base.aspect2d.isHidden(): base.aspect2d.show() self.mustRestoreHiddenAspect2d = True self.renderFrames() base.setBackgroundColor(0, 0, 0) if hood == "localAvatarEnterGame": self.loading_lbl['text'] = "Entering..." elif hood == "init": self.loading_lbl['text'] = "Loading..." else: self.loading_lbl['text'] = "Heading to %s..." % hood self.progress_bar['barColor'] = self.BarColor self.progress_bar['range'] = range self.bgm.reparentTo(aspect2d) ZoneUtil.Hood2ZoneId.keys() # We only want to show special loading screens for actual in-game locations. if hood in ZoneUtil.Hood2ZoneId.keys(): abbr = ZoneUtil.ZoneId2HoodAbbr.get( ZoneUtil.Hood2ZoneId.get(hood)).lower() bgTexture = loader.loadTexture( 'phase_14/maps/{0}_loading.png'.format(abbr), okMissing=True) if bgTexture: self.bg.setTexture(bgTexture, 1) self.barShadow.reparentTo(aspect2d) self.bg.reparentTo(render2d) self.bg_img.reparentTo(hidden) self.loading_lbl.reparentTo(aspect2d) self.logoNode.reparentTo(aspect2d) self.progress_bar.reparentTo(aspect2d) tip = random.choice(CIGlobals.ToonTips) self.toontipLbl.setText("TOON TIP:\n" + tip) self.toontipFrame.reparentTo(aspect2d) self.__count = 0 self.__expectedCount = range self.progress_bar.update(self.__count) def renderFramesTask(self, task): self.renderFrames() return task.cont def end(self): base.setBackgroundColor(CIGlobals.DefaultBackgroundColor) taskMgr.remove("renderFrames") render.show() if self.mustRestoreHiddenAspect2d: base.aspect2d.hide() self.mustRestoreHiddenAspect2d = False self.progress_bar.finish() self.bg_img.reparentTo(hidden) self.logoNode.reparentTo(hidden) self.barShadow.reparentTo(hidden) self.bg.reparentTo(hidden) # Let's get rid of the extra texture stage. self.bg.setTexture(self.defaultBgTexture, 1) self.bgm.reparentTo(hidden) self.loading_lbl.reparentTo(hidden) self.progress_bar.reparentTo(hidden) self.toontipFrame.reparentTo(hidden) base.transitions.fadeScreen(1.0) NametagGlobals.setWant2dNametags(True) self.renderFrames() def destroy(self): self.bg.removeNode() del self.bg self.bgm.removeNode() del self.bgm self.bg_img.destroy() self.barShadow.destroy() del self.barShadow self.loading_lbl.destroy() self.progress_bar.destroy() self.bgm.destroy() self.mustRestoreHiddenAspect2d = False del self.bg_img del self.loading_lbl del self.progress_bar del self.bgm del self.defaultBgTexture del self.mustRestoreHiddenAspect2d def renderFrames(self): base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() def tick(self): self.__count += 1 self.progress_bar.update(self.__count)
class CIProgressScreen: def __init__(self): self.bgm = loader.loadModel('phase_3/models/gui/progress-background.bam') self.bgm.find('**/logo').stash() self.bg = self.bgm.find('**/bg') self.logo = loader.loadTexture('phase_3/maps/CogInvasion_Logo.png') self.logoImg = OnscreenImage(image=self.logo, scale=(0.5, 0, 0.3), pos=(0, 0, 0), parent=hidden) self.logoImg.setTransparency(True) self.bg_img = OnscreenImage(image=self.bg, parent=hidden) self.bg_img.setSx(1.35) self.bg_img.hide() self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0, 0, 0.2)) self.progress_bar.setSx(1.064) self.progress_bar.setSz(0.38) self.loading_lbl = DirectLabel(text='', relief=None, scale=0.08, pos=(-1.0725, 0, -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(0.343, 0.343, 0.343, 1.0), text_font=CIGlobals.getMinnieFont(), parent=hidden, text_shadow=(0, 0, 0, 1)) return def begin(self, hood, range, wantGui): render.hide() self.renderFrames() base.setBackgroundColor(0, 0, 0) if hood == 'localAvatarEnterGame': self.loading_lbl['text'] = 'Entering...' elif hood == 'init': self.loading_lbl['text'] = 'Loading...' else: self.loading_lbl['text'] = 'Heading to %s...' % hood self.progress_bar['barColor'] = (0.343, 0.343, 0.343, 1.0) self.progress_bar['range'] = range self.bgm.reparentTo(aspect2d) self.bg.reparentTo(render2d) self.bg_img.reparentTo(hidden) self.loading_lbl.reparentTo(aspect2d) self.logoImg.reparentTo(aspect2d) self.progress_bar.reparentTo(aspect2d) self.__count = 0 self.__expectedCount = range self.progress_bar.update(self.__count) def renderFramesTask(self, task): self.renderFrames() return task.cont def end(self): base.setBackgroundColor(CIGlobals.DefaultBackgroundColor) taskMgr.remove('renderFrames') render.show() self.progress_bar.finish() self.bg_img.reparentTo(hidden) self.logoImg.reparentTo(hidden) self.bg.reparentTo(hidden) self.bgm.reparentTo(hidden) self.loading_lbl.reparentTo(hidden) self.progress_bar.reparentTo(hidden) self.renderFrames() def destroy(self): self.bg.removeNode() del self.bg self.bgm.removeNode() del self.bgm self.bg_img.destroy() self.loading_lbl.destroy() self.progress_bar.destroy() self.bgm.destroy() del self.bg_img del self.loading_lbl del self.progress_bar del self.bgm def renderFrames(self): base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() def tick(self): self.__count += 1 self.progress_bar.update(self.__count)
class FinalScoreGUI: notify = directNotify.newCategory('FinalScoreGUI') def __init__(self): self.finalScoreBg = None self.finalScoreTitle = None self.finalScoreNameLbl = None self.finalScorePointLbl = None self.finalScoreContainer = None self.finalScores = [] return def load(self): font = CIGlobals.getToonFont() box = DGG.getDefaultDialogGeom() self.finalScoreContainer = DirectFrame() self.finalScoreBg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(1.9, 1.4, 1.4), parent=self.finalScoreContainer) self.finalScoreTitle = OnscreenText(text='Waiting for final scores...', pos=(0, 0.5, 0), font=font, scale=0.12, parent=self.finalScoreContainer) self.finalScoreNameLbl = OnscreenText(text='', scale=0.095, pos=(-0.85, 0.3, 0), font=font, align=TextNode.ALeft, parent=self.finalScoreContainer) self.finalScorePointLbl = OnscreenText(text='', scale=0.095, pos=(0.85, 0.3, 0), font=font, align=TextNode.ARight, parent=self.finalScoreContainer) self.finalScoreContainer.hide() self.finalScoreContainer.setBin('gui-popup', 60) del font del box def unload(self): if self.finalScoreContainer: self.finalScoreContainer.destroy() self.finalScoreContainer = None if self.finalScoreBg: self.finalScoreBg.destroy() self.finalScoreBg = None if self.finalScoreTitle: self.finalScoreTitle.destroy() self.finalScoreTitle = None if self.finalScoreNameLbl: self.finalScoreNameLbl.destroy() self.finalScoreNameLbl = None if self.finalScorePointLbl: self.finalScorePointLbl.destroy() self.finalScorePointLbl = None return def showFinalScores(self): self.finalScoreContainer.show() base.transitions.fadeScreen(0.5) def hideFinalScores(self): base.transitions.noTransitions() self.finalScoreContainer.hide() def handleFinalScores(self, avIdList, scoreList): for avId in avIdList: score = scoreList[avIdList.index(avId)] scoreObj = FinalScore(avId, score) self.finalScores.append(scoreObj) self.finalScores.sort(key=lambda x: x.score, reverse=True) for scoreObj in self.finalScores: name = base.cr.doId2do.get(scoreObj.avId).getName() self.finalScoreNameLbl['text'] += name + '\n' self.finalScorePointLbl['text'] += str(scoreObj.score) + ' Points\n' self.finalScoreTitle['text'] = 'Final Scores'
class RewardPanel(DirectFrame): notify = directNotify.newCategory('RewardPanel') def __init__(self, panelData): dialogBox = loader.loadModel('phase_3/models/gui/dialog_box_gui.bam') DirectFrame.__init__(self, relief=None, geom=dialogBox, geom_color=CIGlobals.DialogColor, geom_scale=(1.75, 1, 0.75 * 1.1), geom_pos=Point3(0, 0, -0.05), pos=(0, 0, 0.661)) self.initialiseoptions(RewardPanel) self.setScale(0.8) # The data for the reward panel inside of a RPToonData object. self.panelData = panelData # Top wood panel saying Reward Panel gagShopNodes = loader.loadModel( 'phase_4/models/gui/gag_shop_purchase_gui.bam') # Original pos: (-0.02, 0, 0.3) scale = (1.55, 1, 1) self.titlePanel = OnscreenImage( parent=self, image=gagShopNodes.find('**/Goofys_Sign'), pos=(0, 0, 0.3), hpr=(1, 0, 0), scale=(1.3, 1, 0.9)) self.avatarNamePanel = DirectFrame(parent=self.titlePanel, pos=(0, 0.005, 0)) self.avatarText = OnscreenText(parent=self.avatarNamePanel, text='', font=CIGlobals.getMickeyFont(), fg=(0.698, 0.13, 0.13, 1), mayChange=1, scale=(0.1, 0.13, 0.1)) self.panelContentsTitle = OnscreenText(parent=self, text=GagPanelName, font=CIGlobals.getMickeyFont(), pos=(0, 0.24, 0), fg=(0.3725, 0.619, 0.627, 1), mayChange=1) self.playerInfo = DirectFrame(parent=self, relief=None, pos=(-0.5, 0, 0)) self.playerInfo.setBin('gui-popup', 0) self.bonusText = OnscreenText(parent=self.playerInfo, text='2X Cog Office Bonus!', font=CIGlobals.getToonFont(), pos=(0, 0.15, 0), scale=(0.055, 0.055, 0.055), align=TextNode.ACenter) self.bonusText.hide() ################################################################################## # GUI Elements relating to the Favorite Gag/Gag Popup Used for showing Gag Unlock# ################################################################################## self.favoriteGagText = OnscreenText(parent=self.playerInfo, text=FavoriteGag, font=CIGlobals.getMickeyFont(), pos=FavoriteGagTitlePos, fg=(1, 0.2, 0.2, 1), sort=0) glow = loader.loadModel('phase_4/models/minigames/particleGlow.bam') self.favoriteGagGlow = OnscreenImage(parent=self.playerInfo, image=glow, pos=FavoriteGagPos, color=GagGlowColor, scale=(0.8, 0.8, 0.8)) self.favoriteGagGlow.setBin('gui-popup', 10) # particleGlow.bam uses a material since it's normally part of render, not render2d. # Since render2d is still fixed-function, we have to explicitly enable shader generation # to correctly display the glow in render2d. self.favoriteGagGlow.setShaderAuto() invIcons = loader.loadModel('phase_3.5/models/gui/inventory_icons.bam') gag = invIcons.find( GagGlobals.InventoryIconByName.get(GagGlobals.Foghorn)) self.favoriteGag = OnscreenImage(parent=self.playerInfo, image=gag, pos=FavoriteGagPos, scale=(1.65, 1.65, 1.65)) self.favoriteGag.setBin('gui-popup', 20) self.favoriteGagName = OnscreenText(parent=self.playerInfo, text=GagGlobals.Foghorn, font=CIGlobals.getToonFont(), pos=FavoriteGagNamePos, mayChange=1) ################################################################################ # GUI elements showing gag experience on the right-side of the gag exp panel # ################################################################################ self.gagExpFrame = DirectFrame(parent=self, relief=None, pos=(0.085, 0, 0.15)) self.trackLabels = [] self.trackIncLabels = [] self.trackBars = [] self.trackBarsOffset = 0 for i in range(len(GagGlobals.TrackNameById.values())): track = GagGlobals.TrackNameById.values()[i] color = GagGlobals.TrackColorByName.get(track) label = DirectLabel(parent=self.gagExpFrame, relief=None, text=track.upper(), text_scale=0.05, text_align=TextNode.ARight, pos=(0.13, 0, -0.09 * i), text_pos=(0, -0.02)) incrementLabel = DirectLabel(parent=self.gagExpFrame, relief=None, text='', text_scale=0.05, text_align=TextNode.ALeft, pos=(0.65, 0, -0.09 * i), text_pos=(0, -0.02)) progressBar = DirectWaitBar( parent=self.gagExpFrame, relief=DGG.SUNKEN, frameSize=(-1, 1, -0.15, 0.15), borderWidth=(0.02, 0.02), scale=0.25, frameColor=(color[0] * 0.7, color[1] * 0.7, color[2] * 0.7, 1), barColor=(color[0], color[1], color[2], 1), text='0/0', text_scale=0.18, text_fg=(0, 0, 0, 1), text_align=TextNode.ACenter, text_pos=(0, -0.05), pos=(0.4, 0, -0.09 * i)) self.trackLabels.append(label) self.trackIncLabels.append(incrementLabel) self.trackBars.append(progressBar) ################################################################################ # GUI elements showing progress updates on quests # ################################################################################ self.questFrame = DirectFrame(parent=self, relief=None) self.questPosters = [] self.congratsLeft = OnscreenText(parent=self.playerInfo, pos=(-0.1, 0.125, -0.1), text='', scale=0.06, align=TextNode.ARight) self.congratsLeft.setR(-30) self.congratsRight = OnscreenText(parent=self.playerInfo, pos=(0.1, 0.125, 0.1), text='', scale=0.06, align=TextNode.ALeft) self.congratsRight.setR(30) glow.removeNode() invIcons.removeNode() gagShopNodes.removeNode() dialogBox.removeNode() def __getAvatarTextScale(self): totalWidth = self.avatarText.node().getWidth() panelWidth = 9.2 defaultTextScale = 1.0 scale = min(defaultTextScale, defaultTextScale / (totalWidth / panelWidth)) return (scale, scale, scale) def enterOff(self): pass def exitOff(self): pass def setPanelData(self, panelData): self.panelData = panelData self.avatarText['text'] = self.panelData.avatarName self.avatarNamePanel.setScale(self.__getAvatarTextScale()) # Let's set the data for our gag experience here. for i in range(len(self.trackLabels)): track = self.panelData.getTrackByName( GagGlobals.TrackNameById.values()[i]) bar = self.trackBars[i] bar['text'] = '%d/%d' % (track.exp, track.maxExp) # When the maximum experience of a track isn't 0, we know it isn't unlocked. if track.maxExp == -1: bar.hide() self.trackIncLabels[i]['text'] = '' self.trackIncLabels[i].show() def __chooseRewardShot(self, av): shotChoices = [(0, 8, av.getHeight() * 0.66, 179, 15, 0), (5.2, 5.45, av.getHeight() * 0.66, 131.5, 3.6, 0)] shot = random.choice(shotChoices) return shot def getQuestsProgressInterval(self): avatar = self.panelData.avatar intervals = [] def toggleFavoriteGagItems(visible): for item in [ self.favoriteGag, self.favoriteGagGlow, self.favoriteGagText, self.favoriteGagName ]: if not visible: item.hide() else: item.show() def setupQuestPosters(): questManager = avatar.questManager numQuests = len(questManager.quests.values()) yPos = 0.47 displayData = { 1: [[Point3(0.0, 0.0, yPos)], 0.88], 2: [[Point3(-0.42, 0.0, yPos), Point3(0.45, 0.0, yPos)], 0.88], 3: [[ Point3(-0.57, 0.0, yPos), Point3(0.0, 0.0, yPos), Point3(0.57, 0.0, yPos) ], 0.70], 4: [[ Point3(-0.32, 0.0, 0.62), Point3(-0.32, 0.0, 0.30), Point3(0.32, 0.0, 0.62), Point3(0.32, 0.0, 0.30) ], 0.52] } # A full frame is a frame showing two quests at once. howManyFullFrames = math.ceil(numQuests / 2.0) howManyRemainderFrames = (numQuests - howManyFullFrames) for i, quest in enumerate(questManager.quests.values()): poster = QuestGlobals.generatePoster(quest, parent=self.questFrame) poster.setScale(displayData.get(numQuests)[1]) poster.setPos(displayData.get(numQuests)[0][i]) poster.show() self.questPosters.append(poster) intervals.append(Func(self.gagExpFrame.hide)) intervals.append(Func(self.playerInfo.show)) intervals.append(Func(self.panelContentsTitle.setText, QuestsPanelName)) intervals.append(Func(toggleFavoriteGagItems, False)) intervals.append(Func(setupQuestPosters)) #intervals.append(Func(self.playerInfo.initialiseoptions, DirectFrame)) return intervals def getGagExperienceInterval(self): avatar = self.panelData.avatar intervals = [] shot = self.__chooseRewardShot(avatar) intervals.append(Func(base.camera.reparentTo, avatar)) intervals.append(Func(base.camera.setPosHpr, *shot)) intervals.append(Func(self.congratsLeft.hide)) intervals.append(Func(self.congratsRight.hide)) intervals.append(Func(self.panelContentsTitle.setText, GagPanelName)) intervals.append(Func(self.setFavoriteGag, self.panelData.favoriteGag)) intervals.append(Func(self.gagExpFrame.show)) intervals.append(Func(self.playerInfo.show)) intervals.append(Wait(1.0)) for i in range(len(self.trackLabels)): track = self.panelData.getTrackByName( GagGlobals.TrackNameById.values()[i]) intervals.extend(self.getTrackIntervalList(track, i)) return intervals def getNextExpValue(self, newValue, track): if newValue < track.maxExp or track.maxExp == 0: return track.maxExp else: levels = GagGlobals.TrackExperienceAmounts[track.name] index = levels.index(track.maxExp) if index + 1 < len(levels): return levels[index + 1] return -1 def incrementExp(self, trackIndex, track, newValue): bar = self.trackBars[trackIndex] nextExp = GagGlobals.getMaxExperienceValue(newValue, track.name) oldValue = bar['value'] color = GagGlobals.TrackColorByName.get(track.name) bar['text'] = '%d/%d' % (newValue, nextExp) bar['range'] = nextExp if not nextExp == -1 else newValue bar['value'] = newValue bar['barColor'] = (color[0], color[1], color[2], 1) def resetBarColor(self, trackIndex): color = GagGlobals.TrackColorByName.get( GagGlobals.TrackNameById.values()[trackIndex]) self.trackBars[trackIndex]['barColor'] = (color[0] * 0.8, color[1] * 0.8, color[2] * 0.8, 1) def showTrackIncLabel(self, trackIndex, track, increment): label = self.trackIncLabels[trackIndex] # Only show increments when that track is unlocked. if track.exp != -1: label['text'] = '+%d' % increment label.show() def getTrackIntervalList(self, track, trackIndex): tickDelay = 1.0 / 60 intervalList = [] intervalList.append( Func(self.showTrackIncLabel, trackIndex, track, track.increment)) barTime = 2.0 if track.exp > 0 else 0.25 numTicks = int(math.ceil(barTime / tickDelay)) for i in range(numTicks): t = (i + 1) / float(numTicks) newValue = int(track.exp + t * track.increment + 0.5) intervalList.append( Func(self.incrementExp, trackIndex, track, newValue)) intervalList.append(Wait(tickDelay)) intervalList.append(Func(self.resetBarColor, trackIndex)) intervalList.append(Wait(0.2)) if track.maxExp > 0 and (track.maxExp != GagGlobals.MaxedTrackExperiences.get(track.name) \ and (track.exp + track.increment) >= track.maxExp): gagIndex = GagGlobals.TrackExperienceAmounts.get(track.name).index( track.maxExp) + 1 newGag = GagGlobals.TrackGagNamesByTrackName.get( track.name)[gagIndex] intervalList.append( self.getShowGagUnlockedInterval(track.name, newGag)) return intervalList def getShowGagUnlockedInterval(self, track, gagName): seq = Sequence( Func(self.gagExpFrame.hide), Func(self.panelContentsTitle.setText, 'Gag Unlocked!'), Func(self.playerInfo.show), Func(self.setFavoriteGag, gagName), Func(self.favoriteGagName.setY, -0.35), Func(self.favoriteGagText.setY, 0.105), Func(self.favoriteGagText.setText, 'New %s Gag' % track), Func(self.bonusText.hide), Func(self.playerInfo.setPos, 0, 0, 0), Func(self.playerInfo.initialiseoptions, DirectFrame)) seq.append(self.getCongratsInterval()) seq.append(Wait(1.0)) seq.append(self.getHideGagUnlockedInterval()) seq.append(Func(self.gagExpFrame.show)) seq.append(Wait(0.5)) return seq def getHideGagUnlockedInterval(self): def correctPositioning(guiElement, pos): guiElement['pos'] = pos seq = Sequence( Func(self.panelContentsTitle.setText, GagPanelName), Func(self.setFavoriteGag, self.panelData.favoriteGag), Func(self.playerInfo.setX, -0.5), Func(correctPositioning, self.favoriteGagName, FavoriteGagNamePos), Func(self.favoriteGagText.setText, FavoriteGag), Func(correctPositioning, self.favoriteGagText, FavoriteGagTitlePos), Func(self.congratsLeft.hide), Func(self.congratsRight.hide)) return seq def __getRandomCongratsPair(self): msgs = list(NewGagCongratsMessages) msg = msgs[random.randint(0, len(msgs) - 1)] msgs.remove(msg) return (msg, msgs[random.randint(0, len(msgs) - 1)]) def getCongratsInterval(self): msgs = self.__getRandomCongratsPair() self.congratsLeft['text'] = msgs[0] self.congratsRight['text'] = msgs[1] sfx = loader.loadSfx('phase_3/audio/sfx/GUI_balloon_popup.ogg') sfx.setLoop(False) sfx.setVolume(1.0) def makeSequence(text): seq = Sequence(Wait(1.0), Func(text.show)) seq.append(Func(sfx.play)) seq.append( CIGlobals.makePulseEffectInterval(text, 1.0, 0.01, 1.05, 0.5, 0.25)) seq.append(Func(sfx.stop)) return seq return Sequence(makeSequence(self.congratsLeft), makeSequence(self.congratsRight)) def setFavoriteGag(self, gagName): invIcons = loader.loadModel('phase_3.5/models/gui/inventory_icons.bam') gag = invIcons.find(GagGlobals.InventoryIconByName.get(gagName)) self.favoriteGagName.setText(gagName) self.favoriteGag['image'] = gag invIcons.removeNode() def destroy(self): if self.titlePanel: self.titlePanel.destroy() if self.avatarText: self.avatarText.destroy() if self.avatarNamePanel: self.avatarNamePanel.destroy() if self.panelContentsTitle: self.panelContentsTitle.destroy() if self.favoriteGag: self.favoriteGag.destroy() if self.favoriteGagGlow: self.favoriteGagGlow.destroy() if self.favoriteGagName: self.favoriteGagName.destroy() if self.playerInfo: self.playerInfo.destroy() if self.trackLabels: for label in self.trackLabels: label.destroy() if self.trackIncLabels: for label in self.trackIncLabels: label.destroy() if self.trackBars: for bar in self.trackBars: bar.destroy() if self.congratsLeft: self.congratsLeft.destroy() if self.congratsRight: self.congratsRight.destroy() if self.gagExpFrame: self.gagExpFrame.destroy() if self.panelData: self.panelData = None del self.titlePanel del self.avatarText del self.avatarNamePanel del self.panelContentsTitle del self.favoriteGag del self.favoriteGagGlow del self.favoriteGagName del self.playerInfo del self.trackLabels del self.trackIncLabels del self.trackBars del self.gagExpFrame del self.congratsLeft del self.congratsRight del self.panelData DirectFrame.destroy(self)
class KOTHGui(DirectFrame): notify = directNotify.newCategory('KOTHGui') pointsSfx = None points = None def __init__(self): # Let's load up the DirectFrame DirectFrame.__init__(self, parent=base.a2dTopLeft, relief=None, pos=(0.275, 1, -0.7), sortOrder=0) # The variables we're going to be using. self.pointsSfx = loader.loadSfx('phase_4/audio/sfx/MG_maze_pickup.ogg') self.points = 0 # Background because it won't work for whatever reason. gui = loader.loadModel('phase_4/models/gui/purchase_gui.bam') panel = gui.find('**/yellowPanel') self.bg = OnscreenImage(image=panel, parent=self) # Let's setup the header text. self.title = OnscreenText(text='Capture Points', font=CIGlobals.getMinnieFont(), parent=self, scale=0.0475, pos=(0, 0.18), fg=(1, 0, 0, 1), shadow=(0.2, 0.2, 0.2, 1)) # Let's setup the amount text. self.amt_label = OnscreenText(text=str(self.points), font=CIGlobals.getToonFont(), parent=self, scale=0.15, pos=(0, 0.03525), shadow=(0.5, 0.5, 0.5, 0.6)) # Let's setup the info text. self.info = OnscreenText( text= 'First Toon to 100 points wins!\nEarn points by standing on the\nhill after capturing it.', parent=self, font=CIGlobals.getToonFont(), scale=0.035, pos=(0, -0.05), fg=(1.5, 0, 0, 1), shadow=(0.2, 0.2, 0.2, 1)) # We're not ready to show the GUI yet. self.hide() def show(self): self.title.show() self.amt_label.show() self.info.show() self.bg.show() def hide(self): self.title.hide() self.amt_label.hide() self.info.hide() self.bg.hide() def destroy(self): self.title.destroy() self.amt_label.destroy() self.info.destroy() self.bg.destroy() self.title = None self.amt_label = None self.info = None self.bg = None # Let's get rid of the sound. self.pointsSfx.stop() self.pointsSfx = None self.points = None DirectFrame.destroy(self) def setPoints(self, points): self.points = points self.amt_label.setText(str(self.points)) self.pointsSfx.play() def getPoints(self): return self.points
class ClickToStart(DirectObject): notify = directNotify.newCategory('ClickToStart') def __init__(self, version='n/a'): DirectObject.__init__(self) self.backgroundNodePath = render2d.attachNewNode('background', 0) self.backgroundModel = loader.loadModel( 'phase_3/models/gui/loading-background.bam') self.backgroundModel.reparentTo(self.backgroundNodePath) self.backgroundNodePath.find('**/fg').removeNode() self.backgroundNodePath.setScale(1, 1, 1) self.logo = OnscreenImage(parent=base.a2dTopCenter, image='phase_3/maps/toontown-logo.png', scale=(1.0, 1, 0.5), pos=(0, 0, -0.85)) self.logo.setTransparency(TransparencyAttrib.MAlpha) self.label = OnscreenText(TTLocalizer.ClickToStartLabel, parent=base.a2dBottomCenter, font=ToontownGlobals.getMinnieFont(), fg=Vec4(1, 1, 1, 1), scale=0.1, align=TextNode.ACenter) self.label.setZ(0.35) self.versionLabel = OnscreenText('\x01white_shadow\x01%s\x02' % version, parent=base.a2dBottomRight, font=ToontownGlobals.getMinnieFont(), fg=Vec4(0, 0, 0, 1), scale=0.06, align=TextNode.ARight) self.versionLabel.setPos(-0.025, 0.025) self.setColorScale(Vec4(0, 0, 0, 0)) self.fadeTrack = None self.logoPosTrack = None self.logoScaleTrack = None self.labelPosTrack = None self.labelColorScaleTrack = None def delete(self): if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None if self.versionLabel is not None: self.versionLabel.destroy() self.versionLabel = None if self.label is not None: self.label.destroy() self.label = None if self.logo is not None: self.logo.destroy() self.logo = None if self.backgroundNodePath is not None: self.backgroundNodePath.removeNode() self.backgroundNodePath = None if self.backgroundModel is not None: self.backgroundModel.removeNode() self.backgroundModel = None def start(self): base.transitions.fadeOut(t=0) self.setColorScale(Vec4(1, 1, 1, 1)) if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.fadeTrack = base.transitions.getFadeInIval(t=2) self.fadeTrack.start() if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None self.logoScaleTrack = Sequence( LerpScaleInterval(self.logo, 2, Vec3(1.1, 1, 0.55), Vec3(1, 1, 0.5), blendType='easeInOut'), LerpScaleInterval(self.logo, 2, Vec3(1, 1, 0.5), Vec3(1.1, 1, 0.55), blendType='easeInOut')) if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None self.logoPosTrack = Sequence( LerpPosInterval(self.logo, 2, Point3(0, 0, -0.85), Point3(0, 0, -0.7), blendType='easeOut'), Func(self.logoScaleTrack.loop)) self.logoPosTrack.start() if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None self.labelColorScaleTrack = Sequence( LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 0.6), Vec4(1, 1, 1, 1)), LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0.6))) if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None self.labelPosTrack = Sequence( LerpPosInterval(self.label, 2, Point3(0, 0, 0.35), Point3(0, 0, 0.15), blendType='easeOut'), Func(self.labelColorScaleTrack.loop)) self.labelPosTrack.start() self.acceptOnce('mouse1', self.begin) def stop(self): self.ignore('mouse1') if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.setColorScale(Vec4(0, 0, 0, 0)) def begin(self): base.cr.introDone = True if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.fadeTrack = base.transitions.getFadeOutIval(t=2) Sequence( Func(self.fadeTrack.start), Wait(2), Func(self.delete), Func(base.cr.introduction.delete), Func(base.cr.loginFSM.request, 'chooseAvatar', [base.cr.avList]), Func(base.transitions.fadeIn, 2)).start() def setColorScale(self, *args, **kwargs): self.backgroundNodePath.setColorScale(*args, **kwargs) self.logo.setColorScale(*args, **kwargs) self.label.setColorScale(*args, **kwargs) self.versionLabel.setColorScale(*args, **kwargs)
class GagWidget(DirectButton): Idle = (0, 115 / 255.0, 194 / 255.0, 1) Selected = (0, 115 / 255.0 * 1.5, 194 / 255.0 * 1.5, 1) NoAmmoIdle = (0, 115 / 255.0 / 1.75, 194 / 255.0 / 1.75, 1) NoAmmoSelected = (0, 115 / 255.0 / 1.75, 194 / 255.0 / 1.75, 1) LockedIdle = (0.5, 0.5, 0.5, 1.0) LockedSelected = (0.5, 0.5, 0.5, 1.0) def __init__(self, track, gagId): self.track = track self.gagId = gagId self.gagName = base.cr.attackMgr.getAttackName(gagId) self.lastScale = 1.0 self.goalScale = 1.0 self.scaleLerpTask = taskMgr.add(self.__scaleLerp, "scaleLerp") self.locked = False DirectButton.__init__(self, scale=1, relief=None, pressEffect=False, rolloverSound=None, clickSound=None, command=self.track.gsg.selectCurrentGag) self['image'] = 'phase_14/maps/gag_box.png' self['image_scale'] = (0.115, 0, 0.114) self.bind(DGG.ENTER, self.mouseEnter) self.bind(DGG.EXIT, self.mouseExit) self.lockedImg = OnscreenImage(image='phase_14/maps/lock.png', scale=(0.061, 0, 0.089), parent=self, color=(1, 1, 1, 0.5)) invIcons = loader.loadModel("phase_3.5/models/gui/inventory_icons.bam") self.gagImg = OnscreenGeom(geom=invIcons.find( GagGlobals.InventoryIconByName[self.gagName]), scale=0.85, parent=self) invIcons.removeNode() del invIcons self.initialiseoptions(GagWidget) def mouseEnter(self, foo=None, bar=None): if self.track.gsg.getCurrentOrNextState() == 'Select': self.track.gsg.ignoreSelectionClick() self.track.gsg.resetTimeout() self.select() def mouseExit(self, foo=None, bar=None): if self.track.gsg.getCurrentOrNextState() == 'Select': self.track.gsg.acceptSelectionClick() self.track.gsg.resetTimeout() self.deselect() def cleanup(self): if self.scaleLerpTask: self.scaleLerpTask.remove() self.scaleLerpTask = None self.lastScale = None self.goalScale = None self.locked = None self.gagId = None self.gagName = None if self.lockedImg: self.lockedImg.destroy() self.lockedImg = None if self.gagImg: self.gagImg.destroy() self.gagImg = None self.destroy() def __scaleLerp(self, task): if self.lastScale == self.goalScale: return task.cont self.lastScale = CIGlobals.lerpWithRatio(self.goalScale, self.lastScale, 0.8) self.setScale(self.lastScale) return task.cont def stash(self): self.scaleLerpTask.remove() DirectButton.stash(self) def unstash(self): taskMgr.add(self.scaleLerpTask) DirectButton.unstash(self) def select(self): if self.locked: self['image_color'] = self.LockedSelected elif not self.hasAmmo(): self['image_color'] = self.NoAmmoSelected else: self['image_color'] = self.Selected self.goalScale = 1.15 if self.track.gsg.currentGag != self: if self.track.gsg.currentGag is not None: self.track.gsg.currentGag.deselect() self.track.gsg.currentGag = self self.track.gsg.update() def hasAmmo(self): if not base.localAvatar.hasAttackId(self.gagId): return False return base.localAvatar.getAttack(self.gagId).hasAmmo() def deselect(self): if self.locked: self['image_color'] = self.LockedIdle elif not self.hasAmmo(): self['image_color'] = self.NoAmmoIdle else: self['image_color'] = self.Idle self.goalScale = 1.0 if self.track.gsg.currentGag == self: self.track.gsg.currentGag = None def setLocked(self, flag): self.locked = flag if flag: self.lockedImg.show() self.gagImg.hide() self['image_color'] = self.LockedIdle self['state'] = DGG.DISABLED else: self.lockedImg.hide() self.gagImg.show() self['image_color'] = self.Idle self['state'] = DGG.NORMAL
class DistributedPieTurretManager(DistributedObject): notify = directNotify.newCategory('DistributedPieTurretManager') def __init__(self, cr): DistributedObject.__init__(self, cr) self.myTurret = None self.guiFrame = None self.guiLabel = None self.guiBar = None self.guiBg = None self.turretGag = None def announceGenerate(self): DistributedObject.announceGenerate(self) base.taskMgr.add(self.__pollMyBattle, '__pollMyBattle') def disable(self): base.taskMgr.remove("DPTM.pollTurret") base.taskMgr.remove("__pollMyBattle") if hasattr(self, 'makeTurretBtn'): self.makeTurretBtn.destroy() del self.makeTurretBtn self.destroyGui() self.myTurret = None if base.localAvatar.getMyBattle(): base.localAvatar.getMyBattle().setTurretManager(None) DistributedObject.disable(self) def clearTurret(self): self.turret = None def __pollTurret(self, turretId, task): turret = self.cr.doId2do.get(turretId) if turret != None: self.myTurret = turret self.myTurret.b_setGag(self.turretGag) self.turretGag = None self.acceptOnce(turret.getDeathEvent(), self.clearTurret) self.makeGui() return Task.done return Task.cont def setGag(self, upgradeId): self.turretGag = upgradeId def d_requestPlace(self, posHpr): self.sendUpdate('requestPlace', [posHpr]) def turretPlaced(self, turretId): base.taskMgr.add(self.__pollTurret, 'DPTM.pollTurret', extraArgs=[turretId], appendTask=True) def yourTurretIsDead(self): base.taskMgr.remove('DPTM.pollTurret') self.destroyGui() self.myTurret = None if base.localAvatar.getPUInventory()[0] > 0: self.createTurretButton() def makeGui(self): self.destroyGui() self.guiFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.55, 0, 0.15)) self.guiBg = OnscreenImage(image="phase_4/maps/turret_gui_bg.png", scale=(0.15, 0, 0.075), parent=self.guiFrame) self.guiBg.setTransparency(True) self.guiLabel = DirectLabel( text="Turret", text_fg=(1, 0, 0, 1), relief=None, text_scale=0.05, text_font=loader.loadFont("phase_3/models/fonts/ImpressBT.ttf"), pos=(0, 0, 0.025), parent=self.guiFrame) self.guiBar = DirectWaitBar(range=self.myTurret.getMaxHealth(), value=self.myTurret.getHealth(), scale=0.125, parent=self.guiFrame, pos=(0, 0, -0.01)) def createTurretButton(self): self.makeTurretBtn = DirectButton(relief=None, geom=CIGlobals.getDefaultBtnGeom(), text='Turret', text_scale=0.055, command=self.handleMakeTurretBtn, pos=(-0.47, 0, 0.1), geom_scale=(0.5, 1.0, 1.0), text_pos=(0, -0.01), parent=base.a2dBottomRight) if base.localAvatar.getPUInventory()[0]: self.setGag(base.localAvatar.getPUInventory()[1]) def handleMakeTurretBtn(self): self.makeTurretBtn.destroy() del self.makeTurretBtn x, y, z = base.localAvatar.getPos() h, p, r = base.localAvatar.getHpr() self.d_requestPlace([x, y, z, h, p, r]) base.localAvatar.sendUpdate('usedPU', [0]) def __pollMyBattle(self, task): if base.localAvatar.getMyBattle(): base.localAvatar.getMyBattle().setTurretManager(self) if base.localAvatar.getPUInventory()[0] > 0: self.createTurretButton() return Task.done return Task.cont def destroyGui(self): if self.guiBar: self.guiBar.destroy() self.guiBar = None if self.guiLabel: self.guiLabel.destroy() self.guiLabel = None if self.guiBg: self.guiBg.destroy() self.guiBg = None if self.guiFrame: self.guiFrame.destroy() self.guiFrame = None def updateTurretGui(self): if self.guiBar: self.guiBar.update(self.myTurret.getHealth()) def getTurret(self): return self.myTurret
class TeamMinigame: notify = directNotify.newCategory('TeamMinigame') def __init__(self, team1Name, team1BtnImg, team2Name, team2BtnImg): self.team1Name = team1Name self.team1BtnImg = team1BtnImg self.team2Name = team2Name self.team2BtnImg = team2BtnImg self.teamNameById = {TEAM1: self.team1Name, TEAM2: self.team2Name} self.team = None self.winnerTeam = None self.playersByTeam = {TEAM1: 0, TEAM2: 0} self.playerListByTeam = {TEAM1: [], TEAM2: []} self.scoreByTeam = {TEAM1: 0, TEAM2: 0} self.container = None self.bg = None self.title = None self.btnFrame = None self.team1Frame = None self.team1Btn = None self.team1Plyrs_Lbl = None self.team2Frame = None self.team2Btn = None self.team2Plyrs_Lbl = None self.teamFull_Lbl = None return def makeSelectionGUI(self): font = CIGlobals.getMickeyFont() box = loader.loadModel('phase_3/models/gui/dialog_box_gui.bam') imp = CIGlobals.getToonFont() geom = CIGlobals.getDefaultBtnGeom() self.container = DirectFrame() self.bg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(1.9, 1.4, 1.4), parent=self.container) self.title = OnscreenText(text='Join a Team', pos=(0, 0.5, 0), font=font, scale=0.12, parent=self.container, fg=(1, 0.9, 0.3, 1)) self.btnFrame = DirectFrame(parent=self.container, pos=(0.14, 0, 0)) self.team1BtnFrame = DirectFrame(parent=self.btnFrame, pos=(-0.5, 0, 0)) self.team2BtnFrame = DirectFrame(parent=self.btnFrame, pos=(0.22, 0, 0)) self.team1Btn = DirectButton(parent=self.team1BtnFrame, relief=None, pressEffect=0, image=self.team1BtnImg, image_scale=(0.9, 1, 1), scale=0.4, command=self.choseTeam, extraArgs=[TEAM1]) self.team1Plyrs_Lbl = OnscreenText(parent=self.team1BtnFrame, text=str(self.playersByTeam[TEAM1]), pos=(0, -0.46, 0), font=imp) self.team2Btn = DirectButton(parent=self.team2BtnFrame, relief=None, pressEffect=0, image=self.team2BtnImg, image_scale=(0.9, 1, 1), scale=0.4, command=self.choseTeam, extraArgs=[TEAM2]) self.team2Plyrs_Lbl = OnscreenText(parent=self.team2BtnFrame, text=str(self.playersByTeam[TEAM2]), pos=(0, -0.46, 0), font=imp) self.teamFull_Lbl = OnscreenText(parent=self.container, text='', pos=(0, -0.6, 0), font=imp) return def destroySelectionGUI(self): if self.teamFull_Lbl: self.teamFull_Lbl.destroy() self.teamFull_Lbl = None if self.team2Plyrs_Lbl: self.team2Plyrs_Lbl.destroy() self.team2Plyrs_Lbl = None if self.team1Plyrs_Lbl: self.team1Plyrs_Lbl.destroy() self.team1Plyrs_Lbl = None if self.team2Btn: self.team2Btn.destroy() self.team2Btn = None if self.team1Btn: self.team1Btn.destroy() self.team1Btn = None if self.team2BtnFrame: self.team2BtnFrame.destroy() self.team2BtnFrame = None if self.team1BtnFrame: self.team1BtnFrame.destroy() self.team1BtnFrame = None if self.title: self.title.destroy() self.title = None if self.bg: self.bg.destroy() self.bg = None if self.container: self.container.destroy() self.container = None return def choseTeam(self, team): self.team = team self.team1Btn['state'] = DGG.DISABLED self.team2Btn['state'] = DGG.DISABLED self.sendUpdate('choseTeam', [team]) def acceptedIntoTeam(self): message = MSG_WELCOME.format(self.teamNameById[self.team]) whisper = WhisperPopup(message, CIGlobals.getToonFont(), ChatGlobals.WTSystem) whisper.manage(base.marginManager) def teamFull(self): self.teamFull_Lbl.setText('Sorry, that team is full.') self.team = None self.team1Btn['state'] = DGG.NORMAL self.team2Btn['state'] = DGG.NORMAL return def incrementTeamPlayers(self, team): self.playersByTeam[team] += 1 if self.fsm.getCurrentState().getName() == 'chooseTeam': if team == TEAM2: lbl = self.team2Plyrs_Lbl else: if team == TEAM1: lbl = self.team1Plyrs_Lbl lbl.setText(str(self.playersByTeam[team])) def setTeamOfPlayer(self, avId, team): if not hasattr(self, 'getRemoteAvatar'): self.notify.error('Minigame must have remote avatars!!') self.playerListByTeam[team].append(avId) remoteAvatar = self.getRemoteAvatar(avId) if remoteAvatar: print('setting team of {0}').format(avId) remoteAvatar.setTeam(team) def incrementTeamScore(self, team): self.scoreByTeam[team] += 1 def teamWon(self, team): self.winnerTeam = team def cleanup(self): self.destroySelectionGUI() del self.scoreByTeam del self.team1Name del self.teamNameById del self.team2Name del self.team1BtnImg del self.team2BtnImg del self.team del self.playersByTeam del self.winnerTeam del self.playerListByTeam
class ClickToStart(DirectObject): notify = directNotify.newCategory('ClickToStart') def __init__(self, version='n/a'): DirectObject.__init__(self) self.backgroundNodePath = render2d.attachNewNode('background', 0) self.backgroundModel = loader.loadModel( 'phase_3/models/gui/loading-background.bam') self.backgroundModel.reparentTo(self.backgroundNodePath) self.backgroundNodePath.find('**/fg').removeNode() self.backgroundNodePath.setScale(1, 1, 1) self.logo = OnscreenImage( parent=base.a2dTopCenter, image='phase_3/maps/toontown-logo.png', scale=(1.0, 1, 0.5), pos=(0, 0, -0.85)) self.logo.setTransparency(TransparencyAttrib.MAlpha) self.label = OnscreenText( TTLocalizer.ClickToStartLabel, parent=base.a2dBottomCenter, font=ToontownGlobals.getMinnieFont(), fg=Vec4(1, 1, 1, 1), scale=0.1, align=TextNode.ACenter) self.label.setZ(0.35) self.versionLabel = OnscreenText( '\x01white_shadow\x01%s\x02' % version, parent=base.a2dBottomRight, font=ToontownGlobals.getMinnieFont(), fg=Vec4(0, 0, 0, 1), scale=0.06, align=TextNode.ARight) self.versionLabel.setPos(-0.025, 0.025) self.setColorScale(Vec4(0, 0, 0, 0)) self.fadeTrack = None self.logoPosTrack = None self.logoScaleTrack = None self.labelPosTrack = None self.labelColorScaleTrack = None def delete(self): if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None if self.versionLabel is not None: self.versionLabel.destroy() self.versionLabel = None if self.label is not None: self.label.destroy() self.label = None if self.logo is not None: self.logo.destroy() self.logo = None if self.backgroundNodePath is not None: self.backgroundNodePath.removeNode() self.backgroundNodePath = None if self.backgroundModel is not None: self.backgroundModel.removeNode() self.backgroundModel = None def start(self): base.transitions.fadeOut(t=0) self.setColorScale(Vec4(1, 1, 1, 1)) if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.fadeTrack = base.transitions.getFadeInIval(t=2) self.fadeTrack.start() if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None self.logoScaleTrack = Sequence( LerpScaleInterval(self.logo, 2, Vec3(1.1, 1, 0.55), Vec3(1, 1, 0.5), blendType='easeInOut'), LerpScaleInterval(self.logo, 2, Vec3(1, 1, 0.5), Vec3(1.1, 1, 0.55), blendType='easeInOut') ) if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None self.logoPosTrack = Sequence( LerpPosInterval(self.logo, 2, Point3(0, 0, -0.85), Point3(0, 0, -0.7), blendType='easeOut'), Func(self.logoScaleTrack.loop) ) self.logoPosTrack.start() if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None self.labelColorScaleTrack = Sequence( LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 0.6), Vec4(1, 1, 1, 1)), LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0.6)) ) if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None self.labelPosTrack = Sequence( LerpPosInterval(self.label, 2, Point3(0, 0, 0.35), Point3(0, 0, 0.15), blendType='easeOut'), Func(self.labelColorScaleTrack.loop) ) self.labelPosTrack.start() self.acceptOnce('mouse1', self.begin) def stop(self): self.ignore('mouse1') if self.labelPosTrack is not None: self.labelPosTrack.finish() self.labelPosTrack = None if self.labelColorScaleTrack is not None: self.labelColorScaleTrack.finish() self.labelColorScaleTrack = None if self.logoPosTrack is not None: self.logoPosTrack.finish() self.logoPosTrack = None if self.logoScaleTrack is not None: self.logoScaleTrack.finish() self.logoScaleTrack = None if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.setColorScale(Vec4(0, 0, 0, 0)) def begin(self): base.cr.introDone = True if self.fadeTrack is not None: self.fadeTrack.finish() self.fadeTrack = None self.fadeTrack = base.transitions.getFadeOutIval(t=2) Sequence( Func(self.fadeTrack.start), Wait(2), Func(self.delete), Func(base.cr.introduction.delete), Func(base.cr.loginFSM.request, 'chooseAvatar', [base.cr.avList]), Func(base.transitions.fadeIn, 2) ).start() def setColorScale(self, *args, **kwargs): self.backgroundNodePath.setColorScale(*args, **kwargs) self.logo.setColorScale(*args, **kwargs) self.label.setColorScale(*args, **kwargs) self.versionLabel.setColorScale(*args, **kwargs)
class DMenuScreen(DirectObject): notify = directNotify.newCategory('DMenuScreen') def __init__(self): DirectObject.__init__(self) base.cr.DMENU_SCREEN = self self.seq = None self.isSeqPlaying = False # .isPlaying() doesnt want to work if DMENU_GAME == 'Toontown': base.cr.avChoice = None fadeSequence = Sequence( Func(base.transitions.fadeOut, .001), Wait(.5), Func(base.transitions.fadeIn, .5), base.camera.posHprInterval(1, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType='easeInOut')).start() if DMENU_GAME == 'Toontown': self.background = loader.loadModel( 'phase_3.5/models/modules/tt_m_ara_int_toonhall') self.background.reparentTo(render) self.background.setPosHpr(-25, 0, 8.1, -95, 0, 0) ropes = loader.loadModel( 'phase_4/models/modules/tt_m_ara_int_ropes') ropes.reparentTo(self.background) self.sillyMeter = Actor.Actor( 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_default', { 'arrowTube': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_arrowFluid', 'phaseOne': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseOne', 'phaseTwo': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseTwo', 'phaseThree': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseThree', 'phaseFour': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFour', 'phaseFourToFive': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFourToFive', 'phaseFive': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFive' }) self.sillyMeter.reparentTo(self.background) self.sillyMeter.makeSubpart('arrow', ['uvj_progressBar*', 'def_springA']) self.sillyMeter.makeSubpart('meter', ['def_pivot'], ['uvj_progressBar*', 'def_springA']) self.audio3d = Audio3DManager.Audio3DManager( base.sfxManagerList[0], camera) self.phase3Sfx = self.audio3d.loadSfx( 'phase_4/audio/sfx/tt_s_prp_sillyMeterPhaseThree.ogg') self.phase3Sfx.setLoop(True) self.arrowSfx = self.audio3d.loadSfx( 'phase_4/audio/sfx/tt_s_prp_sillyMeterArrow.ogg') self.arrowSfx.setLoop(False) self.phase3Sfx.setVolume(0.2) self.arrowSfx.setVolume(0.2) self.animSeq = Sequence( Sequence( ActorInterval(self.sillyMeter, 'arrowTube', partName='arrow', constrainedLoop=0, startFrame=236, endFrame=247), Func(self.arrowSfx.play)), Parallel( ActorInterval(self.sillyMeter, 'arrowTube', partName='arrow', duration=604800, constrainedLoop=1, startFrame=247, endFrame=276), Sequence( Func(self.phase3Sfx.play), Func(self.audio3d.attachSoundToObject, self.phase3Sfx, self.sillyMeter)))) self.animSeq.start() self.smPhase2 = self.sillyMeter.find('**/stage2') self.smPhase2.show() self.sillyMeter.loop('phaseOne', partName='meter') self.sillyMeter.setBlend(frameBlend=True) self.surlee = Toon.Toon() self.surlee.setName('Doctor Surlee') self.surlee.setPickable(0) self.surlee.setPlayerType(CCNonPlayer) dna = ToonDNA.ToonDNA() dna.newToonFromProperties('pls', 'ls', 'l', 'm', 9, 0, 9, 9, 98, 27, 86, 27, 38, 27) self.surlee.setDNA(dna) self.surlee.loop('scientistGame') self.surlee.reparentTo(self.background) self.surlee.setPosHpr(13, 24, 0.025, -180, 0, 0) self.dimm = Toon.Toon() self.dimm.setName('Doctor Dimm') self.dimm.setPickable(0) self.dimm.setPlayerType(CCNonPlayer) dna = ToonDNA.ToonDNA() dna.newToonFromProperties('fll', 'ss', 's', 'm', 15, 0, 15, 15, 99, 27, 86, 27, 39, 27) self.dimm.setDNA(dna) self.dimm.loop('scientistGame') self.dimm.reparentTo(self.background) self.dimm.setPosHpr(16, 24, 0.025, -180, 0, 0) surleeHand = self.surlee.find('**/def_joint_right_hold') clipBoard = loader.loadModel( 'phase_4/models/props/tt_m_prp_acs_clipboard') surleeHandNode = surleeHand.attachNewNode('ClipBoard') clipBoard.instanceTo(surleeHandNode) surleeHandNode.setH(180) surleeHandNode.setScale(render, 1.0) surleeHandNode.setPos(0, 0, 0.1) dimmHand = self.dimm.find('**/def_joint_right_hold') sillyReader = loader.loadModel( 'phase_4/models/props/tt_m_prp_acs_sillyReader') dimHandNode = dimmHand.attachNewNode('SillyReader') sillyReader.instanceTo(dimHandNode) dimHandNode.setH(180) dimHandNode.setScale(render, 1.0) dimHandNode.setPos(0, 0, 0.1) self.banana = self.background.find('**/gagBanana') self.bananaClicker = CollisionTraverser() #self.bananaClicker.showCollisions(render) self.collHandlerQueue = CollisionHandlerQueue() self.bananaRayNode = CollisionNode('bananaMouseRay') self.bananaRayNP = base.camera.attachNewNode(self.bananaRayNode) self.bananaRayNode.setIntoCollideMask(BitMask32.bit(0)) self.bananaRayNode.setFromCollideMask(BitMask32.bit(1)) self.banana.setCollideMask(BitMask32.bit(1)) self.ray = CollisionRay() self.bananaRayNode.addSolid(self.ray) self.bananaClicker.addCollider(self.bananaRayNP, self.collHandlerQueue) self.accept("mouse1", self.slipAndSlideOnThisBananaPeelHaHaHa) for frame in render.findAllMatches('*/doorFrame*'): frame.removeNode() self.sky = loader.loadModel('phase_3.5/models/props/TT_sky') SkyUtil.startCloudSky(self) base.camera.setPosHpr(MAIN_POS, MAIN_HPR) self.logo = OnscreenImage(image=GameLogo, scale=(.5, .5, .25)) self.logo.reparentTo(aspect2d) self.logo.setTransparency(TransparencyAttrib.MAlpha) scale = self.logo.getScale() self.logo.setPos(0, 0, .5) self.logo.setColorScale(Vec4(0, 0, 0, 0)) fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() self.createButtons() self.fadeOut = None self.optionsMgr = PickAToonOptions.NewPickAToonOptions() #self.quitConfirmation = DMenuQuit() self.patNode = None if DMENU_GAME == 'Toontown': # TT: We need these to run the Pick A Toon screen self.patAvList = base.cr.PAT_AVLIST self.patFSM = base.cr.PAT_LOGINFSM self.patDoneEvent = base.cr.PAT_DONEEVENT def slipAndSlideOnThisBananaPeelHaHaHa(self): if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() def setPlayingStatus(status): self.isSeqPlaying = status self.ray.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.bananaClicker.traverse(render) if self.collHandlerQueue.getNumEntries() > 0: self.collHandlerQueue.sortEntries() pickedObj = self.collHandlerQueue.getEntry(0).getIntoNodePath() surleeAnim = random.choice(['slip-backward', 'slip-forward']) dimmAnim = random.choice(['slip-backward', 'slip-forward']) if pickedObj == self.banana: self.seq = Sequence( Func(setPlayingStatus, True), Func(self.surlee.play, surleeAnim), Func(self.dimm.play, dimmAnim), Wait(3), Func(self.surlee.loop, 'scientistGame'), Func(self.dimm.loop, 'scientistGame'), Func(setPlayingStatus, False)) if not self.isSeqPlaying: self.seq.start() def skyTrack(self, task): return SkyUtil.cloudSkyTrack(task) def createButtons(self): buttonImage = GuiModel.find('**/QuitBtn_RLVR') self.PlayButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=PlayGame, text_scale=.1, scale=0.95, command=self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Options, text_scale=.1, scale=0.95, command=self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Quit, text_scale=.1, scale=0.95, command=self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show() # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95) # self.BRButton.reparentTo(aspect2d) # self.BRButton.setPos(-.9, 0, -.9) # self.BRButton.show() self.buttonInAnimation() def murder(self): if self.logo is not None: self.logo.destroy() self.logo = None if self.background is not None: self.background.hide() self.background.reparentTo(hidden) self.background.removeNode() self.background = None if self.PlayButton is not None: self.PlayButton.destroy() self.PlayButton = None if self.OptionsButton is not None: self.OptionsButton.destroy() self.OptionsButton = None if self.QuitButton is not None: self.QuitButton.destroy() self.QuitButton = None if self.phase3Sfx: self.phase3Sfx.stop() del self.phase3Sfx if self.surlee: self.surlee.delete() if self.dimm: self.dimm.delete() del self.bananaRayNode del self.bananaRayNP del self.bananaClicker del self.collHandlerQueue del self.ray self.ignoreAll() taskMgr.remove('skyTrack') self.sky.reparentTo(hidden) def openOptions(self): self.optionsMgr.showOptions() self.closeOptionsButton = DirectButton( relief=None, image=(btnUp, btnDn, btnRlvr), text="Back", text_fg=(0, 0, 0, 1), text_scale=TTLocalizer.AClogoutButton, text_pos=(0, -0.035), image_scale=1, image1_scale=1.05, image2_scale=1.05, scale=0.7, command=self.hideOptions) self.closeOptionsButton.reparentTo(base.a2dTopLeft) self.closeOptionsButton.setPos(0.5, 0, -0.07) Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnHidePos), blendType='easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnHidePos), blendType='easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnHidePos), blendType='easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType='easeInOut')).start() def hideOptions(self): self.optionsMgr.hideOptions() self.closeOptionsButton.hide() self.buttonInAnimation() def playGame(self): if self.fadeOut is not None: self.fadeOut.finish() self.fadeOut = None self.fadeOut = base.transitions.getFadeOutIval(t=1) #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start() Sequence( Func(self.doPlayButton), Wait(1), #Func(self.murder), Func(self.enterGame)).start() #Func(base.transitions.fadeIn, 1)).start() def enterOptions(self): pass def enterGame(self): base.cr.avChoice = PickAToon.PickAToon(self.patAvList, self.patFSM, self.patDoneEvent) base.cr.avChoice.load() base.cr.avChoice.enter() def doPlayButton(self): Parallel( self.PlayButton.posInterval(1, Point3(PlayBtnHidePos), blendType='easeInOut'), self.OptionsButton.posInterval(1, Point3(OptionsBtnHidePos), blendType='easeInOut'), self.QuitButton.posInterval(1, Point3(QuitBtnHidePos), blendType='easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType='easeInOut')).start() def quitGame(self): self.showQuitConfirmation() def showQuitConfirmation(self): #self.quitConfirmation.showConfirmation() base.exitFunc() def buttonInAnimation(self): logo = self.logo.posInterval(.5, Point3(0, 0, .5), blendType='easeInOut') play = self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType='easeInOut') opt = self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType='easeInOut') quit = self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType='easeInOut') Sequence(Func(logo.start), Wait(0.1), Func(play.start), Wait(0.2), Func(opt.start), Wait(0.2), Func(quit.start)).start() def showHamburgerMenu(self): self.hbButton.hide() self.hbHideButton.show() self.patNode2d = aspect2d.find("**/patNode2d") self.patNode2d.posInterval(.5, Point3(.5, 0, 0), blendType='easeInOut').start() self.patNode = render.find("**/patNode") self.patNode.posInterval(.5, Point3(0, -3, 0), blendType='easeInOut').start() def hideHamburgerMenu(self): self.hbButton.show() self.hbHideButton.hide() self.patNode2d.posInterval(.5, Point3(0, 0, 0), blendType='easeInOut').start() self.patNode.posInterval(.5, Point3(0, 0, 0), blendType='easeInOut').start() def reportBug(self): BugReportGUI.BugReportGUI() def createTabs(self): self.PlayButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=PlayGame, text_scale=.1, scale=0.95, command=self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Options, text_scale=.1, scale=0.95, command=self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Quit, text_scale=.1, scale=0.95, command=self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show()
class ShopWindow(DirectFrame): def __init__(self, shop, image): DirectFrame.__init__(self) self.shop = shop self.bgImage = image self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.nPage = -1 self.nPages = 0 self.nextPage = 0 self.prevPage = -1 self.pages = [] self.isSetup = False return def setup(self, title = 'CHOOSE WHAT YOU WANT TO BUY'): font = CIGlobals.getMickeyFont() txtFg = (0, 0, 0, 1) txtScale = 0.05 txtPos = (0, -0.1) buttons = loader.loadModel('phase_3.5/models/gui/QT_buttons.bam') self.window = OnscreenImage(image=self.bgImage, scale=(0.9, 1, 0.7), parent=self) self.title = DirectLabel(text=title, relief=None, pos=(0, 0, 0.5), text_wordwrap=10, text_font=font, text_fg=(1, 1, 0, 1), scale=0.1, parent=self) self.infoLbl = DirectLabel(text='Welcome!', relief=None, text_scale=0.075, text_fg=txtFg, text_shadow=(0, 0, 0, 0), pos=(0, 0, 0.215)) self.okBtn = DirectButton(geom=CIGlobals.getOkayBtnGeom(), relief=None, text='OK', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(-0.1, 0, -0.5), parent=self) self.clBtn = DirectButton(geom=CIGlobals.getCancelBtnGeom(), relief=None, text='Cancel', text_fg=txtFg, text_scale=txtScale, text_pos=txtPos, pos=(0.1, 0, -0.5), parent=self) buttonGeom = (buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back'), buttons.find('**/QT_back')) self.backBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(-0.3, 0, -0.25), parent=self, command=self.changePage, extraArgs=[0]) self.nextBtn = DirectButton(geom=buttonGeom, relief=None, scale=0.05, pos=(0.3, 0, -0.25), hpr=(0, 0, 180), command=self.changePage, extraArgs=[1], parent=self) self.hideInfo() return def changePage(self, direction): var = self.prevPage if direction == 1: var = self.nextPage self.setPage(var) def __makeGagEntry(self, pos, item, values, page): itemImage = values.get('image') button = DirectButton(geom=itemImage, scale=1.3, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item]) supply = base.localAvatar.getBackpack().getSupply(item().getName()) maxSupply = base.localAvatar.getBackpack().getMaxSupply(item().getName()) buttonLabel = DirectLabel(text='%s/%s\n%s JBS' % (str(supply), str(maxSupply), str(values.get('price'))), relief=None, parent=button, text_scale=0.05, pos=(0, 0, -0.11)) self.addEntryToPage(page, item, values, button, buttonLabel) return def __makeUpgradeEntry(self, pos, item, values, page): itemImage = values.get('image') button = DirectButton(image=itemImage, scale=0.15, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item]) button.setTransparency(TransparencyAttrib.MAlpha) upgradeID = values.get('upgradeID') supply = base.localAvatar.getPUInventory()[0] if supply < 0: supply = 0 maxSupply = values.get('maxUpgrades') if upgradeID == 0 and base.localAvatar.getMyBattle().getTurretManager().myTurret: supply = 1 buttonLabel = DirectLabel(text='%s\n%s/%s\n%s JBS' % (item, str(supply), str(maxSupply), str(values.get('price'))), relief=None, parent=button, text_scale=0.3, pos=(0, 0, -1.2)) self.addEntryToPage(page, item, values, button, buttonLabel) return def __makeHealEntry(self, pos, item, values, page): label = '%s' % item itemImage = values.get('image') if 'showTitle' in values: label = '%s\n%s JBS' % (item, values.get('price')) button = DirectButton(image=itemImage, scale=0.105, pos=pos, relief=None, parent=page, command=self.shop.purchaseItem, extraArgs=[item]) button.setTransparency(TransparencyAttrib.MAlpha) buttonLabel = DirectLabel(text=label, relief=None, parent=button, text_scale=0.55, pos=(0, 0, -1.6)) self.addEntryToPage(page, item, values, button, buttonLabel) return def addEntryToPage(self, page, item, values, button, buttonLabel): page.addItemEntry(item, [button, buttonLabel]) page.addItem({item: values}) def makePages(self, items): newItems = dict(items) loadout = [] for slot in base.localAvatar.getBackpack().gagGUI.getSlots(): loadout.append(slot.getGag().getID()) for item, values in newItems.items(): if values.get('type') == ItemType.GAG: gag = item() if gag.getID() not in loadout or not base.localAvatar.getBackpack().isInBackpack(gag.getName()): del newItems[item] self.nPages = int(len(newItems) / 4) if self.nPages % 4 != 0 and len(newItems) > 4: self.nPages += 1 elif self.nPages == 0: self.nPages = 1 itemPos = [(-0.45, 0, 0), (-0.15, 0, 0), (0.15, 0, 0), (0.45, 0, 0)] pageIndex = 0 itemIndex = 0 index = 1 for _ in range(self.nPages): page = Page(self.shop, self) self.pages.append(page) for item, values in newItems.iteritems(): pos = itemPos[itemIndex] page = self.pages[pageIndex] itemType = values.get('type') if itemType == ItemType.GAG: self.__makeGagEntry(pos, item, values, page) elif itemType == ItemType.UPGRADE: self.__makeUpgradeEntry(pos, item, values, page) elif itemType == ItemType.HEAL: self.__makeHealEntry(pos, item, values, page) if index % 4 == 0: index = 1 pageIndex += 1 itemIndex = 0 else: itemIndex = itemIndex + 1 index += 1 if self.nPages == 1: self.backBtn.hide() self.nextBtn.hide() for page in self.pages: page.hide() page.update() self.isSetup = True def updatePages(self): for page in self.pages: page.update() def setPage(self, page): if self.nPage > -1: self.pages[self.nPage].hide() self.setBackBtn(True) self.setNextBtn(True) if page - 1 < 0: self.setBackBtn(False) elif page + 1 == self.nPages: self.setNextBtn(False) if page < 0 or page > self.nPages: return self.prevPage = page - 1 self.nextPage = page + 1 self.nPage = page self.pages[page].show() def setBackBtn(self, enabled): if self.backBtn: if enabled == False: self.backBtn.setColorScale(GRAYED_OUT_COLOR) self.backBtn['state'] = DGG.DISABLED else: self.backBtn.setColorScale(NORMAL_COLOR) self.backBtn['state'] = DGG.NORMAL def setNextBtn(self, enabled): if self.nextBtn: if enabled == False: self.nextBtn.setColorScale(GRAYED_OUT_COLOR) self.nextBtn['state'] = DGG.DISABLED else: self.nextBtn.setColorScale(NORMAL_COLOR) self.nextBtn['state'] = DGG.NORMAL def setOKCommand(self, command): if self.okBtn: self.okBtn['command'] = command def setCancelCommand(self, command): if self.clBtn: self.clBtn['command'] = command def showInfo(self, text, negative = 0, duration = -1): self.infoLbl.show() if negative: self.infoLbl['text_fg'] = (0.9, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 1) else: self.infoLbl['text_fg'] = (0, 0, 0, 1) self.infoLbl['text_shadow'] = (0, 0, 0, 0) self.infoLbl['text'] = text if duration > -1: Sequence(Wait(duration), Func(self.hideInfo)).start() def hideInfo(self): if self.infoLbl: self.infoLbl.hide() def delete(self): elements = [self.title, self.okBtn, self.clBtn, self.infoLbl, self.backBtn, self.nextBtn] for element in elements: element.destroy() del elements for page in self.pages: page.destroy() self.pages.remove(page) self.title = None self.okBtn = None self.clBtn = None self.infoLbl = None self.backBtn = None self.nextBtn = None self.bgImage = None if self.window: self.window.destroy() self.window = None self.destroy() return
class CameraShyFirstPerson(FirstPerson): toonInFocusColor = VBase4(0.25, 1.0, 0.25, 1.0) toonOutOfFocusColor = VBase4(1.0, 1.0, 1.0, 1.0) fullyChargedState = 5 def __init__(self, mg): self.mg = mg self.cameraFocus = None self.batteryFrame = None self.batteryBg = None self.batteryBar = None self.rechargeSound = None self.fullyChargedSound = None self.hasToonInFocus = False self.toonToTakePicOf = None self.cameraRechargeState = None self.cameraRechargingLabel = None self.cameraFlashSeq = None self.camFSM = ClassicFSM('CameraFSM', [State('off', self.enterOff, self.exitOff), State('ready', self.enterCameraReady, self.exitCameraReady), State('recharge', self.enterCameraRecharge, self.exitCameraRecharge)], 'off', 'off') self.camFSM.enterInitialState() FirstPerson.__init__(self) return def movementTask(self, task): if not inputState.isSet('jump') and not base.localAvatar.walkControls.isAirborne and inputState.isSet('forward') or inputState.isSet('reverse') or inputState.isSet('slideLeft') or inputState.isSet('slideRight'): if base.localAvatar.getAnimState() != 'run': base.localAvatar.setAnimState('run') base.localAvatar.playMovementSfx('run') self.mg.sendUpdate('runningAvatar', [base.localAvatar.doId]) elif inputState.isSet('jump') or base.localAvatar.walkControls.isAirborne: if base.localAvatar.getAnimState() != 'jump': base.localAvatar.setAnimState('jump') base.localAvatar.playMovementSfx(None) self.mg.sendUpdate('jumpingAvatar', [base.localAvatar.doId]) elif base.localAvatar.getAnimState() != 'neutral': base.localAvatar.setAnimState('neutral') base.localAvatar.playMovementSfx(None) self.mg.sendUpdate('standingAvatar', [base.localAvatar.doId]) return task.cont def enterOff(self): pass def exitOff(self): pass def enterCameraReady(self): self.acceptOnce('mouse1', self.__mouse1Pressed) def stopCameraFlash(self): if self.cameraFlashSeq: self.cameraFlashSeq.finish() self.cameraFlashSeq = None return def __mouse1Pressed(self): self.cameraFlashSeq = Sequence(Func(base.transitions.setFadeColor, 1, 1, 1), Func(base.transitions.fadeOut, 0.1), Wait(0.1), Func(base.transitions.fadeIn, 0.1), Wait(0.1), Func(base.transitions.setFadeColor, 0, 0, 0)) self.cameraFlashSeq.start() self.mg.sendUpdate('remoteAvatarTakePicture', [base.localAvatar.doId]) self.mg.myRemoteAvatar.takePicture() if self.hasToonInFocus and self.toonToTakePicOf: self.mg.sendUpdate('tookPictureOfToon', [self.toonToTakePicOf.doId]) self.camFSM.request('recharge') def exitCameraReady(self): self.ignore('mouse1') def enterCameraRecharge(self): self.batteryBar.update(0) taskMgr.add(self.__rechargeNextState, 'rechargeCamera') def __rechargeNextState(self, task): if self.cameraRechargeState == None: self.cameraRechargeState = -1 self.cameraRechargeState += 1 if self.cameraRechargeState > 0: base.playSfx(self.rechargeSound) self.batteryBar.update(self.cameraRechargeState) if self.cameraRechargeState == self.fullyChargedState: base.playSfx(self.fullyChargedSound) self.camFSM.request('ready') return task.done else: task.delayTime = 1.0 return task.again def exitCameraRecharge(self): taskMgr.remove('rechargeCamera') self.cameraRechargeState = None return def __handleRayInto(self, entry): intoNP = entry.getIntoNodePath() toonNP = intoNP.getParent() for key in base.cr.doId2do.keys(): obj = base.cr.doId2do[key] if obj.__class__.__name__ == 'DistributedToon': if obj.getKey() == toonNP.getKey(): self.__handleToonInFocus(obj) def __handleRayOut(self, entry): intoNP = entry.getIntoNodePath() toonNP = intoNP.getParent() for key in base.cr.doId2do.keys(): obj = base.cr.doId2do[key] if obj.__class__.__name__ == 'DistributedToon': if obj.getKey() == toonNP.getKey(): self.toonToTakePicOf = None self.hasToonInFocus = False if self.cameraFocus.getColorScale() == self.toonInFocusColor: self.cameraFocus.setColorScale(self.toonOutOfFocusColor) return def __handleToonInFocus(self, toon): if not self.hasToonInFocus or self.toonToTakePicOf is not None or self.toonToTakePicOf.doId != toon.doId: self.toonToTakePicOf = toon self.hasToonInFocus = True self.cameraFocus.setColorScale(self.toonInFocusColor) return def start(self): self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/MG_pairing_match.mp3') self.rechargeSound = base.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.mp3') self.batteryFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.2, 0, 0.1), scale=(0.8, 0, 1)) self.batteryBg = OnscreenImage(image='phase_4/maps/battery_charge_frame.png', parent=self.batteryFrame) self.batteryBg.setTransparency(1) self.batteryBg.setX(0.03) self.batteryBg.setScale(0.17, 0, 0.05) self.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame) self.cameraFocus = loader.loadModel('phase_4/models/minigames/photo_game_viewfinder.bam') self.cameraFocus.reparentTo(base.aspect2d) self.focusCollHandler = CollisionHandlerEvent() self.focusCollHandler.setInPattern('%fn-into') self.focusCollHandler.setOutPattern('%fn-out') self.focusCollNode = CollisionNode('mouseRay') self.focusCollNP = base.camera.attachNewNode(self.focusCollNode) self.focusCollNode.setCollideMask(BitMask32(0)) self.focusCollNode.setFromCollideMask(CIGlobals.WallBitmask) self.focusRay = CollisionRay() self.focusRay.setFromLens(base.camNode, 0.0, 0.0) self.focusCollNode.addSolid(self.focusRay) base.cTrav.addCollider(self.focusCollNP, self.focusCollHandler) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) FirstPerson.start(self) return def reallyStart(self): self.accept('mouseRay-into', self.__handleRayInto) self.accept('mouseRay-out', self.__handleRayOut) self.camFSM.request('recharge') taskMgr.add(self.movementTask, 'movementTask') FirstPerson.reallyStart(self) def end(self): self.camFSM.request('off') taskMgr.remove('movementTask') self.ignore('mouseRay-into') self.ignore('mouseRay-out') FirstPerson.end(self) def reallyEnd(self): self.batteryBar.destroy() self.batteryBar = None self.batteryBg.destroy() self.batteryBg = None self.batteryFrame.destroy() self.batteryFrame = None self.cameraFocus.removeNode() self.cameraFocus = None self.focusCollHandler = None self.focusCollNode = None self.focusCollNP.removeNode() self.focusCollNP = None self.focusRay = None self.hasToonInFocus = None self.toonToTakePicOf = None self.fullyChargedSound = None self.rechargeSound = None self.stopCameraFlash() FirstPerson.reallyEnd(self) base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, CIGlobals.ToonJumpForce, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed) return def cleanup(self): self.camFSM.requestFinalState() self.camFSM = None FirstPerson.cleanup(self) return