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 <QPushButton>
23#include <QToolButton>
24
25// common
26#include "extras.h"
27#include "game.h"
28
29// ruledit
30#include "ruledit.h"
31#include "ruledit_qt.h"
32
33#include "edit_extra.h"
34
35
36#define FLAGROWS 15
37
38/**********************************************************************/
42 : values_dlg()
43{
44 QHBoxLayout *main_layout = new QHBoxLayout(this);
45 QGridLayout *extra_layout = new QGridLayout();
46 QLabel *label;
47 QPushButton *button;
48 int row = 0;
49 int rowcount;
50 int column;
51
52 ui = ui_in;
53 extra = extra_in;
54
55 natives_layout = new QGridLayout();
56 flag_layout = new QGridLayout();
57
58 setWindowTitle(QString::fromUtf8(extra_rule_name(extra)));
59
60 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
61 label->setParent(this);
62
63 gfx_tag = new QLineEdit(this);
64 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
65
66 extra_layout->addWidget(label, row, 0);
67 extra_layout->addWidget(gfx_tag, row++, 1);
68
69 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
70 label->setParent(this);
71
72 gfx_tag_alt = new QLineEdit(this);
73 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
74
75 extra_layout->addWidget(label, row, 0);
76 extra_layout->addWidget(gfx_tag_alt, row++, 1);
77
78 label = new QLabel(QString::fromUtf8(R__("Activity graphics tag")));
79 label->setParent(this);
80
81 act_gfx = new QLineEdit(this);
82 connect(act_gfx, SIGNAL(returnPressed()), this, SLOT(act_gfx_given()));
83
84 extra_layout->addWidget(label, row, 0);
85 extra_layout->addWidget(act_gfx, row++, 1);
86
87 label = new QLabel(QString::fromUtf8(R__("Alt activity gfx tag")));
88 label->setParent(this);
89
90 act_gfx_alt = new QLineEdit(this);
91 connect(act_gfx_alt, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt_given()));
92
93 extra_layout->addWidget(label, row, 0);
94 extra_layout->addWidget(act_gfx_alt, row++, 1);
95
96 label = new QLabel(QString::fromUtf8(R__("Second alt activity gfx tag")));
97 label->setParent(this);
98
99 act_gfx_alt2 = new QLineEdit(this);
100 connect(act_gfx_alt2, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt2_given()));
101
102 extra_layout->addWidget(label, row, 0);
103 extra_layout->addWidget(act_gfx_alt2, row++, 1);
104
105 label = new QLabel(QString::fromUtf8(R__("Removal activity graphics tag")));
106 label->setParent(this);
107
108 rmact_gfx = new QLineEdit(this);
109 connect(rmact_gfx, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_given()));
110
111 extra_layout->addWidget(label, row, 0);
112 extra_layout->addWidget(rmact_gfx, row++, 1);
113
114 label = new QLabel(QString::fromUtf8(R__("Alt removal activity gfx tag")));
115 label->setParent(this);
116
117 rmact_gfx_alt = new QLineEdit(this);
118 connect(rmact_gfx_alt, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_alt_given()));
119
120 extra_layout->addWidget(label, row, 0);
121 extra_layout->addWidget(rmact_gfx_alt, row++, 1);
122
123 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
124 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
125 extra_layout->addWidget(button, row++, 1);
126
127 label = new QLabel(QString::fromUtf8(R__("Native to")));
128 natives_layout->addWidget(label, 0, 0);
129 for (int i = 0; i < game.control.num_unit_classes; i++) {
130 QCheckBox *check = new QCheckBox();
131
132 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
133 natives_layout->addWidget(label, i + 1, 0);
134
135 check->setChecked(BV_ISSET(extra->native_to, i));
136 natives_layout->addWidget(check, i + 1, 1);
137 }
138
139 rowcount = 0;
140 column = 0;
141 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
142 enum extra_flag_id flag = (enum extra_flag_id)i;
143 QCheckBox *check = new QCheckBox();
144
145 label = new QLabel(extra_flag_id_name(flag));
146 flag_layout->addWidget(label, rowcount, column + 1);
147
148 check->setChecked(BV_ISSET(extra->flags, flag));
149 flag_layout->addWidget(check, rowcount, column);
150
151 if (++rowcount >= FLAGROWS) {
152 column += 2;
153 rowcount = 0;
154 }
155 }
156
157 refresh();
158
159 main_layout->addLayout(extra_layout);
160 main_layout->addLayout(natives_layout);
161 main_layout->addLayout(flag_layout);
162
163 setLayout(main_layout);
164}
165
166/**********************************************************************/
169void edit_extra::closeEvent(QCloseEvent *cevent)
170{
171 int rowcount;
172 int column;
173
174 close_help();
175
176 // Save values from text fields.
184
186 for (int i = 0; i < game.control.num_unit_classes; i++) {
187 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
188
189 if (check->isChecked()) {
191 }
192 }
193
195 rowcount = 0;
196 column = 0;
197 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
198 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
199
200 if (check->isChecked()) {
201 BV_SET(extra->flags, i);
202 }
203
204 if (++rowcount >= FLAGROWS) {
205 rowcount = 0;
206 column += 2;
207 }
208 }
209
210 extra->ruledit_dlg = nullptr;
211}
212
213/**********************************************************************/
217{
218 gfx_tag->setText(extra->graphic_str);
219 gfx_tag_alt->setText(extra->graphic_alt);
220 act_gfx->setText(extra->activity_gfx);
221 act_gfx_alt->setText(extra->act_gfx_alt);
223 rmact_gfx->setText(extra->rmact_gfx);
225}
226
227/**********************************************************************/
231{
232 QByteArray tag_bytes = gfx_tag->text().toUtf8();
233
234 sz_strlcpy(extra->graphic_str, tag_bytes);
235}
236
237/**********************************************************************/
241{
242 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
243
244 sz_strlcpy(extra->graphic_alt, tag_bytes);
245}
246
247/**********************************************************************/
251{
252 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
253
254 sz_strlcpy(extra->activity_gfx, tag_bytes);
255}
256
257/**********************************************************************/
261{
262 QByteArray tag_bytes = act_gfx_alt->text().toUtf8();
263
264 sz_strlcpy(extra->act_gfx_alt, tag_bytes);
265}
266
267/**********************************************************************/
271{
272 QByteArray tag_bytes = act_gfx_alt2->text().toUtf8();
273
274 sz_strlcpy(extra->act_gfx_alt2, tag_bytes);
275}
276
277/**********************************************************************/
281{
282 QByteArray tag_bytes = rmact_gfx->text().toUtf8();
283
284 sz_strlcpy(extra->rmact_gfx, tag_bytes);
285}
286
287/**********************************************************************/
291{
292 QByteArray tag_bytes = rmact_gfx_alt->text().toUtf8();
293
294 sz_strlcpy(extra->rmact_gfx_alt, tag_bytes);
295}
296
297/**********************************************************************/
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
QGridLayout * flag_layout
Definition edit_extra.h:53
void rmact_gfx_given()
void act_gfx_alt2_given()
void refresh()
QLineEdit * act_gfx_alt2
Definition edit_extra.h:48
void gfx_tag_alt_given()
void closeEvent(QCloseEvent *cevent)
void rmact_gfx_alt_given()
QLineEdit * gfx_tag
Definition edit_extra.h:44
struct extra_type * extra
Definition edit_extra.h:43
QLineEdit * gfx_tag_alt
Definition edit_extra.h:45
QLineEdit * rmact_gfx
Definition edit_extra.h:49
QLineEdit * rmact_gfx_alt
Definition edit_extra.h:50
QLineEdit * act_gfx
Definition edit_extra.h:46
QGridLayout * natives_layout
Definition edit_extra.h:52
ruledit_gui * ui
Definition edit_extra.h:42
void act_gfx_given()
void helptext()
void gfx_tag_given()
QLineEdit * act_gfx_alt
Definition edit_extra.h:47
void act_gfx_alt_given()
void close_help()
void open_help(struct strvec **help)
#define FLAGROWS
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
#define EF_LAST_USER_FLAG
Definition extras.h:79
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:57
struct packet_ruleset_control control
Definition game.h:83
bv_unit_classes native_to
Definition extras.h:126
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:99
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:97
struct strvec * helptext
Definition extras.h:143
bv_extra_flags flags
Definition extras.h:128
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:95
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:96
void * ruledit_dlg
Definition extras.h:89
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:98
char graphic_str[MAX_LEN_NAME]
Definition extras.h:94
#define sz_strlcpy(dest, src)
Definition support.h:167
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2525
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693