コード例 #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):
        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
コード例 #3
0
 def __init__(self, lines_to_display, chars_per_line, *args, **kwargs):
     self.top_line_index = 0
     self.list_of_strings = []
     options = kwargs.get("layout_options")
     if not options:
         options = LayoutOptions().with_updates(left=2, right=2)
     self.label_view = LabelView(
         str(" "), align_horz='left', align_vert='top',
         layout_options=options)
     super().__init__(subviews=[self.label_view], *args, **kwargs)
     self.lines_to_display = lines_to_display
     self.chars_to_display = chars_per_line
コード例 #4
0
ファイル: game_scene.py プロジェクト: eykd/rogue_basement
    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
コード例 #5
0
 def create_label_value_pair(self, label_text, value_lambda):
     label_layout, value_layout = self.get_next_layout_pair()
     label_view = LabelView(
         label_text,
         layout_options=label_layout,
     )
     current_value = value_lambda()
     value_view = LabelView(
         current_value,
         layout_options=value_layout,
     )
     setattr(value_view, 'update_value', value_lambda)
     self.label_value_pairs.append((label_view, value_view))
     self._subviews.append(label_view),
     self._subviews.append(value_view)
コード例 #6
0
ファイル: skills.py プロジェクト: ChrisLR/BasicDungeonRL
    def __init__(self, game):
        self.covers_screen = True
        self.game = game
        self.skills = {}
        self.points_left = 3
        self.player = self.game.player
        self.player_skills = self.player.skills
        self.game.player = self.player
        self.manager = None

        sorted_skills = sorted(list(skill_listing), key=lambda skill: skill.name)
        sub_views = []
        for i, skill in enumerate(sorted_skills):
            partial_validation = partial(self.validate_points, skill=skill)
            sub_views.append(
                LabelView("%s:" % skill.name,
                          layout_options=LayoutOptions(**get_left_layout(i))))
            sub_views.append(ValidatedIntStepperView(
                validation_callback=partial_validation,
                value=0,
                callback=partial(self.set_skill, skill=skill),
                layout_options=LayoutOptions(**get_right_layout(i+1, width=5))))

        sub_views.append(
            ButtonView(
                'Finish', self.finish,
                layout_options=LayoutOptions(**get_left_layout(0.9, left=0.45))
            ))
        views = [WindowView(title='Skill Selection', subviews=sub_views)]
        super().__init__(views)
コード例 #7
0
ファイル: scenes.py プロジェクト: eykd/rogue_basement
 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
ファイル: run.py プロジェクト: irskep/beepboop
 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
ファイル: main.py プロジェクト: millejoh/Islands
 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, game, selection, executor):
     self.game = game
     self.action_mapping = game.action_mapping
     views = game.game_scene.view.subviews.copy()
     self.label = LabelView("")
     self.cursor_view = CursorView(game, self)
     views.append(self.label)
     views.append(self.cursor_view)
     super().__init__(views=views)
     self.executor = executor
     self.selection = selection
     self.cursor_position = Point(*executor.location.get_local_coords())
コード例 #12
0
 def __init__(self, game_state, *args, **kwargs):
     self.game_state = game_state
     self.progress_bar = ProgressBarView(
         fraction=1,
         layout_options=LayoutOptions.row_top(1).with_updates(top=3,
                                                              right=1))
     self.health_label = LabelView(
         text="  Health: ?  ",
         color_fg="#ffffff",
         color_bg='#000000',
         layout_options=LayoutOptions.row_top(1).with_updates(top=2,
                                                              right=1))
     self.inventory_count = LabelView(
         text="  Rocks: 0  ",
         color_fg="#ffffff",
         color_bg="#000000",
         layout_options=LayoutOptions.row_top(1).with_updates(top=4,
                                                              right=1))
     self.score_label = LabelView(
         text="Score: 0",
         color_fg="#ffff00",
         color_bg="#000000",
         layout_options=LayoutOptions.row_top(1).with_updates(top=6,
                                                              right=1))
     super().__init__(subviews=[
         LabelView(
             text="Stats",
             color_fg='#ffffff',
             color_bg='#660000',
             clear=True,
             layout_options=LayoutOptions.row_top(1).with_updates(right=1)),
         self.health_label,
         self.progress_bar,
         self.inventory_count,
         self.score_label,
     ],
                      *args,
                      **kwargs)
     self.update()
コード例 #13
0
ファイル: run.py プロジェクト: irskep/beepboop
    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
コード例 #14
0
 def __init__(self, game, selection):
     super().__init__([LabelView("Choose a direction.")])
     self.game = game
     self.selection = selection
