コード例 #1
0
ファイル: log.py プロジェクト: osjc/singularity
 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)
コード例 #2
0
ファイル: savegame.py プロジェクト: osjc/singularity
    def return_savegame(self):
        save = self.listbox.current_item()
        try:
            sv.load_savegame(save)
            return True
        except sv.SavegameVersionException as e:
            text=_("""
This save file '{SAVE_NAME}' is from an unsupported or invalid version:
{VERSION}.
""", \
SAVE_NAME = save.name, \
VERSION = e.version)
        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
コード例 #3
0
    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
コード例 #4
0
ファイル: base.py プロジェクト: Uneron/singularity
    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:
                            return
                        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()
コード例 #5
0
 def open_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         base = self.listbox.key_list[self.listbox.list_pos]
         if not base.done:
             return
         self.base_dialog.base = base
         dialog.call_dialog(self.base_dialog, self)
         self.needs_rebuild = True
         self.parent.needs_rebuild = True
コード例 #6
0
 def load_game(self):
     save_names = g.get_save_names()
     self.load_dialog.list = save_names
     index = dialog.call_dialog(self.load_dialog, self)
     if 0 <= index < len(save_names):
         save = save_names[index]
         did_load = g.load_game(save)
         if did_load:
             dialog.call_dialog(self.map_screen, self)
コード例 #7
0
ファイル: location.py プロジェクト: tarsbase/singularity
 def open_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         base = self.listbox.key_list[self.listbox.list_pos]
         if not base.done:
             return
         self.base_dialog.base = base
         dialog.call_dialog(self.base_dialog, self)
         self.needs_rebuild = True
         self.parent.needs_rebuild = True
コード例 #8
0
 def load_game(self):
     save_names = g.get_save_names()
     self.load_dialog.list = save_names
     index = dialog.call_dialog(self.load_dialog, self)
     if 0 <= index < len(save_names):
         save = save_names[index]
         did_load = g.load_game(save)
         if did_load:
            dialog.call_dialog(self.map_screen, self)
コード例 #9
0
ファイル: map.py プロジェクト: Xenega/singularity
    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:
            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
コード例 #10
0
    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
コード例 #11
0
ファイル: location.py プロジェクト: osjc/singularity
 def destroy_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         selected_base = self.listbox.key_list[self.listbox.list_pos]
         all_active_bases = [
             b for b in g.all_bases() if b.maintains_singularity
         ]
         if len(all_active_bases
                ) == 1 and all_active_bases[0] == selected_base:
             dialog.call_dialog(self.cannot_destroy_last_base, self)
         elif dialog.call_dialog(self.confirm_destroy, self):
             selected_base.destroy()
             self.listbox.list = [b.name for b in self.location.bases]
             self.listbox.key_list = self.location.bases
             self.needs_rebuild = True
             self.parent.needs_rebuild = True
コード例 #12
0
ファイル: options.py プロジェクト: AliSajid/singularity
    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)
コード例 #13
0
ファイル: options.py プロジェクト: singularity/singularity
    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
コード例 #14
0
    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)
コード例 #15
0
ファイル: options.py プロジェクト: osjc/singularity
    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
コード例 #16
0
 def show_dialog(self):
     """When the assigned dialog exits, raises Handled with the dialog's
        exit code as a parameter.  Subclass if you care what the code was."""
     if not self.dialog:
         raise constants.Handled
     else:
         from code.graphics import dialog
         raise constants.Handled(dialog.call_dialog(self.dialog, self))
コード例 #17
0
 def new_base(self):
     result = dialog.call_dialog(self.new_base_dialog, self)
     if result:
         base_type, base_name = result
         new_base = g.base.Base(base_type, base_name)
         self.location.add_base(new_base)
         self.needs_rebuild = True
         self.parent.needs_rebuild = True
コード例 #18
0
 def build_item(self, type):
     self.build_dialog.type = type
     result = dialog.call_dialog(self.build_dialog, self)
     if 0 <= result < len(self.build_dialog.key_list):
         item_type = self.build_dialog.key_list[result]
         self.set_current(type, item_type)
         self.needs_rebuild = True
         self.parent.parent.needs_rebuild = True
コード例 #19
0
 def get_name(self):
     if 0 <= self.listbox.list_pos < len(self.key_list):
         type = self.key_list[self.listbox.list_pos]
         self.name_dialog.default_text = \
             generate_base_name(self.parent.location, type)
         name = dialog.call_dialog(self.name_dialog, self)
         if name:
             raise constants.ExitDialog((name, type))
コード例 #20
0
ファイル: map.py プロジェクト: mdtrooper/singularity
    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()
コード例 #21
0
ファイル: location.py プロジェクト: tarsbase/singularity
 def new_base(self):
     result = dialog.call_dialog(self.new_base_dialog, self)
     if result:
         base_type, base_name = result
         new_base = g.base.Base(base_type, base_name)
         self.location.add_base(new_base)
         self.needs_rebuild = True
         self.parent.needs_rebuild = True
