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 <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);
46 QLabel *label;
47 QPushButton *button;
48 int row = 0;
49 int rowcount;
50 int column;
51
52 ui = ui_in;
54
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);
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);
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);
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);
119
120 extra_layout->addWidget(label, row, 0);
121 extra_layout->addWidget(rmact_gfx_alt, row++, 1);
122
123 label = new QLabel(QString::fromUtf8(R__("Second alt removal activity gfx tag")));
124 label->setParent(this);
125
126 rmact_gfx_alt2 = new QLineEdit(this);
128
129 extra_layout->addWidget(label, row, 0);
130 extra_layout->addWidget(rmact_gfx_alt2, row++, 1);
131
132 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
133 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
134 extra_layout->addWidget(button, row++, 1);
135
136 label = new QLabel(QString::fromUtf8(R__("Native to")));
137 natives_layout->addWidget(label, 0, 0);
138 for (int i = 0; i < game.control.num_unit_classes; i++) {
139 QCheckBox *check = new QCheckBox();
140
141 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
142 natives_layout->addWidget(label, i + 1, 0);
143
144 check->setChecked(BV_ISSET(extra->native_to, i));
145 natives_layout->addWidget(check, i + 1, 1);
146 }
147
148 rowcount = 0;
149 column = 0;
150 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
151 enum extra_flag_id flag = (enum extra_flag_id)i;
152 QCheckBox *check = new QCheckBox();
153
154 label = new QLabel(extra_flag_id_name(flag));
155 flag_layout->addWidget(label, rowcount, column + 1);
156
157 check->setChecked(BV_ISSET(extra->flags, flag));
158 flag_layout->addWidget(check, rowcount, column);
159
160 if (++rowcount >= FLAGROWS) {
161 column += 2;
162 rowcount = 0;
163 }
164 }
165
166 refresh();
167
168 main_layout->addLayout(extra_layout);
169 main_layout->addLayout(natives_layout);
170 main_layout->addLayout(flag_layout);
171
172 setLayout(main_layout);
173}
174
175/**********************************************************************/
179{
180 int rowcount;
181 int column;
182
183 close_help();
184
185 // Save values from text fields.
194
196 for (int i = 0; i < game.control.num_unit_classes; i++) {
197 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
198
199 if (check->isChecked()) {
201 }
202 }
203
205 rowcount = 0;
206 column = 0;
207 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
208 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
209
210 if (check->isChecked()) {
211 BV_SET(extra->flags, i);
212 }
213
214 if (++rowcount >= FLAGROWS) {
215 rowcount = 0;
216 column += 2;
217 }
218 }
219
220 extra->ruledit_dlg = nullptr;
221}
222
223/**********************************************************************/
227{
228 gfx_tag->setText(extra->graphic_str);
229 gfx_tag_alt->setText(extra->graphic_alt);
230 act_gfx->setText(extra->activity_gfx);
231 act_gfx_alt->setText(extra->act_gfx_alt);
233 rmact_gfx->setText(extra->rmact_gfx);
236}
237
238/**********************************************************************/
242{
243 QByteArray tag_bytes = gfx_tag->text().toUtf8();
244
246}
247
248/**********************************************************************/
257
258/**********************************************************************/
267
268/**********************************************************************/
277
278/**********************************************************************/
287
288/**********************************************************************/
297
298/**********************************************************************/
307
308/**********************************************************************/
317
318/**********************************************************************/
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
void rmact_gfx_alt2_given()
edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
QGridLayout * flag_layout
Definition edit_extra.h:54
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 * rmact_gfx_alt2
Definition edit_extra.h:51
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:53
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)
char * incite_cost
Definition comments.c:76
#define FLAGROWS
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
#define EF_LAST_USER_FLAG
Definition extras.h:82
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
struct packet_ruleset_control control
Definition game.h:83
bv_unit_classes native_to
Definition extras.h:130
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:102
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
struct strvec * helptext
Definition extras.h:149
bv_extra_flags flags
Definition extras.h:132
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:103
char rmact_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:104
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:98
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:99
void * ruledit_dlg
Definition extras.h:92
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:101
char graphic_str[MAX_LEN_NAME]
Definition extras.h:97
#define sz_strlcpy(dest, src)
Definition support.h:195
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2483
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1647