Freeciv-3.3
Loading...
Searching...
No Matches
tab_misc.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#ifdef FREECIV_MSWINDOWS
19#include <shlobj.h>
20#endif
21
22// Qt
23#include <QCheckBox>
24#include <QGridLayout>
25#include <QHeaderView>
26#include <QLineEdit>
27#include <QMessageBox>
28#include <QPushButton>
29#include <QTableWidget>
30
31// utility
32#include "fcintl.h"
33#include "log.h"
34#include "registry.h"
35
36// common
37#include "achievements.h"
38#include "counters.h"
39#include "game.h"
40#include "government.h"
41#include "specialist.h"
42
43// server
44#include "rssanity.h"
45
46// ruledit
47#include "conversion_log.h"
48#include "ruledit.h"
49#include "ruledit_qt.h"
50#include "rulesave.h"
51
52#include "tab_misc.h"
53
54/**********************************************************************/
58{
59 QGridLayout *main_layout = new QGridLayout(this);
60 QLabel *save_label;
61 QLabel *save_ver_label;
62 QLabel *label;
63 QLabel *name_label;
64 QLabel *version_label;
65 QPushButton *button;
66 int row = 0;
68 char ttbuf[2048];
69
70 ui = ui_in;
71
72 main_layout->setSizeConstraint(QLayout::SetMaximumSize);
73
74 name_label = new QLabel(QString::fromUtf8(R__("Ruleset name")));
75 name_label->setParent(this);
76 main_layout->addWidget(name_label, row, 0);
77 name = new QLineEdit(this);
78 main_layout->addWidget(name, row++, 1);
79 version_label = new QLabel(QString::fromUtf8(R__("Ruleset version")));
80 version_label->setParent(this);
81 main_layout->addWidget(version_label, row, 0);
82 version = new QLineEdit(this);
83 main_layout->addWidget(version, row++, 1);
84 save_label = new QLabel(QString::fromUtf8(R__("Save to directory")));
85 save_label->setParent(this);
86 main_layout->addWidget(save_label, row, 0);
87 savedir = new QLineEdit(this);
88
89#ifdef FREECIV_MSWINDOWS
91
93 nullptr, &folder_path) == S_OK) {
94 savedir->setText(QString::fromWCharArray(folder_path) + "\\ruledit-tmp");
95 } else {
96 savedir->setText("ruledit-tmp");
97 }
98
99#else // FREECIV_MSWINDOWS
100 savedir->setText("ruledit-tmp");
101#endif // FREECIV_MSWINDOWS
102
103 /* TRANS: %s%s%s -> path + directory separator ('/' or '\') + path
104 * Do not translate command '/rulesetdir' name. */
105 fc_snprintf(ttbuf, sizeof(ttbuf),
106 R__("If you want to be able to load the ruleset directly "
107 "to freeciv, place it as a subdirectory under %s%s%s\n"
108 "Use server command \"/rulesetdir <subdirectory>\" "
109 "to load it to freeciv."),
111 savedir->setToolTip(ttbuf);
112
113 savedir->setFocus();
114 main_layout->addWidget(savedir, row++, 1);
115 save_ver_label = new QLabel(QString::fromUtf8(R__("Version suffix to directory name")));
116 save_ver_label->setParent(this);
117 main_layout->addWidget(save_ver_label, row, 0);
118 savedir_version = new QCheckBox(this);
119 main_layout->addWidget(savedir_version, row++, 1);
120 button = new QPushButton(QString::fromUtf8(R__("Save now")), this);
121 connect(button, SIGNAL(pressed()), this, SLOT(save_now()));
122 main_layout->addWidget(button, row++, 1);
123
124 label = new QLabel(QString::fromUtf8(R__("Description from file")));
125 label->setParent(this);
126 main_layout->addWidget(label, row, 0);
127 desc_via_file = new QCheckBox(this);
128 connect(desc_via_file, SIGNAL(toggled(bool)), this, SLOT(desc_file_toggle(bool)));
129 main_layout->addWidget(desc_via_file, row++, 1);
130
131 label = new QLabel(QString::fromUtf8(R__("Description file")));
132 label->setParent(this);
133 main_layout->addWidget(label, row, 0);
134 desc_file = new QLineEdit(this);
135 main_layout->addWidget(desc_file, row++, 1);
136
137 button = new QPushButton(QString::fromUtf8(R__("Sanity check rules")), this);
138 connect(button, SIGNAL(pressed()), this, SLOT(sanity_check()));
139 main_layout->addWidget(button, row++, 1);
140
141 button = new QPushButton(QString::fromUtf8(R__("Always active Effects")), this);
142 connect(button, SIGNAL(pressed()), this, SLOT(edit_aae_effects()));
143 main_layout->addWidget(button, row++, 1);
144 button = new QPushButton(QString::fromUtf8(R__("All Effects")), this);
145 connect(button, SIGNAL(pressed()), this, SLOT(edit_all_effects()));
146 main_layout->addWidget(button, row++, 1);
147
148 stats = new QTableWidget(this);
149 stats->setColumnCount(8);
150 stats->setRowCount(7);
151 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Terrains")));
152 stats->setItem(0, 0, item);
153 item = new QTableWidgetItem("-");
154 stats->setItem(0, 1, item);
155 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Resources")));
156 stats->setItem(1, 0, item);
157 item = new QTableWidgetItem("-");
158 stats->setItem(1, 1, item);
159 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Tech Classes")));
160 stats->setItem(2, 0, item);
161 item = new QTableWidgetItem("-");
162 stats->setItem(2, 1, item);
163 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Techs")));
164 stats->setItem(3, 0, item);
165 item = new QTableWidgetItem("-");
166 stats->setItem(3, 1, item);
167 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Unit Classes")));
168 stats->setItem(4, 0, item);
169 item = new QTableWidgetItem("-");
170 stats->setItem(4, 1, item);
171 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Unit Types")));
172 stats->setItem(5, 0, item);
173 item = new QTableWidgetItem("-");
174 stats->setItem(5, 1, item);
175 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Enablers")));
176 stats->setItem(6, 0, item);
177 item = new QTableWidgetItem("-");
178 stats->setItem(6, 1, item);
179 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Buildings")));
180 stats->setItem(0, 3, item);
181 item = new QTableWidgetItem("-");
182 stats->setItem(0, 4, item);
183 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Nations")));
184 stats->setItem(1, 3, item);
185 item = new QTableWidgetItem("-");
186 stats->setItem(1, 4, item);
187 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Styles")));
188 stats->setItem(2, 3, item);
189 item = new QTableWidgetItem("-");
190 stats->setItem(2, 4, item);
191 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Specialists")));
192 stats->setItem(3, 3, item);
193 item = new QTableWidgetItem("-");
194 stats->setItem(3, 4, item);
195 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Governments")));
196 stats->setItem(4, 3, item);
197 item = new QTableWidgetItem("-");
198 stats->setItem(4, 4, item);
199 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Disasters")));
200 stats->setItem(5, 3, item);
201 item = new QTableWidgetItem("-");
202 stats->setItem(5, 4, item);
203 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Counters")));
204 stats->setItem(6, 3, item);
205 item = new QTableWidgetItem("-");
206 stats->setItem(6, 4, item);
207 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Achievements")));
208 stats->setItem(0, 6, item);
209 item = new QTableWidgetItem("-");
210 stats->setItem(0, 7, item);
211 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Extras")));
212 stats->setItem(1, 6, item);
213 item = new QTableWidgetItem("-");
214 stats->setItem(1, 7, item);
215 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Bases")));
216 stats->setItem(2, 6, item);
217 item = new QTableWidgetItem("-");
218 stats->setItem(2, 7, item);
219 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Roads")));
220 stats->setItem(3, 6, item);
221 item = new QTableWidgetItem("-");
222 stats->setItem(3, 7, item);
223 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Goods")));
224 stats->setItem(4, 6, item);
225 item = new QTableWidgetItem("-");
226 stats->setItem(4, 7, item);
227 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Multipliers")));
228 stats->setItem(5, 6, item);
229 item = new QTableWidgetItem("-");
230 stats->setItem(5, 7, item);
231 item = new QTableWidgetItem(QString::fromUtf8(RQ_("?stat:Effects")));
232 stats->setItem(6, 6, item);
233 item = new QTableWidgetItem("-");
234 stats->setItem(6, 7, item);
235 stats->verticalHeader()->setVisible(false);
236 stats->horizontalHeader()->setVisible(false);
237 stats->setEditTriggers(QAbstractItemView::NoEditTriggers);
238 main_layout->addWidget(stats, row++, 0, 1, 2);
239 button = new QPushButton(QString::fromUtf8(R__("Refresh Stats")), this);
240 connect(button, SIGNAL(pressed()), this, SLOT(refresh_stats()));
241 main_layout->addWidget(button, row++, 0, 1, 2);
242
243 refresh();
244
245 setLayout(main_layout);
246}
247
248/**********************************************************************/
252{
253 if (game.server.ruledit.description_file != nullptr) {
254 desc_via_file->setChecked(true);
256 } else {
257 desc_file->setEnabled(false);
258 }
259
260 refresh();
261}
262
263/**********************************************************************/
267{
268 name->setText(game.control.name);
269 version->setText(game.control.version);
271}
272
273/**********************************************************************/
277{
281
282 ui->flush_widgets();
283
284 ba_bytes = name->text().toUtf8();
285 strncpy(nameUTF8, ba_bytes.data(), sizeof(nameUTF8) - 1);
286
287 if (nameUTF8[0] != '\0') {
289 }
290
291 ba_bytes = version->text().toUtf8();
293 sizeof(game.control.version) - 1);
294
296 QMessageBox *box = new QMessageBox();
297
298 box->setText("Current data fails sanity checks. Save anyway?");
299 box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
300 box->exec();
301
302 if (box->result() != QMessageBox::Yes) {
303 return;
304 }
305 }
306
307 if (savedir_version->isChecked()) {
308 full_dir = savedir->text() + "-" + version->text();
309 } else {
310 full_dir = savedir->text();
311 }
312
313 ba_bytes = full_dir.toUtf8();
315 &(ui->data));
316
317 ui->display_msg(R__("Ruleset saved"));
318}
319
320/**********************************************************************/
327static bool effect_counter(struct effect *peff, void *data)
328{
329 (*(int *)data)++;
330
331 return TRUE;
332}
333
334/**********************************************************************/
338{
339 int row = 0;
340 int count;
341 int base_count;
342 int road_count;
343
344 count = 0;
346 count++;
348 stats->item(row++, 1)->setText(QString::number(count));
349
350 stats->item(row++, 1)->setText(QString::number(game.control.num_resource_types));
351
352 count = 0;
354 count++;
356 stats->item(row++, 1)->setText(QString::number(count));
357
358 count = 0;
360 count++;
362 stats->item(row++, 1)->setText(QString::number(count));
363
364 count = 0;
366 count++;
368 stats->item(row++, 1)->setText(QString::number(count));
369
370 count = 0;
372 count++;
374 stats->item(row++, 1)->setText(QString::number(count));
375
376 count = 0;
377 action_iterate(act) {
379 count++;
382 stats->item(row++, 1)->setText(QString::number(count));
383
384 // Second column
385 row = 0;
386 count = 0;
388 count++;
390 stats->item(row++, 4)->setText(QString::number(count));
391
392 stats->item(row++, 4)->setText(QString::number(game.control.nation_count));
393
394 count = 0;
396 count++;
398 stats->item(row++, 4)->setText(QString::number(count));
399
400 count = 0;
402 count++;
404 stats->item(row++, 4)->setText(QString::number(count));
405
406 count = 0;
408 count++;
410 stats->item(row++, 4)->setText(QString::number(count));
411
412 stats->item(row++, 4)->setText(QString::number(game.control.num_disaster_types));
413 count = 0;
415 count++;
417 stats->item(row++, 4)->setText(QString::number(count));
418
419 // Third column
420 row = 0;
421
422 count = 0;
424 count++;
426 stats->item(row++, 7)->setText(QString::number(count));
427
428 count = 0;
429 base_count = 0;
430 road_count = 0;
432 count++;
433 if (is_extra_caused_by(pextra, EC_BASE)) {
434 base_count++;
435 }
436 if (is_extra_caused_by(pextra, EC_ROAD)) {
437 road_count++;
438 }
440 stats->item(row++, 7)->setText(QString::number(count));
441 stats->item(row++, 7)->setText(QString::number(base_count));
442 stats->item(row++, 7)->setText(QString::number(road_count));
443
444 count = 0;
446 count++;
448 stats->item(row++, 7)->setText(QString::number(count));
449
450 count = 0;
452 count++;
454 stats->item(row++, 7)->setText(QString::number(count));
455
456 count = 0;
458 stats->item(row++, 7)->setText(QString::number(count));
459
460 stats->resizeColumnsToContents();
461}
462
463/**********************************************************************/
467{
468 ui->open_effect_edit(QString::fromUtf8(R__("Always active")),
469 nullptr, EFMC_NONE);
470}
471
473
474/**********************************************************************/
477static void sanity_log_cb(const char *msg)
478{
479 sanitylog->add(msg);
480}
481
482/**********************************************************************/
486{
488
489 sanitylog = new conversion_log(QString::fromUtf8(R__("Sanity Check")));
490
492 compat_info.compat_mode = FALSE;
493 compat_info.log_cb = sanity_log_cb;
494
496 ui->display_msg(R__("Sanity check failed!"));
497 } else {
498 ui->display_msg(R__("Sanity check success"));
499 }
500}
501
502/**********************************************************************/
506{
507 ui->open_effect_edit(QString::fromUtf8(R__("All effects")),
508 nullptr, EFMC_ALL);
509}
510
511/**********************************************************************/
515{
516 if (desc_via_file->isChecked()) {
518
519 df_bytes = desc_file->text().toUtf8();
521 } else {
522 if (game.server.ruledit.description_file != nullptr) {
524 }
526 }
527}
528
529/**********************************************************************/
533{
534 desc_file->setEnabled(checked);
535}
#define achievements_re_active_iterate(_p)
#define achievements_re_active_iterate_end
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1559
#define action_enabler_list_re_iterate_end
Definition actions.h:196
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_iterate_end
Definition actions.h:214
#define action_iterate(_act_)
Definition actions.h:210
Base_type_id base_count(void)
Definition base.c:113
void add(const char *msg)
void flush_widgets()
struct rule_data data
Definition ruledit_qt.h:118
void display_msg(const char *msg)
void open_effect_edit(QString target, struct universal *uni, enum effect_filter_main_class efmc)
void edit_aae_effects()
Definition tab_misc.cpp:466
ruledit_gui * ui
Definition tab_misc.h:45
void desc_file_toggle(bool checked)
Definition tab_misc.cpp:532
QLineEdit * savedir
Definition tab_misc.h:48
void save_now()
Definition tab_misc.cpp:276
QLineEdit * name
Definition tab_misc.h:46
QLineEdit * desc_file
Definition tab_misc.h:52
QCheckBox * desc_via_file
Definition tab_misc.h:51
void edit_all_effects()
Definition tab_misc.cpp:505
void flush_widgets()
Definition tab_misc.cpp:514
void refresh_stats()
Definition tab_misc.cpp:337
QCheckBox * savedir_version
Definition tab_misc.h:49
void ruleset_loaded()
Definition tab_misc.cpp:251
QTableWidget * stats
Definition tab_misc.h:50
QLineEdit * version
Definition tab_misc.h:47
tab_misc(ruledit_gui *ui_in)
Definition tab_misc.cpp:57
void sanity_check()
Definition tab_misc.cpp:485
void refresh()
Definition tab_misc.cpp:266
char * incite_cost
Definition comments.c:76
#define counters_re_iterate_end
Definition counters.h:75
#define counters_re_iterate(pcount)
Definition counters.h:67
@ EFMC_ALL
Definition effect_edit.h:36
@ EFMC_NONE
Definition effect_edit.h:35
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_type_re_active_iterate_end
Definition extras.h:329
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
#define MAX_LEN_NAME
Definition fc_types.h:66
#define RQ_(String)
Definition fcintl.h:76
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
#define governments_re_active_iterate(_p)
Definition government.h:129
#define governments_re_active_iterate_end
Definition government.h:133
#define improvement_re_active_iterate_end
#define improvement_re_active_iterate(_p)
#define fc_strdup(str)
Definition mem.h:43
#define multipliers_re_active_iterate(_mul_)
Definition multipliers.h:71
#define multipliers_re_active_iterate_end
Definition multipliers.h:75
Road_type_id road_count(void)
Definition road.c:50
void rscompat_init_info(struct rscompat_info *info)
Definition rscompat.c:61
bool sanity_check_ruleset_data(struct rscompat_info *compat)
Definition rssanity.c:903
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1616
bool save_ruleset(const char *path, const char *name, struct rule_data *data)
Definition rulesave.c:3397
char * freeciv_storage_dir(void)
Definition shared.c:671
#define DIR_SEPARATOR
Definition shared.h:127
#define specialist_type_re_active_iterate_end
Definition specialist.h:88
#define specialist_type_re_active_iterate(_p)
Definition specialist.h:83
struct civ_game::@32::@36::@42 ruledit
char * description_file
Definition game.h:288
struct packet_ruleset_control control
Definition game.h:83
struct civ_game::@32::@36 server
Definition climisc.h:82
char version[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
#define styles_re_active_iterate_end
Definition style.h:60
#define styles_re_active_iterate(_p)
Definition style.h:56
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
static conversion_log * sanitylog
Definition tab_misc.cpp:472
static void sanity_log_cb(const char *msg)
Definition tab_misc.cpp:477
static bool effect_counter(struct effect *peff, void *data)
Definition tab_misc.cpp:327
#define advance_re_active_iterate(_p)
Definition tech.h:277
#define tech_class_re_active_iterate(_p)
Definition tech.h:203
#define advance_re_active_iterate_end
Definition tech.h:281
#define tech_class_re_active_iterate_end
Definition tech.h:207
#define terrain_re_active_iterate_end
Definition terrain.h:281
#define terrain_re_active_iterate(_p)
Definition terrain.h:277
#define goods_type_re_active_iterate_end
#define goods_type_re_active_iterate(_p)
#define unit_type_re_active_iterate(_p)
Definition unittype.h:874
#define unit_class_re_active_iterate_end
Definition unittype.h:931
#define unit_class_re_active_iterate(_p)
Definition unittype.h:927
#define unit_type_re_active_iterate_end
Definition unittype.h:878