def __init__(self, menu, text, command, parent=None, extra_args=None, pos=(0, 0, 0)): if extra_args is None: extra_args = [] button = DirectButton( text=text, command=command, extraArgs=extra_args, pos=pos, parent=parent, scale=0.1, text_font=menu.default_font, clickSound=loader.loadSfx("resources/sounds/UIClick.ogg"), frameTexture=menu.buttonImages, frameSize=(-4, 4, -1, 1), text_scale=0.75, relief=DGG.FLAT, text_pos=(0, -0.2)) button.setTransparency(True)
def create_stage_button(self,parent,img,btn_text,btn_pos,cmd,level): click_sound = self.blocked hover_sound = self.blocked # This if statement sets the sound that each button will have. # Everything that is not level 1 or level 2 will have the blocked sound effect and will do nothing if level == 'L1' or level == 'L2': click_sound = self.click hover_sound = self.hover btn = DirectButton(parent=parent, text=btn_text, pos=btn_pos, scale=(.2,1,.15), command=cmd, pressEffect=1, text_scale=(.4,.4), text_pos=(.1,.1), text_fg=(.1,.1,.1,1), text_shadow=(1,1,1,1), image=img, image_scale=(1,1,1), image_pos=(0,1,.25), relief=None, rolloverSound = hover_sound, clickSound=click_sound, extraArgs=[level]) btn.setTransparency(TransparencyAttrib.MAlpha)
def createButton(self, text, btnGeom, xPos, command): btn = DirectButton( scale=(0.25, 0.25, 0.25), # some temp text text=text, text_scale=(0.5, 0.5, 0.5), # set the alignment to right text_align=TextNode.ACenter, # put the text on the right side of the button text_pos=(0, -0.15), # set the text color to black text_fg=(1, 1, 1, 1), text_shadow=(0.3, 0.3, 0.1, 1), text_shadowOffset=(0.05, 0.05), # set the buttons images # geom = btnGeom, relief=1, frameColor=(0, 0, 0, 0), pressEffect=False, pos=(xPos, 0, -0.65), command=command, rolloverSound=None, clickSound=None, ) btn.setTransparency(1) return btn
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 createButton(self, text, btnGeom, xPos, command): btn = DirectButton( scale = (0.25, 0.25, 0.25), # some temp text text = text, text_scale = (0.5, 0.5, 0.5), # set the alignment to right text_align = TextNode.ACenter, # put the text on the right side of the button text_pos = (0, -0.15), # set the text color to black text_fg = (1,1,1,1), text_shadow = (0.3, 0.3, 0.1, 1), text_shadowOffset = (0.05, 0.05), # set the buttons images #geom = btnGeom, relief = 1, frameColor = (0,0,0,0), pressEffect = False, pos = (xPos, 0, -0.65), command = command, rolloverSound = None, clickSound = None) btn.setTransparency(1) return btn
def createButton(text, btnGeom, xPos, yPos, args): buttonSize = (-2, 2, 1, -1) btn = DirectButton( scale=0.25, geom=btnGeom, # some temp text text=text, text_scale=0.4, # set the alignment to right text_align=TextNode.ACenter, # set the text color to black text_fg=(1, 1, 1, 1), # set the buttons images relief=1, frameColor=(0,0,0,0), frameSize=buttonSize, pressEffect=False, pos=(xPos, 0, yPos), command=base.messenger.send, extraArgs=args, rolloverSound=None, clickSound=None) # check if the text is to long and resize the frame if necessary if btn.getBounds()[0] < buttonSize[0] or \ btn.getBounds()[1] > buttonSize[1]: btn["frameSize"] = ( btn.getBounds()[0]-0.2, btn.getBounds()[1]+0.2, buttonSize[2], buttonSize[3]) btn.resetFrameSize() btn.setTransparency(True) return btn
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
class KoScreen(DirectObject): def __init__(self): self.frameMain = DirectFrame( frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor = (0, 0, 0, 0.75)) self.frameMain.setTransparency(1) self.lbl_KO = DirectLabel( text = "K.O.", text_fg = (1,1,1,1), scale = 1, pos = (0, 0, 0), frameColor = (0,0,0,0)) self.lbl_KO.setTransparency(1) self.lbl_KO.reparentTo(self.frameMain) self.lbl_PlayerXWon = DirectLabel( text = "PLAYER X WON", text_fg = (1,1,1,1), scale = 0.25, pos = (0, 0, -0.5), frameColor = (0,0,0,0)) self.lbl_PlayerXWon.setTransparency(1) self.lbl_PlayerXWon.reparentTo(self.frameMain) self.btnContinue = DirectButton( text = "CONTINUE", text_fg = (1,1,1,1), scale = 0.1, pad = (0.15, 0.15), pos = (0, 0, -0.8), frameColor = ( (0.2,0.2,0.2,0.8), (0.4,0.4,0.4,0.8), (0.4,0.4,0.4,0.8), (0.1,0.1,0.1,0.8), ), relief = 1, command = base.messenger.send, extraArgs = ["KoScreen-Back"], pressEffect = False, rolloverSound = None, clickSound = None) self.btnContinue.setTransparency(1) self.btnContinue.reparentTo(self.frameMain) self.hide() def show(self, succseedingPlayer): self.frameMain.show() self.lbl_PlayerXWon["text"] = "PLAYER %d WON" % succseedingPlayer def hide(self): self.frameMain.hide()
def createCharacterButton(self, pos, image, charNr): btn = DirectButton(scale=0.1, relief=0, frameColor=(0, 0, 0, 0), pos=pos, image=image, command=self.selectCharacter, extraArgs=[charNr], rolloverSound=None, clickSound=None) btn.setTransparency(1) return btn
def __makeListItem(self, action, event, index): def dummy(): pass if index % 2 == 0: bg = self.listBGEven else: bg = self.listBGOdd item = DirectFrame(text=action, geom=bg, geom_scale=(base.a2dRight - 0.05, 1, 0.1), frameSize=VBase4(base.a2dLeft + 0.05, base.a2dRight - 0.05, -0.05, 0.05), frameColor=VBase4(1, 0, 0, 0), text_align=TextNode.ALeft, text_scale=0.05, text_fg=VBase4(1, 1, 1, 1), text_pos=(base.a2dLeft + 0.3, -0.015), text_shadow=VBase4(0, 0, 0, 0.35), text_shadowOffset=Vec2(-0.05, -0.05), pos=(0.05, 0, -(0.10 * index))) item.setTransparency(True) lbl = DirectLabel( text=event, text_fg=VBase4(1, 1, 1, 1), text_scale=0.05, text_pos=Vec2(0, -0.015), frameColor=VBase4(0, 0, 0, 0), ) lbl.reparentTo(item) lbl.setTransparency(True) self.actionLabels[action] = lbl buttonScale = 0.15 btn = DirectButton(text="Change", geom=self.buttonGeom, scale=buttonScale, text_scale=0.25, text_align=TextNode.ALeft, text_fg=VBase4(0.898, 0.839, 0.730, 1.0), text_pos=Vec2(-0.9, -0.085), relief=1, pad=Vec2(0.01, 0.01), frameColor=VBase4(0, 0, 0, 0), frameSize=VBase4(-1.0, 1.0, -0.25, 0.25), pos=(base.a2dRight - (0.898 * buttonScale + 0.3), 0, 0), pressEffect=False, command=self.changeMapping, extraArgs=[action]) btn.setTransparency(True) btn.reparentTo(item) return item
def createLevelButton(self, pos, image, levelNr): btn = DirectButton(scale=(0.5, 1, 0.75), relief=0, frameColor=(0, 0, 0, 0), pos=pos, image=image, command=self.selectLevel, extraArgs=[levelNr], rolloverSound=None, clickSound=None) btn.setTransparency(1) return btn
def createLevelButton(self, pos, image, levelNr): btn = DirectButton( scale = (0.5, 1, 0.75), relief = 0, frameColor = (0,0,0,0), pos = pos, image = image, command = self.selectLevel, extraArgs = [levelNr], rolloverSound = None, clickSound = None) btn.setTransparency(1) return btn
def createCharacterButton(self, pos, image, charNr): btn = DirectButton( scale = 0.1, relief = 0, frameColor = (0,0,0,0), pos = pos, image = image, command = self.selectCharacter, extraArgs = [charNr], rolloverSound = None, clickSound = None) btn.setTransparency(1) return btn
class KoScreen(DirectObject): def __init__(self): self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0.75)) self.frameMain.setTransparency(1) self.lbl_KO = DirectLabel(text="K.O.", text_fg=(1, 1, 1, 1), scale=1, pos=(0, 0, 0), frameColor=(0, 0, 0, 0)) self.lbl_KO.setTransparency(1) self.lbl_KO.reparentTo(self.frameMain) self.lbl_PlayerXWon = DirectLabel(text="PLAYER X WON", text_fg=(1, 1, 1, 1), scale=0.25, pos=(0, 0, -0.5), frameColor=(0, 0, 0, 0)) self.lbl_PlayerXWon.setTransparency(1) self.lbl_PlayerXWon.reparentTo(self.frameMain) self.btnContinue = DirectButton(text="CONTINUE", text_fg=(1, 1, 1, 1), scale=0.1, pad=(0.15, 0.15), pos=(0, 0, -0.8), frameColor=( (0.2, 0.2, 0.2, 0.8), (0.4, 0.4, 0.4, 0.8), (0.4, 0.4, 0.4, 0.8), (0.1, 0.1, 0.1, 0.8), ), relief=1, command=base.messenger.send, extraArgs=["KoScreen-Back"], pressEffect=False, rolloverSound=None, clickSound=None) self.btnContinue.setTransparency(1) self.btnContinue.reparentTo(self.frameMain) self.hide() def show(self, succseedingPlayer): self.frameMain.show() self.lbl_PlayerXWon["text"] = "PLAYER {} WON".format(succseedingPlayer) def hide(self): self.frameMain.hide()
def __makeListItem(self, action, event, index): def dummy(): pass if index % 2 == 0: bg = self.listBGEven else: bg = self.listBGOdd item = DirectFrame( text=action, geom=bg, geom_scale=(base.a2dRight-0.05, 1, 0.1), frameSize=VBase4(base.a2dLeft+0.05, base.a2dRight-0.05, -0.05, 0.05), frameColor=VBase4(1,0,0,0), text_align=TextNode.ALeft, text_scale=0.05, text_fg=VBase4(1,1,1,1), text_pos=(base.a2dLeft + 0.3, -0.015), text_shadow=VBase4(0, 0, 0, 0.35), text_shadowOffset=Vec2(-0.05, -0.05), pos=(0.05, 0, -(0.10 * index))) item.setTransparency(True) lbl = DirectLabel( text=event, text_fg=VBase4(1, 1, 1, 1), text_scale=0.05, text_pos=Vec2(0, -0.015), frameColor=VBase4(0, 0, 0, 0), ) lbl.reparentTo(item) lbl.setTransparency(True) self.actionLabels[action] = lbl buttonScale = 0.15 btn = DirectButton( text="Change", geom=self.buttonGeom, scale=buttonScale, text_scale=0.25, text_align=TextNode.ALeft, text_fg=VBase4(0.898, 0.839, 0.730, 1.0), text_pos=Vec2(-0.9, -0.085), relief=1, pad=Vec2(0.01, 0.01), frameColor=VBase4(0, 0, 0, 0), frameSize=VBase4(-1.0, 1.0, -0.25, 0.25), pos=(base.a2dRight-(0.898*buttonScale+0.3), 0, 0), pressEffect=False, command=self.changeMapping, extraArgs=[action]) btn.setTransparency(True) btn.reparentTo(item) return item
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 create_menu_button(self,parent,btn_text,btn_pos,cmd): start_btn = DirectButton(parent=parent, text=btn_text, pos=btn_pos, scale=(.2,1,.15), command=cmd, pressEffect=1, text_scale=(.4,.4), text_pos=(.1,.1), text_fg=(.1,.1,.1,1), text_shadow=(1,1,1,1), image='img/btn2.png', image_scale=(2.50,1,.7), image_pos=(0,1,.25), relief=None, rolloverSound = self.hover, clickSound=self.click) start_btn.setTransparency(TransparencyAttrib.MAlpha)
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 createButton(self, verticalPos, eventArgs): maps = loader.loadModel("gui/button_map") btnGeom = (maps.find("**/btn_ready"), maps.find("**/btn_click"), maps.find("**/btn_rollover"), maps.find("**/btn_disabled")) btn = DirectButton(text="apply", text_fg=(1, 1, 1, 1), text_scale=0.05, text_pos=(0.15, -0.013), text_align=TextNode.ALeft, scale=2, geom=btnGeom, pos=(base.a2dRight - 0.7, 0, verticalPos), relief=0, frameColor=(1, 1, 1, 1), command=self.testPlay, extraArgs=[ eventArgs, ], pressEffect=True, rolloverSound=None) btn.reparentTo(self.frameOption) btn.setTransparency(1) return btn
class Highscore(): def __init__(self): home = os.path.expanduser("~") quickJNRDir = os.path.join(home, ".quickShooter") if not os.path.exists(quickJNRDir): os.makedirs(quickJNRDir) self.highscorefile = os.path.join(quickJNRDir, "highscore.txt") self.highscore = [] if not os.path.exists(self.highscorefile): with open(self.highscorefile, "w") as f: f.write("""Foxy;4000 Wolf;3500 Coon;3000 Kitty;2020 Ferret;2000 Lynx;1700 Lion;1280 Tiger;800 Birdy;450 Fishy;250""") with open(self.highscorefile, "r+") as f: data = f.readlines() for line in data: name = line.split(";")[0] pts = line.split(";")[1] self.highscore.append([name, pts]) self.lstHighscore = DirectScrolledList( frameSize = (-1, 1, -0.6, 0.6), frameColor = (0,0,0,0.5), pos = (0, 0, 0), numItemsVisible = 10, itemMakeFunction = self.__makeListItem, itemFrame_frameSize = (-0.9, 0.9, 0.0, -1), itemFrame_color = (1, 1, 1, 0), itemFrame_pos = (0, 0, 0.5)) self.btnBack = DirectButton( # size of the button scale = (0.15, 0.15, 0.15), text = "Back", # set no relief relief = None, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0.2, 0, 0.1), # the event which is thrown on clickSound command = self.btnBack_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(base.a2dBottomLeft) self.refreshList() self.hide() def show(self): self.lstHighscore.show() self.btnBack.show() def hide(self): self.lstHighscore.hide() self.btnBack.hide() def writeHighscore(self): self.__sortHigscore() with open(self.highscorefile, "w") as f: for entry in self.highscore: f.write("{0};{1}".format(entry[0], entry[1])) def refreshList(self): self.__sortHigscore() self.lstHighscore.removeAllItems() for entry in self.highscore: self.lstHighscore.addItem("{0};{1}".format(entry[0], entry[1])) def __makeListItem(self, highscoreItem, stuff, morestuff): name = highscoreItem.split(";")[0] pts = highscoreItem.split(";")[1] # left l = -0.9 # right r = 0.9 itemFrame = DirectFrame( frameColor=(1, 1, 1, 0.5), frameSize=(l, r, -0.1, 0), relief=DGG.SUNKEN, borderWidth=(0.01, 0.01), pos=(0, 0, 0)) lblName = DirectLabel( pos=(l + 0.01, 0, -0.07), text=name, text_align=TextNode.ALeft, scale=0.07, frameColor=(0, 0, 0, 0)) lblPts = DirectLabel( pos=(r - 0.01, 0, -0.07), text=pts, text_align=TextNode.ARight, scale=0.07, frameColor=(0, 0, 0, 0)) lblName.reparentTo(itemFrame) lblPts.reparentTo(itemFrame) return itemFrame def __sortHigscore(self): self.highscore = sorted( self.highscore, key=lambda score: int(score[1]), reverse=True)[:10] def setPoints(self, name, points): self.highscore.append([name, str(points) + "\n"]) self.refreshList() self.writeHighscore() def btnBack_Click(self): self.hide() base.messenger.send("Highscore_back")
def _show_credits(self): """Show the game credits.""" clear_wids(self.save_wids) clear_wids(self.conf_wids) clear_wids(self.tactics_wids) center = 0.25 self.cred_wids.append( DirectLabel( parent=self._main_fr, pos=(center, 0, 0.6), text_scale=0.04, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[31], # noqa: F821 )) self.cred_wids.append( DirectLabel( # Project source code parent=self._main_fr, pos=(center, 0, 0.5), text_scale=0.04, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[32], # noqa: F821 )) self.cred_wids.append( DirectButton( parent=self._main_fr, pos=(center, 0, 0.45), frameColor=(0, 0, 0, 0), text_scale=0.04, text_fg=RUST_COL, text="github.com/IlyaFaer/ForwardOnlyGame", text_font=base.main_font, # noqa: F821 relief=None, command=webbrowser.open, extraArgs=["https://github.com/IlyaFaer/ForwardOnlyGame"], clickSound=self.click_snd, )) self.cred_wids.append( DirectLabel( # Subscribe parent=self._main_fr, pos=(center, 0, 0.35), text_scale=0.04, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[33], # noqa: F821 )) self.cred_wids.append( DirectButton( parent=self._main_fr, pos=(0.11, 0, 0.29), frameTexture="credits/youtube.png", frameSize=(-0.056, 0.056, -0.029, 0.029), relief="flat", command=webbrowser.open, extraArgs=[ "https://www.youtube.com/channel/UCKmtk9K6VkcQdOMiE7H-W9w" ], clickSound=self.click_snd, )) self.cred_wids.append( DirectButton( parent=self._main_fr, pos=(center, 0, 0.29), frameTexture="credits/indie_db.png", frameSize=(-0.058, 0.058, -0.029, 0.029), relief="flat", command=webbrowser.open, extraArgs=["https://www.indiedb.com/games/forward-only"], clickSound=self.click_snd, )) but = DirectButton( parent=self._main_fr, pos=(0.38, 0, 0.29), frameTexture="credits/discord.png", frameSize=(-0.045, 0.045, -0.045, 0.045), relief="flat", command=webbrowser.open, extraArgs=["https://discord.gg/8UgFJAWsFx"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( # Stack parent=self._main_fr, pos=(center, 0, 0.18), text_scale=0.04, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[34], # noqa: F821 )) but = DirectButton( parent=self._main_fr, pos=(0.05, 0, 0.11), frameTexture="credits/python.png", frameSize=(-0.05, 0.05, -0.05, 0.05), relief="flat", command=webbrowser.open, extraArgs=["https://www.python.org/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) but = DirectButton( parent=self._main_fr, pos=(0.185, 0, 0.11), frameTexture="credits/panda3d.png", frameSize=(-0.05, 0.05, -0.05, 0.05), relief="flat", command=webbrowser.open, extraArgs=["https://www.panda3d.org/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) but = DirectButton( parent=self._main_fr, pos=(0.315, 0, 0.11), frameTexture="credits/blender.png", frameSize=(-0.05, 0.05, -0.05, 0.05), relief="flat", command=webbrowser.open, extraArgs=["https://www.blender.org/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) but = DirectButton( parent=self._main_fr, pos=(0.45, 0, 0.11), frameTexture="credits/make_human.png", frameSize=(-0.05, 0.05, -0.05, 0.05), relief="flat", command=webbrowser.open, extraArgs=["http://www.makehumancommunity.org/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( # Tools parent=self._main_fr, pos=(center, 0, -0.02), text_scale=0.04, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[35], # noqa: F821 )) but = DirectButton( parent=self._main_fr, pos=(center - 0.12, 0, -0.09), frameTexture="credits/free_sound.png", frameSize=(-0.057, 0.057, -0.029, 0.029), relief="flat", command=webbrowser.open, extraArgs=["https://freesound.org/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) but = DirectButton( parent=self._main_fr, pos=(center, 0, -0.09), frameTexture="credits/photopea.png", frameSize=(-0.03, 0.03, -0.03, 0.03), relief="flat", command=webbrowser.open, extraArgs=["https://www.photopea.com/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) but = DirectButton( parent=self._main_fr, pos=(center + 0.09, 0, -0.09), frameTexture="credits/online_convert.png", frameSize=(-0.03, 0.03, -0.03, 0.03), relief="flat", command=webbrowser.open, extraArgs=["https://audio.online-convert.com/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( # Music parent=self._main_fr, pos=(center, 0, -0.24), text_scale=0.042, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text=base.labels.MAIN_MENU[39], # noqa: F821 )) but = DirectButton( parent=self._main_fr, pos=(-0.15, 0, -0.45), frameTexture="credits/among_madness_logo.png", frameSize=(-0.15, 0.15, -0.15, 0.15), relief="flat", command=webbrowser.open, extraArgs=[ "https://open.spotify.com/artist/3uy4tvaLvBAsKdV52Kc2TI" ], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( parent=self._main_fr, pos=(-0.15, 0, -0.65), text_scale=0.033, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text="Among Madness", )) but = DirectButton( parent=self._main_fr, pos=(0.25, 0, -0.45), frameTexture="credits/qualia_logo.png", frameSize=(-0.15, 0.15, -0.15, 0.15), relief="flat", command=webbrowser.open, extraArgs=["https://kvalia.net/"], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( parent=self._main_fr, pos=(0.25, 0, -0.65), text_scale=0.033, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text="Квалиа", )) but = DirectButton( parent=self._main_fr, pos=(0.65, 0, -0.45), frameTexture="credits/moloken_logo.png", frameSize=(-0.15, 0.15, -0.15, 0.15), relief="flat", command=webbrowser.open, extraArgs=[ "https://open.spotify.com/artist/3LZzdqKCEcBwhh6vd6y6Q5" ], clickSound=self.click_snd, ) but.setTransparency(TransparencyAttrib.MAlpha) self.cred_wids.append(but) self.cred_wids.append( DirectLabel( parent=self._main_fr, pos=(0.65, 0, -0.65), text_scale=0.033, text_fg=SILVER_COL, text_font=base.main_font, # noqa: F821 frameColor=(0, 0, 0, 0), text="Moloken", ))
class CharacterSelection: def __init__(self): self.frameMain = DirectFrame( frameSize = (base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor = (0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) width = abs(base.a2dLeft) + base.a2dRight red = loader.loadTexture("assets/gui/CharRedBG.png") red.setWrapU(Texture.WM_repeat) red.setWrapV(Texture.WM_repeat) self.char1Frame = DirectFrame( text = "Player 1", text_fg = (1,1,1,1), text_scale = 0.1, text_pos = (0, base.a2dTop - 0.2), frameSize = (-width/6.0, width/6.0, base.a2dBottom, base.a2dTop), frameTexture = red, pos = (base.a2dLeft+width/6.0, 0, 0)) self.char1Frame.updateFrameStyle() self.char1Frame.setTransparency(1) self.char1Frame.reparentTo(self.frameMain) blue = loader.loadTexture("assets/gui/CharBlueBG.png") blue.setWrapU(Texture.WM_repeat) blue.setWrapV(Texture.WM_repeat) self.char2Frame = DirectFrame( text = "Player 2", text_fg = (1,1,1,1), text_scale = 0.1, text_pos = (0, base.a2dTop - 0.2), frameSize = (-width/6.0, width/6.0, base.a2dBottom, base.a2dTop), frameTexture = blue, pos = (base.a2dRight-width/6.0, 0, 0)) self.char2Frame.setTransparency(1) self.char2Frame.reparentTo(self.frameMain) self.footerFrame = DirectFrame( text = "PLAYER 1 - CHOOSE YOUR CHARACTER", text_fg = (1,1,1,1), text_scale = 0.08, text_pos = (0, -0.03), frameSize = (base.a2dLeft, base.a2dRight, 0.1, -0.1), pos = (0, 0, base.a2dBottom + 0.2), frameColor = (0, 0, 0, 0.5)) self.footerFrame.setTransparency(1) self.footerFrame.reparentTo(self.frameMain) self.charSelectFrame = DirectFrame( text = "VS", text_fg = (1,1,1,1), text_scale = 0.1, text_pos = (0, base.a2dTop - 0.2), frameSize = (-width/6.0, width/6.0, base.a2dBottom, base.a2dTop), frameColor = (0,0,0,0)) self.charSelectFrame.reparentTo(self.frameMain) self.btnChar1 = self.createCharacterButton( (-0.2, 0, 0), "assets/gui/Char1Button.png", 1) self.btnChar1.reparentTo(self.charSelectFrame) self.btnChar2 = self.createCharacterButton( (0.2, 0, 0), "assets/gui/Char2Button.png", 2) self.btnChar2.reparentTo(self.charSelectFrame) self.btnBack = DirectButton( text = "BACK", text_fg = (1,1,1,1), text_align = TextNode.ALeft, scale = 0.1, pad = (0.15, 0.15), pos = (base.a2dLeft + 0.08, 0, -0.03), frameColor = ( (0.2,0.2,0.2,0.8), (0.4,0.4,0.4,0.8), (0.4,0.4,0.4,0.8), (0.1,0.1,0.1,0.8)), relief = 1, command = base.messenger.send, extraArgs = ["CharSelection-Back"], pressEffect = False, rolloverSound = None, clickSound = None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.footerFrame) self.btnStart = DirectButton( text = "START", text_fg = (1,1,1,1), text_align = TextNode.ARight, scale = 0.1, pad = (0.15, 0.15), pos = (base.a2dRight - 0.08, 0, -0.03), relief = 1, frameColor = ( (0.2,0.2,0.2,0.8), (0.4,0.4,0.4,0.8), (0.4,0.4,0.4,0.8), (0.1,0.1,0.1,0.8)), command = base.messenger.send, extraArgs = ["CharSelection-Start"], pressEffect = False, rolloverSound = None, clickSound = None) self.btnStart.setTransparency(1) self.btnStart.reparentTo(self.footerFrame) self.btnStart["state"] = DGG.DISABLED self.hide() def createCharacterButton(self, pos, image, charNr): btn = DirectButton( scale = 0.1, relief = 0, frameColor = (0,0,0,0), pos = pos, image = image, command = self.selectCharacter, extraArgs = [charNr], rolloverSound = None, clickSound = None) btn.setTransparency(1) return btn def selectCharacter(self, charNr): if self.char1Frame["image"] == None: self.char1Frame["image"] = "assets/gui/Char{}_L.png".format(charNr) self.char1Frame["image_scale"] = (0.5,1, 1) self.selectedCharacter1 = charNr self.footerFrame["text"] = "PLAYER 2 - CHOOSE YOUR CHARACTER" elif self.char2Frame["image"] == None: self.char2Frame["image"] = "assets/gui/Char{}_R.png".format(charNr) self.char2Frame["image_scale"] = (0.5,1, 1) self.selectedCharacter2 = charNr self.btnStart["state"] = DGG.NORMAL self.footerFrame["text"] = "START THE FIGHT >" def show(self): self.selectedCharacter1 = None self.selectedCharacter2 = None self.char1Frame["image"] = None self.char2Frame["image"] = None self.footerFrame["text"] = "PLAYER 1 - CHOOSE YOUR CHARACTER" self.btnStart["state"] = DGG.DISABLED self.frameMain.show() def hide(self): self.frameMain.hide()
class DirectWindow(DirectFrame): def __init__( self, pos=(-.5, .5), title='Title', curSize=(1, 1), maxSize=(1, 1), minSize=(.5, .5), backgroundColor=(1, 1, 1, 1), borderColor=(1, 1, 1, 1), titleColor=(1, 1, 1, 1), borderSize=0.04, titleSize=0.06, closeButton=False, windowParent=aspect2d, preserve=True, preserveWhole=True, ): self.preserve = preserve self.preserveWhole = preserveWhole self.windowParent = windowParent self.windowPos = pos DirectFrame.__init__( self, parent=windowParent, pos=(self.windowPos[0], 0, self.windowPos[1]), frameColor=(0, 0, 0, 0), frameTexture=loader.loadTexture(DIRECTORY + 'transparent.png')) self.setTransparency(True) # the title part of the window, drag around to move the window self.headerHeight = titleSize h = -self.headerHeight self.windowHeaderLeft = DirectButton( parent=self, frameTexture=DEFAULT_TITLE_GEOM_LEFT, frameSize=(-.5, .5, -.5, .5), borderWidth=(0, 0), relief=DGG.FLAT, frameColor=titleColor, ) self.windowHeaderCenter = DirectButton( parent=self, frameTexture=DEFAULT_TITLE_GEOM_CENTER, frameSize=(-.5, .5, -.5, .5), borderWidth=(0, 0), relief=DGG.FLAT, frameColor=titleColor, ) if closeButton: rightTitleGeom = DEFAULT_TITLE_GEOM_RIGHT_CLOSE command = self.destroy else: rightTitleGeom = DEFAULT_TITLE_GEOM_RIGHT command = None self.windowHeaderRight = DirectButton(parent=self, frameTexture=rightTitleGeom, frameSize=(-.5, .5, -.5, .5), borderWidth=(0, 0), relief=DGG.FLAT, frameColor=titleColor, command=command) self.windowHeaderLeft.setTransparency(True) self.windowHeaderCenter.setTransparency(True) self.windowHeaderRight.setTransparency(True) self.windowHeaderLeft.bind(DGG.B1PRESS, self.startWindowDrag) self.windowHeaderCenter.bind(DGG.B1PRESS, self.startWindowDrag) self.windowHeaderRight.bind(DGG.B1PRESS, self.startWindowDrag) # this is not handled correctly, if a window is dragged which has been # created before another it will not be released # check the bugfixed startWindowDrag function #self.windowHeader.bind(DGG.B1RELEASE,self.stopWindowDrag) text = TextNode('WindowTitleTextNode') text.setText(title) text.setAlign(TextNode.ACenter) text.setTextColor(0, 0, 0, 1) text.setShadow(0.05, 0.05) text.setShadowColor(1, 1, 1, 1) self.textNodePath = self.attachNewNode(text) self.textNodePath.setScale(self.headerHeight * 0.8) # the content part of the window, put stuff beneath # contentWindow.getCanvas() to put it into it self.maxVirtualSize = maxSize self.minVirtualSize = minSize self.resizeSize = borderSize self.contentWindow = DirectScrolledFrame( parent=self, pos=(0, 0, -self.headerHeight), canvasSize=(0, self.maxVirtualSize[0], 0, self.maxVirtualSize[1]), frameColor=( 0, 0, 0, 0), # defines the background color of the resize-button relief=DGG.FLAT, borderWidth=(0, 0), verticalScroll_frameSize=[0, self.resizeSize, 0, 1], horizontalScroll_frameSize=[0, 1, 0, self.resizeSize], # resize the scrollbar according to window size verticalScroll_resizeThumb=False, horizontalScroll_resizeThumb=False, # define the textures for the scrollbars verticalScroll_frameTexture=VERTICALSCROLL_FRAMETEXTURE, verticalScroll_incButton_frameTexture= VERTICALSCROLL_INCBUTTON_FRAMETEXTURE, verticalScroll_decButton_frameTexture= VERTICALSCROLL_DECBUTTON_FRAMETEXTURE, verticalScroll_thumb_frameTexture=VERTICALSCROLL_TUMB_FRAMETEXTURE, horizontalScroll_frameTexture=HORIZONTALSCROLL_FRAMETEXTURE, horizontalScroll_incButton_frameTexture= HORIZONTALSCROLL_INCBUTTON_FRAMETEXTURE, horizontalScroll_decButton_frameTexture= HORIZONTALSCROLL_DECBUTTON_FRAMETEXTURE, horizontalScroll_thumb_frameTexture= HORIZONTALSCROLL_TUMB_FRAMETEXTURE, # make all flat, so the texture is as we want it verticalScroll_relief=DGG.FLAT, verticalScroll_thumb_relief=DGG.FLAT, verticalScroll_decButton_relief=DGG.FLAT, verticalScroll_incButton_relief=DGG.FLAT, horizontalScroll_relief=DGG.FLAT, horizontalScroll_thumb_relief=DGG.FLAT, horizontalScroll_decButton_relief=DGG.FLAT, horizontalScroll_incButton_relief=DGG.FLAT, # colors verticalScroll_frameColor=borderColor, verticalScroll_incButton_frameColor=borderColor, verticalScroll_decButton_frameColor=borderColor, verticalScroll_thumb_frameColor=borderColor, horizontalScroll_frameColor=borderColor, horizontalScroll_incButton_frameColor=borderColor, horizontalScroll_decButton_frameColor=borderColor, horizontalScroll_thumb_frameColor=borderColor, ) self.contentWindow.setTransparency(True) # background color self.backgroundColor = DirectFrame( parent=self.contentWindow.getCanvas(), frameSize=(0, self.maxVirtualSize[0], 0, self.maxVirtualSize[1]), frameColor=backgroundColor, relief=DGG.FLAT, borderWidth=(.01, .01), ) self.backgroundColor.setTransparency(True) # Add a box self.box = boxes.VBox(parent=self.getCanvas()) # is needed for some nicer visuals of the resize button (background) self.windowResizeBackground = DirectButton( parent=self, frameSize=(-.5, .5, -.5, .5), borderWidth=(0, 0), scale=(self.resizeSize, 1, self.resizeSize), relief=DGG.FLAT, frameColor=backgroundColor, ) # the resize button of the window self.windowResize = DirectButton( parent=self, frameSize=(-.5, .5, -.5, .5), borderWidth=(0, 0), scale=(self.resizeSize, 1, self.resizeSize), relief=DGG.FLAT, frameTexture=DEFAULT_RESIZE_GEOM, frameColor=borderColor, ) self.windowResize.setTransparency(True) self.windowResize.bind(DGG.B1PRESS, self.startResizeDrag) self.windowResize.bind(DGG.B1RELEASE, self.stopResizeDrag) # offset then clicking on the resize button from the mouse to the resizebutton # position, required to calculate the position / scaling self.offset = None self.taskName = "resizeTask-%s" % str(hash(self)) # do sizing of the window (minimum) #self.resize( Vec3(0,0,0), Vec3(0,0,0) ) # maximum #self.resize( Vec3(100,0,-100), Vec3(0,0,0) ) self.resize(Vec3(curSize[0], 0, -curSize[1]), Vec3(0, 0, 0)) def getCanvas(self): return self.contentWindow.getCanvas() # dragging functions def startWindowDrag(self, param): self.wrtReparentTo(aspect2dMouseNode) self.ignoreAll() self.accept('mouse1-up', self.stopWindowDrag) def stopWindowDrag(self, param=None): # this is called 2 times (bug), so make sure it's not already parented to aspect2d if self.getParent() != self.windowParent: self.wrtReparentTo(self.windowParent) if self.preserve: if self.preserveWhole: if self.getZ() > 1: self.setZ(1) elif self.getZ() < -1 - self.getHeight(): self.setZ(-1 - self.getHeight()) if self.getX() > base.a2dRight - self.getWidth(): self.setX(base.a2dRight - self.getWidth()) elif self.getX() < base.a2dLeft: self.setX(base.a2dLeft) else: if self.getZ() > 1: self.setZ(1) elif self.getZ() < -1 + self.headerHeight: self.setZ(-1 + self.headerHeight) if self.getX() > base.a2dRight - self.headerHeight: self.setX(base.a2dRight - self.headerHeight) elif self.getX( ) < base.a2dLeft + self.headerHeight - self.getWidth(): self.setX(base.a2dLeft + self.headerHeight - self.getWidth()) #else: #Window moved beyond reach. Destroy window? # resize functions def resize(self, mPos, offset): mXPos = max(min(mPos.getX(), self.maxVirtualSize[0]), self.minVirtualSize[0]) mZPos = max(min(mPos.getZ(), -self.minVirtualSize[1]), -self.maxVirtualSize[1] - self.headerHeight) self.windowResize.setPos(mXPos - self.resizeSize / 2., 0, mZPos + self.resizeSize / 2.) self.windowResizeBackground.setPos(mXPos - self.resizeSize / 2., 0, mZPos + self.resizeSize / 2.) self['frameSize'] = (0, mXPos, 0, mZPos) self.windowHeaderLeft.setPos(self.headerHeight / 2., 0, -self.headerHeight / 2.) self.windowHeaderLeft.setScale(self.headerHeight, 1, self.headerHeight) self.windowHeaderCenter.setPos(mXPos / 2., 0, -self.headerHeight / 2.) self.windowHeaderCenter.setScale(mXPos - self.headerHeight * 2., 1, self.headerHeight) self.windowHeaderRight.setPos(mXPos - self.headerHeight / 2., 0, -self.headerHeight / 2.) self.windowHeaderRight.setScale(self.headerHeight, 1, self.headerHeight) self.contentWindow['frameSize'] = (0, mXPos, mZPos + self.headerHeight, 0) self.textNodePath.setPos(mXPos / 2., 0, -self.headerHeight / 3. * 2.) # show and hide that small background for the window sizer if mXPos == self.maxVirtualSize[0] and \ mZPos == -self.maxVirtualSize[1]-self.headerHeight: self.windowResizeBackground.hide() else: self.windowResizeBackground.show() def resizeTask(self, task=None): mPos = aspect2dMouseNode.getPos(self) + self.offset self.resize(mPos, self.offset) return task.cont def startResizeDrag(self, param): self.offset = self.windowResize.getPos(aspect2dMouseNode) taskMgr.remove(self.taskName) taskMgr.add(self.resizeTask, self.taskName) def stopResizeDrag(self, param): taskMgr.remove(self.taskName) # get the window to the front self.wrtReparentTo(self.windowParent) def addHorizontal(self, widgets): """ Accepts a list of directgui objects which are added to a horizontal box, which is then added to the vertical stack. """ hbox = boxes.HBox() for widget in widgets: hbox.pack(widget) self.box.pack(hbox) self.updateMaxSize() def addVertical(self, widgets): """ Accepts a list of directgui objects which are added to a vertical box, which is then added to the vertical stack. May cause funky layout results. """ #vbox = boxes.VBox() for widget in widgets: self.box.pack(widget) self.updateMaxSize() def add(self, widgets): """Shortcut function for addVertical""" self.addVertical(widgets) def updateMaxSize(self): """Updates the max canvas size to include all items packed. Window is resized to show all contents.""" bottomLeft, topRight = self.box.getTightBounds() self.maxVirtualSize = (topRight[0], -bottomLeft[2]) self.contentWindow['canvasSize'] = (0, self.maxVirtualSize[0], -self.maxVirtualSize[1], 0) self.backgroundColor['frameSize'] = (0, self.maxVirtualSize[0], -self.maxVirtualSize[1], 0) #perhaps this should be optional -- automatically resize for new elements self.reset() def reset(self): """Poorly named function that resizes window to fit all contents""" self.resize( Vec3(self.maxVirtualSize[0], 0, -self.maxVirtualSize[1] - self.headerHeight), Vec3(0, 0, 0))
class HostMenu(DirectObject): def __init__(self): self.defaultBtnMap = base.loader.loadModel("gui/button_map") self.buttonGeom = (self.defaultBtnMap.find("**/button_ready"), self.defaultBtnMap.find("**/button_click"), self.defaultBtnMap.find("**/button_rollover"), self.defaultBtnMap.find("**/button_disabled")) defaultFont = loader.loadFont('gui/eufm10.ttf') self.logFrame = DirectScrolledFrame( canvasSize=(0, base.a2dRight * 2, -5, 0), frameSize=(0, base.a2dRight * 2, (base.a2dBottom + .2) * 2, 0), frameColor=(0.1, 0.1, 0.1, 1)) self.logFrame.reparentTo(base.a2dTopLeft) # create the info and server debug output self.textscale = 0.1 self.txtinfo = OnscreenText(scale=self.textscale, pos=(0.1, -0.1), text="", align=TextNode.ALeft, fg=(0.1, 1.0, 0.15, 1), bg=(0, 0, 0, 0), shadow=(0, 0, 0, 1), shadowOffset=(-0.02, -0.02)) self.txtinfo.setTransparency(1) self.txtinfo.reparentTo(self.logFrame.getCanvas()) # create a close Server button self.btnBackPos = Vec3(0.4, 0, 0.2) self.btnBackScale = 0.25 self.btnBack = DirectButton( # Scale and position scale=self.btnBackScale, pos=self.btnBackPos, # Text text="Quit Server", text_scale=0.45, text_pos=(0, -0.1), text_fg=(0.82, 0.85, 0.87, 1), text_shadow=(0, 0, 0, 1), text_shadowOffset=(-0.02, -0.02), text_font=defaultFont, # Frame geom=self.buttonGeom, frameColor=(0, 0, 0, 0), relief=0, pressEffect=False, # Functionality command=self.back, rolloverSound=None, clickSound=None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(base.a2dBottomLeft) # catch window resizes and recalculate the aspectration self.accept("window-event", self.recalcAspectRatio) self.accept("addLog", self.addLog) def show(self): self.logFrame.show() self.btnBack.show() def hide(self): self.logFrame.hide() self.btnBack.hide() def back(self): self.hide() base.messenger.send("stop_server") self.addLog("Quit Server!") def addLog(self, text): self.txtinfo.appendText(text + "\n") textbounds = self.txtinfo.getTightBounds() self.logFrame["canvasSize"] = (0, textbounds[1].getX(), textbounds[0].getZ(), 0) def recalcAspectRatio(self, window): """get the new aspect ratio to resize the mainframe""" # set the mainframe size to the window borders again self.logFrame["frameSize"] = (0, base.a2dRight * 2, (base.a2dBottom + .2) * 2, 0)
class MainMenu(): def __init__(self): self.frameMain = DirectFrame(image="mainmenu.png", image_scale=(1.7778, 1, 1), frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.frameMain.setTransparency(True) self.btnStart = DirectButton( text="Enter", scale=0.15, text_pos=(0, 1.1), text_scale=0.5, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), frameColor=(0, 0, 0, 0), image=("btnEnter.png", "btnEnter_hover.png", "btnEnter_hover.png", "btnEnter_hover.png"), pos=(0, 0, -0.3), command=base.messenger.send, extraArgs=["menu_StartGame"]) self.btnStart.setTransparency(True) self.btnStart.reparentTo(self.frameMain) self.btnOptions = DirectButton(text="Options", scale=0.1, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), frameColor=(0, 0, 0, 0), image=("settings.png"), image_scale=1.2, text_pos=(0, -0.2), pos=(base.a2dRight - 0.3, 0, base.a2dBottom + 0.25), command=base.messenger.send, extraArgs=["menu_Options"]) self.btnOptions.setTransparency(True) self.btnOptions.reparentTo(self.frameMain) self.btnQuit = DirectButton( text="Exit", scale=0.15, text_pos=(-0.3, -0.25), text_scale=0.75, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), frameColor=(0, 0, 0, 0), image=("btnExit.png", "btnExit_hover.png", "btnExit_hover.png", "btnExit_hover.png"), image_scale=(1, 1, 0.5), pos=(base.a2dLeft + 0.3, 0, base.a2dBottom + 0.25), command=base.messenger.send, extraArgs=["menu_QuitGame"]) self.btnQuit.setTransparency(True) self.btnQuit.reparentTo(self.frameMain) self.imgBouncer = OnscreenImage(image="bouncer.png", scale=(0.75 * 0.25, 1 * 0.25, 1 * 0.25), pos=(-0.25, 0, -0.3)) self.imgBouncer.setTransparency(True) self.imgBouncer.reparentTo(self.frameMain) self.imgBadDude1 = OnscreenImage(image="badDude1.png", scale=(0.25, 0.25, 0.25), pos=(-0.75, 0, -0.4)) self.imgBadDude1.setTransparency(True) self.imgBadDude1.reparentTo(self.frameMain) img = self.imgBadDude1 up = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() + 0.01), bakeInStart=0) left = img.posInterval(3.0, Point3(img.getX() - 0.01, img.getY(), img.getZ()), bakeInStart=0) right = img.posInterval(3.0, Point3(img.getX() + 0.01, img.getY(), img.getZ()), bakeInStart=0) down = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() - 0.01), bakeInStart=0) rotForward = img.hprInterval(3.0, Point3(0, 0, 2.5), bakeInStart=0) rotBackward = img.hprInterval(3.0, Point3(0, 0, -2.5), bakeInStart=0) rotCenter = img.hprInterval(3.0, Point3(0, 0, 0), bakeInStart=0) self.ivalBadDude1 = Sequence(Parallel(rotCenter, up), Parallel(rotBackward, left), down, Parallel(rotCenter, up), Parallel(rotForward, right), down) self.imgGoodGal1 = OnscreenImage(image="goodGal1.png", scale=(0.6 * 0.25, 0.25, 0.25), pos=(-0.95, 0, -0.43)) self.imgGoodGal1.setTransparency(True) self.imgGoodGal1.reparentTo(self.frameMain) img = self.imgGoodGal1 up = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() + 0.01), bakeInStart=0) left = img.posInterval(3.0, Point3(img.getX() - 0.01, img.getY(), img.getZ()), bakeInStart=0) right = img.posInterval(3.0, Point3(img.getX() + 0.01, img.getY(), img.getZ()), bakeInStart=0) down = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() - 0.01), bakeInStart=0) rotForward = img.hprInterval(3.0, Point3(0, 0, 2.5), bakeInStart=0) rotBackward = img.hprInterval(3.0, Point3(0, 0, -2.5), bakeInStart=0) rotCenter = img.hprInterval(3.0, Point3(0, 0, 0), bakeInStart=0) self.ivalGoodGal1 = Sequence(left, right, left, down, up) self.imgGoodDude1 = OnscreenImage(image="goodDude1.png", scale=(0.25, 0.25, 0.25), pos=(0.95, 0, 0)) self.imgGoodDude1.setTransparency(True) self.imgGoodDude1.reparentTo(self.frameMain) img = self.imgGoodDude1 up = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() + 0.02), bakeInStart=0) left = img.posInterval(3.0, Point3(img.getX() - 0.02, img.getY(), img.getZ()), bakeInStart=0) right = img.posInterval(3.0, Point3(img.getX() + 0.02, img.getY(), img.getZ()), bakeInStart=0) down = img.posInterval(3.0, Point3(img.getX(), img.getY(), img.getZ() - 0.02), bakeInStart=0) rotForward = img.hprInterval(3.0, Point3(0, 0, 4), bakeInStart=0) rotBackward = img.hprInterval(3.0, Point3(0, 0, -4), bakeInStart=0) rotCenter = img.hprInterval(3.0, Point3(0, 0, 0), bakeInStart=0) self.ivalGoodDude1 = Sequence(Parallel(up, rotCenter), Parallel(right, rotForward), Parallel(down, rotCenter), Parallel(left, rotBackward)) self.hide() def show(self): self.frameMain.show() self.ivalBadDude1.loop() self.ivalGoodGal1.loop() self.ivalGoodDude1.loop() def hide(self): self.frameMain.hide() self.ivalBadDude1.finish() self.ivalGoodGal1.finish() self.ivalGoodDude1.finish()
class ResourcesGUI: """GUI to track player's resources. Includes money, expendable resources and cohesion. """ def __init__(self): self._coh_desc_wids = [] self._coh_desc_shown = False self._res_desc_wids = [] self._res_desc_shown = False self._resources = {} self._blink_step = 0 self._reload_ico = None self._reload_min = None self._err_snd = loader.loadSfx("sounds/GUI/error.ogg") # noqa: F821 self._res_frame = DirectFrame( parent=base.a2dTopLeft, # noqa: F821 frameSize=(-0.37, 0.37, -0.03, 0.028), pos=(0.37, 0, -0.028), frameTexture=GUI_PIC + "metal1.png", ) self._res_frame.setTransparency(TransparencyAttrib.MAlpha) DirectFrame( parent=self._res_frame, # noqa: F821 frameSize=(-0.023, 0.023, -0.023, 0.023), pos=(-0.34, 0, 0), frameTexture=GUI_PIC + "dollar.png", ) self._resources["dollars"] = DirectLabel( parent=self._res_frame, text="", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.27, 0, -0.008), ) DirectFrame( parent=self._res_frame, # noqa: F821 frameSize=(-0.018, 0.018, -0.018, 0.018), pos=(-0.18, 0, 0), frameTexture=GUI_PIC + "chars.png", ) self._resources["chars"] = DirectLabel( parent=self._res_frame, text="{}/{}".format(len(base.team.chars), base.train.cells), # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.12, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), relief="flat", pos=(-0.06, 0, 0), frameTexture=GUI_PIC + "medicine.png", command=base.team.use_medicine, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "medicine_boxes"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["medicine_boxes"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.02, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), relief="flat", pos=(0.035, 0, 0), frameTexture=GUI_PIC + "smoke_filter.png", command=base.train.use_smoke_filter, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "smoke_filters"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["smoke_filters"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.075, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.014, 0.014, -0.021, 0.021), relief="flat", pos=(0.12, 0, 0), frameTexture=GUI_PIC + "stimulator.png", command=base.team.use_stimulator, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "stimulators"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["stimulators"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.16, 0, -0.008), ) DirectButton( parent=self._res_frame, frameSize=(-0.014, 0.014, -0.021, 0.021), relief="flat", pos=(0.2, 0, 0), frameTexture=GUI_PIC + "places_of_interest.png", ) self._resources["places_of_interest"] = DirectLabel( parent=self._res_frame, text="0/10", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.27, 0, -0.008), ) DirectButton( parent=self._res_frame, pos=(0.34, 0, -0.013), command=self._show_expendable_resources, clickSound=base.main_menu.click_snd, # noqa: F821 **ABOUT_BUT_PARAMS, ).setTransparency(TransparencyAttrib.MAlpha) self._coh_frame = DirectFrame( parent=base.a2dBottomRight, # noqa: F821 frameSize=(-0.55, 0.55, -0.05, 0.05), pos=(-0.6, 0, 1.95), frameTexture=GUI_PIC + "metal1.png", state=DGG.NORMAL, ) self._coh_frame.setTransparency(TransparencyAttrib.MAlpha) self._cohesion = DirectWaitBar( parent=self._coh_frame, frameSize=(-0.45, 0.45, -0.002, 0.002), frameColor=(0.35, 0.35, 0.35, 1), value=0, barColor=SILVER_COL, pos=(0, 0, 0.02), ) recall_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), frameTexture=GUI_PIC + "ny_recall.png", pos=(-0.27, 0, -0.02), relief="flat", command=base.team.cohesion_recall, # noqa: F821 ) recall_ico.setTransparency(TransparencyAttrib.MAlpha) recall_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[recall_ico]) recall_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[recall_ico]) cover_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_cover.png", pos=(-0.09, 0, -0.01), relief="flat", command=base.team.cohesion_cover_fire, # noqa: F821 ) cover_ico.setTransparency(TransparencyAttrib.MAlpha) cover_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[cover_ico]) cover_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[cover_ico]) heal_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), frameTexture=GUI_PIC + "ny_heal.png", pos=(0.09, 0, -0.015), relief="flat", command=base.team.cohesion_heal_wounded, # noqa: F821 ) heal_ico.setTransparency(TransparencyAttrib.MAlpha) heal_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[heal_ico]) heal_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[heal_ico]) rage_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_rage.png", pos=(0.27, 0, -0.015), relief="flat", command=base.team.cohesion_rage, # noqa: F821 ) rage_ico.setTransparency(TransparencyAttrib.MAlpha) rage_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[rage_ico]) rage_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[rage_ico]) heart_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_heart.png", pos=(0.445, 0, -0.015), relief="flat", command=base.team.cohesion_hold_together, # noqa: F821 ) heart_ico.setTransparency(TransparencyAttrib.MAlpha) heart_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[heart_ico]) heart_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[heart_ico]) self._coh_icons = ( {"wid": recall_ico, "file": "recall.png", "value": 20}, {"wid": cover_ico, "file": "cover.png", "value": 40}, {"wid": heal_ico, "file": "heal.png", "value": 60}, {"wid": rage_ico, "file": "rage.png", "value": 80}, {"wid": heart_ico, "file": "heart.png", "value": 100}, ) DirectButton( parent=self._coh_frame, pos=(-0.5, 0, -0.028), command=self._show_cohesion_abilities, clickSound=base.main_menu.click_snd, # noqa: F821 **ABOUT_BUT_PARAMS, ).setTransparency(TransparencyAttrib.MAlpha) def _dehighlight_but(self, button, _): """Dehighlight button. Args: button (panda3d.gui.DirectGui.DirectButton): Button to dehighlight. """ if "hover_" in button["frameTexture"]: button["frameTexture"] = button["frameTexture"].replace("hover_", "") def _highlight_coh_but(self, button, _): """Highlight cohesion skill button, if it can be used. Args: button (panda3d.gui.DirectGui.DirectButton): Button to highlight. """ if "ny_" not in button["frameTexture"]: button["frameTexture"] = ( GUI_PIC + "hover_" + button["frameTexture"].split("/")[-1] ) def _highlight_res_but(self, button, resource, _): """Highlight resource button, if it can be used. Args: button (panda3d.gui.DirectGui.DirectButton): Button to highlight. resource (str): Name of the resource. """ if base.resource(resource): # noqa: F821 button["frameTexture"] = ( GUI_PIC + "hover_" + button["frameTexture"].split("/")[-1] ) def _show_cohesion_abilities(self): """Show/hide cohesion abilities description.""" if self._coh_desc_shown: self._coh_frame["frameSize"] = (-0.55, 0.55, -0.05, 0.05) clear_wids(self._coh_desc_wids) self._coh_desc_shown = False return self._coh_desc_shown = True self._coh_frame["frameSize"] = (-0.55, 0.55, -0.61, 0.05) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[0], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.033, text_fg=SILVER_COL, pos=(0, 0, -0.08), ) ) self._coh_desc_wids.append( DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "recall.png", pos=(-0.45, 0, -0.13), relief="flat", ) ) x_coor = -0.39 self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[1], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_fg=SILVER_COL, pos=(x_coor, 0, -0.117), ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[2], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.028, text_fg=SILVER_COL, pos=(x_coor, 0, -0.155), ) ) self._coh_desc_wids.append( DirectButton( parent=self._coh_frame, frameSize=(-0.045, 0.045, -0.045, 0.045), frameTexture=GUI_PIC + "cover.png", pos=(-0.45, 0, -0.22), relief="flat", ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[3], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_fg=SILVER_COL, pos=(x_coor, 0, -0.217), ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[4], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.028, text_fg=SILVER_COL, pos=(x_coor, 0, -0.255), ) ) self._coh_desc_wids.append( DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "heal.png", pos=(-0.45, 0, -0.33), relief="flat", ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[5], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_fg=SILVER_COL, pos=(x_coor, 0, -0.317), ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[6], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.028, text_fg=SILVER_COL, pos=(x_coor, 0, -0.355), ) ) self._coh_desc_wids.append( DirectButton( parent=self._coh_frame, frameSize=(-0.045, 0.045, -0.045, 0.045), frameTexture=GUI_PIC + "rage.png", pos=(-0.45, 0, -0.43), relief="flat", ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[7], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_fg=SILVER_COL, pos=(x_coor, 0, -0.417), ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[8], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.028, text_fg=SILVER_COL, pos=(x_coor, 0, -0.455), ) ) self._coh_desc_wids.append( DirectButton( parent=self._coh_frame, frameSize=(-0.043, 0.043, -0.043, 0.043), frameTexture=GUI_PIC + "heart.png", pos=(-0.45, 0, -0.53), relief="flat", ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[9], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_fg=SILVER_COL, pos=(x_coor, 0, -0.517), ) ) self._coh_desc_wids.append( DirectLabel( parent=self._coh_frame, text=base.labels.COHESION[10], # noqa: F821 text_font=base.main_font, # noqa: F821 text_align=TextNode.ALeft, frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.028, text_fg=SILVER_COL, pos=(x_coor, 0, -0.555), ) ) def _show_expendable_resources(self): """Show/hide expendable resources description.""" if self._res_desc_shown: self._res_frame["frameSize"] = (-0.37, 0.37, -0.03, 0.028) clear_wids(self._res_desc_wids) self._res_desc_shown = False return self._res_desc_shown = True self._res_frame["frameSize"] = (-0.37, 0.37, -0.51, 0.028) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[0], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.033, text_fg=SILVER_COL, pos=(0, 0, -0.08), ) ) self._res_desc_wids.append( DirectButton( parent=self._res_frame, frameSize=(-0.03, 0.03, -0.03, 0.03), frameTexture=GUI_PIC + "medicine.png", pos=(-0.29, 0, -0.15), relief="flat", ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[1], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.03, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.137), ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[2], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.175), ) ) self._res_desc_wids.append( DirectButton( parent=self._res_frame, frameSize=(-0.03, 0.03, -0.03, 0.03), frameTexture=GUI_PIC + "smoke_filter.png", pos=(-0.29, 0, -0.24), relief="flat", ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[3], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.03, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.233), ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[4], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.27), ) ) self._res_desc_wids.append( DirectButton( parent=self._res_frame, frameSize=(-0.018, 0.018, -0.028, 0.028), frameTexture=GUI_PIC + "stimulator.png", pos=(-0.29, 0, -0.339), relief="flat", ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[5], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.03, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.327), ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[6], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.365), ) ) self._res_desc_wids.append( DirectButton( parent=self._res_frame, frameSize=(-0.03, 0.03, -0.03, 0.03), frameTexture=GUI_PIC + "places_of_interest.png", pos=(-0.29, 0, -0.438), relief="flat", ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[8], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.03, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.426), ) ) self._res_desc_wids.append( DirectLabel( parent=self._res_frame, text=base.labels.RESOURCES[9], # noqa: F821 text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.029, text_align=TextNode.ALeft, text_fg=SILVER_COL, pos=(-0.235, 0, -0.464), ) ) def _blink_widget(self, widget, task): """Make the given widget blinking. Args: widget (str): Name of the widget to blink. """ self._blink_step += 1 if self._blink_step in (2, 4): self._resources[widget]["text_bg"] = (0, 0, 0, 0) self._resources[widget]["text_fg"] = RUST_COL else: self._resources[widget]["text_bg"] = (0.6, 0, 0, 1) self._resources[widget]["text_fg"] = (0, 0, 0, 1) if self._blink_step == 4: self._blink_step = 0 return task.done return task.again def check_enough_money(self, ch_sum): """Ensure that player have enough money for a buy. Make the money widget blink if player doesn't have enough money. Args: ch_sum (int): Buy cost. Returns: bool: True, if player has enough money. """ if ch_sum > base.dollars: # noqa: F821 taskMgr.doMethodLater( # noqa: F821 0.4, self._blink_widget, "blink_money_widget", extraArgs=["dollars"], appendTask=True, ) self._err_snd.play() return False return True def check_has_cell(self): """Check that the Train has at least one cell. Make the characters number widget blink, if there are not free cells. """ if not base.train.has_cell(): # noqa: F821 taskMgr.doMethodLater( # noqa: F821 0.4, self._blink_widget, "blink_money_widget", extraArgs=["chars"], appendTask=True, ) self._err_snd.play() return False return True def disable_cohesion(self): """Disable all the cohesion abilities.""" for icon in self._coh_icons: icon["wid"]["frameTexture"] = GUI_PIC + "ny_" + icon["file"] self._reload_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), frameTexture=GUI_PIC + "reload.png", pos=(-0.433, 0, -0.017), relief="flat", ) self._reload_ico.setTransparency(TransparencyAttrib.MAlpha) self._reload_min = DirectLabel( parent=self._coh_frame, frameSize=(0.1, 0.1, 0.1, 0.1), frameColor=(0, 0, 0, 0), text="? min", text_fg=SILVER_COL, text_scale=0.025, pos=(-0.37, 0, -0.025), ) def finish_reload(self): """Hide reloading timer widgets.""" self._reload_ico.destroy() self._reload_min.destroy() self._reload_ico = None self._reload_min = None def show_reload_min(self, min_num): """Update reloading timer. Args: min_num (int): Number of minutes left in the reloading delay. """ self._reload_min["text"] = str(min_num) + " min" def update_chars(self): """Update characters number widget.""" self._resources["chars"]["text"] = "{current}/{maximum}".format( current=len(base.team.chars), maximum=base.train.cells # noqa: F821 ) def update_cohesion(self, new_value): """Update cohesion indicator with the given value. Args: new_value (int): New amount of the cohesion points. """ self._cohesion["value"] = new_value if base.team.cohesion_cooldown: # noqa: F821 return for icon in self._coh_icons: if "hover_" in icon["wid"]["frameTexture"]: continue if new_value >= icon["value"]: icon["wid"]["frameTexture"] = GUI_PIC + icon["file"] else: icon["wid"]["frameTexture"] = GUI_PIC + "ny_" + icon["file"] def update_resource(self, name, value): """Update the indicator with the given value. Args: name (str): The indicator name. value (Any): The new indicator value. """ self._resources[name]["text"] = str(value)
def __init__(self): self._coh_desc_wids = [] self._coh_desc_shown = False self._res_desc_wids = [] self._res_desc_shown = False self._resources = {} self._blink_step = 0 self._reload_ico = None self._reload_min = None self._err_snd = loader.loadSfx("sounds/GUI/error.ogg") # noqa: F821 self._res_frame = DirectFrame( parent=base.a2dTopLeft, # noqa: F821 frameSize=(-0.37, 0.37, -0.03, 0.028), pos=(0.37, 0, -0.028), frameTexture=GUI_PIC + "metal1.png", ) self._res_frame.setTransparency(TransparencyAttrib.MAlpha) DirectFrame( parent=self._res_frame, # noqa: F821 frameSize=(-0.023, 0.023, -0.023, 0.023), pos=(-0.34, 0, 0), frameTexture=GUI_PIC + "dollar.png", ) self._resources["dollars"] = DirectLabel( parent=self._res_frame, text="", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.27, 0, -0.008), ) DirectFrame( parent=self._res_frame, # noqa: F821 frameSize=(-0.018, 0.018, -0.018, 0.018), pos=(-0.18, 0, 0), frameTexture=GUI_PIC + "chars.png", ) self._resources["chars"] = DirectLabel( parent=self._res_frame, text="{}/{}".format(len(base.team.chars), base.train.cells), # noqa: F821 frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.12, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), relief="flat", pos=(-0.06, 0, 0), frameTexture=GUI_PIC + "medicine.png", command=base.team.use_medicine, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "medicine_boxes"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["medicine_boxes"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(-0.02, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), relief="flat", pos=(0.035, 0, 0), frameTexture=GUI_PIC + "smoke_filter.png", command=base.train.use_smoke_filter, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "smoke_filters"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["smoke_filters"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.075, 0, -0.008), ) but = DirectButton( parent=self._res_frame, frameSize=(-0.014, 0.014, -0.021, 0.021), relief="flat", pos=(0.12, 0, 0), frameTexture=GUI_PIC + "stimulator.png", command=base.team.use_stimulator, # noqa: F821 ) but.bind(DGG.ENTER, self._highlight_res_but, extraArgs=[but, "stimulators"]) but.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[but]) self._resources["stimulators"] = DirectLabel( parent=self._res_frame, text="0", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.16, 0, -0.008), ) DirectButton( parent=self._res_frame, frameSize=(-0.014, 0.014, -0.021, 0.021), relief="flat", pos=(0.2, 0, 0), frameTexture=GUI_PIC + "places_of_interest.png", ) self._resources["places_of_interest"] = DirectLabel( parent=self._res_frame, text="0/10", frameSize=(0.1, 0.1, 0.1, 0.1), text_scale=0.035, text_fg=RUST_COL, pos=(0.27, 0, -0.008), ) DirectButton( parent=self._res_frame, pos=(0.34, 0, -0.013), command=self._show_expendable_resources, clickSound=base.main_menu.click_snd, # noqa: F821 **ABOUT_BUT_PARAMS, ).setTransparency(TransparencyAttrib.MAlpha) self._coh_frame = DirectFrame( parent=base.a2dBottomRight, # noqa: F821 frameSize=(-0.55, 0.55, -0.05, 0.05), pos=(-0.6, 0, 1.95), frameTexture=GUI_PIC + "metal1.png", state=DGG.NORMAL, ) self._coh_frame.setTransparency(TransparencyAttrib.MAlpha) self._cohesion = DirectWaitBar( parent=self._coh_frame, frameSize=(-0.45, 0.45, -0.002, 0.002), frameColor=(0.35, 0.35, 0.35, 1), value=0, barColor=SILVER_COL, pos=(0, 0, 0.02), ) recall_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), frameTexture=GUI_PIC + "ny_recall.png", pos=(-0.27, 0, -0.02), relief="flat", command=base.team.cohesion_recall, # noqa: F821 ) recall_ico.setTransparency(TransparencyAttrib.MAlpha) recall_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[recall_ico]) recall_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[recall_ico]) cover_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_cover.png", pos=(-0.09, 0, -0.01), relief="flat", command=base.team.cohesion_cover_fire, # noqa: F821 ) cover_ico.setTransparency(TransparencyAttrib.MAlpha) cover_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[cover_ico]) cover_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[cover_ico]) heal_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.023, 0.023, -0.023, 0.023), frameTexture=GUI_PIC + "ny_heal.png", pos=(0.09, 0, -0.015), relief="flat", command=base.team.cohesion_heal_wounded, # noqa: F821 ) heal_ico.setTransparency(TransparencyAttrib.MAlpha) heal_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[heal_ico]) heal_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[heal_ico]) rage_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_rage.png", pos=(0.27, 0, -0.015), relief="flat", command=base.team.cohesion_rage, # noqa: F821 ) rage_ico.setTransparency(TransparencyAttrib.MAlpha) rage_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[rage_ico]) rage_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[rage_ico]) heart_ico = DirectButton( parent=self._coh_frame, frameSize=(-0.035, 0.035, -0.035, 0.035), frameTexture=GUI_PIC + "ny_heart.png", pos=(0.445, 0, -0.015), relief="flat", command=base.team.cohesion_hold_together, # noqa: F821 ) heart_ico.setTransparency(TransparencyAttrib.MAlpha) heart_ico.bind(DGG.ENTER, self._highlight_coh_but, extraArgs=[heart_ico]) heart_ico.bind(DGG.EXIT, self._dehighlight_but, extraArgs=[heart_ico]) self._coh_icons = ( {"wid": recall_ico, "file": "recall.png", "value": 20}, {"wid": cover_ico, "file": "cover.png", "value": 40}, {"wid": heal_ico, "file": "heal.png", "value": 60}, {"wid": rage_ico, "file": "rage.png", "value": 80}, {"wid": heart_ico, "file": "heart.png", "value": 100}, ) DirectButton( parent=self._coh_frame, pos=(-0.5, 0, -0.028), command=self._show_cohesion_abilities, clickSound=base.main_menu.click_snd, # noqa: F821 **ABOUT_BUT_PARAMS, ).setTransparency(TransparencyAttrib.MAlpha)
class Credits: def __init__(self): self.frameMain = DirectFrame( frameSize = (base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor = (0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) tpBig = TextProperties() tpBig.setTextScale(1.5) tpSmall = TextProperties() tpSmall.setTextScale(0.75) tpUs = TextProperties() tpUs.setUnderscore(True) tpMgr = TextPropertiesManager.getGlobalPtr() tpMgr.setProperties("big", tpBig) tpMgr.setProperties("small", tpSmall) tpMgr.setProperties("us", tpUs) creditsText = "" with open("credits.txt") as f: creditsText = f.read() self.lblCredits = DirectLabel( text = creditsText, text_fg = (1,1,1,1), text_bg = (0,0,0,0), frameColor = (0,0,0,0), text_align = TextNode.ACenter, scale = 0.1, pos = (0, 0, base.a2dTop - 0.2)) self.lblCredits.setTransparency(1) self.lblCredits.reparentTo(self.frameMain) self.creditsScroll = LerpPosInterval( self.lblCredits, 12.0, (0, 0, base.a2dTop + 3.5), startPos=(0, 0, base.a2dBottom), name="CreditsScroll") self.btnBack = DirectButton( text = "BACK", text_fg = (1,1,1,1), text_align = TextNode.ALeft, scale = 0.1, pad = (0.15, 0.15), pos = (base.a2dLeft + 0.08, 0, base.a2dBottom + 0.05), frameColor = ( (0.2,0.2,0.2,0.8), (0.4,0.4,0.4,0.8), (0.4,0.4,0.4,0.8), (0.1,0.1,0.1,0.8), ), relief = 1, command = base.messenger.send, extraArgs = ["Credits-Back"], pressEffect = False, rolloverSound = None, clickSound = None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self): self.frameMain.show() self.creditsScroll.loop() def hide(self): self.frameMain.hide() self.creditsScroll.finish()
class GameOverScreen(): def __init__(self): # a fill panel so the player doesn't see how everything # gets loaded in the background self.frameMain = DirectFrame( # size of the frame frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), image = "Logo.png", image_scale = (0.612/2.0, 1, 0.495/2.0), image_pos = (0, 0, 0.7), # tramsparent bg color frameColor = (0, 0, 0, 1)) self.frameMain.setTransparency(1) self.lblWin = DirectLabel( scale = 0.25, pos = (0, 0, 0.25), frameColor = (0, 0, 0, 0), text = _("You Succeeded"), text_align = TextNode.ACenter, text_fg = (1,1,1,1)) self.lblWin.reparentTo(self.frameMain) self.lblTime = DirectLabel( scale = 0.07, pos = (0, 0, 0.00), frameColor = (0, 0, 0, 0), text = "your time", text_align = TextNode.ACenter, text_fg = (1,1,1,1)) self.lblTime.reparentTo(self.frameMain) self.lblResult = DirectLabel( scale = 0.40, pos = (0, 0, -0.25), frameColor = (0, 0, 0, 0), text = "00:00", text_align = TextNode.ACenter, text_fg = (1,1,1,1)) self.lblResult.reparentTo(self.frameMain) self.btnContinue = DirectButton( scale = (0.25, 0.25, 0.25), # some temp text text = _("Continue..."), text_scale = (0.5, 0.5, 0.5), # set the alignment to right text_align = TextNode.ACenter, # put the text on the right side of the button text_pos = (0, 0), # set the text color to black text_fg = (1,1,1,1), text_shadow = (0.3, 0.3, 0.1, 1), text_shadowOffset = (0.05, 0.05), relief = 1, frameColor = (0,0,0,0), pressEffect = False, pos = (0, 0, -0.65), command = lambda: base.messenger.send("Exit"), rolloverSound = None, clickSound = None) self.btnContinue.setTransparency(1) self.btnContinue.reparentTo(self.frameMain) self.hide() def show(self, winLoose, resulttime): if winLoose == "win": timestring = "%d:%02d" % (resulttime/60, resulttime%60) self.lblResult["text"] = timestring self.lblTime.show() self.lblResult.show() else: self.lblWin["text"] = _("You Loose") self.lblTime.hide() self.lblResult.hide() self.frameMain.show() def hide(self): self.frameMain.hide()
class OptionsMenu(DirectObject): def __init__(self): """Default constructor""" # create a main frame as big as the window self.frameMain = DirectFrame( # set framesize the same size as the window frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), image = "LogoTextGlow.png", image_scale = (1.06/2.0, 1, 0.7/2.0), image_pos = (0, 0, 0.7), # position center pos = (0, 0, 0), # set tramsparent background color frameColor = (0, 0, 0, 0)) self.frameMain.setTransparency(1) self.frameMain.setBin("fixed", 100) sliderscale = 0.5 buttonScale = 0.25 textscale = 0.1 checkboxscale = 0.05 left = -0.5 right = 0.5 self.sliderTextspeed = DirectSlider( scale = sliderscale, pos = (left, 0, 0.2), range = (0.2,0.01), scrollSize = 0.01, text = _("Textspeed %0.1f%%")%(base.textWriteSpeed * 10), text_scale = textscale, text_align = TextNode.ACenter, text_pos = (0.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = base.textWriteSpeed, command = self.sliderTextspeed_ValueChanged) self.sliderTextspeed.reparentTo(self.frameMain) self.cbParticles = DirectCheckButton( text = _(" Enable Particles"), text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 0.35), pos = (left, 0, -0.0), scale = checkboxscale, frameColor = (0,0,0,0), command = self.cbParticles_CheckedChanged, rolloverSound = None, clickSound = None, pressEffect = False, boxPlacement = "below", boxBorder = 0.8, boxRelief = DGG.FLAT, indicator_scale = 1.5, indicator_text_fg = (0.65, 0.65, 0.0, 1), indicator_text_shadow = (0, 0, 0, 0.35), indicator_frameColor = (0.15, 0.15, 0.15, 1), indicatorValue = base.particleMgrEnabled ) self.cbParticles.indicator['text'] = (' ', 'x') self.cbParticles.indicator['text_pos'] = (0, 0.1) #self.cbParticles.indicator.setX(self.cbParticles.indicator, -0.5) #self.cbParticles.indicator.setZ(self.cbParticles.indicator, -0.1) #self.cbParticles.setFrameSize() self.cbParticles.setTransparency(1) self.cbParticles.reparentTo(self.frameMain) volume = base.musicManager.getVolume() self.sliderVolume = DirectSlider( scale = sliderscale, pos = (left, 0, -0.35), range = (0,1), scrollSize = 0.01, text = _("Volume %d%%")%volume*100, text_scale = textscale, text_align = TextNode.ACenter, text_pos = (.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = volume, command = self.sliderVolume_ValueChanged) self.sliderVolume.reparentTo(self.frameMain) self.lblControltype = DirectLabel( text = _("Control type"), text_fg = (1, 1, 1, 1), text_shadow = (0, 0, 0, 0.35), frameColor = (0, 0, 0, 0), scale = textscale/2, pos = (right, 0, 0.27)) self.lblControltype.setTransparency(1) self.lblControltype.reparentTo(self.frameMain) selectedControlType = 0 if base.controlType == "MouseAndKeyboard": selectedControlType = 1 self.controltype = DirectOptionMenu( pos = (right, 0, 0.18), text_fg = (1, 1, 1, 1), scale = 0.1, items = [_("Keyboard"),_("Keyboard + Mouse")], initialitem = selectedControlType, frameColor = (0.15, 0.15, 0.15, 1), popupMarker_frameColor = (0.65, 0.65, 0.0, 1), popupMarker_relief = DGG.FLAT, highlightColor = (0.65, 0.65, 0.0, 1), relief = DGG.FLAT, command=self.controlType_Changed) self.controltype.reparentTo(self.frameMain) b = self.controltype.getBounds() xPos = right - ((b[1] - b[0]) / 2.0 * 0.1) self.controltype.setX(xPos) setItems(self.controltype) self.controltype.setItems = setItems self.controltype.showPopupMenu = showPopupMenu self.controltype.popupMarker.unbind(DGG.B1PRESS) self.controltype.popupMarker.bind(DGG.B1PRESS, showPopupMenu) self.controltype.unbind(DGG.B1PRESS) self.controltype.bind(DGG.B1PRESS, showPopupMenuExtra, [self.controltype]) isChecked = not base.AppHasAudioFocus img = None if base.AppHasAudioFocus: img = "AudioSwitch_on.png" else: img = "AudioSwitch_off.png" self.cbVolumeMute = DirectCheckBox( text = _("Mute Audio"), text_scale = 0.5, text_align = TextNode.ACenter, text_pos = (0.0, 0.65), text_fg = (1,1,1,1), pos = (right, 0, -0.35), scale = 0.21/2.0, command = self.cbVolumeMute_CheckedChanged, rolloverSound = None, clickSound = None, relief = None, pressEffect = False, isChecked = isChecked, image = img, image_scale = 0.5, checkedImage = "AudioSwitch_off.png", uncheckedImage = "AudioSwitch_on.png") self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) sensitivity = base.mouseSensitivity self.sliderSensitivity = DirectSlider( scale = sliderscale, pos = (right, 0, -0.075), range = (0.5,2), scrollSize = 0.01, text = _("Mouse Sensitivity %0.1fx")%sensitivity, text_scale = textscale, text_align = TextNode.ACenter, text_pos = (.0, 0.15), text_fg = (1,1,1,1), thumb_frameColor = (0.65, 0.65, 0.0, 1), thumb_relief = DGG.FLAT, frameColor = (0.15, 0.15, 0.15, 1), value = sensitivity, command = self.sliderSensitivity_ValueChanged) self.sliderSensitivity.reparentTo(self.frameMain) if base.controlType == "Gamepad": self.sliderSensitivity.hide() # create the back button self.btnBack = DirectButton( scale = buttonScale, # position on the window pos = (0, 0, base.a2dBottom + 0.15), frameColor = (0,0,0,0), # text properties text = _("Back"), text_scale = 0.5, text_fg = (1,1,1,1), text_pos = (0.0, -0.15), text_shadow = (0, 0, 0, 0.35), text_shadowOffset = (-0.05, -0.05), # sounds that should be played rolloverSound = None, clickSound = None, pressEffect = False, relief = None, # the event which is thrown on clickSound command = lambda: base.messenger.send("options_back")) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self, enableResume=False): self.frameMain.show() def hide(self): self.frameMain.hide() def cbVolumeMute_CheckedChanged(self, checked): if checked: base.disableAllAudio() else: base.enableAllAudio() def sliderVolume_ValueChanged(self): volume = round(self.sliderVolume["value"], 2) self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100) base.sfxManagerList[0].setVolume(volume) base.musicManager.setVolume(volume) def sliderSensitivity_ValueChanged(self): sensitivity = round(self.sliderSensitivity["value"], 2) self.sliderSensitivity["text"] = _("Mouse Sensitivity %0.1fx") % sensitivity base.mouseSensitivity = sensitivity def sliderTextspeed_ValueChanged(self): newSpeed = round(self.sliderTextspeed["value"], 2) displaySpeed = 1.0 / newSpeed self.sliderTextspeed["text"] = _("Textspeed %0.1f%%")%displaySpeed base.textWriteSpeed = newSpeed def cbParticles_CheckedChanged(self, unchecked): if unchecked: base.enableParticles() else: base.disableParticles() def controlType_Changed(self, arg): if arg == _("Keyboard"): self.sliderSensitivity.hide() base.controlType = "Gamepad" elif arg == _("Keyboard + Mouse"): self.sliderSensitivity.show() base.controlType = "MouseAndKeyboard"
class LevelSelection: def __init__(self): self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) self.btnLevel1 = self.createLevelButton( (-0.6, 0, 0.15), "assets/gui/Level1Button.png", 1) self.btnLevel1.reparentTo(self.frameMain) self.btnLevel2 = self.createLevelButton( (0.6, 0, 0.15), "assets/gui/Level2Button.png", 2) self.btnLevel2.reparentTo(self.frameMain) self.footerFrame = DirectFrame(text="SELECT THE ARENA", text_fg=(1, 1, 1, 1), text_scale=0.08, text_pos=(0, -0.03), frameSize=(base.a2dLeft, base.a2dRight, 0.1, -0.1), pos=(0, 0, base.a2dBottom + 0.2), frameColor=(0, 0, 0, 0.5)) self.footerFrame.setTransparency(1) self.footerFrame.reparentTo(self.frameMain) self.btnBack = DirectButton(text="BACK", text_fg=(1, 1, 1, 1), text_align=TextNode.ALeft, scale=0.1, pad=(0.15, 0.15), pos=(base.a2dLeft + 0.08, 0, -0.03), frameColor=( (0.2, 0.2, 0.2, 0.8), (0.4, 0.4, 0.4, 0.8), (0.4, 0.4, 0.4, 0.8), (0.1, 0.1, 0.1, 0.8), ), relief=1, command=base.messenger.send, extraArgs=["LevelSelection-Back"], pressEffect=False, rolloverSound=None, clickSound=None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.footerFrame) self.hide() def createLevelButton(self, pos, image, levelNr): btn = DirectButton(scale=(0.5, 1, 0.75), relief=0, frameColor=(0, 0, 0, 0), pos=pos, image=image, command=self.selectLevel, extraArgs=[levelNr], rolloverSound=None, clickSound=None) btn.setTransparency(1) return btn def selectLevel(self, level): self.selectedLevel = level base.messenger.send("LevelSelection-Start") def show(self): self.frameMain.show() def hide(self): self.frameMain.hide()
class MenuMain(Menu): def __init__(self): Menu.__init__(self) screenResMultiplier = 1.33 self.btnStart = DirectButton( # size of the button scale = (0.25, 0.25, 0.25), # some temp text text = "ABC", # size of the text text_scale = (0.5*screenResMultiplier, 0.5, 0.5), # set the alignment to right text_align = TextNode.ARight, # put the text on the right side of the button text_pos = (4.1, -0.15), # set the text color to white text_fg = (1,1,1,1), # set the font of the text #text_font = self.defaultFont, # set the buttons images geom = (self.defaultBtnMaps.find("**/button_ready"), self.defaultBtnMaps.find("**/button_click"), self.defaultBtnMaps.find("**/button_rollover"), self.defaultBtnMaps.find("**/button_disabled")), # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (-1, 0, .55), # the event which is thrown on clickSound command = self.btnStart_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnStart.setTransparency(1) levellist = [] initialitem = 0 for (path, dirs, files) in os.walk("game/assets/levels"): for f in files: if f.endswith(".egg"): print f.rstrip(".egg") levellist.append(f.rstrip(".egg")) self.cmbLanguage = DirectOptionMenu( text = "Levels", scale = 0.15, pos = (base.a2dLeft + 1.5, 0, 0.50), items = levellist, initialitem = initialitem, highlightColor = (0.65,0.65,0.65,1), command = self.cmbLevel_SelectionChanged) self.selectedLevel = levellist[initialitem] self.btnOptions = DirectButton( scale = (0.25, 0.25, 0.25), # some temp text text = "ABC", text_scale = (0.45*screenResMultiplier, 0.45, 0.45), # set the alignment to right text_align = TextNode.ARight, # put the text on the right side of the button text_pos = (4.1, -0.15), # set the text color to white text_fg = (1,1,1,1), # set the font of the text #text_font = self.defaultFont, # set the buttons images geom = (self.defaultBtnMaps.find("**/button_ready"), self.defaultBtnMaps.find("**/button_click"), self.defaultBtnMaps.find("**/button_rollover"), self.defaultBtnMaps.find("**/button_disabled")), relief = 1, frameColor = (0,0,0,0), pressEffect = False, pos = (-1.5, 0, .15), command = self.btnOptions_Click, rolloverSound = None, clickSound = None) self.btnOptions.setTransparency(1) self.btnQuit = DirectButton( scale = (0.25, 0.25, 0.25), # some temp text text = "ABC", text_scale = (0.5*screenResMultiplier, 0.5, 0.5), # set the alignment to right text_align = TextNode.ARight, # put the text on the right side of the button text_pos = (4.1, -0.15), # set the text color to white text_fg = (1,1,1,1), # set the font of the text #text_font = self.defaultFont, # set the buttons images geom = (self.defaultBtnMaps.find("**/button_ready"), self.defaultBtnMaps.find("**/button_click"), self.defaultBtnMaps.find("**/button_rollover"), self.defaultBtnMaps.find("**/button_disabled")), relief = 1, frameColor = (0,0,0,0), pressEffect = False, pos = (-1.75, 0, -.25), command = self.btnQuit_Click, rolloverSound = None, clickSound = None) self.btnQuit.setTransparency(1) self.btnStart.reparentTo(self.frameMain) self.btnOptions.reparentTo(self.frameMain) self.btnQuit.reparentTo(self.frameMain) self.cmbLanguage.reparentTo(self.frameMain) self.recalcAspectRatio() # set the text of all GUI elements self.setText() # hide all buttons at startup self.hideBase() self.accept("LanguageChanged", self.setText) def show(self): self.title["text"] = _("Main Menu") self.showBase() def hide(self): self.hideBase() def setText(self): self.title["text"] = _("Main Menu") self.btnStart["text"] = _("Start") self.btnOptions["text"] = _("Options") self.btnQuit["text"] = _("Quit") def btnStart_Click(self): base.messenger.send("MainMenu_startGame") def btnOptions_Click(self): base.messenger.send("MainMenu_optionsMain") def btnQuit_Click(self): base.messenger.send("MainMenu_quitMain") def cmbLevel_SelectionChanged(self, arg): self.selectedLevel = arg
class LaffMeter(DirectFrame): deathColor = Vec4(0.58039216, 0.80392157, 0.34117647, 1.0) def __init__(self, avdna, hp, maxHp, isLocalHealth=False): DirectFrame.__init__(self, relief=None, sortOrder=50) self.initialiseoptions(LaffMeter) self.style = avdna self.av = None self.hp = hp self.maxHp = maxHp self.__obscured = 0 self.isLocalHealth = isLocalHealth self.container = DirectFrame(parent=self, relief=None) if self.style.type == 't': self.isToon = 1 else: self.isToon = 0 self.load() def showGags(self): self.showDetailsButton['command'] = self.backToDetails self.gagsBtn.hide() self.toontasksButton.hide() messenger.send('home') self.accept('home-up', self.backToDetails) self.accept('end-up', self.backToDetails) def showTasks(self): self.showDetailsButton['command'] = self.backToDetails self.gagsBtn.hide() self.toontasksButton.hide() messenger.send('end') self.accept('home-up', self.backToDetails) self.accept('end-up', self.backToDetails) def backToDetails(self): self.showDetailsButton['command'] = self.hideDetailsPopup self.gagsBtn.show() self.toontasksButton.show() self.ignore('home-up') self.ignore('end-up') messenger.send('home-up') messenger.send('end-up') def showDetailsPopup(self): self.showDetailsButton.setColorScale(1, 1, 1, 1) gagicnmodel = loader.loadModel('phase_3.5/models/gui/inventory_icons') gagicon = gagicnmodel.find('**/inventory_tart') gagicnmodel.removeNode() self.gagsBtn = DirectButton(parent=aspect2d, relief=None, pos=(-0.4, 0, 0), text_style=3, text_pos=(0, -0.3), text_scale=0.08, text=TTLocalizer.InventoryPageTitle, geom=gagicon, geom_scale=2, scale=1, command=self.showGags) tasksicnmodel = loader.loadModel( 'phase_3.5/models/gui/stickerbook_gui') tasksicon = tasksicnmodel.find('**/questCard') tasksicnmodel.removeNode() self.toontasksButton = DirectButton( parent=aspect2d, relief=None, pos=(0.4, 0, 0), text_style=3, text_pos=(0, -0.3), text_scale=0.08, text=TTLocalizer.QuestPageToonTasks, geom=tasksicon, geom_scale=0.35, scale=1, command=self.showTasks) self.backToDetails() def hideDetailsPopup(self): self.showDetailsButton.setColorScale(1, 1, 1, 0) messenger.send('home-up') messenger.send('end-up') self.gagsBtn.destroy() self.toontasksButton.destroy() self.showDetailsButton['command'] = self.showDetailsPopup def obscure(self, obscured): self.__obscured = obscured if self.__obscured: self.hide() base.localAvatar.expBar.hide() def isObscured(self): return self.__obscured def load(self): gui = loader.loadModel('phase_3/models/gui/laff_o_meter') if self.isToon: hType = self.style.getType() if hType == 'dog': headModel = gui.find('**/doghead') elif hType == 'cat': headModel = gui.find('**/cathead') elif hType == 'mouse': headModel = gui.find('**/mousehead') elif hType == 'horse': headModel = gui.find('**/horsehead') elif hType == 'rabbit': headModel = gui.find('**/bunnyhead') elif hType == 'duck': headModel = gui.find('**/duckhead') elif hType == 'monkey': headModel = gui.find('**/monkeyhead') elif hType == 'bear': headModel = gui.find('**/bearhead') elif hType == 'pig': headModel = gui.find('**/pighead') elif hType == 'deer': headModel = gui.find('**/deerhead') else: raise StandardError('unknown toon species: ', hType) self.color = self.style.getHeadColor() self.container['image'] = headModel self.container['image_color'] = self.color self.resetFrameSize() self.setScale(0.1) self.frown = DirectFrame(parent=self.container, relief=None, image=gui.find('**/frown')) self.frown.setY(-0.1) self.smile = DirectFrame(parent=self.container, relief=None, image=gui.find('**/smile')) self.smile.setY(-0.1) self.eyes = DirectFrame(parent=self.container, relief=None, image=gui.find('**/eyes')) self.eyes.setY(-0.1) 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.maxLabel = DirectLabel( parent=self.eyes, relief=None, pos=(0.442, 0, 0.051), text='120', text_scale=0.4, text_font=ToontownGlobals.getInterfaceFont()) self.maxLabel.setY(-0.1) self.hpLabel = DirectLabel( parent=self.eyes, relief=None, pos=(-0.398, 0, 0.051), text='120', text_scale=0.4, text_font=ToontownGlobals.getInterfaceFont()) self.hpLabel.setY(-0.1) self.teeth = [ self.tooth6, self.tooth5, self.tooth4, self.tooth3, self.tooth2, self.tooth1 ] for tooth in self.teeth: tooth.setY(-0.1) self.fractions = [0.0, 0.166666, 0.333333, 0.5, 0.666666, 0.833333] if self.isLocalHealth: self.showDetailsButton = DirectButton( relief=None, parent=self.container, image='phase_3/maps/android/tui_move_l.png', scale=1, command=self.showDetailsPopup) self.showDetailsButton.setTransparency(1) self.showDetailsButton.setColorScale(1, 1, 1, 0) gui.removeNode() def destroy(self): if self.av: ToontownIntervals.cleanup( self.av.uniqueName('laffMeterBoing') + '-' + str(self.this)) ToontownIntervals.cleanup( self.av.uniqueName('laffMeterBoing') + '-' + str(self.this) + '-play') self.ignore(self.av.uniqueName('hpChange')) del self.style del self.av del self.hp del self.maxHp if self.isToon: del self.frown del self.smile del self.openSmile del self.tooth1 del self.tooth2 del self.tooth3 del self.tooth4 del self.tooth5 del self.tooth6 del self.teeth del self.fractions del self.maxLabel del self.hpLabel DirectFrame.destroy(self) def adjustTeeth(self): if self.isToon: for i in xrange(len(self.teeth)): if self.hp > self.maxHp * self.fractions[i]: self.teeth[i].show() else: self.teeth[i].hide() def adjustText(self): if self.isToon: if self.maxLabel['text'] != str( self.maxHp) or self.hpLabel['text'] != str(self.hp): self.maxLabel['text'] = str(self.maxHp) self.hpLabel['text'] = str(self.hp) def animatedEffect(self, delta): if delta == 0 or self.av == None: return name = self.av.uniqueName('laffMeterBoing') + '-' + str(self.this) ToontownIntervals.cleanup(name) if delta > 0: ToontownIntervals.start( ToontownIntervals.getPulseLargerIval(self.container, name)) else: ToontownIntervals.start( ToontownIntervals.getPulseSmallerIval(self.container, name)) def adjustFace(self, hp, maxHp, quietly=0): if self.isToon and self.hp != None: self.frown.hide() self.smile.hide() self.openSmile.hide() self.eyes.hide() for tooth in self.teeth: tooth.hide() delta = hp - self.hp self.hp = hp self.maxHp = maxHp if self.hp < 1: self.frown.show() self.container['image_color'] = self.deathColor elif self.hp >= self.maxHp: self.smile.show() self.eyes.show() self.container['image_color'] = self.color else: self.openSmile.show() self.eyes.show() self.maxLabel.show() self.hpLabel.show() self.container['image_color'] = self.color self.adjustTeeth() self.adjustText() if not quietly: self.animatedEffect(delta) def start(self): if self.av: self.hp = self.av.hp self.maxHp = self.av.maxHp if self.isToon: if not self.__obscured: self.show() self.adjustFace(self.hp, self.maxHp, 1) if self.av: self.accept(self.av.uniqueName('hpChange'), self.adjustFace) def stop(self): if self.isToon: self.hide() if self.av: self.ignore(self.av.uniqueName('hpChange')) def setAvatar(self, av): if self.av: self.ignore(self.av.uniqueName('hpChange')) self.av = av
class MenuPause(Menu): def __init__(self): Menu.__init__(self) self.frameMain.setTransparency(True) self.frameMain.frameColor = (0.25, 0, 1, 0.25) screenResMultiplier = 1.33 self.btnReturn = DirectButton( # size of the button scale = (0.25, 0.25, 0.25), # some temp text text = "ABC", # size of the text text_scale = (0.5*screenResMultiplier, 0.5, 0.5), # set the alignment to center text_align = TextNode.ACenter, # put the text on the left side of the button text_pos = (0, -0.15), # set the text color to white text_fg = (1,1,1,1), # set the font of the text text_font = self.defaultFont, # set the buttons images geom = (self.defaultBtnMaps.find("**/button_ready"), self.defaultBtnMaps.find("**/button_click"), self.defaultBtnMaps.find("**/button_rollover"), self.defaultBtnMaps.find("**/button_disabled")), # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0, 0, .25), # the event which is thrown on clickSound command = self.btnReturn_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnReturn.setTransparency(1) self.btnQuit = DirectButton( scale = (0.25, 0.25, 0.25), # some temp text text = "ABC", text_scale = (0.5*screenResMultiplier, 0.5, 0.5), # set the alignment to center text_align = TextNode.ACenter, # put the text on the left side of the button text_pos = (0, -0.15), # set the text color to white text_fg = (1,1,1,1), # set the font of the text text_font = self.defaultFont, # set the buttons images geom = (self.defaultBtnMaps.find("**/button_ready"), self.defaultBtnMaps.find("**/button_click"), self.defaultBtnMaps.find("**/button_rollover"), self.defaultBtnMaps.find("**/button_disabled")), relief = 1, frameColor = (0,0,0,0), pressEffect = False, pos = (0, 0, -.25), command = self.btnQuit_Click, rolloverSound = None, clickSound = None) self.btnQuit.setTransparency(1) self.btnReturn.reparentTo(self.frameMain) self.btnQuit.reparentTo(self.frameMain) self.recalcAspectRatio() # set the text of all GUI elements self.setText() self.hideBase() def show(self): self.title["text"] = _("Pause") self.showBase() def hide(self): self.hideBase() def setText(self): self.title["text"] = _("Main Menu") self.btnReturn["text"] = _("Return") self.btnQuit["text"] = _("Quit") def btnReturn_Click(self): base.messenger.send("PauseMenu_return") def btnQuit_Click(self): base.messenger.send("PauseMenu_quit")
class MainScreen(): def __init__(self): self.txtPlayerName = DirectEntry( text="", scale=0.08, pos=(-0.15, 0, 0.6), initialText="Name", numLines = 1, width = 4, focus=False, focusInCommand=self.__clearText, focusOutCommand=self.__checkText) self.btnStart = DirectButton( text = "Start", # size of the button scale = (0.25, 0.25, 0.25), # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0, 0, .3), # the event which is thrown on clickSound command = self.btnStart_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnStart.setTransparency(1) self.btnHighscore = DirectButton( text = "Highscore", # size of the button scale = (0.25, 0.25, 0.25), # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0, 0, 0), # the event which is thrown on clickSound command = self.btnHighscore_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnHighscore.setTransparency(1) self.btnQuit = DirectButton( text = "Quit", # size of the button scale = (0.25, 0.25, 0.25), # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0, 0, -.3), # the event which is thrown on clickSound command = self.btnQuit_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnQuit.setTransparency(1) def show(self): self.txtPlayerName.show() self.btnStart.show() self.btnHighscore.show() self.btnQuit.show() def hide(self): self.txtPlayerName.hide() self.btnStart.hide() self.btnHighscore.hide() self.btnQuit.hide() def __clearText(self): if self.txtPlayerName.get() == "" or \ self.txtPlayerName.get() == "Name": self.txtPlayerName.enterText("") def __checkText(self): if self.txtPlayerName.get() == "": self.txtPlayerName.enterText("Name") def btnStart_Click(self): self.hide() base.messenger.send("MainMenu_start") def btnHighscore_Click(self): self.hide() base.messenger.send("Highscore_show") def btnQuit_Click(self): base.messenger.send("MainMenu_quit") def getPlayername(self): return self.txtPlayerName.get()
class MenuStartGame(Menu): def __init__(self): self.charA = None self.charB = None Menu.__init__(self) self.charSelectBtnMaps = base.loader.loadModel( "gui/buttons/charSelection/button_maps") self.btnCharA = DirectButton( # size of the button scale = (2.5, 1, 1.6), # size of the text #text_scale = (0.5*1.33, 0.5, 0.5), # the text on the button text = "", # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # set the buttons images geom = (self.charSelectBtnMaps.find("**/char_ready"), self.charSelectBtnMaps.find("**/char_click"), self.charSelectBtnMaps.find("**/char_rollover"), self.charSelectBtnMaps.find("**/char_disabled")), # position on the window pos = (-1, 0, 0), # the event which is thrown on clickSound command = self.btnCharA_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnCharA.setTransparency(1) self.btnCharB = DirectButton( # size of the button scale = (2.5, 1, 1.6), # size of the text text_scale = (0.5*1.33, 0.5, 0.5), # the text on the button text = "", # set no relief relief = 1, frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # set the buttons images geom = (self.charSelectBtnMaps.find("**/char_ready"), self.charSelectBtnMaps.find("**/char_click"), self.charSelectBtnMaps.find("**/char_rollover"), self.charSelectBtnMaps.find("**/char_disabled")), # position on the window pos = (1, 0, 0), # the event which is thrown on clickSound command = self.btnCharB_Click, # sounds that should be played rolloverSound = None, clickSound = None) self.btnCharB.setTransparency(1) self.btnCharB["state"] = 0 # add every item to the mainframe self.btnCharA.reparentTo(self.frameMain) self.btnCharB.reparentTo(self.frameMain) self.charA = Actor("avatar/Avatar1", {"idle": "avatar/Avatar1-Idle"}) self.charA.setScale(0.30) self.charA.setPos(-1, 4, -0.5) self.charA.reparentTo(camMgr.activeCameras["menuCam"].camNP) self.charA.setPlayRate(0.5, "idle") self.charA.loop("idle") self.charB = Actor("avatar/Avatar1", {"idle": "avatar/Avatar1-Idle"}) self.charB.setScale(0.10) self.charB.setPos(1, 4, 0) self.charB.reparentTo(camMgr.activeCameras["menuCam"].camNP) self.charB.loop('idle') self.createBackButton(self.btnBack_Click) # set the text of all GUI elements self.setText() self.hideBase() self.accept("LanguageChanged", self.setText) def show(self): self.title["text"] = _("Select your Character") self.showBase() def hide(self): self.hideBase() if self.charA: self.charA.hide() if self.charB: self.charB.hide() def setText(self): self.title["text"] = _("Select your Character") self.btnBack["text"] = _("Back") def btnBack_Click(self): # throw event to go back to the main menu base.messenger.send("StartGameMenu_back") def btnCharA_Click(self): # throw event to select Character A for the game base.messenger.send("StartGameMenu_CharacterA") def btnCharB_Click(self): # throw event to select Character B for the game base.messenger.send("StartGameMenu_CharacterB")
class OptionsMenu(DirectObject): def __init__(self): """Default constructor""" # create a main frame as big as the window self.frameMain = DirectFrame( # set framesize the same size as the window frameSize=(base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), image="LogoTextGlow.png", image_scale=(1.06 / 2.0, 1, 0.7 / 2.0), image_pos=(0, 0, 0.7), # position center pos=(0, 0, 0), # set tramsparent background color frameColor=(0, 0, 0, 0)) self.frameMain.setTransparency(1) self.frameMain.setBin("fixed", 100) sliderscale = 0.5 buttonScale = 0.25 textscale = 0.1 checkboxscale = 0.05 left = -0.5 right = 0.5 self.sliderTextspeed = DirectSlider( scale=sliderscale, pos=(left, 0, 0.2), range=(0.2, 0.01), scrollSize=0.01, text=_("Textspeed %0.1f%%") % (base.textWriteSpeed * 10), text_scale=textscale, text_align=TextNode.ACenter, text_pos=(0.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=base.textWriteSpeed, command=self.sliderTextspeed_ValueChanged) self.sliderTextspeed.reparentTo(self.frameMain) self.cbParticles = DirectCheckButton( text=_(" Enable Particles"), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.35), pos=(left, 0, -0.0), scale=checkboxscale, frameColor=(0, 0, 0, 0), command=self.cbParticles_CheckedChanged, rolloverSound=None, clickSound=None, pressEffect=False, boxPlacement="below", boxBorder=0.8, boxRelief=DGG.FLAT, indicator_scale=1.5, indicator_text_fg=(0.65, 0.65, 0.0, 1), indicator_text_shadow=(0, 0, 0, 0.35), indicator_frameColor=(0.15, 0.15, 0.15, 1), indicatorValue=base.particleMgrEnabled) self.cbParticles.indicator['text'] = (' ', 'x') self.cbParticles.indicator['text_pos'] = (0, 0.1) #self.cbParticles.indicator.setX(self.cbParticles.indicator, -0.5) #self.cbParticles.indicator.setZ(self.cbParticles.indicator, -0.1) #self.cbParticles.setFrameSize() self.cbParticles.setTransparency(1) self.cbParticles.reparentTo(self.frameMain) volume = base.musicManager.getVolume() self.sliderVolume = DirectSlider( scale=sliderscale, pos=(left, 0, -0.35), range=(0, 1), scrollSize=0.01, text=_("Volume %d%%") % volume * 100, text_scale=textscale, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=volume, command=self.sliderVolume_ValueChanged) self.sliderVolume.reparentTo(self.frameMain) self.lblControltype = DirectLabel(text=_("Control type"), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.35), frameColor=(0, 0, 0, 0), scale=textscale / 2, pos=(right, 0, 0.27)) self.lblControltype.setTransparency(1) self.lblControltype.reparentTo(self.frameMain) selectedControlType = 0 if base.controlType == "MouseAndKeyboard": selectedControlType = 1 self.controltype = DirectOptionMenu( pos=(right, 0, 0.18), text_fg=(1, 1, 1, 1), scale=0.1, items=[_("Keyboard"), _("Keyboard + Mouse")], initialitem=selectedControlType, frameColor=(0.15, 0.15, 0.15, 1), popupMarker_frameColor=(0.65, 0.65, 0.0, 1), popupMarker_relief=DGG.FLAT, highlightColor=(0.65, 0.65, 0.0, 1), relief=DGG.FLAT, command=self.controlType_Changed) self.controltype.reparentTo(self.frameMain) b = self.controltype.getBounds() xPos = right - ((b[1] - b[0]) / 2.0 * 0.1) self.controltype.setX(xPos) setItems(self.controltype) self.controltype.setItems = setItems self.controltype.showPopupMenu = showPopupMenu self.controltype.popupMarker.unbind(DGG.B1PRESS) self.controltype.popupMarker.bind(DGG.B1PRESS, showPopupMenu) self.controltype.unbind(DGG.B1PRESS) self.controltype.bind(DGG.B1PRESS, showPopupMenuExtra, [self.controltype]) isChecked = not base.AppHasAudioFocus img = None if base.AppHasAudioFocus: img = "AudioSwitch_on.png" else: img = "AudioSwitch_off.png" self.cbVolumeMute = DirectCheckBox( text=_("Mute Audio"), text_scale=0.5, text_align=TextNode.ACenter, text_pos=(0.0, 0.65), text_fg=(1, 1, 1, 1), pos=(right, 0, -0.35), scale=0.21 / 2.0, command=self.cbVolumeMute_CheckedChanged, rolloverSound=None, clickSound=None, relief=None, pressEffect=False, isChecked=isChecked, image=img, image_scale=0.5, checkedImage="AudioSwitch_off.png", uncheckedImage="AudioSwitch_on.png") self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) sensitivity = base.mouseSensitivity self.sliderSensitivity = DirectSlider( scale=sliderscale, pos=(right, 0, -0.075), range=(0.5, 2), scrollSize=0.01, text=_("Mouse Sensitivity %0.1fx") % sensitivity, text_scale=textscale, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(1, 1, 1, 1), thumb_frameColor=(0.65, 0.65, 0.0, 1), thumb_relief=DGG.FLAT, frameColor=(0.15, 0.15, 0.15, 1), value=sensitivity, command=self.sliderSensitivity_ValueChanged) self.sliderSensitivity.reparentTo(self.frameMain) if base.controlType == "Gamepad": self.sliderSensitivity.hide() # create the back button self.btnBack = DirectButton( scale=buttonScale, # position on the window pos=(0, 0, base.a2dBottom + 0.15), frameColor=(0, 0, 0, 0), # text properties text=_("Back"), text_scale=0.5, text_fg=(1, 1, 1, 1), text_pos=(0.0, -0.15), text_shadow=(0, 0, 0, 0.35), text_shadowOffset=(-0.05, -0.05), # sounds that should be played rolloverSound=None, clickSound=None, pressEffect=False, relief=None, # the event which is thrown on clickSound command=lambda: base.messenger.send("options_back")) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self, enableResume=False): self.frameMain.show() def hide(self): self.frameMain.hide() def cbVolumeMute_CheckedChanged(self, checked): if checked: base.disableAllAudio() else: base.enableAllAudio() def sliderVolume_ValueChanged(self): volume = round(self.sliderVolume["value"], 2) self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100) base.sfxManagerList[0].setVolume(volume) base.musicManager.setVolume(volume) def sliderSensitivity_ValueChanged(self): sensitivity = round(self.sliderSensitivity["value"], 2) self.sliderSensitivity["text"] = _( "Mouse Sensitivity %0.1fx") % sensitivity base.mouseSensitivity = sensitivity def sliderTextspeed_ValueChanged(self): newSpeed = round(self.sliderTextspeed["value"], 2) displaySpeed = 1.0 / newSpeed self.sliderTextspeed["text"] = _("Textspeed %0.1f%%") % displaySpeed base.textWriteSpeed = newSpeed def cbParticles_CheckedChanged(self, unchecked): if unchecked: base.enableParticles() else: base.disableParticles() def controlType_Changed(self, arg): if arg == _("Keyboard"): self.sliderSensitivity.hide() base.controlType = "Gamepad" elif arg == _("Keyboard + Mouse"): self.sliderSensitivity.show() base.controlType = "MouseAndKeyboard"
def _createButtons(self, cfg): ''' Creates DirectGui elements for displaying the paging and scrolling buttons. The sprite names are read from the configuration. The create DirectButtons use sprites as images. @param cfg: a ConfigVars instance ''' # button to display next page of items nxPgBtnSprite = cfg.get(PanoConstants.CVAR_INVENTORY_NEXTPAGE_SPRITE) nxPgBtnPressedSprite = cfg.get( PanoConstants.CVAR_INVENTORY_NEXTPAGE_PRESSED_SPRITE) nxPgBtnHoverSprite = cfg.get( PanoConstants.CVAR_INVENTORY_NEXTPAGE_HOVER_SPRITE) nxPgBtnPos = cfg.getVec2(PanoConstants.CVAR_INVENTORY_NEXTPAGE_POS) # button to display previous page of items pvPgBtnSprite = cfg.get(PanoConstants.CVAR_INVENTORY_PREVPAGE_SPRITE) pvPgBtnPressedSprite = cfg.get( PanoConstants.CVAR_INVENTORY_PREVPAGE_PRESSED_SPRITE) pvPgBtnHoverSprite = cfg.get( PanoConstants.CVAR_INVENTORY_PREVPAGE_HOVER_SPRITE) pvPgBtnPos = cfg.getVec2(PanoConstants.CVAR_INVENTORY_PREVPAGE_POS) # button to scroll to next items scrNxBtnSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLNEXT_SPRITE) scrNxBtnPressedSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLNEXT_PRESSED_SPRITE) scrNxBtnHoverSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLNEXT_HOVER_SPRITE) scrNxBtnPos = cfg.getVec2(PanoConstants.CVAR_INVENTORY_SCROLLNEXT_POS) # button to scroll to previous items scrPvBtnSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLPREV_SPRITE) scrPvBtnPressedSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLPREV_PRESSED_SPRITE) scrPvBtnHoverSprite = cfg.get( PanoConstants.CVAR_INVENTORY_SCROLLPREV_HOVER_SPRITE) scrPvBtnPos = cfg.getVec2(PanoConstants.CVAR_INVENTORY_SCROLLPREV_POS) sprites = self.game.getView().getSpritesFactory() origin = aspect2d.getRelativePoint(screen2d, VBase3(0, 0, 0)) # for every button define property name, position, callback, list of sprites for normal, pressed and hover state pagingButtons = [ ('nextPageButton', nxPgBtnPos, self._nextPageCallback, [(nxPgBtnSprite, 'next_page_sprite'), (nxPgBtnPressedSprite, 'next_page_pressed_sprite'), (nxPgBtnHoverSprite, 'next_page_hover_sprite')]), ('prevPageButton', pvPgBtnPos, self._previousPageCallback, [(pvPgBtnSprite, 'previous_page_sprite'), (pvPgBtnPressedSprite, 'previous_page_pressed_sprite'), (pvPgBtnHoverSprite, 'previous_page_hover_sprite')]), ('scrollNextButton', scrNxBtnPos, self._scrollNextCallback, [(scrNxBtnSprite, 'scroll_next_sprite'), (scrNxBtnPressedSprite, 'scroll_next_pressed_sprite'), (scrNxBtnHoverSprite, 'scroll_next_hover_sprite')]), ('scrollPrevButton', scrPvBtnPos, self._scrollPreviousCallback, [(scrPvBtnSprite, 'scroll_previous_sprite'), (scrPvBtnPressedSprite, 'scroll_previous_pressed_sprite'), (scrPvBtnHoverSprite, 'scroll_previous_hover_sprite')]), ] for buttonName, buttonPos, buttonCallback, spritesList in pagingButtons: buttonGeoms = [None, None, None, None] btnScrBounds = [0, 0, 0] i = 0 for spriteFile, spriteName in spritesList: print 'adding sprite %s' % spriteName if spriteFile is not None: spr = None if spriteFile.rindex('.') >= 0: ext = spriteFile[spriteFile.rindex('.'):] print ext if ResourcesTypes.isExtensionOfType( ext, PanoConstants.RES_TYPE_IMAGES): spr = Sprite(spriteName) spr.image = spriteFile else: spr = self.game.getResources().loadSprite(spriteFile) if spr: buttonGeoms[i] = sprites.createSprite(spr).nodepath buttonGeoms[i].setScale(1.0) btnScrBounds = aspect2d.getRelativePoint( screen2d, VBase3(spr.width, 1.0, spr.height)) - origin btnScrBounds[2] *= -1 i += 1 if buttonGeoms[0] is not None: b = DirectButton( geom=(buttonGeoms[0], buttonGeoms[1] if buttonGeoms[1] else buttonGeoms[0], buttonGeoms[2] if buttonGeoms[2] else buttonGeoms[0], buttonGeoms[3] if buttonGeoms[3] else buttonGeoms[0]), relief=None) b['geom_pos'] = (0, 0, 0) b.setTransparency(1) # if position is omitted from the configuration, put the button on the upper left corner if buttonPos is not None: b.setPos( aspect2d.getRelativePoint( screen2d, VBase3(buttonPos[0], 1.0, buttonPos[1]))) else: b.setPos(origin[0], 1.0, origin[2]) b.setScale(btnScrBounds[0], 1.0, btnScrBounds[2]) b.setFrameSize((0, btnScrBounds[0], 1.0, btnScrBounds[2])) b['command'] = buttonCallback b['extraArgs'] = (self.msn, ) b.hide() else: b = None setattr(self, buttonName, b)
def makePages(self, items): if self.isSetup: return self.nPages = int(math.ceil((len(items) / 4))) print "%s pages are needed." % (self.nPages) if len(items) % 4 != 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) self.pages.append(page) for item, values in items.iteritems(): pos = itemPos[itemIndex] itemImage = values.get('image') page = self.pages[pageIndex] itemType = values.get('type') supply = 0 maxSupply = 0 if itemType == ItemType.GAG: 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) ) elif itemType == ItemType.UPGRADE: 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()[upgradeID] maxSupply = values.get('maxUpgrades') if upgradeID == 0 and base.localAvatar.getMyBattle().getTurretManager().myTurret: supply = 1 buttonLabel = DirectLabel( text = '%s/%s\n%s JBS' % (str(supply), str(maxSupply), str(values.get('price'))), relief = None, parent = button, text_scale = 0.5, pos = (0, 0, -1.2) ) elif itemType == ItemType.HEAL: label = '%s' % (item) 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.75, pos = (0, 0, -1.6) ) page.addItemEntry(item, [button, buttonLabel]) page.addItem({item : values}) 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
class OptionsMenu(): def __init__(self): self.frameMain = DirectFrame(image="optionsmenu.png", image_scale=(1.7778, 1, 1), frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.frameMain.setTransparency(True) volume = base.musicManager.getVolume() self.sliderMusicVolume = DirectSlider( scale=0.5, pos=(0, 0, -0.1), range=(0, 1), scrollSize=0.01, text="Music Volume: %d%%" % volume * 100, text_scale=0.15, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), thumb_frameColor=(0.8, 0, 1, 0.75), thumb_relief=DGG.FLAT, frameColor=(0.25, 0.25, 0.55, 1), value=volume, command=self.sliderMusicVolume_ValueChanged) self.sliderMusicVolume.reparentTo(self.frameMain) volume = base.sfxManagerList[0].getVolume() self.sliderSFXVolume = DirectSlider( scale=0.5, pos=(0, 0, -0.3), range=(0, 1), scrollSize=0.01, text="SFX Volume: %d%%" % volume * 100, text_scale=0.15, text_align=TextNode.ACenter, text_pos=(.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), thumb_frameColor=(0.8, 0, 1, 0.75), thumb_relief=DGG.FLAT, frameColor=(0.25, 0.25, 0.55, 1), value=volume, command=self.sliderSFXVolume_ValueChanged) self.sliderSFXVolume.reparentTo(self.frameMain) isChecked = not base.AppHasAudioFocus img = None imgON = "AudioSwitch_on.png" imgOFF = "AudioSwitch_off.png" if base.AppHasAudioFocus: img = imgON else: img = imgOFF self.cbVolumeMute = DirectCheckBox( scale=0.5, text="Mute Audio", text_scale=0.15, text_align=TextNode.ACenter, text_pos=(0.0, 0.15), text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), pos=(0, 0, -0.5), command=self.cbVolumeMute_CheckedChanged, rolloverSound=None, clickSound=None, relief=None, pressEffect=False, isChecked=isChecked, image=img, image_scale=0.1, checkedImage=imgOFF, uncheckedImage=imgON) self.cbVolumeMute.setTransparency(True) self.cbVolumeMute.setImage() self.cbVolumeMute.reparentTo(self.frameMain) radio = base.loader.loadModel("radioBtn") radioGeom = (radio.find("**/RadioButtonReady"), radio.find("**/RadioButtonChecked")) self.lblDifficulty = DirectLabel(text="Difficulty", text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), text_scale=0.6, scale=0.15, frameColor=(0, 0, 0, 0), pos=(-0.5, 0, -0.6)) self.lblDifficulty.reparentTo(self.frameMain) self.difficulty = [base.difficulty] def createDifficultyDRB(self, text, value, initialValue, xPos): drb = DirectRadioButton( text=text, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), variable=self.difficulty, value=value, indicatorValue=initialValue, boxGeom=radioGeom, boxGeomScale=0.5, #indicator_pad = (0.1, 0.1), scale=0.05, frameColor=(0.5, 0.5, 0.5, 1), pressEffect=False, relief=1, pad=(0.5, 0, 0.5, 0.5), pos=(xPos, 0, -0.6), command=self.rbDifficulty_ValueChanged) drb.indicator.setX(drb.indicator.getX() + 0.1) drb.indicator.setZ(drb.indicator.getZ() + 0.1) drb.reparentTo(self.frameMain) return drb self.difficultyButtons = [ createDifficultyDRB(self, "Easy", [0], 1 if base.difficulty == 0 else 0, 0.5 - 0.3), createDifficultyDRB(self, "Medium", [1], 1 if base.difficulty == 1 else 0, 0.5), createDifficultyDRB(self, "Hard", [2], 1 if base.difficulty == 2 else 0, 0.5 + 0.3) ] for button in self.difficultyButtons: button.setOthers(self.difficultyButtons) self.btnBack = DirectButton(text="Back", scale=0.15, text_pos=(-0.3, -0.2), text_scale=0.6, text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1), frameColor=(0, 0, 0, 0), image=("btnExit.png", "btnExit_hover.png", "btnExit_hover.png", "btnExit_hover.png"), image_scale=(1, 1, 0.5), pos=(0, 0, -0.8), command=base.messenger.send, extraArgs=["menu_Back"]) self.btnBack.setTransparency(True) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self): self.frameMain.show() def hide(self): self.frameMain.hide() def cbVolumeMute_CheckedChanged(self, checked): if checked: base.disableAllAudio() else: base.enableAllAudio() def sliderMusicVolume_ValueChanged(self): volume = round(self.sliderMusicVolume["value"], 2) self.sliderMusicVolume["text"] = "Music Volume: %d%%" % int( volume * 100) base.musicManager.setVolume(volume) def sliderSFXVolume_ValueChanged(self): volume = round(self.sliderSFXVolume["value"], 2) self.sliderSFXVolume["text"] = "SFX Volume: %d%%" % int(volume * 100) base.sfxManagerList[0].setVolume(volume) def rbDifficulty_ValueChanged(self): base.difficulty = self.difficulty[0]
class MainMenu(DirectObject): """This class represents the main menu as seen directly after the application has been started""" def __init__(self): # loading music self.menuMusic = loader.loadMusic("music/01Menu.mp3") self.menuMusic.setLoop(True) # create a main frame as big as the window self.frameMain = DirectFrame( # set framesize the same size as the window frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), # position center pos = (0, 0, 0), # set tramsparent background color frameColor = (0.15, 0.15, 0.15, 1)) #self.frameMain.reparentTo(render2d) self.menuBackground = OnscreenImage( image = 'gui/Background.png', scale = (1.66, 1, 1), pos = (0, 0, 0)) self.menuBackground.reparentTo(self.frameMain) self.defaultBtnMap = base.loader.loadModel("gui/button_map") self.buttonGeom = ( self.defaultBtnMap.find("**/button_ready"), self.defaultBtnMap.find("**/button_click"), self.defaultBtnMap.find("**/button_rollover"), self.defaultBtnMap.find("**/button_disabled")) self.defaultTxtMap = base.loader.loadModel("gui/textbox_map") self.textboxGeom = self.defaultTxtMap.find("**/textbox") monospace = loader.loadFont('gui/DejaVuSansMono.ttf') defaultFont = loader.loadFont('gui/eufm10.ttf') # create the title self.textscale = 0.25 self.title = DirectLabel( # scale and position scale = self.textscale, pos = (0.0, 0.0, base.a2dTop - self.textscale), # frame frameColor = (0, 0, 0, 0), # Text text = "Dungeon Crawler", text_align = TextNode.ACenter, text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont) self.title.setTransparency(1) self.title.reparentTo(self.frameMain) # create a host button self.btnHostPos = Vec3(0, 0, .45) self.btnHostScale = 0.25 self.btnHost = DirectButton( # Scale and position scale = self.btnHostScale, pos = self.btnHostPos, # Text text = "Host", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, # Frame geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, # Functionality command = self.host, rolloverSound = None, clickSound = None) self.btnHost.setTransparency(1) self.btnHost.reparentTo(self.frameMain) # create a join button self.btnJoinPos = Vec3(0, 0, 0) self.btnJoinScale = 0.25 self.btnJoin = DirectButton( scale = self.btnJoinScale, pos = self.btnJoinPos, text = "Join", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = self.join, rolloverSound = None, clickSound = None) self.btnJoin.setTransparency(1) self.btnJoin.reparentTo(self.frameMain) # create the IP input field self.txtIPPos = Vec3(0, 0, -.30) self.txtIPScale = 0.25 self.txtIPWidth = 9 self.txtIP = DirectEntry( # scale and position pos = self.txtIPPos, scale = self.txtIPScale, width = self.txtIPWidth, # Text entryFont = monospace, text_align = TextNode.ACenter, text = "", text_scale = 0.5, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (0.04, 0.04), initialText = "127.0.0.1", numLines = 1, # Frame geom = self.textboxGeom, frameColor = (0, 0, 0, 0), relief = 0, # Functionality command = self.join, focusInCommand = self.clearText) self.txtIP.reparentTo(self.frameMain) # create an exit button self.btnExitPos = Vec3(0, 0, -.75) self.btnExitScale = 0.25 self.btnExit = DirectButton( scale = self.btnExitScale, pos = self.btnExitPos, text = "Exit", text_scale = 0.8, text_pos = (0, -0.2), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, command = lambda: base.messenger.send("escape"), rolloverSound = None, clickSound = None) self.btnExit.setTransparency(1) self.btnExit.reparentTo(self.frameMain) # create a mute checkbox self.cbVolumeMute = DirectCheckBox( # set size scale = (0.1, 0.1, 0.1), frameSize = (-1, 1, 1, -1), # functionality and visuals command = self.cbVolumeMute_CheckedChanged, isChecked = True, checkedImage = "gui/SoundSwitch_off.png", uncheckedImage = "gui/SoundSwitch_on.png", # mouse behaviour relief = 0, pressEffect = False, rolloverSound = None, clickSound = None ) self.cbVolumeMute.setTransparency(1) self.cbVolumeMute.reparentTo(self.frameMain) self.cbVolumeMute.commandFunc(None) # catch window resizes and recalculate the aspectration self.accept("window-event", self.recalcAspectRatio) self.accept("showerror", self.showError) # show the menu right away self.show() def host(self): """Function which will be called by pressing the host button""" self.hide() base.messenger.send("start_server") def join(self, ip=None): """Function which will be called by pressing the join button""" if ip == None: ip = self.txtIP.get(True) if ip == "": return self.hide() base.messenger.send("start_client", [ip]) def showError(self, msg): self.show() self.dialog = OkDialog( dialogName="ErrorDialog", text="Error: {}".format(msg), command=self.closeDialog) def closeDialog(self, args): self.dialog.hide() def show(self): """Show the GUI""" self.frameMain.show() self.menuMusic.play() def hide(self): """Hide the GUI""" self.frameMain.hide() self.menuMusic.stop() def clearText(self): """Function to clear the text that was previously entered in the IP input field""" self.txtIP.enterText("") def cbVolumeMute_CheckedChanged(self, checked): if bool(checked): base.disableAllAudio() else: base.enableAllAudio() def recalcAspectRatio(self, window): """get the new aspect ratio to resize the mainframe""" # set the mainframe size to the window borders again self.frameMain["frameSize"] = ( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom) # calculate new aspec tratio wp = window.getProperties() aspX = 1.0 aspY = 1.0 wpXSize = wp.getXSize() wpYSize = wp.getYSize() if wpXSize > wpYSize: aspX = wpXSize / float(wpYSize) else: aspY = wpYSize / float(wpXSize) # calculate new position/size/whatever of the gui items self.title.setPos(0.0, 0.0, base.a2dTop - self.textscale) self.menuBackground.setScale(1.0 * aspX, 1.0, 1.0 * aspY) self.cbVolumeMute.setPos(base.a2dRight - 0.15, 0, base.a2dBottom + 0.15)
class CharacterSelection: def __init__(self): self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) width = abs(base.a2dLeft) + base.a2dRight red = loader.loadTexture("assets/gui/CharRedBG.png") red.setWrapU(Texture.WM_repeat) red.setWrapV(Texture.WM_repeat) self.char1Frame = DirectFrame(text="Player 1", text_fg=(1, 1, 1, 1), text_scale=0.1, text_pos=(0, base.a2dTop - 0.2), frameSize=(-width / 6.0, width / 6.0, base.a2dBottom, base.a2dTop), frameTexture=red, pos=(base.a2dLeft + width / 6.0, 0, 0)) self.char1Frame.updateFrameStyle() self.char1Frame.setTransparency(1) self.char1Frame.reparentTo(self.frameMain) blue = loader.loadTexture("assets/gui/CharBlueBG.png") blue.setWrapU(Texture.WM_repeat) blue.setWrapV(Texture.WM_repeat) self.char2Frame = DirectFrame(text="Player 2", text_fg=(1, 1, 1, 1), text_scale=0.1, text_pos=(0, base.a2dTop - 0.2), frameSize=(-width / 6.0, width / 6.0, base.a2dBottom, base.a2dTop), frameTexture=blue, pos=(base.a2dRight - width / 6.0, 0, 0)) self.char2Frame.setTransparency(1) self.char2Frame.reparentTo(self.frameMain) self.footerFrame = DirectFrame(text="PLAYER 1 - CHOOSE YOUR CHARACTER", text_fg=(1, 1, 1, 1), text_scale=0.08, text_pos=(0, -0.03), frameSize=(base.a2dLeft, base.a2dRight, 0.1, -0.1), pos=(0, 0, base.a2dBottom + 0.2), frameColor=(0, 0, 0, 0.5)) self.footerFrame.setTransparency(1) self.footerFrame.reparentTo(self.frameMain) self.charSelectFrame = DirectFrame( text="VS", text_fg=(1, 1, 1, 1), text_scale=0.1, text_pos=(0, base.a2dTop - 0.2), frameSize=(-width / 6.0, width / 6.0, base.a2dBottom, base.a2dTop), frameColor=(0, 0, 0, 0)) self.charSelectFrame.reparentTo(self.frameMain) self.btnChar1 = self.createCharacterButton( (-0.2, 0, 0), "assets/gui/Char1Button.png", 1) self.btnChar1.reparentTo(self.charSelectFrame) self.btnChar2 = self.createCharacterButton( (0.2, 0, 0), "assets/gui/Char2Button.png", 2) self.btnChar2.reparentTo(self.charSelectFrame) self.btnBack = DirectButton(text="BACK", text_fg=(1, 1, 1, 1), text_align=TextNode.ALeft, scale=0.1, pad=(0.15, 0.15), pos=(base.a2dLeft + 0.08, 0, -0.03), frameColor=((0.2, 0.2, 0.2, 0.8), (0.4, 0.4, 0.4, 0.8), (0.4, 0.4, 0.4, 0.8), (0.1, 0.1, 0.1, 0.8)), relief=1, command=base.messenger.send, extraArgs=["CharSelection-Back"], pressEffect=False, rolloverSound=None, clickSound=None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.footerFrame) self.btnStart = DirectButton(text="START", text_fg=(1, 1, 1, 1), text_align=TextNode.ARight, scale=0.1, pad=(0.15, 0.15), pos=(base.a2dRight - 0.08, 0, -0.03), relief=1, frameColor=((0.2, 0.2, 0.2, 0.8), (0.4, 0.4, 0.4, 0.8), (0.4, 0.4, 0.4, 0.8), (0.1, 0.1, 0.1, 0.8)), command=base.messenger.send, extraArgs=["CharSelection-Start"], pressEffect=False, rolloverSound=None, clickSound=None) self.btnStart.setTransparency(1) self.btnStart.reparentTo(self.footerFrame) self.btnStart["state"] = DGG.DISABLED self.hide() def createCharacterButton(self, pos, image, charNr): btn = DirectButton(scale=0.1, relief=0, frameColor=(0, 0, 0, 0), pos=pos, image=image, command=self.selectCharacter, extraArgs=[charNr], rolloverSound=None, clickSound=None) btn.setTransparency(1) return btn def selectCharacter(self, charNr): if self.char1Frame["image"] == None: self.char1Frame["image"] = "assets/gui/Char{}_L.png".format(charNr) self.char1Frame["image_scale"] = (0.5, 1, 1) self.selectedCharacter1 = charNr self.footerFrame["text"] = "PLAYER 2 - CHOOSE YOUR CHARACTER" elif self.char2Frame["image"] == None: self.char2Frame["image"] = "assets/gui/Char{}_R.png".format(charNr) self.char2Frame["image_scale"] = (0.5, 1, 1) self.selectedCharacter2 = charNr self.btnStart["state"] = DGG.NORMAL self.footerFrame["text"] = "START THE FIGHT >" def show(self): self.selectedCharacter1 = None self.selectedCharacter2 = None self.char1Frame["image"] = None self.char2Frame["image"] = None self.footerFrame["text"] = "PLAYER 1 - CHOOSE YOUR CHARACTER" self.btnStart["state"] = DGG.DISABLED self.frameMain.show() def hide(self): self.frameMain.hide()
def __init__(self): self._weapon_buts = {} self._turn_snd = loader.loadSfx( # noqa: F821 "sounds/train/railroad_switch.ogg" ) frame = DirectFrame( parent=base.a2dBottomRight, # noqa: F821 frameSize=(-0.09, 0.09, -0.28, 0.28), pos=(-0.09, 0, 0.28), frameTexture=GUI_PIC + "metal1.png", ) frame.setTransparency(TransparencyAttrib.MAlpha) DirectFrame( # an icon for the locomotive durability parent=frame, frameSize=(-0.023, 0.023, -0.023, 0.023), pos=(0.05, 0, 0.24), frameTexture=GUI_PIC + "train.png", ).setTransparency(TransparencyAttrib.MAlpha) DirectFrame( # an icon for the locomotive speed parent=frame, frameSize=(-0.028, 0.028, -0.023, 0.023), pos=(-0.012, 0, 0.24), frameTexture=GUI_PIC + "speed.png", ).setTransparency(TransparencyAttrib.MAlpha) self._durability = DirectWaitBar( parent=frame, frameSize=(-0.225, 0.225, -0.002, 0.002), frameColor=(0.35, 0.35, 0.35, 1), range=1000, value=1000, barColor=(0.42, 0.42, 0.8, 1), pos=(0.05, 0, -0.025), ) self._durability.setR(-90) self._speed = DirectWaitBar( parent=frame, frameSize=(-0.225, 0.225, -0.002, 0.002), frameColor=(0.35, 0.35, 0.35, 1), range=1, value=1, barColor=(1, 0.63, 0, 0.6), pos=(-0.012, 0, -0.025), ) self._speed.setR(-90) DirectLabel( # speed gauge scale parent=frame, pos=(-0.05, 0, 0.19), frameSize=(-0.25, 0.25, -0.01, 0.01), frameColor=(0, 0, 0, 0), text="40-\n\n-\n\n-\n\n-\n\n20-\n\n-\n\n-\n\n-\n\n0-", text_scale=0.028, text_fg=SILVER_COL, ) frame_miles = DirectFrame( frameSize=(-0.115, 0.115, -0.06, 0.05), pos=(0, 0, -0.95), frameTexture=GUI_PIC + "metal1.png", sortOrder=-1, ) frame_miles.set_transparency(TransparencyAttrib.MAlpha) but = DirectButton( parent=frame_miles, frameSize=(-0.015, 0.015, -0.025, 0.025), frameTexture=GUI_PIC + "grenade.png", pos=(-0.075, 0, 0.015), relief="flat", ) but.setTransparency(TransparencyAttrib.MAlpha) but.bind(DGG.ENTER, self._highlight_weapon_but, extraArgs=[but]) but.bind(DGG.EXIT, self._dehighlight_weapon_but, extraArgs=[but]) self._weapon_buts["Grenade Launcher"] = { "but": but, "reload_step": 0, "dis_command": None, "reloading_len": 13, "frame": DirectFrame( parent=frame_miles, frameColor=(0, 0, 0, 0.25), pos=(-0.075, 0, -0.01), frameSize=(-0.013, 0.013, 0, 0.05), ), } but = DirectButton( parent=frame_miles, frameSize=(-0.015, 0.015, -0.025, 0.025), frameTexture=GUI_PIC + "machine_gun.png", pos=(0, 0, 0.015), relief="flat", ) but.setTransparency(TransparencyAttrib.MAlpha) but.bind(DGG.ENTER, self._highlight_weapon_but, extraArgs=[but]) but.bind(DGG.EXIT, self._dehighlight_weapon_but, extraArgs=[but]) self._weapon_buts["Machine Gun"] = { "but": but, "reload_step": 0, "dis_command": None, "reloading_len": 22, "frame": DirectFrame( parent=frame_miles, frameColor=(0, 0, 0, 0.25), pos=(0, 0, -0.01), frameSize=(-0.013, 0.013, 0, 0.05), ), } but = DirectButton( parent=frame_miles, frameSize=(-0.015, 0.015, -0.025, 0.025), frameTexture=GUI_PIC + "cluster_rocket.png", pos=(0.075, 0, 0.015), relief="flat", ) but.setTransparency(TransparencyAttrib.MAlpha) but.bind(DGG.ENTER, self._highlight_weapon_but, extraArgs=[but]) but.bind(DGG.EXIT, self._dehighlight_weapon_but, extraArgs=[but]) self._weapon_buts["Cluster Howitzer"] = { "but": but, "reload_step": 0, "dis_command": None, "reloading_len": 45, "frame": DirectFrame( parent=frame_miles, frameColor=(0, 0, 0, 0.25), pos=(0.075, 0, -0.01), frameSize=(-0.013, 0.013, 0, 0.05), ), } self._miles_meter = DirectLabel( parent=frame_miles, text="0000000", text_font=base.main_font, # noqa: F821 frameSize=(0.1, 0.1, 0.15, 0.15), text_scale=(0.033, 0.031), text_fg=RUST_COL, pos=(0, 0, -0.04), ) taskMgr.doMethodLater( # noqa: F821 0.25, self._update_speed, "update_speed_indicator" ) self._fork_lab = None
class DirectWindow( DirectFrame ): def __init__( self, pos = ( -.5, .5), title = 'Title', curSize = ( 1, 1), maxSize = ( 1, 1 ), minSize = ( .5, .5 ), backgroundColor = ( 1, 1, 1, 1 ), borderColor = ( 1, 1, 1, 1 ), titleColor = ( 1, 1, 1, 1 ), borderSize = 0.04, titleSize = 0.06, closeButton = False, windowParent = aspect2d, preserve = True, preserveWhole = True, ): self.preserve = preserve self.preserveWhole = preserveWhole self.windowParent = windowParent self.windowPos = pos DirectFrame.__init__( self, parent = windowParent, pos = ( self.windowPos[0], 0, self.windowPos[1] ), frameColor = ( 0, 0, 0, 0 ), frameTexture = loader.loadTexture( DIRECTORY+'transparent.png' ) ) self.setTransparency(True) # the title part of the window, drag around to move the window self.headerHeight = titleSize h = -self.headerHeight self.windowHeaderLeft = DirectButton( parent = self, frameTexture = DEFAULT_TITLE_GEOM_LEFT, frameSize = ( -.5, .5, -.5, .5 ), borderWidth = ( 0, 0 ), relief = DGG.FLAT, frameColor = titleColor, ) self.windowHeaderCenter = DirectButton( parent = self, frameTexture = DEFAULT_TITLE_GEOM_CENTER, frameSize = ( -.5, .5, -.5, .5 ), borderWidth = ( 0, 0 ), relief = DGG.FLAT, frameColor = titleColor, ) if closeButton: rightTitleGeom = DEFAULT_TITLE_GEOM_RIGHT_CLOSE command = self.destroy else: rightTitleGeom = DEFAULT_TITLE_GEOM_RIGHT command = None self.windowHeaderRight = DirectButton( parent = self, frameTexture = rightTitleGeom, frameSize = ( -.5, .5, -.5, .5 ), borderWidth = ( 0, 0 ), relief = DGG.FLAT, frameColor = titleColor, command = command ) self.windowHeaderLeft.setTransparency(True) self.windowHeaderCenter.setTransparency(True) self.windowHeaderRight.setTransparency(True) self.windowHeaderLeft.bind( DGG.B1PRESS, self.startWindowDrag ) self.windowHeaderCenter.bind( DGG.B1PRESS, self.startWindowDrag ) self.windowHeaderRight.bind( DGG.B1PRESS, self.startWindowDrag ) # this is not handled correctly, if a window is dragged which has been # created before another it will not be released # check the bugfixed startWindowDrag function #self.windowHeader.bind(DGG.B1RELEASE,self.stopWindowDrag) text = TextNode('WindowTitleTextNode') text.setText(title) text.setAlign(TextNode.ACenter) text.setTextColor( 0, 0, 0, 1 ) text.setShadow(0.05, 0.05) text.setShadowColor( 1, 1, 1, 1 ) self.textNodePath = self.attachNewNode(text) self.textNodePath.setScale(self.headerHeight*0.8) # the content part of the window, put stuff beneath # contentWindow.getCanvas() to put it into it self.maxVirtualSize = maxSize self.minVirtualSize = minSize self.resizeSize = borderSize self.contentWindow = DirectScrolledFrame( parent = self, pos = ( 0, 0, -self.headerHeight ), canvasSize = ( 0, self.maxVirtualSize[0], 0, self.maxVirtualSize[1] ), frameColor = ( 0, 0, 0, 0), # defines the background color of the resize-button relief = DGG.FLAT, borderWidth = (0, 0), verticalScroll_frameSize = [0, self.resizeSize, 0, 1], horizontalScroll_frameSize = [0, 1, 0, self.resizeSize], # resize the scrollbar according to window size verticalScroll_resizeThumb = False, horizontalScroll_resizeThumb = False, # define the textures for the scrollbars verticalScroll_frameTexture = VERTICALSCROLL_FRAMETEXTURE, verticalScroll_incButton_frameTexture = VERTICALSCROLL_INCBUTTON_FRAMETEXTURE, verticalScroll_decButton_frameTexture = VERTICALSCROLL_DECBUTTON_FRAMETEXTURE, verticalScroll_thumb_frameTexture = VERTICALSCROLL_TUMB_FRAMETEXTURE, horizontalScroll_frameTexture = HORIZONTALSCROLL_FRAMETEXTURE, horizontalScroll_incButton_frameTexture = HORIZONTALSCROLL_INCBUTTON_FRAMETEXTURE, horizontalScroll_decButton_frameTexture = HORIZONTALSCROLL_DECBUTTON_FRAMETEXTURE, horizontalScroll_thumb_frameTexture = HORIZONTALSCROLL_TUMB_FRAMETEXTURE, # make all flat, so the texture is as we want it verticalScroll_relief = DGG.FLAT, verticalScroll_thumb_relief = DGG.FLAT, verticalScroll_decButton_relief = DGG.FLAT, verticalScroll_incButton_relief = DGG.FLAT, horizontalScroll_relief = DGG.FLAT, horizontalScroll_thumb_relief = DGG.FLAT, horizontalScroll_decButton_relief = DGG.FLAT, horizontalScroll_incButton_relief = DGG.FLAT, # colors verticalScroll_frameColor = borderColor, verticalScroll_incButton_frameColor = borderColor, verticalScroll_decButton_frameColor = borderColor, verticalScroll_thumb_frameColor = borderColor, horizontalScroll_frameColor = borderColor, horizontalScroll_incButton_frameColor = borderColor, horizontalScroll_decButton_frameColor = borderColor, horizontalScroll_thumb_frameColor = borderColor, ) self.contentWindow.setTransparency(True) # background color self.backgroundColor = DirectFrame( parent = self.contentWindow.getCanvas(), frameSize = ( 0, self.maxVirtualSize[0], 0, self.maxVirtualSize[1] ), frameColor = backgroundColor, relief = DGG.FLAT, borderWidth = ( .01, .01), ) self.backgroundColor.setTransparency(True) # Add a box self.box = boxes.VBox(parent = self.getCanvas()) # is needed for some nicer visuals of the resize button (background) self.windowResizeBackground = DirectButton( parent = self, frameSize = ( -.5, .5, -.5, .5 ), borderWidth = ( 0, 0 ), scale = ( self.resizeSize, 1, self.resizeSize ), relief = DGG.FLAT, frameColor = backgroundColor, ) # the resize button of the window self.windowResize = DirectButton( parent = self, frameSize = ( -.5, .5, -.5, .5 ), borderWidth = ( 0, 0 ), scale = ( self.resizeSize, 1, self.resizeSize ), relief = DGG.FLAT, frameTexture = DEFAULT_RESIZE_GEOM, frameColor = borderColor, ) self.windowResize.setTransparency(True) self.windowResize.bind(DGG.B1PRESS,self.startResizeDrag) self.windowResize.bind(DGG.B1RELEASE,self.stopResizeDrag) # offset then clicking on the resize button from the mouse to the resizebutton # position, required to calculate the position / scaling self.offset = None self.taskName = "resizeTask-%s" % str(hash(self)) # do sizing of the window (minimum) #self.resize( Vec3(0,0,0), Vec3(0,0,0) ) # maximum #self.resize( Vec3(100,0,-100), Vec3(0,0,0) ) self.resize( Vec3(curSize[0], 0, -curSize[1]), Vec3(0,0,0)) def getCanvas(self): return self.contentWindow.getCanvas() # dragging functions def startWindowDrag( self, param ): self.wrtReparentTo( aspect2dMouseNode ) self.ignoreAll() self.accept( 'mouse1-up', self.stopWindowDrag ) def stopWindowDrag( self, param=None ): # this is called 2 times (bug), so make sure it's not already parented to aspect2d if self.getParent() != self.windowParent: self.wrtReparentTo( self.windowParent ) if self.preserve: if self.preserveWhole: if self.getZ() > 1: self.setZ(1) elif self.getZ() < -1 - self.getHeight(): self.setZ(-1 - self.getHeight()) if self.getX() > base.a2dRight - self.getWidth(): self.setX(base.a2dRight - self.getWidth()) elif self.getX() < base.a2dLeft: self.setX(base.a2dLeft) else: if self.getZ() > 1: self.setZ(1) elif self.getZ() < -1 + self.headerHeight: self.setZ(-1 + self.headerHeight) if self.getX() > base.a2dRight - self.headerHeight: self.setX(base.a2dRight - self.headerHeight) elif self.getX() < base.a2dLeft + self.headerHeight - self.getWidth(): self.setX(base.a2dLeft + self.headerHeight - self.getWidth()) #else: #Window moved beyond reach. Destroy window? # resize functions def resize( self, mPos, offset ): mXPos = max( min( mPos.getX(), self.maxVirtualSize[0] ), self.minVirtualSize[0]) mZPos = max( min( mPos.getZ(), -self.minVirtualSize[1] ), -self.maxVirtualSize[1]-self.headerHeight) self.windowResize.setPos( mXPos-self.resizeSize/2., 0, mZPos+self.resizeSize/2. ) self.windowResizeBackground.setPos( mXPos-self.resizeSize/2., 0, mZPos+self.resizeSize/2. ) self['frameSize'] = (0, mXPos, 0, mZPos) self.windowHeaderLeft.setPos( self.headerHeight/2., 0, -self.headerHeight/2. ) self.windowHeaderLeft.setScale( self.headerHeight, 1, self.headerHeight ) self.windowHeaderCenter.setPos( mXPos/2., 0, -self.headerHeight/2. ) self.windowHeaderCenter.setScale( mXPos - self.headerHeight*2., 1, self.headerHeight ) self.windowHeaderRight.setPos( mXPos-self.headerHeight/2., 0, -self.headerHeight/2. ) self.windowHeaderRight.setScale( self.headerHeight, 1, self.headerHeight ) self.contentWindow['frameSize'] = ( 0, mXPos, mZPos+self.headerHeight, 0) self.textNodePath.setPos( mXPos/2., 0, -self.headerHeight/3.*2. ) # show and hide that small background for the window sizer if mXPos == self.maxVirtualSize[0] and \ mZPos == -self.maxVirtualSize[1]-self.headerHeight: self.windowResizeBackground.hide() else: self.windowResizeBackground.show() def resizeTask( self, task=None ): mPos = aspect2dMouseNode.getPos( self )+self.offset self.resize( mPos, self.offset ) return task.cont def startResizeDrag( self, param ): self.offset = self.windowResize.getPos( aspect2dMouseNode ) taskMgr.remove( self.taskName ) taskMgr.add( self.resizeTask, self.taskName ) def stopResizeDrag( self, param ): taskMgr.remove( self.taskName ) # get the window to the front self.wrtReparentTo( self.windowParent ) def addHorizontal(self, widgets): """ Accepts a list of directgui objects which are added to a horizontal box, which is then added to the vertical stack. """ hbox = boxes.HBox() for widget in widgets: hbox.pack(widget) self.box.pack(hbox) self.updateMaxSize() def addVertical(self, widgets): """ Accepts a list of directgui objects which are added to a vertical box, which is then added to the vertical stack. May cause funky layout results. """ #vbox = boxes.VBox() for widget in widgets: self.box.pack(widget) self.updateMaxSize() def add(self, widgets): """Shortcut function for addVertical""" self.addVertical(widgets) def updateMaxSize(self): """Updates the max canvas size to include all items packed. Window is resized to show all contents.""" bottomLeft, topRight = self.box.getTightBounds() self.maxVirtualSize = (topRight[0], -bottomLeft[2]) self.contentWindow['canvasSize'] = ( 0, self.maxVirtualSize[0], -self.maxVirtualSize[1], 0) self.backgroundColor['frameSize'] = ( 0, self.maxVirtualSize[0], -self.maxVirtualSize[1], 0 ) #perhaps this should be optional -- automatically resize for new elements self.reset() def reset(self): """Poorly named function that resizes window to fit all contents""" self.resize( Vec3(self.maxVirtualSize[0], 0, -self.maxVirtualSize[1]-self.headerHeight), Vec3(0,0,0))
class Credits: def __init__(self): self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight, base.a2dBottom, base.a2dTop), frameColor=(0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) tpBig = TextProperties() tpBig.setTextScale(1.5) tpSmall = TextProperties() tpSmall.setTextScale(0.75) tpUs = TextProperties() tpUs.setUnderscore(True) tpMgr = TextPropertiesManager.getGlobalPtr() tpMgr.setProperties("big", tpBig) tpMgr.setProperties("small", tpSmall) tpMgr.setProperties("us", tpUs) creditsText = "" with open("credits.txt") as f: creditsText = f.read() self.lblCredits = DirectLabel(text=creditsText, text_fg=(1, 1, 1, 1), text_bg=(0, 0, 0, 0), frameColor=(0, 0, 0, 0), text_align=TextNode.ACenter, scale=0.1, pos=(0, 0, base.a2dTop - 0.2)) self.lblCredits.setTransparency(1) self.lblCredits.reparentTo(self.frameMain) self.creditsScroll = LerpPosInterval(self.lblCredits, 12.0, (0, 0, base.a2dTop + 3.5), startPos=(0, 0, base.a2dBottom), name="CreditsScroll") self.btnBack = DirectButton(text="BACK", text_fg=(1, 1, 1, 1), text_align=TextNode.ALeft, scale=0.1, pad=(0.15, 0.15), pos=(base.a2dLeft + 0.08, 0, base.a2dBottom + 0.05), frameColor=( (0.2, 0.2, 0.2, 0.8), (0.4, 0.4, 0.4, 0.8), (0.4, 0.4, 0.4, 0.8), (0.1, 0.1, 0.1, 0.8), ), relief=1, command=base.messenger.send, extraArgs=["Credits-Back"], pressEffect=False, rolloverSound=None, clickSound=None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.frameMain) self.hide() def show(self): self.frameMain.show() self.creditsScroll.loop() def hide(self): self.frameMain.hide() self.creditsScroll.finish()
class HostMenu(DirectObject): def __init__(self): self.defaultBtnMap = base.loader.loadModel("gui/button_map") self.buttonGeom = ( self.defaultBtnMap.find("**/button_ready"), self.defaultBtnMap.find("**/button_click"), self.defaultBtnMap.find("**/button_rollover"), self.defaultBtnMap.find("**/button_disabled")) defaultFont = loader.loadFont('gui/eufm10.ttf') self.logFrame = DirectScrolledFrame( canvasSize = (0, base.a2dRight * 2, -5, 0), frameSize = (0, base.a2dRight * 2, (base.a2dBottom+.2) * 2, 0), frameColor = (0.1, 0.1, 0.1, 1)) self.logFrame.reparentTo(base.a2dTopLeft) # create the info and server debug output self.textscale = 0.1 self.txtinfo = OnscreenText( scale = self.textscale, pos = (0.1, -0.1), text = "", align = TextNode.ALeft, fg = (0.1,1.0,0.15,1), bg = (0, 0, 0, 0), shadow = (0, 0, 0, 1), shadowOffset = (-0.02, -0.02)) self.txtinfo.setTransparency(1) self.txtinfo.reparentTo(self.logFrame.getCanvas()) # create a close Server button self.btnBackPos = Vec3(0.4, 0, 0.2) self.btnBackScale = 0.25 self.btnBack = DirectButton( # Scale and position scale = self.btnBackScale, pos = self.btnBackPos, # Text text = "Quit Server", text_scale = 0.45, text_pos = (0, -0.1), text_fg = (0.82,0.85,0.87,1), text_shadow = (0, 0, 0, 1), text_shadowOffset = (-0.02, -0.02), text_font = defaultFont, # Frame geom = self.buttonGeom, frameColor = (0, 0, 0, 0), relief = 0, pressEffect = False, # Functionality command = self.back, rolloverSound = None, clickSound = None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(base.a2dBottomLeft) # catch window resizes and recalculate the aspectration self.accept("window-event", self.recalcAspectRatio) self.accept("addLog", self.addLog) def show(self): self.logFrame.show() self.btnBack.show() def hide(self): self.logFrame.hide() self.btnBack.hide() def back(self): self.hide() base.messenger.send("stop_server") self.addLog("Quit Server!") def addLog(self, text): self.txtinfo.appendText(text + "\n") textbounds = self.txtinfo.getTightBounds() self.logFrame["canvasSize"] = (0, textbounds[1].getX(), textbounds[0].getZ(), 0) def recalcAspectRatio(self, window): """get the new aspect ratio to resize the mainframe""" # set the mainframe size to the window borders again self.logFrame["frameSize"] = ( 0, base.a2dRight * 2, (base.a2dBottom+.2) * 2, 0)
class LevelSelection: def __init__(self): self.frameMain = DirectFrame( frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), frameColor = (0.05, 0.05, 0.05, 1)) self.frameMain.setTransparency(1) self.btnLevel1 = self.createLevelButton( (-0.6, 0, 0.15), "assets/gui/Level1Button.png", 1) self.btnLevel1.reparentTo(self.frameMain) self.btnLevel2 = self.createLevelButton( (0.6, 0, 0.15), "assets/gui/Level2Button.png", 2) self.btnLevel2.reparentTo(self.frameMain) self.footerFrame = DirectFrame( text = "SELECT THE ARENA", text_fg = (1,1,1,1), text_scale = 0.08, text_pos = (0, -0.03), frameSize = (base.a2dLeft, base.a2dRight, -0.1, 0.1), pos = (0, 0, base.a2dBottom + 0.2), frameColor = (0, 0, 0, 0.5)) self.footerFrame.setTransparency(1) self.footerFrame.reparentTo(self.frameMain) self.btnBack = DirectButton( text = "BACK", text_fg = (1,1,1,1), text_align = TextNode.ALeft, scale = 0.1, pad = (0.15, 0.15), pos = (base.a2dLeft + 0.08, 0, -0.03), frameColor = ( (0.2,0.2,0.2,0.8), (0.4,0.4,0.4,0.8), (0.4,0.4,0.4,0.8), (0.1,0.1,0.1,0.8), ), relief = 1, command = base.messenger.send, extraArgs = ["LevelSelection-Back"], pressEffect = False, rolloverSound = None, clickSound = None) self.btnBack.setTransparency(1) self.btnBack.reparentTo(self.footerFrame) self.hide() def createLevelButton(self, pos, image, levelNr): btn = DirectButton( scale = (0.5, 1, 0.75), relief = 0, frameColor = (0,0,0,0), pos = pos, image = image, command = self.selectLevel, extraArgs = [levelNr], rolloverSound = None, clickSound = None) btn.setTransparency(1) return btn def selectLevel(self, level): self.selectedLevel = level base.messenger.send("LevelSelection-Start") def show(self): self.frameMain.show() def hide(self): self.frameMain.hide()