def initUI(self): # initialize drone control panel buttonSize = (-4, 4, -.2, .8) buttonDistance = 0.15 frame = DirectFrame(frameColor=(.2, .2, .2, 1), frameSize=(-.5, .5, -.7, .15), pos=(-.9, 0, -.6), scale=.5) button = DirectButton(text="Start", scale=.1, frameSize=buttonSize, command=self.startLandAll) button["extraArgs"] = [button] button.reparentTo(frame) button = DirectButton(text="Random Target", scale=.1, frameSize=buttonSize, command=self.setRandomTargets) button.reparentTo(frame) button.setPos(Vec3(0, 0, -1 * buttonDistance)) button = DirectButton(text="Stop", scale=.1, frameSize=buttonSize, command=self.stopAll) button.reparentTo(frame) button.setPos(Vec3(0, 0, -2 * buttonDistance)) button = DirectButton(text="Return", scale=.1, frameSize=buttonSize, command=self.returnToWaitingPosition) button.reparentTo(frame) button.setPos(Vec3(0, 0, -3 * buttonDistance)) button = DirectButton(text="Connect", scale=.1, frameSize=buttonSize, command=self.toggleConnections) button["extraArgs"] = [button] button.reparentTo(frame) button.setPos(Vec3(0, 0, -4 * buttonDistance)) # initialize an UI element with all available formations loadFormationSelectionFrame(self)
def __init__(self, text_name, selection_items, default_selection=0): name_display = DirectButton( text=text_name, command=None, extraArgs=[len(self._items)], text_align=TextNode.ALeft, scale=0.1, #left/right, forward/back, up/down pos=pos_name, text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, pressEffect=0, relief=None, textMayChange=True #text_font=base.fontLoader.load('Arial Bold.ttf') ) name_display.reparentTo(self.__menuContainer) value_display = DirectButton( text=str(selection_text), command=None, extraArgs=[len(self._items)], text_align=TextNode.ALeft, scale=0.1, #left/right, forward/back, up/down pos=pos_value, text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, pressEffect=0, relief=None, textMayChange=True #text_font=base.fontLoader.load('Arial Bold.ttf') )
def createButton(base, frame, verticlePos, Text, event): btn = DirectButton(text=Text, scale=0.2, command=base.messenger.send, pressEffect=1, extraArgs=[event]) btn.setPos(0, 0, verticlePos) btn.reparentTo(frame)
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 __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 __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
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 LoadButton(self, egg, up, over, x, y, cmd, args): maps = loader.loadModel("Assets/Images/Menus/Popups/%s" % (egg)) b = DirectButton(geom = (maps.find('**/%s' % (up)), maps.find('**/%s' % (over)), maps.find('**/%s' % (over)), maps.find('**/%s' % (up))), command = cmd, extraArgs = args, pressEffect = 0, relief = None, rolloverSound = None, clickSound = None, pos = (x, 1, y), scale = (0.5, 1, 60.0/400.0)) b.reparentTo(self.frame)
def LoadButton(self, egg, up, over, x, y, cmd, args): maps = loader.loadModel("Assets/Images/Menus/MainMenu/%s" % (egg)) b = DirectButton(geom = (maps.find('**/%s' % (up)), maps.find('**/%s' % (over)), maps.find('**/%s' % (over)), maps.find('**/%s' % (up))), command = cmd, extraArgs = args, pressEffect = 0, relief = None, rolloverSound = None, clickSound = None, pos = (x, 1, y), scale = (1, 1, 75.0/500.0)) b.reparentTo(self.node) self.buttons.append(b)
class InventorySlotButton(): def __init__(self, slotIndexX, slotIndexY, xCoord, yCoord, padding, x, y, inventorySlot, parentInventory, onClickFunction): self.xIndex = slotIndexX # The x index of the button in the inventory self.yIndex = slotIndexY # The y index of the button in the inventory self.button = None # The DirectButton self.inventorySlot = inventorySlot # The slot this button represents self.parentInventory = parentInventory # The region this slot belongs to self.LoadContent(x, y, xCoord, yCoord, padding, onClickFunction) def LoadContent(self, x, y, xCoord, yCoord, padding, onClickFunction): egg = 'inventorySlot' up = ''.join([egg, '-up']) over = ''.join([egg, '-over']) maps = loader.loadModel("Assets/Images/Inventory/%s" % ('inventorySlot')) self.button = DirectButton(geom = (maps.find('**/%s' % (up)), maps.find('**/%s' % (over)), maps.find('**/%s' % (over)), maps.find('**/%s' % (up))), command = onClickFunction, extraArgs = [self], pressEffect = 0, relief = None, rolloverSound = None, clickSound = None, scale = (128.0/1024.0, 1, 128.0/1024.0)) pos = Globals.ConvertFromImageAbsoluteToAspect2D(xCoord + x * padding, yCoord + y * padding, 1024) self.button.setPos(pos[0], 0, pos[1]) def ReparentTo(self, node): self.button.reparentTo(node) def GetPos(self): return self.button.getPos() def GetParentInventory(self): return self.parentInventory def GetInventorySlot(self): return self.inventorySlot def GetSlotIndices(self): return [self.xIndex, self.yIndex]
def createButton(self, text, command, verticalPos, horisontalPos=0, frame_size=(-8, 8, -0.6, 1)): btn = DirectButton(text=(text, text, f" {text}!", text), text_fg=(1, 1, 1, 1), pad=(0.7, 0.3), frameSize=frame_size, frameTexture="./Images/Button_Frame.png", relief=1, text_font=thunderstrike, text_scale=0.9, scale=0.1, command=command, pos=(horisontalPos, 0, verticalPos), textMayChange=1) btn.reparentTo(self.menu) return btn
def loadFormationSelectionFrame(manager): """Loads all formations files in the same directory as this .py file and builds a UI element with buttons for each formation. Formations are .csv files where the nth line is the x, y, z coordinate of the nth drone.""" manager = manager formations = [ ] # a list of formations, which are lists consisting of the name and the positions as a numpy array # load all .txt files in the formations folder directory = os.path.dirname( os.path.abspath(__file__) ) # the directory this.py file is in, which also contains the formation files for file in os.listdir(directory): if file.endswith(".csv"): path = os.path.join(directory, file) formations.append(_loadFormation(path)) # size and position of the buttons and the scrollable frame buttonSize = (-8, 8, -.2, .8) buttonDistance = 0.15 scrolledFrame = DirectScrolledFrame(frameColor=(.2, .2, .2, 1), canvasSize=(-.7, .7, -buttonDistance * len(formations), 0), frameSize=(-.9, .9, -.5, .5), pos=(.8, 0, -.7), scale=.5) canvas = scrolledFrame.getCanvas() # add a button for each formation for i in range(0, len(formations)): button = DirectButton(text=formations[i][0], scale=.1, frameSize=buttonSize, command=manager.applyFormation, extraArgs=[formations[i]]) button.reparentTo(canvas) button.setPos(0.15, 0, -(i + 0.75) * buttonDistance) print("{} formations loaded.".format(len(formations)))
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
def createButton(self, text, 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 = text, text_fg = (1,1,1,1), text_scale = 0.05, text_pos = (0.02, -0.013), text_align = TextNode.ACenter, scale = 2, pos = (0, 0, verticalPos), #geom = btnGeom, relief = 0, frameColor = (0,0,0,0), command = base.messenger.send, extraArgs = eventArgs, pressEffect = False, rolloverSound = None, clickSound = None) btn.reparentTo(self.framePause)
def createButton(self, text, 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")) sound = loader.loadSfx("Audio/click.wav") btn = DirectButton( text=text, text_fg=(1, 1, 1, 1), text_scale=0.05, text_pos=(0.25, -0.013), text_align=TextNode.ACenter, #text_font = loader.loadFont('DreamerOne Bold.ttf'), scale=2, pos=(base.a2dLeft + 1.8, 0, verticalPos), geom=btnGeom, relief=0, frameColor=(0, 0, 0, 0), command=base.messenger.send, extraArgs=eventArgs, pressEffect=True, rolloverSound=None, clickSound=sound) btn.reparentTo(self.frameMain)
def createButton(self, text, 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 = text, text_fg = (0,0,0,1), text_scale = 0.05, text_pos = (0.02, -0.015), text_align = TextNode.ALeft, scale = 2, pos = (base.a2dLeft + 0.2, 0, verticalPos), geom = btnGeom, relief = 0, frameColor = (0,0,0,0), command = base.messenger.send, extraArgs = eventArgs, pressEffect = False, rolloverSound = None, clickSound = None) btn.reparentTo(self.frameMain)
def MakeButton(self, egg, up, over, x, y, cmd, parent): maps = loader.loadModel("Assets/Images/Inventory/%s" % (egg)) b = DirectButton(geom = (maps.find('**/%s' % (up)), maps.find('**/%s' % (over)), maps.find('**/%s' % (over)), maps.find('**/%s' % (up))), command = cmd, pressEffect = 0, relief = None, rolloverSound = None, clickSound = None, scale = (150./1024.0, 1, 75.0/1024.0)) b.reparentTo(parent) b.hide() diff = Settings.WIDTH - Settings.HEIGHT xOff = 0 yOff = 0 if(diff > 0): xOff = diff / 2 else: yOff = diff / 2 x = Settings.Transpose(x + 50, 1024) + xOff y = Settings.Transpose(y + 25, 1024) + yOff centerX = Settings.WIDTH / 2 centerY = Settings.HEIGHT / 2 newX = 1.0 * (x - centerX) / (centerX - xOff) newY = 1.0 * (centerY - y) / (centerY - yOff) b.setX(newX) b.setZ(newY) return b
def createButton(self, text, horizontalPos, eventArgs): sound = loader.loadSfx("Audio/click.wav") 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=text, text_fg=(1, 1, 1, 1), text_scale=0.05, text_pos=(0.125, -0.013), text_align=TextNode.ALeft, scale=2, geom=btnGeom, pos=(base.a2dRight - 0.6, 0, horizontalPos), # pos = (horizontalPos, 0, -.7), relief=0, frameColor=(0, 0, 0, 0), command=base.messenger.send, extraArgs=eventArgs, pressEffect=True, rolloverSound=None, clickSound=sound) btn.reparentTo(self.frameArchive) return btn
class FrameAutenticacao(object): ''' FrameAutenticacao ''' def __init__(self, parent=None, **kw): self.__qtd_conexao = 0 self.__frmAuth = DirectFrame(frameColor=(0, 0, 0, .3), frameSize=(-.5, .5, 0, 0.45), pos=(0, 0, -.1), enableEdit=1) self.__lblLogin = DirectLabel(text="Login: "******"Senha: ", scale=0.05, pos=(-0.3, 0, 0.2), frameColor=(0, 0, 0, 0), text_fg=(1, 1, 1, 1)) self.__etySenha = DirectEntry( scale=0.05, width=12, pos=(-.2, 0, 0.2), cursorKeys=1, obscured=1, focusInCommand=self.__command_clear_senha) self.__btnEntrar = DirectButton(frameColor=(0, 0, 0, 1), text="Entrar", scale=0.06, pos=(0.3, 0, 0.1), text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, command=self.__command_entrar) self.__lblLogin.reparentTo(self.__frmAuth) self.__etyLogin.reparentTo(self.__frmAuth) self.__lblSenha.reparentTo(self.__frmAuth) self.__etySenha.reparentTo(self.__frmAuth) self.__btnEntrar.reparentTo(self.__frmAuth) self.__etyLogin.set("viner") self.__etySenha.set("viner") def __command_clear_senha(self): self.__etySenha.set("") def __command_entrar(self, txt=None): login = self.__etyLogin.get() senha = self.__etySenha.get() valido = True if login == "": addMensagem("O campo Login e obrigatorio !", COR_BRANCO) valido = False if senha == "": addMensagem("O campo Senha e obrigatorio !", COR_BRANCO) valido = False if valido: self.__btnEntrar["state"] = DGG.DISABLED taskMgr.add(self.__task_conectar_servidor, 'ConectarServidor', extraArgs=[login, senha], appendTask=True) #inicia_nova_thread(1, 0, "Conectar Servidor", self.__conectar_servidor, login, senha) def __task_conectar_servidor(self, login, senha, task): if self.__qtd_conexao < TENTATIVAS: if vinerOnline.flg_conectado == vinerOnline.ERROLOGIN: vinerOnline.flg_conectado = vinerOnline.DESCONECT self.__btnEntrar["state"] = DGG.NORMAL self.__qtd_conexao = 0 addMensagem('Login ou senha invalido', COR_VERMELHO) self.__etyLogin.setFocus() elif vinerOnline.flg_conectado == vinerOnline.CONECTADO: #addMensagem("Conectado 12 !!!") #self.destroy() pass else: vinerOnline.conectar_servidor(login, senha) self.__qtd_conexao += 1 taskMgr.doMethodLater(INTERVALO_TENTATIVAS, self.__task_conectar_servidor, 'ConectarServidorLater', extraArgs=[login, senha], appendTask=True) msg = "Tentativa %s/5 - Conectando..." % (self.__qtd_conexao) addMensagem(msg, COR_BRANCO) else: vinerOnline.flg_conectado = vinerOnline.DESCONECT self.__btnEntrar["state"] = DGG.NORMAL self.__qtd_conexao = 0 addMensagem("Servidor nao encontrado", COR_VERMELHO) return task.done def destroy(self): self.__frmAuth.destroy() del self.__lblLogin del self.__etyLogin del self.__lblSenha del self.__etySenha del self.__btnEntrar del self.__frmAuth
class DMenuScreen(DirectObject): notify = directNotify.newCategory('DMenuScreen') def __init__(self):#, avatarList, parentFSM, doneEvent): DirectObject.__init__(self) base.disableMouse() #base.cr.avChoice = None fadeSequence = Sequence( Wait(.5), Func(base.transitions.fadeIn, .5), Wait(1)).start()#, #base.camera.posHprInterval(1, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut')).start() #self.background = loader.loadModel('phase_4/models/neighborhoods/toontown_central_full') #self.background.reparentTo(render) #for frame in render.findAllMatches('*/doorFrame*'): # frame.removeNode() #self.sky = loader.loadModel('phase_3.5/models/props/TT_sky') #SkyUtil.startCloudSky(self) #base.camera.setPosHpr(INIT_POS, INIT_HPR) self.background = OnscreenImage(image = DMenuResources.MenuBackground, parent = aspect2d) self.background.setBin('background', 1) self.background.reparentTo(aspect2d) self.background.setScale(2, 1, 1) self.logo = OnscreenImage(image = DMenuResources.GameLogo, scale = (1, 1, .5)) self.logo.reparentTo(aspect2d) self.logo.setTransparency(TransparencyAttrib.MAlpha) scale = self.logo.getScale() self.logo.setPos(0, 0, .5) self.logo.setColorScale(Vec4(0, 0, 0, 0)) #fadeInBackground = (LerpColorScaleInterval(self.background, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() self.createButtons() self.fadeOut = None self.optionsMgr = DMenuOptions.DMenuOptions() self.quitConfirmation = DMenuQuit.DMenuQuit() # TT: We need these to run the Pick A Toon screen #self.patAvList = avatarList #self.patFSM = parentFSM #self.patDoneEvent = doneEvent self.transcircle = Resources.transcircle self.transcircle.setTransparency(TransparencyAttrib.MAlpha) self.transcircle.setScale(VBase3(0.01, 0.01, 0.01)) self.transcircle.setBin('background', 3) self.savemgr = LOTASaveMgr.LOTASaveMgr() # Get the save data self.savePos = self.savemgr.loadSaveData() self.titleMusic = Resources.titleMusic self.titleMusic.setLoop(1) self.setMusicNormal() def skyTrack(self, task): # return SkyUtil.cloudSkyTrack(task) pass def createButtons(self): self.PlayButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.PlayGame, text_scale = .1, scale = 0.95, command = self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Options, text_scale = .1, scale = 0.95, command = self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Quit, text_scale = .1, scale = 0.95, command = self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show() # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95) # self.BRButton.reparentTo(aspect2d) # self.BRButton.setPos(-.9, 0, -.9) # self.BRButton.show() self.buttonInAnimation() # Slap on the saves menu from the old main menu until a proper implementation to DMENU is made self.SavesButton = DirectButton(relief = None, text = AmdLocalizerEnglish.LOTA_SAVES, image_scale = 2, text_scale = .1, scale = 0.95, command = self.openSavesMenu) self.SavesButton.reparentTo(aspect2d) self.SavesButton.setPos(0, 0, -.5) self.SavesButton.show() def murder(self): if self.logo is not None: self.logo.destroy() self.logo = None if self.background is not None: self.background.hide() self.background.reparentTo(hidden) self.background.removeNode() self.background = None if self.PlayButton is not None: self.PlayButton.destroy() self.PlayButton = None if self.OptionsButton is not None: self.OptionsButton.destroy() self.OptionsButton = None if self.QuitButton is not None: self.QuitButton.destroy() self.QuitButton = None if self.SavesButton is not None: self.SavesButton.destroy() self.SavesButton = None if self.titleMusic is not None: self.titleMusic.stop() #taskMgr.remove('skyTrack') #self.sky.reparentTo(hidden) def openOptions(self): self.optionsMgr.showOptions() self.closeOptionsButton = DirectButton(relief = None, text = "< Back", text_fg = (0.977, 0.816, 0.133, 1), text_pos = (0, -0.035), scale = .1, command = self.hideOptions) self.closeOptionsButton.reparentTo(base.a2dTopLeft) self.closeOptionsButton.setPos(0.5, 0, -0.07) Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnHidePos), blendType = 'easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnHidePos), blendType = 'easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnHidePos), blendType = 'easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start() #base.camera.posHprInterval(0.5, Point3(HQ_POS), VBase3(HQ_HPR), blendType = 'easeInOut').start() #self.setMusicCalm() def hideOptions(self): self.optionsMgr.hideOptions() self.closeOptionsButton.hide() Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut'), self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut')).start() base.camera.posHprInterval(0.5, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut').start() #self.setMusicNormal() def playGame(self): if self.fadeOut is not None: self.fadeOut.finish() self.fadeOut = None self.fadeOut = base.transitions.getFadeOutIval(t = 1) #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start() Sequence( Func(self.doPlayButton), #Func(self.fadeOut.start), Wait(1), Func(self.murder), Wait(1), Func(self.enterGame)).start()#, #Func(base.transitions.fadeIn, 1)).start() def enterOptions(self): pass def enterGame(self): #base.cr.avChoice = AvatarChooser.AvatarChooser(self.patAvList, self.patFSM, self.patDoneEvent) #base.cr.avChoice.load(1) #base.cr.avChoice.enter() from Game.NewGame.Scenes import SceneOne # Hamburger Menu Button #self.hbButton = DirectButton(image = "phase_3/maps/dmenu/dmhbmenu.png", relief = None, text = ' ', command=self.showHamburgerMenu) #self.hbButton.reparentTo(base.a2dTopLeft) #self.hbButton.setPos(0.05, 0, -0.05) #self.hbButton.setScale(0.04) # Hamburger Menu Hide Button #self.hbHideButton = DirectButton(image = "phase_3/maps/dmenu/close_window.png", relief = None, text = ' ', command=self.hideHamburgerMenu) #self.hbHideButton.reparentTo(base.a2dTopLeft) #self.hbHideButton.setPos(0.05, 0, -0.05) #self.hbHideButton.setScale(0.04) #self.hbHideButton.hide() # TODO: Add options and stuff to the hamburger menu def doPlayButton(self): Parallel( self.PlayButton.posInterval(1, Point3(PlayBtnHidePos), blendType = 'easeInOut'), self.OptionsButton.posInterval(1, Point3(OptionsBtnHidePos), blendType = 'easeInOut'), self.QuitButton.posInterval(1, Point3(QuitBtnHidePos), blendType = 'easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start() def quitGame(self): self.showQuitConfirmation() def showQuitConfirmation(self): self.quitConfirmation.showConfirmation() #base.exitFunc() def setMusicNormal(self): #LerpFunctionInterval(base.cr.music.setVolume, fromData = 0, toData = .9, duration = 1).start() #LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = .9, toData = 0, duration = 1).start() self.titleMusic.play() def setMusicCalm(self): LerpFunctionInterval(base.cr.music.setVolume, fromData = .9, toData = 0, duration = 1).start() LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = 0, toData = .9, duration = 1).start() def openSavesMenu(self): self.saveOne = DirectButton(relief=None, text = 'Save One: ' + '(Scene ' + str(self.savePos) + ')', scale=0.3, command=self.saveLoader, parent=aspect2d, pos=(0, 0, -.6), text_scale = .5) self.saveOne.hide() self.transcircle.show() self.exitLoadButton = DirectButton(relief=None, text = '< Back', scale=0.3, command=self.closeSavesMenu, parent=base.a2dBottomCenter, pos=(0, 0, -.4), text_scale = .5) self.exitLoadButton.show() self.openSavesMenuSequence = Parallel( self.transcircle.scaleInterval(0.5, VBase3(3, 3, 3), blendType = 'easeInOut'), self.exitLoadButton.posInterval(0.5, Point3(0, 0, .4), blendType = 'easeInOut'), Func(self.saveOne.show), self.saveOne.posInterval(0.5, Point3(0, 0, .2), blendType = 'easeInOut')) self.openSavesMenuSequence.start() def closeSavesMenu(self): self.hideThings = Sequence( Wait(0.5), Func(self.saveOne.hide), Func(self.transcircle.hide)) self.closeSavesMenuSequence = Parallel( self.saveOne.posInterval(0.5, Point3(0, 0, -.6), blendType = 'easeInOut'), self.transcircle.scaleInterval(0.5, VBase3(0.01, 0.01, 0.01), blendType = 'easeInOut'), self.exitLoadButton.posInterval(0.5, Point3(0, 0, -.4), blendType = 'easeInOut'), Func(self.hideThings.start)) self.closeSavesMenuSequence.start() self.exitLoadButton.removeNode() del self.exitLoadButton def saveLoader(self): # this was thrown together in like 10 seconds. how the f**k does this work # TODO: Make this save to a file thats not easily editable self.saveOne.hide() self.background.hide() self.transcircle.hide() if self.savePos == '1': from Game.NewGame.Scenes import SceneOne elif self.savePos == '2': from Game import SceneTwo elif self.savePos == '3': from Game import SceneThree elif self.savePos == '4': from Game import SceneFour elif self.savePos == '5': from Game import SceneFive else: print ("\n\n Save data is set to an unknown scene!!\n\n") def buttonInAnimation(self): logo = self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut') play = self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut') opt = self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut') quit = self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut') Sequence( Func(logo.start), Wait(0.1), Func(play.start), Wait(0.2), Func(opt.start), Wait(0.2), Func(quit.start)).start() def showHamburgerMenu(self): self.hbButton.hide() self.hbHideButton.show() def hideHamburgerMenu(self): self.hbButton.show() self.hbHideButton.hide()
class EntyButtonFrame(object): def __init__(self, parent=None, scale=.05, limitText=100, frameSize=(0, 1.3, 0.11, .2), pos=(0, 0, .1)): self.__show = True self.frmMsg = DirectFrame(parent=parent, frameColor=(0, 0, 0, .5), frameSize=frameSize, pos=pos, enableEdit=1) self.etyMsg = DirectEntry(frameColor=(1, 1, 1, .5), scale=scale, width=22, numLines=1, pos=(.02, 0, .14), cursorKeys=1, focus=1, command=self.__command_enviar_msg, focusInCommand=self.__command_clear_msg) self.btnMsgr = DirectButton(frameColor=(0, 0, 0, 1), text="Enviar", scale=scale, pos=(1.21, 0, .14), text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, command=self.__command_enviar_msg) self.etyMsg.reparentTo(self.frmMsg) self.btnMsgr.reparentTo(self.frmMsg) self.hide() def hide(self): self.frmMsg.hide() self.__show = False def show(self): self.frmMsg.show() self.__show = True self.etyMsg.setFocus() def isShowing(self): return self.__show def __command_clear_msg(self): self.etyMsg.set("") def __command_enviar_msg(self, txt=None): msg = self.etyMsg.get() if msg != "": vinerOnline.envia_pacote_server(0, ACAO_SERVER_falar, [msg]) self.__command_clear_msg() self.etyMsg.setFocus() return False
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 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")
def createGui(self): base.cr.renderFrame() self.m = loader.loadFont("phase_3/models/fonts/MickeyFont.bam") self.bg = loader.loadModel( "phase_3/models/gui/tt_m_gui_pat_mainGui.bam") self.qtbtn = loader.loadModel("phase_3/models/gui/quit_button.bam") self.trash_gui = loader.loadModel( "phase_3/models/gui/trashcan_gui.bam") self.bg_img = OnscreenImage( image=self.bg.find('**/tt_t_gui_pat_background')) self.setTitle("Pick A Toon To Play") base.setBackgroundColor(self.BgColor) self.btn1 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareGreen'), relief=None, pos=(0.012, 0, 0.306), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn2 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePink'), relief=None, pos=(0.01, 0, -0.515), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn3 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareRed'), relief=None, pos=(-0.84, 0, 0.36), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn4 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareYellow'), relief=None, pos=(0.865, 0, -0.45), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn5 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareBlue'), relief=None, pos=(-0.87, 0, -0.44), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn6 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePurple'), relief=None, pos=(0.873, 0, 0.335), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.quit_btn = DirectButton(geom=(self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR')), relief=None, text="Quit", text_font=self.m, text_scale=0.105, text_pos=(0, -0.035), pos=(1.05, 0, -0.9), text_fg=(1, 0.9, 0.1, 1), geom1_scale=(1.02, 1, 1), geom2_scale=(1.02, 1, 1), command=self.quitGame) self.btnList = [] self.btnList.append(self.btn1) self.btnList.append(self.btn2) self.btnList.append(self.btn3) self.btnList.append(self.btn4) self.btnList.append(self.btn5) self.btnList.append(self.btn6) self.headList = [] #datafiler = open("toons/data.txt", "r") #if datafiler.read() == "-": # for btn in self.btnList: # btn['state'] = DGG.DISABLED # self.quit_btn['state'] = DGG.DISABLED # self.tutorial.askTutorial() # datafilew = open("toons/data.txt", "w") # datafilew.write("+") # datafilew.flush() # datafilew.close() #datafiler.close() for slot in range(6): if self.avChooser.hasToonInSlot(slot): notify.info("found existing Toon in slot %s" % (str(slot))) frame = DirectFrame(relief=None, parent=self.btnList[slot], pos=(0, 0, -0.1)) headframe = hidden.attachNewNode('head') headframe.setPosHprScale(0, 5, -0.1, 180, 0, 0, 0.24, 0.24, 0.24) headframe.reparentTo(self.btnList[slot].stateNodePath[0], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[1], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[2], 20) toon = ToonHead(base.cr) self.headList.append(toon) gender, animal, head, headcolor = self.avChooser.getHeadInfo( slot) toon.generateHead(gender, animal, head, 1) toon.getGeomNode().setDepthWrite(1) toon.getGeomNode().setDepthTest(1) toon.startBlink() toon.startLookAround() toon.reparentTo(headframe) toon.setHeadColor(headcolor) toon.flattenLight() name_lbl = DirectLabel(text=self.avChooser.getNameInSlot(slot), text_scale=0.08, text_fg=(1, 1, 1, 1), text_wordwrap=7, relief=None, text_shadow=(0, 0, 0, 1)) name_lbl.reparentTo(self.btnList[slot].stateNodePath[0], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[1], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[2], 20) name_lbl.setPos(self.name_pos[slot]) name_lbl.setHpr(self.name_hpr[slot]) self.btnList[slot]['text'] = ("", "Play This Toon", "Play This Toon", "") self.btnList[slot]['text_scale'] = 0.1 self.btnList[slot]['text_pos'] = (0, 0) self.btnList[slot]['text_fg'] = (1, 0.9, 0, 1) self.btnList[slot]['text_wordwrap'] = 6 self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["playGame", slot] delBtn = DirectButton( text=("", "Delete", "Delete", ""), text_scale=0.15, scale=0.5, text_pos=(0, -0.1), text_fg=(1, 1, 1, 1), relief=None, geom=(self.trash_gui.find('**/TrashCan_CLSD'), self.trash_gui.find('**/TrashCan_OPEN'), self.trash_gui.find('**/TrashCan_RLVR')), pos=self.trash_pos[slot], command=self.deleteToon, extraArgs=[ self.avChooser.getAvChoiceBySlot(slot).getAvId() ], text_shadow=(0, 0, 0, 1)) delBtn.reparentTo(self.btnList[slot].stateNodePath[0], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[1], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[2], 20) else: self.btnList[slot]['text'] = "Make A Toon" self.btnList[slot]['text_font'] = self.m self.btnList[slot]['text0_scale'] = 0.1 self.btnList[slot]['text1_scale'] = 0.12 self.btnList[slot]['text2_scale'] = 0.12 self.btnList[slot]['text3_scale'] = 0.1 self.btnList[slot]['text0_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text1_fg'] = (0, 1, 0.8, 1) self.btnList[slot]['text2_fg'] = (0.3, 1, 0.9, 1) self.btnList[slot]['text3_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["mat", slot] self.btnList[slot]['text_wordwrap'] = 6
class Introduction(DirectObject, FSM): notify = directNotify.newCategory('Introduction') def __init__(self): DirectObject.__init__(self) FSM.__init__(self, self.__class__.__name__) self.label = OnscreenText('', parent=hidden, font=ToontownGlobals.getMinnieFont(), fg=Vec4(1, 1, 1, 1), scale=0.06, align=TextNode.ACenter, wordwrap=35) self.label.setColorScale(Vec4(0, 0, 0, 0)) gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui.bam') shuffleUp = gui.find('**/tt_t_gui_mat_shuffleUp') shuffleDown = gui.find('**/tt_t_gui_mat_shuffleDown') okUp = gui.find('**/tt_t_gui_mat_okUp') okDown = gui.find('**/tt_t_gui_mat_okDown') closeUp = gui.find('**/tt_t_gui_mat_closeUp') closeDown = gui.find('**/tt_t_gui_mat_closeDown') gui.removeNode() del gui self.exitButton = DirectButton( parent=hidden, relief=None, image=(shuffleUp, shuffleDown, shuffleUp), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.63, 0.6, 0.6), image2_scale=(0.63, 0.6, 0.6), text=(TTLocalizer.IntroExitButton, TTLocalizer.IntroExitButton, TTLocalizer.IntroExitButton, ''), text_font=ToontownGlobals.getInterfaceFont(), text_scale=TTLocalizer.SBshuffleBtn, text_pos=(0, -0.02), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.yesButton = DirectButton( parent=hidden, relief=None, image=(okUp, okDown, okUp, okDown), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), text=('', TTLocalizer.IntroYesButton, TTLocalizer.IntroYesButton), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_align=TextNode.ACenter, text_pos=(0, -0.175), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.noButton = DirectButton( parent=hidden, relief=None, image=(closeUp, closeDown, closeUp, closeDown), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), text=('', TTLocalizer.IntroNoButton, TTLocalizer.IntroNoButton), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_align=TextNode.ACenter, text_pos=(0, -0.175), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.disclaimerTrack = None self.presentsTrack = None def delete(self): if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None if self.noButton is not None: self.noButton.destroy() self.noButton = None if self.yesButton is not None: self.yesButton.destroy() self.yesButton = None if self.exitButton is not None: self.exitButton.destroy() self.exitButton = None if self.label is not None: self.label.destroy() self.label = None def calcLabelY(self): sy = self.label.getScale()[1] height = self.label.textNode.getHeight() return (height * sy) / 2.0 def enterOff(self): pass def enterDisclaimer(self): self.label.setText(TTLocalizer.IntroDisclaimer) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None self.disclaimerTrack = Sequence( LerpColorScaleInterval(self.label, 2, Vec4(1, 1, 1, 1), Vec4(0, 0, 0, 0), blendType='easeIn'), Wait(3), LerpColorScaleInterval(self.label, 2, Vec4(0, 0, 0, 0), Vec4(1, 1, 1, 1), blendType='easeOut'), ) self.disclaimerTrack.start() def exitDisclaimer(self): if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterPresents(self): self.label.setText(TTLocalizer.IntroPresents) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None self.presentsTrack = Sequence( LerpColorScaleInterval(self.label, 2, Vec4(1, 1, 1, 1), Vec4(0, 0, 0, 0), blendType='easeIn'), Wait(3), LerpColorScaleInterval(self.label, 2, Vec4(0, 0, 0, 0), Vec4(1, 1, 1, 1), blendType='easeOut'), ) self.presentsTrack.start() def exitPresents(self): if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterLabel(self, text): self.label.setText(text) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitLabel(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterExitDialog(self, text, exitButtonCommand=None, exitButtonExtraArgs=[]): self.label.setText(text) sy = self.label.getScale()[1] bottom = self.label.textNode.getBottom() * sy lineHeight = self.label.textNode.getLineHeight() * sy self.exitButton.setPos(0, 0, bottom - (lineHeight * 2)) self.exitButton['command'] = exitButtonCommand self.exitButton['extraArgs'] = exitButtonExtraArgs labelY = self.calcLabelY() self.label.setPos(0, labelY) self.exitButton.setZ(self.exitButton, labelY) self.exitButton.reparentTo(aspect2d) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitExitDialog(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.exitButton.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') self.exitButton['command'] = None self.exitButton['extraArgs'] = [] self.exitButton.setPos(0, 0, 0) def enterYesNoDialog(self, text, yesButtonCommand=None, yesButtonExtraArgs=[], noButtonCommand=None, noButtonExtraArgs=[]): self.label.setText(text) sy = self.label.getScale()[1] bottom = self.label.textNode.getBottom() * sy lineHeight = self.label.textNode.getLineHeight() * sy self.yesButton.setPos(-0.1, 0, bottom - (lineHeight * 2)) self.yesButton['command'] = yesButtonCommand self.yesButton['extraArgs'] = yesButtonExtraArgs self.noButton.setPos(0.1, 0, bottom - (lineHeight * 2)) self.noButton['command'] = noButtonCommand self.noButton['extraArgs'] = noButtonExtraArgs labelY = self.calcLabelY() self.label.setPos(0, labelY) self.yesButton.setZ(self.yesButton, labelY) self.noButton.setZ(self.noButton, labelY) self.yesButton.reparentTo(aspect2d) self.noButton.reparentTo(aspect2d) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitYesNoDialog(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.noButton.reparentTo(hidden) self.yesButton.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') self.noButton['command'] = None self.noButton['extraArgs'] = [] self.noButton.setPos(0, 0, 0) self.yesButton['command'] = None self.yesButton['extraArgs'] = [] self.yesButton.setPos(0, 0, 0) def enterClickToStart(self): base.cr.clickToStart.start() def exitClickToStart(self): base.cr.clickToStart.stop()
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 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 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 addItem(self, text_name, selection_values, current_selection_idx=-1): """ Adds an item to the list display. text_name - The string representation of the list item selection_values - A list of available values for selection in this field current_selection - The currently selected item """ pos_name = Vec3(-0.47, 0, 0.4 - (len(self._items) * 0.15)) pos_value = Vec3(1.0, 0, 0.4 - (len(self._items) * 0.15)) length = len(self._items) selection_text = "" if current_selection_idx != -1: selection_text = str(selection_values[current_selection_idx]) name_display = DirectButton( text=text_name, command=None, extraArgs=[len(self._items)], text_align=TextNode.ALeft, scale=0.1, #left/right, forward/back, up/down pos=pos_name, text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, pressEffect=0, relief=None, textMayChange=True #text_font=base.fontLoader.load('Arial Bold.ttf') ) name_display.reparentTo(self.__menuContainer) value_display = DirectButton( text=str(selection_text), command=None, extraArgs=[len(self._items)], text_align=TextNode.ALeft, scale=0.1, #left/right, forward/back, up/down pos=pos_value, text_fg=(1, 1, 1, 1), rolloverSound=None, clickSound=None, pressEffect=0, relief=None, textMayChange=True #text_font=base.fontLoader.load('Arial Bold.ttf') ) value_display.reparentTo(self.__menuContainer) v = {} v['name'] = text_name v['name_display'] = name_display v['value_display'] = value_display v['selection_values'] = selection_values v['current_selection_idx'] = current_selection_idx self._items.append(v)
def initUI(self): # initialize drone control panel buttonSize = (-4, 4, -.2, .8) buttonDistance = 0.15 entrySize = (0, 2, -.2, .8) # frame = DirectFrame(frameColor=(.2, .2, .2, 1), frameSize=(-.5, .5, -.7, .15), pos=(-.9, 0, -.6), scale=.5) frame = DirectFrame(frameColor=(.2, .2, .2, 1), frameSize=(-.5, .5, -.7, .15), pos=(-.9, 0, -.4), scale=.5) button = DirectButton(text="Start", scale=.1, frameSize=buttonSize, command=self.startLandAll) button["extraArgs"] = [button] button.reparentTo(frame) button = DirectButton(text="Random Target", scale=.1, frameSize=buttonSize, command=self.setRandomTargets) button.reparentTo(frame) button.setPos(Vec3(0, 0, -1 * buttonDistance)) button = DirectButton(text="Stop", scale=.1, frameSize=buttonSize, command=self.stopAll) button.reparentTo(frame) button.setPos(Vec3(0, 0, -2 * buttonDistance)) button = DirectButton(text="Return", scale=.1, frameSize=buttonSize, command=self.returnToWaitingPosition) button.reparentTo(frame) button.setPos(Vec3(0, 0, -3 * buttonDistance)) button = DirectButton(text="Connect", scale=.1, frameSize=buttonSize, command=self.toggleConnections) button["extraArgs"] = [button] button.reparentTo(frame) button.setPos(Vec3(0, 0, -4 * buttonDistance)) button = DirectButton(text="Rotate", scale=.1, frameSize=buttonSize, command=self.toggleRotation) button.reparentTo(frame) button.setPos(Vec3(0, 0, -5 * buttonDistance)) button = DirectButton(text="Move", scale=.1, frameSize=buttonSize, command=self.moveFormation) button.reparentTo(frame) button.setPos(Vec3(0, 0, -6 * buttonDistance)) self.moveX = DirectEntry(text="", initialText="0", scale=.1, frameSize=entrySize) self.moveX.reparentTo(frame) self.moveX.setPos(Vec3(0.5, 0, -6 * buttonDistance)) self.moveY = DirectEntry(text="", initialText="0", scale=.1, frameSize=entrySize) self.moveY.reparentTo(frame) self.moveY.setPos(Vec3(0.75, 0, -6 * buttonDistance)) self.moveZ = DirectEntry(text="", initialText="0", scale=.1, frameSize=entrySize) self.moveZ.reparentTo(frame) self.moveZ.setPos(Vec3(1, 0, -6 * buttonDistance)) self.rotSpeed = DirectEntry(text="", initialText="3", scale=.1, frameSize=entrySize) self.rotSpeed.reparentTo(frame) self.rotSpeed.setPos(Vec3(0.5, 0, -5 * buttonDistance)) # initialize an UI element with all available formations loadFormationSelectionFrame(self)
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 Introduction(DirectObject, FSM): notify = directNotify.newCategory('Introduction') def __init__(self): DirectObject.__init__(self) FSM.__init__(self, self.__class__.__name__) self.label = OnscreenText( '', parent=hidden, font=ToontownGlobals.getMinnieFont(), fg=Vec4(1, 1, 1, 1), scale=0.06, align=TextNode.ACenter, wordwrap=35) self.label.setColorScale(Vec4(0, 0, 0, 0)) gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui.bam') shuffleUp = gui.find('**/tt_t_gui_mat_shuffleUp') shuffleDown = gui.find('**/tt_t_gui_mat_shuffleDown') okUp = gui.find('**/tt_t_gui_mat_okUp') okDown = gui.find('**/tt_t_gui_mat_okDown') closeUp = gui.find('**/tt_t_gui_mat_closeUp') closeDown = gui.find('**/tt_t_gui_mat_closeDown') gui.removeNode() del gui self.exitButton = DirectButton( parent=hidden, relief=None, image=(shuffleUp, shuffleDown, shuffleUp), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.63, 0.6, 0.6), image2_scale=(0.63, 0.6, 0.6), text=(TTLocalizer.IntroExitButton, TTLocalizer.IntroExitButton, TTLocalizer.IntroExitButton, ''), text_font=ToontownGlobals.getInterfaceFont(), text_scale=TTLocalizer.SBshuffleBtn, text_pos=(0, -0.02), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.yesButton = DirectButton( parent=hidden, relief=None, image=(okUp, okDown, okUp, okDown), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), text=('', TTLocalizer.IntroYesButton, TTLocalizer.IntroYesButton), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_align=TextNode.ACenter, text_pos=(0, -0.175), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.noButton = DirectButton( parent=hidden, relief=None, image=(closeUp, closeDown, closeUp, closeDown), image_scale=(0.6, 0.6, 0.6), image1_scale=(0.7, 0.7, 0.7), image2_scale=(0.7, 0.7, 0.7), text=('', TTLocalizer.IntroNoButton, TTLocalizer.IntroNoButton), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_align=TextNode.ACenter, text_pos=(0, -0.175), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1)) self.disclaimerTrack = None self.presentsTrack = None def delete(self): if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None if self.noButton is not None: self.noButton.destroy() self.noButton = None if self.yesButton is not None: self.yesButton.destroy() self.yesButton = None if self.exitButton is not None: self.exitButton.destroy() self.exitButton = None if self.label is not None: self.label.destroy() self.label = None def calcLabelY(self): sy = self.label.getScale()[1] height = self.label.textNode.getHeight() return (height * sy) / 2.0 def enterOff(self): pass def enterDisclaimer(self): self.label.setText(TTLocalizer.IntroDisclaimer) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None self.disclaimerTrack = Sequence( LerpColorScaleInterval( self.label, 2, Vec4(1, 1, 1, 1), Vec4(0, 0, 0, 0), blendType='easeIn'), Wait(3), LerpColorScaleInterval( self.label, 2, Vec4(0, 0, 0, 0), Vec4(1, 1, 1, 1), blendType='easeOut'), ) self.disclaimerTrack.start() def exitDisclaimer(self): if self.disclaimerTrack is not None: self.disclaimerTrack.finish() self.disclaimerTrack = None self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterPresents(self): self.label.setText(TTLocalizer.IntroPresents) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None self.presentsTrack = Sequence( LerpColorScaleInterval( self.label, 2, Vec4(1, 1, 1, 1), Vec4(0, 0, 0, 0), blendType='easeIn'), Wait(3), LerpColorScaleInterval( self.label, 2, Vec4(0, 0, 0, 0), Vec4(1, 1, 1, 1), blendType='easeOut'), ) self.presentsTrack.start() def exitPresents(self): if self.presentsTrack is not None: self.presentsTrack.finish() self.presentsTrack = None self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterLabel(self, text): self.label.setText(text) self.label.setPos(0, self.calcLabelY()) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitLabel(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') def enterExitDialog(self, text, exitButtonCommand=None, exitButtonExtraArgs=[]): self.label.setText(text) sy = self.label.getScale()[1] bottom = self.label.textNode.getBottom() * sy lineHeight = self.label.textNode.getLineHeight() * sy self.exitButton.setPos(0, 0, bottom - (lineHeight * 2)) self.exitButton['command'] = exitButtonCommand self.exitButton['extraArgs'] = exitButtonExtraArgs labelY = self.calcLabelY() self.label.setPos(0, labelY) self.exitButton.setZ(self.exitButton, labelY) self.exitButton.reparentTo(aspect2d) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitExitDialog(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.exitButton.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') self.exitButton['command'] = None self.exitButton['extraArgs'] = [] self.exitButton.setPos(0, 0, 0) def enterYesNoDialog(self, text, yesButtonCommand=None, yesButtonExtraArgs=[], noButtonCommand=None, noButtonExtraArgs=[]): self.label.setText(text) sy = self.label.getScale()[1] bottom = self.label.textNode.getBottom() * sy lineHeight = self.label.textNode.getLineHeight() * sy self.yesButton.setPos(-0.1, 0, bottom - (lineHeight * 2)) self.yesButton['command'] = yesButtonCommand self.yesButton['extraArgs'] = yesButtonExtraArgs self.noButton.setPos(0.1, 0, bottom - (lineHeight * 2)) self.noButton['command'] = noButtonCommand self.noButton['extraArgs'] = noButtonExtraArgs labelY = self.calcLabelY() self.label.setPos(0, labelY) self.yesButton.setZ(self.yesButton, labelY) self.noButton.setZ(self.noButton, labelY) self.yesButton.reparentTo(aspect2d) self.noButton.reparentTo(aspect2d) self.label.reparentTo(aspect2d) self.label.setColorScale(Vec4(1, 1, 1, 1)) def exitYesNoDialog(self): self.label.setColorScale(Vec4(0, 0, 0, 0)) self.label.reparentTo(hidden) self.noButton.reparentTo(hidden) self.yesButton.reparentTo(hidden) self.label.setPos(0, 0) self.label.setText('') self.noButton['command'] = None self.noButton['extraArgs'] = [] self.noButton.setPos(0, 0, 0) self.yesButton['command'] = None self.yesButton['extraArgs'] = [] self.yesButton.setPos(0, 0, 0) def enterClickToStart(self): base.cr.clickToStart.start() def exitClickToStart(self): base.cr.clickToStart.stop()
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")
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 Menu(DirectObject): def __init__(self): """Default constructor""" # load the default fonts #self.defaultFont = loader.loadFont("gui/fonts/UbuntuBold") #self.defaultFontRegular = loader.loadFont("gui/fonts/UbuntuRegular") # load the default button image map self.defaultBtnMaps = base.loader.loadModel( "gui/buttons/mainMenu/button_maps") # this button can be created with the createBackButton function self.btnBack = None self.frameMain = DirectFrame( # size of the frame frameSize = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom), # position of the frame pos = (0, 0, 0), # tramsparent bg color frameColor = (0, 0, 0, 0)) self.title = DirectLabel( scale = 0.25, pos = (0, 0, -0.25), frameColor = (0, 0, 0, 0), text = "Missing Title", text_align = TextNode.ACenter, text_fg = (1,1,1,1), #text_font = self.defaultFont ) self.title.reparentTo(base.a2dTopCenter) self.clock = DirectLabel( scale = 0.1, pos = (-.1,0,.1), frameColor = (0, 0, 0, 0), text = "00:00", text_align = TextNode.ARight, text_fg = (1,1,1,1)) self.clock.reparentTo(base.a2dBottomRight) self.hide() def showBase(self): """Show all GUI controls of the base menu""" self.accept("RatioChanged", self.recalcAspectRatio) self.frameMain.show() self.clock.show() self.title.show() if self.btnBack: self.btnBack.show() if not taskMgr.hasTaskNamed("clock"): taskMgr.add(self.clockTask, "clock") def hideBase(self): """Hide all GUI controls of the base menu""" self.ignore("RatioChanged") self.frameMain.hide() self.clock.hide() self.title.hide() if self.btnBack: self.btnBack.hide() if taskMgr.hasTaskNamed("clock"): taskMgr.remove("clock") def createBackButton(self, func): """Create the back button on the bottom left edge of the window""" self.btnBack = DirectButton( # size of the button scale = (0.25, 0.25, 0.25), # size of the text text_scale = (0.5*1.33, 0.5, 0.5), # the text on the button text = "ABC", # set the alignment to right text_align = TextNode.ARight, # put the text on the left 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, # make it transparent frameColor = (0,0,0,0), # No sink in when press pressEffect = False, # position on the window pos = (0.0, 0, 0.2), # the event which is thrown on clickSound command = func, # sounds that should be played rolloverSound = None, clickSound = None) self.btnBack.reparentTo(base.a2dBottomLeft) def clockTask(self, task): self.clock["text"] = time.strftime("%H:%M") return task.cont def recalcAspectRatio(self): """get the new aspect ratio to resize the mainframe""" self.frameMain["frameSize"] = ( base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom)
class DMenuScreen(DirectObject): notify = directNotify.newCategory('DMenuScreen') def __init__(self): DirectObject.__init__(self) base.cr.DMENU_SCREEN = self self.seq = None self.isSeqPlaying = False # .isPlaying() doesnt want to work if DMENU_GAME == 'Toontown': base.cr.avChoice = None fadeSequence = Sequence( Func(base.transitions.fadeOut, .001), Wait(.5), Func(base.transitions.fadeIn, .5), base.camera.posHprInterval(1, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType='easeInOut')).start() if DMENU_GAME == 'Toontown': self.background = loader.loadModel( 'phase_3.5/models/modules/tt_m_ara_int_toonhall') self.background.reparentTo(render) self.background.setPosHpr(-25, 0, 8.1, -95, 0, 0) ropes = loader.loadModel( 'phase_4/models/modules/tt_m_ara_int_ropes') ropes.reparentTo(self.background) self.sillyMeter = Actor.Actor( 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_default', { 'arrowTube': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_arrowFluid', 'phaseOne': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseOne', 'phaseTwo': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseTwo', 'phaseThree': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseThree', 'phaseFour': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFour', 'phaseFourToFive': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFourToFive', 'phaseFive': 'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFive' }) self.sillyMeter.reparentTo(self.background) self.sillyMeter.makeSubpart('arrow', ['uvj_progressBar*', 'def_springA']) self.sillyMeter.makeSubpart('meter', ['def_pivot'], ['uvj_progressBar*', 'def_springA']) self.audio3d = Audio3DManager.Audio3DManager( base.sfxManagerList[0], camera) self.phase3Sfx = self.audio3d.loadSfx( 'phase_4/audio/sfx/tt_s_prp_sillyMeterPhaseThree.ogg') self.phase3Sfx.setLoop(True) self.arrowSfx = self.audio3d.loadSfx( 'phase_4/audio/sfx/tt_s_prp_sillyMeterArrow.ogg') self.arrowSfx.setLoop(False) self.phase3Sfx.setVolume(0.2) self.arrowSfx.setVolume(0.2) self.animSeq = Sequence( Sequence( ActorInterval(self.sillyMeter, 'arrowTube', partName='arrow', constrainedLoop=0, startFrame=236, endFrame=247), Func(self.arrowSfx.play)), Parallel( ActorInterval(self.sillyMeter, 'arrowTube', partName='arrow', duration=604800, constrainedLoop=1, startFrame=247, endFrame=276), Sequence( Func(self.phase3Sfx.play), Func(self.audio3d.attachSoundToObject, self.phase3Sfx, self.sillyMeter)))) self.animSeq.start() self.smPhase2 = self.sillyMeter.find('**/stage2') self.smPhase2.show() self.sillyMeter.loop('phaseOne', partName='meter') self.sillyMeter.setBlend(frameBlend=True) self.surlee = Toon.Toon() self.surlee.setName('Doctor Surlee') self.surlee.setPickable(0) self.surlee.setPlayerType(CCNonPlayer) dna = ToonDNA.ToonDNA() dna.newToonFromProperties('pls', 'ls', 'l', 'm', 9, 0, 9, 9, 98, 27, 86, 27, 38, 27) self.surlee.setDNA(dna) self.surlee.loop('scientistGame') self.surlee.reparentTo(self.background) self.surlee.setPosHpr(13, 24, 0.025, -180, 0, 0) self.dimm = Toon.Toon() self.dimm.setName('Doctor Dimm') self.dimm.setPickable(0) self.dimm.setPlayerType(CCNonPlayer) dna = ToonDNA.ToonDNA() dna.newToonFromProperties('fll', 'ss', 's', 'm', 15, 0, 15, 15, 99, 27, 86, 27, 39, 27) self.dimm.setDNA(dna) self.dimm.loop('scientistGame') self.dimm.reparentTo(self.background) self.dimm.setPosHpr(16, 24, 0.025, -180, 0, 0) surleeHand = self.surlee.find('**/def_joint_right_hold') clipBoard = loader.loadModel( 'phase_4/models/props/tt_m_prp_acs_clipboard') surleeHandNode = surleeHand.attachNewNode('ClipBoard') clipBoard.instanceTo(surleeHandNode) surleeHandNode.setH(180) surleeHandNode.setScale(render, 1.0) surleeHandNode.setPos(0, 0, 0.1) dimmHand = self.dimm.find('**/def_joint_right_hold') sillyReader = loader.loadModel( 'phase_4/models/props/tt_m_prp_acs_sillyReader') dimHandNode = dimmHand.attachNewNode('SillyReader') sillyReader.instanceTo(dimHandNode) dimHandNode.setH(180) dimHandNode.setScale(render, 1.0) dimHandNode.setPos(0, 0, 0.1) self.banana = self.background.find('**/gagBanana') self.bananaClicker = CollisionTraverser() #self.bananaClicker.showCollisions(render) self.collHandlerQueue = CollisionHandlerQueue() self.bananaRayNode = CollisionNode('bananaMouseRay') self.bananaRayNP = base.camera.attachNewNode(self.bananaRayNode) self.bananaRayNode.setIntoCollideMask(BitMask32.bit(0)) self.bananaRayNode.setFromCollideMask(BitMask32.bit(1)) self.banana.setCollideMask(BitMask32.bit(1)) self.ray = CollisionRay() self.bananaRayNode.addSolid(self.ray) self.bananaClicker.addCollider(self.bananaRayNP, self.collHandlerQueue) self.accept("mouse1", self.slipAndSlideOnThisBananaPeelHaHaHa) for frame in render.findAllMatches('*/doorFrame*'): frame.removeNode() self.sky = loader.loadModel('phase_3.5/models/props/TT_sky') SkyUtil.startCloudSky(self) base.camera.setPosHpr(MAIN_POS, MAIN_HPR) self.logo = OnscreenImage(image=GameLogo, scale=(.5, .5, .25)) self.logo.reparentTo(aspect2d) self.logo.setTransparency(TransparencyAttrib.MAlpha) scale = self.logo.getScale() self.logo.setPos(0, 0, .5) self.logo.setColorScale(Vec4(0, 0, 0, 0)) fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start() self.createButtons() self.fadeOut = None self.optionsMgr = PickAToonOptions.NewPickAToonOptions() #self.quitConfirmation = DMenuQuit() self.patNode = None if DMENU_GAME == 'Toontown': # TT: We need these to run the Pick A Toon screen self.patAvList = base.cr.PAT_AVLIST self.patFSM = base.cr.PAT_LOGINFSM self.patDoneEvent = base.cr.PAT_DONEEVENT def slipAndSlideOnThisBananaPeelHaHaHa(self): if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() def setPlayingStatus(status): self.isSeqPlaying = status self.ray.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.bananaClicker.traverse(render) if self.collHandlerQueue.getNumEntries() > 0: self.collHandlerQueue.sortEntries() pickedObj = self.collHandlerQueue.getEntry(0).getIntoNodePath() surleeAnim = random.choice(['slip-backward', 'slip-forward']) dimmAnim = random.choice(['slip-backward', 'slip-forward']) if pickedObj == self.banana: self.seq = Sequence( Func(setPlayingStatus, True), Func(self.surlee.play, surleeAnim), Func(self.dimm.play, dimmAnim), Wait(3), Func(self.surlee.loop, 'scientistGame'), Func(self.dimm.loop, 'scientistGame'), Func(setPlayingStatus, False)) if not self.isSeqPlaying: self.seq.start() def skyTrack(self, task): return SkyUtil.cloudSkyTrack(task) def createButtons(self): buttonImage = GuiModel.find('**/QuitBtn_RLVR') self.PlayButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=PlayGame, text_scale=.1, scale=0.95, command=self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Options, text_scale=.1, scale=0.95, command=self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Quit, text_scale=.1, scale=0.95, command=self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show() # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95) # self.BRButton.reparentTo(aspect2d) # self.BRButton.setPos(-.9, 0, -.9) # self.BRButton.show() self.buttonInAnimation() def murder(self): if self.logo is not None: self.logo.destroy() self.logo = None if self.background is not None: self.background.hide() self.background.reparentTo(hidden) self.background.removeNode() self.background = None if self.PlayButton is not None: self.PlayButton.destroy() self.PlayButton = None if self.OptionsButton is not None: self.OptionsButton.destroy() self.OptionsButton = None if self.QuitButton is not None: self.QuitButton.destroy() self.QuitButton = None if self.phase3Sfx: self.phase3Sfx.stop() del self.phase3Sfx if self.surlee: self.surlee.delete() if self.dimm: self.dimm.delete() del self.bananaRayNode del self.bananaRayNP del self.bananaClicker del self.collHandlerQueue del self.ray self.ignoreAll() taskMgr.remove('skyTrack') self.sky.reparentTo(hidden) def openOptions(self): self.optionsMgr.showOptions() self.closeOptionsButton = DirectButton( relief=None, image=(btnUp, btnDn, btnRlvr), text="Back", text_fg=(0, 0, 0, 1), text_scale=TTLocalizer.AClogoutButton, text_pos=(0, -0.035), image_scale=1, image1_scale=1.05, image2_scale=1.05, scale=0.7, command=self.hideOptions) self.closeOptionsButton.reparentTo(base.a2dTopLeft) self.closeOptionsButton.setPos(0.5, 0, -0.07) Parallel( self.PlayButton.posInterval(.5, Point3(PlayBtnHidePos), blendType='easeInOut'), self.OptionsButton.posInterval(.5, Point3(OptionsBtnHidePos), blendType='easeInOut'), self.QuitButton.posInterval(.5, Point3(QuitBtnHidePos), blendType='easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType='easeInOut')).start() def hideOptions(self): self.optionsMgr.hideOptions() self.closeOptionsButton.hide() self.buttonInAnimation() def playGame(self): if self.fadeOut is not None: self.fadeOut.finish() self.fadeOut = None self.fadeOut = base.transitions.getFadeOutIval(t=1) #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start() Sequence( Func(self.doPlayButton), Wait(1), #Func(self.murder), Func(self.enterGame)).start() #Func(base.transitions.fadeIn, 1)).start() def enterOptions(self): pass def enterGame(self): base.cr.avChoice = PickAToon.PickAToon(self.patAvList, self.patFSM, self.patDoneEvent) base.cr.avChoice.load() base.cr.avChoice.enter() def doPlayButton(self): Parallel( self.PlayButton.posInterval(1, Point3(PlayBtnHidePos), blendType='easeInOut'), self.OptionsButton.posInterval(1, Point3(OptionsBtnHidePos), blendType='easeInOut'), self.QuitButton.posInterval(1, Point3(QuitBtnHidePos), blendType='easeInOut'), self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType='easeInOut')).start() def quitGame(self): self.showQuitConfirmation() def showQuitConfirmation(self): #self.quitConfirmation.showConfirmation() base.exitFunc() def buttonInAnimation(self): logo = self.logo.posInterval(.5, Point3(0, 0, .5), blendType='easeInOut') play = self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType='easeInOut') opt = self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType='easeInOut') quit = self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType='easeInOut') Sequence(Func(logo.start), Wait(0.1), Func(play.start), Wait(0.2), Func(opt.start), Wait(0.2), Func(quit.start)).start() def showHamburgerMenu(self): self.hbButton.hide() self.hbHideButton.show() self.patNode2d = aspect2d.find("**/patNode2d") self.patNode2d.posInterval(.5, Point3(.5, 0, 0), blendType='easeInOut').start() self.patNode = render.find("**/patNode") self.patNode.posInterval(.5, Point3(0, -3, 0), blendType='easeInOut').start() def hideHamburgerMenu(self): self.hbButton.show() self.hbHideButton.hide() self.patNode2d.posInterval(.5, Point3(0, 0, 0), blendType='easeInOut').start() self.patNode.posInterval(.5, Point3(0, 0, 0), blendType='easeInOut').start() def reportBug(self): BugReportGUI.BugReportGUI() def createTabs(self): self.PlayButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=PlayGame, text_scale=.1, scale=0.95, command=self.playGame) self.PlayButton.reparentTo(aspect2d) self.PlayButton.setPos(PlayBtnHidePos) self.PlayButton.show() self.OptionsButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Options, text_scale=.1, scale=0.95, command=self.openOptions) self.OptionsButton.reparentTo(aspect2d) self.OptionsButton.setPos(OptionsBtnHidePos) self.OptionsButton.show() self.QuitButton = DirectButton(relief=None, text_style=3, text_fg=(1, 1, 1, 1), text=Quit, text_scale=.1, scale=0.95, command=self.quitGame) self.QuitButton.reparentTo(aspect2d) self.QuitButton.setPos(QuitBtnHidePos) self.QuitButton.show()
class FrameAutenticacao(object): ''' FrameAutenticacao ''' def __init__(self, parent = None, **kw): self.__qtd_conexao = 0 self.__frmAuth = DirectFrame( frameColor = (0,0,0,.3), frameSize = (-.5,.5,0,0.45), pos = (0,0,-.1), enableEdit = 1 ) self.__lblLogin = DirectLabel( text = "Login: "******"Senha: ", scale = 0.05, pos = (-0.3, 0, 0.2), frameColor = (0,0,0,0), text_fg = (1,1,1,1) ) self.__etySenha = DirectEntry( scale = 0.05, width = 12, pos = (-.2, 0, 0.2), cursorKeys = 1, obscured = 1, focusInCommand = self.__command_clear_senha) self.__btnEntrar = DirectButton( frameColor = (0,0,0,1), text = "Entrar", scale = 0.06, pos = (0.3, 0, 0.1), text_fg = (1,1,1,1), rolloverSound = None, clickSound = None, command = self.__command_entrar) self.__lblLogin.reparentTo(self.__frmAuth) self.__etyLogin.reparentTo(self.__frmAuth) self.__lblSenha.reparentTo(self.__frmAuth) self.__etySenha.reparentTo(self.__frmAuth) self.__btnEntrar.reparentTo(self.__frmAuth) self.__etyLogin.set("viner") self.__etySenha.set("viner") def __command_clear_senha(self): self.__etySenha.set("") def __command_entrar(self, txt = None): login = self.__etyLogin.get() senha = self.__etySenha.get() valido = True if login == "": addMensagem("O campo Login e obrigatorio !", COR_BRANCO) valido = False if senha == "": addMensagem("O campo Senha e obrigatorio !", COR_BRANCO) valido = False if valido: self.__btnEntrar["state"] = DGG.DISABLED taskMgr.add( self.__task_conectar_servidor, 'ConectarServidor', extraArgs=[login,senha], appendTask=True) #inicia_nova_thread(1, 0, "Conectar Servidor", self.__conectar_servidor, login, senha) def __task_conectar_servidor(self, login, senha, task): if self.__qtd_conexao < TENTATIVAS: if vinerOnline.flg_conectado == vinerOnline.ERROLOGIN: vinerOnline.flg_conectado = vinerOnline.DESCONECT self.__btnEntrar["state"] = DGG.NORMAL self.__qtd_conexao = 0 addMensagem('Login ou senha invalido', COR_VERMELHO) self.__etyLogin.setFocus() elif vinerOnline.flg_conectado == vinerOnline.CONECTADO: #addMensagem("Conectado 12 !!!") #self.destroy() pass else: vinerOnline.conectar_servidor(login, senha) self.__qtd_conexao += 1 taskMgr.doMethodLater( INTERVALO_TENTATIVAS, self.__task_conectar_servidor, 'ConectarServidorLater', extraArgs = [login,senha], appendTask = True) msg = "Tentativa %s/5 - Conectando..." % (self.__qtd_conexao) addMensagem(msg, COR_BRANCO) else: vinerOnline.flg_conectado = vinerOnline.DESCONECT self.__btnEntrar["state"] = DGG.NORMAL self.__qtd_conexao = 0 addMensagem("Servidor nao encontrado", COR_VERMELHO) return task.done def destroy(self): self.__frmAuth.destroy() del self.__lblLogin del self.__etyLogin del self.__lblSenha del self.__etySenha del self.__btnEntrar del self.__frmAuth
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 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 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 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(): 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()
def createButton(self, text,verticalPos, eventArgs): btn = DirectButton(text=text,scale=0.25, pos=(0,0,verticalPos), command=base.messenger.send, extraArgs=eventArgs, rolloverSound=None, clickSound=None) btn.reparentTo(self.frameMain)
def fillControlsList(self): for key, value in sorted(self.engine.settings.playerKeys.items()): # the base frame of any item in the list itemFrame = DirectFrame( frameSize = (-0.9, 0.9, -0.09, 0), frameColor = (0, 1, 0, 0)) def changeKey(key, value): # all possible keyboard keys to set for a specific action keyboard = [ "escape", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "print_screen", "scroll_lock", "pause", "num_lock", "insert", "delete", "home", "end", "page_up", "page_down", "tab", "caps_lock", "shift", "rcontrol", "lcontrol", "ralt", "lalt", "space", "backspace", "enter", "arrow_left", "arrow_up", "arrow_down", "arrow_right", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ä", "ö", "ü", ",", ";", ".", ":", "_", "-", "#", "'", "+", "*", "~", "'", "`", "!", "\"", "§", "$", "%", "&", "/", "(", ")", "=", "?", "{", "}", "[", "]", "\\", "^", "°" ] def setKey(arg): """ This function will set the chosen key for the given action """ # ignore all keyboard inputs again for keyboardKey in keyboard: self.ignore(keyboardKey) if arg == 1: # if the dialog was closed with OK # set the settings to the new value self.engine.settings.playerKeys[key][0] = self.selectedKey if len(self.engine.settings.playerKeys[key]) > 1: # just set the run key value if it is possible newKey = self.engine.settings.playerKeys["run"][0] + "-" + self.selectedKey self.engine.settings.playerKeys[key][1] = newKey # refresh the controls list self.controlsList.removeAllItems() self.fillControlsList() # finaly close the dialog self.keySelectDialog.hide() self.keySelectDialog = None # this variable will store the selected key for the given action self.selectedKey = value[0] def setSelectedKey(selkey): """ set the pressed key as the selected one and actualise the text on the dialog """ self.selectedKey = selkey self.keySelectDialog["text"] = "{0}: {1}".format(key, self.selectedKey) # accept all keyboard keys for keyboardKey in keyboard: self.accept( keyboardKey, setSelectedKey, [keyboardKey]) # set up a dialog wich will ask for the new key for the chosen action self.keySelectDialog = OkCancelDialog( dialogName = "OkCancelDialog", text = "{0}: {1}".format(key, value[0]), fadeScreen = 1, command = setKey ) # show the dialog self.keySelectDialog.show() # add the change button to change the key of the action itemBtnChange = DirectButton( text = _("change"), scale = 0.05, pos = (0.5, 0, -0.05), command = changeKey, extraArgs = [key, value] ) itemBtnChange.reparentTo(itemFrame) # add the label wich will show the name and key of the action itemText = DirectLabel( text = "{0} - {1}".format(key, value[0]), text_scale = 0.06, text_align = TextNode.ALeft, pos = (-0.88, 0, -0.06)) itemText.reparentTo(itemFrame) # finaly add the item to the list self.controlsList.addItem(itemFrame)
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 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 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()