Пример #1
0
 def __init__(self, *args, **kwargs):
     views = [
         LabelView(
             LOGO[1:].rstrip(),
             layout_options=LayoutOptions.row_top(0.5)),
         LabelView(
             "Try resizing the window!",
             layout_options=LayoutOptions.centered('intrinsic', 'intrinsic')),
         ButtonView(
             text="Play", callback=self.play,
             color_bg='#000000', color_fg='#00ff00',
             layout_options=LayoutOptions.row_bottom(4).with_updates(
                 left=0.2, width=0.2, right=None)),
         ButtonView(
             text="Settings", callback=self.show_settings,
             layout_options=LayoutOptions.row_bottom(4).with_updates(
                 left=0.4, width=0.2, right=None)),
         ButtonView(
             text="[color=red]Quit",
             callback=lambda: self.director.pop_scene(),
             # [color=red] messes up auto size calculations
             size=Size(4, 1),
             layout_options=LayoutOptions.row_bottom(4).with_updates(
                 left=0.6, width=0.2, right=None)),
     ]
     super().__init__(views, *args, **kwargs)
Пример #2
0
    def __init__(self, *args, **kwargs):
        self.tile_size = get_game_config()['cellsize']
        self.font_size = get_game_config()['fontsize']

        self.button_tile_size = ButtonView(
            text=self.tile_size,
            callback=self.rotate_tile_size)

        view = WindowView(
            'Settings',
            layout_options=LayoutOptions.centered(50, 20),
            subviews=[
            ListView(
                [
                    ('Tile size', self.button_tile_size),
                ] + [
                    ('Filler ' + str(i), ButtonView(text='Hi', callback=lambda: None))
                    for i in range(50)
                ],
                layout_options=LayoutOptions(bottom=3)),
            ButtonView(
                text='Apply', callback=self.apply,
                layout_options=LayoutOptions.row_bottom(3).with_updates(right=0.5)),
            ButtonView(
                text='Cancel', callback=lambda: self.director().pop_scene(),
                layout_options=LayoutOptions.row_bottom(3).with_updates(left=0.5)),
        ])
        super().__init__(view, *args, **kwargs)

        self.covers_screen = False
Пример #3
0
    def __init__(self, *args, **kwargs):
        view = WindowView(
            'Settings',
            layout_options=LayoutOptions.centered(60, 20),
            subviews=[
                SettingsListView(
                    [(k,
                      CyclingButtonView(
                          v, v[0], callback=lambda _: None, align_horz='left'))
                     for k, v in sorted(SettingsScene.OPTIONS.items())],
                    value_column_width=20,
                    layout_options=LayoutOptions(bottom=5)),
                ButtonView(
                    text='Apply',
                    callback=self.apply,
                    layout_options=LayoutOptions.row_bottom(5).with_updates(
                        right=0.5)),
                ButtonView(
                    text='Cancel',
                    callback=lambda: self.director.pop_scene(),
                    layout_options=LayoutOptions.row_bottom(5).with_updates(
                        left=0.5)),
            ])
        super().__init__(view, *args, **kwargs)

        # this lets the main screen show underneath
        self.covers_screen = False
Пример #4
0
 def __init__(self, host_filter, targets):
     self.targets = targets
     self.button_controls = collections.OrderedDict(
         (target,
          SelectableButtonView(target.name,
                               functools.partial(self.select_object,
                                                 value=target),
                               align_horz='left')) for target in targets)
     super().__init__([
         WindowView(
             "",
             subviews=[
                 KeyAssignedListView(
                     self.button_controls.values(),
                     value_column_width=max(
                         len(value.text) + 5
                         for value in self.button_controls.values()),
                     layout_options=LayoutOptions.column_left(0.9)),
             ],
             layout_options=LayoutOptions(width=0.5,
                                          left=0.3,
                                          height=0.9,
                                          right=None,
                                          bottom=None),
         ),
         ButtonView("Finish",
                    self.finish,
                    layout_options=LayoutOptions.row_bottom(0.2)),
     ])
     self.host_filter = host_filter
     self.selections = []
