Exemplo n.º 1
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    # header_height = libtcod.console_get_height_rect(con, 0, 0, width,
    #                                                 SCREEN_HEIGHT, header)
    header_height = libtcod.console_get_height_rect(console.body, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # window = libtcod.console_new(width, height)
    window = Panel(0, 0, width, height)

    # libtcod.console_set_default_foreground(window, libtcod.white)
    # libtcod.console_print_rect_ex(window, 0, 0, width, height,
    #                               libtcod.BKGND_NONE, libtcod.LEFT, header)
    window.set_default_foreground(libtcod.white)
    window.write_wrap_ex(0, 0, width, height, header, libtcod.LEFT)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        # libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
        #                          libtcod.LEFT, text)
        window.write(0, y, text)
        y += 1
        letter_index += 1

    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    # libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    window.x = x
    window.y = y
    window.blit(bfade=0.7)

    # libtcod.console_flush()
    root.flush
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Exemplo n.º 2
0
import libtcodpy
import random
from Console import Console
from Panel import Panel


test = Console(20, 20, 'test')
test.set_fps(10)
ptest = Panel(0, 0, 20, 20)
ptest.set_default_foreground(libtcodpy.light_gray)
pshade = Panel(-1, -1, 10, 10)
random.seed(222)
fade = 0.1

while not test.is_window_closed:
    for x in range(0, 20):
        for y in range(0, 20):
            if random.randint(0, 2):
                ptest.write(x, y, '.')
                if not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.red)
                elif not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.blue)
                elif not random.randint(0, 5):
                    ptest.set_default_background(libtcodpy.yellow)
                else:
                    ptest.set_default_background(libtcodpy.black)
            else:
                ptest.write(x, y, '#')
                if not random.randint(0, 3):
                    ptest.set_default_foreground(libtcodpy.red)