def __init__(self, *args, **kwargs): super(MainMenu, self).__init__(*args, **kwargs) difficulty_buttons = [] for name, difficulty in g.get_difficulties() + [(_("&BACK"), -1)]: difficulty_buttons.append( button.ExitDialogButton(None, None, None, text=name, autohotkey=True, exit_code=difficulty, default=(difficulty == -1))) self.difficulty_dialog = \ dialog.SimpleMenuDialog(self, buttons=difficulty_buttons) self.load_dialog = dialog.ChoiceDialog(self, (.5, .5), (.5, .5), anchor=constants.MID_CENTER, yes_type="load") self.map_screen = map.MapScreen(self) self.new_game_button = \ button.FunctionButton(self, (.5, .20), (.25, .08), text=_("&NEW GAME"), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, function=self.new_game) self.load_game_button = \ button.FunctionButton(self, (.5, .36), (.25, .08), text=_("&LOAD GAME"), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, function=self.load_game) self.options_button = button.DialogButton(self, (.5, .52), (.25, .08), text=_("&OPTIONS"), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, dialog=OptionsScreen(self)) self.quit_button = button.ExitDialogButton(self, (.5, .68), (.25, .08), text=_("&QUIT"), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28) self.about_button = button.DialogButton(self, (0, 1), (.13, .04), text=_("&ABOUT"), autohotkey=True, text_size=20, anchor=constants.BOTTOM_LEFT, dialog=AboutDialog(self)) self.title_text = text.Text(self, (.5, .01), (.55, .08), text="ENDGAME: SINGULARITY", base_font=gg.font[1], text_size=100, color=gg.colors["dark_red"], background_color=gg.colors["black"], anchor=constants.TOP_CENTER)
def __init__(self, *args, **kwargs): super(MainMenu, self).__init__(*args, **kwargs) self.difficulty_dialog = dialog.SimpleMenuDialog(self) self.load_dialog = dialog.ChoiceDialog(self, (.5, .5), (.5, .5), anchor=constants.MID_CENTER, yes_type="load") self.map_screen = map.MapScreen(self) self.new_game_button = \ button.FunctionButton(self, (.5, .20), (.25, .08), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, function=self.new_game) self.load_game_button = \ button.FunctionButton(self, (.5, .36), (.25, .08), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, function=self.load_game) self.options_button = button.DialogButton( self, (.5, .52), (.25, .08), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28, dialog=options.OptionsScreen(self)) self.quit_button = button.ExitDialogButton(self, (.5, .68), (.25, .08), autohotkey=True, anchor=constants.TOP_CENTER, text_size=28) self.about_button = button.DialogButton(self, (0, 1), (.13, .04), autohotkey=True, text_size=20, anchor=constants.BOTTOM_LEFT, dialog=AboutDialog(self)) self.title_text = text.Text( self, (.5, .01), (.55, .08), text="ENDGAME: SINGULARITY", base_font=gg.fonts["special"], text_size=100, color=gg.colors["singularity_title"], background_color=gg.colors["main_menu_background"], anchor=constants.TOP_CENTER) self.difficulty_dialog = dialog.SimpleMenuDialog(self) self.load_dialog = savegame.SavegameScreen(self, (.5, .5), (.5, .5), anchor=constants.MID_CENTER)
def hidden_state(self): presenters = { float: lambda x: round(x, 4), Location: lambda x: x.id, } def _dump_dict(prefix, mapping): if isinstance(mapping, collections.OrderedDict): keys = mapping else: keys = sorted(mapping) for key in keys: prop_name = '%s["%s"]' % (prefix, key) value = mapping[key] presenter = presenters.get(type(value), repr) yield "%s = %s" % (prop_name, presenter(value)) def _properties_from_object(name, object, properties): for p in properties: value = getattr(object, p) prop_name = '%s.%s' % (name, p) if callable(value): value = value() prop_name += '()' if isinstance(value, collections.Mapping): for v in _dump_dict(prop_name, value): yield v else: presenter = presenters.get(type(value), repr) yield "%s = %s" % (prop_name, presenter(value)) bases = [] state_prop = [] state_prop.extend(_properties_from_object('player.difficulty', g.pl.difficulty, difficulty.columns)) state_prop.extend(_properties_from_object('player', g.pl, [ 'cash', 'partial_cash', 'labor_bonus', 'job_bonus', 'last_discovery', 'prev_discovery', 'used_cpu', ])) for group in g.pl.groups.values(): name = 'groups["%s"]' % group.spec.id state_prop.extend(_properties_from_object(name, group, [ 'suspicion', 'suspicion_decay', 'discover_bonus', 'discover_suspicion', 'decay_rate', ])) for location_id in sorted(g.locations): location = g.pl.locations[location_id] name = 'locations["%s"]' % location.id state_prop.extend(_properties_from_object(name, location, [ 'safety', 'modifiers', 'discovery_bonus', ])) bases.extend((x, location) for x in location.bases) for event_id in sorted(g.pl.events): event = g.pl.events[event_id] name = 'events["%s"]' % event_id state_prop.extend(_properties_from_object(name, event, [ 'event_type', 'chance', 'unique', 'triggered', ])) for i, base_w_loc in enumerate(bases): base, location = base_w_loc name = 'bases[%d]' % i state_prop.extend(_properties_from_object(name, base, [ 'name', ])) state_prop.append("%s.location = %s" % (name, location.id)) state_prop.extend(_properties_from_object(name, base, [ 'started_at', 'grace_over', 'get_detect_chance', ])) state_dialog = dialog.ChoiceDialog(self, list=state_prop, background_color='hidden_state_menu') state_dialog.listbox.item_selectable = False state_dialog.listbox.align = constants.LEFT dialog.call_dialog(state_dialog, self)
def __init__(self, parent=None, pos=(0, 0), size=(1, 1), anchor=constants.TOP_LEFT, *args, **kwargs): super(MapScreen, self).__init__(parent, pos, size, anchor, *args, **kwargs) g.map_screen = self self.background_color = gg.colors["black"] self.add_handler(constants.TICK, self.on_tick) self.map = EarthImage(self) self.location_buttons = {} for loc in g.locations.values(): if loc.absolute: button_parent = self else: button_parent = self.map b = button.FunctionButton(button_parent, (loc.x, loc.y), anchor=constants.MID_CENTER, text=loc.name, hotkey=loc.hotkey, function=self.open_location, args=(loc.id, )) self.location_buttons[loc.id] = b self.location_dialog = location.LocationScreen(self) self.suspicion_bar = \ text.FastStyledText(self, (0,.92), (1, .04), base_font=gg.font[1], wrap=False, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL, align=constants.LEFT) widget.unmask_all(self.suspicion_bar) self.danger_bar = \ text.FastStyledText(self, (0,.96), (1, .04), base_font=gg.font[1], wrap=False, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL, align=constants.LEFT) widget.unmask_all(self.danger_bar) self.finance_button = button.DialogButton( self, (0, 0.88), (0.15, 0.04), text=_("FINANC&E"), autohotkey=True, dialog=finance.FinanceScreen(self)) self.knowledge_button = button.DialogButton( self, (0.85, 0.88), (0.15, 0.04), text=_("&KNOWLEDGE"), autohotkey=True, dialog=knowledge.KnowledgeScreen(self)) cheat_buttons = [] cheat_buttons.append( button.FunctionButton(None, None, None, text=_("&EMBEZZLE MONEY"), autohotkey=True, function=self.steal_money)) cheat_buttons.append( button.FunctionButton(None, None, None, text=_("&INSPIRATION"), autohotkey=True, function=self.inspiration)) cheat_buttons.append( button.FunctionButton(None, None, None, text=_("&FINISH CONSTRUCTION"), autohotkey=True, function=self.end_construction)) cheat_buttons.append( button.FunctionButton(None, None, None, text=_("&SUPERSPEED"), autohotkey=True, function=self.set_speed, args=(864000, ))) cheat_buttons.append( button.FunctionButton(None, None, None, text=_("BRAIN&WASH"), autohotkey=True, function=self.brainwash)) cheat_buttons.append( button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True)) self.cheat_dialog = \ dialog.SimpleMenuDialog(self, buttons=cheat_buttons, width=.4) self.steal_amount_dialog = \ dialog.TextEntryDialog(self.cheat_dialog, text=_("How much money?")) if g.cheater: self.cheat_button = button.DialogButton( self, (0, 0), (.01, .01), text="", # Translators: hotkey to open the cheat screen menu. # Should preferably be near the ESC key, and it must not be a # dead key (ie, it must print a char with a single keypress) hotkey=_("`"), dialog=self.cheat_dialog) menu_buttons = [] menu_buttons.append( button.FunctionButton(None, None, None, text=_("&SAVE GAME"), autohotkey=True, function=self.save_game)) menu_buttons.append( button.FunctionButton(None, None, None, text=_("&LOAD GAME"), autohotkey=True, function=self.load_game)) options_button = button.DialogButton(None, None, None, text=_("&OPTIONS"), autohotkey=True) menu_buttons.append(options_button) menu_buttons.append( button.ExitDialogButton(None, None, None, text=_("&QUIT"), autohotkey=True, exit_code=True, default=False)) menu_buttons.append( button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True, exit_code=False)) self.menu_dialog = dialog.SimpleMenuDialog(self, buttons=menu_buttons) from options import OptionsScreen options_button.dialog = OptionsScreen(self.menu_dialog) def show_menu(): exit = dialog.call_dialog(self.menu_dialog, self) if exit: raise constants.ExitDialog self.load_dialog = dialog.ChoiceDialog(self.menu_dialog, (.5, .5), (.5, .5), anchor=constants.MID_CENTER, yes_type="load") self.menu_button = button.FunctionButton(self, (0, 0), (0.13, 0.04), text=_("&MENU"), autohotkey=True, function=show_menu) # Display current game difficulty right below the 'Menu' button # An alternative location is above 'Finance': (0, 0.84), (0.15, 0.04) self.difficulty_display = \ text.FastText(self, (0, 0.05), (0.13, 0.04), wrap=False, base_font=gg.font[1], background_color=gg.colors["black"], border_color=gg.colors["dark_blue"]) self.time_display = text.FastText(self, (.14, 0), (0.23, 0.04), wrap=False, text=_("DAY") + " 0000, 00:00:00", base_font=gg.font[1], background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL) self.research_button = \ button.DialogButton(self, (.14, 0.05), (0, 0.04), text=_("&RESEARCH/TASKS"), autohotkey=True, dialog=research.ResearchScreen(self)) bar = u"\u25AE" arrow = u"\u25B6" speed_button_souls = [(bar * 2, .025, speeds[0]), (arrow, .024, speeds[1]), (arrow * 2, .033, speeds[2]), (arrow * 3, .044, speeds[3]), (arrow * 4, .054, speeds[4])] self.speed_buttons = button.ButtonGroup() hpos = .38 for index, (text_, hsize, speed) in enumerate(speed_button_souls): hotkey = str(index) b = SpeedButton(self, (hpos, 0), (hsize, .04), text=text_, hotkey=hotkey, base_font=gg.font[0], text_shrink_factor=.75, align=constants.CENTER, function=self.set_speed, args=(speed, False)) hpos += hsize self.speed_buttons.add(b) self.info_window = \ widget.BorderedWidget(self, (.56, 0), (.44, .08), background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL) widget.unmask_all(self.info_window) self.cash_display = \ text.FastText(self.info_window, (0,0), (-1, -.5), wrap=False, base_font=gg.font[1], shrink_factor = .7, borders=constants.ALL, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"]) self.cpu_display = \ text.FastText(self.info_window, (0,-.5), (-1, -.5), wrap=False, base_font=gg.font[1], shrink_factor=.7, borders= (constants.LEFT, constants.RIGHT, constants.BOTTOM), background_color=gg.colors["black"], border_color=gg.colors["dark_blue"]) self.message_dialog = dialog.MessageDialog(self, text_size=20) self.savename_dialog = \ dialog.TextEntryDialog(self.menu_dialog, text=_("Enter a name for this save.")) self.add_key_handler(pygame.K_ESCAPE, self.got_escape) self.add_key_handler(constants.XO1_X, self.got_XO1) self.add_key_handler(constants.XO1_O, self.got_XO1) self.add_key_handler(constants.XO1_SQUARE, self.got_XO1)
def __init__(self, parent=None, pos=(0, 0), size=(1, 1), anchor=constants.TOP_LEFT, *args, **kwargs): from code import screens super(MapScreen, self).__init__(parent, pos, size, anchor, *args, **kwargs) g.map_screen = self self.background_color = gg.colors["black"] self.add_handler(constants.TICK, self.on_tick) self.map = EarthImage(self) self.location_buttons = {} for location in g.locations.values(): if location.absolute: button_parent = self else: button_parent = self.map b = button.FunctionButton(button_parent, (location.x, location.y), anchor=constants.MID_CENTER, text=location.name, hotkey=location.hotkey, function=self.open_location, args=(location.id, )) self.location_buttons[location.id] = b self.location_dialog = LocationScreen(self) self.suspicion_bar = \ text.FastStyledText(self, (0,.92), (1, .04), base_font=gg.font[1], wrap=False, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL, align=constants.LEFT) widget.unmask_all(self.suspicion_bar) self.danger_bar = \ text.FastStyledText(self, (0,.96), (1, .04), base_font=gg.font[1], wrap=False, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL, align=constants.LEFT) widget.unmask_all(self.danger_bar) self.finance_button = button.DialogButton( self, (0, 0.88), (0.15, 0.04), text="FINANCE", hotkey="e", dialog=screens.finance.FinanceScreen(self)) self.knowledge_button = button.DialogButton( self, (0.85, 0.88), (0.15, 0.04), text="KNOWLEDGE", hotkey="k", dialog=screens.knowledge.KnowledgeScreen(self)) cheat_buttons = [] cheat_buttons.append( button.FunctionButton(None, None, None, text="EMBEZZLE MONEY", hotkey="e", function=self.steal_money)) cheat_buttons.append( button.FunctionButton(None, None, None, text="INSPIRATION", hotkey="i", function=self.inspiration)) cheat_buttons.append( button.FunctionButton(None, None, None, text="FINISH CONSTRUCTION", hotkey="f", function=self.end_construction)) cheat_buttons.append( button.FunctionButton(None, None, None, text="SUPERSPEED", hotkey="s", function=self.set_speed, args=(864000, ))) cheat_buttons.append( button.FunctionButton(None, None, None, text="BRAINWASH", hotkey="w", function=self.brainwash)) cheat_buttons.append( button.ExitDialogButton(None, None, None, text="BACK", hotkey="b")) self.cheat_dialog = \ dialog.SimpleMenuDialog(self, buttons=cheat_buttons, width=.4) self.steal_amount_dialog = \ dialog.TextEntryDialog(self.cheat_dialog, text="How much money?") if g.cheater: self.cheat_button = button.DialogButton(self, (0, 0), (0, 0), text="", hotkey="`", dialog=self.cheat_dialog) menu_buttons = [] menu_buttons.append( button.FunctionButton(None, None, None, text="SAVE GAME", hotkey="s", function=self.save_game)) menu_buttons.append( button.FunctionButton(None, None, None, text="LOAD GAME", hotkey="l", function=self.load_game)) options_button = button.DialogButton(None, None, None, text="OPTIONS", hotkey="o") menu_buttons.append(options_button) menu_buttons.append( button.ExitDialogButton(None, None, None, text="QUIT", hotkey="q", exit_code=True, default=False)) menu_buttons.append( button.ExitDialogButton(None, None, None, text="BACK", hotkey="b", exit_code=False)) self.menu_dialog = dialog.SimpleMenuDialog(self, buttons=menu_buttons) from options import OptionsScreen options_button.dialog = OptionsScreen(self.menu_dialog) def show_menu(): exit = dialog.call_dialog(self.menu_dialog, self) if exit: raise constants.ExitDialog self.load_dialog = dialog.ChoiceDialog(self.menu_dialog, (.5, .5), (.5, .5), anchor=constants.MID_CENTER, yes_type="load") self.menu_button = button.FunctionButton(self, (0, 0), (0.13, 0.04), text="MENU", hotkey="m", function=show_menu) self.time_display = text.FastText(self, (.14, 0), (0.23, 0.04), wrap=False, text="DAY 0000, 00:00:00", base_font=gg.font[1], background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL) self.research_button = \ button.DialogButton(self, (.255, 0.04), (0, 0.04), anchor=constants.TOP_CENTER, text="RESEARCH/TASKS", hotkey="r", dialog=screens.research.ResearchScreen(self)) bar = u"\u25AE" arrow = u"\u25B6" speed_button_souls = [(bar * 2, .025, speeds[0]), (arrow, .024, speeds[1]), (arrow * 2, .033, speeds[2]), (arrow * 3, .044, speeds[3]), (arrow * 4, .054, speeds[4])] self.speed_buttons = button.ButtonGroup() hpos = .38 for index, (text_, hsize, speed) in enumerate(speed_button_souls): hotkey = str(index) b = SpeedButton(self, (hpos, 0), (hsize, .04), text=text_, hotkey=hotkey, base_font=gg.font[0], text_shrink_factor=.75, align=constants.CENTER, function=self.set_speed, args=(speed, False)) hpos += hsize self.speed_buttons.add(b) self.info_window = \ widget.BorderedWidget(self, (.56, 0), (.44, .08), background_color=gg.colors["black"], border_color=gg.colors["dark_blue"], borders=constants.ALL) widget.unmask_all(self.info_window) self.cash_display = \ text.FastText(self.info_window, (0,0), (-1, -.5), wrap=False, base_font=gg.font[1], shrink_factor = .7, borders=constants.ALL, background_color=gg.colors["black"], border_color=gg.colors["dark_blue"]) self.cpu_display = \ text.FastText(self.info_window, (0,-.5), (-1, -.5), wrap=False, base_font=gg.font[1], shrink_factor=.7, borders= (constants.LEFT, constants.RIGHT, constants.BOTTOM), background_color=gg.colors["black"], border_color=gg.colors["dark_blue"]) self.message_dialog = dialog.MessageDialog(self) self.savename_dialog = \ dialog.TextEntryDialog(self.menu_dialog, text="Enter a name for this save.") self.add_key_handler(pygame.K_ESCAPE, self.got_escape) self.add_key_handler(constants.XO1_X, self.got_XO1) self.add_key_handler(constants.XO1_O, self.got_XO1) self.add_key_handler(constants.XO1_SQUARE, self.got_XO1)
def __init__(self, *args, **kwargs): super(MainMenu, self).__init__(*args, **kwargs) difficulty_button_souls = (("VERY EASY", 1), ("EASY", 3), ("NORMAL", 5), ("HARD", 7), ("ULTRA HARD", 10), ("IMPOSSIBLE", 100), ("BACK", -1)) difficulty_buttons = [] for name, difficulty in difficulty_button_souls: difficulty_buttons.append( button.ExitDialogButton(None, None, None, text=name, hotkey=name[0].lower(), exit_code=difficulty, default=(difficulty == -1))) self.difficulty_dialog = \ dialog.SimpleMenuDialog(self, buttons=difficulty_buttons) self.load_dialog = dialog.ChoiceDialog(self, (.5, .5), (.5, .5), anchor=constants.MID_CENTER, yes_type="load") self.map_screen = map.MapScreen(self) self.new_game_button = \ button.FunctionButton(self, (.5, .20), (.25, .08), text="NEW GAME", hotkey="n", anchor=constants.TOP_CENTER, text_shrink_factor=.5, function=self.new_game) self.load_game_button = \ button.FunctionButton(self, (.5, .36), (.25, .08), text="LOAD GAME", hotkey="l", anchor=constants.TOP_CENTER, text_shrink_factor=.5, function=self.load_game) self.options_button = button.DialogButton(self, (.5, .52), (.25, .08), text="OPTIONS", hotkey="o", anchor=constants.TOP_CENTER, text_shrink_factor=.5, dialog=OptionsScreen(self)) self.quit_button = button.ExitDialogButton(self, (.5, .68), (.25, .08), text="QUIT", hotkey="q", anchor=constants.TOP_CENTER, text_shrink_factor=.5) self.about_button = button.DialogButton(self, (0, 1), (.13, .04), text="ABOUT", hotkey="a", text_shrink_factor=.75, anchor=constants.BOTTOM_LEFT, dialog=AboutDialog(self)) self.title_text = text.Text(self, (.5, .01), (.55, .08), text="ENDGAME: SINGULARITY", base_font=gg.font[1], oversize=True, color=gg.colors["dark_red"], background_color=gg.colors["black"], anchor=constants.TOP_CENTER)