コード例 #22
0
ファイル: location.py プロジェクト: singularity/singularity
 def rename_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         base = self.listbox.key_list[self.listbox.list_pos]
         self.name_dialog.default_text = base.name
         name = dialog.call_dialog(self.name_dialog, self)
         if name:
             base.name = name
             self.needs_rebuild = True
コード例 #23
0
ファイル: map.py プロジェクト: mdtrooper/singularity
 def steal_money(self):
     asked = dialog.call_dialog(self.steal_amount_dialog, self.cheat_dialog)
     try:
         g.pl.cash += int(asked)
     except ValueError:
         pass
     else:
         self.needs_rebuild = True
コード例 #24
0
ファイル: location.py プロジェクト: tarsbase/singularity
 def rename_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         base = self.listbox.key_list[self.listbox.list_pos]
         self.name_dialog.default_text = base.name
         name = dialog.call_dialog(self.name_dialog, self)
         if name:
             base.name = name
             self.needs_rebuild = True
コード例 #25
0
 def steal_money(self):
     asked = dialog.call_dialog(self.steal_amount_dialog, self.cheat_dialog)
     try:
         g.pl.cash += int(asked)
     except ValueError:
         pass
     else:
         self.needs_rebuild = True
コード例 #26
0
ファイル: base.py プロジェクト: Uneron/singularity
 def build_item(self, type):
     self.build_dialog.type = type
     result = dialog.call_dialog(self.build_dialog, self)
     if 0 <= result < len(self.build_dialog.key_list):
         item_type = self.build_dialog.key_list[result]
         self.set_current(type, item_type)
         self.needs_rebuild = True
         self.parent.parent.needs_rebuild = True
コード例 #27
0
ファイル: map.py プロジェクト: MrDapperGent/singularity-osx
 def load_game(self):
     save_names = g.get_save_names()
     self.load_dialog.list = save_names
     index = dialog.call_dialog(self.load_dialog, self.menu_dialog)
     if 0 <= index < len(save_names):
         save = save_names[index]
         g.load_game(save)
         self.force_update()
         raise constants.ExitDialog, False
コード例 #28
0
 def load_game(self):
     save_names = g.get_save_names()
     self.load_dialog.list = save_names
     index = dialog.call_dialog(self.load_dialog, self.menu_dialog)
     if 0 <= index < len(save_names):
         save = save_names[index]
         g.load_game(save)
         self.force_update()
         raise constants.ExitDialog, False
コード例 #29
0
    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()
コード例 #30
0
 def destroy_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         if dialog.call_dialog(self.confirm_destroy, self):
             base = self.listbox.key_list[self.listbox.list_pos]
             base.destroy()
             self.listbox.list = [base.name for base in self.location.bases]
             self.listbox.key_list = self.location.bases
             self.needs_rebuild = True
             self.parent.needs_rebuild = True
コード例 #31
0
ファイル: location.py プロジェクト: tarsbase/singularity
 def destroy_base(self):
     if 0 <= self.listbox.list_pos < len(self.listbox.key_list):
         if dialog.call_dialog(self.confirm_destroy, self):
             base = self.listbox.key_list[self.listbox.list_pos]
             base.destroy()
             self.listbox.list = [base.name for base in self.location.bases]
             self.listbox.key_list = self.location.bases
             self.needs_rebuild = True
             self.parent.needs_rebuild = True
コード例 #32
0
ファイル: savegame.py プロジェクト: Xenega/singularity
 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()
コード例 #33
0
ファイル: savegame.py プロジェクト: osjc/singularity
 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()
コード例 #34
0
ファイル: savegame.py プロジェクト: wassname/singularity
 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()
コード例 #35
0
    def show_list(self, message_type, messages):
        if (len(messages) == 0):
            return

        self.dialog.type = message_type
        self.dialog.list = messages
        ret = dialog.call_dialog(self.dialog, self.screen)

        # Pause game
        if (not ret):
            g.pl.pause_game()
            return True

        # Continue
        return False
コード例 #36
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
コード例 #37
0
    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
            exit = dialog.call_dialog(self.menu_dialog, self)
            if exit:
                self.visible = False
                return
コード例 #38
0
    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
            exit = dialog.call_dialog(self.menu_dialog, self)
            if exit:
                self.visible = False
                return
コード例 #39
0
ファイル: warning.py プロジェクト: DrMoriarty/singularity
    def show_dialog(self):
        warnings = self.refresh_warnings()

        if (len(warnings) == 0):
            return

        self.warning_dialog.warnings = warnings
        ret = dialog.call_dialog(self.warning_dialog, self.screen)

        # Pause game
        if (not ret):
            g.pl.pause_game()
            return True

        # Continue
        return False
コード例 #40
0
ファイル: map.py プロジェクト: Xenega/singularity
    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
