-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
134 lines (105 loc) · 4.08 KB
/
launcher.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
import sys
import os
import logging
import datetime
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QTabWidget, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QCheckBox, QLineEdit, QTextEdit
from PyQt6.QtGui import QFont
from game import Game
log_folder = 'logs'
if not os.path.exists(log_folder):
os.makedirs(log_folder)
log_filename = os.path.join(log_folder, datetime.datetime.now().strftime('%Y-%m-%d') + '.log')
logging.basicConfig(filename=log_filename, level=logging.ERROR, format='%(asctime)s:%(levelname)s:%(message)s')
class GameLauncher(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Jeff the Grappler Launcher')
self.setGeometry(100, 100, 300, 300)
# Create tab widget
self.tabs = QTabWidget()
self.setCentralWidget(self.tabs)
# Create start game tab
self.start_game_tab = QWidget()
self.tabs.addTab(self.start_game_tab, "Start Game")
self.init_start_game_tab()
# Create options tab
self.options_tab = QWidget()
self.tabs.addTab(self.options_tab, "Options")
self.init_options_tab()
# Create log viewer tab
self.log_viewer_tab = QWidget()
self.tabs.addTab(self.log_viewer_tab, "Log Viewer")
self.init_log_viewer_tab()
def init_start_game_tab(self):
layout = QVBoxLayout()
# Add large label
game_label = QLabel('Jeff the Grappler', self)
font = QFont()
font.setPointSize(30) # Set font size to 30
game_label.setFont(font)
# Center the label horizontally
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(game_label)
hbox.addStretch(1)
layout.addLayout(hbox)
# Add start button
start_button = QPushButton('Start Game', self)
start_button.setFixedSize(300, 150) # Set button size to 300x150
start_button.clicked.connect(self.start_game)
layout.addWidget(start_button)
self.start_game_tab.setLayout(layout)
def init_options_tab(self):
layout = QVBoxLayout()
# Width input
self.width_input = QLineEdit(self)
self.width_input.setPlaceholderText("Width")
layout.addWidget(self.width_input)
# Height input
self.height_input = QLineEdit(self)
self.height_input.setPlaceholderText("Height")
layout.addWidget(self.height_input)
# FPS input
self.fps_input = QLineEdit(self)
self.fps_input.setPlaceholderText("FPS")
layout.addWidget(self.fps_input)
self.options_tab.setLayout(layout)
def init_log_viewer_tab(self):
layout = QVBoxLayout()
# Add log viewer
self.log_viewer = QTextEdit(self)
self.log_viewer.setReadOnly(True)
layout.addWidget(self.log_viewer)
# Add refresh button
refresh_button = QPushButton('Refresh', self)
refresh_button.clicked.connect(self.load_log)
layout.addWidget(refresh_button)
self.log_viewer_tab.setLayout(layout)
self.load_log()
def load_log(self):
try:
with open(log_filename, 'r') as file:
log_content = file.read()
self.log_viewer.setPlainText(log_content)
except Exception as e:
self.log_viewer.setPlainText(f"Failed to load log file: {e}")
def start_game(self):
self.hide()
width = int(self.width_input.text()) if self.width_input.text() else 1366
height = int(self.height_input.text()) if self.height_input.text() else 768
fps = int(self.fps_input.text()) if self.fps_input.text() else None
try:
game_instance = Game(width, height, fps)
game_instance.run()
except Exception as e:
logging.error("An error occurred in the game loop", exc_info=True)
logging.error(f"Error message: {e}")
def main():
app = QApplication(sys.argv)
launcher = GameLauncher()
launcher.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()