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
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) elif not random.randint(0, 3): ptest.set_default_foreground(libtcodpy.blue) elif not random.randint(0, 3): ptest.set_default_foreground(libtcodpy.yellow) else: ptest.set_default_foreground(libtcodpy.white) ptest.blit(ffade=fade) pshade.x += 1 if pshade.x > 10: pshade.x = 0 pshade.y += 1 if pshade.y > 10: pshade.y = 0 # pshade.blit(bfade=fade) fade += .1 if fade > .9: fade = .1 test.flush libtcodpy.console_wait_for_keypress(False)