def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    """
    Defini une zone d'écriture où on affichechera les messages pendant qu'on joue.

    :param panel:
    :param x:
    :param y:
    :param total_width:
    :param name:
    :param value:
    :param maximum:
    :param bar_color:
    :param back_color:
    """
    bar_width = int(float(value) / maximum * total_width)

    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)

    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER, '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 2
0
def render_bar(panel, x, y, total_width, name, value, bar_color, back_color):
    bar_width = total_width  # int(float(value) / maximum * total_width)

    libtcod.console_set_default_background(con=panel, col=back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(con=panel, col=bar_color)
    if bar_width > 0:
        libtcod.console_rect(con=panel,
                             x=x,
                             y=y,
                             w=bar_width,
                             h=1,
                             clr=False,
                             flag=libtcod.BKGND_SCREEN)

    libtcod.console_set_default_foreground(con=panel, col=libtcod.white)
    libtcod.console_print_ex(con=panel,
                             x=1,
                             y=y,
                             flag=libtcod.BKGND_NONE,
                             alignment=libtcod.LEFT,
                             fmt='[{}] {}'.format(y, name))
    libtcod.console_print_ex(con=panel,
                             x=total_width,
                             y=y,
                             flag=libtcod.BKGND_NONE,
                             alignment=libtcod.RIGHT,
                             fmt='CD:{}'.format(value))
Ejemplo n.º 3
0
    def _draw_item_details(self, idx, inventory, y, width):
        item = inventory.items[idx]
        actions = []
        for component in self.world.components_for_entity(item):
            if isinstance(component, Action):
                actions.append(component)

        num_actions = len(actions)
        num_details = 3
        self._draw_panel_background(width, y, width, num_actions + num_details + 1, self.FOREGROUND_COLOR)

        self._draw_text("ACTIONS", width + int(width / 2), y, libtcod.CENTER)
        y += 1

        for idx_action in range(0, len(actions)):
            action = actions[idx_action]
            if idx_action == inventory.selected_action:
                libtcod.console_set_default_background(self.consoles_inventory.console, self.SELECTED_COLOR)
                libtcod.console_rect(self.consoles_inventory.console, width, y, width, 1, True, libtcod.BKGND_SET)
                libtcod.console_set_default_background(self.consoles_inventory.console, self.FOREGROUND_COLOR)

                self._draw_text(action.name, width + 1, y)
            else:
                self._draw_text(action.name, width + 1, y)

            y += 1

        y += 1
        self._draw_text("DESCRIPTION", width + int(width / 2), y, libtcod.CENTER)

        y += 1
        item_text = self.world.component_for_entity(inventory.items[idx], Text)
        self._draw_text(item_text.description, width + 1, y)
Ejemplo n.º 4
0
def render_bar(panel, x_pos, y_pos, total_width, name, value, maximum,
               bar_color, back_color):
    """ Generates a status bar with name and value

    """

    bar_width = int(float(value) / maximum * total_width)

    tcod.console_set_default_background(panel, back_color)
    tcod.console_rect(panel, x_pos, y_pos, total_width, 1, False,
                      tcod.BKGND_SCREEN)
    tcod.console_set_default_background(panel, bar_color)

    if bar_width > 0:
        tcod.console_rect(panel, x_pos, y_pos, bar_width, 1, False,
                          tcod.BKGND_SCREEN)

    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(
        panel,
        int(x_pos + total_width / 2),
        y_pos,
        tcod.BKGND_NONE,
        tcod.CENTER,
        f"{name}: {value}/{maximum}",
    )
Ejemplo n.º 5
0
 def _draw_slot(self, x, y, width, color):
     libtcod.console_set_default_background(self.consoles_menu.console,
                                            color)
     libtcod.console_rect(self.consoles_menu.console, x, y, width, 1, True,
                          libtcod.BKGND_SET)
     libtcod.console_set_default_background(self.consoles_menu.console,
                                            self.BACKGROUND_COLOR)
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    """Renders a bar on the screen.

    Args:
        panel(Console): The Console object the bar will be rendered in.
        x(int): Width of the bar.
        y(int): Height of the bar.
        total_width(int): Total width of the bar on the screen.
        name(str): The name of the bar (e.g. Health).
        value(int): Current value of the bar.
        maximum(int): Max value of the bar.
        bar_color(tcod.color): The libtcod.Color of the bar.
        back_color(tcod.color): The libtcod.Color of the background.
    """

    bar_width = int(float(value) / maximum * total_width)

    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > - 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)

    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER,
                             '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 7
