mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Some clean up and refactoring
This commit is contained in:
parent
2dc1b3ec43
commit
d775b8baa0
@ -17,16 +17,16 @@ from qt_ui import uiconstants
|
|||||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||||
from qt_ui.windows.QLiberationWindow import QLiberationWindow
|
from qt_ui.windows.QLiberationWindow import QLiberationWindow
|
||||||
from qt_ui.windows.preferences.QLiberationFirstStartWindow import QLiberationFirstStartWindow
|
from qt_ui.windows.preferences.QLiberationFirstStartWindow import QLiberationFirstStartWindow
|
||||||
from userdata import liberation_install, persistency
|
from userdata import liberation_install, persistency, liberation_theme
|
||||||
from userdata import liberation_theme, persistency
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
# init the theme and load the stylesheet based on the theme index
|
||||||
liberation_theme.init();
|
liberation_theme.init();
|
||||||
css = ""
|
css = ""
|
||||||
with open("./resources/stylesheets/"+liberation_theme.get_theme_file()) as stylesheet:
|
with open("./resources/stylesheets/"+liberation_theme.get_theme_css_file()) as stylesheet:
|
||||||
app.setStyleSheet(stylesheet.read())
|
app.setStyleSheet(stylesheet.read())
|
||||||
|
|
||||||
# Inject custom payload in pydcs framework
|
# Inject custom payload in pydcs framework
|
||||||
|
|||||||
@ -22,7 +22,7 @@ SKILL_OPTIONS = ["Average", "Good", "High", "Excellent"]
|
|||||||
|
|
||||||
# new themes can be added here
|
# new themes can be added here
|
||||||
THEMES: Dict[int, Dict[str, str]] = {
|
THEMES: Dict[int, Dict[str, str]] = {
|
||||||
0: {'themeName': 'Windows',
|
0: {'themeName': 'Vanilla',
|
||||||
'themeFile': 'windows-style.css',
|
'themeFile': 'windows-style.css',
|
||||||
'themeIcons': 'medium',
|
'themeIcons': 'medium',
|
||||||
},
|
},
|
||||||
@ -32,10 +32,6 @@ THEMES: Dict[int, Dict[str, str]] = {
|
|||||||
'themeIcons': 'light',
|
'themeIcons': 'light',
|
||||||
},
|
},
|
||||||
|
|
||||||
2: {'themeName': 'Blue',
|
|
||||||
'themeFile': 'style.css',
|
|
||||||
'themeIcons': 'dark',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORS: Dict[str, QColor] = {
|
COLORS: Dict[str, QColor] = {
|
||||||
@ -96,9 +92,9 @@ def load_icons():
|
|||||||
ICONS["ship"] = QPixmap("./resources/ui/ground_assets/ship.png")
|
ICONS["ship"] = QPixmap("./resources/ui/ground_assets/ship.png")
|
||||||
ICONS["ship_blue"] = QPixmap("./resources/ui/ground_assets/ship_blue.png")
|
ICONS["ship_blue"] = QPixmap("./resources/ui/ground_assets/ship_blue.png")
|
||||||
|
|
||||||
ICONS["Generator"] = QPixmap("./resources/ui/misc/generator.png")
|
ICONS["Generator"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/generator.png")
|
||||||
ICONS["Missile"] = QPixmap("./resources/ui/misc/missile.png")
|
ICONS["Missile"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/missile.png")
|
||||||
ICONS["Cheat"] = QPixmap("./resources/ui/misc/cheat.png")
|
ICONS["Cheat"] = QPixmap("./resources/ui/misc/"+get_theme_icons()+"/cheat.png")
|
||||||
|
|
||||||
ICONS["TaskCAS"] = QPixmap("./resources/ui/tasks/cas.png")
|
ICONS["TaskCAS"] = QPixmap("./resources/ui/tasks/cas.png")
|
||||||
ICONS["TaskCAP"] = QPixmap("./resources/ui/tasks/cap.png")
|
ICONS["TaskCAP"] = QPixmap("./resources/ui/tasks/cap.png")
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import sys
|
|||||||
|
|
||||||
import userdata
|
import userdata
|
||||||
from userdata import liberation_install, liberation_theme
|
from userdata import liberation_install, liberation_theme
|
||||||
from userdata.liberation_theme import get_theme_file, set_theme_name, get_theme_index, set_theme_index
|
from userdata.liberation_theme import get_theme_index, set_theme_index
|
||||||
|
|
||||||
|
|
||||||
class QLiberationPreferences(QFrame):
|
class QLiberationPreferences(QFrame):
|
||||||
@ -34,13 +34,10 @@ class QLiberationPreferences(QFrame):
|
|||||||
self.browse_install_dir = QPushButton("Browse...")
|
self.browse_install_dir = QPushButton("Browse...")
|
||||||
self.browse_install_dir.clicked.connect(self.on_browse_installation_dir)
|
self.browse_install_dir.clicked.connect(self.on_browse_installation_dir)
|
||||||
self.themeSelect = QComboBox()
|
self.themeSelect = QComboBox()
|
||||||
|
[self.themeSelect.addItem(y['themeName']) for x, y in CONST.THEMES.items()]
|
||||||
for x, y in CONST.THEMES.items():
|
|
||||||
self.themeSelect.addItem(y['themeName'])
|
|
||||||
|
|
||||||
self.initUi()
|
self.initUi()
|
||||||
|
|
||||||
|
|
||||||
def initUi(self):
|
def initUi(self):
|
||||||
main_layout = QVBoxLayout()
|
main_layout = QVBoxLayout()
|
||||||
layout = QGridLayout()
|
layout = QGridLayout()
|
||||||
@ -92,7 +89,8 @@ class QLiberationPreferences(QFrame):
|
|||||||
error_dialog.exec_()
|
error_dialog.exec_()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not os.path.isdir(os.path.join(self.dcs_install_dir, "Scripts")) and os.path.isfile(os.path.join(self.dcs_install_dir, "bin", "DCS.exe")):
|
if not os.path.isdir(os.path.join(self.dcs_install_dir, "Scripts")) and os.path.isfile(
|
||||||
|
os.path.join(self.dcs_install_dir, "bin", "DCS.exe")):
|
||||||
error_dialog = QMessageBox.critical(self, "Wrong DCS installation directory.",
|
error_dialog = QMessageBox.critical(self, "Wrong DCS installation directory.",
|
||||||
self.dcs_install_dir + " is not a valid DCS installation directory",
|
self.dcs_install_dir + " is not a valid DCS installation directory",
|
||||||
QMessageBox.StandardButton.Ok)
|
QMessageBox.StandardButton.Ok)
|
||||||
@ -101,8 +99,5 @@ class QLiberationPreferences(QFrame):
|
|||||||
|
|
||||||
liberation_install.setup(self.saved_game_dir, self.dcs_install_dir)
|
liberation_install.setup(self.saved_game_dir, self.dcs_install_dir)
|
||||||
liberation_install.save_config()
|
liberation_install.save_config()
|
||||||
liberation_theme.set_theme_file()
|
liberation_theme.save_theme_config()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ QPushButton:hover {
|
|||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*btn-success = a green button*/
|
/*btn-primary*/
|
||||||
QPushButton[style="btn-primary"]{
|
QPushButton[style="btn-primary"]{
|
||||||
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #A4B3B9, stop:1 #85989D);
|
background: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #A4B3B9, stop:1 #85989D);
|
||||||
border: 1px solid #97A9A9;
|
border: 1px solid #97A9A9;
|
||||||
@ -93,9 +93,13 @@ QPushButton[style="btn-primary"]{
|
|||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
text-transform:uppercase;
|
text-transform:uppercase;
|
||||||
}
|
}
|
||||||
|
QPushButton[style="btn-primary"]:hover{
|
||||||
|
background: #85989D;
|
||||||
|
}
|
||||||
|
|
||||||
/*btn-success = a green button*/
|
|
||||||
QPushButton[style="btn-success"]{
|
/*highlighted buttons*/
|
||||||
|
QPushButton[style="btn-success"] , QPushButton[style="start-button"]{
|
||||||
background-color:#82A466;
|
background-color:#82A466;
|
||||||
color: white;
|
color: white;
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
@ -105,27 +109,12 @@ QPushButton[style="btn-success"]{
|
|||||||
text-transform:uppercase;
|
text-transform:uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton[style="btn-success"]:hover{
|
|
||||||
background-color:#5C863F;
|
|
||||||
padding: 5px;
|
|
||||||
border-radius:2px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*mission start button*/
|
|
||||||
QPushButton[style="start-button"]{
|
QPushButton[style="start-button"]{
|
||||||
background:qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #82A466, stop:1 #5C863F);
|
padding: 8px 30px;
|
||||||
border-radius:2px;
|
|
||||||
border: none;
|
|
||||||
text-transform: uppercase;
|
|
||||||
text-weight: bold;
|
|
||||||
padding: 8px 30px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton[style="start-button"]:hover{
|
QPushButton[style="btn-success"]:hover , QPushButton[style="start-button"]:hover{
|
||||||
background:#5C863F;
|
background:#5C863F;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPushButton[style="btn-danger"]{
|
QPushButton[style="btn-danger"]{
|
||||||
@ -145,13 +134,12 @@ QPushButton[style="btn-danger"]:hover{
|
|||||||
|
|
||||||
/*QLabel*/
|
/*QLabel*/
|
||||||
QLabel{
|
QLabel{
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="base-title"]{
|
QLabel[style="base-title"]{
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
font-color: #ccc;
|
font-color: #ccc;
|
||||||
/*border: 1px solid #ccc;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="icon-plane"]{
|
QLabel[style="icon-plane"]{
|
||||||
@ -163,68 +151,74 @@ QLabel[style="icon-plane"]{
|
|||||||
color:white;
|
color:white;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="bordered"]{
|
|
||||||
border: 1px solid black;
|
|
||||||
}
|
|
||||||
|
|
||||||
QLabel[style="BARCAP"]{
|
QLabel[style="BARCAP"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #445299;
|
background-color: #445299;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="TARCAP"]{
|
QLabel[style="TARCAP"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #445299;
|
background-color: #445299;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="CAP"]{
|
QLabel[style="CAP"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #445299;
|
background-color: #445299;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="INTERCEPTION"]{
|
QLabel[style="INTERCEPTION"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #7752bc;
|
background-color: #7752bc;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="CAS"]{
|
QLabel[style="CAS"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #ab2244;
|
background-color: #ab2244;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="BAI"]{
|
QLabel[style="BAI"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #ab2244;
|
background-color: #ab2244;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="ANTISHIP"]{
|
QLabel[style="ANTISHIP"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #ab2244;
|
background-color: #ab2244;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="STRIKE"]{
|
QLabel[style="STRIKE"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #ab2244;
|
background-color: #ab2244;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="DEAD"]{
|
QLabel[style="DEAD"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #cc8844;
|
background-color: #cc8844;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel[style="SEAD"]{
|
QLabel[style="SEAD"]{
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
background-color: #aa7744;
|
background-color: #aa7744;
|
||||||
color:white;
|
color:white;
|
||||||
|
padding:2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*QGroupBox these are the sections that look like fieldsets*/
|
/*QGroupBox these are the sections that look like fieldsets*/
|
||||||
@ -311,7 +305,6 @@ QComboxBox {
|
|||||||
padding:10px;
|
padding:10px;
|
||||||
margin:10px;
|
margin:10px;
|
||||||
border:1px solid #3B4656;
|
border:1px solid #3B4656;
|
||||||
background: #1D2731;
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
QComboBox:editable {
|
QComboBox:editable {
|
||||||
@ -319,14 +312,13 @@ QComboBox:editable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QComboBox:!editable{
|
QComboBox:!editable{
|
||||||
background: #1D2731;
|
/*background: #1D2731;*/
|
||||||
}
|
}
|
||||||
QComboBox::drop-down {
|
QComboBox::drop-down {
|
||||||
subcontrol-origin: padding;
|
subcontrol-origin: padding;
|
||||||
subcontrol-position: top right;
|
subcontrol-position: top right;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border:none;
|
border:none;
|
||||||
background: #1D2731;
|
|
||||||
color: #fff;
|
color: #fff;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
@ -336,13 +328,18 @@ QComboBox::down-arrow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QComboBox QAbstractItemView {
|
QComboBox QAbstractItemView {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border:1px solid #3B4656;
|
border:1px solid #3B4656;
|
||||||
background: #465C74;
|
background: #465C74;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSpinBox{
|
||||||
|
/*TODO:style this*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QLineEdit{
|
QLineEdit{
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
border:1px solid #3B4656;
|
border:1px solid #3B4656;
|
||||||
@ -382,7 +379,11 @@ QTableWidget {
|
|||||||
|
|
||||||
/*helper modifiers*/
|
/*helper modifiers*/
|
||||||
*[style="no-border"] {
|
*[style="no-border"] {
|
||||||
border:none;
|
border:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
*[style="bordered"]{
|
||||||
|
border: 1px solid #1D2731;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,9 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from shutil import copyfile
|
|
||||||
|
|
||||||
import dcs
|
|
||||||
import qt_ui.uiconstants as CONST
|
import qt_ui.uiconstants as CONST
|
||||||
from userdata import persistency
|
|
||||||
|
|
||||||
global __theme_index
|
global __theme_index
|
||||||
global __theme_name
|
|
||||||
global __theme_file
|
|
||||||
global __theme_icons
|
|
||||||
|
|
||||||
THEME_PREFERENCES_FILE_PATH = "liberation_theme.json"
|
THEME_PREFERENCES_FILE_PATH = "liberation_theme.json"
|
||||||
|
|
||||||
@ -29,61 +23,52 @@ def init():
|
|||||||
__theme_index = pref_data["theme_index"]
|
__theme_index = pref_data["theme_index"]
|
||||||
print(__theme_index)
|
print(__theme_index)
|
||||||
set_theme_index(__theme_index)
|
set_theme_index(__theme_index)
|
||||||
set_theme_file()
|
save_theme_config()
|
||||||
print("file setting theme index to " + str(__theme_index))
|
print("file setting theme index to " + str(__theme_index))
|
||||||
except:
|
except:
|
||||||
|
# is this necessary?
|
||||||
set_theme_index(DEFAULT_THEME_INDEX)
|
set_theme_index(DEFAULT_THEME_INDEX)
|
||||||
print("except setting theme index to " + str(__theme_index))
|
print("except setting theme index to " + str(__theme_index))
|
||||||
else:
|
else:
|
||||||
|
# is this necessary?
|
||||||
set_theme_index(DEFAULT_THEME_INDEX)
|
set_theme_index(DEFAULT_THEME_INDEX)
|
||||||
print("else setting theme index to " + str(__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):
|
def set_theme_index(x):
|
||||||
global __theme_index
|
global __theme_index
|
||||||
__theme_index = x
|
__theme_index = x
|
||||||
|
|
||||||
|
|
||||||
|
# get theme index to reference other theme properties(themeName, themeFile, themeIcons)
|
||||||
def get_theme_index():
|
def get_theme_index():
|
||||||
global __theme_index
|
global __theme_index
|
||||||
return __theme_index
|
return __theme_index
|
||||||
|
|
||||||
|
|
||||||
# get or set current theme index number
|
# get theme name based on current index
|
||||||
def set_theme_name(x):
|
|
||||||
global __theme_name
|
|
||||||
__theme_name = str(x)
|
|
||||||
|
|
||||||
|
|
||||||
def get_theme_name():
|
def get_theme_name():
|
||||||
global __theme_name
|
theme_name = CONST.THEMES[get_theme_index()]['themeName']
|
||||||
return __theme_name
|
return theme_name
|
||||||
|
|
||||||
|
|
||||||
# get or set current theme icons based on the theme name
|
|
||||||
def set_theme_icons():
|
|
||||||
global __theme_icons
|
|
||||||
__theme_icons = CONST.THEMES[get_theme_name()]["themeIcons"]
|
|
||||||
|
|
||||||
|
|
||||||
|
# get theme icon sub-folder name based on current index
|
||||||
def get_theme_icons():
|
def get_theme_icons():
|
||||||
theme_icons = CONST.THEMES[get_theme_index()]['themeIcons']
|
theme_icons = CONST.THEMES[get_theme_index()]['themeIcons']
|
||||||
return str(theme_icons)
|
return str(theme_icons)
|
||||||
|
|
||||||
|
|
||||||
# get or set theme from json file
|
# get theme stylesheet css based on current index
|
||||||
def set_theme_file():
|
def get_theme_css_file():
|
||||||
theme_file = CONST.THEMES[get_theme_index()]['themeFile']
|
theme_file = CONST.THEMES[get_theme_index()]['themeFile']
|
||||||
global __theme_file
|
return str(theme_file)
|
||||||
__theme_file = theme_file
|
|
||||||
|
|
||||||
|
|
||||||
|
# save current theme index to json file
|
||||||
|
def save_theme_config():
|
||||||
pref_data = {
|
pref_data = {
|
||||||
"theme_index": get_theme_index()
|
"theme_index": get_theme_index()
|
||||||
}
|
}
|
||||||
with(open(THEME_PREFERENCES_FILE_PATH, "w")) as prefs:
|
with(open(THEME_PREFERENCES_FILE_PATH, "w")) as prefs:
|
||||||
prefs.write(json.dumps(pref_data))
|
prefs.write(json.dumps(pref_data))
|
||||||
|
|
||||||
|
|
||||||
def get_theme_file():
|
|
||||||
global __theme_file
|
|
||||||
return str(__theme_file)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user