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
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
from rare.components.tabs.shop.shop_models import ImageUrlModel
|
|
|
|
from rare.ui.components.tabs.store.wishlist_widget import Ui_WishlistWidget
|
2021-06-15 08:30:57 +12:00
|
|
|
from rare.utils.extra_widgets import ImageLabel
|
2022-07-27 02:58:17 +12:00
|
|
|
from rare.utils.misc import icon
|
2021-06-15 08:30:57 +12:00
|
|
|
|
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()
|
2021-06-17 10:34:23 +12:00
|
|
|
self.layout.addWidget(self.image)
|
2021-09-06 07:52:47 +12:00
|
|
|
mini_layout = QHBoxLayout()
|
|
|
|
self.layout.addLayout(mini_layout)
|
2021-06-17 10:34:23 +12:00
|
|
|
|
2021-10-15 10:05:00 +13:00
|
|
|
if not json_info:
|
|
|
|
self.layout.addWidget(QLabel("An error occurred"))
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
return
|
|
|
|
|
2021-08-19 08:17:14 +12:00
|
|
|
self.title_label = QLabel(json_info.get("title"))
|
2021-06-17 10:34:23 +12:00
|
|
|
self.title_label.setWordWrap(True)
|
2021-09-06 07:52:47 +12:00
|
|
|
mini_layout.addWidget(self.title_label)
|
|
|
|
mini_layout.addStretch(1)
|
|
|
|
|
2021-12-24 22:09:50 +13:00
|
|
|
price = json_info["price"]["totalPrice"]["fmtPrice"]["originalPrice"]
|
|
|
|
discount_price = json_info["price"]["totalPrice"]["fmtPrice"]["discountPrice"]
|
2021-09-06 07:52:47 +12:00
|
|
|
price_label = QLabel(price)
|
|
|
|
if price != discount_price:
|
|
|
|
font = QFont()
|
|
|
|
font.setStrikeOut(True)
|
|
|
|
price_label.setFont(font)
|
2021-12-24 22:09:50 +13:00
|
|
|
mini_layout.addWidget(
|
|
|
|
QLabel(discount_price if discount_price != "0" else self.tr("Free"))
|
|
|
|
)
|
2021-09-06 07:52:47 +12:00
|
|
|
mini_layout.addWidget(price_label)
|
|
|
|
else:
|
2021-11-22 10:44:45 +13:00
|
|
|
if price == "0":
|
|
|
|
price_label.setText(self.tr("Free"))
|
2021-09-06 07:52:47 +12:00
|
|
|
mini_layout.addWidget(price_label)
|
2021-06-17 10:34:23 +12:00
|
|
|
|
|
|
|
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"]:
|
2021-12-24 22:09:50 +13:00
|
|
|
if img["type"] in [
|
|
|
|
"DieselStoreFrontWide",
|
|
|
|
"OfferImageWide",
|
|
|
|
"VaultClosed",
|
|
|
|
"ProductLogo",
|
|
|
|
]:
|
2021-06-15 08:30:57 +12:00
|
|
|
if img["type"] == "VaultClosed" and self.title != "Mystery Game":
|
|
|
|
continue
|
2021-12-24 22:09:50 +13:00
|
|
|
self.image.update_image(
|
|
|
|
img["url"],
|
|
|
|
json_info["title"],
|
|
|
|
(self.width, int(self.width * 9 / 16)),
|
|
|
|
)
|
2021-06-15 08:30:57 +12:00
|
|
|
break
|
|
|
|
else:
|
2021-06-17 05:03:18 +12:00
|
|
|
logger.info(", ".join([img["type"] for img in json_info["keyImages"]]))
|
2021-06-15 08:30:57 +12:00
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
2021-11-22 10:44:45 +13:00
|
|
|
self.setFixedSize(self.width + 10, self.width * 9 // 16 + 50)
|
|
|
|
|
2021-06-15 08:30:57 +12:00
|
|
|
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
|
|
|
|
self.show_info.emit(self.json_info)
|
|
|
|
|
2021-08-19 08:17:14 +12:00
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
class WishlistWidget(QWidget, Ui_WishlistWidget):
|
|
|
|
open_game = pyqtSignal(dict)
|
|
|
|
delete_from_wishlist = pyqtSignal(dict)
|
|
|
|
|
|
|
|
def __init__(self, game: dict):
|
|
|
|
super(WishlistWidget, self).__init__()
|
|
|
|
self.setupUi(self)
|
|
|
|
self.game = game
|
|
|
|
self.title_label.setText(game.get("title"))
|
|
|
|
for attr in game["customAttributes"]:
|
|
|
|
if attr["key"] == "developerName":
|
|
|
|
self.developer.setText(attr["value"])
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.developer.setText(game["seller"]["name"])
|
2021-12-24 22:09:50 +13:00
|
|
|
original_price = game["price"]["totalPrice"]["fmtPrice"]["originalPrice"]
|
|
|
|
discount_price = game["price"]["totalPrice"]["fmtPrice"]["discountPrice"]
|
2021-08-26 06:25:10 +12:00
|
|
|
|
|
|
|
self.price.setText(original_price if original_price != "0" else self.tr("Free"))
|
|
|
|
# if discount
|
|
|
|
if original_price != discount_price:
|
|
|
|
self.discount = True
|
|
|
|
font = QFont()
|
|
|
|
font.setStrikeOut(True)
|
|
|
|
self.price.setFont(font)
|
|
|
|
self.discount_price.setText(discount_price)
|
|
|
|
else:
|
|
|
|
self.discount = False
|
|
|
|
self.discount_price.setVisible(False)
|
|
|
|
|
|
|
|
self.image = ImageLabel()
|
|
|
|
self.layout().insertWidget(0, self.image)
|
|
|
|
image_model = ImageUrlModel.from_json(game["keyImages"])
|
|
|
|
url = image_model.front_wide
|
|
|
|
if not url:
|
|
|
|
url = image_model.offer_image_wide
|
|
|
|
self.image.update_image(url, game.get("title"), (240, 135))
|
|
|
|
self.delete_button.setIcon(icon("mdi.delete", color="white"))
|
2021-12-24 22:09:50 +13:00
|
|
|
self.delete_button.clicked.connect(
|
|
|
|
lambda: self.delete_from_wishlist.emit(self.game)
|
|
|
|
)
|
2021-08-26 06:25:10 +12:00
|
|
|
|
|
|
|
def mousePressEvent(self, e: QtGui.QMouseEvent) -> None:
|
|
|
|
# left button
|
|
|
|
if e.button() == 1:
|
|
|
|
self.open_game.emit(self.game)
|
|
|
|
# right
|
|
|
|
elif e.button() == 2:
|
|
|
|
pass # self.showMenu(e)
|