def __init__(self, cogMenu, dept): NodePath.__init__(self, 'CogMenuBar-%s' % dept) self.dept = dept self.deptIndex = CogDisguiseGlobals.dept2deptIndex(self.dept) icons = loader.loadModel('phase_3/models/gui/cog_icons') self.icon = icons.find(ICON_NODES[self.deptIndex]).copyTo(self) self.icon.setColor(ICON_COLORS[self.deptIndex]) self.icon.setScale(0.07) self.icon.setX(-0.25) icons.removeNode() self.progressBar = DirectWaitBar(parent=self, relief=DirectGuiGlobals.SUNKEN, frameSize=(-1, 1, -0.15, 0.15), borderWidth=(0.02, 0.02), scale=0.20, frameColor=(DisguisePage.DeptColors[self.deptIndex][0] * 0.7, DisguisePage.DeptColors[self.deptIndex][1] * 0.7, DisguisePage.DeptColors[self.deptIndex][2] * 0.7, 1), barColor=(DisguisePage.DeptColors[self.deptIndex][0], DisguisePage.DeptColors[self.deptIndex][1], DisguisePage.DeptColors[self.deptIndex][2], 1), text='0/0 ' + TTLocalizer.RewardPanelMeritBarLabels[self.deptIndex], text_scale=TTLocalizer.RPmeritBarLabels, text_fg=(0, 0, 0, 1), text_align=TextNode.ALeft, text_pos=(-0.96, -0.05)) self.reparentTo(cogMenu)
def __init__(self, phaseNames): self.phaseNames = phaseNames self.model = loader.loadModel('models/gui/pir_m_gui_gen_loadingBar') bar = self.model.findTexture('pir_t_gui_gen_loadingBar') self.model.find('**/loading_bar').hide() self.topFrame = DirectFrame(parent = base.a2dTopRight, pos = (-0.80000000000000004, 0, -0.10000000000000001), sortOrder = NO_FADE_SORT_INDEX + 1) self.text = DirectLabel(relief = None, parent = self.topFrame, guiId = 'DownloadWatcherText', pos = (0, 0, 0), text = ' ', text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 1), text_scale = 0.040000000000000001, textMayChange = 1, text_align = TextNode.ARight, text_pos = (0.17000000000000001, 0), sortOrder = 2) self.bar = DirectWaitBar(relief = None, parent = self.topFrame, guiId = 'DownloadWatcherBar', pos = (0, 0, 0), frameSize = (-0.40000000000000002, 0.38, -0.044999999999999998, 0.065000000000000002), borderWidth = (0.02, 0.02), range = 100, frameColor = (1, 1, 1, 1), barColor = (0, 0.29999999999999999, 0, 1), barTexture = bar, geom = self.model, geom_scale = 0.089999999999999997, geom_pos = (-0.014, 0, 0.01), text = '0%', text_scale = 0.040000000000000001, text_fg = (1, 1, 1, 1), text_align = TextNode.ALeft, text_pos = (0.19, 0), sortOrder = 1) self.bgFrame = DirectFrame(relief = DGG.FLAT, parent = self.topFrame, pos = (0, 0, 0), frameColor = (0.5, 0.27000000000000002, 0.35999999999999999, 0.20000000000000001), frameSize = (-0.44, 0.39000000000000001, -0.035999999999999997, 0.056000000000000001), borderWidth = (0.02, 0.02), scale = 0.90000000000000002, sortOrder = 0) self.accept('launcherPercentPhaseComplete', self.update)
class PiratesDownloadWatcher(DownloadWatcher.DownloadWatcher): positions = [ (Point3(1, 0, 0.90000000000000002), Point3(1, 0, 0.90000000000000002)), (Point3(1, 0, 0.90000000000000002), Point3(1, 0, 0.90000000000000002)), (Point3(1, 0, 0.90000000000000002), Point3(1, 0, 0.90000000000000002))] def __init__(self, phaseNames): self.phaseNames = phaseNames self.model = loader.loadModel('models/gui/pir_m_gui_gen_loadingBar') bar = self.model.findTexture('pir_t_gui_gen_loadingBar') self.model.find('**/loading_bar').hide() self.topFrame = DirectFrame(parent = base.a2dTopRight, pos = (-0.80000000000000004, 0, -0.10000000000000001), sortOrder = NO_FADE_SORT_INDEX + 1) self.text = DirectLabel(relief = None, parent = self.topFrame, guiId = 'DownloadWatcherText', pos = (0, 0, 0), text = ' ', text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 1), text_scale = 0.040000000000000001, textMayChange = 1, text_align = TextNode.ARight, text_pos = (0.17000000000000001, 0), sortOrder = 2) self.bar = DirectWaitBar(relief = None, parent = self.topFrame, guiId = 'DownloadWatcherBar', pos = (0, 0, 0), frameSize = (-0.40000000000000002, 0.38, -0.044999999999999998, 0.065000000000000002), borderWidth = (0.02, 0.02), range = 100, frameColor = (1, 1, 1, 1), barColor = (0, 0.29999999999999999, 0, 1), barTexture = bar, geom = self.model, geom_scale = 0.089999999999999997, geom_pos = (-0.014, 0, 0.01), text = '0%', text_scale = 0.040000000000000001, text_fg = (1, 1, 1, 1), text_align = TextNode.ALeft, text_pos = (0.19, 0), sortOrder = 1) self.bgFrame = DirectFrame(relief = DGG.FLAT, parent = self.topFrame, pos = (0, 0, 0), frameColor = (0.5, 0.27000000000000002, 0.35999999999999999, 0.20000000000000001), frameSize = (-0.44, 0.39000000000000001, -0.035999999999999997, 0.056000000000000001), borderWidth = (0.02, 0.02), scale = 0.90000000000000002, sortOrder = 0) self.accept('launcherPercentPhaseComplete', self.update) def update(self, phase, percent, reqByteRate, actualByteRate): phaseName = self.phaseNames[phase] self.text['text'] = OTPLocalizer.DownloadWatcherUpdate % phaseName + ' -' self.bar['text'] = '%s %%' % percent self.bar['value'] = percent def foreground(self): self.topFrame.reparentTo(base.a2dpTopRight) self.topFrame.setBin('gui-fixed', 55) self.topFrame['sortOrder'] = NO_FADE_SORT_INDEX + 1 def background(self): self.topFrame.reparentTo(base.a2dTopRight) self.topFrame.setBin('unsorted', 49) self.topFrame['sortOrder'] = -1 def cleanup(self): self.text.destroy() self.bar.destroy() self.bgFrame.destroy() self.topFrame.destroy() self.ignoreAll()
def __init__(self, appRunner, parent = None, **kw): PackageInstaller.__init__(self, appRunner) optiondefs = ( ('borderWidth', (0.01, 0.01), None), ('relief', DGG.SUNKEN, self.setRelief), ('range', 1, self.setRange), ('barBorderWidth', (0.01, 0.01), self.setBarBorderWidth), ('barColor', (0.424, 0.647, 0.878, 1), self.setBarColor), ('barRelief', DGG.RAISED, self.setBarRelief), ('text', 'Starting', self.setText), ('text_pos', (0, -0.025), None), ('text_scale', 0.1, None), ('perPackage', False, None), ('updateText', True, None), ('finished', None, None), ) self.defineoptions(kw, optiondefs) DirectWaitBar.__init__(self, parent, **kw) self.initialiseoptions(DWBPackageInstaller) self.updateBarStyle() # Hidden by default until the download begins. self.hide()
def destroy(self): PackageInstaller.cleanup(self) DirectWaitBar.destroy(self)
class Slot(DirectFrame): def __init__(self, baseGui, index, pos, parent): DirectFrame.__init__( self, pos=pos, parent=parent, image=loader.loadTexture('phase_3.5/maps/slot_%s_%s.png' % (str(index), 'idle')), scale=0.15, frameSize=(-1, 1, -1, 1), frameColor=(0, 0, 0, 0), sortOrder=0) self.initialiseoptions(Slot) self.gui = baseGui self.index = index self.hoverObj = None self.gagImage = None self.gag = None self.mouseRlvrSfx = base.loadSfx('phase_3/audio/sfx/GUI_rollover.ogg') self.soundRecharged = base.loadSfx( 'phase_3.5/audio/sfx/tt_s_gui_sbk_cdrSuccess.ogg') # The no ammo text over the gag when you run out of ammo. self.infoText = OnscreenText(text="No\nAmmo", fg=(1, 0, 0, 1), parent=self, scale=0.5, shadow=(0, 0, 0, 1), align=TextNode.ACenter, pos=(0, 0.1)) self.infoText.setBin('unsorted', 100) self.infoText.hide() # The recharging progress bar. self.rechargeBar = DirectWaitBar(value=0, range=100, frameColor=(1, 1, 1, 1), barColor=(0.286, 0.901, 1, 1), relief=DGG.RAISED, borderWidth=(0.04, 0.04), pos=(-1.25, 0, 0), hpr=(0, 0, -90), parent=self, frameSize=(-0.85, 0.85, -0.12, 0.12)) self.rechargeBar.setBin('fixed', 60) self.rechargeBar.hide() # The gag label underneath the gag icon. self.gagLabel = OnscreenText(text="Birthday Cake", fg=(1, 1, 1, 1), parent=self, scale=0.25, shadow=(0, 0, 0, 1), align=TextNode.ACenter, pos=(0, -0.9), mayChange=1) self.gagLabel.setBin('fixed', 50) self.gagLabel.hide() # The left arrow for moving to the gag before this one in the sequence. battleGui = loader.loadModel('phase_3.5/models/gui/battle_gui.bam') arrow = battleGui.find('**/PckMn_BackBtn') arrowRlvr = battleGui.find('**/PckMn_BackBtn_Rlvr') arrowDn = battleGui.find('**/PckMn_BackBtn_Dn') self.leftArrow = DirectButton(geom=(arrow, arrowDn, arrowRlvr, arrow), parent=self, pos=(-0.925, -2.0, -1.02), relief=None, scale=2, command=self.updateLoadout, extraArgs=[0], geom3_color=(0.5, 0.5, 0.5, 1.0)) self.leftArrow.setBin('fixed', 60) self.rightArrow = DirectButton(geom=(arrow, arrowDn, arrowRlvr, arrow), parent=self, pos=(0.925, -2.0, -1.02), hpr=(180, 0, 0), relief=None, scale=2, command=self.updateLoadout, extraArgs=[1], geom3_color=(0.5, 0.5, 0.5, 1.0)) self.rightArrow.setBin('fixed', 60) self.hoverObj = DirectButton(relief=None, parent=self, frameSize=self['frameSize']) self.setBin('transparent', 30) self.setOutlineImage('idle') # Let's handle mouse entering and leaving. self.hoverObj.guiItem.setActive(True) self.hoverObj.bind(DGG.WITHIN, self.mouseEntered) self.hoverObj.bind(DGG.WITHOUT, self.mouseExited) self.hoverObj.bind(DGG.B1CLICK, self.gui.click_setWeapon, [self]) def toggleArrows(self, left, right): if left: self.leftArrow['state'] = DGG.NORMAL else: self.leftArrow['state'] = DGG.DISABLED if right: self.rightArrow['state'] = DGG.NORMAL else: self.rightArrow['state'] = DGG.DISABLED def updateArrows(self): if not self.gag: self.toggleArrows(False, False) else: track = GagGlobals.TrackGagNamesByTrackName.get( GagGlobals.getTrackOfGag(self.gag.getID())) index = None useTrack = [] for name in track: gag = self.gui.backpack.getGagByID( GagGlobals.getIDByName(name)) if gag == self.gag or (not gag in self.gui.backpack.getLoadout()): useTrack.append(name) index = useTrack.index(self.gag.getName()) if index == 0: self.toggleArrows(False, True) elif (index > 0 and index < (len(useTrack) - 1)): gagId = GagGlobals.getIDByName(useTrack[index + 1]) if not self.gui.backpack.hasGag(gagId): self.toggleArrows(True, False) elif (index == (len(useTrack) - 1)): self.toggleArrows(True, False) else: self.toggleArrows(True, True) def updateLoadout(self, forward): if self.gag and self.gag.getState() in [ GagState.RECHARGING, GagState.LOADED ]: track = GagGlobals.TrackGagNamesByTrackName.get( GagGlobals.getTrackOfGag(self.gag.getID())) index = None useTrack = [] for name in track: gag = self.gui.backpack.getGagByID( GagGlobals.getIDByName(name)) if gag == self.gag or (not gag in self.gui.backpack.getLoadout()): useTrack.append(name) index = useTrack.index(self.gag.getName()) if forward == 1: nextGagIndex = index + 1 else: nextGagIndex = index - 1 if nextGagIndex < 0 or nextGagIndex >= len(useTrack): return gagId = GagGlobals.getIDByName(useTrack[nextGagIndex]) loadout = self.gui.backpack.getLoadout() if self.gui.backpack.hasGag(gagId) and self.gag in loadout: self.hideInfoText() if not self.gag in loadout: return loadout[loadout.index( self.gag)] = self.gui.backpack.getGagByID(gagId) self.gui.backpack.setLoadout(loadout) def showNoAmmo(self): self.infoText['text'] = "No\nAmmo" self.infoText['scale'] = 0.5 self.infoText['fg'] = (1, 0, 0, 1) self.infoText['pos'] = (0, 0.1) self.infoText.show() if self.gag and self.gag.getState() == GagState.RECHARGING: self.rechargeBar.show() def showRecharging(self): self.infoText['text'] = "Recharging..." self.infoText['scale'] = 0.315 self.infoText['fg'] = (0.286, 0.901, 1, 1) self.infoText['pos'] = (0, 0) self.infoText.show() self.rechargeBar.show() def __tickRecharge(self): if not self.gag: self.ignoreAll() else: elapsedTime = float(self.gag.getRechargeElapsedTime()) totalTime = float(self.gag.getRechargeTime()) barValue = int( float(elapsedTime / totalTime) * self.rechargeBar['range']) self.rechargeBar['value'] = barValue if barValue == 0: self.gui.setWeapon(self, playSound=False) self.setOutlineImage('no_ammo') self.showRecharging() elif barValue >= 100: base.playSfx(self.soundRecharged) slotImage = 'idle' if base.localAvatar.getBackpack().getSupply( self.gag.getID()) <= 0: slotImage = 'no_ammo' elif self.gui.getActiveSlot() == self: slotImage = 'selected' Sequence(Wait(0.5), Func(self.setOutlineImage, slotImage)).start() def hideInfoText(self): self.infoText.hide() self.rechargeBar.hide() def setSlotImage(self, gagImage): if self.gagImage: self.gagImage.destroy() self.gagImage = None self.gagImage = OnscreenImage(image=gagImage, parent=self) self.gagImage.setTransparency(TransparencyAttrib.MAlpha) def setOutline(self): self.setTransparency(TransparencyAttrib.MAlpha) def setOutlineImage(self, image): phase = 'phase_3.5/maps/' if hasattr(self, '_optionInfo'): self['image'] = loader.loadTexture(phase + 'slot_%s_%s.png' % (str(self.index), image)) self.setOutline() if image != 'no_ammo': if self.gag and base.localAvatar.getBackpack().getSupply( self.gag.getID( )) == 0 or self.gag and self.gag.getState( ) == GagState.RECHARGING: image = 'no_ammo' if image == 'no_ammo': if self.gag and self.gag.getState() == GagState.RECHARGING: # Show the recharge text. self.showRecharging() else: # Show the no ammo text. self.showNoAmmo() self.rechargeBar.hide() # When we have no ammo, render the frame in front of the gag image. self.setBin('fixed', 40) if self.gagImage: self.gagImage.setBin('transparent', 30) else: # Hide the no ammo text if we're not out of ammo. self.hideInfoText() # Render the gag image in front of the frame. if self.gagImage: self.gagImage.setBin('fixed', 40) self.setBin('transparent', 30) def getOutline(self): return self.outline def mouseEntered(self, cmd): if self.gag: self.gagLabel.show() self.mouseRlvrSfx.play() def mouseExited(self, cmd): self.gagLabel.hide() def setGag(self, gag): if type(gag) == types.IntType: gag = self.gui.backpack.getGagByID(gag) self.ignoreAll() self.gag = gag if gag: self.show() self.setSlotImage(self.gag.getImage()) self.gagLabel['text'] = self.gag.getName() self.accept('%s-Recharge-Tick' % (str(self.gag.getID())), self.__tickRecharge) else: self.hide() self.gagLabel['text'] = '' self.updateArrows() def getGag(self): return self.gag
class PiratesDownloadWatcher(DownloadWatcher.DownloadWatcher): positions = [(Point3(1, 0, 0.9), Point3(1, 0, 0.9)), (Point3(1, 0, 0.9), Point3(1, 0, 0.9)), (Point3(1, 0, 0.9), Point3(1, 0, 0.9))] def __init__(self, phaseNames): self.phaseNames = phaseNames self.model = loader.loadModel('models/gui/pir_m_gui_gen_loadingBar') bar = self.model.findTexture('pir_t_gui_gen_loadingBar') self.model.find('**/loading_bar').hide() self.topFrame = DirectFrame(parent=base.a2dTopRight, pos=(-0.8, 0, -0.1), sortOrder=DGG.NO_FADE_SORT_INDEX + 1) self.text = DirectLabel(relief=None, parent=self.topFrame, guiId='DownloadWatcherText', pos=(0, 0, 0), text=' ', text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1), text_scale=0.04, textMayChange=1, text_align=TextNode.ARight, text_pos=(0.17, 0), sortOrder=2) self.bar = DirectWaitBar(relief=None, parent=self.topFrame, guiId='DownloadWatcherBar', pos=(0, 0, 0), frameSize=(-0.4, 0.38, -0.045, 0.065), borderWidth=(0.02, 0.02), range=100, frameColor=(1, 1, 1, 1), barColor=(0, 0.3, 0, 1), barTexture=bar, geom=self.model, geom_scale=0.09, geom_pos=(-0.014, 0, 0.01), text='0%', text_scale=0.04, text_fg=(1, 1, 1, 1), text_align=TextNode.ALeft, text_pos=(0.19, 0), sortOrder=1) self.bgFrame = DirectFrame(relief=DGG.FLAT, parent=self.topFrame, pos=(0, 0, 0), frameColor=(0.5, 0.27, 0.36, 0.2), frameSize=(-0.44, 0.39, -0.036, 0.056), borderWidth=(0.02, 0.02), scale=0.9, sortOrder=0) self.accept('launcherPercentPhaseComplete', self.update) return def update(self, phase, percent, reqByteRate, actualByteRate): phaseName = self.phaseNames[phase] self.text[ 'text'] = OTPLocalizer.DownloadWatcherUpdate % phaseName + ' -' self.bar['text'] = '%s %%' % percent self.bar['value'] = percent def foreground(self): self.topFrame.reparentTo(base.a2dpTopRight) self.topFrame.setBin('gui-fixed', 55) self.topFrame['sortOrder'] = DGG.NO_FADE_SORT_INDEX + 1 def background(self): self.topFrame.reparentTo(base.a2dTopRight) self.topFrame.setBin('unsorted', 49) self.topFrame['sortOrder'] = -1 def cleanup(self): self.text.destroy() self.bar.destroy() self.bgFrame.destroy() self.topFrame.destroy() self.ignoreAll()
class CogMenuBar(NodePath): def __init__(self, cogMenu, dept): NodePath.__init__(self, 'CogMenuBar-%s' % dept) self.dept = dept self.deptIndex = CogDisguiseGlobals.dept2deptIndex(self.dept) icons = loader.loadModel('phase_3/models/gui/cog_icons') self.icon = icons.find(ICON_NODES[self.deptIndex]).copyTo(self) self.icon.setColor(ICON_COLORS[self.deptIndex]) self.icon.setScale(0.07) self.icon.setX(-0.25) icons.removeNode() self.progressBar = DirectWaitBar(parent=self, relief=DirectGuiGlobals.SUNKEN, frameSize=(-1, 1, -0.15, 0.15), borderWidth=(0.02, 0.02), scale=0.20, frameColor=(DisguisePage.DeptColors[self.deptIndex][0] * 0.7, DisguisePage.DeptColors[self.deptIndex][1] * 0.7, DisguisePage.DeptColors[self.deptIndex][2] * 0.7, 1), barColor=(DisguisePage.DeptColors[self.deptIndex][0], DisguisePage.DeptColors[self.deptIndex][1], DisguisePage.DeptColors[self.deptIndex][2], 1), text='0/0 ' + TTLocalizer.RewardPanelMeritBarLabels[self.deptIndex], text_scale=TTLocalizer.RPmeritBarLabels, text_fg=(0, 0, 0, 1), text_align=TextNode.ALeft, text_pos=(-0.96, -0.05)) self.reparentTo(cogMenu) def update(self): if not CogDisguiseGlobals.isSuitComplete(base.localAvatar.cogParts, self.deptIndex): self.progressBar['text'] = '%s %s' % ( CogDisguiseGlobals.getPartCountAsString(base.localAvatar.cogParts, self.deptIndex), TTLocalizer.DisguiseParts) self.progressBar['range'] = CogDisguiseGlobals.PartsPerSuit[self.deptIndex] self.progressBar['value'] = CogDisguiseGlobals.getPartCount(base.localAvatar.cogParts, self.deptIndex) return promoStatus = base.localAvatar.promotionStatus[self.deptIndex] if promoStatus != ToontownGlobals.PendingPromotion: totalMerits = CogDisguiseGlobals.getTotalMerits(base.localAvatar, self.deptIndex) merits = base.localAvatar.cogMerits[self.deptIndex] self.progressBar['range'] = totalMerits self.progressBar['value'] = merits self.progressBar['text'] = '%s/%s %s' % ( merits, totalMerits, TTLocalizer.RewardPanelMeritBarLabels[self.deptIndex]) else: self.progressBar['range'] = 1 self.progressBar['value'] = 1 maxSuitLevel = (SuitDNA.levelsPerSuit - 1) + (SuitDNA.suitsPerDept - 1) if base.localAvatar.cogLevels[self.deptIndex] == maxSuitLevel: self.progressBar['text'] = TTLocalizer.RewardPanelMeritsMaxed else: self.progressBar['text'] = TTLocalizer.RewardPanelPromotionPending def cleanup(self): self.icon.removeNode() self.progressBar.destroy() self.removeNode()
class CogMenuBar(NodePath): def __init__(self, cogMenu, dept): NodePath.__init__(self, 'CogMenuBar-%s' % dept) self.dept = dept self.deptIndex = CogDisguiseGlobals.dept2deptIndex(self.dept) icons = loader.loadModel('phase_3/models/gui/cog_icons') self.icon = icons.find(ICON_NODES[self.deptIndex]).copyTo(self) self.icon.setColor(ICON_COLORS[self.deptIndex]) self.icon.setScale(0.07) self.icon.setX(-0.25) icons.removeNode() self.progressBar = DirectWaitBar( parent=self, relief=DirectGuiGlobals.SUNKEN, frameSize=(-1, 1, -0.15, 0.15), borderWidth=(0.02, 0.02), scale=0.20, frameColor=(DisguisePage.DeptColors[self.deptIndex][0] * 0.7, DisguisePage.DeptColors[self.deptIndex][1] * 0.7, DisguisePage.DeptColors[self.deptIndex][2] * 0.7, 1), barColor=(DisguisePage.DeptColors[self.deptIndex][0], DisguisePage.DeptColors[self.deptIndex][1], DisguisePage.DeptColors[self.deptIndex][2], 1), text='0/0 ' + TTLocalizer.RewardPanelMeritBarLabels[self.deptIndex], text_scale=TTLocalizer.RPmeritBarLabels, text_fg=(0, 0, 0, 1), text_align=TextNode.ALeft, text_pos=(-0.96, -0.05)) self.reparentTo(cogMenu) def update(self): if not CogDisguiseGlobals.isSuitComplete(base.localAvatar.cogParts, self.deptIndex): self.progressBar['text'] = '%s %s' % ( CogDisguiseGlobals.getPartCountAsString( base.localAvatar.cogParts, self.deptIndex), TTLocalizer.DisguiseParts) self.progressBar['range'] = CogDisguiseGlobals.PartsPerSuit[ self.deptIndex] self.progressBar['value'] = CogDisguiseGlobals.getPartCount( base.localAvatar.cogParts, self.deptIndex) return promoStatus = base.localAvatar.promotionStatus[self.deptIndex] if promoStatus != ToontownGlobals.PendingPromotion: totalMerits = CogDisguiseGlobals.getTotalMerits( base.localAvatar, self.deptIndex) merits = base.localAvatar.cogMerits[self.deptIndex] self.progressBar['range'] = totalMerits self.progressBar['value'] = merits self.progressBar['text'] = '%s/%s %s' % ( merits, totalMerits, TTLocalizer.RewardPanelMeritBarLabels[self.deptIndex]) else: self.progressBar['range'] = 1 self.progressBar['value'] = 1 maxSuitLevel = (SuitDNA.levelsPerSuit - 1) + (SuitDNA.suitsPerDept - 1) if base.localAvatar.cogLevels[self.deptIndex] == maxSuitLevel: self.progressBar['text'] = TTLocalizer.RewardPanelMeritsMaxed else: self.progressBar[ 'text'] = TTLocalizer.RewardPanelPromotionPending def cleanup(self): self.icon.removeNode() self.progressBar.destroy() self.removeNode()
class Hud(DirectObject): throwExpLbl = None def __init__(self, avatar): self.avatar = avatar self.setupHud() render.setPythonTag("Hud", self) #GlobalDialog(message = "You're a gay idiot.", doneEvent = "sjdkfa", style = 1) def showMessage(self): ImpressBT = Globals.getFont('ImpressBT.ttf') saveTxt = OnscreenText(text='Successfully saved game!', pos=(0.025, 0.5), font=ImpressBT, fg=(1, 0, 0, 1), scale=(0.08, 0.08, 0.08)) base.taskMgr.doMethodLater(0.8, self.removeText, 'Remove Save TXT', extraArgs=[saveTxt], appendTask=True) def removeText(self, text, task): text.removeNode() return Task.done def showWaveInformation(self): round = render.getPythonTag("Round") next_wave = round.getNextWave() icon = None if next_wave.getInvasion() == None: icon = loader.loadModel("phase_3/models/gui/cog_icons.bam").find( '**/cog') else: degrees = [0, 90, 180, 270, 360, -90, -180, -270, -360] icon = Cogs().getCogHead(next_wave.getInvasion().getCogName()) x = -1 for degree in degrees: pass """ head = copy.copy(icon) head.lookAt(0, 280, 0) head.reparentTo(aspect2d) head.setScale(0.2) head.setX(x) x+=0.2 """ #icon.reparentTo(aspect2d) #icon.setScale(0.2) #icon.setPos(0, 20, 0) def setupHud(self): btnSrc = loader.loadModel('phase_3/models/gui/quit_button.bam') ImpressBT = Globals.getFont('ImpressBT.ttf') btnSrcUP = btnSrc.find('**/QuitBtn_UP') btnSrcDN = btnSrc.find('**/QuitBtn_DN') btnSrcRlvr = btnSrc.find('**/QuitBtn_RLVR') DirectButton(clickSound=Globals.getClickSound(), rolloverSound=Globals.getRlvrSound(), geom=(btnSrcUP, btnSrcDN, btnSrcRlvr), relief=None, pos=(1.12, 0, -0.95), command=self.saveGame) OnscreenText(text='Save', pos=(1.12325, -0.97), font=ImpressBT) DirectButton(clickSound=Globals.getClickSound(), rolloverSound=Globals.getRlvrSound(), geom=(btnSrcUP, btnSrcDN, btnSrcRlvr), relief=None, pos=(1.12, 0, -0.85), command=self.spawnCogs) OnscreenText(text='Spawn Cogs', pos=(1.12325, -0.87), font=ImpressBT) self.showWaveInformation() def drawEXPBar(self): self.throwExp = DirectWaitBar( relief=DGG.SUNKEN, frameSize=(-1, 1, -0.15, 0.15), borderWidth=(0.02, 0.02), scale=0.25, frameColor=(Globals.THROW_COLOR[0] * 0.7, Globals.THROW_COLOR[1] * 0.7, Globals.THROW_COLOR[2] * 0.7, 1), barColor=(Globals.THROW_COLOR[0], Globals.THROW_COLOR[1], Globals.THROW_COLOR[2], 1), pos=(0, 0, -0.8)) self.throwExpLbl = OnscreenText(parent=self.throwExp, pos=(0, -0.05), scale=0.18, fg=(0, 0, 0, 1), mayChange=1, align=TextNode.ACenter) def updateEXPBar(self, levelMgr): exp = levelMgr.getEXP() neededEXP = levelMgr.getEXPToNextLevel() level = levelMgr.getLevel() if (self.throwExpLbl == None): self.drawEXPBar() if not neededEXP == 0: value = ((float(exp) / float(neededEXP)) * 100) else: value = 0 self.throwExp.update(value) if (level != levelMgr.getMaxLevel()): self.throwExpLbl.setText("%s/%s" % (exp, neededEXP)) else: self.throwExpLbl.setText("%s/MAX" % (exp)) def spawnCogs(self): render.getPythonTag('Round').startWave() def saveGame(self): self.showMessage() data = Data() data.saveGame()
def __init__(self, quest, parent=aspect2d, **kw): # The quest this poster is representing. self.quest = quest # Let's define our options for the DirectFrame. bookModel = loader.loadModel( 'phase_3.5/models/gui/stickerbook_gui.bam') optiondefs = (('relief', None, None), ('image', bookModel.find('**/questCard'), None), ('image_scale', (0.8, 1.0, 0.58), None), ('state', DGG.NORMAL, None)) self.defineoptions(kw, optiondefs) # Finally, initialize the DirectFrame. DirectFrame.__init__(self, relief=None) self.initialiseoptions(QuestPoster) # Let's declare and initialize our barebone GUI element variables. self.titleLabel = DirectLabel(parent=self, relief=None, text=self.quest.getName(), text_font=CIGlobals.getMinnieFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.05, text_align=TextNode.ACenter, text_wordwrap=25.0, textMayChange=1, pos=(0, 0, 0.23)) ########################################################################## # THE FOLLOWING ELEMENTS BELOW ARE GROUPED TOGETHER # ########################################################################## # The background frame where the objective image is displayed. # This is the colored background frame. self.auxFrame = DirectFrame( parent=self, relief=None, image=bookModel.find('**/questPictureFrame'), image_scale=QuestGlobals.IMAGE_SCALE_SMALL, text='', text_pos=(0, -0.11), text_fg=QuestGlobals.TEXT_COLOR, text_scale=QuestGlobals.QPtextScale, text_align=TextNode.ACenter, text_wordwrap=11.0, pos=QuestGlobals.DEFAULT_LEFT_PICTURE_POS) # The icon that goes on top of the aux frame. self.auxIcon = DirectFrame(parent=self.auxFrame, relief=None, text=' ', text_font=CIGlobals.getSuitFont(), text_pos=(0, -0.03), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.13, text_align=TextNode.ACenter, text_wordwrap=13.0, textMayChange=1) self.auxIcon.setColorOff(-1) # The aux text saying: DEFEAT, RECOVER, etc. self.auxText = DirectLabel(parent=self, relief=None, text=QuestGlobals.RECOVER, text_font=CIGlobals.getToonFont(), text_scale=QuestGlobals.QPauxText, text_fg=QuestGlobals.TEXT_COLOR, text_align=TextNode.ACenter, textMayChange=1, pos=QuestGlobals.DEFAULT_AUX_POS) self.auxText.hide() ########################################################################## # Information displayed about the objective. self.objectiveInfo = DirectLabel( parent=self, relief=None, text='', text_font=CIGlobals.getToonFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.04, text_align=TextNode.ACenter, text_wordwrap=QuestGlobals.QPtextWordwrap, textMayChange=1, pos=(QuestGlobals.DEFAULT_INFO_POS)) self.objectiveInfo.hide() # Information displayed showing the location. self.locationInfo = DirectLabel( parent=self, relief=None, text='N/A', text_font=CIGlobals.getToonFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=QuestGlobals.QPtextScale, text_align=TextNode.ACenter, text_wordwrap=QuestGlobals.QPtextWordwrap, textMayChange=1, pos=(0, 0, -0.115)) self.locationInfo.hide() # The progress bar showing the objective's progress self.progressBar = DirectWaitBar(parent=self, relief=DGG.SUNKEN, frameSize=(-0.95, 0.95, -0.1, 0.12), borderWidth=(0.025, 0.025), scale=0.2, frameColor=(0.945, 0.875, 0.706, 1.0), barColor=(0.5, 0.7, 0.5, 1), text='0/0', text_font=CIGlobals.getToonFont(), text_scale=0.19, text_fg=(0.05, 0.14, 0.4, 1), text_align=TextNode.ACenter, text_pos=(0, -0.05), pos=(0, 0, -0.2425)) self.progressBar.hide() # The wood panel at the bottom where rewards are displayed. rewardFrameGeom = loader.loadModel( 'phase_4/models/gui/gag_shop_purchase_gui.bam') self.rewardFrame = DirectFrame( parent=self, relief=None, geom=rewardFrameGeom.find('**/Goofys_Sign'), geom_scale=(0.615, 0, 0.4), pos=(-0.01, 0, -0.25)) # The text displayed on the right side of the frame with additional information, if necessary. self.sideInfo = DirectLabel(parent=self, relief=None, text=QuestGlobals.JUST_FOR_FUN, text_fg=(0.0, 0.439, 1.0, 1.0), text_shadow=(0, 0, 0, 1), pos=(-0.2825, 0, 0.2), scale=0.03) self.sideInfo.setR(-30) # This side information is usually not needed, let's hide it. self.sideInfo.hide() # Remove the nodes of the loaded models we no longer need. bookModel.removeNode() rewardFrameGeom.removeNode() # Let's hide this until it is needed. self.hide() return
class QuestPoster(DirectFrame): notify = directNotify.newCategory('QuestPoster') # We need to declare and initialize these variables here # because some methods use them as default arguments. auxIcon = None # Requires one parameter, quest, this must be a Quest instance. # The next argument, parent, is where to reparent the DirectFrame to. # The next arguments are simply additional options when setting up the DirectFrame. def __init__(self, quest, parent=aspect2d, **kw): # The quest this poster is representing. self.quest = quest # Let's define our options for the DirectFrame. bookModel = loader.loadModel( 'phase_3.5/models/gui/stickerbook_gui.bam') optiondefs = (('relief', None, None), ('image', bookModel.find('**/questCard'), None), ('image_scale', (0.8, 1.0, 0.58), None), ('state', DGG.NORMAL, None)) self.defineoptions(kw, optiondefs) # Finally, initialize the DirectFrame. DirectFrame.__init__(self, relief=None) self.initialiseoptions(QuestPoster) # Let's declare and initialize our barebone GUI element variables. self.titleLabel = DirectLabel(parent=self, relief=None, text=self.quest.getName(), text_font=CIGlobals.getMinnieFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.05, text_align=TextNode.ACenter, text_wordwrap=25.0, textMayChange=1, pos=(0, 0, 0.23)) ########################################################################## # THE FOLLOWING ELEMENTS BELOW ARE GROUPED TOGETHER # ########################################################################## # The background frame where the objective image is displayed. # This is the colored background frame. self.auxFrame = DirectFrame( parent=self, relief=None, image=bookModel.find('**/questPictureFrame'), image_scale=QuestGlobals.IMAGE_SCALE_SMALL, text='', text_pos=(0, -0.11), text_fg=QuestGlobals.TEXT_COLOR, text_scale=QuestGlobals.QPtextScale, text_align=TextNode.ACenter, text_wordwrap=11.0, pos=QuestGlobals.DEFAULT_LEFT_PICTURE_POS) # The icon that goes on top of the aux frame. self.auxIcon = DirectFrame(parent=self.auxFrame, relief=None, text=' ', text_font=CIGlobals.getSuitFont(), text_pos=(0, -0.03), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.13, text_align=TextNode.ACenter, text_wordwrap=13.0, textMayChange=1) self.auxIcon.setColorOff(-1) # The aux text saying: DEFEAT, RECOVER, etc. self.auxText = DirectLabel(parent=self, relief=None, text=QuestGlobals.RECOVER, text_font=CIGlobals.getToonFont(), text_scale=QuestGlobals.QPauxText, text_fg=QuestGlobals.TEXT_COLOR, text_align=TextNode.ACenter, textMayChange=1, pos=QuestGlobals.DEFAULT_AUX_POS) self.auxText.hide() ########################################################################## # Information displayed about the objective. self.objectiveInfo = DirectLabel( parent=self, relief=None, text='', text_font=CIGlobals.getToonFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=0.04, text_align=TextNode.ACenter, text_wordwrap=QuestGlobals.QPtextWordwrap, textMayChange=1, pos=(QuestGlobals.DEFAULT_INFO_POS)) self.objectiveInfo.hide() # Information displayed showing the location. self.locationInfo = DirectLabel( parent=self, relief=None, text='N/A', text_font=CIGlobals.getToonFont(), text_fg=QuestGlobals.TEXT_COLOR, text_scale=QuestGlobals.QPtextScale, text_align=TextNode.ACenter, text_wordwrap=QuestGlobals.QPtextWordwrap, textMayChange=1, pos=(0, 0, -0.115)) self.locationInfo.hide() # The progress bar showing the objective's progress self.progressBar = DirectWaitBar(parent=self, relief=DGG.SUNKEN, frameSize=(-0.95, 0.95, -0.1, 0.12), borderWidth=(0.025, 0.025), scale=0.2, frameColor=(0.945, 0.875, 0.706, 1.0), barColor=(0.5, 0.7, 0.5, 1), text='0/0', text_font=CIGlobals.getToonFont(), text_scale=0.19, text_fg=(0.05, 0.14, 0.4, 1), text_align=TextNode.ACenter, text_pos=(0, -0.05), pos=(0, 0, -0.2425)) self.progressBar.hide() # The wood panel at the bottom where rewards are displayed. rewardFrameGeom = loader.loadModel( 'phase_4/models/gui/gag_shop_purchase_gui.bam') self.rewardFrame = DirectFrame( parent=self, relief=None, geom=rewardFrameGeom.find('**/Goofys_Sign'), geom_scale=(0.615, 0, 0.4), pos=(-0.01, 0, -0.25)) # The text displayed on the right side of the frame with additional information, if necessary. self.sideInfo = DirectLabel(parent=self, relief=None, text=QuestGlobals.JUST_FOR_FUN, text_fg=(0.0, 0.439, 1.0, 1.0), text_shadow=(0, 0, 0, 1), pos=(-0.2825, 0, 0.2), scale=0.03) self.sideInfo.setR(-30) # This side information is usually not needed, let's hide it. self.sideInfo.hide() # Remove the nodes of the loaded models we no longer need. bookModel.removeNode() rewardFrameGeom.removeNode() # Let's hide this until it is needed. self.hide() return def setup(self): objective = self.quest.currentObjective objective.updateInfo() self.objectiveInfo.show() self.auxFrame.show() self.locationInfo['text'] = QuestGlobals.getLocationText( objective.location) self.locationInfo['text_pos'] = (0, 0 if not QuestGlobals.isShopLocation( objective.location) else 0.025) self.locationInfo.show() # Let's setup the quest progress bar progress = objective.amount if hasattr(objective, 'amount') else None if progress and objective.neededAmount > 0: self.progressBar['range'] = objective.getNeededAmount() self.progressBar['value'] = progress & pow(2, 16) - 1 if objective.__class__ in [ DeliverItemObjective, CogObjective, RecoverItemObjective ]: self.progressBar.show() self.auxText.show() # Let's handle the objectives. if objective.__class__ == CogObjective: self.handleCogObjective() elif objective.__class__ == VisitNPCObjective: self.handleNPCObjective() self.titleLabel.initialiseoptions(DirectLabel) self.auxIcon.initialiseoptions(DirectFrame) self.auxText.initialiseoptions(DirectLabel) self.objectiveInfo.initialiseoptions(DirectLabel) self.locationInfo.initialiseoptions(DirectLabel) self.rewardFrame.initialiseoptions(DirectFrame) self.sideInfo.initialiseoptions(DirectLabel) # Changes geometry and scale of an icon. def handleSimpleIcon(self, geom, scale, icon): icon['geom'] = geom icon['geom_scale'] = scale def handleComplexIcon(self, geom, icon, scale=QuestGlobals.IMAGE_SCALE_SMALL): isHead = True if type(geom) == ToonHead else geom.getName() == ( '%sHead' % CIGlobals.Suit) if isHead: geom.setDepthWrite(1) geom.setDepthTest(1) self.fitGeometry(geom, fFlip=1) self.handleSimpleIcon(geom, scale, icon) # We have to rotate the head and set the scale of the icon. if CIGlobals.Suit in geom.getName(): cogName = geom.getPythonTag('Settings') data = QuestGlobals.Suit2PosterZNDScale.get(cogName) zOffset = data[0] headScale = data[1] icon.setScale(headScale) icon.setZ(icon.getZ() + zOffset) geom.setH(180) else: raise ValueError( 'Tried to use #handleComplexIcon() on a non-complex icon. Use this method for 3D geometry.' ) def handleCogObjective(self, iconElement=auxIcon, auxText=QuestGlobals.DEFEAT, frameColor=QuestGlobals.BLUE): objective = self.quest.currentObjective infoText = objective.getTaskInfo(speech=False) if objective.__class__ == RecoverItemObjective: infoText = QuestGlobals.makePlural(objective.name) print 'Yep' if not iconElement: iconElement = self.auxIcon # Let's make sure we have a current objective that is # an instance of the CogObjective class and this poster isn't destroyed. if not objective or not hasattr(self, 'titleLabel') or not isinstance( objective, CogObjective): return if objective.dept: icons = loader.loadModel('phase_3/models/gui/cog_icons.bam') deptIcon = None if objective.dept == Dept.BOSS: deptIcon = icons.find('**/CorpIcon') else: deptIcon = icons.find('**/%sIcon' % objective.dept.getTie().title()) # Correct the medallion color. deptIcon.setColor(SuitGlobals.medallionColors[objective.dept]) # Setup the icon and remove the icons node. self.handleSimpleIcon(deptIcon, 0.13, iconElement) icons.removeNode() elif not objective.name: # We aren't fighting a Cog in particular. cogIcon = QuestGlobals.getCogIcon() self.handleSimpleIcon(cogIcon, cogIcon.getScale(), iconElement) # We're fighting a Cog in particular. if objective.name: cogHeadInstance = SuitBank.getSuitByName(objective.name).getHead() cogHead = cogHeadInstance.generate() cogHead.setName('%sHead' % CIGlobals.Suit) cogHead.setPythonTag('Settings', cogHeadInstance.head) cogHeadInstance.setScale(2) self.handleComplexIcon(cogHead, iconElement) if not iconElement is self.auxIcon: if hasattr(self, 'goalInfo'): # We're working with the second frame, on the right. # Let's update the information pertaining to this side. self.goalInfo['text'] = infoText self.goalInfo.setPos(QuestGlobals.RECOVER_INFO2_POS) self.auxText.setPos(QuestGlobals.RECOVER_AUX_POS) else: raise AttributeError( 'Attempted to setup DoubleFrame information for poster using default style.' ) else: self.objectiveInfo['text'] = infoText self.auxText['text'] = auxText # Let's set the progress bar text pgBarText = '%d of %d %s' % (objective.amount, objective.neededAmount, QuestGlobals.makePastTense(auxText)) self.progressBar['text'] = pgBarText # Let's set the color of the poster. frame = self.auxFrame if iconElement is self.auxIcon else self.goalFrame frame['image_color'] = Vec4(*frameColor) def handleNPCObjective(self, iconElement=auxIcon, auxText=QuestGlobals.VISIT, frameColor=QuestGlobals.BROWN): objective = self.quest.currentObjective infoText = CIGlobals.NPCToonNames[objective.npcId] if not iconElement: iconElement = self.auxIcon # Let's make sure we have a current objective that is # an instance of the CogObjective class and this poster isn't destroyed. if not objective or not hasattr(self, 'titleLabel') or not isinstance( objective, VisitNPCObjective): return # Let's generate the head. dna = ToonDNA() dna.setDNAStrand(CIGlobals.NPCToonDict.get(objective.npcId)[2]) head = ToonHead(base.cr) head.generateHead(dna.getGender(), dna.getAnimal(), dna.getHead(), forGui=1) head.setHeadColor(dna.getHeadColor()) self.handleComplexIcon(head, iconElement) self.auxText['text'] = auxText if not iconElement is self.auxIcon: if hasattr(self, 'goalInfo'): # We're working with the second frame, on the right. # Let's update the information pertaining to this side. self.goalInfo['text'] = infoText self.goalInfo.setPos(QuestGlobals.RECOVER_INFO2_POS) self.auxText.setPos(QuestGlobals.RECOVER_AUX_POS) self.goalFrame['image_color'] = frameColor else: raise AttributeError( 'Attempted to setup DoubleFrame information for poster using default style.' ) else: self.objectiveInfo['text'] = infoText self.auxFrame['image_color'] = frameColor def fitGeometry(self, geom, fFlip=0, dimension=0.8): p1 = Point3() p2 = Point3() geom.calcTightBounds(p1, p2) if fFlip: t = p1[0] p1.setX(-p2[0]) p2.setX(-t) d = p2 - p1 biggest = max(d[0], d[2]) s = dimension / biggest mid = (p1 + d / 2.0) * s geomXform = hidden.attachNewNode('geomXform') for child in geom.getChildren(): child.reparentTo(geomXform) geomXform.setPosHprScale(-mid[0], -mid[1] + 1, -mid[2], 180, 0, 0, s, s, s) geomXform.reparentTo(geom) def destroy(self): if hasattr(self, 'titleLabel'): self.titleLabel.destroy() self.auxFrame.destroy() self.auxIcon.destroy() self.auxText.destroy() self.objectiveInfo.destroy() self.locationInfo.destroy() self.progressBar.destroy() self.rewardFrame.destroy() self.sideInfo.destroy() del self.titleLabel del self.auxFrame del self.auxIcon del self.auxText del self.objectiveInfo del self.locationInfo del self.progressBar del self.rewardFrame del self.sideInfo DirectFrame.destroy(self) self.notify.debug('Destroyed all elements.')
class App(ShowBase): def __init__(self): ShowBase.__init__(self) self.prop = WindowProperties() self.prop.setSize(1920, 1080) self.prop.setMinimized(False) self.win.requestProperties(self.prop) self.path = os.path.abspath(sys.path[0]) self.path = Filename.fromOsSpecific(self.path).getFullpath() self.fram = DirectFrame(frameColor=(0, 0, 0, 1), frameSize=(-1, 1, -1, 1), pos=(0, 0, 0), image=self.path + "/start.png") self.fram.reparentTo(self.render2d) self.easyAI = DirectButton(text="Easy AI", command=self.easyPlay, pos=(0, 0, 0), scale=0.1, text_bg=(0, 0, 0, 1), text_fg=(255, 255, 255, 1)) self.hardAI = DirectButton(text="Hard AI", command=self.hardPlay, pos=(0, 0, -0.2), scale=0.1, text_bg=(0, 0, 0, 1), text_fg=(255, 255, 255, 1)) self.help = DirectButton(text="Help", command=self.helpScreen, pos=(0, 0, -0.4), scale=0.1, text_bg=(0, 0, 0, 1), text_fg=(255, 255, 255, 1)) def easyPlay(self): self.play(True) def hardPlay(self): self.play(True, True) def helpScreen(self): self.easyAI.hide() self.hardAI.hide() self.help.hide() self.fram["image"] = self.path + "/help.jpg" self.fram.updateFrameStyle() self.back = DirectButton(text="", command=self.helpScreen, pos=(0, 0, -0.4), scale=0.1, text_bg=(0, 0, 0, 1), text_fg=(255, 255, 255, 1)) def back(self): self.hardAI.show() self.easyAI.show() self.help.show() self.back.destroy() self.fram["image"] = self.path + "/start.png" def play(self, ai, difficult=False): self.easyAI.destroy() self.hardAI.destroy() self.ai = None self.cTrav = CollisionTraverser() self.coll = CollisionHandlerEvent() self.coll.addInPattern("%fn-into-%in") self.clock = ClockObject() terrain = GeoMipTerrain("worldTerrain") terrain.setHeightfield("heightMap.png") terrain.setColorMap("colormap.png") terrain.setBruteforce(True) root = terrain.getRoot() root.reparentTo(self.render) root.setSz(1) terrain.generate() self.player = Character("models/panda-model", 0.05, (300, 300, 0), self.render, {"walk": "models/panda-walk4"}, self, self.path, 200, "player") self.addControls() self.loadUI() self.startTasks() self.accept("proj-into-player", self.player.changeLife, [-1]) self.others = dict() self.roundOv = False self.taskMgr.add(self.update, "Update") self.gameOver = False if ai: self.aiBattle(difficult) def startTasks(self): self.taskMgr.add(self.camra, "Cam") self.taskMgr.add(self.manageCollisions, "colls") def loadUI(self): self.lifeBar = DirectWaitBar(text="", value=self.player.life, barColor=(0, 1, 0.25, 1), barBorderWidth=(0.03, 0.03), borderWidth=(0.01, 0.01), frameColor=(0.5, 0.55, 0.70, 1), range=self.player.life, frameSize=(-1.2, 0, 0, -0.1), pos=(0.6, self.a2dLeft, self.a2dBottom + 0.15)) self.lifeBar.setTransparency(1) self.lifeBar.reparentTo(self.render2d) def addControls(self): self.accept("w", self.moveY, [-80]) self.accept("w-up", self.moveY, [0]) self.accept("s", self.moveY, [80]) self.accept("s-up", self.moveY, [0]) self.accept("a", self.moveZ, [5]) self.accept("a-up", self.moveZ, [0]) self.accept("d", self.moveZ, [-5]) self.accept("d-up", self.moveZ, [0]) self.accept("space", self.fire) for abil in self.player.abilities: self.accept(abil.inp, abil.use) def manageCollisions(self, task): self.cTrav.traverse(self.render) self.player.collisions() for a in self.others: self.others[a].collisions() return Task.cont def camra(self, task): self.camera.setPos(self.player.getX(), self.player.getY(), 750) self.camera.setHpr(10, 270, 100) return Task.cont def aiBattle(self, advanced=False): if not advanced: self.ai = AI("models/panda-model", 0.05, (700, 700, 0), self.render, {"walk": "models/panda-walk4"}, self, self.path, 200) else: self.ai = AdvancedAI("models/panda-model", 0.05, (700, 700, 0), self.render, {"walk": "models/panda-walk4"}, self, self.path, 200) self.others["ai"] = self.ai self.aiLifebar = DirectWaitBar(text="", value=self.ai.life, barColor=(0, 1, 0.25, 1), barBorderWidth=(0.003, 0.003), borderWidth=(0.001, 0.001), frameColor=(0.5, 0.55, 0.70, 1), range=self.ai.life, frameSize=(-0.45, 0, 0, -0.1), pos=(1, 0, self.a2dTop - 0.11) ) self.aiLifebar.setTransparency(1) self.aiLifebar.reparentTo(self.render2d) def moveY(self, amount): self.player.moveY(amount) msg = "moved y " + str(amount) + "\n" print("sending: ", msg) server.send(msg.encode()) def moveZ(self, amount): self.player.moveZ(amount) msg = "moved z " + str(amount) + "\n" print("sending: ", msg) server.send(msg.encode()) def fire(self): self.player.fire() msg = "fired\n" print ("sending: ", msg) server.send(msg.encode()) def update(self, task): self.lifeBar['value'] = self.player.currLife self.lifeBar.setValue() if self.ai is not None: self.aiLifebar['value'] = self.ai.currLife self.aiLifebar.setValue() while serverMsg.qsize() > 0: msg = serverMsg.get(False) try: print("received: ", msg, "\n") msg = msg.split() command = msg[0] if command == "myIDis": self.myPID = msg[1] elif command == "newPlayer": n = msg[1] self.others[n] = Character("models/panda-model", 0.05, (300, 300, 0), self.render, {"walk": "models/panda-walk4"}, self, self.path, 200, "play2") self.taskMgr.add(self.others[n].move, "Move" + n) elif command == "moved": PID = msg[1] if msg[2] == "y": self.others[PID].moveY(int(msg[3])) else: self.others[PID].moveZ(int(msg[3])) elif command == "fired": PID = msg[1] self.others[PID].fire() except: print("rip") serverMsg.task_done() return Task.cont