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_bar(self, x, y, x2, total_width, value, maximum, bar_color, dim_color, text_color, color_lvls): TEXT_PAD = 8 tick_price = int(maximum / total_width) #render the background first libtcod.console_set_background_color(self.panel, dim_color) formated_str = "HP: %i/%i" % (value, maximum) #if displayed value == 0 - skip rendering bar if maximum == 0: return libtcod.console_set_foreground_color(self.panel, text_color) libtcod.console_print_left(self.panel, x, y, libtcod.BKGND_NONE, formated_str) libtcod.console_set_foreground_color(self.panel, self.create_color(bar_color[0])) libtcod.console_print_left(self.panel, x2, y, libtcod.BKGND_NONE, '[' + ''.ljust(total_width, '_') + ']') active_ticks = value * tick_price severity = 0 #now choose apropriate color depending on how much value left (compared to maximum) for color_lvl in color_lvls: if active_ticks <= maximum * color_lvl: severity += 1 #now render the bar on top libtcod.console_set_foreground_color(self.panel, self.create_color(bar_color[severity])) libtcod.console_print_left(self.panel, x2 + 1 ,y, libtcod.BKGND_NONE, '#'.center(active_ticks, '#'))