Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/edit_extra.cpp Source File

Freeciv-3.1

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__("Native to")));
122 natives_layout->addWidget(label, 0, 0);
123 for (int i = 0; i < game.control.num_unit_classes; i++) {
124 QCheckBox *check = new QCheckBox();
125
126 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
127 natives_layout->addWidget(label, i + 1, 0);
128
129 check->setChecked(BV_ISSET(extra->native_to, i));
130 natives_layout->addWidget(check, i + 1, 1);
131 }
132
133 rowcount = 0;
134 column = 0;
135 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
136 enum extra_flag_id flag = (enum extra_flag_id)i;
137 QCheckBox *check = new QCheckBox();
138
139 label = new QLabel(extra_flag_id_name(flag));
140 flag_layout->addWidget(label, rowcount, column + 1);
141
142 check->setChecked(BV_ISSET(extra->flags, flag));
143 flag_layout->addWidget(check, rowcount, column);
144
145 if (++rowcount >= FLAGROWS) {
146 column += 2;
147 rowcount = 0;
148 }
149 }
150
151 refresh();
152
153 main_layout->addLayout(extra_layout);
154 main_layout->addLayout(natives_layout);
155 main_layout->addLayout(flag_layout);
156
157 setLayout(main_layout);
158}
159
160/**********************************************************************/
163 void edit_extra::closeEvent(QCloseEvent *cevent)
164{
165 int rowcount;
166 int column;
167
168 // Save values from text fields.
169 gfx_tag_given();
170 gfx_tag_alt_given();
171 act_gfx_given();
172 act_gfx_alt_given();
173 act_gfx_alt2_given();
174 rmact_gfx_given();
175 rmact_gfx_alt_given();
176
177 BV_CLR_ALL(extra->native_to);
178 for (int i = 0; i < game.control.num_unit_classes; i++) {
179 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
180
181 if (check->isChecked()) {
182 BV_SET(extra->native_to, i);
183 }
184 }
185
186 BV_CLR_ALL(extra->flags);
187 rowcount = 0;
188 column = 0;
189 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
190 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
191
192 if (check->isChecked()) {
193 BV_SET(extra->flags, i);
194 }
195
196 if (++rowcount >= FLAGROWS) {
197 rowcount = 0;
198 column += 2;
199 }
200 }
201
202 extra->ruledit_dlg = nullptr;
203}
204
205/**********************************************************************/
208 void edit_extra::refresh()
209{
210 gfx_tag->setText(extra->graphic_str);
211 gfx_tag_alt->setText(extra->graphic_alt);
212 act_gfx->setText(extra->activity_gfx);
213 act_gfx_alt->setText(extra->act_gfx_alt);
214 act_gfx_alt2->setText(extra->act_gfx_alt2);
215 rmact_gfx->setText(extra->rmact_gfx);
216 rmact_gfx_alt->setText(extra->rmact_gfx_alt);
217}
218
219/**********************************************************************/
222 void edit_extra::gfx_tag_given()
223{
224 QByteArray tag_bytes = gfx_tag->text().toUtf8();
225
226 sz_strlcpy(extra->graphic_str, tag_bytes);
227}
228
229/**********************************************************************/
232 void edit_extra::gfx_tag_alt_given()
233{
234 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
235
236 sz_strlcpy(extra->graphic_alt, tag_bytes);
237}
238
239/**********************************************************************/
242 void edit_extra::act_gfx_given()
243{
244 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
245
246 sz_strlcpy(extra->activity_gfx, tag_bytes);
247}
248
249/**********************************************************************/
252 void edit_extra::act_gfx_alt_given()
253{
254 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
255
256 sz_strlcpy(extra->act_gfx_alt, tag_bytes);
257}
258
259/**********************************************************************/
262 void edit_extra::act_gfx_alt2_given()
263{
264 QByteArray tag_bytes = act_gfx_alt2->text().toUtf8();
265
266 sz_strlcpy(extra->act_gfx_alt2, tag_bytes);
267}
268
269/**********************************************************************/
272 void edit_extra::rmact_gfx_given()
273{
274 QByteArray tag_bytes = rmact_gfx->text().toUtf8();
275
276 sz_strlcpy(extra->rmact_gfx, tag_bytes);
277}
278
279/**********************************************************************/
282 void edit_extra::rmact_gfx_alt_given()
283{
284 QByteArray tag_bytes = rmact_gfx_alt->text().toUtf8();
285
286 sz_strlcpy(extra->rmact_gfx_alt, tag_bytes);
287}
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::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:50
edit_extra::rmact_gfx_given
void rmact_gfx_given()
Definition edit_extra.cpp:272
edit_extra::act_gfx_alt2_given
void act_gfx_alt2_given()
Definition edit_extra.cpp:262
edit_extra::refresh
void refresh()
Definition edit_extra.cpp:208
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:232
edit_extra::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_extra.cpp:163
edit_extra::rmact_gfx_alt_given
void rmact_gfx_alt_given()
Definition edit_extra.cpp:282
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:49
edit_extra::ui
ruledit_gui * ui
Definition edit_extra.h:39
edit_extra::act_gfx_given
void act_gfx_given()
Definition edit_extra.cpp:242
edit_extra::gfx_tag_given
void gfx_tag_given()
Definition edit_extra.cpp:222
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:252
ruledit_gui
Definition ruledit_qt.h:96
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:195
extras.h
EF_LAST_USER_FLAG
#define EF_LAST_USER_FLAG
Definition extras.h:79
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:57
game.h
ruledit.h
ruledit_qt.h
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
extra_type
Definition extras.h:85
extra_type::native_to
bv_unit_classes native_to
Definition extras.h:126
extra_type::rmact_gfx
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:99
extra_type::act_gfx_alt
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:97
extra_type::flags
bv_extra_flags flags
Definition extras.h:128
extra_type::rmact_gfx_alt
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
extra_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:95
extra_type::activity_gfx
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:96
extra_type::ruledit_dlg
void * ruledit_dlg
Definition extras.h:89
extra_type::act_gfx_alt2
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:98
extra_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition extras.h:94
packet_ruleset_control::num_unit_classes
int num_unit_classes
Definition packets_gen.h:1455
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
uclass_by_number
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2524
uclass_rule_name
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693