1
0
Fork 0
mirror of synced 2024-06-23 08:40:45 +12:00
Rare/rare/components/tabs/shop/game_widgets.py

74 lines
2.4 KiB
Python
Raw Normal View History

2021-06-15 08:30:57 +12:00
import logging
from PyQt5 import QtGui
2021-08-08 09:42:40 +12:00
from PyQt5.QtCore import pyqtSignal
2021-08-19 08:17:14 +12:00
from PyQt5.QtGui import QFont
2021-08-08 09:42:40 +12:00
from PyQt5.QtNetwork import QNetworkAccessManager
2021-08-19 08:17:14 +12:00
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
2021-06-15 08:30:57 +12:00
from rare.utils.extra_widgets import ImageLabel
2021-06-17 05:03:18 +12:00
logger = logging.getLogger("GameWidgets")
2021-06-15 08:30:57 +12:00
class GameWidget(QWidget):
show_info = pyqtSignal(dict)
def __init__(self, path, json_info=None, width=300):
super(GameWidget, self).__init__()
self.manager = QNetworkAccessManager()
self.width = width
self.path = path
2021-08-08 09:42:40 +12:00
if json_info:
self.init_ui(json_info)
2021-06-15 08:30:57 +12:00
2021-08-08 09:42:40 +12:00
def init_ui(self, json_info):
2021-06-15 08:30:57 +12:00
self.layout = QVBoxLayout()
self.image = ImageLabel()
self.layout.addWidget(self.image)
2021-08-19 08:17:14 +12:00
self.title_label = QLabel(json_info.get("title"))
self.title_label.setWordWrap(True)
self.layout.addWidget(self.title_label)
for c in r'<>?":|\/*':
json_info["title"] = json_info["title"].replace(c, "")
2021-06-15 08:30:57 +12:00
self.json_info = json_info
self.slug = json_info["productSlug"]
self.title = json_info["title"]
for img in json_info["keyImages"]:
if img["type"] in ["DieselStoreFrontWide", "OfferImageWide", "VaultClosed"]:
if img["type"] == "VaultClosed" and self.title != "Mystery Game":
continue
self.image.update_image(img["url"], json_info["title"], (self.width, int(self.width * 9 / 16)))
break
else:
2021-06-17 05:03:18 +12:00
logger.info(", ".join([img["type"] for img in json_info["keyImages"]]))
# print(json_info["keyImages"])
2021-06-15 08:30:57 +12:00
self.setLayout(self.layout)
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
self.show_info.emit(self.json_info)
2021-08-19 08:17:14 +12:00
class GameWidgetDiscount(GameWidget):
def __init__(self, *args, **kwargs):
super(GameWidgetDiscount, self).__init__(*args, **kwargs)
h_layout = QHBoxLayout()
self.layout.addLayout(h_layout)
price = args[1]['price']['totalPrice']['fmtPrice']['originalPrice']
discount_price = args[1]['price']['totalPrice']['fmtPrice']['discountPrice']
price_label = QLabel(price)
font = QFont()
font.setStrikeOut(True)
price_label.setFont(font)
h_layout.addWidget(QLabel(discount_price if discount_price != "0" else self.tr("Free")))
h_layout.addWidget(price_label)