This repository has been archived by the owner on May 31, 2024. It is now read-only.
forked from hoodedpaladin/HoodTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryManager.py
149 lines (129 loc) · 4.72 KB
/
InventoryManager.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys
import os
ootr_path = os.path.join(os.getcwd(), "OoT-Randomizer")
if ootr_path not in sys.path:
sys.path.append(ootr_path)
from collections import Counter
import ItemPool
from PySide2.QtWidgets import *
import GuiUtils
from CommonUtils import *
total_equipment = ItemPool.item_groups['ProgressItem'] + ItemPool.item_groups['Song'] + ItemPool.item_groups['DungeonReward'] + [
'Bombchu Drop',
'Zeldas Letter',
'Weird Egg',
'Rutos Letter',
'Gerudo Membership Card',
'Deku Stick Capacity',
'Deku Shield',
'Hylian Shield',
'Progressive Hookshot',
'Progressive Strength Upgrade',
'Progressive Strength Upgrade',
'Progressive Scale',
'Progressive Wallet',
] + list(ItemPool.tradeitems)
item_limits = Counter()
for name, item in ItemPool.vanillaSK.items():
if "MQ" in name:
continue
item_limits[item] += 1
for name, item in ItemPool.vanillaBK.items():
if "MQ" in name:
continue
item_limits[item] += 1
for item in total_equipment:
item_limits[item] += 1
item_limits['Gold Skulltula Token'] += 100
class InventoryEntry:
def __init__(self, name, max, current=0):
self.name = name
self.max = max
self.current = current
class InventoryBox(QWidget):
def __init__(self, name, max, current, parent):
super().__init__()
self.parent = parent
self.name = name
self.current = current
self.max = max
self.label = QLabel()
self.plusbox = QPushButton("+")
self.plusbox.setFixedWidth(40)
self.plusbox.clicked.connect(lambda x: self.plusEvent(x))
self.plusspacer = QLabel("")
self.plusspacer.setFixedWidth(40)
self.minusbox = QPushButton("-")
self.minusbox.setFixedWidth(40)
self.minusbox.clicked.connect(lambda x: self.minusEvent(x))
self.minusspacer = QLabel("")
self.minusspacer.setFixedWidth(40)
self.layout = QHBoxLayout()
self.layout.addWidget(self.label)
self.layout.addStretch()
self.layout.addWidget(self.plusbox)
self.layout.addWidget(self.plusspacer)
self.layout.addWidget(self.minusbox)
self.layout.addWidget(self.minusspacer)
self.setLayout(self.layout)
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
self.setFixedHeight(50)
self.updateWidgets()
def plusEvent(self, x):
self.current = min(self.current + 1, self.max)
self.updateWidgets()
self.parent.update(self)
def minusEvent(self, x):
self.current = max(0, self.current - 1)
self.updateWidgets()
self.parent.update(self)
def updateWidgets(self):
self.label.setText("{}: {}".format(self.name, self.current))
self.plusbox.setVisible(self.current < self.max)
self.plusspacer.setVisible(not(self.current < self.max))
self.minusbox.setVisible(self.current > 0)
self.minusspacer.setVisible(not(self.current > 0))
class InventoryManager:
def __init__(self, inventory, parent=None):
self.inv_widgets = [InventoryBox(name=x.name, max=x.max, current=x.current, parent=self) for x in inventory]
self.widget = GuiUtils.ScrollSettingsArea(widgets=self.inv_widgets)
self.parent = parent
def collectItem(self, name, count=1):
item = expectOne([x for x in self.inv_widgets if x.name == name])
item.current += count
assert item.current <= item.max and item.current >= 0
item.updateWidgets()
def getProgItems(self, free_scarecrow, free_epona):
results = Counter()
for x in self.inv_widgets:
assert x.current >= 0
if x.current == 0:
continue
results[x.name] += x.current
# Fixes for buyable + replaceable items
if x.name == 'Deku Shield':
results['Buy Deku Shield'] += x.current
elif x.name == 'Deku Stick Capacity':
results['Deku Stick Drop'] += x.current
elif x.name == 'Hylian Shield':
results['Buy Hylian Shield'] += x.current
# Hardcoded items
if free_scarecrow:
results['Scarecrow Song'] += 1
if free_epona:
results['Epona'] += 1
return results
def update(self, child_item):
self.parent.updateLogic()
def getOutputFormat(self):
results = []
for item in self.inv_widgets:
results += [item.name] * item.current
return results
def makeInventory(max_starting=False):
global item_limits
result = [InventoryEntry(name=item, max=count, current=0) for item, count in item_limits.items()]
if max_starting:
for x in result:
x.current = x.max
return result