mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Remove the userdata package.
This commit is contained in:
100
qt_ui/liberation_install.py
Normal file
100
qt_ui/liberation_install.py
Normal file
@@ -0,0 +1,100 @@
|
||||
import json
|
||||
import os
|
||||
from shutil import copyfile
|
||||
|
||||
import dcs
|
||||
|
||||
from game import persistency
|
||||
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
|
||||
PREFERENCES_FILE_PATH = "liberation_preferences.json"
|
||||
|
||||
|
||||
def init():
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
|
||||
if os.path.isfile(PREFERENCES_FILE_PATH):
|
||||
try:
|
||||
with(open(PREFERENCES_FILE_PATH)) as prefs:
|
||||
pref_data = json.loads(prefs.read())
|
||||
__dcs_saved_game_directory = pref_data["saved_game_dir"]
|
||||
__dcs_installation_directory = pref_data["dcs_install_dir"]
|
||||
is_first_start = False
|
||||
except:
|
||||
__dcs_saved_game_directory = ""
|
||||
__dcs_installation_directory = ""
|
||||
is_first_start = True
|
||||
else:
|
||||
try:
|
||||
__dcs_saved_game_directory = dcs.installation.get_dcs_saved_games_directory()
|
||||
if os.path.exists(__dcs_saved_game_directory + ".openbeta"):
|
||||
__dcs_saved_game_directory = dcs.installation.get_dcs_saved_games_directory() + ".openbeta"
|
||||
except:
|
||||
__dcs_saved_game_directory = ""
|
||||
try:
|
||||
__dcs_installation_directory = dcs.installation.get_dcs_install_directory()
|
||||
except:
|
||||
__dcs_installation_directory = ""
|
||||
|
||||
is_first_start = True
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
return is_first_start
|
||||
|
||||
|
||||
def setup(saved_game_dir, install_dir):
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
__dcs_saved_game_directory = saved_game_dir
|
||||
__dcs_installation_directory = install_dir
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
|
||||
|
||||
def save_config():
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
pref_data = {"saved_game_dir": __dcs_saved_game_directory,
|
||||
"dcs_install_dir": __dcs_installation_directory}
|
||||
with(open(PREFERENCES_FILE_PATH, "w")) as prefs:
|
||||
prefs.write(json.dumps(pref_data))
|
||||
|
||||
|
||||
def get_dcs_install_directory():
|
||||
global __dcs_installation_directory
|
||||
return __dcs_installation_directory
|
||||
|
||||
|
||||
def get_saved_game_dir():
|
||||
global __dcs_saved_game_directory
|
||||
return __dcs_saved_game_directory
|
||||
|
||||
|
||||
def replace_mission_scripting_file():
|
||||
install_dir = get_dcs_install_directory()
|
||||
mission_scripting_path = os.path.join(install_dir, "Scripts", "MissionScripting.lua")
|
||||
liberation_scripting_path = "./resources/scripts/MissionScripting.lua"
|
||||
backup_scripting_path = "./resources/scripts/MissionScripting.original.lua"
|
||||
if os.path.isfile(mission_scripting_path):
|
||||
with open(mission_scripting_path, "r") as ms:
|
||||
current_file_content = ms.read()
|
||||
with open(liberation_scripting_path, "r") as libe_ms:
|
||||
liberation_file_content = libe_ms.read()
|
||||
|
||||
# Save original file
|
||||
if current_file_content != liberation_file_content:
|
||||
copyfile(mission_scripting_path, backup_scripting_path)
|
||||
|
||||
# Replace DCS file
|
||||
copyfile(liberation_scripting_path, mission_scripting_path)
|
||||
|
||||
|
||||
def restore_original_mission_scripting():
|
||||
install_dir = get_dcs_install_directory()
|
||||
mission_scripting_path = os.path.join(install_dir, "Scripts", "MissionScripting.lua")
|
||||
backup_scripting_path = "./resources/scripts/MissionScripting.original.lua"
|
||||
|
||||
if os.path.isfile(backup_scripting_path) and os.path.isfile(mission_scripting_path):
|
||||
copyfile(backup_scripting_path, mission_scripting_path)
|
||||
|
||||
88
qt_ui/liberation_theme.py
Normal file
88
qt_ui/liberation_theme.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import json
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
global __theme_index
|
||||
|
||||
THEME_PREFERENCES_FILE_PATH = "liberation_theme.json"
|
||||
|
||||
DEFAULT_THEME_INDEX = 1
|
||||
|
||||
|
||||
# new themes can be added here
|
||||
THEMES: Dict[int, Dict[str, str]] = {
|
||||
0: {'themeName': 'Vanilla',
|
||||
'themeFile': 'windows-style.css',
|
||||
'themeIcons': 'medium',
|
||||
},
|
||||
|
||||
1: {'themeName': 'DCS World',
|
||||
'themeFile': 'style-dcs.css',
|
||||
'themeIcons': 'light',
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
def init():
|
||||
global __theme_index
|
||||
|
||||
__theme_index = DEFAULT_THEME_INDEX
|
||||
print("init setting theme index to " + str(__theme_index))
|
||||
|
||||
if os.path.isfile(THEME_PREFERENCES_FILE_PATH):
|
||||
try:
|
||||
with(open(THEME_PREFERENCES_FILE_PATH)) as prefs:
|
||||
pref_data = json.loads(prefs.read())
|
||||
__theme_index = pref_data["theme_index"]
|
||||
print(__theme_index)
|
||||
set_theme_index(__theme_index)
|
||||
save_theme_config()
|
||||
print("file setting theme index to " + str(__theme_index))
|
||||
except:
|
||||
# is this necessary?
|
||||
set_theme_index(DEFAULT_THEME_INDEX)
|
||||
print("except setting theme index to " + str(__theme_index))
|
||||
else:
|
||||
# is this necessary?
|
||||
set_theme_index(DEFAULT_THEME_INDEX)
|
||||
print("else setting theme index to " + str(__theme_index))
|
||||
|
||||
|
||||
# set theme index then use save_theme_config to save to file
|
||||
def set_theme_index(x):
|
||||
global __theme_index
|
||||
__theme_index = x
|
||||
|
||||
|
||||
# get theme index to reference other theme properties(themeName, themeFile, themeIcons)
|
||||
def get_theme_index():
|
||||
global __theme_index
|
||||
return __theme_index
|
||||
|
||||
|
||||
# get theme name based on current index
|
||||
def get_theme_name():
|
||||
theme_name = THEMES[get_theme_index()]['themeName']
|
||||
return theme_name
|
||||
|
||||
|
||||
# get theme icon sub-folder name based on current index
|
||||
def get_theme_icons():
|
||||
theme_icons = THEMES[get_theme_index()]['themeIcons']
|
||||
return str(theme_icons)
|
||||
|
||||
|
||||
# get theme stylesheet css based on current index
|
||||
def get_theme_css_file():
|
||||
theme_file = THEMES[get_theme_index()]['themeFile']
|
||||
return str(theme_file)
|
||||
|
||||
|
||||
# save current theme index to json file
|
||||
def save_theme_config():
|
||||
pref_data = {
|
||||
"theme_index": get_theme_index()
|
||||
}
|
||||
with(open(THEME_PREFERENCES_FILE_PATH, "w")) as prefs:
|
||||
prefs.write(json.dumps(pref_data))
|
||||
26
qt_ui/logging_config.py
Normal file
26
qt_ui/logging_config.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
import os
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
|
||||
def init_logging(version_string):
|
||||
if not os.path.isdir("./logs"):
|
||||
os.mkdir("logs")
|
||||
|
||||
logging.basicConfig(level="DEBUG")
|
||||
logger = logging.getLogger()
|
||||
|
||||
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
|
||||
|
||||
handler = RotatingFileHandler('./logs/liberation.log', 'a', 5000000, 1)
|
||||
handler.setLevel(logging.INFO)
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setLevel(logging.DEBUG)
|
||||
stream_handler.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(stream_handler)
|
||||
logger.addHandler(handler)
|
||||
|
||||
logger.info("DCS Liberation {}".format(version_string))
|
||||
@@ -1,5 +1,3 @@
|
||||
from userdata import logging_config
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
@@ -9,11 +7,17 @@ from PySide2 import QtWidgets
|
||||
from PySide2.QtGui import QPixmap
|
||||
from PySide2.QtWidgets import QApplication, QSplashScreen
|
||||
|
||||
from qt_ui import uiconstants
|
||||
from game import persistency
|
||||
from qt_ui import (
|
||||
liberation_install,
|
||||
liberation_theme,
|
||||
logging_config,
|
||||
uiconstants,
|
||||
)
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from qt_ui.windows.QLiberationWindow import QLiberationWindow
|
||||
from qt_ui.windows.preferences.QLiberationFirstStartWindow import QLiberationFirstStartWindow
|
||||
from userdata import liberation_install, persistency, liberation_theme
|
||||
from qt_ui.windows.preferences.QLiberationFirstStartWindow import \
|
||||
QLiberationFirstStartWindow
|
||||
|
||||
# Logging setup
|
||||
logging_config.init_logging(uiconstants.VERSION_STRING)
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
# URL for UI links
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
from PySide2.QtGui import QColor, QFont, QPixmap
|
||||
|
||||
from game.event import UnitsDeliveryEvent, FrontlineAttackEvent
|
||||
from theater.theatergroundobject import CATEGORY_MAP
|
||||
from userdata.liberation_theme import get_theme_icons
|
||||
from .liberation_theme import get_theme_icons
|
||||
|
||||
VERSION_STRING = "2.1.4"
|
||||
|
||||
@@ -28,20 +26,6 @@ FONT_PRIMARY_I = QFont(FONT_NAME, FONT_SIZE, weight=5, italic=True)
|
||||
FONT_PRIMARY_B = QFont(FONT_NAME, FONT_SIZE, weight=75, italic=False)
|
||||
FONT_MAP = QFont(FONT_NAME, 10, weight=75, italic=False)
|
||||
|
||||
# new themes can be added here
|
||||
THEMES: Dict[int, Dict[str, str]] = {
|
||||
0: {'themeName': 'Vanilla',
|
||||
'themeFile': 'windows-style.css',
|
||||
'themeIcons': 'medium',
|
||||
},
|
||||
|
||||
1: {'themeName': 'DCS World',
|
||||
'themeFile': 'style-dcs.css',
|
||||
'themeIcons': 'light',
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
COLORS: Dict[str, QColor] = {
|
||||
"white": QColor(255, 255, 255),
|
||||
"white_transparent": QColor(255, 255, 255, 35),
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
from PySide2.QtGui import QIcon, QPixmap
|
||||
from PySide2.QtWidgets import QLabel, QDialog, QVBoxLayout, QGroupBox, QGridLayout, QPushButton
|
||||
from PySide2.QtWidgets import (
|
||||
QDialog,
|
||||
QGridLayout,
|
||||
QGroupBox,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
from game.game import Event, db, Game
|
||||
from userdata.debriefing import Debriefing
|
||||
from game.debriefing import Debriefing
|
||||
from game.game import Event, Game, db
|
||||
|
||||
|
||||
class QDebriefingWindow(QDialog):
|
||||
|
||||
@@ -17,8 +17,7 @@ from PySide2.QtWidgets import (
|
||||
)
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import Game
|
||||
from game.inventory import GlobalAircraftInventory
|
||||
from game import Game, persistency
|
||||
from qt_ui.dialogs import Dialog
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.uiconstants import URLS
|
||||
@@ -31,7 +30,6 @@ from qt_ui.windows.infos.QInfoPanel import QInfoPanel
|
||||
from qt_ui.windows.newgame.QNewGameWizard import NewGameWizard
|
||||
from qt_ui.windows.preferences.QLiberationPreferencesWindow import \
|
||||
QLiberationPreferencesWindow
|
||||
from userdata import persistency
|
||||
|
||||
|
||||
class QLiberationWindow(QMainWindow):
|
||||
|
||||
@@ -2,15 +2,24 @@ import json
|
||||
import os
|
||||
|
||||
from PySide2 import QtCore
|
||||
from PySide2.QtCore import QObject, Signal, Qt
|
||||
from PySide2.QtGui import QMovie, QIcon, QPixmap
|
||||
from PySide2.QtWidgets import QLabel, QDialog, QGroupBox, QGridLayout, QPushButton, QFileDialog, QMessageBox, QTextEdit, \
|
||||
QHBoxLayout
|
||||
from PySide2.QtCore import QObject, Qt, Signal
|
||||
from PySide2.QtGui import QIcon, QMovie, QPixmap
|
||||
from PySide2.QtWidgets import (
|
||||
QDialog,
|
||||
QFileDialog,
|
||||
QGridLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QTextEdit,
|
||||
)
|
||||
|
||||
from game.debriefing import Debriefing, wait_for_debriefing
|
||||
from game.game import Event, Game, logging
|
||||
from game.persistency import base_path
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from userdata.debriefing import wait_for_debriefing, Debriefing
|
||||
from userdata.persistency import base_path
|
||||
|
||||
|
||||
class DebriefingFileWrittenSignal(QObject):
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import os
|
||||
|
||||
from PySide2 import QtWidgets
|
||||
from PySide2.QtCore import QFile
|
||||
from PySide2.QtGui import Qt
|
||||
from PySide2.QtWidgets import QFrame, QLineEdit, QGridLayout, QVBoxLayout, QLabel, QPushButton, \
|
||||
QFileDialog, QMessageBox, QDialog, QComboBox, QApplication
|
||||
import qt_ui.uiconstants as CONST
|
||||
import sys
|
||||
from PySide2.QtWidgets import (
|
||||
QComboBox,
|
||||
QFileDialog,
|
||||
QFrame,
|
||||
QGridLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
import userdata
|
||||
from userdata import liberation_install, liberation_theme
|
||||
from userdata.liberation_theme import get_theme_index, set_theme_index
|
||||
import qt_ui.uiconstants as CONST
|
||||
from qt_ui import liberation_install, liberation_theme
|
||||
from qt_ui.liberation_theme import get_theme_index, set_theme_index
|
||||
|
||||
|
||||
class QLiberationPreferences(QFrame):
|
||||
|
||||
Reference in New Issue
Block a user