1
0
Fork 0
mirror of synced 2024-06-17 01:54:46 +12:00

Add MangoHud Settings + move some settings widgets to extra folder

This commit is contained in:
Dummerle 2022-03-01 21:16:45 +01:00
parent cc92322d43
commit 58c9e69231
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
11 changed files with 120 additions and 9 deletions

View file

@ -17,7 +17,7 @@ from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame, Game
from rare.components.tabs.settings.linux import LinuxSettings
from rare.components.tabs.settings.wrapper import WrapperSettings
from rare.components.tabs.settings.settings_widgets.wrapper import WrapperSettings
from rare.ui.components.tabs.games.game_info.game_settings import Ui_GameSettings
from rare.utils import config_helper
from rare.utils.extra_widgets import PathEdit
@ -137,6 +137,10 @@ class GameSettings(QWidget, Ui_GameSettings):
self.linux_settings_widget.setVisible(False)
self.game_settings_contents_layout.setAlignment(Qt.AlignTop)
self.linux_settings.mangohud.set_wrapper_activated.connect(
lambda active: self.wrapper_settings.add_wrapper("mangohud")
if active else self.wrapper_settings.delete_wrapper("mangohud"))
def compute_save_path(self):
if (
self.core.is_installed(self.game.app_name)
@ -364,5 +368,6 @@ class LinuxAppSettings(LinuxSettings):
self.wine_prefix.setText(self.load_prefix())
self.wine_exec.setText(self.load_setting(self.name, "wine_executable"))
self.dxvk.name = app_name
self.dxvk.load_settings(self.name)
self.mangohud.load_settings(self.name)

View file

@ -6,8 +6,8 @@ from PyQt5.QtCore import Qt, QRunnable, QObject, pyqtSignal, QThreadPool
from PyQt5.QtWidgets import QSizePolicy, QWidget, QFileDialog, QMessageBox
from rare.shared import LegendaryCoreSingleton
from rare.components.tabs.settings.eos import EosWidget
from rare.components.tabs.settings.ubisoft_activation import UbiActivationHelper
from rare.components.tabs.settings.settings_widgets.eos import EosWidget
from rare.components.tabs.settings.settings_widgets.ubisoft_activation import UbiActivationHelper
from rare.ui.components.tabs.settings.legendary import Ui_LegendarySettings
from rare.utils.extra_widgets import PathEdit, IndicatorLineEdit
from rare.utils.utils import get_size

View file

@ -4,6 +4,7 @@ from logging import getLogger
from PyQt5.QtWidgets import QFileDialog, QWidget
from rare.components.tabs.settings.settings_widgets.dxvk import DxvkSettings
from rare.components.tabs.settings.settings_widgets.mangohud import MangoHudSettings
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
from rare.ui.components.tabs.settings.linux import Ui_LinuxSettings
@ -26,7 +27,7 @@ class LinuxSettings(QWidget, Ui_LinuxSettings):
self.wine_prefix = PathEdit(
self.load_prefix(),
file_type=QFileDialog.DirectoryOnly,
edit_func=lambda path: (os.path.isdir(path), path, PathEdit.reasons.dir_not_exist),
edit_func=lambda path: (os.path.isdir(path) or not path, path, PathEdit.reasons.dir_not_exist),
save_func=self.save_prefix,
)
self.prefix_layout.addWidget(self.wine_prefix)
@ -46,6 +47,9 @@ class LinuxSettings(QWidget, Ui_LinuxSettings):
self.dxvk = DxvkSettings()
self.overlay_layout.addWidget(self.dxvk)
self.mangohud = MangoHudSettings()
self.overlay_layout.addWidget(self.mangohud)
def load_prefix(self) -> str:
return self.load_setting(
f"{self.name}.env",

View file

@ -8,7 +8,7 @@ from PyQt5.QtCore import QSettings, Qt
from PyQt5.QtWidgets import QWidget, QMessageBox
from rare.shared import LegendaryCoreSingleton
from rare.components.tabs.settings.rpc import RPCSettings
from rare.components.tabs.settings.settings_widgets.rpc import RPCSettings
from rare.ui.components.tabs.settings.rare import Ui_RareSettings
from rare.utils import utils
from rare.utils.paths import cache_dir

View file

@ -0,0 +1,99 @@
from enum import Enum
from PyQt5.QtCore import QCoreApplication, pyqtSignal
from rare.shared import LegendaryCoreSingleton
from .overlay_settings import OverlaySettings, CustomOption, ActivationStates
from rare.utils import config_helper
position_values = ["default", "top-left", "top-right", "middle-left", "middle-right", "bottom-left",
"bottom-right", "top-center"]
class MangoHudSettings(OverlaySettings):
set_wrapper_activated = pyqtSignal(bool)
def __init__(self):
super(MangoHudSettings, self).__init__(
[
("fps", QCoreApplication.translate("MangoSettings", "FPS")),
("frame_timing", QCoreApplication.translate("MangoSettings", "Frame Time")),
("cpu_stats", QCoreApplication.translate("MangoSettings", "CPU Load")),
("gpu_stats", QCoreApplication.translate("MangoSettings", "GPU Load")),
("cpu_temp", QCoreApplication.translate("MangoSettings", "CPU Temp")),
("gpu_temp", QCoreApplication.translate("MangoSettings", "GPU Temp")),
("ram", QCoreApplication.translate("MangoSettings", "Memory usage")),
("vram", QCoreApplication.translate("MangoSettings", "VRAM usage")),
("time", QCoreApplication.translate("MangoSettings", "Local Time")),
("version", QCoreApplication.translate("MangoSettings", "MangoHud Version")),
("arch", QCoreApplication.translate("MangoSettings", "System architecture")),
("histogram", QCoreApplication.translate("MangoSettings", "FPS Graph")),
("gpu_name", QCoreApplication.translate("MangoSettings", "GPU Name")),
("cpu_power", QCoreApplication.translate("MangoSettings", "CPU Power consumption")),
("gpu_power", QCoreApplication.translate("MangoSettings", "GPU Power consumption")),
],
[
(
CustomOption.number_input("font_size", 24, is_float=False),
QCoreApplication.translate("MangoSettings", "Font size")
),
(
CustomOption.select_input("position", position_values),
QCoreApplication.translate("MangoSettings", "Position")
)
],
"MANGOHUD_CONFIG", "no_display", set_activation_state=self.set_activation_state
)
self.core = LegendaryCoreSingleton()
self.setTitle(self.tr("MangoHud Settings"))
self.gb_options.setTitle(self.tr("Custom options"))
def load_settings(self, name: str):
self.settings_updatable = False
self.name = name
# override
cfg = self.core.lgd.config.get(f"{name}.env", "MANGOHUD_CONFIG", fallback="")
activated = "mangohud" in self.core.lgd.config.get(name, "wrapper", fallback="")
if not activated:
self.settings_updatable = False
self.gb_options.setDisabled(True)
for i, checkbox in enumerate(list(self.checkboxes.values())):
checkbox.setChecked(i < 4)
self.show_overlay_combo.setCurrentIndex(0)
self.settings_updatable = True
return
super(MangoHudSettings, self).load_settings(name)
self.settings_updatable = False
self.show_overlay_combo.setCurrentIndex(2)
self.gb_options.setDisabled(False)
for var_name, checkbox in list(self.checkboxes.items())[:4]:
checkbox.setChecked(f"{var_name}=0" not in cfg)
self.settings_updatable = True
def set_activation_state(self, state: Enum):
if state in [ActivationStates.DEFAULT, ActivationStates.HIDDEN]:
self.set_wrapper_activated.emit(False)
self.gb_options.setDisabled(True)
elif state == ActivationStates.ACTIVATED:
cfg = self.core.lgd.config.get(f"{self.name}.env", "MANGOHUD_CONFIG", fallback="")
split_config = cfg.split(",")
for name in list(self.checkboxes.keys())[:4]:
if name in split_config:
split_config.remove(name)
cfg = ",".join(split_config)
for var_name, checkbox in list(self.checkboxes.items())[:4]: # first three are by default activated
if not checkbox.isChecked():
if cfg:
cfg += f",{var_name}=0"
else:
cfg = f"{var_name}=0"
if cfg:
config_helper.add_option(f"{self.name}.env", "MANGOHUD_CONFIG", cfg)
else:
config_helper.remove_option(f"{self.name}.env", "MANGOHUD_CONFIG")
self.set_wrapper_activated.emit(True)

View file

@ -179,4 +179,4 @@ class OverlaySettings(QGroupBox, Ui_OverlaySettings):
self.gb_options.setDisabled(False)
self.settings_updatable = True
self.settings_updatable = True

View file

@ -82,12 +82,15 @@ class WrapperSettings(QGroupBox, Ui_WrapperSettings):
widget.deleteLater()
self.wrappers.pop(text)
if len(self.wrappers) == 0:
if self.wrappers:
self.widget_stack.setCurrentIndex(1)
self.save()
def save(self):
config_helper.add_option(self.app_name, "wrapper", self.get_wrapper_string())
if len(self.wrappers) == 0 and len(self.extra_wrappers) == 0:
config_helper.remove_option(self.app_name, "wrapper")
else:
config_helper.add_option(self.app_name, "wrapper", self.get_wrapper_string())
def load_settings(self, app_name):
self.app_name = app_name