class LoadingScreen(): """Show a directWaitbar to display the current loading state of the application""" def __init__(self): # a fill panel so the player doesn't see how everything # gets loaded in the background self.frameMain = DirectFrame( image="gui/MenuBackground.png", image_scale=(1.7778, 1, 1), #image_pos=(0, 0, 0.25), frameSize=( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor=(0,0,0,0)) self.frameMain.setTransparency(True) self.frameMain.setBin("fixed", 6000) self.frameMain.setDepthWrite(False) self.logo = DirectFrame( image="Logo.png", image_scale=0.25, image_pos=(0, 0, 0.55), frameSize=( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor=(0,0,0,0)) self.logo.reparentTo(self.frameMain) # the text Loading... self.lblLoading = DirectLabel( scale=0.10, pos=(0, 0, -0.15), frameColor=(0, 0, 0, 0), text=_("Loading..."), text_align=TextNode.ACenter, text_fg=(1, 1, 1, 1)) self.lblLoading.reparentTo(self.frameMain) self.stop() def start(self): self.frameMain.show() base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() def stop(self): self.frameMain.hide()
class LaffOMeter(DirectFrame): deathColor = Vec4(0.58039216, 0.80392157, 0.34117647, 1.0) def __init__(self, forRender=False): DirectFrame.__init__(self, relief=None, sortOrder=50, parent=base.a2dBottomLeft) self.initialiseoptions(LaffOMeter) self.container = DirectFrame(parent=self, relief=None) self.container.setBin('gui-popup', 60) if forRender: self.container.setY(0) self.setLightOff() self.setFogOff() self.setMaterialOff() self.hide(CIGlobals.ShadowCameraBitmask) self.forRender = forRender def generate(self, r, g, b, animal, maxHP=50, initialHP=50): self.maxHP = maxHP self.initialHP = initialHP self.color = (r, g, b, 1) gui = loader.loadModel("phase_3/models/gui/laff_o_meter.bam") if animal == "rabbit": animal = "bunny" headmodel = gui.find('**/' + animal + 'head') self.container['image'] = headmodel self.container['image_color'] = self.color if animal == 'monkey': self.setPos(0.153, 0.0, 0.13) else: self.setPos(0.133, 0, 0.13) self.resetFrameSize() self.setScale(0.075) self.frown = DirectFrame(parent=self.container, relief=None, image=gui.find('**/frown')) self.smile = DirectFrame(parent=self.container, relief=None, image=gui.find('**/smile')) self.eyes = DirectFrame(parent=self.container, relief=None, image=gui.find('**/eyes')) self.openSmile = DirectFrame(parent=self.container, relief=None, image=gui.find('**/open_smile')) self.tooth1 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_1')) self.tooth2 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_2')) self.tooth3 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_3')) self.tooth4 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_4')) self.tooth5 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_5')) self.tooth6 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_6')) self.teethList = [ self.tooth6, self.tooth5, self.tooth4, self.tooth3, self.tooth2, self.tooth1 ] if self.forRender: self.container['image_pos'] = (0, 0.01, 0) for tooth in self.teethList: tooth.setDepthWrite(False) self.eyes.setDepthWrite(False) self.smile.setDepthWrite(False) self.openSmile.setDepthWrite(False) self.frown.setDepthWrite(False) self.fractions = [0.0, 0.166666, 0.333333, 0.5, 0.666666, 0.833333] self.currentHealthLbl = DirectLabel(text=str(self.initialHP), parent=self.eyes, pos=(-0.425, 0, 0.05), scale=0.4, relief=None) self.maxHealthLbl = DirectLabel(text=str(self.maxHP), parent=self.eyes, pos=(0.425, 0, 0.05), scale=0.4, relief=None) if self.forRender: self.currentHealthLbl.setY(-0.01) self.maxHealthLbl.setY(-0.01) self.updateMeter(self.initialHP) gui.removeNode() return def start(self): taskMgr.add(self.updateMeterTask, "updateMeterTask") def updateMeterTask(self, task): if hasattr(base, 'localAvatar'): if str(base.localAvatar.getHealth() ) != self.currentHealthLbl['text']: self.updateMeter(base.localAvatar.getHealth()) else: return task.done return task.cont def updateMeter(self, health): self.adjustFace(health) def adjustFace(self, health): self.frown.hide() self.smile.hide() self.openSmile.hide() self.eyes.hide() for tooth in self.teethList: tooth.hide() if health <= 0: self.frown.show() self.container['image_color'] = self.deathColor elif health >= self.maxHP: self.smile.show() self.eyes.show() self.container['image_color'] = self.color else: self.openSmile.show() self.eyes.show() self.maxHealthLbl.show() self.currentHealthLbl.show() self.container['image_color'] = self.color self.adjustTeeth(health) self.animatedEffect(health - self.initialHP) self.adjustText(health) def animatedEffect(self, delta): if delta == 0: return name = 'effect' if delta > 0: ToontownIntervals.start( ToontownIntervals.getPulseLargerIval(self.container, name)) else: ToontownIntervals.start( ToontownIntervals.getPulseSmallerIval(self.container, name)) def adjustTeeth(self, health): for i in xrange(len(self.teethList)): if health > self.maxHP * self.fractions[i]: self.teethList[i].show() else: self.teethList[i].hide() def adjustText(self, health): if self.maxHealthLbl['text'] != str( self.maxHP) or self.currentHealthLbl['text'] != str(health): self.currentHealthLbl['text'] = str(health) def stop(self): taskMgr.remove("updateMeterTask") def disable(self): if not hasattr(self, 'frown'): notify.warning("Won't disable LaffOMeter, no var named frown.") return self.frown.destroy() self.smile.destroy() self.eyes.destroy() self.openSmile.destroy() self.tooth1.destroy() self.tooth2.destroy() self.tooth3.destroy() self.tooth4.destroy() self.tooth5.destroy() self.tooth6.destroy() del self.frown del self.smile del self.eyes del self.openSmile del self.tooth1 del self.tooth2 del self.tooth3 del self.tooth4 del self.tooth5 del self.tooth6 self.container["image"] = None return def delete(self): self.container.destroy() del self.container return
class GuiUnitInfo: def __init__(self, offset, parent, unit_type, default_hp, hp, default_ap, ap): self.offset = offset self.frame = DirectFrame( relief = DGG.FLAT , scale = 1 , frameSize = (-0.5, 0.5, 0, -0.5) , parent = parent ) self.frame.setBillboardPointEye() self.frame.setLightOff() self.frame.setBin("fixed", 40) self.frame.setDepthTest(False) self.frame.setDepthWrite(False) fixedWidthFont = loader.loadFont(GUI_FONT)#@UndefinedVariable #fixedWidthFont.setPixelsPerUnit(60) #fixedWidthFont.setRenderMode(fontt.RMSolid) if not fixedWidthFont.isValid(): print "pandaInteractiveConsole.py :: could not load the defined font %s" % str(self.font) fixedWidthFont = DGG.getDefaultFont() self.label = OnscreenText( parent = self.frame , text = "" , pos = (offset.getX(),offset.getZ()+0.1) , align=TextNode.ACenter , mayChange=True , scale=0.1 , fg = (1,0,0,1) #, shadow = (0, 0, 0, 1) #, frame = (200,0,0,1) ) self.label.setFont( fixedWidthFont ) #self.label.setLightOff() self.all_icons = {} self.visible_icons = {} self.addIcon("overwatch") self.addIcon("set_up") self.ap_bar = DirectWaitBar(parent = self.frame , text = "" , range = default_ap , value = ap , pos = (offset.getX()+0.08,0,offset.getZ()-0.27) , barColor = (0,0,1,1) , frameColor = (0,0,0.5,0.2) , scale = (0.3,0.5,0.3)) self.hp_bar = DirectWaitBar(parent = self.frame , text = "" , range = default_hp , value = hp , pos = (offset.getX()+0.08,0,offset.getZ()-0.2) , barColor = (0,1,0,1) , frameColor = (1,0,0,0.9) , scale = (0.3,0.5,0.3)) self.insignia = OnscreenImage(parent = self.frame ,image = "unit_" + unit_type + "_big_transparent_32.png" #,pos = (offset.getX(),0,offset.getZ()+0.14) , pos = (offset.getX() - 0.31,0,offset.getZ()-0.23) ,scale = 0.09) self.insignia.setTransparency(TransparencyAttrib.MAlpha) def addIcon(self, name): self.all_icons[name] = OnscreenImage(parent = self.frame ,image = name + "_icon.png" #,pos = offset + (0,0,-0.1) ,scale = 0.08) self.all_icons[name].setTransparency(TransparencyAttrib.MAlpha) self.all_icons[name].hide() def write(self, text): text = "" self.label.setText(text) def redraw(self): return def remove(self): self.frame.remove() def reparentTo(self, parent): self.frame.reparentTo(parent) def hide(self): self.label.hide() def show(self): self.label.show() def refreshBars(self, hp, ap): self.ap_bar['value'] = ap self.hp_bar['value'] = hp self.ap_bar.setValue() self.hp_bar.setValue() def refreshIcons(self): count = len(self.visible_icons) start_pos = (1 - count) * 0.25 / 2 for icon in self.all_icons: if icon in self.visible_icons: self.visible_icons[icon].setPos(self.offset + (start_pos, 0, -0.08)) self.visible_icons[icon].show() start_pos += 0.21 else: self.all_icons[icon].hide() def hideOverwatch(self): if "overwatch" in self.visible_icons: self.visible_icons.pop("overwatch") self.refreshIcons() def showOverwatch(self): self.visible_icons["overwatch"] = self.all_icons["overwatch"] self.refreshIcons() def hideSetUp(self): if "set_up" in self.visible_icons: self.visible_icons.pop("set_up") self.refreshIcons() def showSetUp(self): self.visible_icons["set_up"] = self.all_icons["set_up"] self.refreshIcons()