Beispiel #1
0
def menu(header, options, width, skip=None):
    maxoptions = 26
    if skip:
        maxoptions = 25

    if len(options) > maxoptions:
        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_height_left_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_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        if skip and letter_index == ord(skip):
            letter_index += 1
        text = "(" + chr(letter_index) + ") " + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, 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")
    maxindex = len(options) - 1
    if skip and index > ord(skip) - ord("a"):
        maxindex = len(options)
    if index >= 0 and index <= maxindex:
        if skip:
            skippedindex = ord(skip) - ord("a")
            if index == skippedindex:
                return None
            if index > skippedindex:
                return index - 1
        return index
    return None
Beispiel #2
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " +
                         str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(
            con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the 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 player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt
                                               or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #3
0
def menu(header, options, width):

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    #calculate height for the header after auto-wrap and one line per option
    header_height = libtcod.console_height_left_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 window
    window = libtcod.console_new(width, height)

    #Print the header with auto-wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, 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_left(window, 0, y, libtcod.BKGND_NONE, 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 player with the root console and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #Convert the ASCII code to an index, and if it corresponds an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    #alt-enter fullscreens
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    return None
Beispiel #4
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " + str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the 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 player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #5
0
def pop_up(text):
	width = INVENTORY_WIDTH

	header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, text)

	height = header_height

	window = libtcod.console_new(width, height)

	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, text)

	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)
Beispiel #6
0
def pop_up(text):
    width = INVENTORY_WIDTH

    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, text)

    height = header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, text)

    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)
Beispiel #7
0
def menu(header, options, width):
    if len(options) > 16:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = libtcod.console_height_left_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_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, 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 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
Beispiel #8
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_height_left_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_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, 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_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

     # blit the contents of "window" to the root console
    x, y = SCREEN_WIDTH / 2 - width / 2, 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

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # (special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    return None
Beispiel #9
0
def render_blotter():
    global blotter
    global took_turn
    
    reached_top = False
    y = PANEL_HEIGHT - 2
    for turn in range(len(blotter)):
        messages = blotter[turn]
        for message in range(len(messages)):
            (text, color) = messages[message]
            color = libtcod.color_lerp(color, libtcod.black, min(turn * 0.2, 1))
            libtcod.console_set_foreground_color(panel, color)
            y -= libtcod.console_height_left_rect(panel, STATS_WIDTH + 2, y, SCREEN_WIDTH - STATS_WIDTH - 3, 0, text)
            libtcod.console_print_left_rect(panel, STATS_WIDTH + 2, y+1, SCREEN_WIDTH - STATS_WIDTH - 3, 0, libtcod.BKGND_NONE, text)
            if y <= 1:
                reached_top = True
                break
        if reached_top:
            break

    if took_turn:
        blotter.insert(0,[])
    blotter = blotter[0:5]
Beispiel #10
0
def menu(header, options, width):
	if len(options) > 16: raise ValueError('Cannot have a menu with more than 26 options.')

	header_height = libtcod.console_height_left_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_foreground_color(window, libtcod.white)
	libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

	y = header_height
	letter_index = ord('a')
	for option_text in options:
		text = '(' + chr(letter_index) + ') ' + option_text
		libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, 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 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