Beispiel #1
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        pos_x = 24
        pos_y = HALF_RES_HEIGHT - 24
        text_height = min(HALF_RES_HEIGHT - 24, self.text.get_height())

        # Draw the menu box + scrollbar
        game_screen.blit(Menu.draw_menu_box(self.width, self.height),
                         (pos_x, pos_y))
        game_screen.blit(
            Menu.draw_scroll_bar(8, self.height, self.scroll_height,
                                 self.scroll_pos, self.text.get_height()),
            (pos_x + self.width, pos_y))

        # Draw the text subscroll
        scrolled_text = self.text.subsurface(
            (0, self.scroll_pos, self.text.get_width(), text_height))
        game_screen.blit(scrolled_text, (pos_x + 12, pos_y + 12))

        # Draw the prompt text
        prompt_text = get_text(label_strings, "TUTORIAL_PROMPT")
        game_screen.blit(prompt_text,
                         (pos_x + self.width - prompt_text.get_width(),
                          pos_y + self.height + 8))
Beispiel #2
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 #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)

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

        # Render phase indicator bar
        ui_screen.fill(light_color, (0, RESOLUTION_HEIGHT - GRID_HEIGHT,
                                     RESOLUTION_WIDTH, GRID_HEIGHT))
        ui_screen.fill(clear_color[self.team],
                       (1, RESOLUTION_HEIGHT - GRID_HEIGHT + 1,
                        RESOLUTION_WIDTH - 2, GRID_HEIGHT - 3))

        x = 0
        for phase in BattlePhase:
            ui_screen.blit(spr_phase_indicator[self.team][phase.value],
                           (x * GRID_WIDTH, RESOLUTION_HEIGHT - GRID_HEIGHT))
            x += 1
        ui_screen.blit(spr_cursor[self.team],
                       (self.get_manager(Manager.TURN).phase.value *
                        GRID_WIDTH, RESOLUTION_HEIGHT - GRID_HEIGHT))

        # Render phase indicator text
        ui_screen.blit(
            get_text(phase_strings,
                     self.get_manager(Manager.TURN).phase),
            (3 + GRID_WIDTH * x, RESOLUTION_HEIGHT - GRID_HEIGHT + 6))

        # Render resource count
        x += 3
        ui_screen.blit(
            draw_resource_count(
                spr_resource_icon, spr_digit_icons, self.team,
                self.get_manager(Manager.TEAM).resources[self.team]),
            (GRID_WIDTH * x, RESOLUTION_HEIGHT - GRID_HEIGHT))

        # Render turn submission status
        x += 1
        for team in self.get_manager(Manager.TEAM).get_teams():
            if self.get_manager(Manager.TEAM).turn_submitted[team]:
                ui_screen.blit(
                    spr_turn_submitted_indicator[team],
                    (GRID_WIDTH * x, RESOLUTION_HEIGHT - GRID_HEIGHT))
                x += 1
            elif self.get_manager(Manager.PLAYER).is_ai_thinking(team):
                ui_screen.blit(
                    spr_turn_thinking_indicator[team],
                    (GRID_WIDTH * x, RESOLUTION_HEIGHT - GRID_HEIGHT))
                x += 1
Beispiel #5
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 #6
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        row_y = 0

        # Render any menu options we have
        for option in self.options:
            position_x, position_y = self.root_x, self.root_y + row_y * 24
            is_selected = self.menu_pos == self.options.index(option)
            x_offset = 0 if is_selected else 16

            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))

            game_screen.blit(spr_main_menu_option[option],
                             (position_x - 24 + x_offset, position_y))
            game_screen.blit(get_text(main_menu_strings, option),
                             (position_x + 24 + 8, position_y + 4))

            row_y += 1
Beispiel #7
0
 def create_toast_from_event(self, event):
     if event.team == self.team:
         self.toast = ToastNotification(
             self,
             get_text(notification_strings, event.event_type, light=True),
             self.team)
