def check_restart(self): # Test all changes that require a restart. Currently, none. # We keep it for future need... need_restart = False # Add restart test here. if not need_restart: # No restart required. Simply exit the dialog respecting all hooks self.yes_button.exit_dialog() return # Ask user about a restart ask_restart = dialog.YesNoDialog( self, pos=(-.50, -.50), anchor=constants.MID_CENTER, text= _("""You must restart for some of the changes to be fully applied.\n Would you like to restart the game now?"""), ) if dialog.call_dialog(ask_restart, self): # YES, go for it #TODO: check if there is an ongoing game, save it under a special # name and automatically load it after restart using a custom # command-line argument save_options() restart() else: # NO, revert "restart-able" changes pass
def convert_save(self): save = self.listbox.current_item() if save is None: return if not self._load_savegame(save): return # For ".sav" files, we end up creating a parallel ".s2" file and need # to clean up the ".sav" file manually. overwrites_in_place = False if sv.savegame_exists(save.name): if save.savegame_format.internal_version < 99.8: # We seem to be updating a ".sav" file but there is an ".s2" # file? This should only happen to beta testers yn = dialog.YesNoDialog( self, pos=(-.5, -.5), size=(-.5, -.5), anchor=constants.MID_CENTER, text=_( "A savegame with the same name but for a newer version exists.\n" "Are you sure to overwrite the saved game ?")) overwrite = dialog.call_dialog(yn, self) if not overwrite: return else: # Saving will override in place; overwrites_in_place = True sv.create_savegame(save.name) if not overwrites_in_place: sv.delete_savegame(save) self.reload_savegames()
def delete_savegame(self): yn = dialog.YesNoDialog(self, pos=(-.5,-.5), size=(-.5,-1), anchor=constants.MID_CENTER, text=_("Are you sure to delete the saved game ?")) delete = dialog.call_dialog(yn, self) yn.parent = None if delete: save = self.listbox.current_item() sv.delete_savegame(save) self.reload_savegames()
def show_story_section(self, name): section = list(g.get_story_section(name)) first_dialog = dialog.YesNoDialog(self, yes_type=N_("&CONTINUE"), no_type=N_("&SKIP")) last_dialog = dialog.MessageDialog(self, ok_type=N_("&OK")) for num, segment in enumerate(section): story_dialog = first_dialog if num != len(section) - 1 else last_dialog story_dialog.text = segment if not dialog.call_dialog(story_dialog, self): break first_dialog.parent = None last_dialog.parent = None
def show_story_section(self, name): section = list(g.get_story_section(name)) first_dialog = dialog.YesNoDialog(self, yes_type="continue", no_type="skip") last_dialog = dialog.MessageDialog(self, ok_type="ok") for num, segment in enumerate(section): story_dialog = first_dialog if num != len( section) - 1 else last_dialog story_dialog.text = segment if not dialog.call_dialog(story_dialog, self): break first_dialog.parent = None last_dialog.parent = None
def save_game(self): self.savename_dialog.default_text = sv.default_savegame_name name = dialog.call_dialog(self.savename_dialog, self) if name: if sv.savegame_exists(name): yn = dialog.YesNoDialog( self, pos=(-.5, -.5), size=(-.5, -.5), anchor=constants.MID_CENTER, text=_("A savegame with the same name exists.\n" "Are you sure to overwrite the saved game ?")) overwrite = dialog.call_dialog(yn, self) if not overwrite: return sv.create_savegame(name) raise constants.ExitDialog(False)
def save_game(self): # If no savename was set yet, use current difficulty if not sv.last_savegame_name: sv.last_savegame_name = g.strip_hotkey(g.pl.difficulty.name) self.savename_dialog.default_text = sv.last_savegame_name self.savename_dialog.add_handler(constants.KEYUP, self.check_filename) self.savename_dialog.text_field.has_focus = True name = dialog.call_dialog(self.savename_dialog, self).strip() if name: if sv.savegame_exists(name): yn = dialog.YesNoDialog(self, pos=(-.5,-.5), size=(-.5,-.5), anchor=constants.MID_CENTER, text=_("A savegame with the same name exists.\n" "Are you sure to overwrite the saved game ?")) overwrite = dialog.call_dialog(yn, self) if not overwrite: self.save_game() sv.create_savegame(name) raise constants.ExitDialog(False)
def show(self): self.force_update() from singularity.code.safety import safe_call # By using safe call here (and only here), if an error is raised # during the game, it will drop back out of all the menus, without # doing anything, and open the pause dialog, so that the player can # save or quit even if the error occurs every game tick. while safe_call(super(MapScreen, self).show, on_error=True): for child in self.children: if isinstance(child, dialog.Dialog): child.visible = False # Display a message so the player understand better what happened. msg = _(""" A error has occurred. The game will automatically pause and open the game menu. You can continue and save or quit immediately. A report was written out to%s Please create a issue with this report at github: https://github.com/singularity/singularity """ % (":\n" + g.logfile if g.logfile is not None else " console output.")) d = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -.5), anchor=constants.MID_CENTER, yes_type="continue", no_type="quit", text=msg) cont = dialog.call_dialog(d, self) if not cont: raise SystemExit exit = dialog.call_dialog(self.menu_dialog, self) if exit: self.visible = False return
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)
def set_current(self, type, item_type, count): if type.id == "cpu": space_left = self.base.space_left_for(item_type) try: count = int(count) except ValueError: msg = _( "\"%(value)s\" does not seem to be a valid integer.") % { "value": count } md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) dialog.call_dialog(md, self) md.parent = None return if count > space_left or count <= 0 or space_left == 0: if space_left > 0: msg = _("Please choose an integer between 1 and %(limit)s." ) % { "limit": space_left } else: msg = _( "The base cannot support any additional number of %(item_name)s." ) % { "item_name": item_type.name } md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) dialog.call_dialog(md, self) md.parent = None return # If there are any existing CPUs of this type, warn that they will # be taken offline until construction finishes. cpu_added = self.base.cpus is not None \ and self.base.cpus.spec == item_type if cpu_added: space_left -= self.base.cpus.count if self.base.cpus.done: msg = _( "I will need to take the existing processors offline while I install the new ones. Continue anyway?" ) yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) go_ahead = dialog.call_dialog(yn, self) yn.parent = None if not go_ahead: return # If there are already existing CPUs of other type, warn that they will # be taken removed. cpu_removed = self.base.cpus is not None \ and self.base.cpus.spec != item_type if cpu_removed: msg = _( "I will need to remove the existing different processors while I install the new type. Continue anyway?" ) yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=msg) go_ahead = dialog.call_dialog(yn, self) yn.parent = None if not go_ahead: return new_cpus = item.Item(item_type, base=self.base, count=count) if cpu_added: self.base.cpus += new_cpus else: self.base.cpus = new_cpus self.base.check_power() else: old_item = self.base.items[type.id] if old_item is None or old_item.spec != item_type: self.base.items[type.id] = item.Item(item_type, base=self.base) self.base.check_power() self.base.recalc_cpu()