Freeciv-3.3
Loading...
Searching...
No Matches
ruledit_qt.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// Qt
19#include <QApplication>
20#include <QCloseEvent>
21#include <QLabel>
22#include <QLineEdit>
23#include <QMainWindow>
24#include <QMessageBox>
25#include <QPushButton>
26#include <QStackedLayout>
27#include <QVBoxLayout>
28
29// utility
30#include "fcintl.h"
31#include "log.h"
32#include "registry.h"
33
34// common
35#include "game.h"
36#include "version.h"
37
38// server
39#include "ruleload.h"
40
41// ruledit
42#include "conversion_log.h"
43#include "effect_edit.h"
44#include "requirers_dlg.h"
45#include "req_edit.h"
46#include "req_vec_fix.h"
47#include "ruledit.h"
48#include "tab_achievement.h"
49#include "tab_building.h"
50#include "tab_counters.h"
51#include "tab_enablers.h"
52#include "tab_extras.h"
53#include "tab_good.h"
54#include "tab_gov.h"
55#include "tab_misc.h"
56#include "tab_multiplier.h"
57#include "tab_nation.h"
58#include "tab_tech.h"
59#include "tab_terrains.h"
60#include "tab_unit.h"
61
62#include "ruledit_qt.h"
63
67
68/**********************************************************************/
71int ruledit_qt_run(int argc, char **argv)
72{
74 QWidget *central;
75 int ret;
76
77 qapp = new QApplication(argc, argv);
78 central = new QWidget;
79 main_window = new ruledit_main(qapp, central);
80
81 gui = new ruledit_gui;
82 gui->setup(central);
83 main_window->setCentralWidget(central);
84 main_window->setVisible(true);
85
86 ret = qapp->exec();
87
88 delete gui;
89 delete qapp;
90
91 return ret;
92}
93
94/**********************************************************************/
97void ruledit_qt_display_requirers(const char *msg, void *data)
98{
100
102}
103
104/**********************************************************************/
108{
111 QWidget *edit_widget = new QWidget();
112 QPushButton *ruleset_accept;
113 QLabel *rs_label;
114 QLabel *version_label;
115 char verbuf[2048];
116 const char *rev_ver;
117 const char *mode;
118
119 data.nationlist = nullptr;
120 data.nationlist_saved = nullptr;
121
123
125
126#ifdef FC_QT5_MODE
127 mode = R__("built in Qt5 mode.");
128#elif defined(FC_QT6X_MODE)
129 mode = R__("built in Qt6x mode.");
130#else // FC_QT5_MODE
131 mode = R__("built in Qt6 mode.");
132#endif // FC_QT5_MODE
133
134 if (rev_ver == nullptr) {
135 fc_snprintf(verbuf, sizeof(verbuf), "%s%s\n%s", word_version(),
136 VERSION_STRING, mode);
137 } else {
138 fc_snprintf(verbuf, sizeof(verbuf), R__("%s%s\ncommit: %s\n%s"),
140 }
141
143
144 if (reargs.ruleset == nullptr) {
146 QWidget *preload_widget = new QWidget();
147
148 preload_layout->setSizeConstraint(QLayout::SetMaximumSize);
149 version_label = new QLabel(verbuf);
150 version_label->setAlignment(Qt::AlignHCenter);
151 version_label->setParent(central);
152 preload_layout->addWidget(version_label);
153 rs_label = new QLabel(QString::fromUtf8(R__("Give ruleset to use as starting point.")));
154 rs_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
155 preload_layout->addWidget(rs_label);
156 ruleset_select = new QLineEdit(central);
159 this, SLOT(rulesetdir_given()));
160 preload_layout->addWidget(ruleset_select);
161 ruleset_accept = new QPushButton(QString::fromUtf8(R__("Start editing")));
162 connect(ruleset_accept, SIGNAL(pressed()), this, SLOT(rulesetdir_given()));
163 preload_layout->addWidget(ruleset_accept);
164
165 preload_widget->setLayout(preload_layout);
166 main_layout->addWidget(preload_widget);
167 }
168
169 stack = new QTabWidget(central);
170
171 misc = new tab_misc(this);
172 stack->addTab(misc, QString::fromUtf8(R__("Misc")));
173 tech = new tab_tech(this);
174 stack->addTab(tech, QString::fromUtf8(R__("Tech")));
175 bldg = new tab_building(this);
176 stack->addTab(bldg, QString::fromUtf8(R__("Buildings")));
177 unit = new tab_unit(this);
178 stack->addTab(unit, QString::fromUtf8(R__("Units")));
179 ach = new tab_achievement(this);
180 stack->addTab(ach, QString::fromUtf8(R__("Achievements")));
181 good = new tab_good(this);
182 stack->addTab(good, QString::fromUtf8(R__("Goods")));
183 gov = new tab_gov(this);
184 stack->addTab(gov, QString::fromUtf8(R__("Governments")));
185 enablers = new tab_enabler(this);
186 stack->addTab(enablers, QString::fromUtf8(R__("Enablers")));
187 extras = new tab_extras(this);
188 stack->addTab(extras, QString::fromUtf8(R__("Extras")));
189 terrains = new tab_terrains(this);
190 stack->addTab(terrains, QString::fromUtf8(R__("Terrains")));
191 multipliers = new tab_multiplier(this);
192 stack->addTab(multipliers, QString::fromUtf8(R__("Multipliers")));
193 counter = new tab_counter(this);
194 stack->addTab(counter, QString::fromUtf8(R__("Counters")));
195 nation = new tab_nation(this);
196 stack->addTab(nation, QString::fromUtf8(R__("Nations")));
197
198 edit_layout->addWidget(stack);
199
200 edit_widget->setLayout(edit_layout);
201 main_layout->addWidget(edit_widget);
202
203 full_layout->addLayout(main_layout);
204
205 msg_dspl = new QLabel(QString::fromUtf8(R__("Welcome to freeciv-ruledit")));
206 msg_dspl->setParent(central);
207
208 msg_dspl->setAlignment(Qt::AlignHCenter);
209
210 full_layout->addWidget(msg_dspl);
211
212 central->setLayout(full_layout);
213
217
218 if (reargs.ruleset != nullptr) {
220 launch_now();
221 }
222}
223
224/**********************************************************************/
227static void conversion_log_cb(const char *msg)
228{
229 convlog->add(msg);
230}
231
232/**********************************************************************/
236{
238
239 rn_bytes = ruleset_select->text().toUtf8();
241
242 launch_now();
243}
244
245/**********************************************************************/
251{
252 convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format")));
253
254 if (load_rulesets(nullptr, nullptr, TRUE, conversion_log_cb, FALSE, TRUE, TRUE)) {
255 display_msg(R__("Ruleset loaded"));
256
257 // Make freeable copy
258 if (game.server.ruledit.nationlist != nullptr) {
260 } else {
261 data.nationlist = nullptr;
262 }
263
264 ach->refresh();
265 bldg->refresh();
267 nation->refresh();
268 tech->refresh();
269 unit->refresh();
270 good->refresh();
271 gov->refresh();
272 enablers->refresh();
273 extras->refresh();
275 terrains->refresh();
276 counter->refresh();
277 main_layout->setCurrentIndex(1);
278 } else {
279 display_msg(R__("Ruleset loading failed!"));
280 }
281}
282
283/**********************************************************************/
291
292/**********************************************************************/
295void ruledit_gui::display_msg(const char *msg)
296{
297 msg_dspl->setText(QString::fromUtf8(msg));
298}
299
300/**********************************************************************/
304{
306
307 requirers = new requirers_dlg(this);
308
309 requirers->clear(title);
310
311 return requirers;
312}
313
314/**********************************************************************/
318{
319 requirers->add(msg);
320
321 // Show dialog if not already visible
322 requirers->show();
323}
324
325/**********************************************************************/
333
334/**********************************************************************/
338{
340
342 if (old_edit->req_vector == preqs) {
343 // Already open
344 return;
345 }
347
348 redit = new req_edit(this, target, preqs);
349
350 redit->show();
351
352 connect(redit,
355
357}
358
359/**********************************************************************/
366
367/**********************************************************************/
371{
373
375 if (old_fixer->item() == item_info->item()) {
376 item_info->close();
377
378 // Already open
379 return;
380 }
382
383 fixer = new req_vec_fix(this, item_info);
384
385 fixer->refresh();
386 fixer->show();
387
388 connect(fixer,
391
393}
394
395/**********************************************************************/
402
403/**********************************************************************/
407 enum effect_filter_main_class efmc)
408{
410
412 struct universal *old = old_edit->filter_get();
413
414 if (uni != nullptr) {
415 if (are_universals_equal(old, uni)) {
416 // Already open
417 return;
418 }
419 } else if (old->kind == VUT_NONE && old_edit->efmc == efmc) {
420 // Already open
421 return;
422 }
424
425 e_edit = new effect_edit(this, target, uni, efmc);
426
427 e_edit->show();
428
430}
431
432/**********************************************************************/
439
440/**********************************************************************/
449
450/**********************************************************************/
454{
455 QPixmap *pm = new QPixmap;
456 const char *full_icon_path = fileinfoname(get_data_dirs(), "freeciv-ruledit.png");
457 const QString title = QString::fromUtf8(R__("Freeciv Ruleset Editor"));
460 int width;
461 int height;
462
463 pm->load(fip);
464 qapp_in->setWindowIcon(QIcon(*pm));
465
466 qapp = qapp_in;
468
470
471 // Adjust Window size
472 old_size = size();
473 width = old_size.width();
474 height = old_size.height();
475
478
479 resize(width, height);
480}
481
482/**********************************************************************/
486{
487 QMessageBox ask(central);
488 int ret;
489
490 ask.setText(R__("Are you sure you want to quit?"));
491 ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
492 ask.setDefaultButton(QMessageBox::Cancel);
493 ask.setIcon(QMessageBox::Warning);
494 ask.setWindowTitle(R__("Quit?"));
495 ret = ask.exec();
496
497 switch (ret) {
498 case QMessageBox::Cancel:
499 return;
500 break;
501 case QMessageBox::Ok:
502 qapp->quit();
503 break;
504 }
505}
506
507/**********************************************************************/
511{
512 // Handle quit via confirmation dialog.
514
515 // Do not handle quit here, but let user to answer to confirmation dialog.
516 cevent->ignore();
517}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
void add(const char *msg)
virtual void close()=0
virtual const void * item()=0
tab_nation * nation
Definition ruledit_qt.h:148
tab_achievement * ach
Definition ruledit_qt.h:136
void req_vec_may_have_changed(const requirement_vector *vec)
void open_req_vec_fix(req_vec_fix_item *item_info)
tab_good * good
Definition ruledit_qt.h:142
tab_enabler * enablers
Definition ruledit_qt.h:144
void unregister_effect_edit(class effect_edit *e_edit)
void flush_widgets()
tab_multiplier * multipliers
Definition ruledit_qt.h:146
QStackedLayout * main_layout
Definition ruledit_qt.h:134
struct rule_data data
Definition ruledit_qt.h:118
tab_misc * misc
Definition ruledit_qt.h:139
struct effect_edit_list * effect_edits
Definition ruledit_qt.h:152
tab_extras * extras
Definition ruledit_qt.h:145
void incoming_req_vec_change(const requirement_vector *vec)
tab_terrains * terrains
Definition ruledit_qt.h:147
void display_msg(const char *msg)
void refresh_effect_edits()
void setup(QWidget *central_in)
void open_req_edit(QString target, struct requirement_vector *preqs)
tab_gov * gov
Definition ruledit_qt.h:143
void unregister_req_vec_fix(req_vec_fix *fixer)
tab_building * bldg
Definition ruledit_qt.h:137
requirers_dlg * create_requirers(const char *title)
tab_tech * tech
Definition ruledit_qt.h:140
void launch_now()
struct req_edit_list * req_edits
Definition ruledit_qt.h:150
QTabWidget * stack
Definition ruledit_qt.h:131
struct req_vec_fix_list * req_vec_fixers
Definition ruledit_qt.h:151
void show_required(requirers_dlg *requirers, const char *msg)
QLabel * msg_dspl
Definition ruledit_qt.h:130
QWidget * central
Definition ruledit_qt.h:133
void rulesetdir_given()
void open_effect_edit(QString target, struct universal *uni, enum effect_filter_main_class efmc)
QLineEdit * ruleset_select
Definition ruledit_qt.h:132
void unregister_req_edit(class req_edit *redit)
QWidget * central
Definition ruledit_qt.h:63
void popup_quit_dialog()
ruledit_main(QApplication *qapp_in, QWidget *central_in)
void closeEvent(QCloseEvent *cevent)
QApplication * qapp
Definition ruledit_qt.h:62
void refresh()
void refresh()
Definition tab_good.cpp:114
void refresh()
Definition tab_gov.cpp:116
void flush_widgets()
Definition tab_misc.cpp:514
void ruleset_loaded()
Definition tab_misc.cpp:251
void flush_widgets()
void refresh()
void refresh()
Definition tab_tech.cpp:139
char * incite_cost
Definition comments.c:76
effect_filter_main_class
Definition effect_edit.h:34
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
#define GAME_DEFAULT_RULESETDIR
Definition game.h:681
const char * title
Definition repodlgs.c:1314
#define fc_strdup(str)
Definition mem.h:43
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
struct ruledit_arguments reargs
Definition ruledit.cpp:56
void ruledit_qt_display_requirers(const char *msg, void *data)
static QApplication * qapp
int ruledit_qt_run(int argc, char **argv)
static void conversion_log_cb(const char *msg)
static ruledit_gui * gui
static conversion_log * convlog
#define RULEDIT_WINHEIGHT
Definition ruledit_qt.h:51
#define effect_edit_list_iterate_end
Definition ruledit_qt.h:85
#define req_edit_list_iterate(reqeditlist, preqedit)
Definition ruledit_qt.h:74
#define RULEDIT_WINWIDTH
Definition ruledit_qt.h:50
#define req_vec_fix_list_iterate(reqvecfixlist, preqvecfix)
Definition ruledit_qt.h:92
#define effect_edit_list_iterate(effecteditlist, peffectedit)
Definition ruledit_qt.h:83
#define req_edit_list_iterate_end
Definition ruledit_qt.h:76
#define req_vec_fix_list_iterate_end
Definition ruledit_qt.h:94
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9188
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
char * nationlist
Definition game.h:289
struct civ_game::@32::@36::@42 ruledit
char rulesetdir[MAX_LEN_NAME]
Definition game.h:246
struct civ_game::@32::@36 server
char * nationlist
Definition rulesave.h:22
char * nationlist_saved
Definition rulesave.h:23
Definition unit.h:140
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * fc_git_revision(void)
Definition version.c:75
const char * word_version(void)
Definition version.c:62