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 show(self): self.force_update() from 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 check_restart(self): # Test all changes that require a restart. Currently, only language if g.language == self.initial_options['language']: # 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 self.language_choice.list_pos = [ i for i, (code, __) in enumerate(self.languages) if code == self.initial_options['language'] ][0] or 0 self.set_language(self.language_choice.list_pos)
def show_intro(self): intro_dialog = dialog.YesNoDialog(self, yes_type="continue", no_type="skip") for segment in g.get_intro(): intro_dialog.text = segment if not dialog.call_dialog(intro_dialog, self): break intro_dialog.remove_hooks()
def __init__(self, *args, **kwargs): super(LocationScreen, self).__init__(*args, **kwargs) self.pos = (-.5, -.5) self.anchor = constants.MID_CENTER self.size = (-.75, -.5) self.name_display = text.Text(self, (0, 0), (-1, -.08), background_color="clear") self.listbox = listbox.CustomListbox(self, (0, -.08), (-1, -.70), remake_func=self.make_item, rebuild_func=self.update_item) self.open_button = \ button.FunctionButton(self, (0, -.8), (-.3, -.09), anchor=constants.TOP_LEFT, autohotkey=True, function=self.open_base) self.rename_button = \ button.FunctionButton(self, (-.50, -.8), (-.3, -.09), anchor=constants.TOP_CENTER, autohotkey=True, function=self.rename_base) self.power_button = \ button.FunctionButton(self, (-1, -.8), (-.3, -.09), anchor=constants.TOP_RIGHT, autohotkey=True, function=self.power_state) self.new_button = \ button.FunctionButton(self, (0, -.91), (-.3, -.09), autohotkey=True, function=self.new_base) self.destroy_button = \ button.FunctionButton(self, (-.50, -.91), (-.3, -.09), anchor=constants.TOP_CENTER, autohotkey=True, function=self.destroy_base) self.back_button = button.ExitDialogButton(self, (-1, -.9), (-.3, -.09), anchor=constants.TOP_RIGHT, autohotkey=True) self.confirm_destroy = \ dialog.YesNoDialog(self, (-.5,0), (-.35, -.7), text=_("Are you sure you want to destroy this base?"), shrink_factor=.5) self.new_base_dialog = NewBaseDialog(self) self.location = None self.name_dialog = \ dialog.TextEntryDialog(self, text=g.strings["name_base_text"]) self.base_dialog = basescreen.BaseScreen(self, (0, 0), anchor=constants.TOP_LEFT)
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 save_game(self): self.savename_dialog.default_text = sv.default_savegame_name name = dialog.call_dialog(self.savename_dialog, self.menu_dialog) if name: print(sv.savegame_exists(name)) if sv.savegame_exists(name): yn = dialog.YesNoDialog(self.menu_dialog, 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.menu_dialog) if not overwrite: return sv.create_savegame(name) raise constants.ExitDialog, False
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: index = self.return_list_pos() if 0 <= index < len(self.list): save = self.list[index] 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="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 __init__(self, *args, **kwargs): super(LocationScreen, self).__init__(*args, **kwargs) self.pos = (-.5, -.5) self.anchor = constants.MID_CENTER self.size = (-.75, -.5) self.name_display = text.Text(self, (0,0), (-1, -.08), background_color=gg.colors["clear"]) self.listbox = listbox.CustomListbox(self, (0,-.08), (-1, -.70), remake_func=self.make_item, rebuild_func=self.update_item) self.open_button = \ button.FunctionButton(self, (-.33, -.8), (-.3, -.09), anchor=constants.TOP_CENTER, text="OPEN BASE", hotkey="o", function=self.open_base) self.power_button = \ button.FunctionButton(self, (-.67, -.8), (-.3, -.09), anchor=constants.TOP_CENTER, text="POWER STATE", hotkey="p", function=self.power_state) self.new_button = \ button.FunctionButton(self, (0, -.91), (-.3, -.09), text="NEW BASE", hotkey="n", function=self.new_base) self.destroy_button = \ button.FunctionButton(self, (-.50, -.91), (-.3, -.09), anchor=constants.TOP_CENTER, text="DESTROY BASE", hotkey="d", function=self.destroy_base) self.back_button = button.ExitDialogButton(self, (-1, -.9), (-.3, -.09), anchor=constants.TOP_RIGHT, text="BACK", hotkey="b") self.confirm_destroy = \ dialog.YesNoDialog(self, (-.5,0), (-.35, -.7), text="Are you sure you want to destroy this base?", shrink_factor=.5) self.new_base_dialog = NewBaseDialog(self) self.location = None from code import screens self.base_dialog = screens.base.BaseScreen(self, (0,0), anchor=constants.TOP_LEFT)
def set_current(self, type, item_type): if type == "cpu": space_left = self.base.type.size # If there are any existing CPUs of this type, warn that they will # be taken offline until construction finishes. matches = self.base.cpus is not None \ and self.base.cpus.type == item_type if matches: space_left -= self.base.cpus.count if self.base.cpus.done: yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["will_lose_cpus"]) go_ahead = dialog.call_dialog(yn, self) yn.remove_hooks() if not go_ahead: return text = g.strings["num_cpu_prompt"] % (item_type.name, space_left) self.count_dialog.text = text self.count_dialog.default_text = locale.format("%d", space_left) can_exit = False while not can_exit: result = dialog.call_dialog(self.count_dialog, self) if not result: can_exit = True else: try: count = locale.atoi(result) if count > space_left: count = space_left elif count < 0: count = 0 new_cpus = g.item.Item(item_type, base=self.base, count=count) if matches: self.base.cpus += new_cpus else: self.base.cpus = new_cpus self.base.check_power() can_exit = True except ValueError: md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["nan"]) dialog.call_dialog(md, self) md.remove_hooks() else: index = ["reactor", "network", "security"].index(type) if self.base.extra_items[index] is None \ or self.base.extra_items[index].type != item_type: self.base.extra_items[index] = \ g.item.Item(item_type, base=self.base) self.base.check_power() self.base.recalc_cpu()
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: md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["nan"]) dialog.call_dialog(md, self) md.parent = None return if count > space_left or count <= 0 or space_left == 0: md = dialog.MessageDialog( self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["item_number_invalid"]) 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.type == item_type if cpu_added: space_left -= self.base.cpus.count if self.base.cpus.done: yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["will_be_offline"]) 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.type != item_type if cpu_removed: yn = dialog.YesNoDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["will_lose_cpus"]) 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.type != item_type: self.base.items[type.id] = item.Item(item_type, base=self.base) self.base.check_power() self.base.recalc_cpu()
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), 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), anchor=constants.TOP_CENTER, autohotkey=True, function=self.rename_base) self.power_button = \ button.FunctionButton(self, (-1, -.8), (-.3, -.09), anchor=constants.TOP_RIGHT, autohotkey=True, function=self.power_state) self.new_button = \ button.FunctionButton(self, (0, -.91), (-.3, -.09), autohotkey=True, function=self.new_base) self.destroy_button = \ button.FunctionButton(self, (-.50, -.91), (-.3, -.09), anchor=constants.TOP_CENTER, autohotkey=True, function=self.destroy_base) self.back_button = button.ExitDialogButton(self, (-1, -.9), (-.3, -.09), anchor=constants.TOP_RIGHT, autohotkey=True) self.confirm_destroy = \ dialog.YesNoDialog(self, (-.5,0), (-.35, -.7), shrink_factor=.5) self.cannot_destroy_last_base = \ dialog.MessageDialog(self, 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 == "cpu": space_left = self.base.type.size try: count = int(count) except ValueError: md = dialog.MessageDialog(self, pos=(-.5, -.5), size=(-.5, -1), anchor=constants.MID_CENTER, text=g.strings["nan"]) dialog.call_dialog(md, self) md.remove_hooks() return if count > space_left: count = space_left elif count <= 0: 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.type == item_type if cpu_added: space_left -= self.base.cpus.count if self.base.cpus.done: yn = dialog.YesNoDialog(self, pos=(-.5,-.5), size=(-.5,-1), anchor=constants.MID_CENTER, text=g.strings["will_be_offline"]) go_ahead = dialog.call_dialog(yn, self) yn.remove_hooks() 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.type != item_type if cpu_removed: yn = dialog.YesNoDialog(self, pos=(-.5,-.5), size=(-.5,-1), anchor=constants.MID_CENTER, text=g.strings["will_lose_cpus"]) go_ahead = dialog.call_dialog(yn, self) yn.remove_hooks() if not go_ahead: return new_cpus = g.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: index = ["reactor", "network", "security"].index(type) if self.base.extra_items[index] is None \ or self.base.extra_items[index].type != item_type: self.base.extra_items[index] = \ g.item.Item(item_type, base=self.base) self.base.check_power() self.base.recalc_cpu()
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()