2021-06-15 08:30:57 +12:00
|
|
|
import logging
|
|
|
|
|
2023-01-30 12:56:29 +13:00
|
|
|
from PyQt5.QtCore import pyqtSignal, Qt
|
2023-04-04 23:46:02 +12:00
|
|
|
from PyQt5.QtGui import QMouseEvent
|
|
|
|
from PyQt5.QtWidgets import QPushButton
|
2021-06-15 08:30:57 +12:00
|
|
|
|
2023-12-13 00:02:07 +13:00
|
|
|
from rare.components.tabs.store.shop_models import ImageUrlModel
|
2023-01-30 12:56:29 +13:00
|
|
|
from rare.shared.image_manager import ImageSize
|
|
|
|
from rare.utils.misc import qta_icon
|
2023-04-04 23:46:02 +12:00
|
|
|
from rare.utils.qt_requests import QtRequestManager
|
2023-01-30 12:56:29 +13:00
|
|
|
from .image_widget import ShopImageWidget
|
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
|
|
|
|
2023-03-31 11:09:40 +13:00
|
|
|
class GameWidget(ShopImageWidget):
|
2021-06-15 08:30:57 +12:00
|
|
|
show_info = pyqtSignal(dict)
|
|
|
|
|
2023-04-04 23:46:02 +12:00
|
|
|
def __init__(self, manager: QtRequestManager, json_info=None, parent=None):
|
|
|
|
super(GameWidget, self).__init__(manager, parent=parent)
|
2023-03-31 11:09:40 +13:00
|
|
|
self.setFixedSize(ImageSize.Wide)
|
|
|
|
self.ui.setupUi(self)
|
|
|
|
self.json_info = json_info
|
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-10-15 10:05:00 +13:00
|
|
|
if not json_info:
|
2023-03-31 11:09:40 +13:00
|
|
|
self.ui.title_label.setText(self.tr("An error occurred"))
|
2021-10-15 10:05:00 +13:00
|
|
|
return
|
|
|
|
|
2023-03-31 11:09:40 +13:00
|
|
|
self.ui.title_label.setText(json_info.get("title"))
|
2023-04-04 23:46:02 +12:00
|
|
|
for attr in json_info["customAttributes"]:
|
|
|
|
if attr["key"] == "developerName":
|
|
|
|
developer = attr["value"]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
developer = json_info["seller"]["name"]
|
|
|
|
self.ui.developer_label.setText(developer)
|
2021-12-24 22:09:50 +13:00
|
|
|
price = json_info["price"]["totalPrice"]["fmtPrice"]["originalPrice"]
|
|
|
|
discount_price = json_info["price"]["totalPrice"]["fmtPrice"]["discountPrice"]
|
2023-03-31 11:09:40 +13:00
|
|
|
self.ui.price_label.setText(f'{price if price != "0" else self.tr("Free")}')
|
2021-09-06 07:52:47 +12:00
|
|
|
if price != discount_price:
|
2023-03-31 11:09:40 +13:00
|
|
|
font = self.ui.price_label.font()
|
2021-09-06 07:52:47 +12:00
|
|
|
font.setStrikeOut(True)
|
2023-03-31 11:09:40 +13:00
|
|
|
self.ui.price_label.setFont(font)
|
|
|
|
self.ui.discount_label.setText(f'{discount_price if discount_price != "0" else self.tr("Free")}')
|
2021-09-06 07:52:47 +12:00
|
|
|
else:
|
2023-03-31 11:09:40 +13:00
|
|
|
self.ui.discount_label.setVisible(False)
|
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
|
|
|
for img in json_info["keyImages"]:
|
2023-03-31 11:09:40 +13:00
|
|
|
if img["type"] in ["DieselStoreFrontWide", "OfferImageWide", "VaultClosed", "ProductLogo",]:
|
|
|
|
if img["type"] == "VaultClosed" and json_info["title"] != "Mystery Game":
|
2021-06-15 08:30:57 +12:00
|
|
|
continue
|
2023-04-04 23:46:02 +12:00
|
|
|
self.fetchPixmap(img["url"])
|
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
|
|
|
|
2023-03-31 11:09:40 +13:00
|
|
|
def mousePressEvent(self, a0: QMouseEvent) -> None:
|
|
|
|
if a0.button() == Qt.LeftButton:
|
|
|
|
a0.accept()
|
|
|
|
self.show_info.emit(self.json_info)
|
2021-06-15 08:30:57 +12:00
|
|
|
|
2021-08-19 08:17:14 +12:00
|
|
|
|
2023-04-04 23:46:02 +12:00
|
|
|
class WishlistWidget(ShopImageWidget):
|
2021-08-26 06:25:10 +12:00
|
|
|
open_game = pyqtSignal(dict)
|
|
|
|
delete_from_wishlist = pyqtSignal(dict)
|
|
|
|
|
2023-04-04 23:46:02 +12:00
|
|
|
def __init__(self, manager: QtRequestManager, game: dict, parent=None):
|
|
|
|
super(WishlistWidget, self).__init__(manager, parent=parent)
|
|
|
|
self.setFixedSize(ImageSize.Wide)
|
|
|
|
self.ui.setupUi(self)
|
2021-08-26 06:25:10 +12:00
|
|
|
self.game = game
|
|
|
|
for attr in game["customAttributes"]:
|
|
|
|
if attr["key"] == "developerName":
|
2023-04-04 23:46:02 +12:00
|
|
|
developer = attr["value"]
|
2021-08-26 06:25:10 +12:00
|
|
|
break
|
|
|
|
else:
|
2023-04-04 23:46:02 +12:00
|
|
|
developer = 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
|
|
|
|
2023-04-04 23:46:02 +12:00
|
|
|
self.ui.title_label.setText(game.get("title"))
|
|
|
|
self.ui.developer_label.setText(developer)
|
|
|
|
self.ui.price_label.setText(f'{original_price if original_price != "0" else self.tr("Free")}')
|
2021-08-26 06:25:10 +12:00
|
|
|
if original_price != discount_price:
|
2023-04-04 23:46:02 +12:00
|
|
|
font = self.ui.price_label.font()
|
2021-08-26 06:25:10 +12:00
|
|
|
font.setStrikeOut(True)
|
2023-04-04 23:46:02 +12:00
|
|
|
self.ui.price_label.setFont(font)
|
|
|
|
self.ui.discount_label.setText(f'{discount_price if discount_price != "0" else self.tr("Free")}')
|
2021-08-26 06:25:10 +12:00
|
|
|
else:
|
2023-04-04 23:46:02 +12:00
|
|
|
self.ui.discount_label.setVisible(False)
|
2021-08-26 06:25:10 +12:00
|
|
|
image_model = ImageUrlModel.from_json(game["keyImages"])
|
|
|
|
url = image_model.front_wide
|
|
|
|
if not url:
|
|
|
|
url = image_model.offer_image_wide
|
2023-04-04 23:46:02 +12:00
|
|
|
self.fetchPixmap(url)
|
|
|
|
|
|
|
|
self.delete_button = QPushButton(self)
|
2021-08-26 06:25:10 +12:00
|
|
|
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)
|
|
|
|
)
|
2023-04-04 23:46:02 +12:00
|
|
|
self.layout().insertWidget(0, self.delete_button, alignment=Qt.AlignRight)
|
2021-08-26 06:25:10 +12:00
|
|
|
|
2023-04-04 23:46:02 +12:00
|
|
|
def mousePressEvent(self, a0: QMouseEvent) -> None:
|
2021-08-26 06:25:10 +12:00
|
|
|
# left button
|
2023-04-04 23:46:02 +12:00
|
|
|
if a0.button() == Qt.LeftButton:
|
|
|
|
a0.accept()
|
2021-08-26 06:25:10 +12:00
|
|
|
self.open_game.emit(self.game)
|
|
|
|
# right
|
2023-04-04 23:46:02 +12:00
|
|
|
elif a0.button() == Qt.RightButton:
|
2021-08-26 06:25:10 +12:00
|
|
|
pass # self.showMenu(e)
|