Freeciv-3.2
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/**********************************************************************/
40{
41 QHBoxLayout *main_layout = new QHBoxLayout(this);
43 QLabel *label;
44 int row = 0;
45 int rowcount;
46 int column;
47
48 ui = ui_in;
50
52
53 setWindowTitle(QString::fromUtf8(utype_rule_name(utype)));
54
55 label = new QLabel(QString::fromUtf8(R__("Build Cost")));
56 label->setParent(this);
57
58 bcost = new QSpinBox(this);
59 bcost->setRange(0, 10000);
60 connect(bcost, SIGNAL
61 (valueChanged(int)), this, SLOT(set_bcost_value(int)));
62
63 unit_layout->addWidget(label, row, 0);
64 unit_layout->addWidget(bcost, row++, 1);
65
66 label = new QLabel(QString::fromUtf8(R__("Attack Strength")));
67 label->setParent(this);
68
69 attack = new QSpinBox(this);
70 attack->setRange(0, 1000);
71 connect(attack, SIGNAL(valueChanged(int)), this, SLOT(set_attack_value(int)));
72
73 unit_layout->addWidget(label, row, 0);
74 unit_layout->addWidget(attack, row++, 1);
75
76 label = new QLabel(QString::fromUtf8(R__("Defense Strength")));
77 label->setParent(this);
78
79 defense = new QSpinBox(this);
80 defense->setRange(0, 1000);
81 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
82
83 unit_layout->addWidget(label, row, 0);
84 unit_layout->addWidget(defense, row++, 1);
85
86 label = new QLabel(QString::fromUtf8(R__("Hitpoints")));
87 label->setParent(this);
88
89 hitpoints = new QSpinBox(this);
90 hitpoints->setRange(0, 1000);
91 connect(hitpoints, SIGNAL(valueChanged(int)), this, SLOT(set_hitpoints(int)));
92
93 unit_layout->addWidget(label, row, 0);
94 unit_layout->addWidget(hitpoints, row++, 1);
95
96 label = new QLabel(QString::fromUtf8(R__("Firepower")));
97 label->setParent(this);
98
99 firepower = new QSpinBox(this);
100 firepower->setRange(0, 200);
101 connect(firepower, SIGNAL(valueChanged(int)), this, SLOT(set_firepower(int)));
102
103 unit_layout->addWidget(label, row, 0);
104 unit_layout->addWidget(firepower, row++, 1);
105
106 label = new QLabel(QString::fromUtf8(R__("Move Rate")));
107 label->setParent(this);
108
109 move_rate = new QSpinBox(this);
110 move_rate->setRange(0, 50);
111 connect(move_rate, SIGNAL(valueChanged(int)), this, SLOT(set_move_rate(int)));
112
113 unit_layout->addWidget(label, row, 0);
114 unit_layout->addWidget(move_rate, row++, 1);
115
116 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
117 label->setParent(this);
118
119 gfx_tag = new QLineEdit(this);
120 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
121
122 unit_layout->addWidget(label, row, 0);
123 unit_layout->addWidget(gfx_tag, row++, 1);
124
125 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
126 label->setParent(this);
127
128 gfx_tag_alt = new QLineEdit(this);
130
131 unit_layout->addWidget(label, row, 0);
132 unit_layout->addWidget(gfx_tag_alt, row++, 1);
133
134 label = new QLabel(QString::fromUtf8(R__("Second alt gfx tag")));
135 label->setParent(this);
136
137 gfx_tag_alt2 = new QLineEdit(this);
139
140 unit_layout->addWidget(label, row, 0);
141 unit_layout->addWidget(gfx_tag_alt2, row++, 1);
142
143 label = new QLabel(QString::fromUtf8(R__("Move sound tag")));
144 label->setParent(this);
145
146 sound_move_tag = new QLineEdit(this);
147 connect(sound_move_tag, SIGNAL(returnPressed()), this,
149
150 unit_layout->addWidget(label, row, 0);
151 unit_layout->addWidget(sound_move_tag, row++, 1);
152
153 label = new QLabel(QString::fromUtf8(R__("Alt move sound tag")));
154 label->setParent(this);
155
156 sound_move_tag_alt = new QLineEdit(this);
157 connect(sound_move_tag_alt, SIGNAL(returnPressed()), this,
159
160 unit_layout->addWidget(label, row, 0);
161 unit_layout->addWidget(sound_move_tag_alt, row++, 1);
162
163 label = new QLabel(QString::fromUtf8(R__("Fight sound tag")));
164 label->setParent(this);
165
166 sound_fight_tag = new QLineEdit(this);
167 connect(sound_fight_tag, SIGNAL(returnPressed()), this,
169
170 unit_layout->addWidget(label, row, 0);
171 unit_layout->addWidget(sound_fight_tag, row++, 1);
172
173 label = new QLabel(QString::fromUtf8(R__("Alt fight sound tag")));
174 label->setParent(this);
175
176 sound_fight_tag_alt = new QLineEdit(this);
177 connect(sound_fight_tag_alt, SIGNAL(returnPressed()), this,
179
180 unit_layout->addWidget(label, row, 0);
181 unit_layout->addWidget(sound_fight_tag_alt, row++, 1);
182
183 rowcount = 0;
184 column = 0;
185 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
186 enum unit_type_flag_id flag = (enum unit_type_flag_id)i;
187 QCheckBox *check = new QCheckBox();
188
189 label = new QLabel(unit_type_flag_id_name(flag));
190 flag_layout->addWidget(label, rowcount, column + 1);
191
192 check->setChecked(BV_ISSET(utype->flags, flag));
193 flag_layout->addWidget(check, rowcount, column);
194
195 if (++rowcount >= 25) {
196 column += 2;
197 rowcount = 0;
198 }
199 }
200
201 refresh();
202
203 main_layout->addLayout(unit_layout);
204 main_layout->addLayout(flag_layout);
205
206 setLayout(main_layout);
207}
208
209/**********************************************************************/
213{
214 int rowcount;
215 int column;
216
217 // Save values from text fields.
225
227 rowcount = 0;
228 column = 0;
229 for (int i = 0; i < UTYF_LAST_USER_FLAG; i++) {
230 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
231
232 if (check->isChecked()) {
233 BV_SET(utype->flags, i);
234 }
235
236 if (++rowcount >= 25) {
237 rowcount = 0;
238 column += 2;
239 }
240 }
241
242 utype->ruledit_dlg = nullptr;
243}
244
245/**********************************************************************/
249{
250 bcost->setValue(utype->build_cost);
251 attack->setValue(utype->attack_strength);
252 defense->setValue(utype->defense_strength);
253 hitpoints->setValue(utype->hp);
254 firepower->setValue(utype->firepower);
255 move_rate->setValue(utype->move_rate);
256 gfx_tag->setText(utype->graphic_str);
257 gfx_tag_alt->setText(utype->graphic_alt);
263}
264
265/**********************************************************************/
269{
270 utype->build_cost = value;
271}
272
273/**********************************************************************/
277{
278 utype->attack_strength = value;
279}
280
281/**********************************************************************/
285{
286 utype->defense_strength = value;
287}
288
289/**********************************************************************/
293{
294 utype->hp = value;
295}
296
297/**********************************************************************/
301{
302 utype->firepower = value;
303}
304
305/**********************************************************************/
309{
310 utype->move_rate = value;
311}
312
313/**********************************************************************/
317{
318 QByteArray tag_bytes = gfx_tag->text().toUtf8();
319
321}
322
323/**********************************************************************/
332
333/**********************************************************************/
342
343/**********************************************************************/
352
353/**********************************************************************/
362
363/**********************************************************************/
372
373/**********************************************************************/
#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:46
void set_bcost_value(int value)
QLineEdit * sound_move_tag_alt
Definition edit_utype.h:52
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:50
QSpinBox * attack
Definition edit_utype.h:43
QSpinBox * bcost
Definition edit_utype.h:42
QLineEdit * sound_fight_tag
Definition edit_utype.h:53
QLineEdit * sound_fight_tag_alt
Definition edit_utype.h:54
void gfx_tag_given()
void sound_fight_tag_given()
QLineEdit * sound_move_tag
Definition edit_utype.h:51
void refresh()
void set_firepower(int value)
ruledit_gui * ui
Definition edit_utype.h:40
void closeEvent(QCloseEvent *cevent)
QSpinBox * defense
Definition edit_utype.h:44
QSpinBox * move_rate
Definition edit_utype.h:47
void set_move_rate(int value)
QSpinBox * hitpoints
Definition edit_utype.h:45
void sound_move_tag_alt_given()
QLineEdit * gfx_tag_alt
Definition edit_utype.h:49
QGridLayout * flag_layout
Definition edit_utype.h:56
void gfx_tag_alt_given()
struct unit_type * utype
Definition edit_utype.h:41
void sound_fight_tag_alt_given()
QLineEdit * gfx_tag
Definition edit_utype.h:48
void set_hitpoints(int value)
char * incite_cost
Definition comments.c:74
#define R__(String)
Definition fcintl.h:75
int defense_strength
Definition unittype.h:516
int firepower
Definition unittype.h:525
char graphic_alt[MAX_LEN_NAME]
Definition unittype.h:506
char sound_move_alt[MAX_LEN_NAME]
Definition unittype.h:509
int build_cost
Definition unittype.h:512
int move_rate
Definition unittype.h:517
char graphic_str[MAX_LEN_NAME]
Definition unittype.h:505
char sound_move[MAX_LEN_NAME]
Definition unittype.h:508
char sound_fight_alt[MAX_LEN_NAME]
Definition unittype.h:511
char graphic_alt2[MAX_LEN_NAME]
Definition unittype.h:507
bv_unit_type_flags flags
Definition unittype.h:534
char sound_fight[MAX_LEN_NAME]
Definition unittype.h:510
int attack_strength
Definition unittype.h:515
void * ruledit_dlg
Definition unittype.h:504
#define sz_strlcpy(dest, src)
Definition support.h:189
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
#define UTYF_LAST_USER_FLAG
Definition unittype.h:331