Ejemplo n.º 1
0
    def __init__(self, editor: PresetEditor, game: GameDescription):
        super().__init__(editor)
        self.setupUi(self)
        self.game_description = game
        self._during_batch_update = False

        self._row_widget_for_node = {}

        world_list = self.game_description.world_list

        nodes_by_world = collections.defaultdict(list)
        node_names = {}
        pickup_match = re.compile(r"Pickup \(([^\)]+)\)")

        for world in world_list.worlds:
            for is_dark_world in dark_world_flags(world):
                for area in world.areas:
                    if area.in_dark_aether != is_dark_world:
                        continue
                    for node in area.nodes:
                        if isinstance(node, PickupNode):
                            nodes_by_world[world.correct_name(
                                is_dark_world)].append(node)
                            match = pickup_match.match(node.name)
                            if match is not None:
                                node_name = match.group(1)
                            else:
                                node_name = node.name
                            node_names[
                                node] = f"{world_list.nodes_to_area(node).name} ({node_name})"

        for world_name in sorted(nodes_by_world.keys()):
            spoiler = Foldable(world_name)
            vbox_layout = QtWidgets.QVBoxLayout()

            first_node = True
            for node in sorted(nodes_by_world[world_name], key=node_names.get):
                if not first_node:
                    separator_line = QFrame()
                    separator_line.setFrameShape(QFrame.HLine)
                    separator_line.setFrameShadow(QFrame.Sunken)
                    transparent = QGraphicsOpacityEffect(separator_line)
                    transparent.setOpacity(0.33)
                    separator_line.setGraphicsEffect(transparent)
                    vbox_layout.addWidget(separator_line)
                else:
                    first_node = False

                row_widget = LocationPoolRowWidget(node, node_names[node])
                vbox_layout.addWidget(row_widget)
                row_widget.changed.connect(
                    functools.partial(self._on_location_changed, row_widget))
                self._row_widget_for_node[node] = row_widget

            spoiler.set_content_layout(vbox_layout)
            self.locations_scroll_area_layout.addWidget(spoiler)

        self.locations_scroll_area_layout.addItem(
            QSpacerItem(5, 5, QSizePolicy.Expanding, QSizePolicy.Expanding))
Ejemplo n.º 2
0
def test_foldable_initial_state(skip_qtbot):
    # Setup & Run
    foldable = Foldable("My foldable title", False)
    foldable_2 = Foldable("")

    skip_qtbot.addWidget(foldable)
    skip_qtbot.addWidget(foldable_2)

    # Assert
    assert foldable._toggleButton.text() == "My foldable title"
    assert not foldable._folded
    assert foldable_2._folded
Ejemplo n.º 3
0
def test_foldable_actions(skip_qtbot):
    # Setup
    foldable = Foldable("My foldable title")

    skip_qtbot.addWidget(foldable)

    # Run & Assert
    foldable._unfold()
    assert not foldable._folded
    assert not foldable._contentArea.isHidden()

    foldable._fold()
    assert foldable._folded
    assert foldable._contentArea.isHidden()
Ejemplo n.º 4
0
    def _add_dock_type(self, dock_type: DockType,
                       type_params: DockRandoParams):
        self.type_checks[dock_type] = defaultdict(dict)

        type_box = Foldable(dock_type.long_name)
        type_box.setObjectName(f"type_box {dock_type.short_name}")
        type_layout = QtWidgets.QHBoxLayout()
        type_layout.setObjectName(f"type_layout {dock_type.short_name}")
        type_box.set_content_layout(type_layout)

        self.dock_types_group.layout().addWidget(type_box)

        def add_group(name: str, desc: str, weaknesses: dict[DockWeakness,
                                                             bool]):
            group = QtWidgets.QGroupBox()
            group.setObjectName(f"{name}_group {dock_type.short_name}")
            group.setTitle(desc)
            layout = QtWidgets.QVBoxLayout()
            group.setLayout(layout)

            for weakness, enabled in weaknesses.items():
                check = QtWidgets.QCheckBox()
                check.setObjectName(
                    f"{name}_check {dock_type.short_name} {weakness.name}")
                check.setText(weakness.long_name)
                check.setEnabled(enabled)
                signal_handling.on_checked(
                    check,
                    self._persist_weakness_setting(name, dock_type, weakness))
                layout.addWidget(check)
                self.type_checks[dock_type][weakness][name] = check

            type_layout.addWidget(group)

        def keyfunc(weakness: DockWeakness):
            if weakness == type_params.unlocked:
                return 0
            return len(weakness.long_name)

        change_from = {
            weakness: True
            for weakness in sorted(type_params.change_from, key=keyfunc)
        }
        change_to = {
            weakness: weakness != type_params.unlocked
            for weakness in sorted(type_params.change_to, key=keyfunc)
        }
        add_group("can_change_from", "Doors to Change", change_from)
        add_group("can_change_to", "Change Doors To", change_to)
Ejemplo n.º 5
0
    def _create_categories_boxes(self, item_database: ItemDatabase, size_policy):
        self._boxes_for_category = {}

        categories = set()
        for major_item in item_database.major_items.values():
            if not major_item.hide_from_gui:
                categories.add(major_item.item_category)

        all_categories = list(item_database.item_categories.values())
        for major_item_category in sorted(categories, key=lambda it: all_categories.index(it)):
            category_box = Foldable(major_item_category.long_name)
            category_box.setObjectName(f"category_box {major_item_category}")
            category_layout = QtWidgets.QGridLayout()
            category_layout.setObjectName(f"category_layout {major_item_category}")
            category_box.set_content_layout(category_layout)

            self.item_pool_layout.addWidget(category_box)
            self._boxes_for_category[major_item_category.name] = category_box, category_layout, {}
Ejemplo n.º 6
0
    def create_template_editor(self, name: str):
        template_box = Foldable(name)
        template_box.setObjectName(f"template_box {name}")
        template_layout = QtWidgets.QVBoxLayout()
        template_layout.setObjectName(f"template_layout {name}")
        template_box.set_content_layout(template_layout)

        edit_template_button = QtWidgets.QPushButton()
        edit_template_button.setText("Edit")
        edit_template_button.clicked.connect(functools.partial(self.edit_template, name))
        template_layout.addWidget(edit_template_button)

        self.editor_for_template[name] = TemplateEditor(
            template_name=name,
            foldable=template_box,
            edit_button=edit_template_button,
            template_layout=template_layout,
            visualizer=None,
            connections_layout=None,
        )
        self.editor_for_template[name].create_visualizer(self.db)

        self.tab_template_layout.addWidget(template_box)