0
def render_bar(panel, x, y, width, name, value, maximum, bar_colour, back_colour):
    filled_width=int(float(value)/maximum*width)
    tcod.console_set_default_background(panel, back_colour)
    tcod.console_rect(panel, x, y, width, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_background(panel, bar_colour)
    if filled_width>0:
        tcod.console_rect(panel, x, y, filled_width, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int((x+width+1)/2), y, tcod.BKGND_NONE, tcod.CENTER, '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 8
0
 def drawBar(self, drawInfo):
     title = " " + drawInfo[1]
     libtcod.console_print_ex(drawInfo[0], drawInfo[4], drawInfo[5],
                              libtcod.BKGND_NONE, libtcod.LEFT, title)
     libtcod.console_set_default_background(drawInfo[0], drawInfo[3])
     if drawInfo[2] > 0:
         libtcod.console_rect(drawInfo[0], drawInfo[4], drawInfo[5],
                              drawInfo[2], 1, False, libtcod.BKGND_SCREEN)
     libtcod.console_set_default_background(drawInfo[0], libtcod.black)
Ejemplo n.º 9
0
    def render_bar(console, x, y, bar_width, value, max_value, color,
                   bg_color):
        width = int(float(value) / max_value * bar_width)
        tcod.console_set_default_background(console, bg_color)
        tcod.console_rect(console, x, y, bar_width, 1, True, tcod.BKGND_SET)

        tcod.console_set_default_background(console, color)
        if value > 0:
            tcod.console_rect(console, x, y, width, 1, True, tcod.BKGND_SET)
Ejemplo n.º 10
0
def renderBar(x, y, totalWidth, name, value, max, barColor, backColor):
    barWidth = int(float(value) / max * totalWidth)
    tcod.console_set_default_foreground(panel, backColor)
    tcod.console_rect(panel, x, y, totalWidth, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_background(panel, barColor)
    if barWidth > 0:
        tcod.console_rect(panel, x, y, barWidth, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, x + totalWidth / 2, y, tcod.BKGND_NONE, tcod.CENTER, name + ': ' + str(value) + '/' + str(max))
Ejemplo n.º 11
0
def renderPanel(panel, x, y, totalWidth, name, value, maximum, barColor, backColor):
    barWidth = int(float(value) / maximum * totalWidth)
    tcod.console_set_default_background(panel, backColor)
    tcod.console_rect(panel, x, y, totalWidth, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_background(panel, backColor)
    if barWidth > 0:
        tcod.console_rect(panel, x, y, barWidth, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + totalWidth / 2), y, tcod.BKGND_NONE, tcod.CENTER,
                          '{}: {}/{}'.format(name, value, maximum))
Ejemplo n.º 12
0
def render_bar(panel, x, y, total_width, text, bar_color, back_color):
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(panel, bar_color)

    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y,
                             libtcod.BKGND_NONE, libtcod.CENTER, text)
Ejemplo n.º 13
0
def render_turn_bar(panel, x, y, total_width, name, value, color):

    libtcod.console_set_default_background(panel, color)

    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y,
                             libtcod.BKGND_NONE, libtcod.CENTER,
                             '{0}: {1}'.format(name, value))
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    bar_width = int(float(value) / maximum * total_width)

    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
    
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER, "{0}: {1}/{2}".format(name, value, maximum))
Ejemplo n.º 15
0
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    bar_width = int(float(value)/maximum*total_width)

    tcod.console_set_default_background(panel, back_color)
    tcod.console_rect(panel, x, y, total_width, 1, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + total_width/2), y, tcod.BKGND_NONE, tcod.CENTER, 
                        f'{name}: {value}/{maximum}')
