Freeciv-3.3
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);
44 QLabel *label;
45 QPushButton *button;
46 QMenu *menu;
47 int row = 0;
48 int rowcount;
49 int column;
50
51 ui = ui_in;
53
55
56 setWindowTitle(QString::fromUtf8(utype_rule_name(utype)));
57
58 label = new QLabel(QString::fromUtf8(R__("Class")));
59 label->setParent(this);
61 class_button->setParent(this);
62 class_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
63 class_button->setPopupMode(QToolButton::MenuButtonPopup);
64 menu = new QMenu();
65 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(class_menu(QAction *)));
66
68 menu->addAction(uclass_rule_name(pclass));
70
71 class_button->setMenu(menu);
72
73 unit_layout->addWidget(label, row, 0);
74 unit_layout->addWidget(class_button, row++, 1);
75
76 label = new QLabel(QString::fromUtf8(R__("Build Cost")));
77 label->setParent(this);
78
79 bcost = new QSpinBox(this);
80 bcost->setRange(0, 10000);
81 connect(bcost, SIGNAL
82 (valueChanged(int)), this, SLOT(set_bcost_value(int)));
83
84 unit_layout->addWidget(label, row, 0);
85 unit_layout->addWidget(bcost, row++, 1);
86
87 label = new QLabel(QString::fromUtf8(R__("Attack Strength")));
88 label->setParent(this);
89
90 attack = new QSpinBox(this);
91 attack->setRange(0, 1000);
92 connect(attack, SIGNAL(valueChanged(int)), this, SLOT(set_attack_value(int)));
93
94 unit_layout->addWidget(label, row, 0);
95 unit_layout->addWidget(attack, row++, 1);
96
97 label = new QLabel(QString::fromUtf8(R__("Defense Strength")));
98 label->setParent(this);
99
100 defense = new QSpinBox(this);
101 defense->setRange(0, 1000);
102 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
103
104 unit_layout->addWidget(label, row, 0);
105 unit_layout->addWidget(defense, row++, 1);
106
107 label = new QLabel(QString::fromUtf8(R__("Hitpoints")));
108 label->setParent(this);
109
110 hitpoints = new QSpinBox(this);
111 hitpoints->setRange(0, 1000);
112 connect(hitpoints, SIGNAL(valueChanged(int)), this, SLOT(set_hitpoints(int)));
113
114 unit_layout->addWidget(label, row, 0);
115 unit_layout->addWidget(hitpoints, row++, 1);
116
117 label = new QLabel(QString::fromUtf8(R__("Firepower")));
118 label->setParent(this);
119
120 firepower = new QSpinBox(this);
121 firepower->setRange(0, 200);
122 connect(firepower, SIGNAL(valueChanged(int)), this, SLOT(set_firepower(int)));
123
124 unit_layout->addWidget(label, row, 0);
125 unit_layout->addWidget(firepower, row++, 1);
126
127 label = new QLabel(QString::fromUtf8(R__("Move Rate")));
128 label->setParent(this);
129
130 move_rate = new QSpinBox(this);
131 move_rate->setRange(0, 50);
132 connect(move_rate, SIGNAL(valueChanged(int)), this, SLOT(set_move_rate(int)));
133
134 unit_layout->addWidget(label, row, 0);
135 unit_layout->addWidget(move_rate, row++, 1);
136
137 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
138 label->setParent(this);
139
140 gfx_tag = new QLineEdit(this);
141 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
142
143 unit_layout->addWidget(label, row, 0);
144 unit_layout->addWidget(gfx_tag, row++, 1);
145
146 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
147 label->setParent(this);
148
149 gfx_tag_alt = new QLineEdit(this);
151
152 unit_layout->addWidget(label, row, 0);
153 unit_layout->addWidget(gfx_tag_alt, row++, 1);
154
155 label = new QLabel(QString::fromUtf8(R__("Second alt gfx tag")));
156 label->setParent(this);
157
158 gfx_tag_alt2 = new QLineEdit(this);
160
161 unit_layout->addWidget(label, row, 0);
162 unit_layout->addWidget(gfx_tag_alt2, row++, 1);
163
164 label = new QLabel(QString::fromUtf8(R__("Move sound tag")));
165 label->setParent(this);
166
167 sound_move_tag = new QLineEdit(this);
168 connect(sound_move_tag, SIGNAL(returnPressed()), this,
170
171 unit_layout->addWidget(label, row, 0);
172 unit_layout->addWidget(sound_move_tag, row++, 1);
173
174 label = new QLabel(QString::fromUtf8(R__("Alt move sound tag")));
175 label->setParent(this);
176
177 sound_move_tag_alt = new QLineEdit(this);
178 connect(sound_move_tag_alt, SIGNAL(returnPressed()), this,
180
181 unit_layout->addWidget(label, row, 0);
182 unit_layout->addWidget(sound_move_tag_alt, row++, 1);
183
184 label = new QLabel(QString::fromUtf8(R__("Fight sound tag")));
185 label->setParent(this);
186
187 sound_fight_tag = new QLineEdit(this);
188 connect(sound_fight_tag, SIGNAL(returnPressed()), this,
190
191 unit_layout->addWidget(label, row, 0);
192 unit_layout->addWidget(sound_fight_tag, row++, 1);
193
194 label = new QLabel(QString::fromUtf8(R__("Alt fight sound tag")));
195 label->setParent(this);
196
197 sound_fight_tag_alt = new QLineEdit(this);
198 connect(sound_fight_tag_alt, SIGNAL(returnPressed()), this,
200
201 unit_layout->addWidget(label, row, 0);
202 unit_layout->addWidget(sound_fight_tag_alt, row++, 1);
203
204 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
205 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
206 unit_layout->addWidget(button, row++, 1);
207
208 rowcount = 0;
209 column = 0;
210 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
211 enum unit_type_flag_id flag = (enum unit_type_flag_id)i;
212 QCheckBox *check = new QCheckBox();
213
214 label = new QLabel(unit_type_flag_id_name(flag));
215 flag_layout->addWidget(label, rowcount, column + 1);
216
217 check->setChecked(BV_ISSET(utype->flags, flag));
218 flag_layout->addWidget(check, rowcount, column);
219
220 if (++rowcount >= 25) {
221 column += 2;
222 rowcount = 0;
223 }
224 }
225
226 refresh();
227
228 main_layout->addLayout(unit_layout);
229 main_layout->addLayout(flag_layout);
230
231 setLayout(main_layout);
232}
233
234/**********************************************************************/
238{
239 int rowcount;
240 int column;
241
242 close_help();
243
244 // Save values from text fields.
252
254 rowcount = 0;
255 column = 0;
256 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
257 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
258
259 if (check->isChecked()) {
260 BV_SET(utype->flags, i);
261 }
262
263 if (++rowcount >= 25) {
264 rowcount = 0;
265 column += 2;
266 }
267 }
268
269 utype->ruledit_dlg = nullptr;
270}
271
272/**********************************************************************/
276{
278 bcost->setValue(utype->build_cost);
279 attack->setValue(utype->attack_strength);
280 defense->setValue(utype->defense_strength);
281 hitpoints->setValue(utype->hp);
282 firepower->setValue(utype->firepower);
283 move_rate->setValue(utype->move_rate);
284 gfx_tag->setText(utype->graphic_str);
285 gfx_tag_alt->setText(utype->graphic_alt);
291}
292
293/**********************************************************************/
297{
298 utype->build_cost = value;
299}
300
301/**********************************************************************/
305{
306 utype->attack_strength = value;
307}
308
309/**********************************************************************/
313{
314 utype->defense_strength = value;
315}
316
317/**********************************************************************/
321{
322 utype->hp = value;
323}
324
325/**********************************************************************/
329{
330 utype->firepower = value;
331}
332
333/**********************************************************************/
337{
338 utype->move_rate = value;
339}
340
341/**********************************************************************/
345{
346 QByteArray tag_bytes = gfx_tag->text().toUtf8();
347
349}
350
351/**********************************************************************/
360
361/**********************************************************************/
370
371/**********************************************************************/
380
381/**********************************************************************/
390
391/**********************************************************************/
400
401/**********************************************************************/
410
411/**********************************************************************/
415{
417 struct unit_class *pclass;
418
419 cn_bytes = action->text().toUtf8();
421
423
424 refresh();
425}
426
427/**********************************************************************/
#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:50
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 gfx_tag_alt2_given()
void set_attack_value(int value)
QLineEdit * gfx_tag_alt2
Definition edit_utype.h:54
QSpinBox * attack
Definition edit_utype.h:47
QSpinBox * bcost
Definition edit_utype.h:46
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:45
void closeEvent(QCloseEvent *cevent)
void helptext()
QSpinBox * defense
Definition edit_utype.h:48
QSpinBox * move_rate
Definition edit_utype.h:51
void set_move_rate(int value)
QSpinBox * hitpoints
Definition edit_utype.h:49
void sound_move_tag_alt_given()
QLineEdit * gfx_tag_alt
Definition edit_utype.h:53
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:52
void set_hitpoints(int value)
void close_help()
void open_help(struct strvec **help)
char * incite_cost
Definition comments.c:74
#define R__(String)
Definition fcintl.h:75
struct unit_class * uclass
Definition unittype.h:563
int defense_strength
Definition unittype.h:523
int firepower
Definition unittype.h:532
char graphic_alt[MAX_LEN_NAME]
Definition unittype.h:513
char sound_move_alt[MAX_LEN_NAME]
Definition unittype.h:516
int build_cost
Definition unittype.h:519
int move_rate
Definition unittype.h:524
struct strvec * helptext
Definition unittype.h:578
char graphic_str[MAX_LEN_NAME]
Definition unittype.h:512
char sound_move[MAX_LEN_NAME]
Definition unittype.h:515
char sound_fight_alt[MAX_LEN_NAME]
Definition unittype.h:518
char graphic_alt2[MAX_LEN_NAME]
Definition unittype.h:514
bv_unit_type_flags flags
Definition unittype.h:541
char sound_fight[MAX_LEN_NAME]
Definition unittype.h:517
int attack_strength
Definition unittype.h:522
void * ruledit_dlg
Definition unittype.h:511
#define sz_strlcpy(dest, src)
Definition support.h:189
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1784
#define unit_class_re_active_iterate_end
Definition unittype.h:928
#define UTYF_LAST_USER_FLAG
Definition unittype.h:337
#define unit_class_re_active_iterate(_p)
Definition unittype.h:924