Beispiel #1
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options!')

    header_height = 0
    if len(header) > 0:
        header_height = tcod.root_console.get_height_rect(width=width, text=header)
    height = header_height + len(options)

    con = tcod.Console(width, height)
    con.set_default_foreground(tcod.COLOR_WHITE)
    con.print_rect_ex(text=header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '( ) ' + option_text
        con.set_default_foreground(tcod.COLOR_WHITE)
        con.print_ex(y=y, text=text)
        con.set_default_foreground(tcod.COLOR_YELLOW)
        con.put_char(1, y, chr(letter_index))
        y += 1
        letter_index += 1

    x = const.SCREEN_WIDTH/2 - width/2
    y = const.SCREEN_HEIGHT/2 - height/2
    con.blit(dest_x=x, dest_y=y, alpha_bg=0.7)

    tcod.flush()
    key, mouse = tcod.wait_for_event(tcod.EVENT_KEY_PRESS, flush=True)
    return key
Beispiel #2
0
    def update(self, entities):
        self._root_console.clear()

        for e in entities:
            dc = e.get(DisplayComponent)
            self._root_console.draw_char(dc.x, dc.y, dc.character, dc.color)

        libtcodpy.flush()
Beispiel #3
0
def target_tile(player, max_range=None):
    while True:
        tcod.flush()
        key, mouse = tcod.check_for_event()
        render_all(player)

        x, y = (mouse.cx, mouse.cy)
        if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE:
            panel.add_message('Cancelled.', tcod.COLOR_RED)
            return (None, None)
        elif(mouse.lbutton_pressed and player.map.is_visible(x, y) and
             (max_range is None or player.distance(x, y) <= max_range)):
            return (x, y)
Beispiel #4
0
def slow_print(widget, text, y=1):
    label = widgets.Label(parent=widget, y=y, text=text)
    label.center_in_parent(vertical=False)
    label.text = ""

    for char in text:
        label.text = label.text + char

        widget.render()
        tcod.flush() # Relying on the tcod.set_fps_limit() from earlier to limit our render rate
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS | tcod.event.MOUSE_PRESS)
        if key.vk != tcod.key.NONE or mouse.lbutton or mouse.rbutton:
            label.text = text
            widget.render()
            return
Beispiel #5
0
def slow_print(widget, text, y=1):
    label = widgets.Label(parent=widget, y=y, text=text)
    label.center_in_parent(vertical=False)
    label.text = ""

    for char in text:
        label.text = label.text + char

        widget.render()
        tcod.flush(
        )  # Relying on the tcod.set_fps_limit() from earlier to limit our render rate
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS
                                          | tcod.event.MOUSE_PRESS)
        if key.vk != tcod.key.NONE or mouse.lbutton or mouse.rbutton:
            label.text = text
            widget.render()
            return
Beispiel #6
0
def render_all(player):
    player.map.render()
    panel.clear(const.PANEL_BACKGROUND)
    panel.render_bar(1, 1, const.BAR_WIDTH, label='HP',
                     value=player.fighter.hp, maximum=player.fighter.max_hp,
                     bar_color=const.PANEL_HPBAR_COLOR, back_color=const.PANEL_HPBAR_BACK,
                     text_color=const.PANEL_TEXT_COLOR)
    panel.render_bar(1, 2, const.BAR_WIDTH, label='XP',
                     value=player.fighter.xp, maximum=xp_to_level_up(player.level),
                     bar_color=const.PANEL_XPBAR_COLOR, back_color=const.PANEL_XPBAR_BACK,
                     text_color=const.PANEL_TEXT_COLOR)

    panel.console.set_default_foreground(tcod.COLOR_YELLOW)
    panel.console.print_ex(x=1, y=6, text='Dungeon(%d)' % player.map.level)

    player.map.console.blit()
    panel.render(tcod.root_console)
    tcod.flush()
    player.map.post_render()
Beispiel #7
0
def main_loop(top, dialog=False):
    while True:
        top.render()
        tcod.flush()

        # Get the input...
        get_input()
        if tcod.is_window_closed():
            events.post(events.QUIT)

        # ...and handle it:
        for event in events.generator():
            if event.type is events.QUIT:
                # Repost the quit event to break out of all the loops.
                events.post(events.QUIT)
                return
            elif dialog and event.type in {events.OK, events.CANCEL}:
                return event.data
            elif event.type is events.LAUNCH:
                event.data()
            else:
                top.handle_event(event)
Beispiel #8
0
def main_loop(top, dialog=False):
    while True:
        top.render()
        tcod.flush()

        # Get the input...
        get_input()
        if tcod.is_window_closed():
            events.post(events.QUIT)

        # ...and handle it:
        for event in events.generator():
            if event.type is events.QUIT:
                # Repost the quit event to break out of all the loops.
                events.post(events.QUIT)
                return
            elif dialog and event.type in {events.OK, events.CANCEL}:
                return event.data
            elif event.type is events.LAUNCH:
                event.data()
            else:
                top.handle_event(event)