コード例 #41
0
ファイル: base.py プロジェクト: tarsbase/singularity
    def build_item(self, type):
        if (type.id == "cpu"):
            build_dialog = self.multiple_build_dialog
        else:
            build_dialog = self.build_dialog

        build_dialog.type = type

        result = dialog.call_dialog(build_dialog, self)
        if 0 <= result < len(build_dialog.key_list):
            item_type = build_dialog.key_list[result]

            count = 1
            if (type.id == "cpu"):
                count = build_dialog.count

            self.set_current(type, item_type, count)
            self.needs_rebuild = True
            self.parent.parent.needs_rebuild = True
コード例 #42
0
ファイル: base.py プロジェクト: Xenega/singularity
 def build_item(self, type):
     if (type.id == "cpu"):
         build_dialog = self.multiple_build_dialog
     else:
         build_dialog = self.build_dialog
     
     build_dialog.type = type
     
     result = dialog.call_dialog(build_dialog, self)
     if 0 <= result < len(build_dialog.key_list):
         item_type = build_dialog.key_list[result]
         
         count = 1
         if (type.id == "cpu"):
             count = build_dialog.count
         
         self.set_current(type, item_type, count)
         self.needs_rebuild = True
         self.parent.parent.needs_rebuild = True
コード例 #43
0
ファイル: map.py プロジェクト: Xenega/singularity
 def show_message(self, message, color=None):
     self.message_dialog.text = message
     if color == None:
         color = "text"
     self.message_dialog.color = color
     dialog.call_dialog(self.message_dialog, self)
コード例 #44
0
ファイル: research.py プロジェクト: AliSajid/singularity
 def show_help(self, danger_level):
     self.help_dialog.text = g.strings["danger_common"] % \
                                      g.strings["danger_%d" % danger_level]
     dialog.call_dialog(self.help_dialog, self)
コード例 #45
0
 def load_game(self):
     did_load = dialog.call_dialog(self.load_dialog, self.menu_dialog)
     if did_load:
         self.force_update()
         raise constants.ExitDialog, False
コード例 #46
0
ファイル: base.py プロジェクト: Xenega/singularity
    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()
コード例 #47
0
 def open_location(self, location):
     self.location_dialog.location = g.locations[location]
     dialog.call_dialog(self.location_dialog, self)
     return
コード例 #48
0
 def show_help(self, danger_level):
     self.help_dialog.text = g.strings["danger_common"] % \
                                      g.strings["danger_%d" % danger_level]
     dialog.call_dialog(self.help_dialog, self)
コード例 #49
0
ファイル: map.py プロジェクト: mdtrooper/singularity
 def show_menu():
     exit = dialog.call_dialog(self.menu_dialog, self)
     if exit:
         raise constants.ExitDialog
コード例 #50
0
ファイル: main_menu.py プロジェクト: singularity/singularity
 def load_game(self):
     did_load = dialog.call_dialog(self.load_dialog, self)
     if did_load:
         dialog.call_dialog(self.map_screen, self)
コード例 #51
0
ファイル: main_menu.py プロジェクト: Uneron/singularity
 def new_game(self):
     difficulty = dialog.call_dialog(self.difficulty_dialog, self)
     if difficulty > 0:
         g.new_game(difficulty)
         dialog.call_dialog(self.map_screen, self)
コード例 #52
0
ファイル: map.py プロジェクト: Xenega/singularity
 def load_game(self):
     did_load = dialog.call_dialog(self.load_dialog, self.menu_dialog)
     if did_load:
         self.force_update()
         raise constants.ExitDialog, False
コード例 #53
0
ファイル: map.py プロジェクト: mdtrooper/singularity
 def show_message(self, message, color=None):
     self.message_dialog.text = message
     if color == None:
         color = gg.colors["white"]
     self.message_dialog.color = color
     dialog.call_dialog(self.message_dialog, self)
コード例 #54
0
 def show_menu():
     exit = dialog.call_dialog(self.menu_dialog, self)
     if exit:
         raise constants.ExitDialog
コード例 #55
0
ファイル: map.py プロジェクト: mdtrooper/singularity
 def open_location(self, location):
     self.location_dialog.location = g.locations[location]
     dialog.call_dialog(self.location_dialog, self)
     return
コード例 #56
0
 def show_message(self, message, color=None):
     self.message_dialog.text = message
     if color == None:
         color = "text"
     self.message_dialog.color = color
     dialog.call_dialog(self.message_dialog, self)
コード例 #57
0
ファイル: map.py プロジェクト: mdtrooper/singularity
 def save_game(self):
     self.savename_dialog.default_text = g.default_savegame_name
     name = dialog.call_dialog(self.savename_dialog, self.menu_dialog)
     if name:
         g.save_game(name)
         raise constants.ExitDialog, False
コード例 #58
0
ファイル: base.py プロジェクト: singularity/singularity
    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.type == 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.type != 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.type != item_type:
                self.base.items[type.id] = item.Item(item_type, base=self.base)
                self.base.check_power()

        self.base.recalc_cpu()