Ejemplo n.º 16
0
def render_bar(panel_con, x, y, total_width, name, value, maximum, bar_color, back_color):
    #Figure out how wide the bar should be
    bar_width = int(float(value) / maximum * total_width)
    #Create the background
    tcod.console_set_default_background(panel_con, back_color)
    tcod.console_rect(panel_con, x, y, total_width, 1, False, tcod.BKGND_SCREEN)
    #Create the bar
    tcod.console_set_default_background(panel_con, bar_color)
    if bar_width > 0:
        tcod.console_rect(panel_con, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)
    #Print the value
    tcod.console_set_default_foreground(panel_con, tcod.white)
    tcod.console_print_ex(panel_con, int(x + total_width / 2), y, tcod.BKGND_NONE, tcod.CENTER, '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 17
0
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    bar_width = int(float(value) / maximum * total_width)
    
    tc.console_set_default_background(panel, back_color)
    tc.console_rect(panel, x, y, total_width, 1, False, tc.BKGND_SCREEN)
    
    tc.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        tc.console_rect(panel, x, y, bar_width, 1, False, tc.BKGND_SCREEN)
    
    tc.console_set_default_foreground(panel, tc.white)
    tc.console_print_ex(panel, int(x + total_width/2), y, tc.BKGND_NONE, tc.CENTER,
                        '{0}: {1}%'.format(name, int(100 * value / maximum)))
Ejemplo n.º 18
0
def render_enemy_bar(panel, x, y, total_width, name, value, maximum, bar_colour, bg_colour):
    bar_width = int(float(value) / maximum * total_width)

    tcod.console_set_default_background(panel, bg_colour)
    tcod.console_rect(panel, x, y, total_width, 2, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_background(panel, bar_colour)
    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 2, False, tcod.BKGND_SCREEN)
    
    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + total_width / 2), y, tcod.BKGND_NONE, tcod.CENTER, '{0}'.format(name))
    tcod.console_print_ex(panel, int(x + total_width / 2), y + 1, tcod.BKGND_NONE, tcod.CENTER, '{0}/{1}'.format(value, maximum))
Ejemplo n.º 19
0
    def render_bar(self, x, y, name, value, maximum):
        bar_width = int(float(value) / maximum * self.panel_width)

        self.panel_buffer.default_bg = self.back_color
        tcod.console_rect(self.panel_buffer, x, y, self.panel_width, 1, False,
                          tcod.BKGND_SCREEN)

        self.panel_buffer.default_bg = self.bar_color
        if bar_width > 0:
            self.panel_buffer.rect(x, y, bar_width, 1, False,
                                   tcod.BKGND_SCREEN)

        self.panel_buffer.default_fg = tcod.white
        health_text = '{0}: {1}/{2}'.format(name, value, maximum)
        tcod.console_print_ex(self.panel_buffer, int(x + self.panel_width / 2),
                              y, tcod.BKGND_NONE, tcod.CENTER, health_text)
def render_bar(panel, x, y, total_width, name, value, maximum, bar_colour,
               back_colour):
    """ Render bar for stat. eg Health"""
    bar_width = int(float(value) / maximum * total_width)

    tcod.console_set_default_background(panel, back_colour)
    tcod.console_rect(panel, x, y, total_width, 1, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_background(panel, bar_colour)
    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + total_width / 2), y, tcod.BKGND_NONE,
                          tcod.CENTER,
                          '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 21
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar, first calculate width
    bar_width = int(float(value) / maximum * total_width)

    #render background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    #render bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
    
    #some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width / 2, y, libtcod.BKGND_NONE, libtcod.CENTER, name + ': ' + str(value) + '/' + str(maximum))
Ejemplo n.º 22
0
Archivo: main.py Proyecto: Jipes/TYRMA
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)

    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.black)
    libtcod.console_print_ex(panel, x + int(total_width/2), y, libtcod.BKGND_NONE, libtcod.CENTER,
        name + ': ' + str(value) + '/' + str(maximum))
