-
Notifications
You must be signed in to change notification settings - Fork 16
/
mainwindow.cpp
233 lines (199 loc) · 5.61 KB
/
mainwindow.cpp
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
/*
The MIT License (MIT)
Copyright (c) 2013 The ioquake Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <QDir>
#include <QMessageBox>
#include <QProcess>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "installwizard.h"
#include "quakeutils.h"
ioLaunch::ioLaunch(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ioLaunch)
{
ui->setupUi(this);
// Calculate the ioquake3 home path.
const QString homePath = QuakeUtils::calculateHomePath();
const QDir homeDir(homePath);
// Try to parse q3config.cfg to get default settings if this is the first time the program has run.
if (!homePath.isEmpty() && homeDir.exists() && !settings.getHaveRun())
{
QuakeUtils::parseQuake3Config(&settings, homePath);
}
// On first run, try to get the Q3A path.
if (!settings.getHaveRun())
{
settings.setQuakePath(QuakeUtils::calculateQuake3Path());
}
settings.setHaveRun(true);
// Populate the GUI with values read from settings.
if (settings.getResolutionMode() >= 0)
{
// Predefined.
ui->cbResolution->setCurrentIndex(2 + settings.getResolutionMode());
}
else if (settings.getResolutionMode() == -1)
{
// Custom.
ui->cbResolution->setCurrentIndex(1);
}
else if (settings.getResolutionMode() == -2)
{
// Desktop.
ui->cbResolution->setCurrentIndex(0);
}
ui->sbWidth->setValue(settings.getResolutionWidth());
ui->sbHeight->setValue(settings.getResolutionHeight());
if (settings.getResolutionFullscreen())
{
ui->rbFull->setChecked(true);
}
else
{
ui->rbWin->setChecked(true);
}
}
ioLaunch::~ioLaunch()
{
delete ui;
}
void ioLaunch::on_btnLaunch_clicked()
{
QString ioq3;
#ifdef Q_OS_WIN32
if(!isQuake3PathValid())
{
InstallWizard wizard(this, &settings);
wizard.exec();
if(!isQuake3PathValid())
return;
}
ioq3 = QString("\"") + settings.getQuakePath() + "/ioquake3.x86.exe\"";
#else
#if defined Q_OS_MAC
ioq3 = "open -a ioquake3 --args";
#elif defined Q_OS_UNIX
ioq3 = "ioquake3";
#else
#error "Unsupported platform"
#endif
QString quakePath = settings.getQuakePath();
if ( !quakePath.isEmpty() )
{
ioq3 += QString(" +set fs_basepath \"%1\"").arg(quakePath);
}
#endif
int r_mode = settings.getResolutionMode();
int r_width = settings.getResolutionWidth();
int r_height = settings.getResolutionHeight();
// Handle modes outside what ioquake3 recognize.
if (r_mode == 12)
{
r_mode = -1;
r_width = 1280;
r_height = 720;
}
else if (r_mode == 13)
{
r_mode = -1;
r_width = 1920;
r_height = 1080;
}
else if (r_mode == 14)
{
r_mode = -1;
r_width = 1280;
r_height = 800;
}
ioq3 += QString(" +set r_mode \"%1\"").arg(r_mode);
if (r_mode == -1)
{
ioq3 += QString(" +set r_customwidth %1").arg(r_width) + QString(" +set r_customheight %1").arg(r_height);
}
ioq3 += QString(" +set r_fullscreen %1").arg(settings.getResolutionFullscreen() ? "1" : "0");
if(!QProcess::startDetached(ioq3))
{
QMessageBox ioq3Failed;
ioq3Failed.setText("ioquake3 failed to start!\nIs it installed?\n");
ioq3Failed.exec();
}
}
void ioLaunch::on_cbResolution_currentIndexChanged(int index)
{
if (index == 0)
{
// Desktop.
settings.setResolutionMode(-2);
}
else if (index == 1)
{
// Custom.
settings.setResolutionMode(-1);
}
else if (index >= 2)
{
// Predefined.
settings.setResolutionMode(index - 2);
}
if (index == 1)
{
ui->sbWidth->setEnabled(true);
ui->sbHeight->setEnabled(true);
}
else
{
ui->sbWidth->setEnabled(false);
ui->sbHeight->setEnabled(false);
}
}
void ioLaunch::on_rbFull_toggled(bool checked)
{
if(checked)
{
settings.setResolutionFullscreen(true);
}
}
void ioLaunch::on_rbWin_toggled(bool checked)
{
if(checked)
{
settings.setResolutionFullscreen(false);
}
}
void ioLaunch::on_sbWidth_valueChanged(int arg1)
{
settings.setResolutionWidth(arg1);
}
void ioLaunch::on_sbHeight_valueChanged(int arg1)
{
settings.setResolutionHeight(arg1);
}
void ioLaunch::on_btnRunInstallWizard_clicked()
{
InstallWizard wizard(this, &settings);
wizard.exec();
}
#ifdef Q_OS_WIN32
bool ioLaunch::isQuake3PathValid() const
{
if (!settings.containsQuakePath())
return false;
return !settings.getQuakePath().isEmpty() && QDir(settings.getQuakePath()).exists();
}
#endif