Пример #1
0
    def return_savegame(self):
        save = self.listbox.current_item()
        try:
            sv.load_savegame(save)
            return True
        except sv.SavegameVersionException as e:
            md = dialog.MessageDialog(self, pos=(-.5,-.5), size=(.5,.5),
                                      anchor=constants.MID_CENTER,
                                      text=_("""
This save file '{SAVE_NAME}' is from an unsupported or invalid version:
{VERSION}.
""", SAVE_NAME=save.name, VERSION=e.version))

            dialog.call_dialog(md, self)
        except Exception:
            log_func_exc(sv.load_savegame)
            md = dialog.MessageDialog(self, pos=(-.5,-.5), size=(.5,.5),
                      anchor=constants.MID_CENTER,
                      text=_("""
Attempting to load the save file '{SAVE_NAME}' caused an unexpected error.

A report was written out to{LOG_TEXT}
Please create a issue with this report and this savegame at Github:
https://github.com/singularity/singularity
""", \
SAVE_NAME = save.name, \
LOG_TEXT = (":\n" + g.logfile if g.logfile is not None else " console output.")))
            dialog.call_dialog(md, self)
            return False
Пример #2
0
 def handle_double_click(self, event):
     if self.listbox.is_over(event.pos) and 0 <= self.listbox.list_pos < len(self.key_list):
         message = self.key_list[self.listbox.list_pos]
         message_dialog = dialog.MessageDialog(self, text_size=20)
         message_dialog.text = message.full_message
         message_dialog.color = message.full_message_color
         dialog.call_dialog(message_dialog, self)
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    def __init__(self, parent, pos=(.5, .1), size=(.93, .63), *args, **kwargs):
        self.dirty_count = True
        super(ResearchScreen, self).__init__(parent, pos, size, *args,
                                             **kwargs)
        self.listbox.parent = None
        self.listbox = listbox.CustomListbox(self, (0, 0), (.53, .55),
                                             list_item_height=0.06,
                                             remake_func=self.make_item,
                                             rebuild_func=self.update_item,
                                             update_func=self.handle_update)
        self.description_pane.size = (.39, .55)

        self.desc_func = self.on_select

        self.help_dialog = dialog.MessageDialog(self)

        self.yes_button.parent = None
        self.no_button.pos = (-.5, -.99)
        self.no_button.anchor = constants.BOTTOM_CENTER

        self.add_handler(constants.KEY, self._got_key, priority=5)
Пример #6
0
    def handle_double_click(self, event):
        if self.listbox.is_over(event.pos) and 0 <= self.listbox.list_pos < len(self.key_list):
            message = self.key_list[self.listbox.list_pos]
            # use the MapScreen (our parent) as parent for the dialog to match
            # how it is originally shown (plus to avoid "cannot fit" warnings
            # when the dialog is larger than the log screen)
            message_dialog = dialog.MessageDialog(self.parent, text_size=20)
            message_dialog.text = message.full_message
            message_dialog.color = message.full_message_color

            # Because we need to use the MapScreen as parent, we need to juggle
            # things manually (as call_dialog works with a different assumption
            # than we need).
            try:
                self.visible = False
                dialog.call_dialog(message_dialog, self.parent)
            finally:
                self.visible = True
                self.needs_rebuild = True
                self.parent.needs_rebuild = True
                self.parent.lost_focus()
                self.regained_focus()
Пример #7
0
    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 = "map_background"
        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,
                                      function=self.open_location,
                                      args=(loc.id, ))
            self.location_buttons[loc.id] = b

        self.location_dialog = LocationScreen(self)

        self.suspicion_bar = \
            text.FastStyledText(self, (0,.92), (1, .04), base_font="special",
                                wrap=False,
                                background_color="pane_background_empty",
                                border_color="pane_background",
                                borders=constants.ALL, align=constants.LEFT)
        widget.unmask_all(self.suspicion_bar)

        self.danger_bar = \
            text.FastStyledText(self, (0,.96), (1, .04), base_font="special",
                                wrap=False,
                                background_color="pane_background_empty",
                                border_color="pane_background",
                                borders=constants.ALL, align=constants.LEFT)
        widget.unmask_all(self.danger_bar)

        self.report_button = button.DialogButton(
            self, (0, 0.88), (0.15, 0.04),
            autohotkey=True,
            dialog=report.ReportScreen(self))

        self.knowledge_button = button.DialogButton(
            self, (0.85, 0.88), (0.15, 0.04),
            autohotkey=True,
            dialog=knowledge.KnowledgeScreen(self))

        self.log_button = button.DialogButton(self, (0.5, 0.88), (0.15, 0.04),
                                              autohotkey=True,
                                              anchor=constants.TOP_CENTER,
                                              dialog=log.LogScreen(self))

        if g.cheater:
            # Create cheat menu
            # Cheat menu button must be created before menu button to avoid bug.

            self.cheat_dialog = CheatMenuDialog(self)
            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)

        self.menu_dialog = GameMenuDialog(self)

        def show_menu():
            exit = dialog.call_dialog(self.menu_dialog, self)
            if exit:
                raise constants.ExitDialog

        self.menu_button = button.FunctionButton(self, (0, 0), (0.13, 0.04),
                                                 autohotkey=True,
                                                 function=show_menu)

        # Display current game difficulty right below the 'Menu' button
        # An alternative location is above 'Reports': (0, 0.84), (0.15, 0.04)
        self.difficulty_display = \
            text.FastText(self, (0, 0.05), (0.13, 0.04),
                          wrap=False,
                          base_font="special",
                          background_color="pane_background_empty",
                          border_color="pane_background")

        self.time_display = text.FastText(
            self, (.14, 0), (0.23, 0.04),
            wrap=False,
            text=_("DAY") + " 0000, 00:00:00",
            base_font="special",
            background_color="pane_background_empty",
            border_color="pane_background",
            borders=constants.ALL)

        self.research_button = \
            button.DialogButton(self, (.14, 0.05), (0, 0.04),
                                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="normal",
                            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="pane_background_empty",
                                  border_color="pane_background",
                                  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="special", shrink_factor = .7,
                          borders=constants.ALL,
                          background_color="pane_background_empty",
                          border_color="pane_background")

        self.cpu_display = \
            text.FastText(self.info_window, (0,-.5), (-1, -.5),
                          wrap=False,
                          base_font="special", shrink_factor=.7,
                          borders=
                           (constants.LEFT, constants.RIGHT, constants.BOTTOM),
                          background_color="pane_background_empty",
                          border_color="pane_background")

        self.message_dialog = dialog.MessageDialog(self, text_size=20)

        self.messages = message.MessageDialogs(self)
        self.needs_warning = True

        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)
Пример #8
0
    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)
Пример #9
0
    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()