def __init__(self, parent, pos=(0, 0), size=(-1, -1),
                 anchor=constants.TOP_LEFT, *args, **kwargs):
        super(EventManipulationDialog, self).__init__(parent, pos, size, anchor,
                                                      *args, **kwargs)

        self.selected_event_spec = None

        self.yes_button.parent = None

        self.no_button.pos = (-.97,-.99)
        self.no_button.size = (-.22, -.1)

        self.trigger_event_button = button.FunctionButton(self, (-.27, -.99), (-.22, -.1),
                                                          autotranslate=True,
                                                          enabled=False,
                                                          text=N_("Trigger"),
                                                          anchor=constants.BOTTOM_LEFT,
                                                          function=self._trigger_event)
        self.expire_event_button = button.FunctionButton(self, (-.51, -.99), (-.22, -.1),
                                                         autotranslate=True,
                                                         enabled=False,
                                                         text=N_("Expire"),
                                                         anchor=constants.BOTTOM_LEFT,
                                                         function=self._expire_event)
        self.description = ""
        self.desc_func = self.on_change
Example #2
0
 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
Example #3
0
 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
Example #4
0
    def __init__(self, *args, **kwargs):
        super(MessageListDialog, self).__init__(*args, **kwargs)
        
        self.title = text.Text(self, (-.01, -.01), (-.98, -.1),
                               background_color="clear",
                               anchor=constants.TOP_LEFT,
                               valign=constants.MID, align=constants.LEFT,
                               base_font="special", text_size=28)

        self.body = text.Text(self, (-.01, -.11), (-.98, -.83),
                               background_color="clear",
                               anchor=constants.TOP_LEFT,
                               valign=constants.TOP, align=constants.LEFT,
                               text_size=20)

        self.prev_button = button.FunctionButton(self, (-.78, -.01), (-.2, -.1),
                                                 text=_("P&REV"), autohotkey=True,
                                                 anchor=constants.TOP_RIGHT,
                                                 text_size=28,
                                                 function=self.prev_message)   

        self.next_button = button.FunctionButton(self, (-.99, -.01), (-.2, -.1),
                                                 text=_("&NEXT"), autohotkey=True,
                                                 anchor=constants.TOP_RIGHT,
                                                 text_size=28,
                                                 function=self.next_message)            
                               
        self.add_key_handler(pygame.K_LEFT, self.handle_key, only_on_event_type=pygame.KEYDOWN)
        self.add_key_handler(pygame.K_RIGHT, self.handle_key, only_on_event_type=pygame.KEYDOWN)
Example #5
0
    def __init__(self,
                 parent,
                 pos=(-.50, -.50),
                 size=(.50, .10),
                 anchor=constants.MID_CENTER,
                 **kwargs):
        kwargs.setdefault('wrap', False)
        kwargs.setdefault("shrink_factor", 1)
        kwargs.setdefault("text_size", 20)
        self.default_text = kwargs.pop("default_text", "")
        ok_type = kwargs.pop("ok_type", N_("&OK"))
        cancel_type = kwargs.pop("cancel_type", N_("&CANCEL"))
        super(TextEntryDialog, self).__init__(parent, pos, size, anchor,
                                              **kwargs)

        self.text_field = text.EditableText(self, (0, -.50), (-.71, -.50),
                                            borders=constants.ALL,
                                            base_font="normal")

        self.ok_button = button.FunctionButton(self, (-.72, -.50),
                                               (-.14, -.50),
                                               autotranslate=True,
                                               text=ok_type,
                                               function=self.return_text)
        self.cancel_button = button.FunctionButton(
            self, (-.86, -.50), (-.14, -.50),
            autotranslate=True,
            text=cancel_type,
            function=self.return_nothing)

        self.add_key_handler(pygame.K_RETURN, self.return_text)
        self.add_key_handler(pygame.K_KP_ENTER, self.return_text)
        self.add_key_handler(pygame.K_ESCAPE, self.return_nothing)
Example #6
0
    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)
Example #7
0
    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
Example #8
0
 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
