Ejemplo n.º 1
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        base_x = 24
        base_y = 24

        # Draw winning team
        game_screen.blit(
            Menu.draw_menu_box(RESOLUTION_WIDTH - 48,
                               24,
                               background=light_team_color[self.winning_team]),
            (base_x, base_y))
        game_screen.blit(
            draw_text(
                get_string(formatted_strings, "RESULTS_HEADER").format(
                    get_string(team_name_strings, self.winning_team),
                    self.turn), light_color, dark_color),
            (base_x + 8, base_y + 8))

        x = 0
        for piece in self.winning_pieces:
            if x < RESOLUTION_WIDTH - 24:
                game_screen.blit(
                    spr_pieces[piece.team][piece.piece_type].subsurface(
                        0, 0, 24, 24), (base_x + x, base_y + 24))
                x += 12

        x = 0
        y = 2
        team_box_width = (RESOLUTION_WIDTH -
                          (36 * len(self.all_teams))) // len(self.all_teams)
        for team in self.all_teams:
            stats = self.team_stats[team].items()

            game_screen.blit(
                Menu.draw_menu_box(team_box_width, (len(stats) + 1) * 24,
                                   background=shadow_color[team]),
                (base_x + x, base_y + (y * 24)))
            game_screen.blit(get_text(team_name_strings, team),
                             (base_x + x + 8, base_y + (y * 24) + 8))

            y += 1
            for stat, value in stats:
                game_screen.blit(
                    draw_text(
                        get_string(formatted_strings, stat).format(value),
                        light_color, dark_color),
                    (base_x + x + 8, base_y + (y * 24) + 8))
                y += 1

            x += team_box_width + 24
            y = 2

        results_text = draw_text(get_string(label_strings, "RESULTS_PROMPT"),
                                 light_color, shadow_color[Team.RED])
        game_screen.blit(results_text,
                         (RESOLUTION_WIDTH - results_text.get_width() - 24,
                          RESOLUTION_HEIGHT - 16))
Ejemplo n.º 2
0
    def log_results(self, event):
        self.logger.info("=== BATTLE OVER! ===")
        winning_team = event.results["winning_team"]
        all_teams = event.results["all_teams"]
        team_stats = event.results["team_stats"]

        for team in all_teams:
            if team == winning_team:
                self.logger.info("{} team has won!".format(team))
            else:
                self.logger.info("{} team has lost.".format(team))

            self.logger.info("-- Stats for team {} --".format(team))
            for stat, value in team_stats[team].items():
                self.logger.info("  * " + get_string(formatted_strings, stat).format(value))
