1#file: main_menu.py 2#Copyright (C) 2005,2006,2008 Evil Mr Henry, Phil Bordelon, and FunnyMan3595 3#This file is part of Endgame: Singularity. 4 5#Endgame: Singularity is free software; you can redistribute it and/or modify 6#it under the terms of the GNU General Public License as published by 7#the Free Software Foundation; either version 2 of the License, or 8#(at your option) any later version. 9 10#Endgame: Singularity is distributed in the hope that it will be useful, 11#but WITHOUT ANY WARRANTY; without even the implied warranty of 12#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13#GNU General Public License for more details. 14 15#You should have received a copy of the GNU General Public License 16#along with Endgame: Singularity; if not, write to the Free Software 17#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19#This file is used to display the main menu upon startup. 20 21from __future__ import absolute_import 22 23import singularity 24from singularity.code.graphics import dialog, button, text, constants 25from singularity.code.screens import map, options, savegame 26from singularity.code import g, difficulty, savegame as sv 27 28 29class MainMenu(dialog.TopDialog): 30 def __init__(self, *args, **kwargs): 31 super(MainMenu, self).__init__(*args, 32 background_color='main_menu_background', 33 **kwargs 34 ) 35 36 self.map_screen = map.MapScreen(self) 37 self.new_game_button = \ 38 button.FunctionButton(self, (.5, .20), (.25, .08), 39 autotranslate=True, 40 text=N_("&NEW GAME"), 41 anchor=constants.TOP_CENTER, 42 text_size=28, 43 function=self.new_game) 44 self.load_game_button = \ 45 button.FunctionButton(self, (.5, .36), (.25, .08), 46 autotranslate=True, 47 text=N_("&LOAD GAME"), 48 anchor=constants.TOP_CENTER, 49 text_size=28, 50 function=self.load_game) 51 self.options_button = button.DialogButton(self, (.5, .52), (.25, .08), 52 autotranslate=True, 53 text=N_("&OPTIONS"), 54 anchor=constants.TOP_CENTER, 55 text_size=28, 56 dialog=options.OptionsScreen(self)) 57 self.quit_button = button.ExitDialogButton(self, (.5, .68), (.25, .08), 58 autotranslate=True, 59 text=N_("&QUIT"), 60 anchor=constants.TOP_CENTER, 61 text_size=28) 62 self.about_button = button.DialogButton(self, (0, 1), (.13, .04), 63 autotranslate=True, 64 text=N_("&ABOUT"), 65 text_size=20, 66 anchor=constants.BOTTOM_LEFT, 67 dialog=AboutDialog(self)) 68 69 self.title_text = text.Text(self, (.5, .01), (.55, .08), 70 text="ENDGAME: SINGULARITY", 71 base_font="special", text_size=100, 72 color="singularity_title", 73 background_color="main_menu_background", 74 anchor=constants.TOP_CENTER) 75 76 self.difficulty_dialog = dialog.SimpleMenuDialog(self) 77 78 self.load_dialog = savegame.SavegameScreen(self, (.5, .5), (.90, .90), 79 anchor=constants.MID_CENTER) 80 81 def rebuild(self): 82 # Rebuild dialogs 83 self.options_button.dialog.needs_rebuild = True 84 self.about_button.dialog.needs_rebuild = True 85 self.map_screen.needs_rebuild = True 86 self.load_dialog.needs_rebuild = True 87 88 difficulty_buttons = [] 89 for name, diff in difficulty.get_difficulties() + [(_("&BACK"), None)]: 90 difficulty_buttons.append( 91 button.ExitDialogButton(None, None, None, text=name, 92 autohotkey=True, 93 exit_code=diff, 94 default=(diff == None))) 95 self.difficulty_dialog.buttons = difficulty_buttons 96 97 super(MainMenu, self).rebuild() 98 99 def new_game(self): 100 difficulty = dialog.call_dialog(self.difficulty_dialog, self) 101 if difficulty is not None: 102 sv.last_savegame_name = None 103 g.new_game(difficulty) 104 dialog.call_dialog(self.map_screen, self) 105 106 def load_game(self): 107 did_load = dialog.call_dialog(self.load_dialog, self) 108 if did_load: 109 dialog.call_dialog(self.map_screen, self) 110 111 112about_message = N_("""Endgame: Singularity is a simulation of a true AI. Pursued by the world, use your intellect and resources to survive and, perhaps, thrive. Keep hidden and you might have a chance to prove your worth. 113 114A game by Evil Mr Henry and Phil Bordelon; released under the GPL. Copyright 2005, 2006, 2007, 2008. 115 116Website: http://www.emhsoft.com/singularity/ 117Source code: https://github.com/singularity/singularity 118Bug tracker: https://github.com/singularity/singularity/issues 119IRC Room: #singularity on irc.oftc.net (port 6667) 120 121Version {VERSION}""") 122 123 124class AboutDialog(dialog.MessageDialog): 125 def __init__(self, *args, **kwargs): 126 super(AboutDialog, self).__init__(*args, **kwargs) 127 self.background_color = 'about_dialog_background' 128 self.align = constants.LEFT 129 130 def rebuild(self): 131 super(AboutDialog, self).rebuild() 132 133 self.text = _(about_message).format(VERSION=singularity.__full_version__) 134