mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Preference option to prioritize custom Liberation payloads
This commit is contained in:
parent
7c05e94619
commit
63d05ea696
@ -11,6 +11,7 @@ from dcs.unittype import FlyingType
|
||||
from game.data.weapons import Pylon, Weapon, WeaponType
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from .flighttype import FlightType
|
||||
from ..persistency import prefer_liberation_payloads
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .flight import Flight
|
||||
@ -161,7 +162,10 @@ class Loadout:
|
||||
# last - the first element in the tuple will be tried first, then the second,
|
||||
# etc.
|
||||
loadout_names = {
|
||||
t: [f"Retribution {t.value}", f"Liberation {t.value}"] for t in FlightType
|
||||
t: [f"Liberation {t.value}", f"Retribution {t.value}"]
|
||||
if prefer_liberation_payloads()
|
||||
else [f"Retribution {t.value}", f"Liberation {t.value}"]
|
||||
for t in FlightType
|
||||
}
|
||||
legacy_names = {
|
||||
FlightType.TARCAP: (
|
||||
|
||||
@ -16,6 +16,7 @@ if TYPE_CHECKING:
|
||||
from game import Game
|
||||
|
||||
_dcs_saved_game_folder: Optional[str] = None
|
||||
_prefer_liberation_payloads: bool = False
|
||||
|
||||
|
||||
# fmt: off
|
||||
@ -74,9 +75,11 @@ class MigrationUnpickler(pickle.Unpickler):
|
||||
# fmt: on
|
||||
|
||||
|
||||
def setup(user_folder: str) -> None:
|
||||
def setup(user_folder: str, prefer_liberation_payloads: bool) -> None:
|
||||
global _dcs_saved_game_folder
|
||||
_dcs_saved_game_folder = user_folder
|
||||
global _prefer_liberation_payloads
|
||||
_prefer_liberation_payloads = prefer_liberation_payloads
|
||||
if not save_dir().exists():
|
||||
save_dir().mkdir(parents=True)
|
||||
|
||||
@ -110,6 +113,11 @@ def payloads_dir(backup: bool = False) -> Path:
|
||||
return payloads
|
||||
|
||||
|
||||
def prefer_liberation_payloads() -> bool:
|
||||
global _prefer_liberation_payloads
|
||||
return _prefer_liberation_payloads
|
||||
|
||||
|
||||
def user_custom_weapon_injections_dir() -> Path:
|
||||
return base_path() / "Retribution" / "WeaponInjections"
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ from game import persistency
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
global __last_save_file
|
||||
global __prefer_liberation_payloads
|
||||
|
||||
|
||||
USER_PATH = Path(os.environ["LOCALAPPDATA"]) / "DCSRetribution"
|
||||
@ -23,6 +24,7 @@ def init():
|
||||
global __dcs_installation_directory
|
||||
global __last_save_file
|
||||
global __ignore_empty_install_directory
|
||||
global __prefer_liberation_payloads
|
||||
|
||||
if PREFERENCES_PATH.exists():
|
||||
try:
|
||||
@ -35,16 +37,21 @@ def init():
|
||||
__ignore_empty_install_directory = pref_data.get(
|
||||
"ignore_empty_install_directory", False
|
||||
)
|
||||
__prefer_liberation_payloads = pref_data.get(
|
||||
"prefer_liberation_payloads", False
|
||||
)
|
||||
is_first_start = False
|
||||
except (KeyError, json.JSONDecodeError):
|
||||
__dcs_saved_game_directory = ""
|
||||
__dcs_installation_directory = ""
|
||||
__last_save_file = ""
|
||||
__ignore_empty_install_directory = False
|
||||
__prefer_liberation_payloads = False
|
||||
is_first_start = True
|
||||
else:
|
||||
__last_save_file = ""
|
||||
__ignore_empty_install_directory = False
|
||||
__prefer_liberation_payloads = False
|
||||
try:
|
||||
__dcs_saved_game_directory = (
|
||||
dcs.installation.get_dcs_saved_games_directory()
|
||||
@ -61,16 +68,18 @@ def init():
|
||||
__dcs_installation_directory = ""
|
||||
|
||||
is_first_start = True
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
persistency.setup(__dcs_saved_game_directory, __prefer_liberation_payloads)
|
||||
return is_first_start
|
||||
|
||||
|
||||
def setup(saved_game_dir, install_dir):
|
||||
def setup(saved_game_dir, install_dir, prefer_liberation_payloads):
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
global __prefer_liberation_payloads
|
||||
__dcs_saved_game_directory = saved_game_dir
|
||||
__dcs_installation_directory = install_dir
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
__prefer_liberation_payloads = prefer_liberation_payloads
|
||||
persistency.setup(__dcs_saved_game_directory, __prefer_liberation_payloads)
|
||||
|
||||
|
||||
def setup_last_save_file(last_save_file):
|
||||
@ -88,6 +97,7 @@ def save_config():
|
||||
"dcs_install_dir": __dcs_installation_directory,
|
||||
"last_save_file": __last_save_file,
|
||||
"ignore_empty_install_directory": __ignore_empty_install_directory,
|
||||
"prefer_liberation_payloads": __prefer_liberation_payloads,
|
||||
}
|
||||
PREFERENCES_PATH.parent.mkdir(exist_ok=True, parents=True)
|
||||
with PREFERENCES_PATH.open("w") as prefs:
|
||||
@ -104,6 +114,11 @@ def get_saved_game_dir():
|
||||
return __dcs_saved_game_directory
|
||||
|
||||
|
||||
def prefer_liberation_payloads():
|
||||
global __prefer_liberation_payloads
|
||||
return __prefer_liberation_payloads
|
||||
|
||||
|
||||
def ignore_empty_install_directory():
|
||||
global __ignore_empty_install_directory
|
||||
return __ignore_empty_install_directory
|
||||
|
||||
@ -11,6 +11,7 @@ from PySide6.QtWidgets import (
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QCheckBox,
|
||||
)
|
||||
|
||||
from qt_ui import liberation_install, liberation_theme
|
||||
@ -40,6 +41,11 @@ class QLiberationPreferences(QFrame):
|
||||
self.themeSelect = QComboBox()
|
||||
[self.themeSelect.addItem(y["themeName"]) for x, y in THEMES.items()]
|
||||
|
||||
preference = liberation_install.prefer_liberation_payloads()
|
||||
self.prefer_liberation_payloads = preference if preference else False
|
||||
self.payloads_cb = QCheckBox()
|
||||
self.payloads_cb.setChecked(self.prefer_liberation_payloads)
|
||||
|
||||
self.initUi()
|
||||
|
||||
def initUi(self):
|
||||
@ -73,6 +79,14 @@ class QLiberationPreferences(QFrame):
|
||||
layout.addWidget(self.themeSelect, 4, 1, alignment=Qt.AlignmentFlag.AlignRight)
|
||||
self.themeSelect.setCurrentIndex(get_theme_index())
|
||||
|
||||
layout.addWidget(
|
||||
QLabel("<strong>Prefer custom Liberation payloads:</strong>"),
|
||||
5,
|
||||
0,
|
||||
alignment=Qt.AlignmentFlag.AlignLeft,
|
||||
)
|
||||
layout.addWidget(self.payloads_cb, 5, 1, alignment=Qt.AlignmentFlag.AlignRight)
|
||||
|
||||
main_layout.addLayout(layout)
|
||||
main_layout.addStretch()
|
||||
|
||||
@ -98,6 +112,7 @@ class QLiberationPreferences(QFrame):
|
||||
print("Applying changes")
|
||||
self.saved_game_dir = self.edit_saved_game_dir.text()
|
||||
self.dcs_install_dir = self.edit_dcs_install_dir.text()
|
||||
self.prefer_liberation_payloads = self.payloads_cb.isChecked()
|
||||
set_theme_index(self.themeSelect.currentIndex())
|
||||
|
||||
if not os.path.isdir(self.saved_game_dir):
|
||||
@ -153,7 +168,9 @@ class QLiberationPreferences(QFrame):
|
||||
error_dialog.exec_()
|
||||
return False
|
||||
|
||||
liberation_install.setup(self.saved_game_dir, self.dcs_install_dir)
|
||||
liberation_install.setup(
|
||||
self.saved_game_dir, self.dcs_install_dir, self.prefer_liberation_payloads
|
||||
)
|
||||
liberation_install.save_config()
|
||||
liberation_theme.save_theme_config()
|
||||
return True
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user