2021-06-15 08:30:57 +12:00
|
|
|
from PyQt5.QtWidgets import QStackedWidget, QTabWidget
|
2021-06-04 09:23:55 +12:00
|
|
|
|
2021-09-07 07:10:18 +12:00
|
|
|
from legendary.core import LegendaryCore
|
2022-02-26 06:43:27 +13:00
|
|
|
from rare.shared import LegendaryCoreSingleton, ApiResultsSingleton
|
2022-02-17 12:04:53 +13:00
|
|
|
from rare.utils.paths import cache_dir
|
|
|
|
from .game_info import ShopGameInfo
|
|
|
|
from .search_results import SearchResults
|
|
|
|
from .shop_api_core import ShopApiCore
|
|
|
|
from .shop_widget import ShopWidget
|
|
|
|
from .wishlist import WishlistWidget, Wishlist
|
2021-06-04 09:23:55 +12:00
|
|
|
|
|
|
|
|
|
|
|
class Shop(QStackedWidget):
|
|
|
|
init = False
|
2021-06-05 04:16:27 +12:00
|
|
|
|
2021-06-15 08:30:57 +12:00
|
|
|
def __init__(self, core: LegendaryCore):
|
2021-06-04 09:23:55 +12:00
|
|
|
super(Shop, self).__init__()
|
2021-06-15 08:30:57 +12:00
|
|
|
self.core = core
|
2022-02-26 06:43:27 +13:00
|
|
|
self.api_results = ApiResultsSingleton()
|
2021-12-24 22:09:50 +13:00
|
|
|
self.api_core = ShopApiCore(
|
|
|
|
self.core.egs.session.headers["Authorization"],
|
|
|
|
self.core.language_code,
|
|
|
|
self.core.country_code,
|
|
|
|
)
|
2021-08-08 10:49:27 +12:00
|
|
|
|
2022-09-08 10:27:37 +12:00
|
|
|
self.shop = ShopWidget(cache_dir(), self.core, self.api_core)
|
2021-08-26 06:25:10 +12:00
|
|
|
self.wishlist_widget = Wishlist(self.api_core)
|
2021-06-15 08:30:57 +12:00
|
|
|
|
|
|
|
self.store_tabs = QTabWidget()
|
|
|
|
self.store_tabs.addTab(self.shop, self.tr("Games"))
|
2021-08-26 06:25:10 +12:00
|
|
|
self.store_tabs.addTab(self.wishlist_widget, self.tr("Wishlist"))
|
2021-06-04 09:23:55 +12:00
|
|
|
|
2021-06-15 08:30:57 +12:00
|
|
|
self.addWidget(self.store_tabs)
|
2021-06-04 09:23:55 +12:00
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
self.search_results = SearchResults(self.api_core)
|
2021-06-09 10:00:00 +12:00
|
|
|
self.addWidget(self.search_results)
|
|
|
|
self.search_results.show_info.connect(self.show_game_info)
|
2021-12-24 22:09:50 +13:00
|
|
|
self.info = ShopGameInfo(
|
2022-02-26 06:43:27 +13:00
|
|
|
[i.asset_infos["Windows"].namespace for i in self.api_results.game_list],
|
2021-12-24 22:09:50 +13:00
|
|
|
self.api_core,
|
|
|
|
)
|
2021-06-04 09:23:55 +12:00
|
|
|
self.addWidget(self.info)
|
2021-06-05 04:16:27 +12:00
|
|
|
self.info.back_button.clicked.connect(lambda: self.setCurrentIndex(0))
|
2021-06-04 09:23:55 +12:00
|
|
|
|
2021-06-11 05:58:35 +12:00
|
|
|
self.search_results.back_button.clicked.connect(lambda: self.setCurrentIndex(0))
|
2021-08-08 09:42:40 +12:00
|
|
|
self.shop.show_info.connect(self.show_search_results)
|
2021-08-23 08:22:17 +12:00
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
self.wishlist_widget.show_game_info.connect(self.show_game_info)
|
2021-06-09 10:00:00 +12:00
|
|
|
self.shop.show_game.connect(self.show_game_info)
|
2021-08-26 06:25:10 +12:00
|
|
|
self.api_core.update_wishlist.connect(self.update_wishlist)
|
|
|
|
self.wishlist_widget.update_wishlist_signal.connect(self.update_wishlist)
|
|
|
|
|
|
|
|
def update_wishlist(self):
|
|
|
|
self.shop.update_wishlist()
|
2021-06-04 09:23:55 +12:00
|
|
|
|
|
|
|
def load(self):
|
|
|
|
if not self.init:
|
|
|
|
self.init = True
|
|
|
|
self.shop.load()
|
2021-08-26 06:25:10 +12:00
|
|
|
self.wishlist_widget.update_wishlist()
|
2021-06-04 09:23:55 +12:00
|
|
|
|
2021-06-09 10:00:00 +12:00
|
|
|
def show_game_info(self, data):
|
|
|
|
self.info.update_game(data)
|
|
|
|
self.setCurrentIndex(2)
|
|
|
|
|
2021-08-08 09:42:40 +12:00
|
|
|
def show_search_results(self, text: str):
|
|
|
|
self.search_results.load_results(text)
|
2021-06-04 09:23:55 +12:00
|
|
|
self.setCurrentIndex(1)
|