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

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/**********************************************************************/
40edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in) : values_dlg()
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);
68 tab_tech::techs_to_menu(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
83 unit_class_re_active_iterate(pclass) {
84 menu->addAction(uclass_rule_name(pclass));
85 } unit_class_re_active_iterate_end;
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,
186 SLOT(sound_move_tag_alt_given()));
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,
206 SLOT(sound_fight_tag_alt_given()));
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/**********************************************************************/
244 void edit_utype::closeEvent(QCloseEvent *cevent)
245{
246 int rowcount;
247 int column;
248
249 close_help();
250
251 // Save values from text fields.
252 gfx_tag_given();
253 gfx_tag_alt_given();
254 sound_move_tag_given();
255 sound_move_tag_alt_given();
256 sound_fight_tag_given();
257 sound_fight_tag_alt_given();
258
259 BV_CLR_ALL(utype->flags);
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/**********************************************************************/
281 void edit_utype::refresh()
282{
283 req_button->setText(tab_tech::tech_name(utype->require_advance));
284 class_button->setText(uclass_rule_name(utype->uclass));
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);
293 sound_move_tag->setText(utype->sound_move);
294 sound_move_tag_alt->setText(utype->sound_move_alt);
295 sound_fight_tag->setText(utype->sound_fight);
296 sound_fight_tag_alt->setText(utype->sound_fight_alt);
297}
298
299/**********************************************************************/
302 void edit_utype::req_menu(QAction *action)
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/**********************************************************************/
320 void edit_utype::set_bcost_value(int value)
321{
322 utype->build_cost = value;
323}
324
325/**********************************************************************/
328 void edit_utype::set_attack_value(int value)
329{
330 utype->attack_strength = value;
331}
332
333/**********************************************************************/
336 void edit_utype::set_defense_value(int value)
337{
338 utype->defense_strength = value;
339}
340
341/**********************************************************************/
344 void edit_utype::set_hitpoints(int value)
345{
346 utype->hp = value;
347}
348
349/**********************************************************************/
352 void edit_utype::set_firepower(int value)
353{
354 utype->firepower = value;
355}
356
357/**********************************************************************/
360 void edit_utype::set_move_rate(int value)
361{
362 utype->move_rate = value;
363}
364
365/**********************************************************************/
368 void edit_utype::gfx_tag_given()
369{
370 QByteArray tag_bytes = gfx_tag->text().toUtf8();
371
372 sz_strlcpy(utype->graphic_str, tag_bytes);
373}
374
375/**********************************************************************/
378 void edit_utype::gfx_tag_alt_given()
379{
380 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
381
382 sz_strlcpy(utype->graphic_alt, tag_bytes);
383}
384
385/**********************************************************************/
388 void edit_utype::sound_move_tag_given()
389{
390 QByteArray tag_bytes = sound_move_tag->text().toUtf8();
391
392 sz_strlcpy(utype->sound_move, tag_bytes);
393}
394
395/**********************************************************************/
398 void edit_utype::sound_move_tag_alt_given()
399{
400 QByteArray tag_bytes = sound_move_tag_alt->text().toUtf8();
401
402 sz_strlcpy(utype->sound_move_alt, tag_bytes);
403}
404
405/**********************************************************************/
408 void edit_utype::sound_fight_tag_given()
409{
410 QByteArray tag_bytes = sound_fight_tag->text().toUtf8();
411
412 sz_strlcpy(utype->sound_fight, tag_bytes);
413}
414
415/**********************************************************************/
418 void edit_utype::sound_fight_tag_alt_given()
419{
420 QByteArray tag_bytes = sound_fight_tag_alt->text().toUtf8();
421
422 sz_strlcpy(utype->sound_fight_alt, tag_bytes);
423}
424
425/**********************************************************************/
428 void edit_utype::class_menu(QAction *action)
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/**********************************************************************/
444 void edit_utype::helptext()
445{
446 open_help(&utype->helptext);
447}
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_utype::firepower
QSpinBox * firepower
Definition edit_utype.h:51
edit_utype::set_bcost_value
void set_bcost_value(int value)
Definition edit_utype.cpp:320
edit_utype::sound_move_tag_alt
QLineEdit * sound_move_tag_alt
Definition edit_utype.h:56
edit_utype::edit_utype
edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in)
Definition edit_utype.cpp:40
edit_utype::sound_move_tag_given
void sound_move_tag_given()
Definition edit_utype.cpp:388
edit_utype::set_defense_value
void set_defense_value(int value)
Definition edit_utype.cpp:336
edit_utype::set_attack_value
void set_attack_value(int value)
Definition edit_utype.cpp:328
edit_utype::attack
QSpinBox * attack
Definition edit_utype.h:48
edit_utype::bcost
QSpinBox * bcost
Definition edit_utype.h:47
edit_utype::sound_fight_tag
QLineEdit * sound_fight_tag
Definition edit_utype.h:57
edit_utype::sound_fight_tag_alt
QLineEdit * sound_fight_tag_alt
Definition edit_utype.h:58
edit_utype::gfx_tag_given
void gfx_tag_given()
Definition edit_utype.cpp:368
edit_utype::sound_fight_tag_given
void sound_fight_tag_given()
Definition edit_utype.cpp:408
edit_utype::sound_move_tag
QLineEdit * sound_move_tag
Definition edit_utype.h:55
edit_utype::refresh
void refresh()
Definition edit_utype.cpp:281
edit_utype::set_firepower
void set_firepower(int value)
Definition edit_utype.cpp:352
edit_utype::ui
ruledit_gui * ui
Definition edit_utype.h:43
edit_utype::class_button
QToolButton * class_button
Definition edit_utype.h:46
edit_utype::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_utype.cpp:244
edit_utype::helptext
void helptext()
Definition edit_utype.cpp:444
edit_utype::defense
QSpinBox * defense
Definition edit_utype.h:49
edit_utype::move_rate
QSpinBox * move_rate
Definition edit_utype.h:52
edit_utype::set_move_rate
void set_move_rate(int value)
Definition edit_utype.cpp:360
edit_utype::hitpoints
QSpinBox * hitpoints
Definition edit_utype.h:50
edit_utype::req_menu
void req_menu(QAction *action)
Definition edit_utype.cpp:302
edit_utype::sound_move_tag_alt_given
void sound_move_tag_alt_given()
Definition edit_utype.cpp:398
edit_utype::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_utype.h:54
edit_utype::class_menu
void class_menu(QAction *action)
Definition edit_utype.cpp:428
edit_utype::flag_layout
QGridLayout * flag_layout
Definition edit_utype.h:60
edit_utype::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_utype.cpp:378
edit_utype::utype
struct unit_type * utype
Definition edit_utype.h:44
edit_utype::sound_fight_tag_alt_given
void sound_fight_tag_alt_given()
Definition edit_utype.cpp:418
edit_utype::gfx_tag
QLineEdit * gfx_tag
Definition edit_utype.h:53
edit_utype::req_button
QToolButton * req_button
Definition edit_utype.h:45
edit_utype::set_hitpoints
void set_hitpoints(int value)
Definition edit_utype.cpp:344
ruledit_gui
Definition ruledit_qt.h:96
tab_tech::techs_to_menu
static void techs_to_menu(QMenu *fill_menu)
Definition tab_tech.cpp:189
tab_tech::tech_name
static QString tech_name(struct advance *padv)
Definition tab_tech.cpp:201
values_dlg
Definition values_dlg.h:28
values_dlg::close_help
void close_help()
Definition values_dlg.cpp:60
values_dlg::open_help
void open_help(struct strvec **help)
Definition values_dlg.cpp:38
edit_utype.h
R__
#define R__(String)
Definition fcintl.h:75
ruledit.h
ruledit_qt.h
action
Definition actions.h:379
advance
Definition tech.h:124
unit_class
Definition unittype.h:136
unit_type
Definition unittype.h:481
unit_type::uclass
struct unit_class * uclass
Definition unittype.h:537
unit_type::defense_strength
int defense_strength
Definition unittype.h:496
unit_type::firepower
int firepower
Definition unittype.h:506
unit_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition unittype.h:487
unit_type::sound_move_alt
char sound_move_alt[MAX_LEN_NAME]
Definition unittype.h:489
unit_type::build_cost
int build_cost
Definition unittype.h:492
unit_type::move_rate
int move_rate
Definition unittype.h:497
unit_type::require_advance
struct advance * require_advance
Definition unittype.h:500
unit_type::helptext
struct strvec * helptext
Definition unittype.h:552
unit_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition unittype.h:486
unit_type::sound_move
char sound_move[MAX_LEN_NAME]
Definition unittype.h:488
unit_type::hp
int hp
Definition unittype.h:505
unit_type::sound_fight_alt
char sound_fight_alt[MAX_LEN_NAME]
Definition unittype.h:491
unit_type::flags
bv_unit_type_flags flags
Definition unittype.h:515
unit_type::sound_fight
char sound_fight[MAX_LEN_NAME]
Definition unittype.h:490
unit_type::attack_strength
int attack_strength
Definition unittype.h:495
unit_type::ruledit_dlg
void * ruledit_dlg
Definition unittype.h:485
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
tab_tech.h
advance_by_rule_name
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
utype_rule_name
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
uclass_rule_name
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693
unit_class_by_rule_name
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1836
unittype.h
unit_class_re_active_iterate_end
#define unit_class_re_active_iterate_end
Definition unittype.h:892
UTYF_LAST_USER_FLAG
#define UTYF_LAST_USER_FLAG
Definition unittype.h:315
unit_class_re_active_iterate
#define unit_class_re_active_iterate(_p)
Definition unittype.h:888