Freeciv-3.2
Loading...
Searching...
No Matches
tab_extras.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 <QCheckBox>
20#include <QGridLayout>
21#include <QLineEdit>
22#include <QListWidget>
23#include <QMenu>
24#include <QPushButton>
25#include <QToolButton>
26
27// utility
28#include "fcintl.h"
29#include "log.h"
30
31// common
32#include "game.h"
33#include "extras.h"
34
35// ruledit
36#include "edit_extra.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_extras.h"
42
43/**********************************************************************/
47{
48 QVBoxLayout *main_layout = new QVBoxLayout(this);
50 QLabel *label;
51 QPushButton *effects_button;
52 QPushButton *add_button;
53 QPushButton *delete_button;
54 QPushButton *reqs_button;
55 QPushButton *edit_button;
56 int row = 0;
57
58 ui = ui_in;
59 selected = 0;
60
61 extra_list = new QListWidget(this);
62
64 main_layout->addWidget(extra_list);
65
66 extra_layout->setSizeConstraint(QLayout::SetMaximumSize);
67
68 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
69 label->setParent(this);
70 rname = new QLineEdit(this);
71 rname->setText(R__("None"));
72 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
73 extra_layout->addWidget(label, row, 0);
74 extra_layout->addWidget(rname, row++, 2);
75
76 label = new QLabel(QString::fromUtf8(R__("Name")));
77 label->setParent(this);
78 same_name = new QCheckBox();
79 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
80 name = new QLineEdit(this);
81 name->setText(R__("None"));
82 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
83 extra_layout->addWidget(label, row, 0);
84 extra_layout->addWidget(same_name, row, 1);
85 extra_layout->addWidget(name, row++, 2);
86
87 edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this);
88 connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now()));
89 extra_layout->addWidget(edit_button, row++, 2);
90
91 reqs_button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
92 connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
93 extra_layout->addWidget(reqs_button, row++, 2);
94
95 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
96 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
97 extra_layout->addWidget(effects_button, row++, 2);
98
99 add_button = new QPushButton(QString::fromUtf8(R__("Add Extra")), this);
100 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
101 extra_layout->addWidget(add_button, row, 0);
103
104 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Extra")), this);
105 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
106 extra_layout->addWidget(delete_button, row++, 2);
107 show_experimental(delete_button);
108
109 refresh();
110 update_extra_info(nullptr);
111
112 main_layout->addLayout(extra_layout);
113
114 setLayout(main_layout);
115}
116
117/**********************************************************************/
121{
122 extra_list->clear();
123
126 = new QListWidgetItem(QString::fromUtf8(extra_rule_name(pextra)));
127
128 extra_list->insertItem(extra_index(pextra), item);
130}
131
132/**********************************************************************/
136{
137 selected = pextra;
138
139 if (selected != nullptr) {
140 QString dispn = QString::fromUtf8(untranslated_name(&(pextra->name)));
141 QString rulen = QString::fromUtf8(extra_rule_name(pextra));
142
143 name->setText(dispn);
144 rname->setText(rulen);
145 if (dispn == rulen) {
146 name->setEnabled(false);
147 same_name->setChecked(true);
148 } else {
149 same_name->setChecked(false);
150 name->setEnabled(true);
151 }
152 } else {
153 name->setText(R__("None"));
154 rname->setText(R__("None"));
155 same_name->setChecked(true);
156 name->setEnabled(false);
157 }
158}
159
160/**********************************************************************/
164{
166
167 if (!select_list.isEmpty()) {
169
170 en_bytes = select_list.at(0)->text().toUtf8();
172 }
173}
174
175/**********************************************************************/
179{
180 if (selected != nullptr) {
183
184 extra_type_iterate(pextra) {
185 if (pextra != selected && !pextra->ruledit_disabled) {
186 rname_bytes = rname->text().toUtf8();
187 if (!strcmp(extra_rule_name(pextra), rname_bytes.data())) {
188 ui->display_msg(R__("An extra with that rule name already exists!"));
189 return;
190 }
191 }
193
194 if (same_name->isChecked()) {
195 name->setText(rname->text());
196 }
197
198 name_bytes = name->text().toUtf8();
199 rname_bytes = rname->text().toUtf8();
200 names_set(&(selected->name), 0,
201 name_bytes.data(),
202 rname_bytes.data());
203 refresh();
204 }
205}
206
207/**********************************************************************/
211{
212 if (selected != nullptr) {
214
217 return;
218 }
219
221
222 if (selected->ruledit_dlg != nullptr) {
223 ((edit_extra *)selected->ruledit_dlg)->done(0);
224 }
225
226 refresh();
227 update_extra_info(nullptr);
228 }
229}
230
231/**********************************************************************/
235{
236 if (extra_type_by_rule_name("New Extra") != nullptr) {
237 return false;
238 }
239
240 name_set(&(pextra->name), 0, "New Extra");
241 BV_CLR_ALL(pextra->flags);
242 if (pextra->helptext != nullptr) {
243 strvec_clear(pextra->helptext);
244 }
245
246 return true;
247}
248
249/**********************************************************************/
253{
254 struct extra_type *new_extra;
255
256 // Try to reuse freed extra slot
257 extra_type_iterate(pextra) {
258 if (pextra->ruledit_disabled) {
259 if (initialize_new_extra(pextra)) {
260 pextra->ruledit_disabled = false;
261 update_extra_info(pextra);
262 refresh();
263 }
264 return;
265 }
267
268 // Try to add completely new extra
270 return;
271 }
272
273 // num_extra_types must be big enough to hold new extra or
274 // extra_by_number() fails.
279
280 refresh();
281 } else {
282 game.control.num_extra_types--; // Restore
283 }
284}
285
286/**********************************************************************/
290{
291 name->setEnabled(!checked);
292 if (checked) {
293 name->setText(rname->text());
294 }
295}
296
297/**********************************************************************/
301{
302 if (selected != nullptr) {
303 ui->open_req_edit(QString::fromUtf8(extra_rule_name(selected)),
304 &selected->reqs);
305 }
306}
307
308/**********************************************************************/
312{
313 if (selected != nullptr) {
314 struct universal uni;
315
316 uni.value.extra = selected;
317 uni.kind = VUT_EXTRA;
318
319 ui->open_effect_edit(QString::fromUtf8(extra_rule_name(selected)),
320 &uni, EFMC_NORMAL);
321 }
322}
323
324/**********************************************************************/
328{
329 if (selected != nullptr) {
330 if (selected->ruledit_dlg == nullptr) {
332
333 edit->show();
335 } else {
336 ((edit_extra *)selected->ruledit_dlg)->raise();
337 }
338 }
339}
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
void display_msg(const char *msg)
void open_req_edit(QString target, struct requirement_vector *preqs)
requirers_dlg * create_requirers(const char *title)
void open_effect_edit(QString target, struct universal *uni, enum effect_filter_main_class efmc)
void same_name_toggle(bool checked)
void add_now()
void update_extra_info(struct extra_type *pextra)
QListWidget * extra_list
Definition tab_extras.h:45
QCheckBox * same_name
Definition tab_extras.h:46
void name_given()
tab_extras(ruledit_gui *ui_in)
QLineEdit * name
Definition tab_extras.h:43
void edit_now()
QLineEdit * rname
Definition tab_extras.h:44
void refresh()
void delete_now()
struct extra_type * selected
Definition tab_extras.h:48
void edit_effects()
ruledit_gui * ui
Definition tab_extras.h:39
void edit_reqs()
bool initialize_new_extra(struct extra_type *pextra)
void select_extra()
char * incite_cost
Definition comments.c:75
@ EFMC_NORMAL
Definition effect_edit.h:34
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:212
struct extra_type * extra_by_number(int id)
Definition extras.c:183
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define extra_index(_e_)
Definition extras.h:183
#define extra_type_re_active_iterate_end
Definition extras.h:329
#define extra_type_re_active_iterate(_p)
Definition extras.h:325
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
#define edit(pedit)
Definition widget_edit.h:34
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * untranslated_name(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:237
void ruledit_qt_display_requirers(const char *msg, void *data)
void strvec_clear(struct strvec *psv)
struct packet_ruleset_control control
Definition game.h:83
struct strvec * helptext
Definition extras.h:149
bv_extra_flags flags
Definition extras.h:132
bool ruledit_disabled
Definition extras.h:91
void * ruledit_dlg
Definition extras.h:92
struct requirement_vector reqs
Definition extras.h:106
struct name_translation name
Definition extras.h:90
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
struct extra_type * extra
Definition fc_types.h:722
bool is_extra_needed(struct extra_type *pextra, requirers_cb cb, void *data)
Definition validity.c:301