Beispiel #8
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 #9
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 #10
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        # If we have multiple targets, draw tabs for each target
        if len(self.targets) > 0:
            index = 0
            for target, team in self.targets:
                x_offset = 0 if self.index == index else GRID_WIDTH / 2
                ui_screen.blit(
                    Menu.draw_menu_box(GRID_WIDTH + 8,
                                       GRID_HEIGHT * 2,
                                       background=team_color[team],
                                       border=clear_color[team]),
                    (self.x - GRID_WIDTH + x_offset, self.y +
                     (index * GRID_HEIGHT * 2)))
                index += 1

        # Draw the base container
        ui_screen.blit(
            Menu.draw_menu_box(self.width,
                               self.height,
                               background=light_color,
                               border=clear_color[self.team]),
            (self.x, self.y))

        if self.target in PieceType:
            # Render piece icons
            ui_screen.fill(clear_color[self.team],
                           (self.x + 4, self.y + 12, 16, 16))
            ui_screen.blit(
                spr_pieces[self.team][self.target].subsurface(0, 0, 24, 24),
                (self.x + 2, self.y + 8))

            ui_screen.blit(
                get_text(piece_name_strings, self.target, light=False),
                (self.x + 32, self.y + 16))

            y_offset = self.render_piece_attributes(ui_screen)

        elif self.target in UpgradeType:
            # Render upgrade icons
            ui_screen.blit(spr_upgrade_icons[self.team][self.target],
                           (self.x + 4, self.y + 8))

            ui_screen.blit(
                get_text(upgrade_name_strings, self.target, light=False),
                (self.x + 32, self.y + 16))

            y_offset = self.render_upgrade_attributes(ui_screen)
        else:
            # Render menu option icons
            ui_screen.blit(spr_order_options[self.team][self.target],
                           (self.x + 4, self.y + 8))

            ui_screen.blit(
                get_text(menu_option_strings, self.target, light=False),
                (self.x + 32, self.y + 16))

            y_offset = 16

        # Render the description text
        description = get_multiline_text(menu_help_strings,
                                         self.target,
                                         light=False,
                                         width=subgrid_width * subgrid_size -
                                         8)
        ui_screen.blit(description, (self.x + 4, self.y + 16 + y_offset))

        # Render any bought upgrades for this piece
        relevant_upgrades = [
            upgrade for upgrade in self.get_manager(
                Manager.TEAM).get_owned_upgrades(self.team) if self.target in
            base_upgrades[upgrade][UpgradeAttribute.DISPLAY_FOR]
        ]

        x_offset = 0
        for upgrade in relevant_upgrades:
            ui_screen.blit(spr_upgrade_icons[self.team][upgrade],
                           (self.x + 4 + x_offset,
                            self.y + subgrid_size * subgrid_height - 4))
            x_offset += 24
Beispiel #11
0
    def render(self, game_screen, ui_screen):
        super().render(game_screen, ui_screen)

        if self.detailbox:
            self.detailbox.render(game_screen, ui_screen)
        else:
            row_y = 0
            displayable_options = self.options[self.menu_min:self.menu_max]

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

            for option in displayable_options:
                is_selected = self.menu_pos == self.options.index(option)
                x_offset = 0 if is_selected else 4

                # Draw the row
                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[self.team]
                    if is_selected else clear_color[self.team])
                ui_screen.blit(box, (position_x + x_offset, position_y))

                if option in PieceType:
                    # Render buildable pieces
                    ui_screen.blit(spr_menu_option_item_background[self.team],
                                   (self.root_x + x_offset,
                                    self.root_y + row_y * option_height))

                    ui_screen.blit(
                        spr_pieces[self.team][option].subsurface(0, 0, 24, 24),
                        (self.root_x + x_offset,
                         self.root_y + row_y * option_height))
                    ui_screen.blit(
                        get_text(piece_name_strings, option, light=True),
                        (self.root_x + 29,
                         self.root_y + 8 + row_y * option_height))

                    # if self.option_pos == row_y + self.option_min:
                    ui_screen.blit(
                        draw_resource_count(
                            spr_resource_icon, spr_digit_icons, self.team,
                            self.get_manager(Manager.TEAM).attr(
                                self.team, option, Attribute.PRICE)),
                        (self.root_x + self.width - 20,
                         self.root_y + row_y * option_height))

                    row_y += 1
                elif option in UpgradeType:
                    # Render purchaseable upgrades
                    ui_screen.blit(spr_upgrade_icons[self.team][option],
                                   (self.root_x + x_offset,
                                    self.root_y + row_y * option_height))
                    ui_screen.blit(
                        get_text(upgrade_name_strings, option, light=True),
                        (self.root_x + 29,
                         self.root_y + 8 + row_y * option_height))

                    # if self.option_pos == row_y + self.option_min:
                    ui_screen.blit(
                        draw_resource_count(
                            spr_resource_icon, spr_digit_icons, self.team,
                            base_upgrades[option][
                                UpgradeAttribute.UPGRADE_PRICE]),
                        (self.root_x + self.width - 24,
                         self.root_y + row_y * option_height))

                    row_y += 1
                else:
                    # Render menu option icons
                    ui_screen.blit(spr_order_options[self.team][option],
                                   (self.root_x + x_offset,
                                    self.root_y + row_y * option_height))

                    # Render 'contested' indicator if necessary
                    if self.is_option_contested(option):
                        ui_screen.blit(spr_contested_icon[self.team],
                                       (self.root_x + x_offset,
                                        self.root_y + row_y * option_height))

                    ui_screen.blit(
                        get_text(menu_option_strings, option, light=True),
                        (self.root_x + 29,
                         self.root_y + 8 + row_y * option_height))
                    row_y += 1