Пример #5
0
 def __init__(self, host_filter, hierarchy):
     self.hierarchy = hierarchy
     self.button_controls_list = []
     self._recursive_create_buttons(hierarchy)
     self.button_controls = collections.OrderedDict(
         self.button_controls_list)
     super().__init__([
         WindowView(
             "",
             subviews=[
                 KeyAssignedListView(
                     self.button_controls.values(),
                     value_column_width=max(
                         len(value.text) + 5
                         for value in self.button_controls.values()),
                     layout_options=LayoutOptions.column_left(0.9)),
             ],
             layout_options=LayoutOptions(width=0.5,
                                          left=0.3,
                                          height=0.9,
                                          right=None,
                                          bottom=None),
         ),
         ButtonView("Finish",
                    self.finish,
                    layout_options=LayoutOptions.row_bottom(0.2)),
     ])
     self.host_filter = host_filter
     self.selections = []
Пример #6
0
    def __init__(self, *args, **kwargs):
        view = WindowView(
            'Character',
            layout_options=LayoutOptions(top=7, right=10, bottom=7, left=10),
            subviews=[
                LabelView('Name:', layout_options=LayoutOptions(
                    height=1, top=1, bottom=None)),
                SingleLineTextInputView(
                    callback=self.print_name,
                    layout_options=LayoutOptions
                    .centered('intrinsic', 'intrinsic')
                    .with_updates(top=2, bottom=None)),
                LabelView('Strength:', layout_options=LayoutOptions(
                    height=1, top=4, bottom=None)),
                IntStepperView(
                    value=10, min_value=1, max_value=20, callback=lambda x: print(x),
                    layout_options=LayoutOptions
                    .centered('intrinsic', 'intrinsic')
                    .with_updates(top=5)),
                ButtonView(
                    text='Cancel', callback=lambda: self.director.pop_scene(),
                    layout_options=LayoutOptions.row_bottom(3)),
            ]
        )
        super().__init__(view, *args, **kwargs)

        self.covers_screen = True
Пример #7
0
 def __init__(self, score, *args, **kwargs):
     view = WindowView(
         'Game Over',
         layout_options=LayoutOptions.centered(80, 30),
         subviews=[
             LabelView(TEXT_GAME_OVER,
                       layout_options=LayoutOptions.centered(
                           'intrinsic', 'intrinsic')),
             LabelView(
                 "Your score: {}".format(score),
                 layout_options=LayoutOptions.row_bottom(1).with_updates(
                     bottom=6)),
             ButtonView(text='Aaauuuuggghhhhhh...',
                        callback=self.done,
                        layout_options=LayoutOptions.row_bottom(3)),
         ])
     super().__init__(view, *args, **kwargs)
     self.covers_screen = False
Пример #8
0
 def __init__(self, *args, **kwargs):
     views = [
         LabelView(
             FONT_LOGO.renderText('BeepBoop'),
             layout_options=LayoutOptions.row_top(0.3)),
         LabelView(
             get_image('robot'),
             layout_options=LayoutOptions(top=0.3, bottom=4)),
         ButtonView(
             text="Play", callback=self.play,
             layout_options=LayoutOptions.row_bottom(4).with_updates(left=0.2, width=0.2, right=None)),
         ButtonView(
             text="Settings", callback=self.show_settings,
             layout_options=LayoutOptions.row_bottom(4).with_updates(left=0.4, width=0.2, right=None)),
         ButtonView(
             text="Quit", callback=lambda: self.director().pop_scene(),
             layout_options=LayoutOptions.row_bottom(4).with_updates(left=0.6, width=0.2, right=None)),
     ]
     super().__init__(views, *args, **kwargs)
