Exemplo n.º 1
0
    def draw_state(self, state):
        """
        Draws the state
        :param state:
        """
        if self.state != state:
            self.reset()
            self.state = state

        opt = Options()
        # Clear the screen
        self.screen.fill(DrawingTool.color(opt.background_color))

        # If state is None we just want to clear the screen
        if self.state is None:
            return

        # If items were added, or removed (run restarted) regenerate items
        if self.state.modified:
            self.__reflow()
            # We picked up an item, start the counter
            self.item_picked_up()
            overlay = Overlay(self.file_prefix, self.state)
            overlay.update_seed()
            if len(self.drawn_items) > 0:
                overlay.update_stats()
                overlay.update_last_item_description()
        current_floor = self.state.last_floor


        # 19 pixels is the default line height, but we don't know what the
        # line height is with respect to the user's particular size_multiplier.
        # Thus, we can just draw a single space to ensure that the spacing is consistent
        # whether text happens to be showing or not.
        if opt.show_description or opt.show_status_message:
            self.text_height = self.write_message(" ")
        else:
            self.text_height = 0

        # Draw item pickup text, if applicable
        text_written = False
        if opt.show_description and self.item_message_countdown_in_progress():
            text_written = self.write_item_text()
        if not text_written and opt.show_status_message:
            # Draw seed/guppy text:
            seed = self.state.seed

            dic = defaultdict(str, seed=seed)
            # Update this dic with player stats

            for stat in ItemInfo.stat_list:
                dic[stat] = Overlay.format_value(self.state.player_stats[stat])
            dic["guppy"] = Overlay.format_guppy(self.state.guppy_set)

            # Use vformat to handle the case where the user adds an
            # undefined placeholder in default_message
            message = string.Formatter().vformat(
                opt.status_message,
                (),
                dic
            )
            self.text_height = self.write_message(message)

        floor_to_draw = None

        idx = 0
        # Draw items on screen, excluding filtered items:
        for drawable_item in self.drawn_items:
            if floor_to_draw is None or floor_to_draw.floor != drawable_item.item.floor:
                floor_to_draw = DrawableFloor(
                    drawable_item.item.floor,
                    drawable_item.x,
                    drawable_item.y,
                    self
                )
            if not floor_to_draw.is_drawn and opt.show_floors:
                floor_to_draw.draw()
            drawable_item.draw(selected=(idx == self.selected_item_index))

            idx += 1

        # Also draw the floor if we hit the end, so the current floor is visible
        if opt.show_floors and floor_to_draw is not None:
            if floor_to_draw.floor != current_floor and current_floor is not None:
                x, y = self.next_item
                DrawableFloor(current_floor, x, y, self).draw()

        self.state.drawn()
        pygame.display.flip()
        self.framecount += 1
Exemplo n.º 2
0
    def draw_state(self, state, framecount):
        """
        Draws the state
        :param state:
        """
        if self.state != state:
            self.reset()
            self.state = state

        opt = Options()
        if opt.transparent_mode and self.state.modified:
            self.screen = pygame.display.set_mode((opt.width, opt.height),
                                                  NOFRAME)
            self.transparent_mode()
        elif opt.transparent_mode is False and self.state.modified:
            self.screen = pygame.display.set_mode((opt.width, opt.height),
                                                  RESIZABLE)
            self.screen.fill(DrawingTool.color(opt.background_color))
        elif opt.transparent_mode:
            self.screen.fill(DrawingTool.color("#2C2C00"))
        elif opt.transparent_mode is False:
            self.screen.fill(DrawingTool.color(opt.background_color))

        # If state is None we just want to clear the screen
        if self.state is None:
            return

        # If items were added, or removed (run restarted) regenerate items
        if self.state.modified:
            # We picked up an item, start the counter
            self.item_picked_up()
            overlay = Overlay(self.wdir_prefix, self.state)
            overlay.update_seed()
            if len(self.drawn_items) > 0:
                overlay.update_stats()
                overlay.update_last_item_description()
        current_floor = self.state.last_floor

        # Draw item pickup text, if applicable
        # Save the previous text_height to know if we need to reflow the items
        text_height_before = self.text_height
        text_written = False
        if self.item_message_countdown_in_progress():
            if opt.show_description:
                text_written = self.write_item_text()
        else:
            self.selected_item_index = None
        if not text_written and opt.show_status_message:
            # Draw seed/guppy text:
            seed = self.state.seed

            dic = defaultdict(str,
                              seed=seed,
                              version_number=self.state.version_number,
                              room_id=self.state.room_id)
            # Update this dic with player stats

            for stat in ItemInfo.stat_list:
                dic[stat] = Overlay.format_value(self.state.player_stats[stat])
            for transform in ItemInfo.transform_list:
                if self.state.player == 19:
                    dic[transform] = Overlay.format_transform(
                        self.state.player_transforms[transform]
                    ) + " - " + Overlay.format_transform(
                        self.state.player2_transforms[transform])
                else:
                    dic[transform] = Overlay.format_transform(
                        self.state.player_transforms[transform])

            # Use vformat to handle the case where the user adds an
            # undefined placeholder in default_message
            message = string.Formatter().vformat(opt.status_message, (), dic)
            self.text_height = self.write_message(message)
        elif not text_written:
            self.text_height = 0

        # We want to reflow if the state has been modified or if the text
        # height has changed
        if self.state.modified or self.text_height != text_height_before:
            self.__reflow()

        floor_to_draw = None

        idx = 0
        # Draw items on screen, excluding filtered items:
        for drawable_item in self.drawn_items:
            if floor_to_draw is None or floor_to_draw.floor != drawable_item.item.floor:
                floor_to_draw = DrawableFloor(drawable_item.item.floor,
                                              drawable_item.x, drawable_item.y,
                                              self)
            if not floor_to_draw.is_drawn and self.show_floors:
                floor_to_draw.draw()
            drawable_item.draw(selected=(idx == self.selected_item_index),
                               framecount=framecount)

            idx += 1

        # Also draw the floor if we hit the end or if the list is empty,
        # so the current floor is visible
        if self.show_floors and current_floor is not None:
            if floor_to_draw is None or (floor_to_draw is not None and
                                         floor_to_draw.floor != current_floor):
                x, y = self.next_item
                DrawableFloor(current_floor, x, y, self).draw()

        self.state.drawn()
        pygame.display.flip()
        self.framecount += 1
