Beispiel #1
0
def menu(con,
         header,
         options,
         width,
         screen_width,
         screen_height,
         render_func=render_option):
    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)
    height = len(options) + header_height

    window = libtcod.console_new(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)

    y = header_height
    index = 1
    for option in options:
        render_func(option, index, window, y)
        index += 1
        y += 1

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #2
0
def menu(con, header, options, width, screen_width, screen_height):

    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    # print all the options
    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)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #3
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have menu with more than 26 options.")

    # calculate header height and give one line per option
    header_height = libtcod.console_get_height_rect(
        con, 0, 0, width, screen_height, header
    )
    height = len(options) + header_height

    # create an off-screen console for the menu window
    window = libtcod.console_new(width, height)

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(
        window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header
    )

    # print the menu options
    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)
        y += 1
        letter_index += 1

    # blit the "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #4
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 12: raise ValueError('Cannot have a menu with more than 12 options')

    # calc total menu height for the header 
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # create off-screen console that represents the menu's window
    window = libtcod.console.Console(width, height)

    # print header (with auto-wrap)
    libtcod.console_set_default_foreground(window, libtcod.white)
    #libtcod.console_set_default_background(window, libtcod.gray)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    # print all options
    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)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #5
0
def menu(console, header, options, width, screen_width, screen_height):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    # Calculates the total height for the header and does one line per option
    header_height = tcod.console_get_height_rect(console, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # Creates a new console that represents the menu window
    window = tcod.console_new(width, height)

    # Prints the header
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header)

    # Prints the options in the menu
    y = header_height
    letter_index = ord('a')
    for option in options:
        text = '(' + chr(letter_index) + ')' + option
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #6
0
def menu(con, header, options, width, screen_width, screen_height):
    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)
    height = len(options) + header_height

    # メニューのコンソールを作る
    window = libtcod.console.Console(width, height)

    # 自動折り返しでヘッダをprintする
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    # すべてのオプションをprintする
    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)
        y += 1
        letter_index += 1

    # ウィンドウの内容をルートコンソールにblitする
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #7
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + header_height + 2

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE, tcod.LEFT, header)

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

    x = int(SCREEN_WIDTH /2 - width / 2)
    y = int(SCREEN_HEIGHT /2 - height / 2)


    tcod.console_blit(window, 0, 0, width, height, 0, x, y - 3, 1.0, 0.7)

    tcod.console_flush()
    key = tcod.console_wait_for_keypress(True)

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    return None
Beispiel #8
0
def menu(con, header, options, width, screen_width, screen_height):
    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)
    height = len(options) + header_height
    window = libtcod.console_new(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)

    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)
        y += 1
        letter_index += 1

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #9
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    # ヘッダーの高さの合計を計算し、 (自動折り返し後) オプションごとに1行ずつ計算
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # メニューのウィンドウを表すコンソールを作成
    window = libtcod.console_new(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)

    # すべてのオプションを表示
    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)
        y += 1
        letter_index += 1

    # ルートコンソールに "window "の内容を格納
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #10
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with over 26 options")

    # Calculates height of header after text wrap
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    # Creates new console window for the menu
    window = libtcod.console_new(width, height)

    # Print the header with auto wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    # Prints options
    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)
        y += 1
        letter_index += 1

    # Blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #11
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('You cannot have more than 26 menu options')

    # calculate total height for header
    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 screen_height, header)
    height = len(options) + header_height

    # create an off-screen console for menu's window
    window = tcod.console.Console(width, height)

    # print header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    # print out the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = f'({chr(letter_index)}) {option_text}'
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #12
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have menu with more than 26 options')

    #calc total height for header after auto-wrap, one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    #create off-screen console for menu window
    window = libtcod.console_new(width, height)

    #print header with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    #print options
    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)
        y += 1
        letter_index += 1

    #blit to to root console from window
    y = int(screen_height / 2 - height / 2)
    x = int(screen_width / 2 - width / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def determine_main_menu_index(menu_name,options,con,constants,player,mouse):
    inventory_title = get_menu_title(menu_name)
    menu_width =  get_menu_width(menu_name)

    if inventory_title == "":
        header_height = 0
    else:
        header_height = libtcod.console_get_height_rect(con, 0, 0, menu_width,
                                                    get_menu_height(constants['screen_height']), inventory_title)

    height = len(options) + header_height

    x = get_menu_height(constants['screen_height']) / 2 - 50 / 2
    y = get_menu_height(constants['screen_height']) / 2 - height / 2

    # Compute x and y offsets to convert console position to menu position
    x_offset = x  # x is the left edge of the menu
    y_offset = y + (header_height - (header_height / 5)) - 1 # The top edge of the menu

    (menu_x, menu_y) = (mouse.cx - x_offset, mouse.cy - y_offset)
    if menu_x >= 0 and menu_x < menu_width and menu_y >= 0 and menu_y < height - header_height:
        menu_y = int(math.ceil(menu_y)) - 1
        return menu_y
    else:
        return menu_y
Beispiel #14
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    # Calculate total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 screen_height, header)
    height = len(options) + header_height

    # Offscreen console that shows the menu
    window = tcod.console_new(width, height)

    # Print the head with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

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

    # blit contents of window to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)

    # If header is empty string, don't draw that line
    if header == '':
        tcod.console_blit(window, 0, 1, width, height, 0, x, y, 1.0, 0.5)
    else:
        tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.5)
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)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    window = libtcod.console_new(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)
    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)
        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)
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
    if key.vk == libtcod.KEY_ENTER:
        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