Example #9
0
    def __init__(self, parent, pos, size=(.58, .06), anchor=constants.TOP_LEFT,
                 item_type=None, **kwargs):

        kwargs.setdefault("background_color", "pane_background")

        super(ItemPane, self).__init__(parent, pos, size, anchor=anchor, **kwargs)

        if item_type is None or not isinstance(item_type, item.ItemType):
            raise ValueError('Type must be of class ItemType.')

        self.item_type = item_type

        self.name_panel = text.Text(self, (0,0), (.45, .03),
                                    anchor=constants.TOP_LEFT,
                                    align=constants.LEFT,
                                    background_color=self.background_color,
                                    bold=True)

        self.build_panel = text.Text(self, (0,.03), (.45, .03),
                                     anchor=constants.TOP_LEFT,
                                     align=constants.LEFT,
                                     background_color=self.background_color,
                                     text="", bold=True)

        self.change_button = button.FunctionButton(
            self, (.415,.01), (.16, .04),
            anchor=constants.TOP_LEFT,
            force_underline=len(_("CHANGE")) + 2,
            autohotkey=True,
            function=self.parent.parent.build_item,
            kwargs={'type': self.item_type},
        )
Example #10
0
    def __init__(self, parent, *args, **kwargs):
        super(SavegameScreen, self).__init__(parent, *args, yes_type="load", **kwargs)

        self.yes_button.pos = (-.03,-.99)
        self.yes_button.exit_code_func = self.return_savegame

        self.no_button.pos = (-.97,-.99)
        self.no_button.exit_code = None

        self._all_savegames_sorted = []

        self.label = text.Text(self, (-.01, -.01), (-.20, -.08),
                               borders=constants.ALL,
                               anchor=constants.TOP_LEFT,
                               base_font="normal")
        self.text_field = text.UpdateEditableText(self, (-.21, -.01), (-.78, -.08),
                                                  borders=constants.ALL,
                                                  anchor=constants.TOP_LEFT,
                                                  update_func=self._search_for_savegame,
                                                  base_font="normal")

        self.delete_button = button.FunctionButton(self, (-.50,-.99), (-.3,-.1),
                                                   anchor=constants.BOTTOM_CENTER,
                                                   autohotkey=True,
                                                   function=self.delete_savegame)

        self.add_handler(constants.KEY, self._got_key, priority=5)
    def make_item(self, canvas):
        # Dirty, underhanded trick to make the canvas into a progress bar.
        canvas.__class__ = text.ProgressText
        canvas.progress = 0
        canvas.progress_color = "progress_background_progress"

        canvas.research_name = text.Text(canvas, (-.01, -.01), (-.70, -.5),
                                         align=constants.LEFT,
                                         background_color="clear")
        canvas.research_name.visible = False
        canvas.alloc_cpus = text.Text(canvas, (-.99, -.01), (-.21, -.5),
                                      anchor=constants.TOP_RIGHT,
                                      text="1,000,000,000",
                                      align=constants.RIGHT,
                                      background_color="clear")
        canvas.alloc_cpus.visible = False
        canvas.slider = slider.UpdateSlider(canvas, (-.01, -.55), (-.98, -.40),
                                            anchor=constants.TOP_LEFT,
                                            horizontal=True,
                                            priority=150)
        canvas.slider.visible = False

        canvas.help_button = button.FunctionButton(canvas, (-.11, -.55),
                                                   (0, -.40),
                                                   text=" ??? ",
                                                   text_shrink_factor=1,
                                                   base_font="normal",
                                                   function=self.show_help)
    def __init__(self, parent, *args, **kwargs):
        super(SavegameScreen, self).__init__(parent,
                                             *args,
                                             yes_type=N_("&LOAD"),
                                             **kwargs)

        self.yes_button.pos = (-.03, -.99)
        self.yes_button.size = (-.22, -.1)
        self.yes_button.function = self.exit_savegame
        self.yes_button.force_underline = -1  # Work around #224

        self.no_button.pos = (-.97, -.99)
        self.no_button.size = (-.22, -.1)
        self.no_button.exit_code = None
        self.no_button.force_underline = -1  # Work around #224

        self._all_savegames_sorted = []

        self.label = text.Text(self, (-.01, -.01), (-.20, -.08),
                               autotranslate=True,
                               text=N_("Filter: "),
                               borders=constants.ALL,
                               anchor=constants.TOP_LEFT,
                               base_font="normal")
        self.text_field = text.UpdateEditableText(
            self, (-.21, -.01), (-.78, -.08),
            borders=constants.ALL,
            anchor=constants.TOP_LEFT,
            update_func=self._search_for_savegame,
            background_color="text_entry_background",
            base_font="normal")

        self.convert_button = button.FunctionButton(
            self, (-.27, -.99), (-.22, -.1),
            autotranslate=True,
            text=N_("Upgrade"),
            anchor=constants.BOTTOM_LEFT,
            function=self.convert_save)

        self.delete_button = button.FunctionButton(
            self, (-.51, -.99), (-.22, -.1),
            autotranslate=True,
            text=N_("Delete"),
            anchor=constants.BOTTOM_LEFT,
            function=self.delete_savegame)

        self.add_handler(constants.KEY, self._got_key, priority=5)
