Skip to content

Commit

Permalink
ShopGameInfo: Design it to me similar to GameInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
loathingKernel committed Mar 31, 2023
1 parent ef41eac commit 7c514f6
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 275 deletions.
5 changes: 3 additions & 2 deletions rare/components/tabs/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, core: LegendaryCore, parent=None):
self.init = False

self.core = core
self.rcore = RareCore.instance()
# self.rcore = RareCore.instance()
self.api_core = ShopApiCore(
self.core.egs.session.headers["Authorization"],
self.core.language_code,
Expand All @@ -35,7 +35,8 @@ def __init__(self, core: LegendaryCore, parent=None):
# self.search.back_button.clicked.connect(lambda: self.setCurrentIndex(self.shop_index))

self.info = ShopGameInfo(
[i.asset_infos["Windows"].namespace for i in self.rcore.game_list if bool(i.asset_infos)],
# [i.asset_infos["Windows"].namespace for i in self.rcore.game_list if bool(i.asset_infos)],
[],
self.api_core,
parent=self
)
Expand Down
74 changes: 38 additions & 36 deletions rare/components/tabs/store/game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rare.components.tabs.store.shop_models import ShopGame
from rare.shared import LegendaryCoreSingleton
from rare.shared.image_manager import ImageSize
from rare.ui.components.tabs.store.shop_game_info import Ui_ShopGameInfo
from rare.ui.components.tabs.store.shop_game_info import Ui_ShopInfo
from rare.utils.misc import icon
from rare.widgets.side_tab import SideTabWidget, SideTabContents
from rare.widgets.elide_label import ElideLabel
Expand All @@ -22,30 +22,31 @@
logger = logging.getLogger("ShopInfo")


class ShopGameInfo(QWidget, Ui_ShopGameInfo, SideTabContents):
class ShopGameInfo(QWidget, SideTabContents):

# TODO Design
def __init__(self, installed_titles: list, api_core, parent=None):
super(ShopGameInfo, self).__init__(parent=parent)
self.setupUi(self)
self.core = LegendaryCoreSingleton()
self.ui = Ui_ShopInfo()
self.ui.setupUi(self)
# self.core = LegendaryCoreSingleton()
self.api_core = api_core
self.installed = installed_titles
self.open_store_button.clicked.connect(self.button_clicked)
self.ui.open_store_button.clicked.connect(self.button_clicked)
self.image = ShopImageWidget(self)
self.image.setFixedSize(ImageSize.Normal)
self.image_info_layout.insertWidget(0, self.image)
self.ui.left_layout.insertWidget(0, self.image, alignment=Qt.AlignTop)

self.game: ShopGame = None
self.data: dict = {}

self.wishlist_button.clicked.connect(self.add_to_wishlist)
self.ui.wishlist_button.clicked.connect(self.add_to_wishlist)
self.in_wishlist = False
self.wishlist = []

self.requirements_tabs: SideTabWidget = SideTabWidget(parent=self.requirements_group)
self.requirements_tabs: SideTabWidget = SideTabWidget(parent=self.ui.requirements_group)
self.requirements_tabs.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.requirements_layout.addWidget(self.requirements_tabs)
self.ui.requirements_layout.addWidget(self.requirements_tabs)

self.setDisabled(True)

Expand All @@ -55,15 +56,15 @@ def handle_wishlist_update(self, data):
self.wishlist = [i["offer"]["title"] for i in data]
if self.title_str in self.wishlist:
self.in_wishlist = True
self.wishlist_button.setVisible(True)
self.wishlist_button.setText(self.tr("Remove from Wishlist"))
self.ui.wishlist_button.setVisible(True)
self.ui.wishlist_button.setText(self.tr("Remove from Wishlist"))
else:
self.in_wishlist = False
self.wishlist_button.setVisible(False)
self.ui.wishlist_button.setVisible(False)

def update_game(self, data: dict):
self.set_title.emit(data["title"])
self.title.setText(data["title"])
self.ui.title.setText(data["title"])
self.title_str = data["title"]
self.id_str = data["id"]
self.api_core.get_wishlist(self.handle_wishlist_update)
Expand All @@ -86,14 +87,14 @@ def update_game(self, data: dict):
self.slug = slug

if data["namespace"] in self.installed:
self.open_store_button.setText(self.tr("Show Game on Epic Page"))
self.owned_label.setVisible(True)
self.ui.open_store_button.setText(self.tr("Show Game on Epic Page"))
self.ui.owned_label.setVisible(True)
else:
self.open_store_button.setText(self.tr("Buy Game in Epic Games Store"))
self.owned_label.setVisible(False)
self.ui.open_store_button.setText(self.tr("Buy Game in Epic Games Store"))
self.ui.owned_label.setVisible(False)

self.price.setText(self.tr("Loading"))
self.wishlist_button.setVisible(False)
self.ui.price.setText(self.tr("Loading"))
self.ui.wishlist_button.setVisible(False)
# self.title.setText(self.tr("Loading"))
# self.image.setPixmap(QPixmap())
self.data = data
Expand All @@ -118,9 +119,9 @@ def add_to_wishlist(self):
self.api_core.remove_from_wishlist(
self.game.namespace,
self.game.offer_id,
lambda success: self.wishlist_button.setVisible(False)
lambda success: self.ui.wishlist_button.setVisible(False)
if success
else self.wishlist_button.setText("Something goes wrong"),
else self.ui.wishlist_button.setText("Something goes wrong"),
)

def data_received(self, game):
Expand Down Expand Up @@ -148,23 +149,23 @@ def data_received(self, game):
return
# self.title.setText(self.game.title)

self.price.setFont(QFont())
self.ui.price.setFont(QFont())
if self.game.price == "0" or self.game.price == 0:
self.price.setText(self.tr("Free"))
self.ui.price.setText(self.tr("Free"))
else:
self.price.setText(self.game.price)
self.ui.price.setText(self.game.price)
if self.game.price != self.game.discount_price:
font = QFont()
font.setStrikeOut(True)
self.price.setFont(font)
self.discount_price.setText(
self.ui.price.setFont(font)
self.ui.discount_price.setText(
self.game.discount_price
if self.game.discount_price != "0"
else self.tr("Free")
)
self.discount_price.setVisible(True)
self.ui.discount_price.setVisible(True)
else:
self.discount_price.setVisible(False)
self.ui.discount_price.setVisible(False)

bold_font = QFont()
bold_font.setBold(True)
Expand Down Expand Up @@ -211,16 +212,16 @@ def data_received(self, game):
# self.image_stack.setCurrentIndex(0)
try:
if isinstance(self.game.developer, list):
self.dev.setText(", ".join(self.game.developer))
self.ui.dev.setText(", ".join(self.game.developer))
else:
self.dev.setText(self.game.developer)
self.ui.dev.setText(self.game.developer)
except KeyError:
pass
self.tags.setText(", ".join(self.game.tags))
self.ui.tags.setText(", ".join(self.game.tags))

# clear Layout
for b in self.social_group.findChildren(SocialButton, options=Qt.FindDirectChildrenOnly):
self.social_layout.removeWidget(b)
for b in self.ui.social_group.findChildren(SocialButton, options=Qt.FindDirectChildrenOnly):
self.ui.social_layout.removeWidget(b)
b.deleteLater()

link_count = 0
Expand All @@ -235,11 +236,11 @@ def data_received(self, game):
logger.error(str(e))
continue

button = SocialButton(icn, url, parent=self.social_group)
self.social_layout.addWidget(button)
button = SocialButton(icn, url, parent=self.ui.social_group)
self.ui.social_layout.addWidget(button)
link_count += 1

self.social_group.setEnabled(bool(link_count))
self.ui.social_group.setEnabled(bool(link_count))

self.setEnabled(True)

Expand All @@ -249,6 +250,7 @@ def add_wishlist_items(self, wishlist):
self.wishlist.append(game["offer"]["title"])

def button_clicked(self):
return
QDesktopServices.openUrl(QUrl(f"https://www.epicgames.com/store/{self.core.language_code}/p/{self.slug}"))


Expand Down
73 changes: 22 additions & 51 deletions rare/components/tabs/store/game_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,64 @@

from PyQt5 import QtGui
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtGui import QFont
from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout, QSizePolicy
from PyQt5.QtGui import QFont, QMouseEvent
from PyQt5.QtWidgets import QWidget

from rare.components.tabs.store.shop_models import ImageUrlModel
from rare.shared.image_manager import ImageSize
from rare.ui.components.tabs.store.wishlist_widget import Ui_WishlistWidget
from rare.utils.extra_widgets import ImageLabel
from rare.utils.misc import icon
from rare.widgets.elide_label import ElideLabel
from .image_widget import ShopImageWidget

logger = logging.getLogger("GameWidgets")


class GameWidget(QWidget):
class GameWidget(ShopImageWidget):
show_info = pyqtSignal(dict)

def __init__(self, path, json_info=None):
super(GameWidget, self).__init__()
self.manager = QNetworkAccessManager()
def __init__(self, path, json_info=None, parent=None):
super(GameWidget, self).__init__(parent=parent)
self.setFixedSize(ImageSize.Wide)
self.ui.setupUi(self)
self.path = path
self.json_info = json_info
if json_info:
self.init_ui(json_info)

def init_ui(self, json_info):
self.layout = QVBoxLayout()
self.layout.setSizeConstraint(QVBoxLayout.SetFixedSize)
self.image = ShopImageWidget(self)
self.image.setFixedSize(ImageSize.Wide)
self.layout.addWidget(self.image)
mini_layout = QHBoxLayout()
self.layout.addLayout(mini_layout)

if not json_info:
self.layout.addWidget(QLabel("An error occurred"))
self.setLayout(self.layout)
self.ui.title_label.setText(self.tr("An error occurred"))
return

self.title_label = ElideLabel(json_info.get("title"), parent=self)
self.title_label.setWordWrap(False)
mini_layout.addWidget(self.title_label)
# mini_layout.addStretch(1)

self.ui.title_label.setText(json_info.get("title"))
price = json_info["price"]["totalPrice"]["fmtPrice"]["originalPrice"]
discount_price = json_info["price"]["totalPrice"]["fmtPrice"]["discountPrice"]
price_label = QLabel(price)
self.ui.price_label.setText(f'{price if price != "0" else self.tr("Free")}')
if price != discount_price:
font = QFont()
font = self.ui.price_label.font()
font.setStrikeOut(True)
price_label.setFont(font)
free_label = QLabel(discount_price if discount_price != "0" else self.tr("Free"))
free_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
free_label.setAlignment(Qt.AlignRight)
mini_layout.addWidget(free_label)
self.ui.price_label.setFont(font)
self.ui.discount_label.setText(f'{discount_price if discount_price != "0" else self.tr("Free")}')
else:
if price == "0":
price_label.setText(self.tr("Free"))
price_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
price_label.setAlignment(Qt.AlignRight)
mini_layout.addWidget(price_label)
self.ui.discount_label.setVisible(False)

for c in r'<>?":|\/*':
json_info["title"] = json_info["title"].replace(c, "")

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",
"ProductLogo",
]:
if img["type"] == "VaultClosed" and self.title != "Mystery Game":
if img["type"] in ["DieselStoreFrontWide", "OfferImageWide", "VaultClosed", "ProductLogo",]:
if img["type"] == "VaultClosed" and json_info["title"] != "Mystery Game":
continue
self.image.fetchPixmap(img["url"], json_info["id"], json_info["title"])
self.fetchPixmap(img["url"], json_info["id"], json_info["title"])
break
else:
logger.info(", ".join([img["type"] for img in json_info["keyImages"]]))

self.setLayout(self.layout)

def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
self.show_info.emit(self.json_info)
def mousePressEvent(self, a0: QMouseEvent) -> None:
if a0.button() == Qt.LeftButton:
a0.accept()
self.show_info.emit(self.json_info)


class WishlistWidget(QWidget, Ui_WishlistWidget):
Expand Down
Loading

0 comments on commit 7c514f6

Please sign in to comment.