Beispiel #16
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
    #calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + header_height
    #create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
    #print all the options
    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)
        y += 1
        letter_index += 1
    #blit the contents of "window" to the root console
    x = int(SCREEN_WIDTH/2 - width/2)
    y = int(SCREEN_HEIGHT/2 - height/2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Beispiel #17
0
def menu(console, header, options, width, screen_width, screen_height):
    """ Main game menu (displays options available for selection)

    """

    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options")

    # total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(console, 0, 0, width,
                                                 screen_height, header)
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tcod.console_new(width, height)

    # print the header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    # print all the options
    y_pos = header_height
    letter_index = ord("a")
    for option_text in options:
        text = f"({chr(letter_index)})" + option_text
        tcod.console_print_ex(window, 0, y_pos, tcod.BKGND_NONE, tcod.LEFT,
                              text)
        y_pos += 1
        letter_index += 1

    # blit the contents of 'window' to the root console
    x_pos = int(screen_width / 2 - width / 2)
    y_pos = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x_pos, y_pos, 1.0, 0.7)
Beispiel #18
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")

    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(
        con, 0, 0, width, screen_height, header
    )
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tcod.console_new(width, height)

    # print the header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(
        window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header
    )

    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        if option_text == "Inventory is empty.":
            text = f"( ) {option_text}"
        else:
            text = f"({chr(letter_index)}) {option_text}"
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def menu(con, header, options, width, max_capacity=6):
    '''
    OK this menu only shows up on the center of the screen and with some transparency...
    also it only works for numeric values for the options...
    '''

    if len(options) > max_capacity: raise ValueError('No more than 6.')

    #Calculate total height for header
    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 const['screen_height'],
                                                 header)
    height = len(options) + header_height

    #create an offscreen console that represents the menu's window
    window = tcod.console_new(width, height)

    #print header, with autowrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

    #print all options
    y = header_height
    num_index = 1
    for option_text in options:
        text = '(' + str(num_index) + ')' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        num_index += 1

    #blit the contents of 'window' to the root console
    x = int(const['screen_width'] / 2 - width / 2)
    y = int(const['screen_height'] / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #20
0
def render_game_menu(con, header, options, width, screen_width, screen_height,
                     game_state, index):
    window = libtcodpy.console_new(width, 30)
    header_height = libtcodpy.console_get_height_rect(con, 0, 0, width,
                                                      screen_height, header)
    height = len(options) + header_height

    y = header_height

    letter_index = ord('a')
    for i in range(len(options)):
        # text = '(' + chr(letter_index) + ') ' + option_text
        if i == index:
            libtcodpy.console_print_ex(
                window, int(width / 2), y, libtcodpy.BKGND_SET,
                libtcodpy.CENTER, '%c{0}%c'.format(options[i]) %
                (libtcodpy.COLCTRL_1, libtcodpy.COLCTRL_STOP))
        else:
            libtcodpy.console_print_ex(window, int(width / 2), y,
                                       libtcodpy.BKGND_SET, libtcodpy.CENTER,
                                       '{0}'.format(options[i]))
        y += 2
        letter_index += 1

    libtcodpy.console_blit(window, 0, 0, width, 30, 0, int(screen_width - 80),
                           screen_height - 30, 1.0, 0.7)
def test_console_printing(console, fg, bg):
    libtcodpy.console_set_background_flag(console,
                                          libtcodpy.BKGND_SET)
    assert (libtcodpy.console_get_background_flag(console) ==
                     libtcodpy.BKGND_SET)

    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    assert (libtcodpy.console_get_alignment(console) ==
                     libtcodpy.LEFT)

    libtcodpy.console_print(console, 0, 0, 'print')
    libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET,
                               libtcodpy.LEFT, 'print ex')

    assert (libtcodpy.console_print_rect(
        console, 0, 0, 8, 8, 'print rect') > 0
        )
    assert (libtcodpy.console_print_rect_ex(
        console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT,
        'print rect ex') > 0
        )
    assert (libtcodpy.console_get_height_rect(
        console, 0, 0, 8, 8, 'get height') > 0
        )

    libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
