def __init__(self, map_screen): super(GameMenuDialog, self).__init__(parent=map_screen) self._map_screen = map_screen self.options_dialog = OptionsScreen(self) self.savename_dialog = dialog.TextEntryDialog(self) self.load_dialog = savegame.SavegameScreen(self, (.5, .5), (.90, .90), anchor=constants.MID_CENTER) self._buttons = [ button.FunctionButton(None, None, None, text=_("&SAVE GAME"), autotranslate=True, function=self.save_game), button.FunctionButton(None, None, None, text=_("&LOAD GAME"), autotranslate=True, function=self.load_game), button.DialogButton(None, None, None, text=_("&OPTIONS"), autotranslate=True, dialog=self.options_dialog), button.ExitDialogButton(None, None, None, text=_("&QUIT"), autotranslate=True, exit_code=True, default=False), button.ExitDialogButton(None, None, None, text=_("&BACK"), autotranslate=True, exit_code=False), ] self.needs_rebuild = True
def _rebuild_menu_buttons(self): menu_buttons = [ button.FunctionButton(None, None, None, text=_("&SAVE GAME"), autohotkey=True, function=self.save_game), button.FunctionButton(None, None, None, text=_("&LOAD GAME"), autohotkey=True, function=self.load_game), button.DialogButton(None, None, None, text=_("&OPTIONS"), autohotkey=True, dialog=self.options_dialog), button.ExitDialogButton(None, None, None, text=_("&QUIT"), autohotkey=True, exit_code=True, default=False), button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True, exit_code=False), ] self._buttons = menu_buttons
def __init__(self, parent, *args, **kwargs): self.parent = parent yes_type = kwargs.pop("yes_type", N_("&YES")) no_type = kwargs.pop("no_type", N_("&NO")) self.invert_enter = kwargs.pop("invert_enter", False) self.invert_escape = kwargs.pop("invert_escape", False) super(YesNoDialog, self).__init__(parent, *args, **kwargs) self.yes_button = button.ExitDialogButton(self, (-.1, -.99), (-.3, -.1), text=yes_type, autotranslate=True, anchor=constants.BOTTOM_LEFT, exit_code=True, default=False) self.no_button = button.ExitDialogButton(self, (-.9, -.99), (-.3, -.1), text=no_type, autotranslate=True, anchor=constants.BOTTOM_RIGHT, exit_code=False, default=False) self.add_key_handler(pygame.K_RETURN, self.on_return) self.add_key_handler(pygame.K_KP_ENTER, self.on_return) self.add_key_handler(pygame.K_ESCAPE, self.on_escape)
def __init__(self, *args, **kwargs): super(KnowledgeScreen, self).__init__(*args, **kwargs) self.cur_knowledge_type = "" self.cur_knowledge = None self.knowledge_inner_list = () self.knowledge_inner_list_key = () self.knowledge_choice = \ listbox.UpdateListbox(self, (0.04, .18), (.18, .25), update_func=self.set_knowledge_type) # Tech names are typically a lot longer than knowledge concepts. # Therefore, we make knowledge_inner a lot wider than # knowledge_choice. self.knowledge_inner = \ listbox.UpdateListbox(self, (.26, .18), (.37, .25), update_func=self.set_knowledge) self.description_pane = \ widget.BorderedWidget(self, (0.66, 0), (0.30, 0.7), anchor = constants.TOP_LEFT) self.back_button = button.ExitDialogButton(self, (0.17, 0.46), (-.3, -.1), autotranslate=True, text=N_("&BACK"), anchor=constants.TOP_LEFT, autohotkey=True) self.took_focus(self.knowledge_choice) self.add_key_handler(pygame.K_LEFT, self.key_handle) self.add_key_handler(pygame.K_RIGHT, self.key_handle)
def __init__(self, map_screen): super(CheatMenuDialog, self).__init__(parent=map_screen) self._map_screen = map_screen self.steal_amount_dialog = None self.buttons = [ button.FunctionButton(None, None, None, text=_("&EMBEZZLE MONEY"), autotranslate=True, function=self.steal_money), button.FunctionButton(None, None, None, text=_("&INSPIRATION"), autotranslate=True, function=self.inspiration), button.FunctionButton(None, None, None, text=_("&FINISH CONSTRUCTION"), autotranslate=True, function=self.end_construction), button.FunctionButton(None, None, None, text=_("&SUPERSPEED"), autotranslate=True, function=self._map_screen.set_speed, args=(864000,)), button.FunctionButton(None, None, None, text=_("BRAIN&WASH"), autotranslate=True, function=self.brainwash), button.FunctionButton(None, None, None, text=_("TOGGLE &DETECTION"), autotranslate=True, function=self.toggle_detection), button.FunctionButton(None, None, None, text=_("TOGGLE &ANALYSIS"), autotranslate=True, function=self.set_analysis), button.FunctionButton(None, None, None, text=_("HIDDEN S&TATE"), autotranslate=True, function=self.hidden_state), button.ExitDialogButton(None, None, None, text=_("&BACK"), autotranslate=True), ] self.needs_rebuild = True
def rebuild(self): # Rebuild dialogs self.options_button.dialog.needs_rebuild = True self.about_button.dialog.needs_rebuild = True self.map_screen.needs_rebuild = True self.load_dialog.needs_rebuild = True difficulty_buttons = [] for name, diff in difficulty.get_difficulties() + [(_("&BACK"), None)]: difficulty_buttons.append( button.ExitDialogButton(None, None, None, text=name, autohotkey=True, exit_code=diff, default=(diff == None))) self.difficulty_dialog.buttons = difficulty_buttons # Update buttons translations self.new_game_button.text = _("&NEW GAME") self.load_game_button.text = _("&LOAD GAME") self.options_button.text = _("&OPTIONS") self.quit_button.text = _("&QUIT") self.about_button.text = _("&ABOUT") super(MainMenu, self).rebuild()
def _rebuild_menu_buttons(self): menu_buttons = [ button.FunctionButton(None, None, None, text=_("&EMBEZZLE MONEY"), autohotkey=True, function=self.steal_money), button.FunctionButton(None, None, None, text=_("&INSPIRATION"), autohotkey=True, function=self.inspiration), button.FunctionButton(None, None, None, text=_("&FINISH CONSTRUCTION"), autohotkey=True, function=self.end_construction), button.FunctionButton(None, None, None, text=_("&SUPERSPEED"), autohotkey=True, function=self._map_screen.set_speed, args=(864000, )), button.FunctionButton(None, None, None, text=_("BRAIN&WASH"), autohotkey=True, function=self.brainwash), button.FunctionButton(None, None, None, text=_("TOGGLE &DETECTION"), autohotkey=True, function=self.toggle_detection), button.FunctionButton(None, None, None, text=_("TOGGLE &ANALYSIS"), autohotkey=True, function=self.set_analysis), button.FunctionButton(None, None, None, text=_("HIDDEN S&TATE"), autohotkey=True, function=self.hidden_state), button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True), ] self._buttons = menu_buttons
def __init__(self, map_screen): super(GameMenuDialog, self).__init__(parent=map_screen) self._map_screen = map_screen self.options_dialog = OptionsScreen(self) self.savename_dialog = dialog.TextEntryDialog(self) self.load_dialog = savegame.SavegameScreen(self, (.5, .5), (.90, .90), anchor=constants.MID_CENTER) self._buttons = [ button.FunctionButton(None, None, None, text=_("&SAVE GAME"), autotranslate=True, function=self.save_game), button.FunctionButton(None, None, None, text=_("&LOAD GAME"), autotranslate=True, function=self.load_game), button.DialogButton(None, None, None, text=_("&OPTIONS"), autotranslate=True, dialog=self.options_dialog), button.ExitDialogButton(None, None, None, text=_("&QUIT"), autotranslate=True, exit_code=True, default=False), button.ExitDialogButton(None, None, None, text=_("&BACK"), autotranslate=True, exit_code=False), ] # Hide hotkeys (#289) to avoid confusion due to poor focus visibility self.savename_dialog.ok_button.force_underline = -1 self.savename_dialog.cancel_button.force_underline = -1 self.needs_rebuild = True
def __init__(self, parent, **kwargs): self.parent = parent self.ok_type = kwargs.pop("ok_type", "ok") super(MessageDialog, self).__init__(parent, **kwargs) self.ok_button = button.ExitDialogButton( self, (-.5, -.99), (-.3, -.1), anchor=constants.BOTTOM_CENTER) self.add_key_handler(pygame.K_RETURN, self.on_return) self.add_key_handler(pygame.K_KP_ENTER, self.on_return)
def __init__(self, *args, **kwargs): super(KnowledgeScreen, self).__init__(*args, **kwargs) self.cur_knowledge_type = "" self.cur_knowledge = None self.knowledge_inner_list = () self.knowledge_inner_list_key = () self.cur_focus = 0 self.knowledge_choice = \ listbox.UpdateListbox(self, (0.05, .18), (.21, .25), update_func=self.set_knowledge_type) self.knowledge_inner = \ listbox.UpdateListbox(self, (.30, .18), (.21, .25), update_func=self.set_knowledge) self.description_pane = \ widget.BorderedWidget(self, (0.55, 0), (0.40, 0.7), anchor = constants.TOP_LEFT) self.back_button = button.ExitDialogButton(self, (0.17, 0.46), (-.3, -.1), anchor=constants.TOP_LEFT, autohotkey=True) #Set up the key handling. #This is likely not the best way to do it. self.remove_key_handler(pygame.K_UP, self.knowledge_choice.got_key) self.remove_key_handler(pygame.K_DOWN, self.knowledge_choice.got_key) self.remove_key_handler(pygame.K_PAGEUP, self.knowledge_choice.got_key) self.remove_key_handler(pygame.K_PAGEDOWN, self.knowledge_choice.got_key) self.remove_key_handler(pygame.K_UP, self.knowledge_inner.got_key) self.remove_key_handler(pygame.K_DOWN, self.knowledge_inner.got_key) self.remove_key_handler(pygame.K_PAGEUP, self.knowledge_inner.got_key) self.remove_key_handler(pygame.K_PAGEDOWN, self.knowledge_inner.got_key) self.add_key_handler(pygame.K_UP, self.key_handle, only_on_event_type=pygame.KEYDOWN) self.add_key_handler(pygame.K_DOWN, self.key_handle, only_on_event_type=pygame.KEYDOWN) self.add_key_handler(pygame.K_LEFT, self.key_handle, only_on_event_type=pygame.KEYDOWN) self.add_key_handler(pygame.K_RIGHT, self.key_handle, only_on_event_type=pygame.KEYDOWN)
def __init__(self, parent, **kwargs): ok_type = kwargs.pop("ok_type", N_("&OK")) super(MessageDialog, self).__init__(parent, **kwargs) self.ok_button = button.ExitDialogButton( self, (-.5, -.99), (-.3, -.1), autotranslate=True, text=ok_type, anchor=constants.BOTTOM_CENTER) self.add_key_handler(pygame.K_RETURN, self.on_return) self.add_key_handler(pygame.K_KP_ENTER, self.on_return)
def __init__(self, *args, **kwargs): super(MainMenu, self).__init__(*args, background_color='main_menu_background', **kwargs) self.map_screen = map.MapScreen(self) self.new_game_button = \ button.FunctionButton(self, (.5, .20), (.25, .08), autotranslate=True, text=N_("&NEW GAME"), anchor=constants.TOP_CENTER, text_size=28, function=self.new_game) self.load_game_button = \ button.FunctionButton(self, (.5, .36), (.25, .08), autotranslate=True, text=N_("&LOAD GAME"), anchor=constants.TOP_CENTER, text_size=28, function=self.load_game) self.options_button = button.DialogButton( self, (.5, .52), (.25, .08), autotranslate=True, text=N_("&OPTIONS"), anchor=constants.TOP_CENTER, text_size=28, dialog=options.OptionsScreen(self)) self.quit_button = button.ExitDialogButton(self, (.5, .68), (.25, .08), autotranslate=True, text=N_("&QUIT"), anchor=constants.TOP_CENTER, text_size=28) self.about_button = button.DialogButton(self, (0, 1), (.13, .04), autotranslate=True, text=N_("&ABOUT"), 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="special", text_size=100, color="singularity_title", background_color="main_menu_background", anchor=constants.TOP_CENTER) self.difficulty_dialog = dialog.SimpleMenuDialog(self) self.load_dialog = savegame.SavegameScreen(self, (.5, .5), (.90, .90), anchor=constants.MID_CENTER)
def __init__(self, parent, pos=(.5, .1), size=(.93, .73), *args, **kwargs): super(ReportScreen, self).__init__(parent, pos, size, *args, **kwargs) kwargs.setdefault("background_color", "clear") self.format_buttons = button.ButtonGroup() self.stats_button = button.DialogButton(self, (-.49, -.99), (-.3, -.1), autotranslate=True, text=N_("&STATISTICS"), anchor=constants.BOTTOM_RIGHT, dialog=stat.StatScreen(self)) self.back_button = button.ExitDialogButton( self, (-.51, -.99), (-.3, -.1), autotranslate=True, text=N_("&BACK"), anchor=constants.BOTTOM_LEFT, ) self.add_key_handler(pygame.K_ESCAPE, self.back_button.activate_with_sound) self.money_report_pane = widget.BorderedWidget( self, (0, .08), (-.45, -.72), anchor=constants.TOP_LEFT) self.cpu_report_pane = widget.BorderedWidget( self, (-1, .08), (-.45, -.72), anchor=constants.TOP_RIGHT) self.format_button_midnight = FormatButton(self, (-.5, 0), (-.15, -.08), autotranslate=True, text=N_("&Midnight"), anchor=constants.TOP_RIGHT, function=self.format_toggle) self.format_button_midnight.args = (self.format_button_midnight, True) self.format_buttons.add(self.format_button_midnight) self.format_button_24hours = FormatButton(self, (-.5, 0), (-.15, -.08), autotranslate=True, text=N_("24 &Hours"), anchor=constants.TOP_LEFT, function=self.format_toggle) self.format_button_24hours.args = (self.format_button_24hours, False) self.format_buttons.add(self.format_button_24hours) self.format_button_midnight.chosen_one() self.midnight_stop = True
def rebuild(self): # Rebuild dialogs self.options_button.dialog.needs_rebuild = True self.about_button.dialog.needs_rebuild = True self.map_screen.needs_rebuild = True self.load_dialog.needs_rebuild = True difficulty_buttons = [] for name, diff in difficulty.get_difficulties() + [(_("&BACK"), None)]: difficulty_buttons.append( button.ExitDialogButton(None, None, None, text=name, autohotkey=True, exit_code=diff, default=(diff == None))) self.difficulty_dialog.buttons = difficulty_buttons super(MainMenu, self).rebuild()
def __init__(self, *args, **kwargs): super(KnowledgeScreen, self).__init__(*args, **kwargs) self.knowledge_types = collections.OrderedDict() self.knowledge_type_index = collections.defaultdict(int) self.cur_knowledge_type = "" self.cur_knowledge = None self.knowledge_inner_list = () self.knowledge_inner_list_key = () self.knowledge_choice_title = button.HotkeyText( self, (.08, .04), (.42, .05), autotranslate=True, text=N_("&Sections:"), align=constants.LEFT, background_color="clear") self.knowledge_choice = \ listbox.UpdateListbox(self, (.08, .09), (.42, .22), update_func=self.set_knowledge_type) self.knowledge_choice_title.hotkey_func = lambda e: self.took_focus( self.knowledge_choice) self.knowledge_inner_title = button.HotkeyText( self, (.08, .35), (.42, .05), autotranslate=True, text=N_("&Entries:"), align=constants.LEFT, background_color="clear") self.knowledge_inner = \ listbox.UpdateListbox(self, (.08, .40), (.42, .22), update_func=self.set_knowledge) self.knowledge_inner_title.hotkey_func = lambda e: self.took_focus( self.knowledge_inner) self.description_pane = \ widget.BorderedWidget(self, (.54, .04), (.38, .70), anchor = constants.TOP_LEFT) self.back_button = button.ExitDialogButton(self, (.18, .68), (.22, .06), autotranslate=True, text=N_("&BACK"), anchor=constants.TOP_LEFT, autohotkey=True) self.took_focus(self.knowledge_choice)
def __init__(self, *args, **kwargs): if len(args) < 3: kwargs.setdefault("size", (.90, .70)) base = kwargs.pop("base", None) super(BaseScreen, self).__init__(*args, **kwargs) self.base = base self.build_dialog = BuildDialog(self) self.multiple_build_dialog = MultipleBuildDialog(self) self.header = widget.Widget(self, (0, 0), (-1, .08), anchor=constants.TOP_LEFT) self.name_display = text.Text(self.header, (-.5, 0), (-1, -.5), anchor=constants.TOP_CENTER, borders=constants.ALL, border_color="pane_background", background_color="pane_background_empty", shrink_factor=.85, bold=True) self.next_base_button = \ button.FunctionButton(self.name_display, (-1, 0), (.03, -1), anchor=constants.TOP_RIGHT, text=">", hotkey=">", function=self.switch_base, kwargs={"forwards": True}) self.add_key_handler(pygame.K_RIGHT, self.next_base_button.activate_with_sound) self.prev_base_button = \ button.FunctionButton(self.name_display, (0, 0), (.03, -1), anchor=constants.TOP_LEFT, text="<", hotkey="<", function=self.switch_base, kwargs={"forwards": False}) self.add_key_handler(pygame.K_LEFT, self.prev_base_button.activate_with_sound) self.state_display = text.Text( self.header, (-.5, -.5), (-1, -.5), anchor=constants.TOP_CENTER, borders=(constants.LEFT, constants.RIGHT, constants.BOTTOM), border_color="pane_background", background_color="pane_background_empty", shrink_factor=.8, bold=True) self.back_button = \ button.ExitDialogButton(self, (-.5, -1), autotranslate=True, text=N_("&BACK"), anchor=constants.BOTTOM_CENTER, ) self.info_frame = text.Text(self, (-1, .09), (.26, .53), anchor=constants.TOP_RIGHT, background_color="pane_background", borders=constants.ALL, bold=True, align=constants.LEFT, valign=constants.TOP) self.contents_frame = \ widget.BorderedWidget(self, (0, .09), (.60, .53), anchor=constants.TOP_LEFT, background_color="pane_background", borders=range(6)) for i, item_type in enumerate(item.all_types()): setattr( self, item_type.id + "_pane", ItemPane(self.contents_frame, (.01, .01 + .08 * i), item_type=item_type))
def __init__(self, *args, **kwargs): super(LocationScreen, self).__init__(*args, **kwargs) self.pos = (-.5, -.5) self.anchor = constants.MID_CENTER self.size = (.75, .70) self.name_display = text.Text(self, (0,0), (-1, -.08), anchor=constants.TOP_LEFT, borders=constants.ALL, border_color="pane_background", background_color="pane_background_empty", shrink_factor=1, bold=True) self.modifier_display = text.Text(self, (-.75, -.01), (-.25, -.06), anchor=constants.TOP_LEFT, background_color="clear") self.open_button = \ button.FunctionButton(self, (0, -.8), (-.3, -.09), autotranslate=True, text=N_("&OPEN BASE"), anchor=constants.TOP_LEFT, autohotkey=True, function=self.open_base) self.listbox = listbox.CustomListbox(self, (0,-.09), (-1, -.69), remake_func=self.make_item, rebuild_func=self.update_item, on_double_click_on_item=self.open_button.activated, ) self.rename_button = \ button.FunctionButton(self, (-.50, -.8), (-.3, -.09), autotranslate=True, text=N_("&RENAME BASE"), anchor=constants.TOP_CENTER, autohotkey=True, function=self.rename_base) self.power_button = \ button.FunctionButton(self, (-1, -.8), (-.3, -.09), autotranslate=True, text=N_("&POWER STATE"), anchor=constants.TOP_RIGHT, autohotkey=True, function=self.power_state) self.new_button = \ button.FunctionButton(self, (0, -.91), (-.3, -.09), autotranslate=True, text=N_("&NEW BASE"), autohotkey=True, function=self.new_base) self.destroy_button = \ button.FunctionButton(self, (-.50, -.91), (-.3, -.09), autotranslate=True, text=N_("&DESTROY BASE"), anchor=constants.TOP_CENTER, autohotkey=True, function=self.destroy_base) self.back_button = button.ExitDialogButton(self, (-1, -.9), (-.3, -.09), autotranslate=True, text=N_("&BACK"), anchor=constants.TOP_RIGHT, autohotkey=True) self.confirm_destroy = \ dialog.YesNoDialog(self, (-.5, 0), (-.35, -.7), autotranslate=True, text=N_("Are you sure you want to destroy this base?"), shrink_factor=.5) self.cannot_destroy_last_base = \ dialog.MessageDialog(self, autotranslate=True, text=N_("Destroying my last active base would be suicidal. I cannot do that."), pos=(-.5, 0), size=(-.35, -.7), shrink_factor=.5) self.new_base_dialog = NewBaseDialog(self) self.location = None self.name_dialog = dialog.TextEntryDialog(self) self.base_dialog = basescreen.BaseScreen(self, (0,0), anchor=constants.TOP_LEFT)