@@ -145,29 +145,104 @@ bool MainWindow::checkServerExists(QString dstds_path, bool reload_template)
145
145
QDir checkFolder;
146
146
if (checkFolder.exists (dstds_path+ QString (" /" ) + QString (folder_world)) && checkFolder.exists (dstds_path+ QString (" /" ) + QString (folder_cave)))
147
147
{
148
+ if (!readINI (DST_WORLD, dstds_path + QString (" /" ) + QString (folder_cave) + QString (" /" ) + QString (settings_ini)))
149
+ {
150
+ QMessageBox::critical (this , " Error" , " Cannot found ini files in world folder!" );
151
+ writeINIToGUI (DST_WORLD);
152
+ return false ;
153
+ }
148
154
if (!readINI (DST_CAVE, dstds_path + QString (" /" ) + QString (folder_world) + QString (" /" ) + QString (settings_ini)))
149
155
{
150
156
QMessageBox::critical (this , " Error" , " Cannot found ini files in cave folder!" );
151
157
return false ;
152
158
}
153
- if (!readINI (DST_WORLD, dstds_path + QString (" /" ) + QString (folder_cave) + QString (" /" ) + QString (settings_ini), true ))
159
+
160
+ if (!readLua (DST_WORLD, dstds_path + QString (" /" ) + QString (folder_cave) + QString (" /" ) + QString (override_lua)))
154
161
{
155
162
QMessageBox::critical (this , " Error" , " Cannot found ini files in world folder!" );
163
+ writeLuaToGUI (DST_WORLD);
156
164
return false ;
157
165
}
158
166
167
+
159
168
disableSetttingsWhenServerExists (true );
160
169
return true ;
161
170
}
162
171
else if (reload_template)
163
172
{
164
173
readINI (DST_CAVE, QString (" template/" ) + QString (ini_cave));
165
174
readINI (DST_WORLD, QString (" template/" ) + QString (ini_world));
175
+ readLua (DST_WORLD, QString (" template/" ) + QString (override_world_lua_template));
176
+ writeINIToGUI (DST_WORLD);
177
+ writeLuaToGUI (DST_WORLD);
166
178
disableSetttingsWhenServerExists (false );
167
179
}
168
180
return false ;
169
181
}
170
182
183
+ void MainWindow::writeINIToGUI (int world_num)
184
+ {
185
+ for (int i = 0 ; i < world[world_num].ini .size (); i++)
186
+ {
187
+ properties &p = world[world_num].ini [i];
188
+ QString name = p.name ;
189
+ QString value = p.settings ;
190
+
191
+ if (!name.compare (" default_server_name" )){ui->lineEdit_servername ->setText (value);}
192
+ else if (!name.compare (" default_server_description" )){ui->lineEdit_serverDescription ->setText (value);}
193
+ else if (!name.compare (" max_players" )){ui->spinBox_serverMaxPlayers ->setValue (value.toInt ());}
194
+ else if (!name.compare (" server_password" )){ui->lineEdit_serverPassword ->setText (value);}
195
+ else if (!name.compare (" server_save_slot" )){ui->comboBox_serverSaveSlot ->setCurrentIndex (value.toInt () - 1 );}
196
+ else if (!name.compare (" server_intention" ))
197
+ {
198
+ if (!name.compare (" cooperative" ))
199
+ ui->comboBox_serverIntention ->setCurrentIndex (0 );
200
+ }
201
+ else if (!name.compare (" game_mode" ))
202
+ {
203
+ if (!name.compare (" Endless" ))
204
+ ui->comboBox_gamemode ->setCurrentIndex (0 );
205
+ else if (!name.compare (" Survival" ))
206
+ ui->comboBox_gamemode ->setCurrentIndex (1 );
207
+ else if (!name.compare (" Wilderness" ))
208
+ ui->comboBox_gamemode ->setCurrentIndex (2 );
209
+ }
210
+ else if (!name.compare (" pvp" ))
211
+ {
212
+ (!value.compare (" true" )) ? ui->radioButton_pvpYes ->setChecked (true ) : ui->radioButton_pvpNo ->setChecked (true );
213
+ }
214
+ }
215
+ }
216
+
217
+ void MainWindow::writeLuaToGUI (int world_num)
218
+ {
219
+ if (world_num == DST_WORLD)
220
+ {
221
+ ui->tableWidget_worldGen ->clear ();
222
+ ui->tableWidget_worldGen ->setColumnCount (3 );
223
+ ui->tableWidget_worldGen ->setRowCount (world[world_num].pro .size ());
224
+ ui->tableWidget_worldGen ->setHorizontalHeaderItem (0 , new QTableWidgetItem (" Group" ));
225
+ ui->tableWidget_worldGen ->setHorizontalHeaderItem (1 , new QTableWidgetItem (" Name" ));
226
+ QTableWidgetItem* t3 = new QTableWidgetItem (" Value" );
227
+ t3->setBackground (Qt::lightGray);
228
+ ui->tableWidget_worldGen ->setHorizontalHeaderItem (2 , t3);
229
+
230
+ for (int i = 0 ; i < world[world_num].pro .size (); i++)
231
+ {
232
+ properties &p = world[world_num].pro [i];
233
+ QTableWidgetItem* n1 = new QTableWidgetItem (p.group );
234
+ n1->setFlags (n1->flags () & ~Qt::ItemIsEditable);
235
+ ui->tableWidget_worldGen ->setItem (i, 0 , n1);
236
+ QTableWidgetItem* n2 = new QTableWidgetItem (p.name );
237
+ n2->setFlags (n2->flags () & ~Qt::ItemIsEditable);
238
+ ui->tableWidget_worldGen ->setItem (i, 1 , n2);
239
+ QTableWidgetItem* n3 = new QTableWidgetItem (p.settings );
240
+ n3->setBackground (Qt::lightGray);
241
+ ui->tableWidget_worldGen ->setItem (i, 2 , n3);
242
+ }
243
+ }
244
+ }
245
+
171
246
bool MainWindow::firstServerSetup ()
172
247
{
173
248
_dstds_folder = ui->lineEdit_serverDataLocation ->text ();
@@ -257,33 +332,6 @@ void MainWindow::changeSettings(int world_num, QString name, QString value)
257
332
}
258
333
}
259
334
260
- void MainWindow::changeBasicSettingsUI (QString name, QString value)
261
- {
262
- if (!name.compare (" default_server_name" )){ui->lineEdit_servername ->setText (value);}
263
- else if (!name.compare (" default_server_description" )){ui->lineEdit_serverDescription ->setText (value);}
264
- else if (!name.compare (" max_players" )){ui->spinBox_serverMaxPlayers ->setValue (value.toInt ());}
265
- else if (!name.compare (" server_password" )){ui->lineEdit_serverPassword ->setText (value);}
266
- else if (!name.compare (" server_save_slot" )){ui->comboBox_serverSaveSlot ->setCurrentIndex (value.toInt () - 1 );}
267
- else if (!name.compare (" server_intention" ))
268
- {
269
- if (!name.compare (" cooperative" ))
270
- ui->comboBox_serverIntention ->setCurrentIndex (0 );
271
- }
272
- else if (!name.compare (" game_mode" ))
273
- {
274
- if (!name.compare (" Endless" ))
275
- ui->comboBox_gamemode ->setCurrentIndex (0 );
276
- else if (!name.compare (" Survival" ))
277
- ui->comboBox_gamemode ->setCurrentIndex (1 );
278
- else if (!name.compare (" Wilderness" ))
279
- ui->comboBox_gamemode ->setCurrentIndex (2 );
280
- }
281
- else if (!name.compare (" pvp" ))
282
- {
283
- (!value.compare (" true" )) ? ui->radioButton_pvpYes ->setChecked (true ) : ui->radioButton_pvpNo ->setChecked (true );
284
- }
285
- }
286
-
287
335
bool MainWindow::readINI (int world_num, QString file_path, bool ui_c)
288
336
{
289
337
QSettings settings (file_path, QSettings::IniFormat);
@@ -300,7 +348,6 @@ bool MainWindow::readINI(int world_num, QString file_path, bool ui_c)
300
348
ini.settings = settings.value (keys[j]).toString ();
301
349
302
350
world[world_num].ini .push_back (ini);
303
- changeBasicSettingsUI (ini.name , ini.settings );
304
351
}
305
352
settings.endGroup ();
306
353
}
@@ -321,24 +368,8 @@ bool MainWindow::writeINI(int world_num, QString file_path)
321
368
// Custom lua content in app currently not supported. Please modify the template file directly to work.
322
369
bool MainWindow::readLua (int world_num, QString file_path)
323
370
{
324
- if (world_num == DST_WORLD)
325
- {
326
- // QFile file_r("template/worldgenoverride_cave.lua");
327
- // if(!file_r.open(QIODevice::ReadOnly))
328
- // {
329
- // return false;
330
- // }
331
-
332
- // if(file.open(QIODevice::ReadWrite))
333
- // {
334
- // QTextStream stream(&file);
335
-
336
- // }
337
- }
338
- else if (world_num == DST_CAVE)
339
- {
340
-
341
- }
371
+ IOWorldGenOverrideLua genlua;
372
+ genlua.readLuaFile (world[world_num].pro , file_path);
342
373
return true ;
343
374
}
344
375
@@ -348,14 +379,7 @@ bool MainWindow::writeLua(int world_num, QString file_path)
348
379
// QFile file_w(file_path);
349
380
if (world_num == DST_WORLD)
350
381
{
351
- if (world[0 ].pro .empty ())
352
- {
353
- return QFile::copy (" template/worldgenoverride_world.lua" , file_path);
354
- }
355
- else
356
- {
357
-
358
- }
382
+ return QFile::copy (" template/worldgenoverride_world.lua" , file_path);
359
383
}
360
384
else if (world_num == DST_CAVE)
361
385
{
@@ -416,12 +440,6 @@ void MainWindow::on_pushButton_startServer_clicked()
416
440
return ;
417
441
}
418
442
419
-
420
-
421
- // Check again if the folder changed.
422
- ui->statusBar ->showMessage (" Check if there is an existing server." );
423
- _server_found = checkServerExists (_dstds_folder, false );
424
-
425
443
if (!_server_found)
426
444
{
427
445
ui->statusBar ->showMessage (" Creating new server." );
0 commit comments