Example #13
0
    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
Example #14
0
    def __init__(self, parent, pos=(.5, .5), size=(.73, .63), *args, **kwargs):
        super(LogScreen, self).__init__(parent, pos, size, *args, **kwargs)
        self.anchor = constants.MID_CENTER

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

        self.filter_log_dialog = FilterLogDialog(self)

        self.filter_log = button.FunctionButton(self, (-1., 0.), (-.15, -.08),
                                                anchor=constants.TOP_RIGHT,
                                                autohotkey=True,
                                                function=self.show_filters)
Example #15
0
    def __init__(self, *args, **kwargs):
        super(VideoPane, self).__init__(*args, **kwargs)

        self.resolution_initialized = False

        self.resolution_label = text.Text(self, (.01, .01), (.14, .05),
                                          autotranslate=True,
                                          text=N_("Resolution:"),
                                          align=constants.LEFT,
                                          background_color="clear")

        self.resolution_choice = \
            listbox.UpdateListbox(self, (.16, .01), (.20, .25),
                                  update_func=self.update_resolution)

        self.resolution_custom = button.HotkeyText(self, (.01, .28), (.14, .05),
                                                   autotranslate=True,
                                                   text=N_("&Custom:"),
                                                   align=constants.LEFT,
                                                   background_color="clear")

        self.resolution_custom_horiz = \
            text.EditableText(self, (.16, .28), (.14, .05),
                              text=str(gg.default_screen_size[0]),
                              allowed_characters=constants.DIGIT_CHARS,
                              borders=constants.ALL)

        self.resolution_custom_X = text.Text(self,
                                             (.30, .28),
                                             (.02, .05),
                                             text="X",
                                             base_font="special",
                                             background_color="clear")

        self.resolution_custom_vert = \
            text.EditableText(self, (.32, .28), (.14, .05),
                              text=str(gg.default_screen_size[1]),
                              allowed_characters=constants.DIGIT_CHARS,
                              borders=constants.ALL)

        self.resolution_custom_ok = button.FunctionButton(self, (.47, .28), (.14, .05),
                                                          autotranslate=True,
                                                          autohotkey=False,
                                                          text=N_("OK"),
                                                          function=self.set_resolution_custom)
        self.resolution_custom.hotkey_target = self.resolution_custom_ok

        self.fullscreen_label = button.HotkeyText(self, (.40, .01), (.30, .05),
                                                  autotranslate=True,
                                                  text=N_("&Fullscreen:"),
                                                  align=constants.LEFT,
                                                  background_color="clear")
        self.fullscreen_toggle = OptionButton(self, (.715, .01), (.07, .05),
                                              autotranslate=True,
                                              autohotkey=False,
                                              text_shrink_factor=.75,
                                              force_underline=-1,
                                              function=self.set_fullscreen,
                                              args=(button.TOGGLE_VALUE,))
        self.fullscreen_label.hotkey_target = self.fullscreen_toggle

        self.daynight_label = button.HotkeyText(self, (.40, .08), (.30, .05),
                                                autotranslate=True,
                                                text=N_("Da&y/night display:"),
                                                align=constants.LEFT,
                                                background_color="clear")
        self.daynight_toggle = OptionButton(self, (.715, .08), (.07, .05),
                                            autotranslate=True,
                                            autohotkey=False,
                                            text_shrink_factor=.75,
                                            force_underline=-1,
                                            function=self.set_daynight,
                                            args=(button.TOGGLE_VALUE,))
        self.daynight_label.hotkey_target = self.daynight_toggle

        self.grab_label = button.HotkeyText(self, (.40, .15), (.30, .05),
                                            autotranslate=True,
                                            text=N_("&Mouse grab:"),
                                            align=constants.LEFT,
                                            background_color="clear")
        self.grab_toggle = OptionButton(self, (.715, .15), (.07, .05),
                                        autotranslate=True,
                                        autohotkey=False,
                                        text_shrink_factor=.75,
                                        force_underline=-1,
                                        function=self.set_grab,
                                        args=(button.TOGGLE_VALUE,))
        self.grab_label.hotkey_target = self.grab_toggle
Example #16
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)
Example #17
0
    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))
Example #18
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)