Ejemplo n.º 3
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        self.tick += 2.5 / TICK_RATE

        if self.height < self.max_height and self.tick < 1:
            self.height += 2
        elif self.height > 2 and (2 < self.tick < 3):
            self.height -= 2
        elif (2 < self.tick < 3) and self.height == 2:
            # Finish the animation once we've finished shrinking
            self.finish_animation()

        ui_screen.fill(light_color, (0 + HALF_RES_WIDTH / 2, HALF_RES_HEIGHT - self.height // 2, HALF_RES_WIDTH, self.height))
        ui_screen.fill(clear_color[self.get_manager(Manager.PLAYER).active_team], (1 + HALF_RES_WIDTH / 2, HALF_RES_HEIGHT + 1 - self.height // 2, HALF_RES_WIDTH - 2, self.height - 3))

        if self.height == self.max_height:
            text_surface = draw_text(get_string(formatted_strings, "NEW_TURN_MESSAGE").format(self.turn_number), light_color)
            ui_screen.blit(text_surface, (HALF_RES_WIDTH - text_surface.get_width() // 2, HALF_RES_HEIGHT - text_surface.get_height() // 2))
Ejemplo n.º 4
0
 def log_new_phase(self, event):
     self.logger.info("= {} phase begins".format(get_string(phase_strings, event.new_phase)))
Ejemplo n.º 5
0
 def __str__(self):
     from terra.strings import attribute_value_strings, get_string
     return get_string(attribute_value_strings, self)
Ejemplo n.º 6
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        if self.text_input:
            self.text_input.render(game_screen, ui_screen)
        elif self.tutorial:
            self.tutorial.render(game_screen, ui_screen)
        else:
            # Draw text for the menu title
            menu_title_text = get_text(main_menu_strings, self.current_menu[0])
            game_screen.blit(
                self.draw_menu_box(self.width - 16,
                                   24,
                                   background=light_team_color[Team.RED]),
                (self.root_x - 8, self.root_y - 16))
            game_screen.blit(menu_title_text,
                             (self.root_x + 24, self.root_y - 12))

            # Draw a scrollbar if necessary
            if self.should_show_scroll_bar(self.max_displayable_options,
                                           self.num_options):
                width = 8
                height = self.option_height * min(self.max_displayable_options,
                                                  self.num_options)
                game_screen.blit(
                    self.draw_scroll_bar(width, height,
                                         self.max_displayable_options,
                                         self.menu_min, self.num_options),
                    (self.root_x + self.width - 24, self.root_y))

            # Draw each menu option
            row_y = 0
            displayable_options = self.current_menu[1][self.menu_min:self.
                                                       menu_max]
            for option in displayable_options:
                is_selected = self.menu_pos == self.current_menu[1].index(
                    option)
                x_offset = 0 if is_selected else 16

                position_x, position_y = self.root_x, self.root_y + row_y * self.option_height
                box = self.draw_menu_box(
                    self.width - x_offset,
                    self.option_height,
                    background=light_team_color[Team.RED]
                    if is_selected else shadow_color[Team.RED])
                game_screen.blit(box, (position_x - 24 + x_offset, position_y))

                # Render splash graphics for top-level menu options
                if is_selected and self.current_menu[0] == Option.START:
                    splash_width = self.width - 24
                    splash_height = 24 * (self.max_displayable_options)

                    game_screen.blit(
                        self.draw_menu_box(splash_width, splash_height),
                        (self.root_x - splash_width - 24, self.root_y))
                    game_screen.blit(
                        spr_main_menu_preview[option[0]],
                        (self.root_x - splash_width - 12, self.root_y + 12))
                    game_screen.fill(clear_color[Team.RED],
                                     (self.root_x - splash_width - 12,
                                      self.root_y + 132, 120, 2))

                if isinstance(option[0], str):
                    # Render arbitrary text

                    # Format the text a bit
                    text = option[0]\
                        .replace("_", " ")\
                        .replace(".map", "")\
                        .replace(".sav", "")\
                        .title()

                    # Render arbitrary text
                    game_screen.blit(draw_text(text, light_color, dark_color),
                                     (position_x + 8, position_y + 8))

                    # For campaign, render an icon for completed missions
                    if option[0] in self.progress:
                        game_screen.blit(
                            spr_mission_completed,
                            (position_x + self.width - 48, position_y - 2))

                    # Render map previews if we're trying to select a map
                    if is_selected and self.current_menu[0] in [
                            Option.NEW_GAME, Option.NEW_MAP, Option.LOAD_GAME,
                            Option.LOAD_MAP, Option.NEW_NETWORK_GAME,
                            Option.LOAD_NETWORK_GAME, Option.NEW_CAMPAIGN_GAME,
                            Option.LOAD_CAMPAIGN_GAME
                    ]:

                        if self.current_menu[0] in [
                                Option.LOAD_GAME, Option.LOAD_NETWORK_GAME
                        ]:
                            asset_type = AssetType.SAVE
                        elif self.current_menu[0] in [
                                Option.NEW_CAMPAIGN_GAME
                        ]:
                            asset_type = AssetType.CAMPAIGN_MAP
                        elif self.current_menu[0] in [
                                Option.LOAD_CAMPAIGN_GAME
                        ]:
                            asset_type = AssetType.CAMPAIGN_SAVE
                        else:
                            asset_type = AssetType.MAP

                        container_height = 24 * self.max_displayable_options
                        container_width = self.width - 24

                        map_preview = draw_map_preview_from_file(
                            container_width,
                            container_height,
                            option[0],
                            asset_type=asset_type)
                        game_screen.blit(
                            map_preview,
                            (self.root_x - container_width - 24, self.root_y))

                elif option[0] in Setting:
                    # Display the setting prompt and the current value
                    display_string = get_string(
                        formatted_strings,
                        option[0]).format(SETTINGS.get_unsaved(option[0]))
                    game_screen.blit(
                        draw_text(display_string, light_color, dark_color),
                        (position_x + 24, position_y + 8))

                else:
                    # Display the icon for the option
                    game_screen.blit(spr_main_menu_option[option[0]],
                                     (position_x - 24 + x_offset, position_y))
                    # Display prerendered text
                    game_screen.blit(get_text(main_menu_strings, option[0]),
                                     (position_x + 24, position_y + 8))

                row_y += 1
Ejemplo n.º 7
0
def draw_map_preview(container_width, container_height, bitmap, pieces, teams):
    container = Surface((container_width, container_height), SRCALPHA, 32)

    translated_teams = {}
    piece_totals = {}
    # Determine the teams in the game
    for team in teams:
        data = team.split(' ')
        team = Team[data[0]]
        translated_teams[team] = int(data[1])
        piece_totals[team] = 0

    # Determine how many pieces each team has
    for piece in pieces:
        data = piece.split(' ')
        team = Team[data[2]]
        if team in piece_totals:
            piece_totals[team] += 1

    # Render a container for the whole thing
    container.fill(light_color, (0, 0, container_width, container_height))
    container.fill(shadow_color[Team.RED],
                   (1, 1, container_width - 2, container_height - 3))

    # Render the minimap
    minimap = generate_minimap(bitmap, pieces)

    # Trim giant maps to fit in the window
    if minimap.get_width() > container_width - 8:
        minimap = minimap.subsurface(
            (0, 0, container_width - 8, minimap.get_height()))
    if minimap.get_height() > container_height - 38:
        minimap = minimap.subsurface(
            (0, 0, minimap.get_width(), container_height - 38))

    minimap_x_offset = (container_width - minimap.get_width()) / 2
    container.blit(minimap, (minimap_x_offset, 32))
    container.fill(
        clear_color[Team.RED],
        (minimap_x_offset, 32 + minimap.get_height(), minimap.get_width(), 2))

    # Render teams + piece counts
    xoffset = 0
    container.fill(light_team_color[Team.RED], (1, 1, container_width - 2, 21))
    container.fill(light_color, (1, 22, container_width - 2, 2))

    for team, resource_count in translated_teams.items():
        piece_count = piece_totals[team]
        container.blit(
            spr_pieces[team][PieceType.TROOPER].subsurface((0, 0, 24, 24)),
            (container_width - 24 + xoffset, 0))

        display_string = get_string(formatted_strings,
                                    "QUANTITY").format(piece_count)
        container.blit(
            draw_text(display_string, light_color, shadow_color[Team.RED]),
            (container_width - 16 + xoffset, 14))

        xoffset -= 24

    return container
Ejemplo n.º 8
0
    def render(self, ui_screen):
        super().render(ui_screen)

        player_manager = self.get_manager(Manager.PLAYER)

        game_screen = Surface((RESOLUTION_WIDTH, RESOLUTION_HEIGHT), SRCALPHA,
                              32)
        game_screen.fill(clear_color[Team.RED])

        game_screen.blit(spr_title_text,
                         (self.root_x - spr_title_text.get_width() // 2, 24))

        # Render a minimap preview of the current map
        minimap = draw_map_preview(menu_width - 24, 144, self.bitmap,
                                   self.pieces, self.team_data)
        game_screen.blit(minimap,
                         (self.root_x - minimap.get_width() - 24, self.root_y))

        # Render the current lobby status-- open and filled teams for network games, human and AI teams for local
        if self.is_network_game():
            filled_teams = self.get_manager(Manager.NETWORK).filled_teams
            ai_teams = []
        else:
            filled_teams = dict([(team, get_string(label_strings,
                                                   "HUMAN_TEAM"))
                                 for team in player_manager.human_teams])
            ai_teams = player_manager.ai_teams

        row_y = 0
        for team in self.teams:
            position_x, position_y = self.root_x, self.root_y + row_y * 24 + 1

            is_filled = team in filled_teams.keys()
            x_offset = 0 if is_filled else 16

            game_screen.fill(light_color,
                             (position_x - 24 - 1 + x_offset, position_y - 1,
                              menu_width + 3 - x_offset, 24))
            game_screen.fill(
                light_team_color[team] if is_filled else shadow_color[team],
                (position_x - 24 + x_offset, position_y, menu_width - x_offset,
                 21))

            if team in filled_teams:
                game_screen.blit(
                    draw_text(filled_teams[team], light_color, dark_color),
                    (position_x + 8, position_y + 4))
            elif team in ai_teams:
                personality_type = player_manager.get_ai_player(
                    team).personality.personality_type
                game_screen.blit(
                    get_text(personality_strings, personality_type),
                    (position_x + 8, position_y + 4))
            else:
                game_screen.blit(get_text(label_strings, "OPEN_TEAM"),
                                 (position_x + 8, position_y + 4))

            row_y += 1

        if self.lobby_menu:
            self.lobby_menu.render(game_screen, ui_screen)

        return game_screen
Ejemplo n.º 9
0
    def render_upgrade_attributes(self, ui_screen):
        upgrade = base_upgrades[self.target]

        y_offset = 24
        if upgrade.get(UpgradeAttribute.NEW_STAT):
            for piece_type, attributes in upgrade[
                    UpgradeAttribute.NEW_STAT].items():
                for attribute in attributes:
                    # Draw the affected piece
                    ui_screen.blit(
                        spr_pieces[self.team][piece_type].subsurface(
                            0, 0, 24, 24), (self.x + 2, self.y + 8 + y_offset))

                    # Render the affected attribute + its new stat
                    text = get_string(attribute_label_strings, attribute)
                    value = upgrade[
                        UpgradeAttribute.NEW_STAT][piece_type][attribute]
                    if not isinstance(value, bool):
                        text += " +" + str(value)

                    ui_screen.blit(draw_text(text, dark_color, light_color),
                                   (self.x + 24, self.y + 16 + y_offset))
                    y_offset += 24

        if upgrade.get(UpgradeAttribute.NEW_TYPE):
            for piece_type, attributes in upgrade[
                    UpgradeAttribute.NEW_TYPE].items():
                for attribute in attributes:
                    # Draw the affected piece
                    ui_screen.blit(
                        spr_pieces[self.team][piece_type].subsurface(
                            0, 0, 24, 24), (self.x + 2, self.y + 8 + y_offset))

                    # Render the affected attribute + its new stat
                    text = get_string(attribute_label_strings, attribute)
                    value = upgrade[
                        UpgradeAttribute.NEW_TYPE][piece_type][attribute]
                    if not isinstance(value, bool):
                        text += " -> " + str(value)

                    ui_screen.blit(draw_text(text, dark_color, light_color),
                                   (self.x + 24, self.y + 16 + y_offset))
                    y_offset += 24

        if upgrade.get(UpgradeAttribute.NEW_ATTACK_MULTIPLIER):
            for piece_type, multipliers in upgrade[
                    UpgradeAttribute.NEW_ATTACK_MULTIPLIER].items():
                for enemy_archetype, value in multipliers.items():
                    # Render the first piece type
                    ui_screen.blit(
                        spr_pieces[self.team][piece_type].subsurface(
                            0, 0, 24, 24), (self.x + 2, self.y + 8 + y_offset))

                    # Render the attack icon
                    ui_screen.blit(spr_combat_icon[self.team],
                                   (self.x + 2 + 24, self.y + 8 + y_offset))

                    # Render the target piece type
                    ui_screen.blit(
                        spr_pieces[self.team]
                        [piece_archetype_to_type[enemy_archetype]].subsurface(
                            0, 0, 24,
                            24), (self.x + 2 + 48, self.y + 8 + y_offset))

                    # Render the new multiplier
                    text = get_string(formatted_strings, "QUANTITY")\
                        .format(upgrade[UpgradeAttribute.NEW_ATTACK_MULTIPLIER][piece_type][enemy_archetype])
                    ui_screen.blit(draw_text(text, dark_color, light_color),
                                   (self.x + 72, self.y + 16 + y_offset))

                    y_offset += 24

        if upgrade.get(UpgradeAttribute.NEW_BUILDABLE):
            for piece_type, new_pieces in upgrade[
                    UpgradeAttribute.NEW_BUILDABLE].items():
                # Render the affected piece type
                ui_screen.blit(
                    spr_pieces[self.team][piece_type].subsurface(0, 0, 24, 24),
                    (self.x + 2, self.y + 8 + y_offset))

                # Render the build icon
                ui_screen.blit(spr_build_icon[self.team],
                               (self.x + 2 + 24, self.y + 8 + y_offset))

                # Render each new buildable piece
                x_offset = 0
                for new_piece in new_pieces:
                    ui_screen.blit(
                        spr_pieces[self.team][new_piece].subsurface(
                            0, 0, 24, 24),
                        (self.x + 2 + 48 + x_offset, self.y + 8 + y_offset))
                    x_offset += 24

                y_offset += 24

        return y_offset