117 lines
5.1 KiB
Python
117 lines
5.1 KiB
Python
|
import os
|
||
|
|
||
|
from PyQt5.QtCore import pyqtSignal, QSettings, QSize
|
||
|
from PyQt5.QtGui import QPixmap
|
||
|
from PyQt5.QtWidgets import QFrame, QWidget, QMessageBox
|
||
|
|
||
|
from legendary.core import LegendaryCore
|
||
|
from legendary.models.game import Game
|
||
|
from rare import data_dir
|
||
|
from rare.utils.utils import download_image
|
||
|
from rare.ui.components.tabs.games.game_info.game_dlc import Ui_GameDlc
|
||
|
from rare.ui.components.tabs.games.game_info.game_dlc_widget import Ui_GameDlcWidget
|
||
|
|
||
|
|
||
|
class GameDlc(QWidget, Ui_GameDlc):
|
||
|
install_dlc = pyqtSignal(str, bool)
|
||
|
game: Game
|
||
|
|
||
|
def __init__(self, core: LegendaryCore, parent=None):
|
||
|
super(GameDlc, self).__init__(parent=parent)
|
||
|
self.setupUi(self)
|
||
|
self.core = core
|
||
|
self.installed_dlcs = list()
|
||
|
self.installed_dlc_widgets = list()
|
||
|
self.available_dlc_widgets = list()
|
||
|
|
||
|
def update_dlcs(self, app_name, dlcs: list):
|
||
|
self.game = self.core.get_game(app_name)
|
||
|
self.game_title.setText(f"<h2>{self.game.app_title}</h2>")
|
||
|
|
||
|
if self.installed_dlc_widgets:
|
||
|
for dlc_widget in self.installed_dlc_widgets:
|
||
|
dlc_widget.deleteLater()
|
||
|
self.installed_dlc_widgets.clear()
|
||
|
if self.available_dlc_widgets:
|
||
|
for dlc_widget in self.available_dlc_widgets:
|
||
|
dlc_widget.install.disconnect()
|
||
|
dlc_widget.deleteLater()
|
||
|
self.available_dlc_widgets.clear()
|
||
|
|
||
|
self.installed_dlcs = [i.app_name for i in self.core.get_installed_dlc_list()]
|
||
|
|
||
|
for dlc in sorted(dlcs[self.game.asset_info.catalog_item_id], key=lambda x: x.app_title):
|
||
|
if dlc.app_name in self.installed_dlcs:
|
||
|
dlc_widget = GameDlcWidget(dlc, True)
|
||
|
self.installed_dlc_widgets.append(dlc_widget)
|
||
|
self.installed_dlc_contents_layout.addWidget(dlc_widget)
|
||
|
else:
|
||
|
dlc_widget = GameDlcWidget(dlc, False)
|
||
|
dlc_widget.install.connect(self.install)
|
||
|
self.available_dlc_widgets.append(dlc_widget)
|
||
|
self.available_dlc_contents_layout.addWidget(dlc_widget)
|
||
|
|
||
|
self.installed_dlc_label.setVisible(not self.installed_dlc_widgets)
|
||
|
self.installed_dlc_scroll.setVisible(bool(self.installed_dlc_widgets))
|
||
|
|
||
|
self.available_dlc_label.setVisible(not self.available_dlc_widgets)
|
||
|
self.available_dlc_scroll.setVisible(bool(self.available_dlc_widgets))
|
||
|
|
||
|
def install(self, app_name):
|
||
|
if not self.core.is_installed(self.game.app_name):
|
||
|
QMessageBox.warning(self, "Error", self.tr("Base Game is not installed. Please install {} first").format(
|
||
|
self.game.app_title))
|
||
|
return
|
||
|
self.install_dlc.emit(app_name, True)
|
||
|
|
||
|
|
||
|
class GameDlcWidget(QFrame, Ui_GameDlcWidget):
|
||
|
install = pyqtSignal(str) # Appname
|
||
|
|
||
|
def __init__(self, dlc: Game, installed: bool, parent=None):
|
||
|
super(GameDlcWidget, self).__init__(parent=parent)
|
||
|
self.setupUi(self)
|
||
|
self.dlc = dlc
|
||
|
image_dir = QSettings().value("img_dir", os.path.join(data_dir, "images"))
|
||
|
|
||
|
if installed:
|
||
|
if os.path.exists(os.path.join(image_dir, dlc.app_name, "FinalArt.png")):
|
||
|
pixmap = QPixmap(os.path.join(image_dir, dlc.app_name, "FinalArt.png"))
|
||
|
elif os.path.exists(os.path.join(image_dir, dlc.app_name, "DieselGameBoxTall.png")):
|
||
|
pixmap = QPixmap(os.path.join(image_dir, dlc.app_name, "DieselGameBoxTall.png"))
|
||
|
elif os.path.exists(os.path.join(image_dir, dlc.app_name, "DieselGameBoxLogo.png")):
|
||
|
pixmap = QPixmap(os.path.join(image_dir, dlc.app_name, "DieselGameBoxLogo.png"))
|
||
|
else:
|
||
|
print(f"No Image found: {dlc.app_title}")
|
||
|
pixmap = None
|
||
|
if not pixmap or pixmap.isNull():
|
||
|
print(dlc.app_title + " has corrupt Image")
|
||
|
download_image(dlc, force=True)
|
||
|
pixmap = QPixmap(f"{image_dir}/{dlc.app_name}/UninstalledArt.png")
|
||
|
else:
|
||
|
if os.path.exists(f"{image_dir}/{dlc.app_name}/UninstalledArt.png"):
|
||
|
pixmap = QPixmap(f"{image_dir}/{dlc.app_name}/DieselGameBoxTall.png")
|
||
|
else:
|
||
|
pixmap = None
|
||
|
if not pixmap or pixmap.isNull():
|
||
|
print(dlc.app_title + " has corrupt Image")
|
||
|
download_image(dlc, force=True)
|
||
|
pixmap = QPixmap(f"{image_dir}/{dlc.app_name}/UninstalledArt.png")
|
||
|
self.image.setPixmap(pixmap.scaledToHeight(pixmap.height()*0.5))
|
||
|
|
||
|
self.dlc_name.setText(dlc.app_title)
|
||
|
self.version.setText(dlc.app_version)
|
||
|
self.app_name.setText(dlc.app_name)
|
||
|
|
||
|
if not installed:
|
||
|
self.install_button.clicked.connect(lambda: self.install.emit(dlc.app_name))
|
||
|
self.status.setText(self.tr("Not installed"))
|
||
|
else:
|
||
|
self.status.setText(self.tr("Installed. Uninstalling DLCs is not supported"))
|
||
|
self.install_button.setVisible(not installed)
|
||
|
|
||
|
def install_game(self):
|
||
|
self.install_button.setDisabled(True)
|
||
|
self.install_button.setText(self.tr("Installing"))
|
||
|
self.install.emit(self.dlc.app_name)
|