File size: 4,055 Bytes
f0b1638
 
 
 
 
2452398
970efde
f0b1638
 
 
 
 
 
88de31c
f0b1638
 
b76daae
f0b1638
0ed027c
f0b1638
88de31c
f0b1638
 
88de31c
 
 
 
f0b1638
88de31c
 
f0b1638
 
 
 
 
0ed027c
88de31c
f0b1638
 
 
 
 
88de31c
f0b1638
 
88de31c
f0b1638
 
 
 
 
 
 
 
88de31c
f0b1638
 
 
 
 
 
 
 
 
0ed027c
 
f0b1638
88de31c
f0b1638
 
 
88de31c
2452398
f0b1638
88de31c
 
2452398
f0b1638
2452398
f0b1638
2452398
f0b1638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
import os

from qt.constant import POSITION_MAP, STONES_POSITIONS, EQUIPMENTS_DIR, ENCHANTS_DIR, STONES_DIR, MAX_STONE_ATTR
from qt.constant import EMBED_POSITIONS, MAX_EMBED_LEVEL, MAX_STONE_LEVEL, SPECIAL_ENCHANT_POSITIONS
from qt.components import ComboWithLabel, RadioWithLabel, TableWithLabel
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QTabWidget


class EquipmentWidget(QWidget):
    def __init__(self, label):
        super().__init__()
        self.position = POSITION_MAP[label]
        layout = QVBoxLayout(self)

        self.equipment_json = json.load(open(os.path.join(EQUIPMENTS_DIR, self.position), encoding="utf-8"))
        self.equipment_mapping = {v['id']: k for k, v in self.equipment_json.items()}
        self.enchant_json = json.load(open(os.path.join(ENCHANTS_DIR, self.position), encoding="utf-8"))
        self.enchant_mapping = {v['id']: k for k, v in self.enchant_json.items()}
        self.equipment = ComboWithLabel("装备")
        layout.addWidget(self.equipment)

        self.detail_widget = QWidget()
        detail_layout = QHBoxLayout(self.detail_widget)
        layout.addWidget(self.detail_widget)
        self.detail_widget.hide()
        layout.addStretch()

        input_layout = QGridLayout()
        detail_layout.addLayout(input_layout)

        if not self.enchant_json:
            self.enchant = None
        else:
            self.enchant = ComboWithLabel("附魔")
            self.enchant.set_items([""] + list(self.enchant_json))
            input_layout.addWidget(self.enchant, 0, 0, 1, 2)

        if self.position not in SPECIAL_ENCHANT_POSITIONS:
            self.special_enchant = None
        else:
            self.special_enchant = RadioWithLabel("大附魔")
            input_layout.addWidget(self.special_enchant, 0, 2, 1, 2)

        self.strength_level = ComboWithLabel("精炼等级")
        input_layout.addWidget(self.strength_level, 1, 0)

        self.embed_levels = []
        for i in range(EMBED_POSITIONS[self.position]):
            embed_level = ComboWithLabel(
                f"镶嵌等级-{i + 1}", items=[str(i) for i in range(MAX_EMBED_LEVEL + 1)]
            )
            embed_level.combo_box.setCurrentIndex(MAX_EMBED_LEVEL)
            self.embed_levels.append(embed_level)
            input_layout.addWidget(embed_level, 1, i + 1)

        if self.position not in STONES_POSITIONS:
            self.stones_json = None
            self.stone_level = None
            self.stone_attrs = None
        else:
            self.stones_json = json.load(open(STONES_DIR, encoding="utf-8"))

            self.stone_level = ComboWithLabel(
                "五彩石等级", items=[str(i) for i in range(MAX_STONE_LEVEL + 1)]
            )
            self.stone_attrs = []
            input_layout.addWidget(self.stone_level, 2, 0)
            for i in range(MAX_STONE_ATTR):
                stone_attr = ComboWithLabel(f"五彩石属性-{i + 1}")
                self.stone_attrs.append(stone_attr)
                input_layout.addWidget(stone_attr, 2, i + 1)
        self.detail_widget.hide()

        output_layout = QVBoxLayout()
        detail_layout.addLayout(output_layout)
        self.base_attr = TableWithLabel("基本属性", column_count=2)
        output_layout.addWidget(self.base_attr)
        self.magic_attr = TableWithLabel("精炼属性", column_count=2)
        output_layout.addWidget(self.magic_attr)
        self.embed_attr = TableWithLabel("镶嵌属性", column_count=2)
        output_layout.addWidget(self.embed_attr)


class EquipmentsWidget(QTabWidget):
    def __init__(self):
        super().__init__()
        self.equipments = {}
        for label in POSITION_MAP:
            self.equipments[label] = EquipmentWidget(label)
            self.addTab(self.equipments[label], label)

    def __getitem__(self, item) -> EquipmentWidget:
        return self.equipments[item]

    def items(self):
        return self.equipments.items()

    def values(self):
        return self.equipments.values()