Beispiel #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))
Beispiel #2
0
def __get_cached_text__(string, light=True):
    color = light_color if light else dark_color
    background = dark_color if light else light_color

    if text_objects.get((string, color), None):
        return text_objects[(string, color)]
    else:
        new_text = draw_text(string, color, background)
        text_objects[(string, color)] = new_text
        return new_text
Beispiel #3
0
    def render_attribute(self, attribute):
        surface = pygame.Surface((96, 12), pygame.SRCALPHA, 32)
        surface.blit(spr_piece_attribute_icons[self.team][attribute], (0, 0))

        value = self.get_manager(Manager.TEAM).attr(self.team, self.target,
                                                    attribute)
        if attribute in [Attribute.ARCHETYPE, Attribute.MOVEMENT_TYPE]:
            surface.blit(get_text(attribute_value_strings, value, light=False),
                         (14, 0))
        else:
            surface.blit(draw_text(str(value), dark_color), (14, 0))

        return surface
Beispiel #4
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        label_text = get_text(label_strings, self.label)
        ui_screen.blit(label_text, (self.x, self.y - 24))

        # Draw the text box
        ui_screen.fill(
            light_color,
            (self.x - 1, self.y - 1, self.width + 3, self.height + 3))
        ui_screen.fill(shadow_color[Team.RED],
                       (self.x, self.y, self.width, self.height))

        # Draw the current text
        rendered_text = self.current_text + "|" if len(
            self.current_text) >= 32 else self.current_text + "_"
        text = draw_text(rendered_text, light_color)
        ui_screen.blit(text, (self.x + 4, self.y + 2))
Beispiel #5
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))
Beispiel #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
Beispiel #7
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
Beispiel #8
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