def runMusic(self): if self.menumusic and not self.song.isPlaying(): #re-randomize if self.files: i = random.randint(0, len(self.files) - 1) filename = self.files[i] sound = os.path.join("themes", self.themename, "sounds", filename) self.menumusic = True self.engine.menuMusic = True self.song = Audio.Music(self.engine.resource.fileName(sound)) self.song.setVolume( self.engine.config.get("audio", "menu_volume")) self.song.play(0) else: self.menumusic = False self.engine.menuMusic = False
def __init__(self, engine): self.engine = engine self.logClassInits = Config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("MainMenu class init (MainMenu.py)...") self.time = 0.0 self.nextLayer = None self.visibility = 0.0 self.active = False self.showStartupMessages = False self.gfxVersionTag = Config.get("game", "gfx_version_tag") self.chosenNeck = Config.get("game", "default_neck") exists = 0 if engine.loadImgDrawing( self, "ok", os.path.join("necks", self.chosenNeck + ".png")): exists = 1 elif engine.loadImgDrawing( self, "ok", os.path.join("necks", "Neck_" + self.chosenNeck + ".png")): exists = 1 #MFH - fallback logic now supports a couple valid default neck filenames #MFH - check for Neck_1 if exists == 0: if engine.loadImgDrawing(self, "ok", os.path.join("necks", "Neck_1.png")): Config.set("game", "default_neck", "1") Log.warn( "Default chosen neck not valid; fallback Neck_1.png forced." ) exists = 1 #MFH - check for defaultneck if exists == 0: if engine.loadImgDrawing(self, "ok", os.path.join("necks", "defaultneck.png")): Log.warn( "Default chosen neck not valid; fallback defaultneck.png forced." ) Config.set("game", "default_neck", "defaultneck") exists = 1 else: Log.error( "Default chosen neck not valid; fallbacks Neck_1.png and defaultneck.png also not valid!" ) #Get theme self.theme = self.engine.data.theme self.themeCoOp = self.engine.data.themeCoOp self.themename = self.engine.data.themeLabel self.useSoloMenu = self.engine.theme.use_solo_submenu allowMic = True self.menux = self.engine.theme.menuPos[0] self.menuy = self.engine.theme.menuPos[1] self.rbmenu = self.engine.theme.menuRB #MFH self.main_menu_scale = self.engine.theme.main_menu_scaleVar self.main_menu_vspacing = self.engine.theme.main_menu_vspacingVar if not self.engine.loadImgDrawing( self, "background", os.path.join("themes", self.themename, "menu", "mainbg.png")): self.background = None self.engine.loadImgDrawing( self, "BGText", os.path.join("themes", self.themename, "menu", "maintext.png")) self.engine.loadImgDrawing( self, "optionsBG", os.path.join("themes", self.themename, "menu", "optionsbg.png")) self.engine.loadImgDrawing( self, "optionsPanel", os.path.join("themes", self.themename, "menu", "optionspanel.png")) #racer: added version tag if self.gfxVersionTag or self.engine.theme.versiontag == True: if not self.engine.loadImgDrawing( self, "version", os.path.join("themes", self.themename, "menu", "versiontag.png")): if not self.engine.loadImgDrawing( self, "version", "versiontag.png" ): #falls back on default versiontag.png in data\ folder self.version = None else: self.version = None #myfingershurt: random main menu music function, menu.ogg and menuXX.ogg (any filename with "menu" as the first 4 letters) self.files = None filepath = self.engine.getPath( os.path.join("themes", self.themename, "sounds")) if os.path.isdir(filepath): self.files = [] allfiles = os.listdir(filepath) for name in allfiles: if os.path.splitext(name)[1] == ".ogg": if string.find(name, "menu") > -1: self.files.append(name) if self.files: i = random.randint(0, len(self.files) - 1) filename = self.files[i] sound = os.path.join("themes", self.themename, "sounds", filename) self.menumusic = True engine.menuMusic = True self.song = Audio.Music(self.engine.resource.fileName(sound)) self.song.setVolume(self.engine.config.get("audio", "menu_volume")) self.song.play(0) #no loop else: self.menumusic = False self.opt_text_color = self.engine.theme.opt_text_colorVar self.opt_selected_color = self.engine.theme.opt_selected_colorVar trainingMenu = [ (_("Tutorials"), self.showTutorial), (_("Practice"), lambda: self.newLocalGame(mode1p=1)), ] self.opt_bkg_size = [float(i) for i in self.engine.theme.opt_bkg_size] self.opt_text_color = self.engine.theme.hexToColor( self.engine.theme.opt_text_colorVar) self.opt_selected_color = self.engine.theme.hexToColor( self.engine.theme.opt_selected_colorVar) if self.BGText: strCareer = "" strQuickplay = "" strSolo = "" strMultiplayer = "" strTraining = "" strSettings = "" strQuit = "" else: strCareer = "Career" strQuickplay = "Quickplay" strSolo = "Solo" strMultiplayer = "Multiplayer" strTraining = "Training" strSettings = "Settings" strQuit = "Quit" multPlayerMenu = [ (_("Face-Off"), lambda: self.newLocalGame(players=2, maxplayers=4)), (_("Pro Face-Off"), lambda: self.newLocalGame(players=2, mode2p=1, maxplayers=4)), (_("Party Mode"), lambda: self.newLocalGame(mode2p=2)), (_("FoFiX Co-Op"), lambda: self.newLocalGame( players=2, mode2p=3, maxplayers=4, allowMic=allowMic)), (_("RB Co-Op"), lambda: self.newLocalGame( players=2, mode2p=4, maxplayers=4, allowMic=allowMic)), (_("GH Co-Op"), lambda: self.newLocalGame(players=2, mode2p=5, maxplayers=4)), (_("GH Battle"), lambda: self.newLocalGame(players=2, mode2p=6, allowDrum=False) ), #akedrou- so you can block drums ] if not self.useSoloMenu: mainMenu = [ (strCareer, lambda: self.newLocalGame(mode1p=2, allowMic=allowMic)), (strQuickplay, lambda: self.newLocalGame(allowMic=allowMic)), ((strMultiplayer, "multiplayer"), multPlayerMenu), ((strTraining, "training"), trainingMenu), ((strSettings, "settings"), self.settingsMenu), (strQuit, self.quit), ] else: soloMenu = [ (_("Solo Tour"), lambda: self.newLocalGame(mode1p=2, allowMic=allowMic)), (_("Quickplay"), lambda: self.newLocalGame(allowMic=allowMic)), ] mainMenu = [ ((strSolo, "solo"), soloMenu), ((strMultiplayer, "multiplayer"), multPlayerMenu), ((strTraining, "training"), trainingMenu), ((strSettings, "settings"), self.settingsMenu), (strQuit, self.quit), ] w, h, = self.engine.view.geometry[2:4] self.menu = Menu(self.engine, mainMenu, onClose=lambda: self.engine.view.popLayer(self), pos=(self.menux, .75 - (.75 * self.menuy))) engine.mainMenu = self #Points engine.mainMenu to the one and only MainMenu object instance ## whether the main menu has come into view at least once self.shownOnce = False