Exemplo n.º 1
0
def print_lyrics(panel, lyrics, active_character):
    primary_color = tcod.sea
    primary_color_dark = tcod.darkest_sea

    tcod.console_set_default_foreground(panel, primary_color)
    tcod.console_set_default_background(panel, tcod.black)

    tcod.console_set_color_control(tcod.COLCTRL_1, primary_color_dark,
                                   tcod.black)
    tcod.console_set_color_control(tcod.COLCTRL_2, tcod.black, primary_color)

    lyrics_pre_active = '%c{}%c'.format(
        lyrics[:active_character]) % (tcod.COLCTRL_1, tcod.COLCTRL_STOP)
    lyrics_active = '%c{}%c'.format(
        lyrics[active_character]) % (tcod.COLCTRL_2, tcod.COLCTRL_STOP)
    lyrics_post_active = lyrics[active_character + 1:]
    formatted_lyrics = lyrics_pre_active + lyrics_active + lyrics_post_active

    x = int(tcod.console_get_width(panel) / 2)
    y = 1
    w = tcod.console_get_width(panel) - 8
    h = tcod.console_get_height(panel)

    tcod.console_print_rect_ex(panel, x, y, w, h, tcod.BKGND_SET, tcod.CENTER,
                               formatted_lyrics)
Exemplo n.º 2
0
    def attack(self, target):
        """Calculate damage and return combat message."""
        results = []

        damage = self.power - target.fighter.defense

        libtcod.console_set_color_control(libtcod.COLCTRL_4, libtcod.red,
                                          libtcod.black)

        if damage > 0:
            results.append({
                'message':
                Message(
                    '{0} attacks {1} for {2} hit points.'.format(
                        self.owner.name.capitalize(), target.name,
                        str(damage)), libtcod.lightest_sepia)
            })
            results.extend(target.fighter.take_damage(damage))
        else:
            results.append({
                'message':
                Message(
                    '{0} attacks {1} but does no damage.'.format(
                        self.owner.name.capitalize(), target.name),
                    libtcod.lightest_sepia)
            })

        return results
