1
0
Fork 0
mirror of synced 2024-09-30 01:07:47 +13:00

Fix installing game widget, which displays progress wrong; update get_uninstalled_pixmap()

This commit is contained in:
Dummerle 2021-12-01 20:14:41 +01:00
parent 2f959249ba
commit 31932aa8a0
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
3 changed files with 36 additions and 32 deletions

View file

@ -8,7 +8,7 @@ import rare.shared as shared
from legendary.models.game import InstalledGame from legendary.models.game import InstalledGame
from rare.ui.components.tabs.games.games_tab import Ui_GamesTab from rare.ui.components.tabs.games.games_tab import Ui_GamesTab
from rare.utils.extra_widgets import FlowLayout from rare.utils.extra_widgets import FlowLayout
from rare.utils.utils import get_pixmap, download_image from rare.utils.utils import get_pixmap, download_image, get_uninstalled_pixmap
from .cloud_save_utils import CloudSaveUtils from .cloud_save_utils import CloudSaveUtils
from .cloud_save_utils import CloudSaveUtils from .cloud_save_utils import CloudSaveUtils
from .game_info import GameInfoTabs from .game_info import GameInfoTabs
@ -110,7 +110,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
game = self.core.get_game(app_name, False) game = self.core.get_game(app_name, False)
if game.is_dlc: if game.is_dlc:
return return
self.installing_widget.set_game(game) self.installing_widget.set_game(app_name)
self.installing_widget.setVisible(True) self.installing_widget.setVisible(True)
def verification_finished(self, igame: InstalledGame): def verification_finished(self, igame: InstalledGame):
@ -197,10 +197,7 @@ class GamesTab(QStackedWidget, Ui_GamesTab):
return icon_widget, list_widget return icon_widget, list_widget
def add_uninstalled_widget(self, game): def add_uninstalled_widget(self, game):
pixmap = get_pixmap(game.app_name) pixmap = get_uninstalled_pixmap(game.app_name)
img = pixmap.toImage()
img = img.convertToFormat(QImage.Format_Grayscale8)
pixmap = QPixmap.fromImage(img)
if pixmap.isNull(): if pixmap.isNull():
logger.warning(game.app_title + " has a corrupt image. Reloading...") logger.warning(game.app_title + " has a corrupt image. Reloading...")
download_image(game, force=True) download_image(game, force=True)

View file

