Beispiel #1
0
def menu(con, 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) + 1
    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height + 1)
    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    #libtcod.console_print_rect_ex(window, 1, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
    libtcod.console_print_frame(window,
                                0,
                                0,
                                width,
                                height + 1,
                                fmt="Inventory")
    # print all the options
    y = 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 1, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1
    # blit the contents of "window" to the root console
    x = int(CAMERA_WIDTH / 2 - width / 2)
    y = int(CAMERA_HEIGHT / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height + 1, 0, x, y, 1.0, 0.7)
Beispiel #2
0
 def draw(self, message_log):
     tcod.console_set_default_foreground(self.con, tcod.white)
     # tcod.console_clear(self.con)
     tcod.console_print_frame(self.con,
                              0,
                              0,
                              self.con.width,
                              self.con.height,
                              clear=True,
                              fmt=self.name)
     if self.name == 'log':
         # Print the game messages, one line at a time
         y = 1
         for message in message_log.messages:
             tcod.console_set_default_foreground(self.con, message.color)
             tcod.console_print_ex(self.con, message_log.x, y,
                                   tcod.BKGND_NONE, tcod.LEFT, message.text)
             y += 1
     elif self.name == 'sidebar':
         y = 1
         tcod.console_set_default_foreground(self.con, tcod.yellow)
         tcod.console_print_ex(self.con, 1, y, tcod.BKGND_NONE, tcod.LEFT,
                               "i")
         tcod.console_set_default_foreground(self.con, tcod.light_blue)
         tcod.console_print_ex(self.con, 2, y, tcod.BKGND_NONE, tcod.LEFT,
                               "nventory")
     tcod.console_blit(self.con, 0, 0, self.con.width, self.con.height, 0,
                       self.x, self.y)
Beispiel #3
0
 def draw(self, target_console):
     """Updates and blits the windows's console buffer to another console."""
     tcod.console_print_frame(self.console, 0, 0, self.w, self.h, True, tcod.BKGND_DEFAULT)
     for index in range (len(self.contents)):
         tcod.console_print(self.console, 3, index+2, self.contents[index])
     tcod.console_put_char_ex(self.console, 2, self.selection+2, '>', tcod.white, tcod.black)
     tcod.console_blit(self.console, 0, 0, self.w, self.h, target_console, self.x, self.y, 1.0, 0.9)
    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
Beispiel #5
0
 def print_frame(self, x, y, width, height, clear=True,
                 flag=tcod.BKGND_DEFAULT, fmt=0):
     """Draw a rectangle with size `width` and `height` located at
     position (x, y).
     """
     tcod.console_print_frame(self._c, x, y,
                              width, height,
                              clear, flag, fmt)
Beispiel #6
0
 def print_frame(self,
                 x,
                 y,
                 width,
                 height,
                 clear=True,
                 flag=tcod.BKGND_DEFAULT,
                 fmt=0):
     """Draw a rectangle with size `width` and `height` located at
     position (x, y).
     """
     tcod.console_print_frame(self._c, x, y, width, height, clear, flag,
                              fmt)
    def _render_creature_details(self, creature: Creature, x: int, y: int, include_health_values: bool=False):
        """
            Renders the creature box for the defending creature.
        """
        height = BattleRenderer.creature_details_height_w_hp if include_health_values else BattleRenderer.creature_details_height_no_hp

        libtcod.console_set_default_foreground(self.console, settings.BATTLE_TEXT_COLOR)
        libtcod.console_print_frame(self.console, x, y, BattleRenderer.creature_details_width, height)
        libtcod.console_print(self.console, x + 1, y + 1, creature.nickname[:10])
        libtcod.console_print(self.console, x + BattleRenderer.creature_details_width - 6, y + 1, "LV.{0}".format(creature.level))
        
        self._render_health_bar(creature, BattleRenderer.creature_details_width - 2, x + 1, y + 3)
        if include_health_values:
            self._render_health_values(creature, x + BattleRenderer.creature_details_width - 8, y + 5)
Beispiel #8
0
def main_menu(options, width, title):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')
    height = len(options) + 1
    window = libtcod.console_new(width, height + 1)
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_frame(window, 0, 0, width, height + 1, fmt=title)
    y = 1
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        #libtcod.console_set_default_background(window, libtcod.red)
        libtcod.console_print_ex(window, 1, y, libtcod.BKGND_OVERLAY,
                                 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 + 1, 0, x, y, 1.0, 0.7)
    def _render_details_box(self, species, status):
        """
            If a pokemon has been selected then this is called to display a 
            box with the specific details as an overlay on top of the pokedex.
        """
        libtcod.console_set_default_foreground(self.console, settings.POKEDEX_LINE_COLOR)
        libtcod.console_print_frame(self.console, 19, 15, 43, 16)  # TODO: Generalise to widths
        
        libtcod.console_print(self.console, 23, 16, u"No. {0.pokedex_number:0=3d}  {0.name}".format(species))

        if status == 2:
            libtcod.console_print(self.console, 23, 17, u"  {0.genus} Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, u"Type(s): {0}".format(', '.join(str(t) for t in species.types)))
            libtcod.console_print(self.console, 23, 19, "Height: {0}".format(species.imperial_height_str()))
            libtcod.console_print(self.console, 23, 20, "Weight: {0}".format(species.imperial_weight_str()))
            
            libtcod.console_print_rect(self.console, 20, 22, 41, 14, species.flavor_text)
        elif status == 1:
            libtcod.console_print(self.console, 23, 17, "  ????? Pokemon".format(species))
            libtcod.console_print(self.console, 23, 18, "Type(s): ?????")
            libtcod.console_print(self.console, 23, 19, "Height: ??'??\"")
            libtcod.console_print(self.console, 23, 20, "Weight: ????.? lbs.")
def test_console_print_frame(console):
    libtcodpy.console_print_frame(console, 0, 0, 9, 9)
Beispiel #11
0
def test_console_print_frame(console):
    libtcodpy.console_print_frame(console, 0, 0, 9, 9)
 def _render_blank_message_box(self, x: int, y: int, width: int, height: int):
     """
         Utility function to render the box in which messages go.
     """
     libtcod.console_print_frame(self.console, x, y, width, height)
 def _render_lines(self):
     """
         Renders the border.
     """
     libtcod.console_print_frame(self.console, 1, 1, LevelUpRenderer.width - 2, LevelUpRenderer.height - 2)
Beispiel #14
0
 def frame(self, x, y, w, h, text, clear=True, flag=tcod.BKGND_NONE):
     tcod.console_print_frame(self._c, x, y, w, h, clear, flag, text)
Beispiel #15
0
 def frame(self, x, y, w, h, text, clear=True, flag=tcod.BKGND_NONE):
     tcod.console_print_frame(self._c, x, y, w, h, clear, flag, text)