2024-08-14 14:38:39 -06:00
|
|
|
from PyQt6.QtWidgets import (
|
|
|
|
QWidget,
|
|
|
|
QPushButton,
|
|
|
|
QVBoxLayout,
|
|
|
|
QHBoxLayout,
|
|
|
|
)
|
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
from PyQt6.QtCore import Qt
|
|
|
|
from components.customButton import CustomButton
|
|
|
|
|
2024-08-14 14:38:39 -06:00
|
|
|
from data.collectibles import collectibles
|
|
|
|
|
|
|
|
class MainWindow(QWidget):
|
|
|
|
collectibles = {}
|
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
def __init__(self: QWidget, *args, **kwargs):
|
2024-08-14 14:38:39 -06:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
def initUI(self):
|
2024-08-14 14:38:39 -06:00
|
|
|
# Set the window title
|
|
|
|
self.setWindowTitle('Y-Tracker')
|
|
|
|
self.collectibles = collectibles
|
|
|
|
|
|
|
|
# Create & Edit Layout
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
vLayout = QVBoxLayout()
|
|
|
|
hLayout = QHBoxLayout()
|
|
|
|
|
|
|
|
layout.addLayout(hLayout)
|
|
|
|
layout.addLayout(vLayout)
|
|
|
|
|
|
|
|
self.layout_dict = {}
|
|
|
|
self.label_dict = {}
|
|
|
|
self.button_dict = {}
|
2024-08-15 20:42:05 -06:00
|
|
|
self.modifiers = Qt.KeyboardModifier.NoModifier
|
2024-08-14 14:38:39 -06:00
|
|
|
|
|
|
|
# Build the Inputs
|
|
|
|
for type in self.collectibles:
|
|
|
|
|
|
|
|
if self.collectibles[type]['meta']['orient'] == 'horizontal':
|
|
|
|
self.layout_dict[type] = QHBoxLayout()
|
|
|
|
vLayout.addLayout(self.layout_dict[type])
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.layout_dict[type] = QVBoxLayout()
|
|
|
|
hLayout.addLayout(self.layout_dict[type])
|
|
|
|
|
|
|
|
self.button_dict[type] = {}
|
|
|
|
|
|
|
|
for item in self.collectibles[type]:
|
|
|
|
|
|
|
|
if item != 'meta':
|
2024-08-15 20:42:05 -06:00
|
|
|
self.button_dict[type][item] = CustomButton()
|
2024-08-14 14:38:39 -06:00
|
|
|
self.button_dict[type][item].setObjectName(f'{type}-{item}')
|
|
|
|
|
|
|
|
if self.collectibles[type]['meta']['type'] == 'bool':
|
|
|
|
self.button_dict[type][item].setText(self.collectibles[type][item]['name'])
|
|
|
|
|
|
|
|
if self.collectibles[type][item]['value'] == False:
|
|
|
|
self.button_dict[type][item].setStyleSheet("""
|
|
|
|
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
|
|
|
|
color: #88FFFFFF
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.button_dict[type][item].setStyleSheet("""
|
|
|
|
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
|
|
|
|
color: #FFFFFFFF
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.boolButtonSelect(x[0], x[1]))
|
2024-08-14 14:38:39 -06:00
|
|
|
|
|
|
|
elif self.collectibles[type]['meta']['type'] == 'int':
|
|
|
|
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
|
2024-08-15 20:42:05 -06:00
|
|
|
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.intButtonSelect(x[0], x[1]))
|
2024-08-14 14:38:39 -06:00
|
|
|
|
|
|
|
elif self.collectibles[type]['meta']['type'] == 'list':
|
|
|
|
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
2024-08-15 20:42:05 -06:00
|
|
|
self.button_dict[type][item].clicked.connect(lambda state, x=[type, item]: self.listButtonSelect(x[0], x[1]))
|
2024-08-14 14:38:39 -06:00
|
|
|
|
|
|
|
self.layout_dict[type].addWidget(self.button_dict[type][item])
|
2024-08-15 20:42:05 -06:00
|
|
|
|
|
|
|
# show the window
|
|
|
|
self.show()
|
2024-08-14 14:38:39 -06:00
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
# Add Slots
|
|
|
|
def boolButtonSelect(self, type, item):
|
|
|
|
if self.collectibles[type][item]['value']:
|
|
|
|
self.collectibles[type][item]['value'] = False
|
|
|
|
self.button_dict[type][item].setStyleSheet("""
|
|
|
|
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
|
|
|
|
color: #88FFFFFF
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
else:
|
|
|
|
self.collectibles[type][item]['value'] = True
|
|
|
|
self.button_dict[type][item].setStyleSheet("""
|
|
|
|
QPushButton#""" + self.button_dict[type][item].objectName() + """ {
|
|
|
|
color: #FFFFFFFF
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
|
|
|
|
def intButtonSelect(self, type, item):
|
|
|
|
if self.modifiers == Qt.KeyboardModifier.ShiftModifier:
|
|
|
|
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] - 1
|
|
|
|
else:
|
2024-08-14 14:38:39 -06:00
|
|
|
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
|
2024-08-15 20:42:05 -06:00
|
|
|
|
|
|
|
self.button_dict[type][item].setText(f'{self.collectibles[type][item]["name"]}: {self.collectibles[type][item]["value"]}')
|
2024-08-14 14:38:39 -06:00
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
def listButtonSelect(self, type, item):
|
|
|
|
if self.modifiers == Qt.KeyboardModifier.ShiftModifier:
|
|
|
|
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] - 1
|
|
|
|
else:
|
2024-08-14 14:38:39 -06:00
|
|
|
self.collectibles[type][item]['value'] = self.collectibles[type][item]['value'] + 1
|
|
|
|
|
2024-08-15 20:42:05 -06:00
|
|
|
try:
|
|
|
|
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
|
|
|
except:
|
|
|
|
if self.collectibles[type][item]['value'] < 0:
|
|
|
|
self.collectibles[type][item]['value'] = len(self.collectibles[type]['meta']['list']) - 1
|
|
|
|
else:
|
|
|
|
self.collectibles[type][item]['value'] = 0
|
|
|
|
|
|
|
|
self.button_dict[type][item].setText(self.collectibles[type]['meta']['list'][self.collectibles[type][item]['value']])
|
|
|
|
|
|
|
|
def mousePressEvent(self, e):
|
|
|
|
self.modifiers = e.modifiers()
|
2024-08-14 14:38:39 -06:00
|
|
|
|