def _add_box_with_requirements(self, alternative: RequirementList):
        group_box = self._create_box_in_grid()
        group_box.rows = []

        vertical_layout = QVBoxLayout(group_box)
        vertical_layout.setObjectName(f"Layout with index {self._current_last_index - 1}")
        vertical_layout.setAlignment(Qt.AlignTop)

        empty = True
        trick_level = LayoutTrickLevel.NO_TRICKS

        for item in sorted(alternative.items):
            if self.edit_mode:
                ItemRow(group_box, vertical_layout, self.resource_database, item, group_box.rows)
            else:
                if item.resource.resource_type == ResourceType.DIFFICULTY:
                    trick_level = LayoutTrickLevel.from_number(item.amount)
                else:
                    empty = False
                    label = QLabel(group_box)
                    if item.resource.resource_type == ResourceType.TRICK:
                        label.setText(f"{item.resource} ({LayoutTrickLevel.from_number(item.amount).long_name})")
                    else:
                        label.setText(item.pretty_text)

                    vertical_layout.addWidget(label)

        if self.edit_mode:
            tools_layout = QHBoxLayout(group_box)
            tools_layout.setObjectName(f"Tools layout with index {self._current_last_index - 1}")
            vertical_layout.addLayout(tools_layout)

            add_new_button = QPushButton(group_box)
            add_new_button.setText("New Requirement")
            tools_layout.addWidget(add_new_button)

            delete_button = QPushButton(group_box)
            delete_button.setText("Delete")
            delete_button.clicked.connect(partial(self._delete_alternative, group_box))
            tools_layout.addWidget(delete_button)

            def _new_row():
                empty_item = IndividualRequirement(
                    self.resource_database.get_by_type(ResourceType.ITEM)[0],
                    1, False
                )
                ItemRow(group_box, vertical_layout, self.resource_database, empty_item, group_box.rows)
                vertical_layout.removeItem(tools_layout)
                vertical_layout.addLayout(tools_layout)

            add_new_button.clicked.connect(_new_row)

        else:
            group_box.setTitle(f"Difficulty: {trick_level.long_name}")
            if empty:
                label = QLabel(group_box)
                label.setText("No requirements.")
                vertical_layout.addWidget(label)

        return group_box
示例#2
0
 def _on_slide_trick_slider(self, trick: TrickResourceInfo, value: int):
     if self._slider_for_trick[trick].isEnabled():
         with self._editor as options:
             options.set_configuration_field(
                 "trick_level",
                 options.configuration.trick_level.set_level_for_trick(
                     trick, LayoutTrickLevel.from_number(value)))
示例#3
0
def pretty_print_resource_requirement(requirement: ResourceRequirement) -> str:
    if requirement.resource.resource_type == ResourceType.TRICK:
        return f"{requirement.resource} ({LayoutTrickLevel.from_number(requirement.amount).long_name})"
    elif requirement.resource.resource_type == ResourceType.DIFFICULTY:
        trick_level = LayoutTrickLevel.from_number(requirement.amount)
        return f"Difficulty: {trick_level.long_name}"
    else:
        return requirement.pretty_text
def _difficulties_for_trick(world_list: WorldList, trick: SimpleResourceInfo):
    result = set()

    for area in world_list.all_areas:
        for _, _, requirements in area.all_connections:
            for individual in requirements.all_individual:
                if individual.resource == trick:
                    result.add(LayoutTrickLevel.from_number(individual.amount))

    return result
示例#5
0
def difficulties_for_trick(world_list: WorldList, trick: TrickResourceInfo):
    result = set()

    for area in world_list.all_areas:
        for _, _, requirement in area.all_connections:
            for resource_requirement in requirement.iterate_resource_requirements(
            ):
                if resource_requirement.resource == trick:
                    result.add(
                        LayoutTrickLevel.from_number(
                            resource_requirement.amount))

    return result
示例#6
0
 def process(req: Requirement, result: Set[LayoutTrickLevel]):
     for resource_requirement in req.iterate_resource_requirements():
         if resource_requirement.resource == trick:
             result.add(
                 LayoutTrickLevel.from_number(resource_requirement.amount))