Exemplo n.º 3
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green,
                                      libtcod.black)
    libtcod.console_print(
        stat_con, 1, 1, "Position: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2,
                          "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(
        stat_con, 1, 5, "Mouse: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy,
         libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7,
                          "Current depth: " + str(current_depth))
    libtcod.console_print(
        stat_con, 1, 10,
        "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") %
                               (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def character_screen(player, character_screen_width, character_screen_height,
                     screen_width, screen_height, colors):
    """Show character_screen with basic information."""
    window = libtcod.console_new(character_screen_width,
                                 character_screen_height)

    libtcod.console_set_default_foreground(window, colors['text_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_1,
                                      colors['text_info_alt'], libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2,
                                      colors['text_emphasize'], libtcod.black)

    heading = f'%cCharacter Information%c' % (libtcod.COLCTRL_2,
                                              libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 1, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, heading)

    player_level = f'Level: %c{player.level.current_level}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_level)

    player_experience = f'Experience: %c{player.level.current_xp}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_experience)

    player_experience_to_next_level = f'Experience to level: %c{player.level.experience_to_next_level}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  player_experience_to_next_level)

    player_maximum_hp = f'Maximum HP: %c{player.fighter.max_hp}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_maximum_hp)

    player_attack = f'Attack: %c{player.fighter.power}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_attack)

    player_defense = f'Defense: %c{player.fighter.defense}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_defense)

    x = int(screen_width / 2 - character_screen_width / 2)
    y = int(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)
Exemplo n.º 6
0
def print_season_overview(con, panel_width, season):
    tcod.console_clear(con)
    LINE_LENGTH = 50
    # Print team standings

    top_line = 2
    if (season.current_race >= len(season.circuits)):
        winner = None
        # Ugly way to get winner
        for team, points in season.get_ordered_standings().items():
            winner = team
            break

        win_text = '!!! ' + winner.name + ' WINS THE ' + str(
            season.year) + ' SEASON !!!'
        tcod.console_print_ex(con, int(panel_width / 2), 2, tcod.BKGND_SET,
                              tcod.CENTER, win_text)
        top_line = 6

    header = 'Team' + (' ' * (LINE_LENGTH - 10)) + 'Points'
    underline = '=' * LINE_LENGTH
    tcod.console_print_ex(con, int(panel_width / 2), top_line + 0,
                          tcod.BKGND_SET, tcod.CENTER, header)
    tcod.console_print_ex(con, int(panel_width / 2), top_line + 1,
                          tcod.BKGND_SET, tcod.CENTER, underline)

    place = 1
    for team, points in season.get_ordered_standings().items():
        place_name = str(place) + '. ' + team.name
        point_string = str(points)
        space_count = LINE_LENGTH - (len(place_name) + len(point_string))
        line = place_name + (' ' * space_count) + point_string
        tcod.console_print_ex(con, int(panel_width / 2), 1 + top_line + place,
                              tcod.BKGND_SET, tcod.CENTER, line)
        place += 1

    # Print inidividual races.

    # For the highlighted next race
    tcod.console_set_color_control(tcod.COLCTRL_1, tcod.darker_sea,
                                   tcod.light_azure)

    tcod.console_print_ex(con, int(panel_width / 2), 0, tcod.BKGND_SET,
                          tcod.CENTER,
                          str(season.year) + " SEASON")
    overview = season.get_overview()
    for x in range(0, len(overview)):
        race_name = overview[x][0]
        winner_name = "TBD"
        if (x < season.current_race):
            winner_name = season.get_winner(season.races[x]).name
        spaces = panel_width - len(race_name) - len(winner_name)
        full_line = race_name + (' ' * spaces) + winner_name
        if x == season.current_race:
            full_line = '%c{}%c'.format(full_line) % (tcod.COLCTRL_1,
                                                      tcod.COLCTRL_STOP)
        tcod.console_print_ex(con, 0, x * 2 + top_line + 10, tcod.BKGND_SET,
                              tcod.LEFT, full_line)
Exemplo n.º 7
0
def character_sheet_attributes(con, width, height):
	character_sheet_ui(con, width, height, ' Player stats ')
	libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.green, libtcod.black)
	libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.red, libtcod.black)
	libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.gold, libtcod.black)
	libtcod.console_set_color_control(libtcod.COLCTRL_4, libtcod.silver, libtcod.black)
	libtcod.console_set_color_control(libtcod.COLCTRL_5, libtcod.copper, libtcod.black)
	libtcod.console_print(con, 2, 2, game.player.name + ', a level ' + str(game.player.level) + ' ' + game.player.gender + ' ' + game.player.race + ' ' + game.player.profession)
	g, s, c = util.convert_coins(game.player.money)

	if game.player.strength > game.player.base_strength:
		libtcod.console_print(con, 2, 4, 'Strength     : %c%i%c' % (libtcod.COLCTRL_1, game.player.strength, libtcod.COLCTRL_STOP))
	elif game.player.strength < game.player.base_strength:
		libtcod.console_print(con, 2, 4, 'Strength     : %c%i%c' % (libtcod.COLCTRL_2, game.player.strength, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(con, 2, 4, 'Strength     : ' + str(game.player.strength))

	if game.player.dexterity > game.player.base_dexterity:
		libtcod.console_print(con, 2, 5, 'Dexterity    : %c%i%c' % (libtcod.COLCTRL_1, game.player.dexterity, libtcod.COLCTRL_STOP))
	elif game.player.dexterity < game.player.base_dexterity:
		libtcod.console_print(con, 2, 5, 'Dexterity    : %c%i%c' % (libtcod.COLCTRL_2, game.player.dexterity, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(con, 2, 5, 'Dexterity    : ' + str(game.player.dexterity))

	if game.player.intelligence > game.player.intelligence:
		libtcod.console_print(con, 2, 6, 'Intelligence : %c%i%c' % (libtcod.COLCTRL_1, game.player.intelligence, libtcod.COLCTRL_STOP))
	elif game.player.intelligence < game.player.intelligence:
		libtcod.console_print(con, 2, 6, 'Intelligence : %c%i%c' % (libtcod.COLCTRL_2, game.player.intelligence, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(con, 2, 6, 'Intelligence : ' + str(game.player.intelligence))

	if game.player.wisdom > game.player.wisdom:
		libtcod.console_print(con, 2, 7, 'Wisdom       : %c%i%c' % (libtcod.COLCTRL_1, game.player.wisdom, libtcod.COLCTRL_STOP))
	elif game.player.wisdom < game.player.wisdom:
		libtcod.console_print(con, 2, 7, 'Wisdom       : %c%i%c' % (libtcod.COLCTRL_2, game.player.wisdom, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(con, 2, 7, 'Wisdom       : ' + str(game.player.wisdom))

	if game.player.endurance > game.player.endurance:
		libtcod.console_print(con, 2, 8, 'Endurance    : %c%i%c' % (libtcod.COLCTRL_1, game.player.endurance, libtcod.COLCTRL_STOP))
	elif game.player.endurance < game.player.endurance:
		libtcod.console_print(con, 2, 8, 'Endurance    : %c%i%c' % (libtcod.COLCTRL_2, game.player.endurance, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(con, 2, 8, 'Endurance    : ' + str(game.player.endurance))

	libtcod.console_print(con, 2, 9, 'Karma        : ' + str(game.player.karma))
	libtcod.console_print(con, 30, 4, 'Health     : ' + str(game.player.health) + ' / ' + str(game.player.max_health))
	libtcod.console_print(con, 30, 5, 'Stamina    : ' + str(game.player.stamina) + ' / ' + str(game.player.max_stamina))
	libtcod.console_print(con, 30, 6, 'Mana       : ' + str(game.player.mana) + ' / ' + str(game.player.max_mana))
	libtcod.console_print(con, 30, 7, 'Experience : ' + str(game.player.xp))
	libtcod.console_print(con, 30, 8, 'Coins      : %c%s%c%c%c%c%i %c%s%c%c%c%c%i %c%s%c%c%c%c%i%c' % (libtcod.COLCTRL_3, chr(23), libtcod.COLCTRL_FORE_RGB, 255, 255, 255, g, libtcod.COLCTRL_4, chr(23), libtcod.COLCTRL_FORE_RGB, 255, 255, 255, s, libtcod.COLCTRL_5, chr(23), libtcod.COLCTRL_FORE_RGB, 255, 255, 255, c, libtcod.COLCTRL_STOP))
	libtcod.console_print(con, 2, 11, 'Attack Rating     : ' + str(game.player.attack_rating()))
	libtcod.console_print(con, 2, 12, 'Defense Rating    : ' + str(game.player.defense_rating()))
	libtcod.console_print(con, 2, 13, 'Carrying Capacity : ' + str(game.player.weight_carried()) + ' / ' + str(game.player.max_carrying_capacity()) + ' lbs')
Exemplo n.º 8
0
def init():
    # init window
    font = os.path.join(b'resources', b'consolas10x10_gs_tc.png')
    libtcod.console_set_custom_font(font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(SCREEN_SIZE.x, SCREEN_SIZE.y, b'DalekRL')
    libtcod.sys_set_fps(LIMIT_FPS)

    # set default text palette # TODO: merge with UI class statics
    libtcod.console_set_color_control(libtcod.COLCTRL_1,libtcod.red,libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2,libtcod.dark_yellow,libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_3,libtcod.light_green,libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_4,libtcod.light_blue,libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_5,libtcod.purple,libtcod.black)
Exemplo n.º 9
0
def equipment_menu(con, header, player, equipment_menu_width, screen_width,
                   screen_height, colors):
    """Show what items the player has equipped on the equipment slots."""
    header_height = libtcod.console_get_height_rect(con, 0, 0,
                                                    equipment_menu_width,
                                                    screen_height, header)
    height = header_height + 10

    window = libtcod.console_new(equipment_menu_width, height)

    libtcod.console_set_default_foreground(window, colors['text_default'])

    libtcod.console_set_color_control(libtcod.COLCTRL_1,
                                      colors['text_emphasize'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_2,
                                      colors['text_desaturate'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_3, colors['text_info'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_4,
                                      colors['text_info_alt'],
                                      colors['background_default'])

    slots = [(player.equipment.main_hand, 'Main hand'),
             (player.equipment.off_hand, 'Off hand'),
             (player.equipment.torso, 'Torso'),
             (player.equipment.head, 'Head'), (player.equipment.coat, 'Coat'),
             (player.equipment.ring_l, 'Ring (left)'),
             (player.equipment.ring_r, 'Ring (right)'),
             (player.equipment.special, 'Special')]

    libtcod.console_print_rect_ex(window, 0, 1, equipment_menu_width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    line = header_height + 1
    letter_index = ord('a')

    for slot, slot_desc in slots:
        equippable_name = '%cEmpty.%c' % (libtcod.COLCTRL_2,
                                          libtcod.COLCTRL_STOP)
        index_prefix = f'%c({chr(letter_index)})%c' % (libtcod.COLCTRL_1,
                                                       libtcod.COLCTRL_STOP)

        if slot is not None:
            equippable_name = f'%c{slot.name} %c{slot.equippable}%c' % (
                libtcod.COLCTRL_3, libtcod.COLCTRL_4, libtcod.COLCTRL_STOP)
            equippable_stats = str(slot.equippable)

        libtcod.console_print_rect_ex(
            window, 0, line, equipment_menu_width, height, libtcod.BKGND_NONE,
            libtcod.LEFT, '{0}{1}: {2}'.format(index_prefix, slot_desc,
                                               equippable_name))
        line += 1
        letter_index += 1

    x = int(screen_width / 2 - equipment_menu_width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, equipment_menu_width, height, 0, x, y,
                         1.0, 0.7)
Exemplo n.º 10
0
def do_render():
    y = 1
    for c in range(list_cam, min(list_size + list_cam, len(category_list))):
        if c == select:
            libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.cyan, libtcod.blue)
        else:
            libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.white, libtcod.black)
        if len(category_list[c].name) > 17:
            s = category_list[c].name[:17]
        else:
            s = category_list[c].name
        libtcod.console_print(0, 1, y, "{:c}{}{:c}".format(libtcod.COLCTRL_1, s, libtcod.COLCTRL_STOP))
        y += 1
    libtcod.console_blit(result_display, 0, 0, RESULT_W, RESULT_H, 0, 18, 1)
Exemplo n.º 11
0
def character_sheet_inventory(con, width, height):
	character_sheet_ui(con, width, height, ' Inventory ')
	libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.gray, libtcod.black)
	output = util.item_stacking(game.player.inventory)
	for i in range(len(output)):
		text_left = output[i].get_name()
		if output[i].duration > 0:
			text_left += ' (' + str(output[i].duration) + ' turns left)'
		text_right = str(round(output[i].weight * output[i].quantity, 1)) + ' lbs'
		if output[i].is_identified() and output[i].quality == 0:
			libtcod.console_print(con, 2, i + 2, '%c%s%c' % (libtcod.COLCTRL_1, text_left, libtcod.COLCTRL_STOP))
			libtcod.console_print_ex(con, width - 3, i + 2, libtcod.BKGND_SET, libtcod.RIGHT, '%c%s%c' % (libtcod.COLCTRL_1, text_right, libtcod.COLCTRL_STOP))
		else:
			libtcod.console_print(con, 2, i + 2, text_left)
			libtcod.console_print_ex(con, width - 3, i + 2, libtcod.BKGND_SET, libtcod.RIGHT, text_right)
	util.reset_quantity(game.player.inventory)
Exemplo n.º 12
0
    def apply(self, console=None):
        """
        Call this before rendering a string that wants to use the color pairs
        defined in this ColorSet. If you provide a console, the console's fore-
        and background will be set to the default colors.
        """
        if console:
            console.set_default_foreground(self.fgcolor)
            console.set_default_background(self.bgcolor)

        for color_code, colors in self.colors.iteritems():
            fgcolor, bgcolor = colors
            if fgcolor is None:
                fgcolor = self.fgcolor
            if bgcolor is None:
                bgcolor = self.bgcolor
            libtcod.console_set_color_control(color_code, fgcolor, bgcolor)
Exemplo n.º 13
0
def menu(con,
         header,
         options,
         width,
         screen_width,
         screen_height,
         colors,
         in_game=True):
    """Show menu window in center of the screen."""
    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 more 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, colors['text_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_1,
                                      colors['text_emphasize'],
                                      colors['background_default'])
    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 = f'%c({chr(letter_index)})%c{option_text}' % (
            libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
        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
    if not in_game:
        x = int(screen_width / 2 - width / 2)
    else:
        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)
Exemplo n.º 14
0
 def print_rec(self, layer):
     libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.turquoise, libtcod.black)
     libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.gray, libtcod.black)
     if not self.hidden:
         libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{:c}{}:{:c}".format(libtcod.COLCTRL_2, self.name, libtcod.COLCTRL_STOP))
         libtcod.console_print(result_display, Category.pc[0], Category.pc[1], "{:c}{}{:c}".format(libtcod.COLCTRL_3, '|' * layer, libtcod.COLCTRL_STOP))
         Category.pc[1] += libtcod.console_get_height_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{:c}{}:{:c}".format(libtcod.COLCTRL_2, self.name, libtcod.COLCTRL_STOP))
     glist = self.get()
     for g in glist:
         libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{}".format(g))
         libtcod.console_print(result_display, Category.pc[0], Category.pc[1], "{:c}{}{:c}".format(libtcod.COLCTRL_3, '|' * layer, libtcod.COLCTRL_STOP))
         Category.pc[1] += libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{}".format(g))
         for s in self.sub:
             s.print_rec(layer + 1)
     if not len(glist):
         for s in self.sub:
             s.print_rec(layer + 1)
Exemplo n.º 15
0
 def render(self,
       draw_frame=False, draw_index=False,
       align='left', fgalpha=.9, bgalpha=.3):
   if len(self.opts) > MAX_OPTS:
     raise ValueError('No more than %d options allowed.' % MAX_OPTS)
   # calculate height, set options window, print header
   _w, _h = self.width+2, self.h+2   #total width and height
   window = tl.console_new(_w, _h)
   tl.console_clear(window)
   tl.console_set_default_background(window, tl.violet)
   tl.console_set_default_foreground(window, tl.lightest_grey)
   if draw_frame: tl.console_print_frame(window, 0, 0, _w, _h)
   tl.console_print_rect_ex(window, 1,1, self.width,self.h, tl.BKGND_NONE,tl.LEFT,
               self.header)
   if self.opts != []:  # draw a separator line if options are not empty
     tl.console_hline(window, 1, self.headerHeight+1, self.width)
     if draw_frame:
       tl.console_put_char(window, 0, self.headerHeight+1, tl.CHAR_TEEE)
       tl.console_put_char(window, self.width+1, self.headerHeight+1, tl.CHAR_TEEW)
     # print all options
     n,y = 0,self.headerHeight+2
     sel = self.highlightedItemIdx if self.highlightedItemIdx >= 0 else MAX_OPTS+self.highlightedItemIdx
     for txt in self.opts:
       txt = txt.rjust(self.width) if align=='right'\
         else txt.center(self.width) if align=='center'\
         else '   '+txt.ljust(self.width)[:-3] if draw_index\
         else txt.ljust(self.width)
       if draw_index:
         txt = ' %d %s' % (n, txt)
         txt = '{'+txt[1]+'}'+txt[6:] if sel == n else txt[3:]
       scolor = 'amber' if sel == n else 'light_grey'
       if self.isAnimated and sel == n:
         # hicky-hacky color animation
         scolor = tl.amber*(self.phase/PHASES)
         tl.console_set_color_control(tl.COLCTRL_1, scolor, tl.black)
         txt = '%c%s%c'%(tl.COLCTRL_1,txt.ljust(self.width),tl.COLCTRL_STOP)
       else:
         txt = tc.parse('{{%s}}%s{{stop}}'%(scolor,txt.ljust(self.width)))
       tl.console_print(window, 1, y, txt)
       n += 1; y += 1
   # calculate window position, blit window to screen & flush
   x = SCREEN_W/2 - self.width/2
   y = SCREEN_H/2 - self.h/2
   tl.console_blit(window, 0, 0, _w, _h, 0, x, y, fgalpha, bgalpha)
Exemplo n.º 16
0
def init():
    # init window
    font = os.path.join(b'resources', b'consolas10x10_gs_tc.png')
    libtcod.console_set_custom_font(
        font, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(SCREEN_SIZE.x, SCREEN_SIZE.y, b'DalekRL')
    libtcod.sys_set_fps(LIMIT_FPS)

    # set default text palette # TODO: merge with UI class statics
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.dark_yellow,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.light_green,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_4, libtcod.light_blue,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_5, libtcod.purple,
                                      libtcod.black)
Exemplo n.º 17
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red, libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green, libtcod.black)
    libtcod.console_print(stat_con, 1, 1,
                          "Position: %c(%s, %s)%c" % (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2, "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(stat_con, 1, 5, "Mouse: %c(%s, %s)%c" % (
        libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7, "Current depth: " + str(current_depth))
    libtcod.console_print(stat_con, 1, 10, "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
Exemplo n.º 18
0
def inventory_menu(con, header, player, inventory_width, screen_width,
                   screen_height, colors):
    """Show a menu with each item of the inventory as an option."""
    if len(player.inventory.items) == 0:
        options = ['Inventory is empty.']
    else:
        options = []

        for item in player.inventory.items:
            if item in player.equipment.equipped:
                libtcod.console_set_color_control(libtcod.COLCTRL_3,
                                                  colors['text_desaturate'],
                                                  colors['background_default'])
                options.append(f'%c{item.name} (equipped)%c' %
                               (libtcod.COLCTRL_3, libtcod.COLCTRL_STOP))
            else:
                libtcod.console_set_color_control(libtcod.COLCTRL_2,
                                                  colors['text_default'],
                                                  colors['background_default'])
                options.append(f'%c{item.name}%c' %
                               (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))

    menu(con, header, options, inventory_width, screen_width, screen_height,
         colors)
Exemplo n.º 19
0
Arquivo: ui.py Projeto: ajare/citadel
    def render(self, entity):
        """Renders an entity's inventory in the given window.
        
        Arguments:
        entity - the entity whose inventory you want to render
        
        """
        # Background
        libtcod.console_set_default_background(0, libtcod.black)
        libtcod.console_set_default_foreground(0, libtcod.black)
        libtcod.console_rect(0, self.x_offset, self.y_offset, self.width, self.height, True, libtcod.BKGND_SET)
        
        libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_print(0, self.x_offset + 1, self.y_offset + 1, entity.name)
        
        if entity.inventory is None:
            libtcod.console_print(0, self.x_offset + 1, self.y_offset + 3, "This entity has no inventory.  %s" % DEBUG_MSG)
        else:
            char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
            
            # Draw actions text - highlight the selected one
            libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.blue, libtcod.black)
            libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.blue, libtcod.white)
            libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.black, libtcod.white)

            action_text = "%cU%cse%c   %cD%crop%c   %cT%chrow%c   %cC%consume%c   %cE%cquip%c   %cW%cear%c"
            action_text_format = [libtcod.COLCTRL_1, libtcod.COLCTRL_STOP, libtcod.COLCTRL_STOP] * 6
            if self.action_filter is not None:
                index = ["use", "drop", "throw", "consume", "equip", "wear"].index(self.action_filter)
                action_text_format[index * 3 + 0] = libtcod.COLCTRL_2
                action_text_format[index * 3 + 1] = libtcod.COLCTRL_3
                          
            action_text = action_text % tuple(action_text_format)
            libtcod.console_print(0, self.x_offset + 1, self.y_offset + 3, action_text)
            
            # Set up screen offsets for rendering
            lcol = self.x_offset + 1
            rcol = self.x_offset + 25
            lrow = rrow = self.y_offset + 5
        
            # In the case of no items, render_types will return 0, but still render a line (none) - so we need to
            # take this line into account when adjusting offsets.
            char_index      = 0
            num_weapons     = self.render_types(entity.inventory, lcol, lrow, EntityType.WEAPON, "WEAPONS", char_list[char_index:])
            lrow           += max(1, num_weapons) + 3
            char_index     += num_weapons
            num_clothing    = self.render_types(entity.inventory, rcol, rrow, EntityType.CLOTHING, "CLOTHING", char_list[char_index:])
            rrow           += max(1, num_clothing) + 3
            char_index     += num_clothing
            num_comestibles = self.render_types(entity.inventory, lcol, lrow, EntityType.COMESTIBLE, "COMESTIBLES", char_list[char_index:])
            lrow           += max(1, num_comestibles) + 3
            char_index     += num_comestibles
            num_medecine    = self.render_types(entity.inventory, rcol, rrow, EntityType.MEDECINE, "MEDECINE", char_list[char_index:])
            rrow           += max(1, num_medecine) + 3
            char_index     += num_medecine
            num_other       = self.render_types(entity.inventory, lcol, lrow, EntityType.OTHER, "OTHER", char_list[char_index:])
Exemplo n.º 20
0
def render_player_stats_panel():
	libtcod.console_set_default_background(game.ps, libtcod.black)
	libtcod.console_clear(game.ps)
	libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.green, libtcod.black)
	libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.red, libtcod.black)
	render_bar(game.ps, 0, 6, game.PLAYER_STATS_WIDTH, 'HP', game.player.health, game.player.max_health, libtcod.red, libtcod.darker_red)
	render_bar(game.ps, 0, 7, game.PLAYER_STATS_WIDTH, 'ST', game.player.stamina, game.player.max_stamina, libtcod.yellow, libtcod.darker_yellow)
	render_bar(game.ps, 0, 8, game.PLAYER_STATS_WIDTH, 'MP', game.player.mana, game.player.max_mana, libtcod.blue, libtcod.darker_blue)
	libtcod.console_print(game.ps, 0, 0, game.player.name)
	libtcod.console_print(game.ps, 0, 1, game.player.race + ' ' + game.player.profession)
	libtcod.console_print(game.ps, 0, 2, 'Level ' + str(game.player.level))
	libtcod.console_print(game.ps, 0, 4, game.current_map.location_abbr + '-' + str(game.current_map.location_level) + '     ')
	libtcod.console_print(game.ps, 0, 10, 'XP: ' + str(game.player.xp))

	if game.player.strength > game.player.base_strength:
		libtcod.console_print(game.ps, 0, 11, 'Str: %c%i%c ' % (libtcod.COLCTRL_1, game.player.strength, libtcod.COLCTRL_STOP))
	elif game.player.strength < game.player.base_strength:
		libtcod.console_print(game.ps, 0, 11, 'Str: %c%i%c ' % (libtcod.COLCTRL_2, game.player.strength, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(game.ps, 0, 11, 'Str: ' + str(game.player.strength) + ' ')

	if game.player.dexterity > game.player.base_dexterity:
		libtcod.console_print(game.ps, 0, 12, 'Dex: %c%i%c ' % (libtcod.COLCTRL_1, game.player.dexterity, libtcod.COLCTRL_STOP))
	elif game.player.dexterity < game.player.base_dexterity:
		libtcod.console_print(game.ps, 0, 12, 'Dex: %c%i%c ' % (libtcod.COLCTRL_2, game.player.dexterity, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(game.ps, 0, 12, 'Dex: ' + str(game.player.dexterity) + ' ')

	if game.player.intelligence > game.player.base_intelligence:
		libtcod.console_print(game.ps, 0, 13, 'Int: %c%i%c ' % (libtcod.COLCTRL_1, game.player.intelligence, libtcod.COLCTRL_STOP))
	elif game.player.intelligence < game.player.base_intelligence:
		libtcod.console_print(game.ps, 0, 13, 'Int: %c%i%c ' % (libtcod.COLCTRL_2, game.player.intelligence, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(game.ps, 0, 13, 'Int: ' + str(game.player.intelligence) + ' ')

	if game.player.wisdom > game.player.base_wisdom:
		libtcod.console_print(game.ps, 0, 14, 'Wis: %c%i%c ' % (libtcod.COLCTRL_1, game.player.wisdom, libtcod.COLCTRL_STOP))
	elif game.player.wisdom < game.player.base_wisdom:
		libtcod.console_print(game.ps, 0, 14, 'Wis: %c%i%c ' % (libtcod.COLCTRL_2, game.player.wisdom, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(game.ps, 0, 14, 'Wis: ' + str(game.player.wisdom) + ' ')

	if game.player.endurance > game.player.base_endurance:
		libtcod.console_print(game.ps, 0, 15, 'End: %c%i%c ' % (libtcod.COLCTRL_1, game.player.endurance, libtcod.COLCTRL_STOP))
	elif game.player.endurance < game.player.base_endurance:
		libtcod.console_print(game.ps, 0, 15, 'End: %c%i%c ' % (libtcod.COLCTRL_2, game.player.endurance, libtcod.COLCTRL_STOP))
	else:
		libtcod.console_print(game.ps, 0, 15, 'End: ' + str(game.player.endurance) + ' ')

	libtcod.console_print(game.ps, 0, 16, 'Karma: ' + str(game.player.karma) + ' ')
	libtcod.console_print(game.ps, 0, game.PLAYER_STATS_HEIGHT - 2, 'Turns: ' + str(game.turns) + ' ')
	libtcod.console_print(game.ps, 0, 18, 'Hunger level: ')
	libtcod.console_print(game.ps, 0, 21, 'Active skills: ')
	libtcod.console_print(game.ps, 0, 24, 'Condition: ')
	libtcod.console_set_default_foreground(game.ps, libtcod.light_sepia)

	for flags in game.player.flags:
		if flags in ['hungry', 'famished', 'starving', 'bloated', 'full', 'normal']:
			libtcod.console_print(game.ps, 0, 19, '%c%c%c%c%s%c' % (libtcod.COLCTRL_FORE_RGB, 115, 255, 115, flags.capitalize(), libtcod.COLCTRL_STOP))

	act_skill = ''
	if 'detect_trap' in game.player.flags:
		act_skill += 'DetectTrap '
	if 'swimming' in game.player.flags:
		act_skill += 'Swimming '
	libtcod.console_print(game.ps, 0, 22, act_skill)

	cond = ''
	for flags in game.player.flags:
		if flags in ['stuck', 'poison', 'sleep', 'unconscious', 'burdened', 'strained', 'overburdened']:
			cond += flags.capitalize() + ' '
	libtcod.console_print(game.ps, 0, 25, cond)
	libtcod.console_blit(game.ps, 0, 0, game.PLAYER_STATS_WIDTH, game.PLAYER_STATS_HEIGHT, 0, game.PLAYER_STATS_X, game.PLAYER_STATS_Y)
Exemplo n.º 21
0
    def render(self, entity):
        """Renders an entity's inventory in the given window.
        
        Arguments:
        entity - the entity whose inventory you want to render
        
        """
        # Background
        libtcod.console_set_default_background(0, libtcod.black)
        libtcod.console_set_default_foreground(0, libtcod.black)
        libtcod.console_rect(0, self.x_offset, self.y_offset, self.width,
                             self.height, True, libtcod.BKGND_SET)

        libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_print(0, self.x_offset + 1, self.y_offset + 1,
                              entity.name)

        if entity.inventory is None:
            libtcod.console_print(
                0, self.x_offset + 1, self.y_offset + 3,
                "This entity has no inventory.  %s" % DEBUG_MSG)
        else:
            char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

            # Draw actions text - highlight the selected one
            libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.blue,
                                              libtcod.black)
            libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.blue,
                                              libtcod.white)
            libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.black,
                                              libtcod.white)

            action_text = "%cU%cse%c   %cD%crop%c   %cT%chrow%c   %cC%consume%c   %cE%cquip%c   %cW%cear%c"
            action_text_format = [
                libtcod.COLCTRL_1, libtcod.COLCTRL_STOP, libtcod.COLCTRL_STOP
            ] * 6
            if self.action_filter is not None:
                index = ["use", "drop", "throw", "consume", "equip",
                         "wear"].index(self.action_filter)
                action_text_format[index * 3 + 0] = libtcod.COLCTRL_2
                action_text_format[index * 3 + 1] = libtcod.COLCTRL_3

            action_text = action_text % tuple(action_text_format)
            libtcod.console_print(0, self.x_offset + 1, self.y_offset + 3,
                                  action_text)

            # Set up screen offsets for rendering
            lcol = self.x_offset + 1
            rcol = self.x_offset + 25
            lrow = rrow = self.y_offset + 5

            # In the case of no items, render_types will return 0, but still render a line (none) - so we need to
            # take this line into account when adjusting offsets.
            char_index = 0
            num_weapons = self.render_types(entity.inventory, lcol, lrow,
                                            EntityType.WEAPON, "WEAPONS",
                                            char_list[char_index:])
            lrow += max(1, num_weapons) + 3
            char_index += num_weapons
            num_clothing = self.render_types(entity.inventory, rcol, rrow,
                                             EntityType.CLOTHING, "CLOTHING",
                                             char_list[char_index:])
            rrow += max(1, num_clothing) + 3
            char_index += num_clothing
            num_comestibles = self.render_types(entity.inventory, lcol, lrow,
                                                EntityType.COMESTIBLE,
                                                "COMESTIBLES",
                                                char_list[char_index:])
            lrow += max(1, num_comestibles) + 3
            char_index += num_comestibles
            num_medecine = self.render_types(entity.inventory, rcol, rrow,
                                             EntityType.MEDECINE, "MEDECINE",
                                             char_list[char_index:])
            rrow += max(1, num_medecine) + 3
            char_index += num_medecine
            num_other = self.render_types(entity.inventory, lcol, lrow,
                                          EntityType.OTHER, "OTHER",
                                          char_list[char_index:])
Exemplo n.º 22
0
def updateDisplay(player):
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red, libtcod.black)
    statusString = player.name + " HP:" + str(player.hp) + "/" + str(player.hpmax) + " Level " + str(player.level)
    libtcod.console_clear(statusCon)
    libtcod.console_print_left(statusCon, 0, 0, libtcod.BKGND_NONE, statusString)
    libtcod.console_blit(statusCon, 0, 0, config.SCREEN_WIDTH, 2, 0, 0, config.SCREEN_HEIGHT - 2, 1, 1)
Exemplo n.º 23
0
    def debug_start(self):

        #self.jauge=self.ui.create_cell_jauge(self.charamenu,self.get_A,self.get_B,libtcod.red)

        #self.test_icon=ui.State_Icon(self.charamenu,chr(35),Color.GREEN,Color.RED,chr(79),Color.LCYAN,Color.GREEN)
        #self.charamenu.add_elem(self.test_icon)

        #self.test_icon.switch()

        #print os.path.abspath('..')
        #print os.path.dirname()

        #tileset=Map.Tileset(16)

        #tileset.load('data/Ressources/tileset1.cfg')

        #tileset.set_empty(1)

        #	self.level=Level.Level()
        #	self.level.set_tileset(tileset)

        #self.level.map=Level.create_test_map(tileset)

        #self.set_game_window(self.game_w)

        #	self.create_squad()
        #	self.squad.get_unit(1).set_pos(16,15)
        #	self.squad.get_unit(2).set_pos(18,15)
        #	self.squad.get_unit(3).set_pos(16,14)
        #	self.squad.get_unit(4).set_pos(17,14)

        for u in self.squad.get_units():
            self.heal_HP(u, 10)
            self.heal_AP(u, 10)

        libtcod.console_set_color_control(libtcod.COLCTRL_1, Color.RED,
                                          Color.BLACK)
        libtcod.console_set_color_control(libtcod.COLCTRL_2, Color.LBLUE,
                                          Color.BLACK)
        libtcod.console_set_color_control(libtcod.COLCTRL_2, Color.DBLUE,
                                          Color.BLACK)

        #self.squad_ui=ui.Squad_Ui(self.charamenu,self.squad,self)
        #self.charamenu.add_elem(self.squad_ui)

        self.level.add_monster(self.create_monster(Classes.Demonito()))
        self.level.add_monster(self.create_monster(Classes.Runner()))
        self.level.monsters.get_unit(1).set_pos(20, 16)
        self.level.monsters.get_unit(2).set_pos(21, 15)

        self.set_state(1)

        self.initialize_path_map()
        self.path_place_unit()

        self.log_w = self.window.create_window(50, 8, 0, 42, 'Log')
        self.log = ui.Log(self.log_w, 48, 6)
        self.log_w.add_elem(self.log)

        self.selected_window = None

        self.window.build()