class MainMenu(Menu): "Main Menu" def __init__(self): "Sets up the menu" Menu.__init__(self, "MoleFusion Main Menu", "sprites/back1.jpg") self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse( open("languages/MainMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"), (0.5, 0.1), (27, 22, 24)) self.start = GW_Button(self.curHandler.getText("start"), (0.5, 0.3), (255, 255, 255)) self.start.add_eventhandler("onmouseclick", self.start_onmouseclick) self.options = GW_Button(self.curHandler.getText("options"), (0.5, 0.45), (255, 255, 255)) self.options.add_eventhandler("onmouseclick", self.options_onmouseclick) self.highscores = GW_Button(self.curHandler.getText("highscores"), (0.5, 0.6), (255, 255, 255)) self.highscores.add_eventhandler("onmouseclick", self.highscores_onmouseclick) self.help = GW_Button(self.curHandler.getText("help"), (0.5, 0.75), (255, 255, 255)) self.help.add_eventhandler("onmouseclick", self.help_onmouseclick) self.quit = GW_Button(self.curHandler.getText("quit"), (0.5, 0.9), (255, 255, 255)) self.quit.add_eventhandler("onmouseclick", self.quit_onmouseclick) self.widget_man = GuiWidgetManager([ self.title, self.start, self.options, self.highscores, self.help, self.quit ]) self.time_speed = pygame.time.Clock() self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.widget_man.set_draw(True) def on_exit(self): pygame.event.clear() f = FadeTransition(500, Constants.FADECOLOR, "to") del f self.widget_man.set_draw(False) def start_onmouseclick(self, event): self.start.onmouseclick(event) self.on_exit() game = Game() game.run() self.start.onmouseclickup(event) self.on_enter() def options_onmouseclick(self, event): self.options.onmouseclick(event) self.on_exit() options = OptionsMenu() options.run() self.reload_titles() self.options.onmouseclickup(event) self.on_enter() def highscores_onmouseclick(self, event): self.highscores.onmouseclick(event) self.on_exit() highscores = HighScoresMenu("sprites/back1.jpg") highscores.run() self.reload_titles() self.highscores.onmouseclickup(event) self.on_enter() def help_onmouseclick(self, event): self.help.onmouseclick(event) self.on_exit() help = HelpMenu() help.run() self.help.onmouseclickup(event) self.reload_titles() self.on_enter() def quit_onmouseclick(self, event): self.quit.onmouseclick(event) self.on_exit() exit = ExitMenu() exit.run() pygame.event.post(pygame.event.Event(QUIT, {})) def reload_titles(self): self.parser.parse( open("languages/MainMenu_" + Constants.LANGUAGE + ".xml")) self.title.set_title(self.curHandler.getText("title")) self.start.set_title(self.curHandler.getText("start")) self.options.set_title(self.curHandler.getText("options")) self.highscores.set_title(self.curHandler.getText("highscores")) self.help.set_title(self.curHandler.getText("help")) self.quit.set_title(self.curHandler.getText("quit")) def run(self): while 1: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN and event.key == K_ESCAPE: self.quit_onmouseclick(event) else: pygame.event.post( event ) #Reinject the event into the queue for maybe latter process self.widget_man.run()
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 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 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 MainMenu(Menu): "Main Menu" def __init__(self): "Sets up the menu" Menu.__init__(self, "MoleFusion Main Menu", "sprites/back1.jpg") self.parser = make_parser() self.curHandler = Localization() self.parser.setContentHandler(self.curHandler) self.parser.parse(open("languages/MainMenu_" + Constants.LANGUAGE + ".xml")) self.title = GW_Label(self.curHandler.getText("title"), (0.5, 0.1), (27, 22, 24)) self.start = GW_Button(self.curHandler.getText("start"), (0.5, 0.3), (255, 255, 255)) self.start.add_eventhandler("onmouseclick", self.start_onmouseclick) self.options = GW_Button(self.curHandler.getText("options"), (0.5, 0.45), (255, 255, 255)) self.options.add_eventhandler("onmouseclick", self.options_onmouseclick) self.highscores = GW_Button(self.curHandler.getText("highscores"), (0.5, 0.6), (255, 255, 255)) self.highscores.add_eventhandler("onmouseclick", self.highscores_onmouseclick) self.help = GW_Button(self.curHandler.getText("help"), (0.5, 0.75), (255, 255, 255)) self.help.add_eventhandler("onmouseclick", self.help_onmouseclick) self.quit = GW_Button(self.curHandler.getText("quit"), (0.5, 0.9), (255, 255, 255)) self.quit.add_eventhandler("onmouseclick", self.quit_onmouseclick) self.widget_man = GuiWidgetManager( [self.title, self.start, self.options, self.highscores, self.help, self.quit] ) self.time_speed = pygame.time.Clock() self.on_enter() def on_enter(self): pygame.event.clear() self.screen.blit(self.background, (0, 0)) pygame.display.flip() self.widget_man.set_draw(True) def on_exit(self): pygame.event.clear() f = FadeTransition(500, Constants.FADECOLOR, "to") del f self.widget_man.set_draw(False) def start_onmouseclick(self, event): self.start.onmouseclick(event) self.on_exit() game = Game() game.run() self.start.onmouseclickup(event) self.on_enter() def options_onmouseclick(self, event): self.options.onmouseclick(event) self.on_exit() options = OptionsMenu() options.run() self.reload_titles() self.options.onmouseclickup(event) self.on_enter() def highscores_onmouseclick(self, event): self.highscores.onmouseclick(event) self.on_exit() highscores = HighScoresMenu("sprites/back1.jpg") highscores.run() self.reload_titles() self.highscores.onmouseclickup(event) self.on_enter() def help_onmouseclick(self, event): self.help.onmouseclick(event) self.on_exit() help = HelpMenu() help.run() self.help.onmouseclickup(event) self.reload_titles() self.on_enter() def quit_onmouseclick(self, event): self.quit.onmouseclick(event) self.on_exit() exit = ExitMenu() exit.run() pygame.event.post(pygame.event.Event(QUIT, {})) def reload_titles(self): self.parser.parse(open("languages/MainMenu_" + Constants.LANGUAGE + ".xml")) self.title.set_title(self.curHandler.getText("title")) self.start.set_title(self.curHandler.getText("start")) self.options.set_title(self.curHandler.getText("options")) self.highscores.set_title(self.curHandler.getText("highscores")) self.help.set_title(self.curHandler.getText("help")) self.quit.set_title(self.curHandler.getText("quit")) def run(self): while 1: self.time_speed.tick(Constants.FPS) for event in pygame.event.get(): if event.type == QUIT: os._exit(0) elif event.type == KEYDOWN and event.key == K_ESCAPE: self.quit_onmouseclick(event) else: pygame.event.post(event) # Reinject the event into the queue for maybe latter process self.widget_man.run()