2021-02-28 03:54:26 +13:00
|
|
|
from logging import getLogger
|
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
from PyQt5.QtCore import pyqtSignal
|
2021-04-29 09:36:59 +12:00
|
|
|
from PyQt5.QtWidgets import QGroupBox
|
2021-04-30 20:05:35 +12:00
|
|
|
from PyQt5.QtWidgets import QWidget, QCheckBox, QVBoxLayout, QWidgetAction, QMenu, QToolButton, QHBoxLayout
|
2021-04-29 09:36:59 +12:00
|
|
|
|
2021-09-07 07:10:18 +12:00
|
|
|
from legendary.core import LegendaryCore
|
2021-10-08 07:19:24 +13:00
|
|
|
from rare import shared
|
2021-04-30 20:05:35 +12:00
|
|
|
from rare.ui.components.tabs.settings.dxvk import Ui_DxvkSettings
|
2021-02-27 07:28:54 +13:00
|
|
|
|
2021-02-28 03:54:26 +13:00
|
|
|
logger = getLogger("DXVK Settings")
|
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
|
2021-04-29 09:36:59 +12:00
|
|
|
class DxvkSettings(QGroupBox, Ui_DxvkSettings):
|
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
def __init__(self, name=None):
|
2021-04-29 09:36:59 +12:00
|
|
|
super(DxvkSettings, self).__init__()
|
|
|
|
self.setupUi(self)
|
|
|
|
|
|
|
|
self.name = name if name is not None else "default"
|
2021-10-08 07:19:24 +13:00
|
|
|
self.core = shared.legendary_core
|
2021-04-29 09:36:59 +12:00
|
|
|
|
|
|
|
self.dxvk_options_map = {
|
|
|
|
"devinfo": self.devinfo,
|
|
|
|
"fps": self.fps,
|
|
|
|
"frametime": self.frametime,
|
|
|
|
"memory": self.memory,
|
|
|
|
"gpuload": self.gpuload,
|
|
|
|
"version": self.version,
|
|
|
|
"api": self.api,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.load_settings()
|
|
|
|
self.show_dxvk.currentIndexChanged.connect(self.store_settings)
|
|
|
|
for opt in self.dxvk_options_map:
|
|
|
|
self.dxvk_options_map[opt].stateChanged.connect(self.store_settings)
|
|
|
|
|
|
|
|
# Show HUD ComboBox
|
|
|
|
# System Default, index 0, removes DXVK_HUD to use setting from env
|
|
|
|
# Hidden , index 1, adds DXVK_HUD=0 to override system configuration
|
|
|
|
# Visible , index 2, adds DXVK_HUD=1 to override system configuration
|
|
|
|
# Custom Options, index 3, adds DXVK_HUD=devinfo,fps and enables the customization panel
|
|
|
|
|
|
|
|
def load_settings(self):
|
|
|
|
dxvk_options = self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback=None)
|
|
|
|
self.gb_dxvk_options.setDisabled(True)
|
|
|
|
if dxvk_options is not None:
|
|
|
|
if dxvk_options == "0":
|
|
|
|
self.show_dxvk.setCurrentIndex(1)
|
|
|
|
elif dxvk_options == "1":
|
|
|
|
self.show_dxvk.setCurrentIndex(2)
|
|
|
|
else:
|
|
|
|
self.show_dxvk.setCurrentIndex(3)
|
|
|
|
self.gb_dxvk_options.setDisabled(False)
|
|
|
|
for opt in dxvk_options.split(","):
|
|
|
|
try:
|
|
|
|
self.dxvk_options_map[opt].setChecked(True)
|
|
|
|
except KeyError:
|
|
|
|
print("Malformed DXVK Option: " + opt)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
self.show_dxvk.setCurrentIndex(0)
|
|
|
|
|
|
|
|
def store_settings(self):
|
|
|
|
show_dxvk_index = self.show_dxvk.currentIndex()
|
|
|
|
if show_dxvk_index:
|
|
|
|
if f"{self.name}.env" not in self.core.lgd.config.sections():
|
|
|
|
print("add section dxvk")
|
|
|
|
self.core.lgd.config.add_section(f"{self.name}.env")
|
|
|
|
if show_dxvk_index == 1:
|
|
|
|
self.core.lgd.config[f"{self.name}.env"]["DXVK_HUD"] = "0"
|
|
|
|
if show_dxvk_index == 2:
|
|
|
|
self.core.lgd.config[f"{self.name}.env"]["DXVK_HUD"] = "1"
|
|
|
|
if show_dxvk_index == 3:
|
|
|
|
dxvk_options = []
|
2021-05-02 06:00:32 +12:00
|
|
|
for opt in self.dxvk_options_map:
|
|
|
|
if self.dxvk_options_map[opt].isChecked():
|
|
|
|
dxvk_options.append(opt)
|
2021-04-29 09:36:59 +12:00
|
|
|
if not dxvk_options:
|
2021-05-02 06:00:32 +12:00
|
|
|
# Check if this is the first activation
|
|
|
|
stored = self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback=None)
|
|
|
|
if stored not in [None, "0", "1"]:
|
|
|
|
self.core.lgd.config[f"{self.name}.env"]["DXVK_HUD"] = "0"
|
|
|
|
else:
|
|
|
|
dxvk_options = ["devinfo", "fps"]
|
|
|
|
# Check again if dxvk_options changed due to first activation
|
|
|
|
if dxvk_options:
|
|
|
|
self.core.lgd.config[f"{self.name}.env"]["DXVK_HUD"] = ",".join(dxvk_options)
|
2021-04-29 09:36:59 +12:00
|
|
|
else:
|
|
|
|
if self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback=None) is not None:
|
|
|
|
self.core.lgd.config.remove_option(f"{self.name}.env", "DXVK_HUD")
|
|
|
|
if not self.core.lgd.config[f"{self.name}.env"]:
|
|
|
|
self.core.lgd.config.remove_section(f"{self.name}.env")
|
|
|
|
self.core.lgd.save_config()
|
|
|
|
self.load_settings()
|
|
|
|
|
|
|
|
|
2021-03-28 05:51:38 +13:00
|
|
|
class DxvkWidget(QGroupBox):
|
2021-02-27 07:28:54 +13:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
def __init__(self, name=None):
|
2021-02-27 07:28:54 +13:00
|
|
|
super(DxvkWidget, self).__init__()
|
2021-10-08 07:19:24 +13:00
|
|
|
self.core = shared.legendary_core
|
2021-04-09 23:30:59 +12:00
|
|
|
self.setObjectName("settings_widget")
|
2021-03-28 05:51:38 +13:00
|
|
|
self.dxvk_settings = {
|
2021-04-08 21:09:17 +12:00
|
|
|
"fps": [False, "Fps"],
|
|
|
|
"gpuload": [False, self.tr("GPU usage")],
|
|
|
|
"memory": [False, self.tr("Used Memory")],
|
|
|
|
"devinfo": [False, self.tr("Device info")],
|
|
|
|
"version": [False, self.tr("DXVK version")],
|
|
|
|
"api": [False, self.tr("D3D Level of application")],
|
|
|
|
"frametime": [False, self.tr("Frame time graph")]
|
2021-03-28 05:51:38 +13:00
|
|
|
}
|
2021-05-02 06:00:32 +12:00
|
|
|
self.name = name
|
2021-02-27 07:28:54 +13:00
|
|
|
self.layout = QVBoxLayout()
|
|
|
|
self.child_layout = QHBoxLayout()
|
2021-03-28 05:51:38 +13:00
|
|
|
self.setTitle(self.tr("dxvk settings"))
|
2021-02-27 07:28:54 +13:00
|
|
|
self.show_dxvk = QCheckBox("Show Dxvk HUD")
|
|
|
|
|
|
|
|
self.more_settings = QToolButton()
|
2021-03-10 09:57:54 +13:00
|
|
|
dxvk_hud = self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback="")
|
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
self.more_settings.setDisabled(not dxvk_hud == "")
|
|
|
|
if dxvk_hud:
|
|
|
|
for s in dxvk_hud.split(","):
|
2021-04-08 21:09:17 +12:00
|
|
|
self.dxvk_settings[s][0] = True
|
2021-02-27 07:28:54 +13:00
|
|
|
|
|
|
|
self.more_settings.setPopupMode(QToolButton.InstantPopup)
|
|
|
|
self.more_settings.setMenu(QMenu())
|
|
|
|
self.more_settings.setText("More DXVK settings")
|
2021-04-06 20:28:03 +12:00
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
action = QWidgetAction(self)
|
|
|
|
self.more_settings_widget = DxvkMoreSettingsWidget(self.dxvk_settings, self.core)
|
2021-04-06 20:28:03 +12:00
|
|
|
self.more_settings_widget.show_dxvk.connect(lambda x: self.show_dxvk.setChecked(x))
|
2021-02-27 07:28:54 +13:00
|
|
|
action.setDefaultWidget(self.more_settings_widget)
|
|
|
|
self.more_settings.menu().addAction(action)
|
|
|
|
|
2021-02-27 07:39:02 +13:00
|
|
|
self.show_dxvk.stateChanged.connect(self.update_dxvk_active)
|
2021-02-27 07:28:54 +13:00
|
|
|
self.show_dxvk.setChecked(not dxvk_hud == "")
|
|
|
|
self.child_layout.addWidget(self.show_dxvk)
|
|
|
|
|
|
|
|
self.child_layout.addWidget(self.more_settings)
|
|
|
|
self.layout.addLayout(self.child_layout)
|
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
2021-03-10 09:57:54 +13:00
|
|
|
def update_settings(self, app_name):
|
|
|
|
self.name = app_name
|
|
|
|
dxvk_hud = self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback="")
|
|
|
|
if dxvk_hud:
|
2021-03-28 05:51:38 +13:00
|
|
|
self.more_settings.setDisabled(False)
|
2021-03-10 09:57:54 +13:00
|
|
|
for s in dxvk_hud.split(","):
|
2021-04-08 21:09:17 +12:00
|
|
|
self.dxvk_settings[s][0] = True
|
2021-03-10 09:57:54 +13:00
|
|
|
else:
|
|
|
|
self.show_dxvk.setChecked(False)
|
2021-03-28 05:51:38 +13:00
|
|
|
self.more_settings.setDisabled(True)
|
2021-03-10 09:57:54 +13:00
|
|
|
|
2021-02-27 07:39:02 +13:00
|
|
|
def update_dxvk_active(self):
|
|
|
|
if self.show_dxvk.isChecked():
|
2021-03-10 09:57:54 +13:00
|
|
|
if not f"{self.name}.env" in self.core.lgd.config.sections():
|
2021-04-06 20:28:03 +12:00
|
|
|
print("add section dxvk")
|
|
|
|
self.core.lgd.config.add_section(f"{self.name}.env")
|
2021-02-27 07:39:02 +13:00
|
|
|
self.more_settings.setDisabled(False)
|
2021-03-28 05:51:38 +13:00
|
|
|
|
|
|
|
for i in self.more_settings_widget.settings:
|
|
|
|
if i in ["fps", "gpuload"]:
|
2021-04-08 21:09:17 +12:00
|
|
|
self.more_settings_widget.settings[i][0] = True
|
2021-03-28 05:51:38 +13:00
|
|
|
|
2021-03-10 09:57:54 +13:00
|
|
|
self.core.lgd.config[f"{self.name}.env"]["DXVK_HUD"] = "fps,gpuload"
|
2021-02-27 07:39:02 +13:00
|
|
|
for w in self.more_settings_widget.widgets:
|
2021-02-27 11:43:34 +13:00
|
|
|
if w.tag == "fps" or w.tag == "gpuload":
|
2021-02-27 07:39:02 +13:00
|
|
|
w.setChecked(True)
|
2021-02-27 11:43:34 +13:00
|
|
|
|
2021-02-27 07:39:02 +13:00
|
|
|
else:
|
|
|
|
w.setChecked(False)
|
|
|
|
else:
|
|
|
|
self.more_settings.setDisabled(True)
|
2021-03-10 09:57:54 +13:00
|
|
|
if not self.core.lgd.config.get(f"{self.name}.env", "DXVK_HUD", fallback="") == "":
|
|
|
|
self.core.lgd.config.remove_option(f"{self.name}.env", "DXVK_HUD")
|
|
|
|
if not self.core.lgd.config[f"{self.name}.env"]:
|
|
|
|
self.core.lgd.config.remove_section(f"{self.name}.env")
|
2021-02-27 07:39:02 +13:00
|
|
|
self.core.lgd.save_config()
|
2021-02-27 07:28:54 +13:00
|
|
|
|
2021-02-27 11:43:34 +13:00
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
class DxvkMoreSettingsWidget(QWidget):
|
2021-04-06 20:28:03 +12:00
|
|
|
show_dxvk = pyqtSignal(bool)
|
2021-04-08 21:09:17 +12:00
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
def __init__(self, settings: dict, core: LegendaryCore):
|
|
|
|
super(DxvkMoreSettingsWidget, self).__init__()
|
|
|
|
self.layout = QVBoxLayout()
|
2021-03-10 09:57:54 +13:00
|
|
|
self.name = "default"
|
2021-02-27 07:28:54 +13:00
|
|
|
self.widgets = []
|
|
|
|
self.core = core
|
|
|
|
self.settings = settings
|
|
|
|
for i in settings:
|
|
|
|
widget = CheckBox(i, settings[i])
|
|
|
|
widget.signal.connect(self.change)
|
|
|
|
self.layout.addWidget(widget)
|
|
|
|
self.widgets.append(widget)
|
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
2021-04-08 21:09:17 +12:00
|
|
|
def change(self, signal: list):
|
2021-02-27 07:28:54 +13:00
|
|
|
tag, checked = signal
|
2021-04-08 21:09:17 +12:00
|
|
|
self.settings[tag][0] = checked
|
2021-04-06 20:28:03 +12:00
|
|
|
|
2021-02-27 07:28:54 +13:00
|
|
|
sett = []
|
2021-02-28 03:54:26 +13:00
|
|
|
logger.debug(self.settings)
|
2021-02-27 07:28:54 +13:00
|
|
|
for i in self.settings:
|
|
|
|
check, _ = self.settings[i]
|
|
|
|
if check:
|
|
|
|
sett.append(i)
|
2021-04-08 21:09:17 +12:00
|
|
|
if len(sett) > 0:
|
2021-04-06 21:25:36 +12:00
|
|
|
self.core.lgd.config.set(f"{self.name}.env", "DXVK_HUD", ",".join(sett))
|
2021-04-06 20:28:03 +12:00
|
|
|
|
|
|
|
else:
|
|
|
|
self.core.lgd.config.remove_option(f"{self.name}.env", "DXVK_HUD")
|
|
|
|
self.show_dxvk.emit(False)
|
|
|
|
if not self.core.lgd.config.options(f"{self.name}.env"):
|
|
|
|
self.core.lgd.config.remove_section(f"{self.name}.env")
|
|
|
|
self.core.lgd.save_config()
|
2021-02-27 07:28:54 +13:00
|
|
|
|
|
|
|
|
|
|
|
class CheckBox(QCheckBox):
|
|
|
|
signal = pyqtSignal(tuple)
|
|
|
|
|
|
|
|
def __init__(self, tag, settings):
|
|
|
|
checked, text = settings
|
|
|
|
super(CheckBox, self).__init__(text)
|
|
|
|
self.setChecked(checked)
|
|
|
|
self.tag = tag
|
|
|
|
self.clicked.connect(lambda: self.signal.emit((self.tag, self.isChecked())))
|