Пример #9
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.info_bar_view = LabelView(' Status/Resources',
                                    align_horz='left',
                                    layout_options=LayoutOptions.row_top(1))
     self.world_view = View(layout_options=LayoutOptions(top=2))
     self.message_view = RectView(
         layout_options=LayoutOptions.row_bottom(10))
     self.add_subviews(
         [self.info_bar_view, self.world_view, self.message_view])
Пример #10
0
 def __init__(self, *args, **kwargs):
     views = [
         LabelView(TITLE[1:].rstrip(),
                   layout_options=LayoutOptions.row_top(0.5)),
         LabelView(ABOUT,
                   color_fg='#ffcb00',
                   layout_options=LayoutOptions.centered(
                       'intrinsic', 'intrinsic').with_updates(top=28)),
         ButtonView(
             text="Descend the stairs",
             callback=self.play,
             layout_options=LayoutOptions.row_bottom(10).with_updates(
                 left=0.2, width=0.2, right=None)),
         ButtonView(
             text="Quit",
             callback=lambda: self.director.pop_scene(),
             layout_options=LayoutOptions.row_bottom(10).with_updates(
                 left=0.6, width=0.2, right=None)),
     ]
     super().__init__(views, *args, **kwargs)
Пример #11
0
 def __init__(self, *args, **kwargs):
     view = WindowView(
         'Pause',
         layout_options=LayoutOptions.centered(40, 10),
         subviews=[
             ButtonView(text='Resume',
                        callback=self.resume,
                        layout_options=LayoutOptions.row_top(5)),
             ButtonView(text='Quit',
                        callback=self.quit,
                        layout_options=LayoutOptions.row_bottom(5)),
         ])
     super().__init__(view, *args, **kwargs)
     self.covers_screen = False
Пример #12
0
    def __init__(self, *args, **kwargs):
        view = WindowView(
            'Character',
            layout_options=LayoutOptions(top=7, right=10, bottom=7, left=10),
            subviews=[
                LabelView('There is no game yet.', layout_options=LayoutOptions.row_top(0.5)),
                ButtonView(
                    text='Darn', callback=lambda: self.director().pop_scene(),
                    layout_options=LayoutOptions.row_bottom(0.5)),
            ]
        )
        super().__init__(view, *args, **kwargs)

        self.covers_screen = False
Пример #13
0
    def __init__(self, game_state, *args, **kwargs):
        # All the game scenes share a GameState object.
        self.game_state = game_state

        # They also use the global player, but access it via a property just in
        # case I change my mind later.
        self.n_track_player = N_TRACK_PLAYER

        # Make some views. Read the clubsandwich docs for details on this stuff.
        # Some of them we just add as subviews and forget about, but the stats
        # view will need to be updated from time to time, so hang onto a reference
        # to it.
        sidebar_width = 21
        # The game drawing is all done by this GameView object. It happens every
        # frame, so we can mostly forget about it for now.
        game_view = GameView(self.game_state,
                             layout_options=LayoutOptions().with_updates(
                                 left=sidebar_width, bottom=1))
        log_view = LabelView(
            text="",
            align_horz='left',
            color_bg='#333333',
            clear=True,
            layout_options=LayoutOptions.row_bottom(1).with_updates(
                left=sidebar_width))
        help_view = LabelView(text=TEXT_HELP,
                              align_horz='left',
                              layout_options=LayoutOptions.column_left(
                                  sidebar_width).with_updates(
                                      top=None, height='intrinsic'))
        self.stats_view = StatsView(
            self.game_state,
            layout_options=LayoutOptions.column_left(sidebar_width))
        views = [
            game_view,
            self.stats_view,
            help_view,
            log_view,
        ]
        super().__init__(views, *args, **kwargs)

        # Each game scene has its own log controller. It's defined after the super()
        # call because it needs log_view to exist.
        self.logger = Logger(log_view)

        # This boolean signals to DirectorLoop that it doesn't need to draw any
        # scenes behind this one. (Compare with the pause screen, which wants the
        # game scene to be drawn behind it, since it's a popup window!)
        self.covers_screen = True