Freeciv-3.2
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 "ruleset.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
121
123
125
126#ifndef FC_QT5_MODE
127 mode = R__("built in Qt6 mode.");
128#else // FC_QT5_MODE
129 mode = R__("built in Qt5 mode.");
130#endif // FC_QT5_MODE
131
132 if (rev_ver == NULL) {
133 fc_snprintf(verbuf, sizeof(verbuf), "%s%s\n%s", word_version(),
134 VERSION_STRING, mode);
135 } else {
136 fc_snprintf(verbuf, sizeof(verbuf), R__("%s%s\ncommit: %s\n%s"),
138 }
139
141
142 if (reargs.ruleset == nullptr) {
144 QWidget *preload_widget = new QWidget();
145
146 preload_layout->setSizeConstraint(QLayout::SetMaximumSize);
147 version_label = new QLabel(verbuf);
148 version_label->setAlignment(Qt::AlignHCenter);
149 version_label->setParent(central);
150 preload_layout->addWidget(version_label);
151 rs_label = new QLabel(QString::fromUtf8(R__("Give ruleset to use as starting point.")));
152 rs_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
153 preload_layout->addWidget(rs_label);
154 ruleset_select = new QLineEdit(central);
157 this, SLOT(rulesetdir_given()));
158 preload_layout->addWidget(ruleset_select);
159 ruleset_accept = new QPushButton(QString::fromUtf8(R__("Start editing")));
160 connect(ruleset_accept, SIGNAL(pressed()), this, SLOT(rulesetdir_given()));
161 preload_layout->addWidget(ruleset_accept);
162
163 preload_widget->setLayout(preload_layout);
164 main_layout->addWidget(preload_widget);
165 }
166
167 stack = new QTabWidget(central);
168
169 misc = new tab_misc(this);
170 stack->addTab(misc, QString::fromUtf8(R__("Misc")));
171 tech = new tab_tech(this);
172 stack->addTab(tech, QString::fromUtf8(R__("Tech")));
173 bldg = new tab_building(this);
174 stack->addTab(bldg, QString::fromUtf8(R__("Buildings")));
175 unit = new tab_unit(this);
176 stack->addTab(unit, QString::fromUtf8(R__("Units")));
177 ach = new tab_achievement(this);
178 stack->addTab(ach, QString::fromUtf8(R__("Achievements")));
179 good = new tab_good(this);
180 stack->addTab(good, QString::fromUtf8(R__("Goods")));
181 gov = new tab_gov(this);
182 stack->addTab(gov, QString::fromUtf8(R__("Governments")));
183 enablers = new tab_enabler(this);
184 stack->addTab(enablers, QString::fromUtf8(R__("Enablers")));
185 extras = new tab_extras(this);
186 stack->addTab(extras, QString::fromUtf8(R__("Extras")));
187 terrains = new tab_terrains(this);
188 stack->addTab(terrains, QString::fromUtf8(R__("Terrains")));
189 multipliers = new tab_multiplier(this);
190 stack->addTab(multipliers, QString::fromUtf8(R__("Multipliers")));
191 counter = new tab_counter(this);
192 stack->addTab(counter, QString::fromUtf8(R__("Counters")));
193 nation = new tab_nation(this);
194 stack->addTab(nation, QString::fromUtf8(R__("Nations")));
195
196 edit_layout->addWidget(stack);
197
198 edit_widget->setLayout(edit_layout);
199 main_layout->addWidget(edit_widget);
200
201 full_layout->addLayout(main_layout);
202
203 msg_dspl = new QLabel(QString::fromUtf8(R__("Welcome to freeciv-ruledit")));
204 msg_dspl->setParent(central);
205
206 msg_dspl->setAlignment(Qt::AlignHCenter);
207
208 full_layout->addWidget(msg_dspl);
209
210 central->setLayout(full_layout);
211
215
216 if (reargs.ruleset != nullptr) {
218 launch_now();
219 }
220}
221
222/**********************************************************************/
225static void conversion_log_cb(const char *msg)
226{
227 convlog->add(msg);
228}
229
230/**********************************************************************/
234{
236
237 rn_bytes = ruleset_select->text().toUtf8();
239
240 launch_now();
241}
242
243/**********************************************************************/
249{
250 convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format")));
251
253 display_msg(R__("Ruleset loaded"));
254
255 // Make freeable copy
258 } else {
260 }
261
262 ach->refresh();
263 bldg->refresh();
265 nation->refresh();
266 tech->refresh();
267 unit->refresh();
268 good->refresh();
269 gov->refresh();
270 enablers->refresh();
271 extras->refresh();
273 terrains->refresh();
274 counter->refresh();
275 main_layout->setCurrentIndex(1);
276 } else {
277 display_msg(R__("Ruleset loading failed!"));
278 }
279}
280
281/**********************************************************************/
289
290/**********************************************************************/
293void ruledit_gui::display_msg(const char *msg)
294{
295 msg_dspl->setText(QString::fromUtf8(msg));
296}
297
298/**********************************************************************/
302{
304
305 requirers = new requirers_dlg(this);
306
307 requirers->clear(title);
308
309 return requirers;
310}
311
312/**********************************************************************/
316{
317 requirers->add(msg);
318
319 // Show dialog if not already visible
320 requirers->show();
321}
322
323/**********************************************************************/
331
332/**********************************************************************/
336{
338
340 if (old_edit->req_vector == preqs) {
341 // Already open
342 return;
343 }
345
346 redit = new req_edit(this, target, preqs);
347
348 redit->show();
349
350 connect(redit,
353
355}
356
357/**********************************************************************/
364
365/**********************************************************************/
369{
371
373 if (old_fixer->item() == item_info->item()) {
374 item_info->close();
375
376 // Already open
377 return;
378 }
380
381 fixer = new req_vec_fix(this, item_info);
382
383 fixer->refresh();
384 fixer->show();
385
386 connect(fixer,
389
391}
392
393/**********************************************************************/
400
401/**********************************************************************/
405 enum effect_filter_main_class efmc)
406{
408
410 struct universal *old = old_edit->filter_get();
411
412 if (uni != nullptr) {
413 if (are_universals_equal(old, uni)) {
414 // Already open
415 return;
416 }
417 } else if (old->kind == VUT_NONE && old_edit->efmc == efmc) {
418 // Already open
419 return;
420 }
422
423 e_edit = new effect_edit(this, target, uni, efmc);
424
425 e_edit->show();
426
428}
429
430/**********************************************************************/
437
438/**********************************************************************/
447
448/**********************************************************************/
452{
453 QPixmap *pm = new QPixmap;
454 const char *full_icon_path = fileinfoname(get_data_dirs(), "freeciv-ruledit.png");
455 const QString title = QString::fromUtf8(R__("Freeciv Ruleset Editor"));
458 int width;
459 int height;
460
461 pm->load(fip);
462 qapp_in->setWindowIcon(QIcon(*pm));
463
464 qapp = qapp_in;
466
468
469 // Adjust Window size
470 old_size = size();
471 width = old_size.width();
472 height = old_size.height();
473
476
477 resize(width, height);
478}
479
480/**********************************************************************/
484{
485 QMessageBox ask(central);
486 int ret;
487
488 ask.setText(R__("Are you sure you want to quit?"));
489 ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
490 ask.setDefaultButton(QMessageBox::Cancel);
491 ask.setIcon(QMessageBox::Warning);
492 ask.setWindowTitle(R__("Quit?"));
493 ret = ask.exec();
494
495 switch (ret) {
496 case QMessageBox::Cancel:
497 return;
498 break;
499 case QMessageBox::Ok:
500 qapp->quit();
501 break;
502 }
503}
504
505/**********************************************************************/
509{
510 // Handle quit via confirmation dialog.
512
513 // Do not handle quit here, but let user to answer to confirmation dialog.
514 cevent->ignore();
515}
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:75
effect_filter_main_class
Definition effect_edit.h:34
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
#define GAME_DEFAULT_RULESETDIR
Definition game.h:676
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 ruleset.c:9358
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1101
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
char * nationlist
Definition game.h:285
char rulesetdir[MAX_LEN_NAME]
Definition game.h:242
struct civ_game::@31::@35::@40 ruledit
struct civ_game::@31::@35 server
char * nationlist
Definition rulesave.h:22
char * nationlist_saved
Definition rulesave.h:23
Definition unit.h:138
enum universals_n kind
Definition fc_types.h:902
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#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