コード例 #15
0
class ScrollingTextView(View):
    """
    :param int lines_to_display: How many lines to display at once (will not adjust the layout)
    :param int chars_per_line: Maximum amount of characters per line,  for text wrapping.

    See :py:class:`View` for the rest of the init arguments.
    """
    def __init__(self, lines_to_display, chars_per_line, *args, **kwargs):
        self.top_line_index = 0
        self.list_of_strings = []
        options = kwargs.get("layout_options")
        if not options:
            options = LayoutOptions().with_updates(left=2, right=2)
        self.label_view = LabelView(str(" "),
                                    align_horz='left',
                                    align_vert='top',
                                    layout_options=options)
        super().__init__(subviews=[self.label_view], *args, **kwargs)
        self.lines_to_display = lines_to_display
        self.chars_to_display = chars_per_line

    @property
    def can_become_first_responder(self):
        return True

    def add_lines(self, lines_string):
        unwrapped_lines = lines_string.splitlines(keepends=True)
        wrapped_lines = []
        for line in unwrapped_lines:
            wrapped_lines.extend(
                textwrap.wrap(line, width=self.chars_to_display))

        self.list_of_strings.extend(wrapped_lines)
        lines_added = len(wrapped_lines)
        if self.top_line_index + self.lines_to_display <= len(
                self.list_of_strings) - lines_added:
            if lines_added > self.lines_to_display:
                focus_substract = lines_added
            else:
                focus_substract = self.lines_to_display - lines_added

            self.focus_on_line(len(self.list_of_strings) - focus_substract - 1)
        else:
            self._refocus()

    def focus_on_line(self, line_index):
        self.top_line_index = line_index if line_index >= 0 else 0
        self._refocus()

    def scroll_up(self):
        if self.top_line_index > 0:
            self.top_line_index -= 1
            self._refocus()

    def scroll_down(self):
        if self.top_line_index + self.lines_to_display < len(
                self.list_of_strings):
            self.top_line_index += 1
            self._refocus()

    def _refocus(self):
        new_view_lines = "\n".join(
            self.list_of_strings[self.top_line_index:self.top_line_index +
                                 self.lines_to_display])
        self.label_view.text = new_view_lines

    @property
    def intrinsic_size(self):
        # add space for arrows
        return self.label_view.intrinsic_size + Size(4, 0)

    def set_needs_layout(self, val=True):
        super().set_needs_layout(val)
        self.label_view.set_needs_layout(val)

    def did_become_first_responder(self):
        self.label_view.color_fg = '#000000'
        self.label_view.color_bg = '#ffffff'

    def did_resign_first_responder(self):
        self.label_view.color_fg = '#ffffff'
        self.label_view.color_bg = '#000000'

    def draw(self, ctx):
        color_fg = '#ffffff'
        color_bg = '#000000'
        if self.is_first_responder:
            color_fg = '#000000'
            color_bg = '#ffffff'
        ctx.color(color_fg)
        ctx.bkcolor(color_bg)
        ctx.print(Point(self.bounds.width, 2), '↑')
        ctx.print(Point(self.bounds.width, self.bounds.height), '↓')

    def terminal_read(self, val):
        if val == terminal.TK_UP:
            self.scroll_up()

        if val == terminal.TK_DOWN:
            self.scroll_down()
コード例 #16
0
ファイル: attributes.py プロジェクト: ChrisLR/BasicDungeonRL
    def __init__(self, game):
        self.covers_screen = True
        self.game = game
        self.manager = None
        stat_initial = 7
        stat_minimum = 3
        stat_maximum = 18

        views = [
            WindowView(
                title='Ability Score Selection',
                subviews=[
                    LabelView(
                        "Name:",
                        layout_options=LayoutOptions(**get_left_layout(2))),
                    SingleLineTextInputView(
                        callback=self.set_name,
                        layout_options=LayoutOptions(
                            **get_right_layout(3, width=0.2, right=0.4))),
                    LabelView(
                        "Strength:",
                        layout_options=LayoutOptions(**get_left_layout(6))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat(
                            "Strength", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(7, width=5)),
                    ),
                    LabelView(
                        "Dexterity:",
                        layout_options=LayoutOptions(**get_left_layout(7))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat(
                            "Dexterity", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(8, width=5)),
                    ),
                    LabelView(
                        "Constitution:",
                        layout_options=LayoutOptions(**get_left_layout(8))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat(
                            "Constitution", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(9, width=5)),
                    ),
                    LabelView(
                        "Intelligence:",
                        layout_options=LayoutOptions(**get_left_layout(9))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat(
                            "Intelligence", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(10, width=5)),
                    ),
                    LabelView(
                        "Charisma:",
                        layout_options=LayoutOptions(**get_left_layout(10))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat(
                            "Charisma", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(11, width=5)),
                    ),
                    LabelView(
                        "Wisdom:",
                        layout_options=LayoutOptions(**get_left_layout(11))),
                    ValidatedIntStepperView(
                        validation_callback=self.validate_points,
                        value=stat_initial,
                        callback=lambda value: self.set_stat("Wisdom", value),
                        min_value=stat_minimum,
                        max_value=stat_maximum,
                        layout_options=LayoutOptions(
                            **get_right_layout(12, width=5))),
                    ButtonView('Finish',
                               self.finish,
                               layout_options=LayoutOptions(
                                   **get_left_layout(13, left=0.45)))
                ])
        ]
        super().__init__(views)

        self.name = ""
        self.stats = {
            "strength": stat_initial,
            "dexterity": stat_initial,
            "constitution": stat_initial,
            "intelligence": stat_initial,
            "charisma": stat_initial,
            "wisdom": stat_initial
        }
        self.points_left = 18
        self.choices = {}