Freeciv-3.3: /fast/freeciv/nightly/main/tools/ruledit/edit_extra.cpp Source File

Freeciv-3.3

Loading...
Searching...
No Matches
edit_extra.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2023 The Freeciv Team
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 <QToolButton>
23
24// common
25#include "extras.h"
26#include "game.h"
27
28// ruledit
29#include "ruledit.h"
30#include "ruledit_qt.h"
31
32#include "edit_extra.h"
33
34
35#define FLAGROWS 15
36
37/**********************************************************************/
40edit_extra::edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
41 : QDialog()
42{
43 QHBoxLayout *main_layout = new QHBoxLayout(this);
44 QGridLayout *extra_layout = new QGridLayout();
45 QLabel *label;
46 int row = 0;
47 int rowcount;
48 int column;
49
50 ui = ui_in;
51 extra = extra_in;
52
53 natives_layout = new QGridLayout();
54 flag_layout = new QGridLayout();
55
56 setWindowTitle(QString::fromUtf8(extra_rule_name(extra)));
57
58 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
59 label->setParent(this);
60
61 gfx_tag = new QLineEdit(this);
62 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
63
64 extra_layout->addWidget(label, row, 0);
65 extra_layout->addWidget(gfx_tag, row++, 1);
66
67 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
68 label->setParent(this);
69
70 gfx_tag_alt = new QLineEdit(this);
71 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
72
73 extra_layout->addWidget(label, row, 0);
74 extra_layout->addWidget(gfx_tag_alt, row++, 1);
75
76 label = new QLabel(QString::fromUtf8(R__("Activity graphics tag")));
77 label->setParent(this);
78
79 act_gfx = new QLineEdit(this);
80 connect(act_gfx, SIGNAL(returnPressed()), this, SLOT(act_gfx_given()));
81
82 extra_layout->addWidget(label, row, 0);
83 extra_layout->addWidget(act_gfx, row++, 1);
84
85 label = new QLabel(QString::fromUtf8(R__("Alt activity gfx tag")));
86 label->setParent(this);
87
88 act_gfx_alt = new QLineEdit(this);
89 connect(act_gfx_alt, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt_given()));
90
91 extra_layout->addWidget(label, row, 0);
92 extra_layout->addWidget(act_gfx_alt, row++, 1);
93
94 label = new QLabel(QString::fromUtf8(R__("Second alt activity gfx tag")));
95 label->setParent(this);
96
97 act_gfx_alt2 = new QLineEdit(this);
98 connect(act_gfx_alt2, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt2_given()));
99
100 extra_layout->addWidget(label, row, 0);
101 extra_layout->addWidget(act_gfx_alt2, row++, 1);
102
103 label = new QLabel(QString::fromUtf8(R__("Removal activity graphics tag")));
104 label->setParent(this);
105
106 rmact_gfx = new QLineEdit(this);
107 connect(rmact_gfx, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_given()));
108
109 extra_layout->addWidget(label, row, 0);
110 extra_layout->addWidget(rmact_gfx, row++, 1);
111
112 label = new QLabel(QString::fromUtf8(R__("Alt removal activity gfx tag")));
113 label->setParent(this);
114
115 rmact_gfx_alt = new QLineEdit(this);
116 connect(rmact_gfx_alt, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_alt_given()));
117
118 extra_layout->addWidget(label, row, 0);
119 extra_layout->addWidget(rmact_gfx_alt, row++, 1);
120
121 label = new QLabel(QString::fromUtf8(R__("Second alt removal activity gfx tag")));
122 label->setParent(this);
123
124 rmact_gfx_alt2 = new QLineEdit(this);
125 connect(rmact_gfx_alt2, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_alt2_given()));
126
127 extra_layout->addWidget(label, row, 0);
128 extra_layout->addWidget(rmact_gfx_alt2, row++, 1);
129
130 label = new QLabel(QString::fromUtf8(R__("Native to")));
131 natives_layout->addWidget(label, 0, 0);
132 for (int i = 0; i < game.control.num_unit_classes; i++) {
133 QCheckBox *check = new QCheckBox();
134
135 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
136 natives_layout->addWidget(label, i + 1, 0);
137
138 check->setChecked(BV_ISSET(extra->native_to, i));
139 natives_layout->addWidget(check, i + 1, 1);
140 }
141
142 rowcount = 0;
143 column = 0;
144 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
145 enum extra_flag_id flag = (enum extra_flag_id)i;
146 QCheckBox *check = new QCheckBox();
147
148 label = new QLabel(extra_flag_id_name(flag));
149 flag_layout->addWidget(label, rowcount, column + 1);
150
151 check->setChecked(BV_ISSET(extra->flags, flag));
152 flag_layout->addWidget(check, rowcount, column);
153
154 if (++rowcount >= FLAGROWS) {
155 column += 2;
156 rowcount = 0;
157 }
158 }
159
160 refresh();
161
162 main_layout->addLayout(extra_layout);
163 main_layout->addLayout(natives_layout);
164 main_layout->addLayout(flag_layout);
165
166 setLayout(main_layout);
167}
168
169/**********************************************************************/
172 void edit_extra::closeEvent(QCloseEvent *cevent)
173{
174 int rowcount;
175 int column;
176
177 // Save values from text fields.
178 gfx_tag_given();
179 gfx_tag_alt_given();
180 act_gfx_given();
181 act_gfx_alt_given();
182 act_gfx_alt2_given();
183 rmact_gfx_given();
184 rmact_gfx_alt_given();
185 rmact_gfx_alt2_given();
186
187 BV_CLR_ALL(extra->native_to);
188 for (int i = 0; i < game.control.num_unit_classes; i++) {
189 QCheckBox *check = static_cast< QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
190
191 if (check->isChecked()) {
192 BV_SET(extra->native_to, i);
193 }
194 }
195
196 BV_CLR_ALL(extra->flags);
197 rowcount = 0;
198 column = 0;
199 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
200 QCheckBox *check = static_cast< QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
201
202 if (check->isChecked()) {
203 BV_SET(extra->flags, i);
204 }
205
206 if (++rowcount >= FLAGROWS) {
207 rowcount = 0;
208 column += 2;
209 }
210 }
211
212 extra->ruledit_dlg = nullptr;
213}
214
215/**********************************************************************/
218 void edit_extra::refresh()
219{
220 gfx_tag->setText(extra->graphic_str);
221 gfx_tag_alt->setText(extra->graphic_alt);
222 act_gfx->setText(extra->activity_gfx);
223 act_gfx_alt->setText(extra->act_gfx_alt);
224 act_gfx_alt2->setText(extra->act_gfx_alt2);
225 rmact_gfx->setText(extra->rmact_gfx);
226 rmact_gfx_alt->setText(extra->rmact_gfx_alt);
227 rmact_gfx_alt2->setText(extra->rmact_gfx_alt2);
228}
229
230/**********************************************************************/
233 void edit_extra::gfx_tag_given()
234{
235 QByteArray tag_bytes = gfx_tag->text().toUtf8();
236
237 sz_strlcpy(extra->graphic_str, tag_bytes);
238}
239
240/**********************************************************************/
243 void edit_extra::gfx_tag_alt_given()
244{
245 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
246
247 sz_strlcpy(extra->graphic_alt, tag_bytes);
248}
249
250/**********************************************************************/
253 void edit_extra::act_gfx_given()
254{
255 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
256
257 sz_strlcpy(extra->activity_gfx, tag_bytes);
258}
259
260/**********************************************************************/
263 void edit_extra::act_gfx_alt_given()
264{
265 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
266
267 sz_strlcpy(extra->act_gfx_alt, tag_bytes);
268}
269
270/**********************************************************************/
273 void edit_extra::act_gfx_alt2_given()
274{
275 QByteArray tag_bytes = act_gfx_alt2->text().toUtf8();
276
277 sz_strlcpy(extra->act_gfx_alt2, tag_bytes);
278}
279
280/**********************************************************************/
283 void edit_extra::rmact_gfx_given()
284{
285 QByteArray tag_bytes = rmact_gfx->text().toUtf8();
286
287 sz_strlcpy(extra->rmact_gfx, tag_bytes);
288}
289
290/**********************************************************************/
293 void edit_extra::rmact_gfx_alt_given()
294{
295 QByteArray tag_bytes = rmact_gfx_alt->text().toUtf8();
296
297 sz_strlcpy(extra->rmact_gfx_alt, tag_bytes);
298}
299
300/**********************************************************************/
303 void edit_extra::rmact_gfx_alt2_given()
304{
305 QByteArray tag_bytes = rmact_gfx_alt2->text().toUtf8();
306
307 sz_strlcpy(extra->rmact_gfx_alt2, tag_bytes);
308}
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
edit_extra::rmact_gfx_alt2_given
void rmact_gfx_alt2_given()
Definition edit_extra.cpp:303
edit_extra::edit_extra
edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
Definition edit_extra.cpp:40
edit_extra::flag_layout
QGridLayout * flag_layout
Definition edit_extra.h:51
edit_extra::rmact_gfx_given
void rmact_gfx_given()
Definition edit_extra.cpp:283
edit_extra::act_gfx_alt2_given
void act_gfx_alt2_given()
Definition edit_extra.cpp:273
edit_extra::refresh
void refresh()
Definition edit_extra.cpp:218
edit_extra::act_gfx_alt2
QLineEdit * act_gfx_alt2
Definition edit_extra.h:45
edit_extra::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_extra.cpp:243
edit_extra::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_extra.cpp:172
edit_extra::rmact_gfx_alt_given
void rmact_gfx_alt_given()
Definition edit_extra.cpp:293
edit_extra::rmact_gfx_alt2
QLineEdit * rmact_gfx_alt2
Definition edit_extra.h:48
edit_extra::gfx_tag
QLineEdit * gfx_tag
Definition edit_extra.h:41
edit_extra::extra
struct extra_type * extra
Definition edit_extra.h:40
edit_extra::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_extra.h:42
edit_extra::rmact_gfx
QLineEdit * rmact_gfx
Definition edit_extra.h:46
edit_extra::rmact_gfx_alt
QLineEdit * rmact_gfx_alt
Definition edit_extra.h:47
edit_extra::act_gfx
QLineEdit * act_gfx
Definition edit_extra.h:43
edit_extra::natives_layout
QGridLayout * natives_layout
Definition edit_extra.h:50
edit_extra::ui
ruledit_gui * ui
Definition edit_extra.h:39
edit_extra::act_gfx_given
void act_gfx_given()
Definition edit_extra.cpp:253
edit_extra::gfx_tag_given
void gfx_tag_given()
Definition edit_extra.cpp:233
edit_extra::act_gfx_alt
QLineEdit * act_gfx_alt
Definition edit_extra.h:44
edit_extra::act_gfx_alt_given
void act_gfx_alt_given()
Definition edit_extra.cpp:263
ruledit_gui
Definition ruledit_qt.h:97
incite_cost
char * incite_cost
Definition comments.c:74
FLAGROWS
#define FLAGROWS
Definition edit_extra.cpp:35
edit_extra.h
extra_rule_name
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
extras.h
EF_LAST_USER_FLAG
#define EF_LAST_USER_FLAG
Definition extras.h:82
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:61
game.h
ruledit.h
ruledit_qt.h
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
extra_type
Definition extras.h:88
extra_type::native_to
bv_unit_classes native_to
Definition extras.h:130
extra_type::rmact_gfx
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:102
extra_type::act_gfx_alt
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
extra_type::flags
bv_extra_flags flags
Definition extras.h:132
extra_type::rmact_gfx_alt
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:103
extra_type::rmact_gfx_alt2
char rmact_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:104
extra_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:98
extra_type::activity_gfx
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:99
extra_type::ruledit_dlg
void * ruledit_dlg
Definition extras.h:92
extra_type::act_gfx_alt2
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:101
extra_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition extras.h:97
packet_ruleset_control::num_unit_classes
int num_unit_classes
Definition packets_gen.h:1437
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
uclass_by_number
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2476
uclass_rule_name
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641