Ejemplo n.º 23
0
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    # figures out how much of bar should be 'full'. accounts for bars that arent the same width as the max value. in that case a bar would 'empty' proportionally
    bar_width = int(float(value) / maximum * total_width)

    # Draws the whole bar with the background color
    tcod.console_set_default_background(panel, back_color)
    tcod.console_rect(panel, x, y, total_width, 1, False, tcod.BKGND_SCREEN)

    # draws the 'full' portion of the bar over the background bar. this gives an 'emptying' sort of effect
    tcod.console_set_default_background(panel, bar_color)
    if (bar_width > 0):
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)

    # draws text in the middle of the bar that shows numeric values and the name of the bar
    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + total_width / 2), y, tcod.BKGND_NONE, tcod.CENTER, f'{name}: {value}/{maximum}')
Ejemplo n.º 24
0
def desenhar_barra(panel, x, y, total_largura, nome, valor, maximo, cor,
                   cor_fundo):
    largura_barra = int(float(valor) / maximo * total_largura)

    libtcod.console_set_default_background(panel, cor_fundo)
    libtcod.console_rect(panel, x, y, total_largura, 1, False,
                         libtcod.BKGND_SCREEN)

    libtcod.console_set_default_background(panel, cor_fundo)
    if largura_barra > 0:
        libtcod.console_rect(panel, x, y, largura_barra, 1, False,
                             libtcod.BKGND_SCREEN)

    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_largura / 2), y,
                             libtcod.BKGND_NONE, libtcod.CENTER,
                             '{0}: {1}/{2}'.format(nome, valor, maximo))
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) // maximum * total_width)
 
    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)
 
    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
 
    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width // 2, y, libtcod.BKGND_NONE, libtcod.CENTER,
        name + ': ' + str(value) + '/' + str(maximum))
Ejemplo n.º 26
0
def render_debugbar(panel, x, y, total_width,current_speed,entities,player,game_state):
    status="["+str(player.x)+","+str(player.y)+"] "+str(current_speed) + " "+str(game_state.value)
    libtcod.console_set_default_background(panel, libtcod.darkest_chartreuse)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)    
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x+1, y, libtcod.BKGND_NONE, libtcod.LEFT, status) 
    ghost_count=0
    for entity in entities:
        if entity.ai:
            ghost_count += 1
            ghoststatus = entity.char + entity.ai.last_action
            if entity.ai.target:
                ghoststatus = ghoststatus + " [" + str(entity.ai.target.x) +","+ str(entity.ai.target.y) +"]"
            libtcod.console_set_default_background(panel, libtcod.darkest_chartreuse)
            libtcod.console_rect(panel, x, y+ghost_count, total_width, 1, False, libtcod.BKGND_SCREEN)    
            libtcod.console_set_default_foreground(panel, libtcod.white)
            libtcod.console_print_ex(panel, x+1, y + ghost_count, libtcod.BKGND_NONE, libtcod.LEFT, ghoststatus)             
Ejemplo n.º 27
0
def render_overlay(panel, message):
    x_size=   constants['overlay_size'][0]
    y_size=   constants['overlay_size'][1]
    colors=   constants['colors']
    
    libtcod.console_set_default_background(panel, colors.get('overlay_bkg'))
    libtcod.console_rect(panel, 0, 0, x_size, y_size, False, libtcod.BKGND_SCREEN)
    libtcod.console_set_default_foreground(panel, colors.get('overlay_border'))
    border_h="+"+"-"*(x_size-2)+"+"
    border_v="|"+" "*(x_size-2)+"|"
    libtcod.console_print_ex(panel, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT, border_h)  
    for i in range(1,y_size-1):
            libtcod.console_print_ex(panel, 0, i, libtcod.BKGND_NONE, libtcod.LEFT, border_v)
    libtcod.console_print_ex(panel, 0, y_size-1, libtcod.BKGND_NONE, libtcod.LEFT, border_h)
    
    libtcod.console_set_default_foreground(panel, colors.get('overlay_text'))
    libtcod.console_print_ex(panel, int(x_size/2), int(y_size/2), libtcod.BKGND_NONE, libtcod.CENTER, message)
