Update to 0.1.5-alpha
- Add profile icon and launch background customization. Apply same image limitation as official Launcher. - Add game file hash verification settings. - Update CoreLib download library hash verification handling. CoreLib update to v0.1.8
This commit is contained in:
1 parent
fcd61b3755
commit
ca1eac5eb9
19 files changed
+479
-99
No files matched your search
+22
-23
@@ -8,8 +8,9 @@ from PySide6.QtWidgets import (QWidget, QVBoxLayout, QLabel, QHBoxLayout, QPushB
|
||||
from core_lib.qt.item_button import ItemButton
|
||||
from manager.game import LaunchManager, LaunchResult
|
||||
from core_lib.game.version_info import LATEST_VERSION_ALIASES
|
||||
from manager.profile import ProfileSummary, LaunchProfile, ProfileManager
|
||||
from manager.profile import ProfileSummary, LaunchProfile, ProfileManager, _profile_icon
|
||||
from manager.widgets import AskForRequest, WidgetManager
|
||||
from manager.settings_models import AppearanceSettings
|
||||
from pages.process_log import ProcessLogWindow
|
||||
|
||||
|
||||
@@ -68,16 +69,8 @@ class ProfileButton(QFrame):
|
||||
self.name_label.setText(profile.display_name)
|
||||
self.version_label.setText(profile.version_id)
|
||||
|
||||
icon_path = profile.icon
|
||||
|
||||
if not isinstance(icon_path, Path):
|
||||
icon_path = Path(icon_path)
|
||||
|
||||
if not icon_path.exists() or not icon_path.is_file():
|
||||
# Use default
|
||||
icon_path = Path(self.app.icon_dir, "profile_default.png")
|
||||
|
||||
self.icon_label.setPixmap(QIcon(icon_path.as_posix()).pixmap(36, 36))
|
||||
icon = profile.icon
|
||||
self.icon_label.setPixmap(_profile_icon(icon, self.app.icon_dir).pixmap(36, 36))
|
||||
|
||||
def set_popup_open(self, opened: bool) -> None:
|
||||
self.arrow_label.setText("▴" if opened else "▾")
|
||||
@@ -121,8 +114,8 @@ class ProfileListItem(ItemButton):
|
||||
layout.addLayout(text_layout, 1)
|
||||
self.clicked.connect(lambda: self.selected.emit(self.profile))
|
||||
|
||||
def set_icon(self, icon_path: Path) -> None:
|
||||
self.icon_label.setPixmap(QIcon(icon_path.as_posix()).pixmap(36, 36))
|
||||
def set_icon(self, icon: QPixmap) -> None:
|
||||
self.icon_label.setPixmap(icon)
|
||||
|
||||
class ProfilePopup(QFrame):
|
||||
profile_selected = Signal(object)
|
||||
@@ -166,18 +159,9 @@ class ProfilePopup(QFrame):
|
||||
self.clean_profiles()
|
||||
|
||||
for profile in profiles:
|
||||
icon_path = profile.icon
|
||||
|
||||
if not isinstance(icon_path, Path):
|
||||
icon_path = Path(icon_path)
|
||||
|
||||
if not icon_path.exists() or not icon_path.is_file():
|
||||
# Use default
|
||||
icon_path = Path(self.app.icon_dir, "profile_default.png")
|
||||
|
||||
item = ProfileListItem(profile, self)
|
||||
item.selected.connect(self.profile_selected)
|
||||
item.set_icon(icon_path)
|
||||
item.set_icon(_profile_icon(profile.icon, self.app.icon_dir).pixmap(36, 36))
|
||||
self.content_layout.addWidget(item)
|
||||
|
||||
def clean_profiles(self) -> None:
|
||||
@@ -293,11 +277,26 @@ class LaunchProfilePage(QWidget):
|
||||
self.load_profiles,
|
||||
)
|
||||
|
||||
def showEvent(self, event):
|
||||
super().showEvent(event)
|
||||
appearance = self.app.settings_manager.get("appearance", AppearanceSettings)
|
||||
self.profile_frame.set_background(
|
||||
appearance.launch_background,
|
||||
Path(self.app.icon_dir, "profile_default.png"),
|
||||
)
|
||||
|
||||
class ProfileBackgroundFrame(QFrame):
|
||||
def __init__(self, image_path, parent=None):
|
||||
super().__init__(parent)
|
||||
self.background = QPixmap(str(image_path))
|
||||
|
||||
def set_background(self, path, default_path):
|
||||
background = QPixmap(str(path)) if path else QPixmap()
|
||||
if background.isNull():
|
||||
background = QPixmap(str(default_path))
|
||||
self.background = background
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, event):
|
||||
super().paintEvent(event)
|
||||
|
||||
|
||||
+73
-9
@@ -3,15 +3,16 @@ from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from PySide6.QtCore import Qt, QUrl, Signal
|
||||
from PySide6.QtGui import QDesktopServices, QIcon
|
||||
from PySide6.QtGui import QDesktopServices, QImageReader
|
||||
from PySide6.QtWidgets import (
|
||||
QFileDialog, QFormLayout, QFrame, QHBoxLayout, QLabel, QLineEdit,
|
||||
QMessageBox, QPushButton, QScrollArea, QSizePolicy, QSpinBox,
|
||||
QVBoxLayout, QWidget, QMenu, QComboBox, QTabWidget,
|
||||
)
|
||||
|
||||
from core_lib.qt.hack import base64_to_qicon, prepare_profile_icon
|
||||
from core_lib.qt.item_button import ItemButton
|
||||
from manager.profile import ProfileDetail, ProfileManager, ProfileSummary, UpdateProfileRequest
|
||||
from manager.profile import ProfileDetail, ProfileManager, ProfileSummary, UpdateProfileRequest, _profile_icon
|
||||
from manager.game import AvailableVersion
|
||||
from pages.add_modded_version import AddModdedVersionDialog
|
||||
|
||||
@@ -41,12 +42,9 @@ class ManageProfileItem(ItemButton):
|
||||
layout.setContentsMargins(12, 8, 12, 8)
|
||||
layout.setSpacing(12)
|
||||
|
||||
icon_path = Path(profile.icon)
|
||||
if not icon_path.is_file():
|
||||
icon_path = Path(app.icon_dir, "profile_default.png")
|
||||
icon = QLabel()
|
||||
icon.setFixedSize(40, 40)
|
||||
icon.setPixmap(QIcon(icon_path.as_posix()).pixmap(36, 36))
|
||||
icon.setPixmap(_profile_icon(profile.icon, app.icon_dir).pixmap(36, 36))
|
||||
icon.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
texts = QVBoxLayout()
|
||||
@@ -91,6 +89,7 @@ class ManageProfileItem(ItemButton):
|
||||
menu.exec(global_position)
|
||||
|
||||
|
||||
|
||||
class ManageProfilePage(QWidget):
|
||||
"""
|
||||
Profile manage page
|
||||
@@ -109,6 +108,7 @@ class ManageProfilePage(QWidget):
|
||||
self.app = app
|
||||
self.profile_manager: ProfileManager = app.profile_manager
|
||||
self.manifest_manager = app.game_manager.manifest
|
||||
self.widget_manager = app.widget_manager
|
||||
self.selected_profile_id: str | None = None
|
||||
self.profile_items: dict[str, ManageProfileItem] = {}
|
||||
self.version_options: list[AvailableVersion] = []
|
||||
@@ -157,7 +157,26 @@ class ManageProfilePage(QWidget):
|
||||
form.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
|
||||
form.setVerticalSpacing(12)
|
||||
|
||||
# Icon & Name
|
||||
self.profile_icon = QLabel()
|
||||
self.profile_icon.setFixedSize(64, 64)
|
||||
self.profile_icon.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.name_edit = QLineEdit()
|
||||
self.replace_icon_btn = QPushButton(self.app.tr_text("Replace Icon"))
|
||||
self.reset_icon_btn = QPushButton(self.app.tr_text("Reset Icon"))
|
||||
self.reset_icon_btn.clicked.connect(self._reset_icon)
|
||||
|
||||
profile_head_h_layout = QHBoxLayout()
|
||||
profile_head_v_layout = QVBoxLayout()
|
||||
|
||||
profile_head_v_layout.addWidget(self.name_edit)
|
||||
icon_actions = QHBoxLayout()
|
||||
icon_actions.addWidget(self.replace_icon_btn)
|
||||
icon_actions.addWidget(self.reset_icon_btn)
|
||||
profile_head_v_layout.addLayout(icon_actions)
|
||||
profile_head_h_layout.addWidget(self.profile_icon)
|
||||
profile_head_h_layout.addLayout(profile_head_v_layout)
|
||||
|
||||
self.version_dropdown = QComboBox()
|
||||
self.version_dropdown.setObjectName("Dropdown")
|
||||
self.version_dropdown.setSizePolicy(
|
||||
@@ -172,22 +191,22 @@ class ManageProfilePage(QWidget):
|
||||
self.type_dropdown.setObjectName("Dropdown")
|
||||
self.game_dir_edit = QLineEdit()
|
||||
self.java_args_edit = QLineEdit()
|
||||
self.icon_edit = QLineEdit()
|
||||
self.icon_edit = QLineEdit(self.editor)
|
||||
self.icon_edit.hide()
|
||||
self.width_spin = self._dimension_spin()
|
||||
self.height_spin = self._dimension_spin()
|
||||
|
||||
form.addRow(self.app.tr_text("Profile name"), self.name_edit)
|
||||
form.addRow(self.app.tr_text("Type"), self.type_dropdown)
|
||||
form.addRow(self.app.tr_text("Version"), self.version_dropdown)
|
||||
form.addRow(self.app.tr_text("Game directory"), self.game_dir_edit)
|
||||
form.addRow(self.app.tr_text("Java arguments"), self.java_args_edit)
|
||||
form.addRow(self.app.tr_text("Icon"), self.icon_edit)
|
||||
|
||||
resolution = QHBoxLayout()
|
||||
resolution.addWidget(self.width_spin)
|
||||
resolution.addWidget(QLabel("×"))
|
||||
resolution.addWidget(self.height_spin)
|
||||
form.addRow(self.app.tr_text("Resolution"), resolution)
|
||||
editor_layout.addLayout(profile_head_h_layout)
|
||||
editor_layout.addLayout(form)
|
||||
|
||||
file_actions = QHBoxLayout()
|
||||
@@ -228,6 +247,7 @@ class ManageProfilePage(QWidget):
|
||||
|
||||
self.type_dropdown.currentIndexChanged.connect(self._filter_versions)
|
||||
self.profile_manager.profiles_changed.connect(self.refresh_profiles)
|
||||
self.replace_icon_btn.clicked.connect(self._replace_icon)
|
||||
self.app.apply_qss(Path("manage_profile.qss"), self.setStyleSheet)
|
||||
self._load_type_dropdown()
|
||||
self.refresh_profiles()
|
||||
@@ -361,6 +381,9 @@ class ManageProfilePage(QWidget):
|
||||
|
||||
def _set_detail(self, profile: ProfileDetail) -> None:
|
||||
self.name_edit.setText(profile.name)
|
||||
profile_icon = _profile_icon(profile.icon, self.app.icon_dir)
|
||||
self.profile_icon.setPixmap(profile_icon.pixmap(64, 64))
|
||||
|
||||
option = next(
|
||||
(item for item in self.version_options if item.id == profile.version_id),
|
||||
None,
|
||||
@@ -611,3 +634,44 @@ class ManageProfilePage(QWidget):
|
||||
cleanup()
|
||||
raise
|
||||
return cleanup
|
||||
|
||||
def _reset_icon(self):
|
||||
if self.selected_profile_id is None:
|
||||
return
|
||||
self.icon_edit.clear()
|
||||
self.profile_icon.setPixmap(_profile_icon("", self.app.icon_dir).pixmap(64, 64))
|
||||
|
||||
def _replace_icon(self):
|
||||
profile_id = self.selected_profile_id
|
||||
|
||||
if not profile_id or self.profile_manager.get_profile(profile_id) is None:
|
||||
self.widget_manager.signal.show_warning_message.emit(
|
||||
self.app.tr_text("Select a profile before replacing the icon")
|
||||
)
|
||||
return
|
||||
|
||||
formats = " ".join(
|
||||
"*." + bytes(fmt).decode("ascii")
|
||||
for fmt in QImageReader.supportedImageFormats()
|
||||
)
|
||||
filename, _ = QFileDialog.getOpenFileName(
|
||||
self, self.app.tr_text("Replace Icon"), "",
|
||||
self.app.tr_text("Images") + f" ({formats});;" + self.app.tr_text("All files") + " (*)",
|
||||
)
|
||||
if not filename:
|
||||
return
|
||||
try:
|
||||
path = Path(filename)
|
||||
value, resized = prepare_profile_icon(path)
|
||||
icon = base64_to_qicon(value)
|
||||
if icon.isNull():
|
||||
raise ValueError(self.app.tr_text("Image format is not supported."))
|
||||
except (OSError, ValueError) as error:
|
||||
self.widget_manager.signal.show_error_message.emit(self.app.tr_text(str(error)))
|
||||
return
|
||||
if resized:
|
||||
self.widget_manager.signal.show_info_message.emit(self.app.tr_text(
|
||||
"This image exceeds 128 x 128 pixels and will be resized to 128 x 128."
|
||||
))
|
||||
self.icon_edit.setText(value)
|
||||
self.profile_icon.setPixmap(icon.pixmap(64, 64))
|
||||
+85
-3
@@ -2,8 +2,9 @@ import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QImageReader, QPixmap
|
||||
from PySide6.QtWidgets import (
|
||||
QComboBox,
|
||||
QComboBox, QCheckBox, QFileDialog,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
@@ -18,7 +19,7 @@ from PySide6.QtWidgets import (
|
||||
from constant import LAUNCHER_NAME, LAUNCHER_VERSION, LAUNCHER_DESCRIPTION_KEYWORD, \
|
||||
LAUNCHER_DESCRIPTION_MARKDOWN, LAUNCHER_DESCRIPTION_MARKDOWN_KEYWORD
|
||||
from core_lib.qt import messagebox
|
||||
from manager.settings_models import AccountSettings, AppearanceSettings, GeneralSettings
|
||||
from manager.settings_models import AccountSettings, AppearanceSettings, GeneralSettings, GameSettings
|
||||
from pages.plugins import PluginsDialog
|
||||
|
||||
LANGUAGE_LABELS = {
|
||||
@@ -104,6 +105,7 @@ class SettingsPage(QWidget):
|
||||
|
||||
self.main_page = self._create_main_page()
|
||||
self.general_page = self._create_general_page()
|
||||
self.game_page = self._create_game_page()
|
||||
self.appearance_page = self._create_appearance_page()
|
||||
self.account_page = self._create_account_page()
|
||||
self.about_page = self._create_about_page()
|
||||
@@ -111,6 +113,7 @@ class SettingsPage(QWidget):
|
||||
for page in (
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.game_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
@@ -147,12 +150,14 @@ class SettingsPage(QWidget):
|
||||
|
||||
self.main_page = self._create_main_page()
|
||||
self.general_page = self._create_general_page()
|
||||
self.game_page = self._create_game_page()
|
||||
self.appearance_page = self._create_appearance_page()
|
||||
self.account_page = self._create_account_page()
|
||||
self.about_page = self._create_about_page()
|
||||
for page in (
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.game_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
@@ -189,6 +194,7 @@ class SettingsPage(QWidget):
|
||||
|
||||
pages = (
|
||||
(tr("General"), tr("Language and launcher directories"), "general_page"),
|
||||
(tr("Game"), tr("Game file hash verification"), "game_page"),
|
||||
(tr("Appearance"), tr("Launcher theme"), "appearance_page"),
|
||||
(tr("Account"), tr("Microsoft authentication settings"), "account_page"),
|
||||
(tr("About"), tr("Version and project information"), "about_page"),
|
||||
@@ -239,6 +245,19 @@ class SettingsPage(QWidget):
|
||||
page.content_layout.addWidget(self.language_combo)
|
||||
return page
|
||||
|
||||
def _create_game_page(self) -> QWidget:
|
||||
tr = self.app.tr_text
|
||||
page = SettingsSubPage(tr("Game"), self._go_back)
|
||||
current = self.settings.get("game", GameSettings)
|
||||
self.verify_hash_on_download = QCheckBox(tr("Verify file hashes when downloading"))
|
||||
self.verify_hash_on_download.setChecked(current.verify_hash_on_download)
|
||||
self.verify_hash_on_launch = QCheckBox(tr("Verify library hashes before launch"))
|
||||
self.verify_hash_on_launch.setChecked(current.verify_hash_on_launch)
|
||||
for checkbox in (self.verify_hash_on_download, self.verify_hash_on_launch):
|
||||
checkbox.toggled.connect(self._mark_settings_dirty)
|
||||
page.content_layout.addWidget(checkbox)
|
||||
return page
|
||||
|
||||
def _create_appearance_page(self) -> QWidget:
|
||||
tr = self.app.tr_text
|
||||
page = SettingsSubPage(tr("Appearance"), self._go_back)
|
||||
@@ -260,8 +279,67 @@ class SettingsPage(QWidget):
|
||||
help_label.setObjectName("settingsHelpText")
|
||||
help_label.setWordWrap(True)
|
||||
page.content_layout.addWidget(help_label)
|
||||
page.content_layout.addWidget(QLabel(tr("Launch page background")))
|
||||
self.launch_background = current.launch_background
|
||||
self.background_preview = QLabel()
|
||||
self.background_preview.setFixedSize(320, 180)
|
||||
self.background_preview.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
page.content_layout.addWidget(self.background_preview)
|
||||
self._update_background_preview()
|
||||
background_actions = QHBoxLayout()
|
||||
choose_background = QPushButton(tr("Choose background image"))
|
||||
choose_background.clicked.connect(self._choose_launch_background)
|
||||
reset_background = QPushButton(tr("Restore default background"))
|
||||
reset_background.clicked.connect(self._reset_launch_background)
|
||||
background_actions.addWidget(choose_background)
|
||||
background_actions.addWidget(reset_background)
|
||||
background_actions.addStretch()
|
||||
page.content_layout.addLayout(background_actions)
|
||||
return page
|
||||
|
||||
def _update_background_preview(self):
|
||||
path = self.launch_background or str(Path(self.app.icon_dir, "profile_default.png"))
|
||||
pixmap = QPixmap(path)
|
||||
self.background_preview.setPixmap(pixmap.scaled(
|
||||
320, 180, Qt.AspectRatioMode.KeepAspectRatio,
|
||||
Qt.TransformationMode.SmoothTransformation,
|
||||
))
|
||||
|
||||
def _choose_launch_background(self):
|
||||
formats = " ".join("*." + bytes(fmt).decode("ascii")
|
||||
for fmt in QImageReader.supportedImageFormats())
|
||||
filename, _ = QFileDialog.getOpenFileName(
|
||||
self, self.app.tr_text("Choose background image"), "",
|
||||
self.app.tr_text("Images") + f" ({formats})",
|
||||
)
|
||||
if not filename:
|
||||
return
|
||||
reader = QImageReader(filename)
|
||||
reader.setDecideFormatFromContent(True)
|
||||
reader.setAutoTransform(True)
|
||||
image = reader.read()
|
||||
if image.isNull():
|
||||
QMessageBox.warning(self, self.app.tr_text("Settings error"),
|
||||
self.app.tr_text("Image format is not supported."))
|
||||
return
|
||||
try:
|
||||
directory = Path(self.app.work_dir) / "backgrounds"
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
destination = directory / f"{uuid.uuid4().hex}.png"
|
||||
if not image.save(str(destination), "PNG"):
|
||||
raise OSError(self.app.tr_text("Unable to save background image."))
|
||||
except OSError as error:
|
||||
QMessageBox.warning(self, self.app.tr_text("Settings error"), str(error))
|
||||
return
|
||||
self.launch_background = str(destination.resolve())
|
||||
self._update_background_preview()
|
||||
self._mark_settings_dirty()
|
||||
|
||||
def _reset_launch_background(self):
|
||||
self.launch_background = ""
|
||||
self._update_background_preview()
|
||||
self._mark_settings_dirty()
|
||||
|
||||
def _create_account_page(self) -> QWidget:
|
||||
tr = self.app.tr_text
|
||||
page = SettingsSubPage(tr("Account"), self._go_back)
|
||||
@@ -323,6 +401,7 @@ class SettingsPage(QWidget):
|
||||
|
||||
description_text = self.app.tr_text(LAUNCHER_DESCRIPTION_MARKDOWN_KEYWORD)
|
||||
description = QTextBrowser()
|
||||
# description.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
||||
description.setObjectName("settingsDescription")
|
||||
description.setReadOnly(True)
|
||||
description.setOpenExternalLinks(True)
|
||||
@@ -424,7 +503,10 @@ class SettingsPage(QWidget):
|
||||
old_theme = self.settings.get("appearance", AppearanceSettings).theme
|
||||
data = {
|
||||
"general": {"language": self.language_combo.currentData()},
|
||||
"appearance": {"theme": self.theme_combo.currentData()},
|
||||
"game": {"verify_hash_on_download": self.verify_hash_on_download.isChecked(),
|
||||
"verify_hash_on_launch": self.verify_hash_on_launch.isChecked()},
|
||||
"appearance": {"theme": self.theme_combo.currentData(),
|
||||
"launch_background": self.launch_background},
|
||||
"account": {"custom_client_id": client_id if client_id else None,
|
||||
"credentials_save_method": selected_credentials_method,
|
||||
"token_refresh_interval":
|
||||
|
||||
Reference in new issue
Block a user