Beispiel #22
0
def menu(con, header, options, width, screen_width, screen_height, root):
    if len(options) > 25:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tcod.console_new(width, height)

    # print the header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header)
    # print all the options
    y = header_height
    letter_index = 1
    if len(options) > 0:
        MenuState.menu_state = MenuState.menu_state % len(options)
    for option_index in range(0, len(options)):
        if option_index == MenuState.menu_state and MenuState.menu_state < len(options):
            text = '(' + "X" + ') ' + options[option_index]
        else:
            text = '(' + " " + ') ' + options[option_index]
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, root, x, y, 1.0, 0.7)
Beispiel #23
0
def menu(con, header: str, options: List[str], width: int):
    if len(options) > 26:
        raise ValueError('Cannot have more than 26 options')

    # Calculate total height for the header (after textwrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    constants.screen_height,
                                                    header)
    height = len(options) + header_height

    # Create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    # Print the header, with wrapped text
    libtcod.console_set_default_foreground(window, colors.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

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

    # Blit the contents of "window" to the root console
    x = constants.screen_width // 2 - width // 2
    y = constants.screen_height // 2 - height // 2
    # noinspection PyTypeChecker
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #24
0
def menu(con, header, options, width, screenWidth, screenHeight):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # Calculate height for header and one line per option
    headerHeight = tcod.console_get_height_rect(con, 0, 0, width, screenHeight,
                                                header)
    height = len(options) + headerHeight

    # Create off-screen console with menu's window
    window = tcod.console_new(width, height)

    # Print header with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_ex(window, 0, 0, tcod.BKGND_NONE, tcod.LEFT, header)

    # Print Options
    y = headerHeight
    letterIndex = ord('a')
    for optionText in options:
        text = '(' + chr(letterIndex) + ')' + optionText
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letterIndex += 1

    # BLit contents to root console
    x = int(screenWidth / 2 - width / 2)
    y = int(screenHeight / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #25
0
def menu(header, options, width, renderer):
    if len(options) > 26:
        raise ValueError('Cannot have more than 26 options')

    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(renderer.con, 0, 0, width,
                                                 renderer.screen_height,
                                                 header)
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tcod.console.Console(width, height)

    # print the header, with auto-wrap
    window.default_fg = tcod.white
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

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

    # blit the contents of "window" to the root console
    x = int(renderer.screen_width / 2 - width / 2)
    y = int(renderer.screen_height / 2 - height / 2)
    window.blit(renderer.root, x, y, 0, 0, width, height, 1.0, 0.7)
Beispiel #26
0
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for header, auto wrap, and one line per option
    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 screen_height, header)
    height = len(options) + header_height

    # create off-screen console representing menu's window
    window = tcod.console_new(width, height)

    # print header w/ auto wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 0, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

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

    # blit contents of window to root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def test_console_printing(console, fg, bg):
    libtcodpy.console_set_background_flag(console,
                                          libtcodpy.BKGND_SET)
    assert (libtcodpy.console_get_background_flag(console) ==
                     libtcodpy.BKGND_SET)

    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    assert (libtcodpy.console_get_alignment(console) ==
                     libtcodpy.LEFT)

    libtcodpy.console_print(console, 0, 0, 'print')
    libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET,
                               libtcodpy.LEFT, 'print ex')

    assert (libtcodpy.console_print_rect(
        console, 0, 0, 8, 8, 'print rect') > 0
        )
    assert (libtcodpy.console_print_rect_ex(
        console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT,
        'print rect ex') > 0
        )
    assert (libtcodpy.console_get_height_rect(
        console, 0, 0, 8, 8, 'get height') > 0
        )

    libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
Beispiel #28
0
def menu(header, options, width):
    global key, mouse

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = tcod.console_get_height_rect(con, 0, 0, width,
                                                 SCREEN_HEIGHT, header)

    if header == '':
        header_height = 0

    height = len(options) + header_height

    window = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(window, 0, 1, width, height, tcod.BKGND_NONE,
                               tcod.LEFT, header)

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

    x = int(SCREEN_WIDTH / 2 - width / 2)
    y = int(SCREEN_HEIGHT / 2 - height / 2)

    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    x_offset = x
    y_offset = y + header_height

    while True:
        tcod.console_flush()
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if mouse.lbutton_pressed:
            (menu_x, menu_y) = (mouse.cx - x_offset, mouse.cy - y_offset)

            if 0 <= menu_x and menu_x <= width and 0 <= menu_y and menu_y < height - header_height:
                return menu_y

        if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE:
            return None

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

        index = key.c - ord('a')
        if index >= 0 and index < len(options):
            return index

        if index >= 0 and index <= 26:
            return None
Beispiel #29
0
    def get_text_height(self, x: int, y: int, w: int, h: int, fmt: str):
        """Return the expected height of the autowrapped string `fmt` without
        actually drawing the screen to the console.

        Parameters
        ----------
        x, y : Upper left coordinate of text box.
        w, h : Width and height of text box.
        fmt : Format string to be printed in the text box.
        """
        return tcod.console_get_height_rect(self._c, x, y, w, h, fmt)
Beispiel #30
0
    def get_text_height(self, x: int, y: int, w: int, h: int,
                        fmt: str):
        """Return the expected height of the autowrapped string `fmt` without
        actually drawing the screen to the console.

        Parameters
        ----------
        x, y : Upper left coordinate of text box.
        w, h : Width and height of text box.
        fmt : Format string to be printed in the text box.
        """
        return tcod.console_get_height_rect(self._c, x, y, w, h, fmt)
Beispiel #31
0
def menu(
    con: libtcod.console.Console,
    header: str,
    options: list,
    width: int,
    screen_width: int,
    screen_height: int,
):
    """Generic Menu rendering function.
    
    Arguments:
        con {libtcod.console.Console} -- Target console to show the menu
        header {str} -- header (description) for the menu
        options {list} -- lsit of options for the menu
        width {int} -- desired width of the menu
        screen_width {int} -- limit screen width 
        screen_height {int} -- limit screen height
    
    Raises:
        ValueError: if list of `options` has more than 26 members
    """
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")

    # calculate total height for the header (after auto-wrap), one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    # Off screen console fo the menu's window
    window = libtcod.console_new(width, height)

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

    # Render all options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        text = f"({chr(letter_index)}) {option_text}"
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Beispiel #32
0
def look_menu(con, thing, screen_width, screen_height):
    width = 50
    height = 50
    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, thing.name)

    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 1, 1, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, thing.name)
    mon_desc = get_monster_desc()
    item_desc = get_item_desc()
    spell_desc = get_spell_desc()
    y = header_height + 1

    # kinda a dumb loop maybe I should just make one big desc list to kill it?
    if thing.item:
        thing_text = item_desc[thing.name]
    elif thing.fighter:
        thing_text = mon_desc[thing.name]
    elif thing.spell:
        thing_text = spell_desc[thing.name]

    lined_mon_text = textwrap.wrap(thing_text, width - 2)
    for line in lined_mon_text:
        text = line
        libtcod.console_print_ex(window, 1, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)

    # Draws * borders around menus if borders is True
    for x_val in range(0, width):
        libtcod.console_put_char(window, x_val, 0, '*')
    for y_val in range(0, height):
        libtcod.console_put_char(window, 0, y_val, '*')
    for y_v in range(0, height):
        libtcod.console_put_char(window, width - 1, y_v, '*')
    for x_v in range(0, width):
        libtcod.console_put_char(window, x_v, height - 1, '*')

    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
 
    #calculate total height for the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
 
    #create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)
 
    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
 
    #print all the options
    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)
        y += 1
        letter_index += 1
 
    #blit the contents of "window" to the root console
    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)
 
    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None