def menu(main_console, 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 = main_console.get_height_rect(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 window.default_bg = 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 = '({}) {}'.format(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, main_console, x, y, 1.0, 0.7) window.blit(main_console, x, y, 0, 0, width, height, 1.0, 0.7)
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)
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)
def character_screen(player, character_screen_width, character_screen_height, screen_width, screen_height): window = libtcod.console_new(character_screen_width, character_screen_height) libtcod.console_set_default_foreground(window, libtcod.white) character_sheet = [ 'Character Information', 'Level: {0}'.format(player.level.current_level), 'Experience: {0}'.format(player.level.current_xp), 'Experience to Level: {0}'.format( player.level.experience_to_next_level), 'Maximum HP: {0}'.format(player.fighter.max_hp), 'Damage: {0}'.format(player.fighter.power), 'Accuracy: {0}'.format(player.fighter.hit), 'Defense: {0}'.format(player.fighter.defense), ] if player.status_effects.active_statuses: character_sheet.append("Active Status Effects:") character_sheet.extend( "{} ({} turns left)".format(name, status.duration) for name, status in player.status_effects.active_statuses.items()) for i, s in enumerate(character_sheet): libtcod.console_print_rect_ex(window, 0, i, character_screen_width, character_screen_height, libtcod.BKGND_NONE, libtcod.LEFT, s) x = screen_width // 2 - character_screen_width // 2 y = screen_height // 2 - character_screen_height // 2 libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
def render(self, con, x: int, y: int, alignment: int = None): if alignment is None: alignment = self.alignment if self.fill_char != 0: box = np.full((self.width, self.height), self.fill_char) for dx, col in enumerate(box): for dy, char in enumerate(col): if type(char) == 'int': char = chr(char) if char != ScreenObject.NONE_CHAR: libtcod.console_put_char_ex(con, x + dx, y + dy, char, fore=self.fg, back=self.bg) libtcod.console_set_default_foreground(con, self.fg) libtcod.console_set_default_background(con, self.bg) libtcod.console_print_rect_ex(con, x, y, self.width, self.height, flag=libtcod.BKGND_SET, alignment=alignment, fmt=self.text)
def help_menu(con, width, screen_width, screen_height): height = screen_height window = libtcod.console_new(width, height) libtcod.console_set_default_foreground(window, libtcod.white) header = 'Help' text = [ 'Use wasd to move;', 'Use g to pick up items;', 'Use b to drop items;', 'Use i to open inventory;', 'Use p to toggle realtime mode on and off' 'Use t to teleport to the next floor', 'Be advised though, the deeper you go, the more dangerous dungeon becomes' 'Hover mouse over something, to see what is it. ', 'Press esc to exit', '', 'Now go explore dungeon and genocide local population.' ] libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header) y = 1 for elem in text: libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, elem) 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)
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)
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)
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)
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)
def process(self): window = tcod.console_new(self.width, self.height) tcod.console_set_default_foreground(window, tcod.white) """(con, x, y, w, h, flag, alignment, fmt)""" info = self.get_player_info() for y, text in enumerate(info): tcod.console_print_rect_ex( con=window, x=0, y=y, w=self.width, h=self.height, flag=tcod.BKGND_NONE, alignment=tcod.LEFT, fmt=text ) x = const.SCREEN_WIDTH // 2 - self.width // 2 y = const.SCREEN_HEIGHT // 2 - self.height // 2 window.blit( dest=self.scene.manager.root_console, dest_x=x, dest_y=y, src_x=0, src_y=0, width=self.width, height=self.height, fg_alpha=1.0, bg_alpha=0.7, key_color=None ) tcod.console_flush()
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(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 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
def render(self, pokeball: Pokeball, percent_complete: float, message: str) -> libtcod.console: """ Render the area and return the full console """ rows_complete = int(len(CatchGraphicRenderer.graphic) * (percent_complete / 100)) libtcod.console_clear(self.console) libtcod.console_set_default_background(self.console, settings.CATCH_GRAPHIC_BG_COLOR) libtcod.console_set_default_foreground(self.console, settings.LINE_COLOR) libtcod.console_print_frame(self.console, 0, 0, CatchGraphicRenderer.width, CatchGraphicRenderer.height) for y, row in enumerate(CatchGraphicRenderer.graphic): for x, cell in enumerate(row): if cell[0] != '': if len(CatchGraphicRenderer.graphic) - y <= rows_complete: if cell[1] == "upper": color = pokeball.top_color elif cell[1] == "lower": color = pokeball.bottom_color else: color = cell[1] else: color = libtcod.gray libtcod.console_set_default_foreground(self.console, color) libtcod.console_put_char(self.console, x + self.x_offset, y + self.y_offset, cell[0]) if message: libtcod.console_print_rect_ex(self.console, CatchGraphicRenderer.width // 2, CatchGraphicRenderer.height - 3, CatchGraphicRenderer.width - 2, 2, libtcod.BKGND_NONE, libtcod.CENTER, message) return self.console
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)
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
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
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)
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)
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)
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)
def character_screen(player, character_screen_width, character_screen_height, renderer): window = tcod.console.Console(character_screen_width, character_screen_height) window.default_fg = tcod.white info_table = [ 'Character Information', 'Level: {0}'.format(player.level.current_level), 'Experience: {0}'.format(player.level.current_xp), 'Experience to next level: {0}'.format( player.level.experience_to_next_level), 'Attack: {0}'.format(player.fighter.power), 'Defense: {0}'.format(player.fighter.defense), '-' * 20, 'Attributes:', str(player.strength), str(player.dexterity), str(player.constitution), str(player.intelligence), str(player.wisdom), str(player.charisma), ] for index, text in enumerate(info_table): tcod.console_print_rect_ex(window, 0, index, character_screen_width, character_screen_height, tcod.BKGND_NONE, tcod.LEFT, text) x = renderer.screen_width // 2 - character_screen_width // 2 y = renderer.screen_height // 2 - character_screen_height // 2 window.blit(renderer.root, x, y, 0, 0, character_screen_width, character_screen_height, 1.0, 0.7)
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)
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 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)
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)
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)
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(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
def ability_screen(con, player, menu_width, menu_height, screen_width, screen_height): window = libtcod.console_new(menu_width, menu_height) libtcod.console_set_default_foreground(window, libtcod.white) libtcod.console_print_rect_ex(window, 0, 1, menu_width, menu_height, libtcod.BKGND_NONE, libtcod.LEFT, 'Placeholder until abilities are implemented!') x = screen_width // 2 - menu_width // 2 y = screen_height // 2 - menu_height // 2 libtcod.console_blit(window, 0, 0, menu_width, menu_height, con, x, y, 1, 1)
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)
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