@ -2,8 +2,8 @@ from PyQt5.QtCore import Qt, QRect
from PyQt5.QtGui import QPaintEvent, QPainter, QPixmap, QPen, QFont, QColor from PyQt5.QtGui import QPaintEvent, QPainter, QPixmap, QPen, QFont, QColor
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QHBoxLayout, QWidget from PyQt5.QtWidgets import QVBoxLayout, QLabel, QHBoxLayout, QWidget
from legendary.models.game import Game from rare import shared
from rare.utils.utils import get_pixmap, get_uninstalled_pixmap, optimal_text_background, text_color_for_background from rare.utils.utils import get_pixmap, optimal_text_background, text_color_for_background, get_uninstalled_pixmap
class InstallingGameWidget(QWidget): class InstallingGameWidget(QWidget):
@ -30,43 +30,52 @@ class InstallingGameWidget(QWidget):
minilayout.addWidget(self.title_label) minilayout.addWidget(self.title_label)
self.layout().addLayout(minilayout) self.layout().addLayout(minilayout)
def set_game(self, game: Game): def set_game(self, app_name):
game = shared.core.get_game(app_name)
self.title_label.setText(f"<h4>{game.app_title}</h4>") self.title_label.setText(f"<h4>{game.app_title}</h4>")
self.pixmap = get_pixmap(game.app_name)
w = 200 self.image_widget.set_game(game.app_name)
self.pixmap = self.pixmap.scaled(w, int(w * 4 / 3), transformMode=Qt.SmoothTransformation)
self.image_widget.set_game(self.pixmap, game.app_name)
def set_status(self, s: int): def set_status(self, s: int):
self.image_widget.status = s self.image_widget.progress = s
self.image_widget.repaint() self.image_widget.repaint()
class PaintWidget(QWidget): class PaintWidget(QWidget):
color_image: QPixmap
bw_image: QPixmap
progress: int = 0
def __init__(self): def __init__(self):
super(PaintWidget, self).__init__() super(PaintWidget, self).__init__()
def set_game(self, pixmap: QPixmap, app_name): def set_game(self, app_name: str):
self.image = pixmap game = shared.core.get_game(app_name, False)
self.setFixedSize(self.image.size()) self.color_image = get_pixmap(game.app_name)
self.new_image = get_uninstalled_pixmap(app_name) w = 200
self.status = 0 self.color_image = self.color_image.scaled(w, int(w * 4 // 3), transformMode=Qt.SmoothTransformation)
self.setFixedSize(self.color_image.size())
self.bw_image = get_uninstalled_pixmap(app_name)
self.bw_image = self.bw_image.scaled(w, int(w * 4 // 3), transformMode=Qt.SmoothTransformation)
self.progress = 0
pixel_list = [] pixel_list = []
for x in range(self.image.width()): for x in range(self.color_image.width()):
for y in range(self.image.height()): for y in range(self.color_image.height()):
# convert pixmap to qimage, get pixel and remove alpha channel # convert pixmap to qimage, get pixel and remove alpha channel
pixel_list.append(self.image.toImage().pixelColor(x, y).getRgb()[:-1]) pixel_list.append(self.color_image.toImage().pixelColor(x, y).getRgb()[:-1])
self.rgb_tuple = optimal_text_background(pixel_list) self.rgb_tuple = optimal_text_background(pixel_list)
def paintEvent(self, a0: QPaintEvent) -> None: def paintEvent(self, a0: QPaintEvent) -> None:
painter = QPainter() painter = QPainter()
painter.begin(self) painter.begin(self)
painter.drawPixmap(self.rect(), self.image) painter.drawPixmap(self.rect(), self.bw_image)
w = self.image.width() * (1 - self.status // 100) w = self.bw_image.width() * self.progress // 100
painter.drawPixmap(self.image.width() - w, 0, w, self.image.height(),
self.new_image.copy(QRect(self.image.width() - w, 0, w, self.image.height()))) painter.drawPixmap(0, 0, w, self.color_image.height(),
self.color_image.copy(QRect(0, 0, w, self.color_image.height())))
# Draw Circle # Draw Circle
pen = QPen(QColor(*self.rgb_tuple), 3) pen = QPen(QColor(*self.rgb_tuple), 3)
@ -77,5 +86,5 @@ class PaintWidget(QWidget):
# draw text # draw text
painter.setPen(QColor(*text_color_for_background(self.rgb_tuple))) painter.setPen(QColor(*text_color_for_background(self.rgb_tuple)))
painter.setFont(QFont(None, 16)) painter.setFont(QFont(None, 16))
painter.drawText(a0.rect(), Qt.AlignCenter, str(self.status) + "%") painter.drawText(a0.rect(), Qt.AlignCenter, str(self.progress) + "%")
painter.end() painter.end()

View file

@ -363,11 +363,9 @@ def get_pixmap(app_name: str) -> QPixmap:
def get_uninstalled_pixmap(app_name: str) -> QPixmap: def get_uninstalled_pixmap(app_name: str) -> QPixmap:
if os.path.exists(image := os.path.join(image_dir, app_name, "UninstalledArt.png")): pm = get_pixmap(app_name)
pixmap = QPixmap(image) grey_image = pm.toImage().convertToFormat(QImage.Format_Grayscale8)
else: return QPixmap.fromImage(grey_image)
pixmap = QPixmap()
return pixmap
def optimal_text_background(image: list) -> Tuple[int, int, int]: def optimal_text_background(image: list) -> Tuple[int, int, int]: