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 <QSpinBox>
24#include <QToolButton>
25
26// common
27#include "unittype.h"
28
29// ruledit
30#include "ruledit.h"
31#include "ruledit_qt.h"
32#include "tab_tech.h"
33
34#include "edit_utype.h"
35
36/**********************************************************************/
39edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in) : QDialog()
40{
41 QHBoxLayout *main_layout = new QHBoxLayout(this);
42 QGridLayout *unit_layout = new QGridLayout();
43 QLabel *label;
44 QMenu *req;
45 int row = 0;
46 int rowcount;
47 int column;
48
49 ui = ui_in;
50 utype = utype_in;
51
52 flag_layout = new QGridLayout();
53
54 setWindowTitle(QString::fromUtf8(utype_rule_name(utype)));
55
56 label = new QLabel(QString::fromUtf8(R__("Requirement")));
57 label->setParent(this);
58
59 req = new QMenu();
60 req_button = new QToolButton();
61 req_button->setParent(this);
62 req_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
63 req_button->setPopupMode(QToolButton::MenuButtonPopup);
64 req_button->setMenu(req);
65 tab_tech::techs_to_menu(req);
66 connect(req_button, SIGNAL(triggered(QAction *)), this, SLOT(req_menu(QAction *)));
67
68 unit_layout->addWidget(label, row, 0);
69 unit_layout->addWidget(req_button, row++, 1);
70
71 label = new QLabel(QString::fromUtf8(R__("Build Cost")));
72 label->setParent(this);
73
74 bcost = new QSpinBox(this);
75 bcost->setRange(0, 10000);
76 connect(bcost, SIGNAL
77 (valueChanged(int)), this, SLOT(set_bcost_value(int)));
78
79 unit_layout->addWidget(label, row, 0);
80 unit_layout->addWidget(bcost, row++, 1);
81
82 label = new QLabel(QString::fromUtf8(R__("Attack Strength")));
83 label->setParent(this);
84
85 attack = new QSpinBox(this);
86 attack->setRange(0, 1000);
87 connect(attack, SIGNAL(valueChanged(int)), this, SLOT(set_attack_value(int)));
88
89 unit_layout->addWidget(label, row, 0);
90 unit_layout->addWidget(attack, row++, 1);
91
92 label = new QLabel(QString::fromUtf8(R__("Defense Strength")));
93 label->setParent(this);
94
95 defense = new QSpinBox(this);
96 defense->setRange(0, 1000);
97 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
98
99 unit_layout->addWidget(label, row, 0);
100 unit_layout->addWidget(defense, row++, 1);
101
102 label = new QLabel(QString::fromUtf8(R__("Hitpoints")));
103 label->setParent(this);
104
105 hitpoints = new QSpinBox(this);
106 hitpoints->setRange(0, 1000);
107 connect(hitpoints, SIGNAL(valueChanged(int)), this, SLOT(set_hitpoints(int)));
108
109 unit_layout->addWidget(label, row, 0);
110 unit_layout->addWidget(hitpoints, row++, 1);
111
112 label = new QLabel(QString::fromUtf8(R__("Firepower")));
113 label->setParent(this);
114
115 firepower = new QSpinBox(this);
116 firepower->setRange(0, 200);
117 connect(firepower, SIGNAL(valueChanged(int)), this, SLOT(set_firepower(int)));
118
119 unit_layout->addWidget(label, row, 0);
120 unit_layout->addWidget(firepower, row++, 1);
121
122 label = new QLabel(QString::fromUtf8(R__("Move Rate")));
123 label->setParent(this);
124
125 move_rate = new QSpinBox(this);
126 move_rate->setRange(0, 50);
127 connect(move_rate, SIGNAL(valueChanged(int)), this, SLOT(set_move_rate(int)));
128
129 unit_layout->addWidget(label, row, 0);
130 unit_layout->addWidget(move_rate, row++, 1);
131
132 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
133 label->setParent(this);
134
135 gfx_tag = new QLineEdit(this);
136 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
137
138 unit_layout->addWidget(label, row, 0);
139 unit_layout->addWidget(gfx_tag, row++, 1);
140
141 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
142 label->setParent(this);
143
144 gfx_tag_alt = new QLineEdit(this);
145 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
146
147 unit_layout->addWidget(label, row, 0);
148 unit_layout->addWidget(gfx_tag_alt, row++, 1);
149
150 label = new QLabel(QString::fromUtf8(R__("Move sound tag")));
151 label->setParent(this);
152
153 sound_move_tag = new QLineEdit(this);
154 connect(sound_move_tag, SIGNAL(returnPressed()), this,
155 SLOT(sound_move_tag_given()));
156
157 unit_layout->addWidget(label, row, 0);
158 unit_layout->addWidget(sound_move_tag, row++, 1);
159
160 label = new QLabel(QString::fromUtf8(R__("Alt move sound tag")));
161 label->setParent(this);
162
163 sound_move_tag_alt = new QLineEdit(this);
164 connect(sound_move_tag_alt, SIGNAL(returnPressed()), this,
165 SLOT(sound_move_tag_alt_given()));
166
167 unit_layout->addWidget(label, row, 0);
168 unit_layout->addWidget(sound_move_tag_alt, row++, 1);
169
170 label = new QLabel(QString::fromUtf8(R__("Fight sound tag")));
171 label->setParent(this);
172
173 sound_fight_tag = new QLineEdit(this);
174 connect(sound_fight_tag, SIGNAL(returnPressed()), this,
175 SLOT(sound_fight_tag_given()));
176
177 unit_layout->addWidget(label, row, 0);
178 unit_layout->addWidget(sound_fight_tag, row++, 1);
179
180 label = new QLabel(QString::fromUtf8(R__("Alt fight sound tag")));
181 label->setParent(this);
182
183 sound_fight_tag_alt = new QLineEdit(this);
184 connect(sound_fight_tag_alt, SIGNAL(returnPressed()), this,
185 SLOT(sound_fight_tag_alt_given()));
186
187 unit_layout->addWidget(label, row, 0);
188 unit_layout->addWidget(sound_fight_tag_alt, row++, 1);
189
190 rowcount = 0;
191 column = 0;
192 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
193 enum unit_type_flag_id flag = (enum unit_type_flag_id)i;
194 QCheckBox *check = new QCheckBox();
195
196 label = new QLabel(unit_type_flag_id_name(flag));
197 flag_layout->addWidget(label, rowcount, column + 1);
198
199 check->setChecked(BV_ISSET(utype->flags, flag));
200 flag_layout->addWidget(check, rowcount, column);
201
202 if (++rowcount >= 25) {
203 column += 2;
204 rowcount = 0;
205 }
206 }
207
208 refresh();
209
210 main_layout->addLayout(unit_layout);
211 main_layout->addLayout(flag_layout);
212
213 setLayout(main_layout);
214}
215
216/**********************************************************************/
219 void edit_utype::closeEvent(QCloseEvent *cevent)
220{
221 int rowcount;
222 int column;
223
224 // Save values from text fields.
225 gfx_tag_given();
226 gfx_tag_alt_given();
227 sound_move_tag_given();
228 sound_move_tag_alt_given();
229 sound_fight_tag_given();
230 sound_fight_tag_alt_given();
231
232 BV_CLR_ALL(utype->flags);
233 rowcount = 0;
234 column = 0;
235 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
236 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
237
238 if (check->isChecked()) {
239 BV_SET(utype->flags, i);
240 }
241
242 if (++rowcount >= 25) {
243 rowcount = 0;
244 column += 2;
245 }
246 }
247
248 utype->ruledit_dlg = nullptr;
249}
250
251/**********************************************************************/
254 void edit_utype::refresh()
255{
256 req_button->setText(tab_tech::tech_name(utype->require_advance));
257 bcost->setValue(utype->build_cost);
258 attack->setValue(utype->attack_strength);
259 defense->setValue(utype->defense_strength);
260 hitpoints->setValue(utype->hp);
261 firepower->setValue(utype->firepower);
262 move_rate->setValue(utype->move_rate);
263 gfx_tag->setText(utype->graphic_str);
264 gfx_tag_alt->setText(utype->graphic_alt);
265 sound_move_tag->setText(utype->sound_move);
266 sound_move_tag_alt->setText(utype->sound_move_alt);
267 sound_fight_tag->setText(utype->sound_fight);
268 sound_fight_tag_alt->setText(utype->sound_fight_alt);
269}
270
271/**********************************************************************/
274 void edit_utype::req_menu(QAction *action)
275{
276 struct advance *padv;
277 QByteArray an_bytes;
278
279 an_bytes = action->text().toUtf8();
280 padv = advance_by_rule_name(an_bytes.data());
281
282 if (padv != nullptr) {
283 utype->require_advance = padv;
284
285 refresh();
286 }
287}
288
289/**********************************************************************/
292 void edit_utype::set_bcost_value(int value)
293{
294 utype->build_cost = value;
295}
296
297/**********************************************************************/
300 void edit_utype::set_attack_value(int value)
301{
302 utype->attack_strength = value;
303}
304
305/**********************************************************************/
308 void edit_utype::set_defense_value(int value)
309{
310 utype->defense_strength = value;
311}
312
313/**********************************************************************/
316 void edit_utype::set_hitpoints(int value)
317{
318 utype->hp = value;
319}
320
321/**********************************************************************/
324 void edit_utype::set_firepower(int value)
325{
326 utype->firepower = value;
327}
328
329/**********************************************************************/
332 void edit_utype::set_move_rate(int value)
333{
334 utype->move_rate = value;
335}
336
337/**********************************************************************/
340 void edit_utype::gfx_tag_given()
341{
342 QByteArray tag_bytes = gfx_tag->text().toUtf8();
343
344 sz_strlcpy(utype->graphic_str, tag_bytes);
345}
346
347/**********************************************************************/
350 void edit_utype::gfx_tag_alt_given()
351{
352 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
353
354 sz_strlcpy(utype->graphic_alt, tag_bytes);
355}
356
357/**********************************************************************/
360 void edit_utype::sound_move_tag_given()
361{
362 QByteArray tag_bytes = sound_move_tag->text().toUtf8();
363
364 sz_strlcpy(utype->sound_move, tag_bytes);
365}
366
367/**********************************************************************/
370 void edit_utype::sound_move_tag_alt_given()
371{
372 QByteArray tag_bytes = sound_move_tag_alt->text().toUtf8();
373
374 sz_strlcpy(utype->sound_move_alt, tag_bytes);
375}
376
377/**********************************************************************/
380 void edit_utype::sound_fight_tag_given()
381{
382 QByteArray tag_bytes = sound_fight_tag->text().toUtf8();
383
384 sz_strlcpy(utype->sound_fight, tag_bytes);
385}
386
387/**********************************************************************/
390 void edit_utype::sound_fight_tag_alt_given()
391{
392 QByteArray tag_bytes = sound_fight_tag_alt->text().toUtf8();
393
394 sz_strlcpy(utype->sound_fight_alt, tag_bytes);
395}
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:47
edit_utype::set_bcost_value
void set_bcost_value(int value)
Definition edit_utype.cpp:292
edit_utype::sound_move_tag_alt
QLineEdit * sound_move_tag_alt
Definition edit_utype.h:52
edit_utype::edit_utype
edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in)
Definition edit_utype.cpp:39
edit_utype::sound_move_tag_given
void sound_move_tag_given()
Definition edit_utype.cpp:360
edit_utype::set_defense_value
void set_defense_value(int value)
Definition edit_utype.cpp:308
edit_utype::set_attack_value
void set_attack_value(int value)
Definition edit_utype.cpp:300
edit_utype::attack
QSpinBox * attack
Definition edit_utype.h:44
edit_utype::bcost
QSpinBox * bcost
Definition edit_utype.h:43
edit_utype::sound_fight_tag
QLineEdit * sound_fight_tag
Definition edit_utype.h:53
edit_utype::sound_fight_tag_alt
QLineEdit * sound_fight_tag_alt
Definition edit_utype.h:54
edit_utype::gfx_tag_given
void gfx_tag_given()
Definition edit_utype.cpp:340
edit_utype::sound_fight_tag_given
void sound_fight_tag_given()
Definition edit_utype.cpp:380
edit_utype::sound_move_tag
QLineEdit * sound_move_tag
Definition edit_utype.h:51
edit_utype::refresh
void refresh()
Definition edit_utype.cpp:254
edit_utype::set_firepower
void set_firepower(int value)
Definition edit_utype.cpp:324
edit_utype::ui
ruledit_gui * ui
Definition edit_utype.h:40
edit_utype::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_utype.cpp:219
edit_utype::defense
QSpinBox * defense
Definition edit_utype.h:45
edit_utype::move_rate
QSpinBox * move_rate
Definition edit_utype.h:48
edit_utype::set_move_rate
void set_move_rate(int value)
Definition edit_utype.cpp:332
edit_utype::hitpoints
QSpinBox * hitpoints
Definition edit_utype.h:46
edit_utype::req_menu
void req_menu(QAction *action)
Definition edit_utype.cpp:274
edit_utype::sound_move_tag_alt_given
void sound_move_tag_alt_given()
Definition edit_utype.cpp:370
edit_utype::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_utype.h:50
edit_utype::flag_layout
QGridLayout * flag_layout
Definition edit_utype.h:56
edit_utype::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_utype.cpp:350
edit_utype::utype
struct unit_type * utype
Definition edit_utype.h:41
edit_utype::sound_fight_tag_alt_given
void sound_fight_tag_alt_given()
Definition edit_utype.cpp:390
edit_utype::gfx_tag
QLineEdit * gfx_tag
Definition edit_utype.h:49
edit_utype::req_button
QToolButton * req_button
Definition edit_utype.h:42
edit_utype::set_hitpoints
void set_hitpoints(int value)
Definition edit_utype.cpp:316
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
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_type
Definition unittype.h:481
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::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
unittype.h
UTYF_LAST_USER_FLAG
#define UTYF_LAST_USER_FLAG
Definition unittype.h:315