-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull.py
339 lines (274 loc) · 11 KB
/
full.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import sys
import os
import subprocess
import json
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QPushButton, QFileDialog, QGridLayout, QLabel, QLineEdit, QMessageBox, QListWidget, QHBoxLayout, QSizePolicy
)
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QPixmap, QFontDatabase, QFont, QIcon
CONFIG_FILE = "config.json"
class ConfigManager:
def __init__(self, config_file=CONFIG_FILE):
self.config_file = config_file
self.config = self.load_config()
def load_config(self):
if os.path.exists(self.config_file):
with open(self.config_file, 'r') as file:
return json.load(file)
return {"gzdoom_path": "", "pk3_files": [], "presets": {}, "preset_window_position": (100, 100), "options_window_position": (100, 100)}
def save_config(self):
with open(self.config_file, 'w') as file:
json.dump(self.config, file, indent=4)
def update_gzdoom_path(self, path):
self.config["gzdoom_path"] = path
self.save_config()
class BaseWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowIcon(QIcon("./resources/icon.ico"))
self.config_manager = ConfigManager()
self.load_custom_font()
self.setStyleSheet(self.get_stylesheet())
def load_custom_font(self):
font_id = QFontDatabase.addApplicationFont("./fonts/doomed.ttf")
font_families = QFontDatabase.applicationFontFamilies(font_id)
if font_families:
self.setFont(QFont(font_families[0], 12))
def center_window(self):
screen = self.screen()
screen_rect = screen.availableGeometry()
self.move(
(screen_rect.width() - self.width()) // 2,
(screen_rect.height() - self.height()) // 2
)
def get_stylesheet(self):
return """
QWidget {
background-color: #1a1a1a; /* Gris muy oscuro */
}
QLabel {
font-size: 20px;
color: white;
margin-bottom: 10px;
text-align: center;
}
QPushButton {
padding: 10px 20px;
text-transform: uppercase;
border-radius: 8px;
font-size: 17px;
font-weight: 500;
color: #ffffff80;
background: transparent;
border: 1px solid #ffffff80;
}
QPushButton:hover,
QPushButton:focus {
color: #ffffff;
background: #ff0019;
border: 1px solid #932323;
}
QLineEdit {
padding: 10px;
border: 1px solid #ffffff80;
border-radius: 8px;
color: #ffffff;
background: transparent;
}
QListWidget {
border: 1px solid #ffffff80;
border-radius: 8px;
background: transparent;
color: white;
}
QListWidget::item {
padding: 10px;
}
QListWidget::item:selected {
background: #ad1414;
}
"""
class SplashScreen(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.FramelessWindowHint)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.init_ui()
def init_ui(self):
layout = QVBoxLayout()
self.label = QLabel()
pixmap = QPixmap("./resources/moodselectorlogo.png")
self.label.setPixmap(pixmap)
layout.addWidget(self.label)
self.setLayout(layout)
self.setFixedSize(pixmap.width(), pixmap.height())
self.center_window()
def center_window(self):
screen = self.screen()
screen_rect = screen.availableGeometry()
self.move(
(screen_rect.width() - self.width()) // 2,
(screen_rect.height() - self.height()) // 2
)
class PresetWindow(BaseWindow):
def __init__(self):
super().__init__()
self.pk3_files = []
self.init_ui()
self.load_presets()
self.center_window()
def init_ui(self):
self.setWindowTitle("Select Preset")
self.setFixedSize(400, 500)
layout = self.create_main_layout()
self.setLayout(layout)
def create_main_layout(self):
layout = QVBoxLayout()
layout.setContentsMargins(50, 50, 50, 50)
self.label_presets = QLabel("Select Game")
self.label_presets.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_presets.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
layout.addWidget(self.label_presets, alignment=Qt.AlignmentFlag.AlignHCenter)
self.grid_layout = QGridLayout()
layout.addLayout(self.grid_layout)
layout.addSpacing(20)
layout.addLayout(self.create_options_layout())
return layout
def create_options_layout(self):
options_layout = QHBoxLayout()
self.options_button = QPushButton("Options")
self.options_button.setObjectName("optionsButton") # Set object name for styling
self.options_button.clicked.connect(self.show_options)
options_layout.addStretch()
options_layout.addWidget(self.options_button)
options_layout.addStretch()
return options_layout
def load_presets(self):
self.clear_grid_layout()
preset_buttons = self.create_preset_buttons()
self.add_buttons_to_layout(preset_buttons)
def clear_grid_layout(self):
for i in reversed(range(self.grid_layout.count())):
widget = self.grid_layout.itemAt(i).widget()
if widget is not None:
widget.deleteLater()
def create_preset_buttons(self):
preset_buttons = []
for preset_name in os.listdir("."):
if preset_name.endswith(".json") and preset_name != CONFIG_FILE:
button_text = os.path.splitext(os.path.basename(preset_name))[0]
button = QPushButton(button_text)
button.clicked.connect(lambda checked, name=preset_name: self.run_selected_preset(name))
preset_buttons.append(button)
return preset_buttons
def add_buttons_to_layout(self, preset_buttons):
for index, button in enumerate(preset_buttons):
self.grid_layout.addWidget(button, index // 3, index % 3)
def run_selected_preset(self, preset_name):
try:
with open(preset_name, 'r') as preset_file:
self.pk3_files = json.load(preset_file)
self.run_gzdoom()
except Exception as e:
QMessageBox.warning(self, "Error", f"Could not load the preset: {str(e)}")
def run_gzdoom(self):
if not self.pk3_files:
QMessageBox.warning(self, "Error", "No mods in this preset.")
return
gzdoom_path = self.config_manager.config.get("gzdoom_path", "")
if not gzdoom_path:
QMessageBox.warning(self, "Error", "GZDoom is not configured.")
return
command = [gzdoom_path] + ["-file"] + self.pk3_files
subprocess.Popen(command)
def show_options(self):
self.save_position()
self.options_window = DoomModSelectorApp()
self.options_window.show()
self.close()
def save_position(self):
self.config_manager.config["preset_window_position"] = (self.x(), self.y())
self.config_manager.save_config()
class DoomModSelectorApp(BaseWindow):
def __init__(self):
super().__init__()
self.pk3_files = []
self.init_ui()
self.load_pk3_files()
self.center_window()
def init_ui(self):
self.setWindowTitle("Doom Mod Selector")
self.setFixedSize(400, 500)
layout = QVBoxLayout()
layout.setContentsMargins(50, 50, 50, 50)
self.label = QLabel("Selected PK3 Mods:")
layout.addWidget(self.label)
self.list_widget = QListWidget()
layout.addWidget(self.list_widget)
self.add_button = QPushButton("Add PK3")
self.add_button.clicked.connect(self.add_pk3_file)
layout.addWidget(self.add_button)
self.gzdoom_input = QLineEdit("")
self.gzdoom_input.setPlaceholderText("Path to GZDoom.exe")
layout.addWidget(self.gzdoom_input)
self.browse_button = QPushButton("Browse GZDoom")
self.browse_button.clicked.connect(self.browse_gzdoom_path)
layout.addWidget(self.browse_button)
self.save_preset_button = QPushButton("Save Preset")
self.save_preset_button.clicked.connect(self.save_preset)
layout.addWidget(self.save_preset_button)
self.run_button = QPushButton("Run GZDoom")
self.run_button.clicked.connect(self.run_gzdoom)
layout.addWidget(self.run_button)
self.back_button = QPushButton("Back to Presets")
self.back_button.clicked.connect(self.back_to_presets)
layout.addWidget(self.back_button)
self.setLayout(layout)
def add_pk3_file(self):
files, _ = QFileDialog.getOpenFileNames(self, "Select PK3 Files", "", "PK3 Files (*.pk3);;All Files (*)")
if files:
self.pk3_files.extend(files)
self.update_pk3_list()
def browse_gzdoom_path(self):
file, _ = QFileDialog.getOpenFileName(self, "Select GZDoom.exe", "", "Executable Files (*.exe);;All Files (*)")
if file:
self.gzdoom_input.setText(file)
self.save_gzdoom_path()
def save_gzdoom_path(self):
self.config_manager.update_gzdoom_path(self.gzdoom_input.text())
def load_pk3_files(self):
self.pk3_files = self.config_manager.config.get("pk3_files", [])
self.update_pk3_list()
def update_pk3_list(self):
self.list_widget.clear()
self.list_widget.addItems(self.pk3_files)
def save_preset(self):
preset_name, _ = QFileDialog.getSaveFileName(self, "Save Preset", "", "JSON Files (*.json)")
if preset_name:
with open(preset_name, 'w') as preset_file:
json.dump(self.pk3_files, preset_file)
def run_gzdoom(self):
if not self.pk3_files:
QMessageBox.warning(self, "Error", "No mods selected.")
return
gzdoom_path = self.config_manager.config.get("gzdoom_path", "")
if not gzdoom_path:
QMessageBox.warning(self, "Error", "GZDoom is not configured.")
return
command = [gzdoom_path] + ["-file"] + self.pk3_files
subprocess.Popen(command)
def back_to_presets(self):
self.save_position()
self.preset_window = PresetWindow()
self.preset_window.show()
self.close()
def save_position(self):
self.config_manager.config["options_window_position"] = (self.x(), self.y())
self.config_manager.save_config()
if __name__ == "__main__":
app = QApplication(sys.argv)
splash = SplashScreen()
splash.show()
QTimer.singleShot(2000, lambda: [splash.close(), PresetWindow().show()]) # 2000 ms = 2 seconds
sys.exit(app.exec())