Freeciv-3.1
Loading...
Searching...
No Matches
edit_utype.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 <QCheckBox>
20#include <QGridLayout>
21#include <QLineEdit>
22#include <QMenu>
23#include <QPushButton>
24#include <QSpinBox>
25#include <QToolButton>
26
27// common
28#include "unittype.h"
29
30// ruledit
31#include "ruledit.h"
32#include "ruledit_qt.h"
33#include "tab_tech.h"
34
35#include "edit_utype.h"
36
37/**********************************************************************/
41{
42 QHBoxLayout *main_layout = new QHBoxLayout(this);
43 QGridLayout *unit_layout = new QGridLayout();
44 QLabel *label;
45 QPushButton *button;
46 QMenu *req;
47 QMenu *menu;
48 int row = 0;
49 int rowcount;
50 int column;
51
52 ui = ui_in;
53 utype = utype_in;
54
55 flag_layout = new QGridLayout();
56
57 setWindowTitle(QString::fromUtf8(utype_rule_name(utype)));
58
59 label = new QLabel(QString::fromUtf8(R__("Requirement")));
60 label->setParent(this);
61
62 req = new QMenu();
63 req_button = new QToolButton();
64 req_button->setParent(this);
65 req_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
66 req_button->setPopupMode(QToolButton::MenuButtonPopup);
67 req_button->setMenu(req);
69 connect(req_button, SIGNAL(triggered(QAction *)), this, SLOT(req_menu(QAction *)));
70
71 unit_layout->addWidget(label, row, 0);
72 unit_layout->addWidget(req_button, row++, 1);
73
74 label = new QLabel(QString::fromUtf8(R__("Class")));
75 label->setParent(this);
76 class_button = new QToolButton();
77 class_button->setParent(this);
78 class_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
79 class_button->setPopupMode(QToolButton::MenuButtonPopup);
80 menu = new QMenu();
81 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(class_menu(QAction *)));
82
84 menu->addAction(uclass_rule_name(pclass));
86
87 class_button->setMenu(menu);
88
89 unit_layout->addWidget(label, row, 0);
90 unit_layout->addWidget(class_button, row++, 1);
91
92 label = new QLabel(QString::fromUtf8(R__("Build Cost")));
93 label->setParent(this);
94
95 bcost = new QSpinBox(this);
96 bcost->setRange(0, 10000);
97 connect(bcost, SIGNAL
98 (valueChanged(int)), this, SLOT(set_bcost_value(int)));
99
100 unit_layout->addWidget(label, row, 0);
101 unit_layout->addWidget(bcost, row++, 1);
102
103 label = new QLabel(QString::fromUtf8(R__("Attack Strength")));
104 label->setParent(this);
105
106 attack = new QSpinBox(this);
107 attack->setRange(0, 1000);
108 connect(attack, SIGNAL(valueChanged(int)), this, SLOT(set_attack_value(int)));
109
110 unit_layout->addWidget(label, row, 0);
111 unit_layout->addWidget(attack, row++, 1);
112
113 label = new QLabel(QString::fromUtf8(R__("Defense Strength")));
114 label->setParent(this);
115
116 defense = new QSpinBox(this);
117 defense->setRange(0, 1000);
118 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
119
120 unit_layout->addWidget(label, row, 0);
121 unit_layout->addWidget(defense, row++, 1);
122
123 label = new QLabel(QString::fromUtf8(R__("Hitpoints")));
124 label->setParent(this);
125
126 hitpoints = new QSpinBox(this);
127 hitpoints->setRange(0, 1000);
128 connect(hitpoints, SIGNAL(valueChanged(int)), this, SLOT(set_hitpoints(int)));
129
130 unit_layout->addWidget(label, row, 0);
131 unit_layout->addWidget(hitpoints, row++, 1);
132
133 label = new QLabel(QString::fromUtf8(R__("Firepower")));
134 label->setParent(this);
135
136 firepower = new QSpinBox(this);
137 firepower->setRange(0, 200);
138 connect(firepower, SIGNAL(valueChanged(int)), this, SLOT(set_firepower(int)));
139
140 unit_layout->addWidget(label, row, 0);
141 unit_layout->addWidget(firepower, row++, 1);
142
143 label = new QLabel(QString::fromUtf8(R__("Move Rate")));
144 label->setParent(this);
145
146 move_rate = new QSpinBox(this);
147 move_rate->setRange(0, 50);
148 connect(move_rate, SIGNAL(valueChanged(int)), this, SLOT(set_move_rate(int)));
149
150 unit_layout->addWidget(label, row, 0);
151 unit_layout->addWidget(move_rate, row++, 1);
152
153 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
154 label->setParent(this);
155
156 gfx_tag = new QLineEdit(this);
157 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
158
159 unit_layout->addWidget(label, row, 0);
160 unit_layout->addWidget(gfx_tag, row++, 1);
161
162 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
163 label->setParent(this);
164
165 gfx_tag_alt = new QLineEdit(this);
166 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
167
168 unit_layout->addWidget(label, row, 0);
169 unit_layout->addWidget(gfx_tag_alt, row++, 1);
170
171 label = new QLabel(QString::fromUtf8(R__("Move sound tag")));
172 label->setParent(this);
173
174 sound_move_tag = new QLineEdit(this);
175 connect(sound_move_tag, SIGNAL(returnPressed()), this,
176 SLOT(sound_move_tag_given()));
177
178 unit_layout->addWidget(label, row, 0);
179 unit_layout->addWidget(sound_move_tag, row++, 1);
180
181 label = new QLabel(QString::fromUtf8(R__("Alt move sound tag")));
182 label->setParent(this);
183
184 sound_move_tag_alt = new QLineEdit(this);
185 connect(sound_move_tag_alt, SIGNAL(returnPressed()), this,
187
188 unit_layout->addWidget(label, row, 0);
189 unit_layout->addWidget(sound_move_tag_alt, row++, 1);
190
191 label = new QLabel(QString::fromUtf8(R__("Fight sound tag")));
192 label->setParent(this);
193
194 sound_fight_tag = new QLineEdit(this);
195 connect(sound_fight_tag, SIGNAL(returnPressed()), this,
196 SLOT(sound_fight_tag_given()));
197
198 unit_layout->addWidget(label, row, 0);
199 unit_layout->addWidget(sound_fight_tag, row++, 1);
200
201 label = new QLabel(QString::fromUtf8(R__("Alt fight sound tag")));
202 label->setParent(this);
203
204 sound_fight_tag_alt = new QLineEdit(this);
205 connect(sound_fight_tag_alt, SIGNAL(returnPressed()), this,
207
208 unit_layout->addWidget(label, row, 0);
209 unit_layout->addWidget(sound_fight_tag_alt, row++, 1);
210
211 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
212 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
213 unit_layout->addWidget(button, row++, 1);
214
215 rowcount = 0;
216 column = 0;
217 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
218 enum unit_type_flag_id flag = (enum unit_type_flag_id)i;
219 QCheckBox *check = new QCheckBox();
220
221 label = new QLabel(unit_type_flag_id_name(flag));
222 flag_layout->addWidget(label, rowcount, column + 1);
223
224 check->setChecked(BV_ISSET(utype->flags, flag));
225 flag_layout->addWidget(check, rowcount, column);
226
227 if (++rowcount >= 25) {
228 column += 2;
229 rowcount = 0;
230 }
231 }
232
233 refresh();
234
235 main_layout->addLayout(unit_layout);
236 main_layout->addLayout(flag_layout);
237
238 setLayout(main_layout);
239}
240
241/**********************************************************************/
244void edit_utype::closeEvent(QCloseEvent *cevent)
245{
246 int rowcount;
247 int column;
248
249 close_help();
250
251 // Save values from text fields.
258
260 rowcount = 0;
261 column = 0;
262 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
263 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
264
265 if (check->isChecked()) {
266 BV_SET(utype->flags, i);
267 }
268
269 if (++rowcount >= 25) {
270 rowcount = 0;
271 column += 2;
272 }
273 }
274
275 utype->ruledit_dlg = nullptr;
276}
277
278/**********************************************************************/
282{
285 bcost->setValue(utype->build_cost);
286 attack->setValue(utype->attack_strength);
287 defense->setValue(utype->defense_strength);
288 hitpoints->setValue(utype->hp);
289 firepower->setValue(utype->firepower);
290 move_rate->setValue(utype->move_rate);
291 gfx_tag->setText(utype->graphic_str);
292 gfx_tag_alt->setText(utype->graphic_alt);
297}
298
299/**********************************************************************/
303{
304 struct advance *padv;
305 QByteArray an_bytes;
306
307 an_bytes = action->text().toUtf8();
308 padv = advance_by_rule_name(an_bytes.data());
309
310 if (padv != nullptr) {
311 utype->require_advance = padv;
312
313 refresh();
314 }
315}
316
317/**********************************************************************/
321{
322 utype->build_cost = value;
323}
324
325/**********************************************************************/
329{
330 utype->attack_strength = value;
331}
332
333/**********************************************************************/
337{
338 utype->defense_strength = value;
339}
340
341/**********************************************************************/
345{
346 utype->hp = value;
347}
348
349/**********************************************************************/
353{
354 utype->firepower = value;
355}
356
357/**********************************************************************/
361{
362 utype->move_rate = value;
363}
364
365/**********************************************************************/
369{
370 QByteArray tag_bytes = gfx_tag->text().toUtf8();
371
372 sz_strlcpy(utype->graphic_str, tag_bytes);
373}
374
375/**********************************************************************/
379{
380 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
381
382 sz_strlcpy(utype->graphic_alt, tag_bytes);
383}
384
385/**********************************************************************/
389{
390 QByteArray tag_bytes = sound_move_tag->text().toUtf8();
391
392 sz_strlcpy(utype->sound_move, tag_bytes);
393}
394
395/**********************************************************************/
399{
400 QByteArray tag_bytes = sound_move_tag_alt->text().toUtf8();
401
402 sz_strlcpy(utype->sound_move_alt, tag_bytes);
403}
404
405/**********************************************************************/
409{
410 QByteArray tag_bytes = sound_fight_tag->text().toUtf8();
411
412 sz_strlcpy(utype->sound_fight, tag_bytes);
413}
414
415/**********************************************************************/
419{
420 QByteArray tag_bytes = sound_fight_tag_alt->text().toUtf8();
421
422 sz_strlcpy(utype->sound_fight_alt, tag_bytes);
423}
424
425/**********************************************************************/
429{
430 QByteArray cn_bytes;
431 struct unit_class *pclass;
432
433 cn_bytes = action->text().toUtf8();
434 pclass = unit_class_by_rule_name(cn_bytes.data());
435
436 utype->uclass = pclass;
437
438 refresh();
439}
440
441/**********************************************************************/
#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
QSpinBox * firepower
Definition edit_utype.h:51
void set_bcost_value(int value)
QLineEdit * sound_move_tag_alt
Definition edit_utype.h:56
edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in)
void sound_move_tag_given()
void set_defense_value(int value)
void set_attack_value(int value)
QSpinBox * attack
Definition edit_utype.h:48
QSpinBox * bcost
Definition edit_utype.h:47
QLineEdit * sound_fight_tag
Definition edit_utype.h:57
QLineEdit * sound_fight_tag_alt
Definition edit_utype.h:58
void gfx_tag_given()
void sound_fight_tag_given()
QLineEdit * sound_move_tag
Definition edit_utype.h:55
void refresh()
void set_firepower(int value)
ruledit_gui * ui
Definition edit_utype.h:43
QToolButton * class_button
Definition edit_utype.h:46
void closeEvent(QCloseEvent *cevent)
void helptext()
QSpinBox * defense
Definition edit_utype.h:49
QSpinBox * move_rate
Definition edit_utype.h:52
void set_move_rate(int value)
QSpinBox * hitpoints
Definition edit_utype.h:50
void req_menu(QAction *action)
void sound_move_tag_alt_given()
QLineEdit * gfx_tag_alt
Definition edit_utype.h:54
void class_menu(QAction *action)
QGridLayout * flag_layout
Definition edit_utype.h:60
void gfx_tag_alt_given()
struct unit_type * utype
Definition edit_utype.h:44
void sound_fight_tag_alt_given()
QLineEdit * gfx_tag
Definition edit_utype.h:53
QToolButton * req_button
Definition edit_utype.h:45
void set_hitpoints(int value)
static void techs_to_menu(QMenu *fill_menu)
Definition tab_tech.cpp:189
static QString tech_name(struct advance *padv)
Definition tab_tech.cpp:201
void close_help()
void open_help(struct strvec **help)
#define R__(String)
Definition fcintl.h:75
struct unit_class * uclass
Definition unittype.h:537
int defense_strength
Definition unittype.h:496
int firepower
Definition unittype.h:506
char graphic_alt[MAX_LEN_NAME]
Definition unittype.h:487
char sound_move_alt[MAX_LEN_NAME]
Definition unittype.h:489
int build_cost
Definition unittype.h:492
int move_rate
Definition unittype.h:497
struct advance * require_advance
Definition unittype.h:500
struct strvec * helptext
Definition unittype.h:552
char graphic_str[MAX_LEN_NAME]
Definition unittype.h:486
char sound_move[MAX_LEN_NAME]
Definition unittype.h:488
char sound_fight_alt[MAX_LEN_NAME]
Definition unittype.h:491
bv_unit_type_flags flags
Definition unittype.h:515
char sound_fight[MAX_LEN_NAME]
Definition unittype.h:490
int attack_strength
Definition unittype.h:495
void * ruledit_dlg
Definition unittype.h:485
#define sz_strlcpy(dest, src)
Definition support.h:161
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1836
#define unit_class_re_active_iterate_end
Definition unittype.h:892
#define UTYF_LAST_USER_FLAG
Definition unittype.h:315
#define unit_class_re_active_iterate(_p)
Definition unittype.h:888