33import shutil
44from typing import TypeVar
55
6- from PySide6 .QtCore import Qt , Slot
6+ from PySide6 .QtCore import Qt , Signal , Slot
77from PySide6 .QtGui import QShowEvent
88from PySide6 .QtWidgets import (
99 QCheckBox ,
1616
1717import rare .utils .config_helper as config
1818from rare .shared import RareCore
19+ from rare .utils .wrapper_exe import wrapper_path
1920from rare .widgets .indicator_edit import IndicatorReasonsCommon , PathEdit
2021
2122from .wrappers import WrapperSettings
2223
2324
2425class LaunchSettingsBase (QGroupBox ):
26+ # str: option key
27+ environ_changed : Signal = Signal (str )
28+
2529 def __init__ (self , rcore : RareCore , wrapper_widget : type [WrapperSettings ], parent = None ):
2630 super (LaunchSettingsBase , self ).__init__ (parent = parent )
2731 self .setTitle (self .tr ('Launch' ))
@@ -33,21 +37,21 @@ def __init__(self, rcore: RareCore, wrapper_widget: type[WrapperSettings], paren
3337 path = '' ,
3438 placeholder = self .tr ('Path to a script or program to run before the game' ),
3539 file_mode = QFileDialog .FileMode .ExistingFile ,
36- edit_func = self .__prelaunch_cmd_edit_callback ,
37- save_func = self .__prelaunch_cmd_save_callback ,
40+ edit_func = self ._prelaunch_cmd_edit_callback ,
41+ save_func = self ._prelaunch_cmd_save_callback ,
3842 )
3943
4044 self .prelaunch_args = QLineEdit ('' )
4145 self .prelaunch_args .setPlaceholderText (self .tr ('Arguments to the script or program to run before the game' ))
4246 self .prelaunch_args .setToolTip (self .prelaunch_args .placeholderText ())
43- self .prelaunch_args .textChanged .connect (self .__prelaunch_changed )
47+ self .prelaunch_args .textChanged .connect (self ._prelaunch_changed )
4448
4549 font = self .font ()
4650 font .setItalic (True )
4751
4852 self .prelaunch_check = QCheckBox (self .tr ('Wait for the pre-launch command to finish before launching the game' ))
4953 self .prelaunch_check .setFont (font )
50- self .prelaunch_check .checkStateChanged .connect (self .__prelauch_check_changed )
54+ self .prelaunch_check .checkStateChanged .connect (self ._prelauch_check_changed )
5155
5256 prelaunch_layout = QVBoxLayout ()
5357 prelaunch_layout .addWidget (self .prelaunch_cmd )
@@ -61,6 +65,13 @@ def __init__(self, rcore: RareCore, wrapper_widget: type[WrapperSettings], paren
6165
6266 self .wrappers_widget = wrapper_widget (rcore , self )
6367
68+ self .lgd_wrapper = QCheckBox (
69+ self .tr ('Use "EpicGamesLauncher.exe" shim for compatibility with third-party launchers (Rockstar etc.)' )
70+ )
71+ self .lgd_wrapper .setFont (font )
72+ self .lgd_wrapper .checkStateChanged .connect (self ._lgd_wrapper_check_changed )
73+
74+ self .main_layout .addRow (self .tr ('Use fake EGL' ), self .lgd_wrapper )
6475 self .main_layout .addRow (self .tr ('Wrappers' ), self .wrappers_widget )
6576 self .main_layout .addRow (self .tr ('Pre-launch' ), prelaunch_layout )
6677
@@ -77,31 +88,36 @@ def showEvent(self, a0: QShowEvent):
7788 self .prelaunch_check .setChecked (wait )
7889 self .prelaunch_check .setEnabled (bool (command ))
7990
91+ wrapper = config .get_envvar_with_global (self .app_name , 'LEGENDARY_WRAPPER_EXE' , fallback = False )
92+
93+ self .lgd_wrapper .setEnabled (wrapper_path ().exists ())
94+ self .lgd_wrapper .setChecked (wrapper_path ().exists () and bool (wrapper ) and os .path .exists (wrapper ))
95+
8096 return super ().showEvent (a0 )
8197
8298 @Slot ()
8399 def tool_enabled (self ):
84100 self .wrappers_widget .update_state ()
85101
86102 @staticmethod
87- def __prelaunch_cmd_edit_callback (text : str ) -> tuple [bool , str , int ]:
103+ def _prelaunch_cmd_edit_callback (text : str ) -> tuple [bool , str , int ]:
88104 if not text .strip ():
89105 return True , text , IndicatorReasonsCommon .UNDEFINED
90106 if not os .path .isfile (text ) and not shutil .which (text ):
91107 return False , text , IndicatorReasonsCommon .FILE_NOT_EXISTS
92108 else :
93109 return True , text , IndicatorReasonsCommon .VALID
94110
95- def __prelaunch_cmd_save_callback (self , text ):
111+ def _prelaunch_cmd_save_callback (self , text ):
96112 self .prelaunch_check .setEnabled (bool (text ))
97- self .__prelaunch_changed ()
113+ self ._prelaunch_changed ()
98114
99115 @Slot (Qt .CheckState )
100- def __prelauch_check_changed (self , state : Qt .CheckState ):
116+ def _prelauch_check_changed (self , state : Qt .CheckState ):
101117 config .set_boolean (self .app_name , 'pre_launch_wait' , state != Qt .CheckState .Unchecked )
102118
103119 @Slot ()
104- def __prelaunch_changed (self ):
120+ def _prelaunch_changed (self ):
105121 command = self .prelaunch_cmd .text ().strip ()
106122 if not command :
107123 config .adjust_option (self .app_name , 'pre_launch_command' , command )
@@ -111,5 +127,11 @@ def __prelaunch_changed(self):
111127 arguments = self .prelaunch_args .text ().strip ()
112128 config .adjust_option (self .app_name , 'pre_launch_command' , ' ' .join ([command , arguments ]))
113129
130+ @Slot (Qt .CheckState )
131+ def _lgd_wrapper_check_changed (self , state : Qt .CheckState ):
132+ _wrapper = str (wrapper_path ())
133+ config .adjust_envvar (self .app_name , 'LEGENDARY_WRAPPER_EXE' , _wrapper if state == Qt .CheckState .Checked else '' )
134+ self .environ_changed .emit ('LEGENDARY_WRAPPER_EXE' )
135+
114136
115137LaunchSettingsType = TypeVar ('LaunchSettingsType' , bound = LaunchSettingsBase )
0 commit comments