1
0
Fork 0
mirror of synced 2024-05-18 11:32:50 +12:00
Rare/rare/components/tabs/store/__init__.py
loathingKernel f6396f488a
Store: Exploratory changes to the store page
Important changes:
* Refactored QtRequests to accept parameters for `GET` operations
* Infer response data type from content-type header
* Support caching to disk, a manager with this set prefers the cache
* Support multiple handlers for a single request (unused, possibly pointeless)

* Subclass `ShopImageWidget` for all widgets used in the shop
* Request a resized image instead of the original one
* Fix the search and browse functions
2024-02-25 21:35:43 +02:00

80 lines
2.9 KiB
Python

from legendary.core import LegendaryCore
from rare.shared import RareCore
from rare.utils.paths import cache_dir
from rare.widgets.side_tab import SideTabWidget
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
class StoreTab(SideTabWidget):
def __init__(self, core: LegendaryCore, parent=None):
super(StoreTab, self).__init__(parent=parent)
self.init = False
self.core = core
# self.rcore = RareCore.instance()
self.api_core = ShopApiCore(
self.core.egs.session.headers["Authorization"],
self.core.language_code,
self.core.country_code,
)
self.shop = ShopWidget(cache_dir(), self.core, self.api_core, parent=self)
self.shop_index = self.addTab(self.shop, self.tr("Store"))
self.shop.show_game.connect(self.show_game)
self.shop.show_info.connect(self.show_search)
self.search = SearchResults(self.api_core, parent=self)
self.search_index = self.addTab(self.search, self.tr("Search"), self.tr("Results"))
self.search.show_info.connect(self.show_game)
# 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)],
[],
self.api_core,
parent=self
)
self.info_index = self.addTab(self.info, self.tr("Information"), self.tr("Information"))
# self.info.back_button.clicked.connect(lambda: self.setCurrentIndex(self.previous_index))
self.wishlist = Wishlist(self.api_core, parent=self)
self.wishlist_index = self.addTab(self.wishlist, self.tr("Wishlist"), self.tr("Wishlist"))
self.wishlist.update_wishlist_signal.connect(self.update_wishlist)
self.wishlist.show_game_info.connect(self.show_game)
self.api_core.update_wishlist.connect(self.update_wishlist)
self.previous_index = self.shop_index
def showEvent(self, a0: QShowEvent) -> None:
if a0.spontaneous() or self.init:
return super().showEvent(a0)
self.shop.load()
self.wishlist_widget.update_wishlist()
self.init = True
return super().showEvent(a0)
def hideEvent(self, a0: QHideEvent) -> None:
if a0.spontaneous():
return super().hideEvent(a0)
# TODO: Implement store unloading
return super().hideEvent(a0)
def update_wishlist(self):
self.shop.update_wishlist()
def show_game(self, data):
self.previous_index = self.currentIndex()
self.info.update_game(data)
self.setCurrentIndex(self.info_index)
def show_search(self, text: str):
self.search.load_results(text)
self.setCurrentIndex(self.search_index)