class HelpMenu(Menu): "Help Menu" def __init__(self): "Sets up the Help menu" Menu.__init__(self,"MoleFusion Help Menu","sprites/back1.jpg") self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse(open("languages/HelpMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"),(0.5,0.1),(27,22,24)) self.help = GW_Image(self.curHandler.getText("help"),(0.5,0.3)) self.returnMain = GW_Button(self.curHandler.getText("returnMain"),(0.5,0.5),(255,255,255)) self.returnMain.add_eventhandler("onmouseclick",self.returnMain_onmouseclick) self.widget_man = GuiWidgetManager([self.title,self.help,self.returnMain]) self.time_speed=pygame.time.Clock() self.exit=False self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.exit=False self.widget_man.set_draw(True) def on_exit(self): f = FadeTransition(500,Constants.FADECOLOR,"to") del f self.exit=True self.widget_man.set_draw(False) pygame.event.clear() def returnMain_onmouseclick(self,event): self.returnMain.onmouseclick(event) self.on_exit() def reload_titles(self): self.parser.parse(open("languages/OptionsMenu_" + Constants.LANGUAGE + ".xml")) self.title.set_title(self.curHandler.getText("title")) self.help.set_title(self.curHandler.getText("help")) self.returnMain.set_title(self.curHandler.getText("returnMain")) def run(self): while 1 and self.exit==False: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN: if (not self.widget_man.has_input_focus()): if(event.key == K_ESCAPE): return #else: # pygame.event.post(event) #Reinject the event into the queue for maybe latter process else: pygame.event.post(event) #Reinject the event into the queue for maybe latter process self.widget_man.run()
class OptionsMenu(Menu): "Options Menu" def __init__(self): "Sets up the options menu" Menu.__init__(self, "MoleFusion Options Menu", "sprites/back1.jpg") self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse(open("languages/OptionsMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"), (0.5, 0.1), (27, 22, 24)) self.name = GW_Label(self.curHandler.getText("name"), (0.5, 0.2), (255, 255, 255)) self.inputname = GW_TextInput((0.5, 0.3), 24, 0.4, Constants.PLAYERNAME) self.language = GW_Button(self.curHandler.getText("language"), (0.5, 0.5), (255, 255, 255)) self.language.add_eventhandler("onmouseclick", self.language_onmouseclick) self.returnMain = GW_Button(self.curHandler.getText("returnMain"), (0.5, 0.8), (255, 255, 255)) self.returnMain.add_eventhandler("onmouseclick", self.returnMain_onmouseclick) self.widget_man = GuiWidgetManager([self.title, self.name, self.inputname, self.language, self.returnMain]) self.time_speed = pygame.time.Clock() self.exit = False self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.exit = False self.widget_man.set_draw(True) def on_exit(self): f = FadeTransition(500, Constants.FADECOLOR, "to") del f Constants.PLAYTIME = pygame.mixer.music.get_pos() self.exit = True self.widget_man.set_draw(False) Constants.PLAYERNAME = self.inputname.get_Text() pygame.event.clear() def language_onmouseclick(self, event): self.language.onmouseclick(event) self.on_exit() l = LanguageMenu() l.run() self.language.onmouseclickup(event) self.reload_titles() self.on_enter() pygame.mixer.music.play() def returnMain_onmouseclick(self, event): self.returnMain.onmouseclick(event) self.on_exit() def reload_titles(self): self.parser.parse(open("languages/OptionsMenu_" + Constants.LANGUAGE + ".xml")) self.name.set_title(self.curHandler.getText("name")) self.title.set_title(self.curHandler.getText("title")) self.language.set_title(self.curHandler.getText("language")) self.returnMain.set_title(self.curHandler.getText("returnMain")) def run(self): while 1 and self.exit == False: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN: if not self.widget_man.has_input_focus(): if event.key == K_ESCAPE: return else: pygame.event.post(event) # Reinject the event into the queue for maybe latter process else: pygame.event.post(event) # Reinject the event into the queue for maybe latter process self.widget_man.run()
class HighScoresMenu(Menu): "HighScores Menu" def __init__(self, background): "Set up the HighScores menu" Menu.__init__(self, "MoleFusion HighScore Menu", background) self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse( open("languages/HighScoresMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"), (0.5, 0.1), (27, 22, 24)) self.name_column = GW_Label(self.curHandler.getText("name"), (0.25, 0.25), (212, 224, 130)) self.points_column = GW_Label(self.curHandler.getText("points"), (0.75, 0.25), (212, 224, 130)) self.returnMain = GW_Button(self.curHandler.getText("returnMain"), (0.5, 0.9), (255, 255, 255)) self.returnMain.add_eventhandler("onmouseclick", self.returnMain_onmouseclick) h = HighScores() highscorelist = h.get_HighScores() self.widgetlist = [ self.title, self.name_column, self.points_column, self.returnMain ] for val, i in enumerate(highscorelist[0:5]): self.widgetlist.append( GW_Label(i.get_name(), (0.25, 0.35 + val / 10.0), (250, 254, 210))) self.widgetlist.append( GW_Label(str(i.get_points()), (0.75, 0.35 + val / 10.0), (250, 254, 210))) self.widget_man = GuiWidgetManager(self.widgetlist) self.time_speed = pygame.time.Clock() self.exit = False self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.exit = False self.widget_man.set_draw(True) def on_exit(self): pygame.event.clear() f = FadeTransition(500, Constants.FADECOLOR, "to") del f self.exit = True self.widget_man.set_draw(False) def returnMain_onmouseclick(self, event): self.returnMain.onmouseclick(event) self.on_exit() def run(self): while 1 and self.exit == False: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN: if (not self.widget_man.has_input_focus()): if (event.key == K_ESCAPE): return #else: # pygame.event.post(event) #Reinject the event into the queue for maybe latter process else: pygame.event.post( event ) #Reinject the event into the queue for maybe latter process self.widget_man.run()
class HighScoresMenu(Menu): "HighScores Menu" def __init__(self,background): "Set up the HighScores menu" Menu.__init__(self,"MoleFusion HighScore Menu",background) self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse(open("languages/HighScoresMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"),(0.5,0.1),(27,22,24)) self.name_column = GW_Label(self.curHandler.getText("name"),(0.25,0.25),(212,224,130)) self.points_column = GW_Label(self.curHandler.getText("points"),(0.75,0.25),(212,224,130)) self.returnMain = GW_Button(self.curHandler.getText("returnMain"),(0.5,0.9),(255,255,255)) self.returnMain.add_eventhandler("onmouseclick",self.returnMain_onmouseclick) h = HighScores() highscorelist = h.get_HighScores() self.widgetlist = [self.title,self.name_column,self.points_column,self.returnMain] for val,i in enumerate(highscorelist[0:5]): self.widgetlist.append(GW_Label(i.get_name(),(0.25,0.35+val/10.0),(250,254,210))) self.widgetlist.append(GW_Label(str(i.get_points()),(0.75,0.35+val/10.0),(250,254,210))) self.widget_man = GuiWidgetManager(self.widgetlist) self.time_speed=pygame.time.Clock() self.exit=False self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.exit=False self.widget_man.set_draw(True) def on_exit(self): pygame.event.clear() f = FadeTransition(500,Constants.FADECOLOR,"to") del f self.exit=True self.widget_man.set_draw(False) def returnMain_onmouseclick(self,event): self.returnMain.onmouseclick(event) self.on_exit() def run(self): while 1 and self.exit==False: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN: if (not self.widget_man.has_input_focus()): if(event.key == K_ESCAPE): return #else: # pygame.event.post(event) #Reinject the event into the queue for maybe latter process else: pygame.event.post(event) #Reinject the event into the queue for maybe latter process self.widget_man.run()