Exemplo n.º 3
0
    def draw_state(self, state):
        """
        Draws the state
        :param state:
        """
        if self.state != state:
            self.reset()
            self.state = state

        opt = Options()
        # Clear the screen
        self.screen.fill(DrawingTool.color(opt.background_color))

        # If state is None we just want to clear the screen
        if self.state is None:
            return

        # If items were added, or removed (run restarted) regenerate items
        if self.state.modified:
            # We picked up an item, start the counter
            self.item_picked_up()
            overlay = Overlay(self.file_prefix, self.state)
            overlay.update_seed()
            if len(self.drawn_items) > 0:
                overlay.update_stats()
                overlay.update_last_item_description()
        current_floor = self.state.last_floor


        # Draw item pickup text, if applicable
        # Save the previous text_height to know if we need to reflow the items
        text_height_before = self.text_height
        text_written = False
        if opt.show_description and self.item_message_countdown_in_progress():
            text_written = self.write_item_text()
        if not text_written and opt.show_status_message:
            # Draw seed/guppy text:
            seed = self.state.seed

            dic = defaultdict(str, seed=seed)
            # Update this dic with player stats

            for stat in ItemInfo.stat_list:
                dic[stat] = Overlay.format_value(self.state.player_stats[stat])
            for transform in ItemInfo.transform_list:
                dic[transform] = Overlay.format_transform(self.state.player_transforms[transform])

            # Use vformat to handle the case where the user adds an
            # undefined placeholder in default_message
            message = string.Formatter().vformat(
                opt.status_message,
                (),
                dic
            )
            self.text_height = self.write_message(message)
        elif not text_written:
            self.text_height = 0

        # We want to reflow if the state has been modified or if the text
        # height has changed
        if self.state.modified or self.text_height != text_height_before:
            self.__reflow()

        floor_to_draw = None

        idx = 0
        # Draw items on screen, excluding filtered items:
        for drawable_item in self.drawn_items:
            if floor_to_draw is None or floor_to_draw.floor != drawable_item.item.floor:
                floor_to_draw = DrawableFloor(
                    drawable_item.item.floor,
                    drawable_item.x,
                    drawable_item.y,
                    self
                )
            if not floor_to_draw.is_drawn and opt.show_floors:
                floor_to_draw.draw()
            drawable_item.draw(selected=(idx == self.selected_item_index))

            idx += 1

        # Also draw the floor if we hit the end or if the list is empty,
        # so the current floor is visible
        if opt.show_floors and current_floor is not None:
            if floor_to_draw is None or (floor_to_draw is not None and
                                         floor_to_draw.floor != current_floor):
                x, y = self.next_item
                DrawableFloor(current_floor, x, y, self).draw()

        self.state.drawn()
        pygame.display.flip()
        self.framecount += 1