From 648fd6fd7fa7b8bbe8f3702461dc8031fcddace4 Mon Sep 17 00:00:00 2001 From: Dummerle Date: Sun, 5 Sep 2021 21:52:47 +0200 Subject: [PATCH] Add price to game widget --- rare/components/tabs/shop/game_widgets.py | 36 ++++++++++------------- rare/components/tabs/shop/shop_widget.py | 26 ++++++++-------- rare/ui/components/tabs/store/store.py | 10 +++++++ rare/ui/components/tabs/store/store.ui | 13 ++++++++ 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/rare/components/tabs/shop/game_widgets.py b/rare/components/tabs/shop/game_widgets.py index 947b4a03..e24897ba 100644 --- a/rare/components/tabs/shop/game_widgets.py +++ b/rare/components/tabs/shop/game_widgets.py @@ -29,10 +29,25 @@ class GameWidget(QWidget): self.layout = QVBoxLayout() self.image = ImageLabel() self.layout.addWidget(self.image) + mini_layout = QHBoxLayout() + self.layout.addLayout(mini_layout) self.title_label = QLabel(json_info.get("title")) self.title_label.setWordWrap(True) - self.layout.addWidget(self.title_label) + mini_layout.addWidget(self.title_label) + mini_layout.addStretch(1) + + price = json_info['price']['totalPrice']['fmtPrice']['originalPrice'] + discount_price = json_info['price']['totalPrice']['fmtPrice']['discountPrice'] + price_label = QLabel(price) + if price != discount_price: + font = QFont() + font.setStrikeOut(True) + price_label.setFont(font) + mini_layout.addWidget(QLabel(discount_price if discount_price != "0" else self.tr("Free"))) + mini_layout.addWidget(price_label) + else: + mini_layout.addWidget(price_label) for c in r'<>?":|\/*': json_info["title"] = json_info["title"].replace(c, "") @@ -57,25 +72,6 @@ class GameWidget(QWidget): self.show_info.emit(self.json_info) -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) - - class WishlistWidget(QWidget, Ui_WishlistWidget): open_game = pyqtSignal(dict) delete_from_wishlist = pyqtSignal(dict) diff --git a/rare/components/tabs/shop/shop_widget.py b/rare/components/tabs/shop/shop_widget.py index e1d0effe..8742a925 100644 --- a/rare/components/tabs/shop/shop_widget.py +++ b/rare/components/tabs/shop/shop_widget.py @@ -2,13 +2,13 @@ import datetime import logging import random -from PyQt5.QtCore import Qt, pyqtSignal -from PyQt5.QtWidgets import QWidget, QCompleter, QGroupBox, QHBoxLayout, QScrollArea, QCheckBox, QVBoxLayout, QLabel +from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import QWidget, QGroupBox, QScrollArea, QCheckBox, QVBoxLayout, QLabel from custom_legendary.core import LegendaryCore from rare.components.tabs.shop import ShopApiCore from rare.components.tabs.shop.constants import Constants -from rare.components.tabs.shop.game_widgets import GameWidget, GameWidgetDiscount +from rare.components.tabs.shop.game_widgets import GameWidget from rare.components.tabs.shop.shop_models import BrowseModel from rare.ui.components.tabs.store.store import Ui_ShopWidget from rare.utils.extra_widgets import WaitingSpinner, FlowLayout, ButtonLineEdit @@ -38,12 +38,12 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): self.types = [] self.locale = get_lang() self.update_games_allowed = True - + self.free_widget.setLayout(FlowLayout()) self.free_games_now = QGroupBox(self.tr("Now Free")) self.free_games_now.setLayout(FlowLayout()) self.free_widget.layout().addWidget(self.free_games_now) self.coming_free_games = QGroupBox(self.tr("Free Games next week")) - self.coming_free_games.setLayout(QHBoxLayout()) + self.coming_free_games.setLayout(FlowLayout()) self.free_widget.layout().addWidget(self.coming_free_games) self.free_stack.addWidget(WaitingSpinner()) self.free_stack.setCurrentIndex(1) @@ -56,15 +56,11 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): self.game_stack.addWidget(WaitingSpinner()) self.game_stack.setCurrentIndex(1) - self.completer = QCompleter() - self.completer.setCaseSensitivity(Qt.CaseInsensitive) - self.search_bar = ButtonLineEdit("fa.search", placeholder_text=self.tr("Search Games")) self.layout().insertWidget(0, self.search_bar) # self.search_bar.textChanged.connect(self.search_games) - self.search_bar.setCompleter(self.completer) self.search_bar.returnPressed.connect(self.show_search_results) self.search_bar.buttonClicked.connect(self.show_search_results) @@ -91,7 +87,7 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): if not game: continue if game["offer"]["price"]["totalPrice"]["discount"] > 0: - w = GameWidgetDiscount(self.path, game["offer"]) + w = GameWidget(self.path, game["offer"]) w.show_info.connect(self.show_game.emit) self.discount_widget.layout().addWidget(w) discounts += 1 @@ -142,7 +138,7 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): coming_free_games.append(game) # free games now for free_game in free_games_now: - w = GameWidgetDiscount(self.path, free_game) + w = GameWidget(self.path, free_game) w.show_info.connect(self.show_game.emit) self.free_games_now.layout().addWidget(w) self.free_game_widgets.append(w) @@ -244,7 +240,13 @@ class ShopWidget(QScrollArea, Ui_ShopWidget): self.game_widget.setLayout(FlowLayout()) for game in data: - w = GameWidget(self.path, game, 275) + price = game['price']['totalPrice']['fmtPrice']['originalPrice'] + discount_price = game['price']['totalPrice']['fmtPrice']['discountPrice'] + + if price != discount_price: + w = GameWidget(self.path, game, 275) + else: + w = GameWidget(self.path, game, 275) self.game_widget.layout().addWidget(w) w.show_info.connect(self.show_game.emit) diff --git a/rare/ui/components/tabs/store/store.py b/rare/ui/components/tabs/store/store.py index 26c5e58f..00f33e1d 100644 --- a/rare/ui/components/tabs/store/store.py +++ b/rare/ui/components/tabs/store/store.py @@ -32,12 +32,22 @@ class Ui_ShopWidget(object): self.verticalLayout = QtWidgets.QVBoxLayout(self.widget) self.verticalLayout.setObjectName("verticalLayout") self.free_game_group_box = QtWidgets.QGroupBox(self.widget) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.free_game_group_box.sizePolicy().hasHeightForWidth()) + self.free_game_group_box.setSizePolicy(sizePolicy) self.free_game_group_box.setObjectName("free_game_group_box") self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.free_game_group_box) self.verticalLayout_3.setObjectName("verticalLayout_3") self.free_stack = QtWidgets.QStackedWidget(self.free_game_group_box) self.free_stack.setObjectName("free_stack") self.free_widget = QtWidgets.QWidget() + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.free_widget.sizePolicy().hasHeightForWidth()) + self.free_widget.setSizePolicy(sizePolicy) self.free_widget.setObjectName("free_widget") self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.free_widget) self.verticalLayout_8.setObjectName("verticalLayout_8") diff --git a/rare/ui/components/tabs/store/store.ui b/rare/ui/components/tabs/store/store.ui index d53748a1..b1ddb6ae 100644 --- a/rare/ui/components/tabs/store/store.ui +++ b/rare/ui/components/tabs/store/store.ui @@ -36,6 +36,12 @@ + + + 0 + 0 + + Free Games @@ -43,6 +49,13 @@ + + + 0 + 0 + +