Freeciv-3.3
Loading...
Searching...
No Matches
effect_edit.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 <QGridLayout>
20#include <QLabel>
21#include <QLineEdit>
22#include <QMenu>
23#include <QPushButton>
24#include <QSpinBox>
25
26// utility
27#include "fcintl.h"
28
29// common
30#include "effects.h"
31#include "multipliers.h"
32
33// ruledit
34#include "ruledit.h"
35#include "ruledit_qt.h"
36#include "validity.h"
37
38#include "effect_edit.h"
39
40#define NO_MULTIPLIER_NAME "No Multiplier"
41
42/**********************************************************************/
46 struct universal *filter_in,
47 enum effect_filter_main_class efmc_in) : QDialog()
48{
49 QVBoxLayout *main_layout = new QVBoxLayout(this);
52 QPushButton *close_button;
53 QPushButton *button;
54 QMenu *menu;
55 QLabel *lbl;
56 enum effect_type eff;
57 int row;
58
59 ui = ui_in;
60 selected = nullptr;
61 if (filter_in == nullptr) {
64 } else {
67 }
68 name = target;
69
70 efmc = efmc_in;
71
72 list_widget = new QListWidget(this);
74
76 main_layout->addWidget(list_widget);
77
78 lbl = new QLabel(R__("Type:"));
79 active_layout->addWidget(lbl, 0);
80 edit_type_button = new QToolButton(this);
81 menu = new QMenu();
82 edit_type_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
83 edit_type_button->setPopupMode(QToolButton::MenuButtonPopup);
84 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(effect_type_menu(QAction *)));
85 edit_type_button->setMenu(menu);
86 for (eff = (enum effect_type)0; eff < EFT_COUNT;
87 eff = (enum effect_type)(eff + 1)) {
88 menu->addAction(effect_type_name(eff));
89 }
90 active_layout->addWidget(edit_type_button, 1);
91
92 lbl = new QLabel(R__("Value:"));
93 active_layout->addWidget(lbl, 2);
94 value_box = new QSpinBox(this);
95 value_box->setRange(-1000, 1000);
96 active_layout->addWidget(value_box, 3);
97 connect(value_box, SIGNAL(valueChanged(int)), this, SLOT(set_value(int)));
98
99 main_layout->addLayout(active_layout);
100 row = 0;
101
102 mp_button = new QToolButton();
103 mp_button->setParent(this);
104 mp_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
105 mp_button->setPopupMode(QToolButton::MenuButtonPopup);
106 menu = new QMenu();
107 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(multiplier_menu(QAction *)));
108 mp_button->setMenu(menu);
109 menu->addAction(NO_MULTIPLIER_NAME); // FIXME: Can't translate, as we compare to "rule_name"
111 menu->addAction(multiplier_rule_name(pmul));
113 effect_edit_layout->addWidget(mp_button, row++, 0, 1, 2);
114
115 lbl = new QLabel(QString::fromUtf8(R__("Comment")));
116 effect_edit_layout->addWidget(lbl, row, 0);
117 comment = new QLineEdit(this);
118 connect(comment, SIGNAL(returnPressed()), this, SLOT(comment_given()));
119 effect_edit_layout->addWidget(comment, row++, 1);
120
121 button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
122 connect(button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
123 effect_edit_layout->addWidget(button, row++, 0, 1, 2);
124
125 button = new QPushButton(QString::fromUtf8(R__("Add Effect")), this);
126 connect(button, SIGNAL(pressed()), this, SLOT(add_now()));
127 effect_edit_layout->addWidget(button, row++, 0, 1, 2);
128
129 button = new QPushButton(QString::fromUtf8(R__("Delete Effect")), this);
130 connect(button, SIGNAL(pressed()), this, SLOT(delete_now()));
131 effect_edit_layout->addWidget(button, row++, 0, 1, 2);
132
133 close_button = new QPushButton(QString::fromUtf8(R__("Close")), this);
134 connect(close_button, SIGNAL(pressed()), this, SLOT(close_now()));
135 effect_edit_layout->addWidget(close_button, row++, 0, 1, 2);
136
137 refresh();
138
139 main_layout->addLayout(effect_edit_layout);
140
141 setLayout(main_layout);
142 setWindowTitle(target);
143}
144
145/**********************************************************************/
152
153/**********************************************************************/
156static bool effect_list_fill_cb(struct effect *peffect, void *data)
157{
158 struct effect_list_fill_data *cbdata = (struct effect_list_fill_data *)data;
159
160 if (cbdata->filter->kind == VUT_NONE) {
161 if (cbdata->efmc == EFMC_NONE) {
162 // Look for empty req lists.
163 if (requirement_vector_size(&peffect->reqs) == 0) {
165 }
166 } else {
167 fc_assert(cbdata->efmc == EFMC_ALL);
168 cbdata->edit->add_effect_to_list(peffect, cbdata);
169 }
171 cbdata->filter)) {
172 cbdata->edit->add_effect_to_list(peffect, cbdata);
173 }
174
175 return true;
176}
177
178/**********************************************************************/
182{
184
185 list_widget->clear();
187 cb_data.filter = &filter;
188 cb_data.efmc = efmc;
189 cb_data.edit = this;
190 cb_data.num = 0;
191
193
194 fill_active();
195}
196
197/**********************************************************************/
201 struct effect_list_fill_data *fill_data)
202{
203 char buf[512];
205
206 fc_snprintf(buf, sizeof(buf), R__("Effect #%d: %s"),
207 fill_data->num + 1, effect_type_name(peffect->type));
208
209 item = new QListWidgetItem(QString::fromUtf8(buf));
210 list_widget->insertItem(fill_data->num++, item);
212 if (selected == peffect) {
213 item->setSelected(true);
214 }
215}
216
217/**********************************************************************/
221{
222 return &filter;
223}
224
225/**********************************************************************/
229{
231 done(0);
232}
233
234/**********************************************************************/
238{
239 int i = 0;
240
243
244 if (item != nullptr && item->isSelected()) {
246 selected_nbr = i;
247 fill_active();
248 return;
249 }
251}
252
253/**********************************************************************/
257{
258 if (selected != nullptr) {
260 value_box->setValue(selected->value);
261 if (selected->multiplier != nullptr) {
263 } else {
265 }
266
267 if (selected->rulesave.comment == nullptr) {
268 comment->setText("");
269 } else {
270 comment->setText(selected->rulesave.comment);
271 }
272 } else {
274 }
275}
276
277/**********************************************************************/
281{
282 QByteArray en_bytes = action->text().toUtf8();
283 enum effect_type type = effect_type_by_name(en_bytes.data(),
285
286 if (selected != nullptr) {
287 selected->type = type;
288 }
289
291}
292
293/**********************************************************************/
297{
298 if (selected != nullptr) {
299 selected->value = value;
300 }
301
303}
304
305/**********************************************************************/
309{
310 if (selected != nullptr) {
311 char buf[128];
313
314 en_bytes = name.toUtf8();
315 fc_snprintf(buf, sizeof(buf), R__("%s effect #%d"), en_bytes.data(),
317
318 ui->open_req_edit(QString::fromUtf8(buf), &selected->reqs);
319 }
320}
321
322/**********************************************************************/
329
330/**********************************************************************/
334{
335 struct effect *peffect = effect_new((enum effect_type)0, 0, nullptr);
336
337 if (filter.kind != VUT_NONE) {
338 struct requirement req;
339
341 nullptr, false, true, false,
344 }
345
346 refresh();
347}
348
349/**********************************************************************/
353{
354 if (selected != nullptr) {
356
357 selected = nullptr;
358
359 refresh();
360 }
361}
362
363/**********************************************************************/
367{
368 QByteArray an_bytes = action->text().toUtf8();
369
370 if (selected == nullptr) {
371 return;
372 }
373
375 selected->multiplier = nullptr;
376 } else {
378 }
379
380 refresh();
381}
382
383/**********************************************************************/
387{
388 if (selected != nullptr) {
389 if (selected->rulesave.comment != nullptr) {
391 }
392
393 if (!comment->text().isEmpty()) {
394 selected->rulesave.comment = fc_strdup(comment->text().toUtf8());
395 } else {
396 selected->rulesave.comment = nullptr;
397 }
398
399 fill_active();
400 }
401}
struct effect_list * effects
Definition effect_edit.h:70
void multiplier_menu(QAction *action)
QToolButton * edit_type_button
Definition effect_edit.h:75
QString name
Definition effect_edit.h:67
void add_effect_to_list(struct effect *peffect, struct effect_list_fill_data *fill_data)
void fill_active()
enum effect_filter_main_class efmc
Definition effect_edit.h:62
void set_value(int value)
QToolButton * mp_button
Definition effect_edit.h:78
void delete_now()
void comment_given()
void closeEvent(QCloseEvent *event)
struct universal filter
Definition effect_edit.h:69
QListWidget * list_widget
Definition effect_edit.h:68
struct universal * filter_get()
effect_edit(ruledit_gui *ui_in, QString target, struct universal *filter_in, enum effect_filter_main_class efmc_in)
QSpinBox * value_box
Definition effect_edit.h:76
ruledit_gui * ui
Definition effect_edit.h:65
void effect_type_menu(QAction *action)
QLineEdit * comment
Definition effect_edit.h:79
struct effect * selected
Definition effect_edit.h:72
void select_effect()
void unregister_effect_edit(class effect_edit *e_edit)
void refresh_effect_edits()
void open_req_edit(QString target, struct requirement_vector *preqs)
char * incite_cost
Definition comments.c:76
static bool effect_list_fill_cb(struct effect *peffect, void *data)
#define NO_MULTIPLIER_NAME
effect_filter_main_class
Definition effect_edit.h:34
@ EFMC_ALL
Definition effect_edit.h:36
@ EFMC_NORMAL
Definition effect_edit.h:34
@ EFMC_NONE
Definition effect_edit.h:35
void effect_remove(struct effect *peffect)
Definition effects.c:230
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1321
struct effect * effect_new(enum effect_type type, int value, struct multiplier *pmul)
Definition effects.c:186
void effect_req_append(struct effect *peffect, struct requirement req)
Definition effects.c:266
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
enum event_type event
Definition events.c:81
#define R__(String)
Definition fcintl.h:75
GType type
Definition repodlgs.c:1313
#define fc_assert(condition)
Definition log.h:177
#define fc_strdup(str)
Definition mem.h:43
const char * multiplier_rule_name(const struct multiplier *pmul)
struct multiplier * multiplier_by_rule_name(const char *name)
#define multipliers_re_active_iterate(_mul_)
Definition multipliers.h:71
#define multipliers_re_active_iterate_end
Definition multipliers.h:75
struct requirement req_from_str(const char *type, const char *range, bool survives, bool present, bool quiet, const char *value)
const char * universal_rule_name(const struct universal *psource)
const char * universal_type_rule_name(const struct universal *psource)
bool universal_is_mentioned_by_requirements(const struct requirement_vector *reqs, const struct universal *psource)
class effect_edit * edit
Definition effect_edit.h:43
int value
Definition effects.h:49
char * comment
Definition effects.h:62
struct multiplier * multiplier
Definition effects.h:44
struct effect::@24 rulesave
struct requirement_vector reqs
Definition effects.h:53
enum effect_type type
Definition effects.h:41
Definition climisc.h:82
struct universal item
Definition climisc.h:83
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186