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
|
2021-08-08 10:49:27 +12:00
|
|
|
from rare import cache_dir
|
2021-08-23 08:22:17 +12:00
|
|
|
from rare.components.tabs.shop.game_info import ShopGameInfo
|
2021-06-09 10:00:00 +12:00
|
|
|
from rare.components.tabs.shop.search_results import SearchResults
|
2021-08-23 08:22:17 +12:00
|
|
|
from rare.components.tabs.shop.shop_api_core import ShopApiCore
|
2021-06-04 09:23:55 +12:00
|
|
|
from rare.components.tabs.shop.shop_widget import ShopWidget
|
2021-08-26 06:25:10 +12:00
|
|
|
from rare.components.tabs.shop.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
|
2021-09-14 06:24:09 +12: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
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
self.shop = ShopWidget(cache_dir, core, self.api_core)
|
|
|
|
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-08-25 10:01:53 +12:00
|
|
|
# self.store_tabs.addTab(self.browse_games, self.tr("Browse"))
|
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-08-26 06:25:10 +12:00
|
|
|
self.info = ShopGameInfo([i.asset_info.namespace for i in self.core.get_game_list(True)], 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)
|