def render_ui(self, player): #prepare to render the GUI panel libtcod.console_set_background_color(self.panel, libtcod.black) libtcod.console_clear(self.panel) #show the player's HP self.render_bar(1, 1, 13, 10, player.hp, player.base_hp, HP_BAR, libtcod.darker_red, self.create_color(COLOR_STATUS_TEXT), HP_BAR_PERCENT) self.render_bar(1, 2, 13, 10, player.mp, player.base_mp, MP_BAR, libtcod.darker_red, self.create_color(COLOR_STATUS_TEXT), MP_BAR_PERCENT) self.render_stats_two_column(1, 3, "AC", player.base_ac, 13, "EVADE", "player.evade", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 4, "Str", "str", 13, "To", "tough", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 5, "Dex", "des", 13, "Int", "int", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 6, "XL", player.xl, 13, "EXP", "%d/%d" % (player.xp, util.xp_for_lvl(player.xl)) , COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) #blit the contents of "panel" to the root console libtcod.console_blit(self.panel, 0, 0, RIGHT_PANEL_WIDTH, RIGHT_PANEL_HEIGHT, 0, RIGHT_PANEL_X, 0) #print the game messages, one line at a time y = 0 for (line, level) in gl.__msgs__: if level < 1 and not gl.__wizard_mode__: continue libtcod.console_set_foreground_color(self.panel_msg, self.message_colours.get(level, libtcod.white)) libtcod.console_print_left(self.panel_msg, 0, y, libtcod.BKGND_NONE, line.ljust(SCREEN_WIDTH, ' ')) y += 1 libtcod.console_blit(self.panel_msg, 0, 0, SCREEN_WIDTH, MSG_PANEL_HEIGHT, 0, 0, MSG_PANEL_Y ) libtcod.console_flush()
def render_examine(self, player, map): libtcod.console_clear(self.con_full) _x, _y = self.viewport.look_x, self.viewport.look_y if (_x, _y) == self.viewport.playerxy: #starting point of view libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.con_full, 1, 0, 'This is you'.ljust(SCREEN_WIDTH, ' ')) libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' ')) else: visible = rlfl.has_flag(map.current.fov_map0, (_x, _y), rlfl.CELL_MEMO) if not visible: libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.con_full, 1, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' ')) libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' ')) return result = '' crit = map.critter_at(_x, _y) if crit: result += getattr(crit, 'description_' + player.time) tile_at = map.tile_at(_x, _y) result += tile_at.get_full_description(player.time) result += '\n\nPress e to go back to look-around mode.' libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.con_full, 0, 0, result.ljust(SCREEN_WIDTH, ' ')) libtcod.console_blit(self.con_full, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush()
def render(self): libtcod.console_clear(self.console) pages = len(self.content) / (self.height - 2) pages += 1 if len(self.content) % (self.height - 2) != 0 else 0 x = 0 y = 1 if self.offset: libtcod.console_set_default_foreground(self.console, libtcod.dark_crimson) libtcod.console_print(self.console, 0, 0, "--- [-][PgDwn] Scroll up ---" .center(self.width)) for line, rgb, newline in self.content[self.offset:]: libtcod.console_set_default_foreground(self.console, rgb) libtcod.console_print(self.console, x, y, line) if newline: x = 0 y+= 1 else: x += len(line) y = self.height - 1 if pages > 1: libtcod.console_set_default_foreground(self.console, libtcod.dark_crimson) footer = "--- [+][PgDwn] Scroll down \t Line [%d]/[%d] ---" % (self.offset, len(self.content)) libtcod.console_print(self.console, 0, y, footer.center(self.width)) libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 0, 0) libtcod.console_flush()
def _render_inventory(self, items, action, multiple=False): """ Renders inventory screen, executing action if player presses one of mapped keys """ mapped_items = {} libtcod.console_clear(self.con_full) inven = items selected_items = None if multiple: selected_items = {} while True: msgs = ScrollList() if not multiple: msgs.append(('Select letter to ' + action).center(SCREEN_WIDTH), libtcod.white) else: msgs.append(('Select letters to ' + action).center(SCREEN_WIDTH), libtcod.white) y = 1 letter = ord('a') for category, items in inven.items(): msgs.append(category + ":", libtcod.dark_han) y += 1 for item in items: cletter = chr(letter) msgs.append(cletter, libtcod.dark_orange, False) if multiple and selected_items.has_key(cletter): line = " + " + item.name else: line = " - " + item.name mapped_items[cletter] = item letter += 1 if letter > 122: letter = ord('A') msgs.append(line, libtcod.white) y += 1 sp = ScrollPane(self.con_full, SCREEN_WIDTH, SCREEN_HEIGHT, msgs) sp.render() key = sp.handle_input() if multiple and key == libtcod.KEY_ENTER: return selected_items.values() if not isinstance(key, str) or key not in valid_inventory_chars: return None if not key in mapped_items: continue #todo maybe we should exit here or give a warning? if not multiple: return mapped_items[key] else: if selected_items.has_key(key): selected_items[key] = None else: selected_items[key] = mapped_items[key]
def render_ui(self, player): cc = self.create_color #prepare to render the GUI panel libtcod.console_set_default_background(self.panel, libtcod.black) libtcod.console_clear(self.panel) #show the player's HP self.render_bar(1, 1, 13, 10, player.hp, player.base_hp, HP_BAR, libtcod.darker_red, cc(COLOR_STATUS_TEXT), HP_BAR_PERCENT) self.render_bar(1, 2, 13, 10, player.mp, player.base_mp, MP_BAR, libtcod.darker_red, cc(COLOR_STATUS_TEXT), MP_BAR_PERCENT) self.render_stats_two_column(1, 3, "AC", player.base_ac, 13, "EVADE", "player.evade", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 4, "Str", "str", 13, "To", "tough", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 5, "Dex", "des", 13, "Int", "int", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 6, "XL", player.xl, 13, "EXP", "%d/%d" % (player.xp, util.xp_for_lvl(player.xl)) , COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) self.render_stats_two_column(1, 7, "Turns", gl.__turn_count__, 13, "", "", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES) #blit the contents of "panel" to the root console libtcod.console_blit(self.panel, 0, 0, RIGHT_PANEL_WIDTH, RIGHT_PANEL_HEIGHT, 0, RIGHT_PANEL_X, 0)
def render_tile_description(self, map, player): libtcod.console_clear(self.panel_msg) _x, _y = self.viewport.look_x, self.viewport.look_y if (_x, _y) == self.viewport.playerxy: #starting point of view libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.panel_msg, 0, 0, 'Look-around mode. Use keys to move cursor'.ljust(SCREEN_WIDTH, ' ')) else: visible = rlfl.has_flag(map.current.fov_map0, (_x, _y), rlfl.CELL_MEMO) if not visible: libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.panel_msg, 0, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' ')) return result = '' crit = map.critter_at(_x, _y) if crit: result += 'You see ' + crit.name + '.\n' tile_at = map.tile_at(_x, _y) result += tile_at.get_view_description() result += 'Press e to examine' libtcod.console_set_default_foreground(self.panel_msg, libtcod.white) libtcod.console_print(self.panel_msg, 0, 0, result.ljust(SCREEN_WIDTH, ' '))
def clear_screen(self): libtcod.console_clear(self.con)
def toggle_lookmode(self): if not self.viewport: raise RuntimeError('No viewport') self.viewport.look_x, self.viewport.look_y = self.viewport.playerxy libtcod.console_clear(self.panel_msg)