Ejemplo n.º 28
0
def render_bar(panel, x, y, total_width, name, value, maximum,
               foreground_color, background_color):
    """ Render a bar (HP, XP, etc.). """
    bar_width = int((value / maximum) * total_width)

    # Going to be honest, don't know why it has to be done this way
    tcod.console_set_default_background(panel, background_color)
    tcod.console_rect(panel, x, y, total_width, 1, False, tcod.BKGND_SCREEN)
    tcod.console_set_default_background(panel, foreground_color)

    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)

    tcod.console_set_default_foreground(panel, tcod.white)
    tcod.console_print_ex(panel, int(x + total_width / 2), y, tcod.BKGND_NONE,
                          tcod.CENTER,
                          "{0}: {1}/{2}".format(name, value, maximum))
Ejemplo n.º 29
0
    def render_bar(self, x, y, name, value, maximum, bar_color, back_color):
        panel = self.panel
        total_width = panel_vars.bar_width
        bar_width = int(float(value) / maximum * total_width)

        panel.default_bg = back_color
        tcod.console_rect(panel, x, y, total_width, 1, False,
                          tcod.BKGND_SCREEN)
        panel.default_bg = bar_color
        if bar_width > 0:
            tcod.console_rect(panel, x, y, bar_width, 1, False,
                              tcod.BKGND_SCREEN)

        panel.default_fg = tcod.white
        tcod.console_print_ex(panel, int(x + total_width / 2), y,
                              tcod.BKGND_NONE, tcod.CENTER,
                              '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 30
0
def render_bar(
    panel: libtcod.console.Console,
    x: int,
    y: int,
    total_width: int,
    label: str,
    val: int,
    maximum: int,
    fg_color: libtcod.Color,
    bg_color: libtcod.Color,
):
    """UI Bar rendering function
    
    Arguments:
        panel {libtcod.console.Console} -- Target console to draw the bar
        x {int} -- x position
        y {int} -- y position
        total_width {int} -- total desired width
        label {str} -- label for the bar
        val {int} -- current value for the bar
        maximum {int} -- maximum expected value for the bar
        fg_color {libtcod.Color} -- foreground color
        bg_color {libtcod.Color} -- background color
    """
    bar_width = int(val / maximum * total_width)

    # Render bar
    libtcod.console_set_default_background(panel, bg_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)
    libtcod.console_set_default_background(panel, fg_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False,
                             libtcod.BKGND_SCREEN)

    # Render text
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(
        panel,
        int(x + total_width / 2),
        y,
        libtcod.BKGND_NONE,
        libtcod.CENTER,
        f"{label}: {val}/{maximum}",
    )
Ejemplo n.º 31
0
def render_bar(panel: tcod.console.Console, x: int, y: int, total_width: int,
               name: str, value: int, maximum: int,
               bar_colour: tcod.color.Color, back_colour: tcod.color.Color):
    bar_width = int(float(value) / maximum * total_width)

    panel.default_bg = back_colour
    panel.rect(x, y, total_width, 1, False, tcod.BKGND_SCREEN)

    panel.default_bg = bar_colour
    if bar_width > 0:
        tcod.console_rect(panel, x, y, bar_width, 1, False, tcod.BKGND_SCREEN)
        panel.rect(x, y, bar_width, 1, False, tcod.BKGND_SCREEN)

    panel.default_fg = tcod.white
    panel.print_(int(x + total_width / 2), y,
                 '{0}: {1}/{2}'.format(name, value,
                                       maximum), tcod.BKGND_NONE, tcod.CENTER)
    return
Ejemplo n.º 32
0
 def draw_rect(self, x, y, w, h, clear=False, flag=tcod.BKGND_NONE):
     tcod.console_rect(self._c, x, y, w, h, clear, flag)
Ejemplo n.º 33
0
def test_console_rect(console):
    libtcodpy.console_rect(console, 0, 0, 4, 4, False, libtcodpy.BKGND_SET)