@@ -37,6 +37,9 @@ LauncherWindow::LauncherWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui
37
37
gameInstances = 0 ;
38
38
39
39
ui->setupUi (this );
40
+ connect (this , SIGNAL (enableUpdate (bool )), ui->updateButton , SLOT (setEnabled (bool )));
41
+ connect (ui->updatesCheckBox , SIGNAL (toggled (bool )), this , SLOT (toggleAutoUpdates ()));
42
+ connect (ui->updateButton , SIGNAL (clicked (bool )), this , SLOT (updateFiles ()));
40
43
41
44
// read the previous settings
42
45
readSettings ();
@@ -66,7 +69,15 @@ LauncherWindow::LauncherWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui
66
69
emit enableLogin (false );
67
70
loginIsReady = false ;
68
71
69
- updateFiles ();
72
+ if (autoUpdate)
73
+ {
74
+ updateFiles ();
75
+ }
76
+ else
77
+ {
78
+ loginReady ();
79
+ ui->progressBar ->hide ();
80
+ }
70
81
}
71
82
72
83
LauncherWindow::~LauncherWindow ()
@@ -94,10 +105,20 @@ void LauncherWindow::relayHideProgressBar()
94
105
emit hideProgressBar ();
95
106
}
96
107
108
+ void LauncherWindow::updatesReady ()
109
+ {
110
+ if (gameInstances == 0 )
111
+ {
112
+ emit enableUpdate (true );
113
+ }
114
+ }
115
+
97
116
void LauncherWindow::loginReady ()
98
117
{
99
118
emit enableLogin (true );
100
119
loginIsReady = true ;
120
+
121
+ emit sendMessage (" Logins are ready!" );
101
122
}
102
123
103
124
void LauncherWindow::initiateLogin ()
@@ -128,6 +149,9 @@ void LauncherWindow::initiateLogin()
128
149
129
150
void LauncherWindow::gameHasStarted ()
130
151
{
152
+ // disable updates while an instance is running
153
+ emit enableUpdate (false );
154
+
131
155
// check whether to save the credentials or not
132
156
if (ui->saveCredentialsBox ->isChecked ())
133
157
{
@@ -183,6 +207,9 @@ void LauncherWindow::gameHasFinished(int exitCode, QByteArray gameOutput)
183
207
" Looks like Toontown Rewritten has crashed. The engine's error message is:\n " + gameOutput,
184
208
QMessageBox::Ok);
185
209
}
210
+
211
+ // re-enable updates (checks to see if no other instances are running as well)
212
+ updatesReady ();
186
213
}
187
214
188
215
void LauncherWindow::authenticationFailed ()
@@ -232,13 +259,28 @@ void LauncherWindow::newsViewLoaded()
232
259
ui->newsWebview ->page ()->runJavaScript (QString (" document.body.style.backgroundColor = \" #141618\" ;" ));
233
260
}
234
261
262
+ void LauncherWindow::toggleAutoUpdates ()
263
+ {
264
+ if (ui->updatesCheckBox ->isChecked ())
265
+ {
266
+ autoUpdate = true ;
267
+ }
268
+ else
269
+ {
270
+ autoUpdate = false ;
271
+ }
272
+
273
+ writeSettings ();
274
+ }
275
+
235
276
void LauncherWindow::writeSettings ()
236
277
{
237
278
QSettings settings (" Shticker-Book-Rewritten" , " Shticker-Book-Rewritten" );
238
279
239
280
settings.beginGroup (" LauncherWindow" );
240
281
settings.setValue (" size" , size ());
241
282
settings.setValue (" pos" , pos ());
283
+ settings.setValue (" update" , autoUpdate);
242
284
settings.endGroup ();
243
285
244
286
settings.beginGroup (" Logins" );
@@ -254,13 +296,19 @@ void LauncherWindow::readSettings()
254
296
settings.beginGroup (" LauncherWindow" );
255
297
resize (settings.value (" size" , QSize (400 , 400 )).toSize ());
256
298
move (settings.value (" pos" , QPoint (200 , 200 )).toPoint ());
299
+ autoUpdate = settings.value (" update" , true ).toBool ();
257
300
settings.endGroup ();
258
301
259
302
settings.beginGroup (" Logins" );
260
303
savedUsers = settings.value (" username" ).toStringList ();
261
304
savedPasses = settings.value (" pass" ).toStringList ();
262
305
settings.endGroup ();
263
306
307
+ if (autoUpdate)
308
+ {
309
+ ui->updatesCheckBox ->setChecked (true );
310
+ }
311
+
264
312
readSettingsPath ();
265
313
}
266
314
@@ -298,6 +346,10 @@ void LauncherWindow::fillCredentials(QString username)
298
346
299
347
void LauncherWindow::updateFiles ()
300
348
{
349
+ ui->progressBar ->show ();
350
+
351
+ emit enableUpdate (false );
352
+
301
353
// check to make sure the cache directory exists and make it if it doesn't
302
354
if (!QDir (filePath).exists ())
303
355
{
@@ -323,6 +375,7 @@ void LauncherWindow::updateFiles()
323
375
connect (updateWorker, SIGNAL (showProgressBar ()), this , SLOT (relayShowProgressBar ()));
324
376
connect (updateWorker, SIGNAL (hideProgressBar ()), this , SLOT (relayHideProgressBar ()));
325
377
connect (updateWorker, SIGNAL (updateComplete ()), this , SLOT (loginReady ()));
378
+ connect (updateWorker, SIGNAL (updateComplete ()), this , SLOT (updatesReady ()));
326
379
327
380
updateThread->start ();
328
381
}
0 commit comments