1
0
Fork 0
mirror of synced 2024-07-04 22:21:21 +12:00
Rare/Rare/Components/Tabs/Games/GameList.py

167 lines
6.7 KiB
Python
Raw Normal View History

import os
from logging import getLogger
2021-03-09 03:07:07 +13:00
from PyQt5.QtCore import Qt, pyqtSignal, QSettings
from PyQt5.QtGui import QPixmap
2021-02-10 23:48:25 +13:00
from PyQt5.QtWidgets import *
2021-03-26 00:14:34 +13:00
from Rare.Components.Tabs.Games.GameWidgets.UninstalledListWidget import ListWidgetUninstalled
from Rare.Components.Tabs.Games.GameWidgets.UninstalledIconWidget import IconWidgetUninstalled
from Rare.Components.Tabs.Games.GameWidgets.InstalledIconWidget import GameWidgetInstalled
from Rare.Components.Tabs.Games.GameWidgets.InstalledListWidget import InstalledListWidget
2021-03-09 08:36:42 +13:00
from Rare.utils.Models import InstallOptions
2021-02-10 23:48:25 +13:00
from Rare.utils.QtExtensions import FlowLayout
from Rare.utils.utils import download_image
2021-03-19 00:45:59 +13:00
from custom_legendary.core import LegendaryCore
2021-02-10 23:48:25 +13:00
logger = getLogger("Game list")
2021-02-10 23:48:25 +13:00
class GameList(QStackedWidget):
2021-03-09 08:36:42 +13:00
install_game = pyqtSignal(InstallOptions)
2021-02-23 06:50:00 +13:00
show_game_info = pyqtSignal(str)
2021-03-09 05:20:28 +13:00
update_game = pyqtSignal()
2021-03-09 08:36:42 +13:00
2021-02-10 23:48:25 +13:00
def __init__(self, core: LegendaryCore):
super(GameList, self).__init__()
self.core = core
2021-02-18 05:46:03 +13:00
self.setObjectName("list_widget")
2021-02-10 23:48:25 +13:00
2021-03-09 03:07:07 +13:00
self.settings = QSettings()
icon_view = self.settings.value("icon_view", True, bool)
self.init_ui(icon_view)
def init_ui(self, icon_view=True):
self.icon_scrollarea = QScrollArea()
self.icon_widget = QWidget()
self.list_scrollarea = QScrollArea()
self.list_widget = QWidget()
self.icon_scrollarea.setWidgetResizable(True)
self.icon_scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
2021-03-09 03:07:07 +13:00
self.list_scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.icon_layout = FlowLayout()
self.list_layout = QVBoxLayout()
IMAGE_DIR = self.settings.value("img_dir", os.path.expanduser("~/.cache/rare"), str)
self.updates = []
self.widgets = {}
2021-03-26 02:15:18 +13:00
2021-02-18 05:46:03 +13:00
# Installed Games
2021-02-18 06:19:37 +13:00
for game in sorted(self.core.get_installed_list(), key=lambda x: x.title):
if os.path.exists(f"{IMAGE_DIR}/{game.app_name}/FinalArt.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/FinalArt.png")
elif os.path.exists(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png")
elif os.path.exists(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxLogo.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxLogo.png")
2021-03-09 03:07:07 +13:00
else:
logger.warning(f"No Image found: {game.title}")
pixmap = None
if pixmap.isNull():
logger.info(game.title + " has a corrupt image.")
download_image(game, force=True)
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/DieselGameBoxTall.png")
2021-03-26 02:15:18 +13:00
icon_widget = GameWidgetInstalled(game, self.core, pixmap)
list_widget = InstalledListWidget(game, self.core, pixmap)
icon_widget.show_info.connect(self.show_game_info.emit)
list_widget.show_info.connect(self.show_game_info.emit)
icon_widget.launch_signal.connect(self.launch)
2021-03-27 00:50:57 +13:00
icon_widget.finish_signal.connect(self.finished)
list_widget.launch_signal.connect(self.launch)
2021-03-27 00:50:57 +13:00
list_widget.launch_signal.connect(self.finished)
self.icon_layout.addWidget(icon_widget)
self.list_layout.addWidget(list_widget)
if icon_widget.update_available:
self.updates.append(game)
self.widgets[game.app_name] = (icon_widget, list_widget)
2021-02-10 23:48:25 +13:00
uninstalled_games = []
2021-02-18 05:46:03 +13:00
installed = [i.app_name for i in self.core.get_installed_list()]
# get Uninstalled games
for game in sorted(self.core.get_game_list(), key=lambda x: x.app_title):
2021-02-10 23:48:25 +13:00
if not game.app_name in installed:
uninstalled_games.append(game)
2021-02-18 05:46:03 +13:00
for game in uninstalled_games:
if os.path.exists(f"{IMAGE_DIR}/{game.app_name}/UninstalledArt.png"):
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
if pixmap.isNull():
logger.info(game.app_title + " has a corrupt image.")
download_image(game, force=True)
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
2021-03-09 03:07:07 +13:00
else:
logger.warning(f"No Image found: {self.game.app_title}")
download_image(game, force=True)
pixmap = QPixmap(f"{IMAGE_DIR}/{game.app_name}/UninstalledArt.png")
icon_widget = IconWidgetUninstalled(game, self.core, pixmap)
icon_widget.install_game.connect(self.install_game.emit)
2021-03-26 02:15:18 +13:00
list_widget = ListWidgetUninstalled(self.core, game, pixmap)
list_widget.install_game.connect(self.install_game.emit)
self.icon_layout.addWidget(icon_widget)
self.list_layout.addWidget(list_widget)
self.widgets[game.app_name] = (icon_widget, list_widget)
2021-03-26 02:15:18 +13:00
self.list_layout.addStretch(1)
self.icon_widget.setLayout(self.icon_layout)
self.list_widget.setLayout(self.list_layout)
self.icon_scrollarea.setWidget(self.icon_widget)
self.list_scrollarea.setWidget(self.list_widget)
self.addWidget(self.icon_scrollarea)
self.addWidget(self.list_scrollarea)
if not icon_view:
self.setCurrentIndex(1)
2021-03-26 02:15:18 +13:00
if self.settings.value("installed_only", False, bool):
self.installed_only(True)
2021-03-27 00:50:57 +13:00
def finished(self, app_name):
self.widgets[app_name][0].info_text = ""
self.widgets[app_name][0].info_label.setText("")
self.widgets[app_name][1].launch_button.setDisabled(False)
self.widgets[app_name][1].launch_button.setText(self.tr("Launch"))
def launch(self, app_name):
self.widgets[app_name][0].info_text = self.tr("Game running")
self.widgets[app_name][1].launch_button.setDisabled(True)
self.widgets[app_name][1].launch_button.setText(self.tr("Game running"))
2021-02-10 23:48:25 +13:00
def filter(self, text: str):
for t in self.widgets.values():
for w in t:
2021-03-26 00:14:34 +13:00
if text.lower() in w.game.app_title.lower() + w.game.app_name.lower():
w.setVisible(True)
else:
w.setVisible(False)
def installed_only(self, i_o: bool):
for t in self.widgets.values():
for w in t:
w.setVisible(not (not self.core.is_installed(w.game.app_name) and i_o))
2021-03-26 02:15:18 +13:00
self.settings.setValue("installed_only", i_o)
2021-02-18 05:46:03 +13:00
2021-03-09 03:07:07 +13:00
def update_list(self, icon_view=True):
self.settings.setValue("icon_view", icon_view)
self.removeWidget(self.icon_scrollarea)
self.removeWidget(self.list_scrollarea)
2021-03-09 03:07:07 +13:00
self.init_ui(icon_view)
2021-02-23 06:50:00 +13:00
self.update()