Freeciv-3.2
Loading...
Searching...
No Matches
edit_extra.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2023 The Freeciv Team
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 <QToolButton>
23
24// common
25#include "extras.h"
26#include "game.h"
27
28// ruledit
29#include "ruledit.h"
30#include "ruledit_qt.h"
31
32#include "edit_extra.h"
33
34
35#define FLAGROWS 15
36
37/**********************************************************************/
41 : QDialog()
42{
43 QHBoxLayout *main_layout = new QHBoxLayout(this);
45 QLabel *label;
46 int row = 0;
47 int rowcount;
48 int column;
49
50 ui = ui_in;
52
55
56 setWindowTitle(QString::fromUtf8(extra_rule_name(extra)));
57
58 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
59 label->setParent(this);
60
61 gfx_tag = new QLineEdit(this);
62 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
63
64 extra_layout->addWidget(label, row, 0);
65 extra_layout->addWidget(gfx_tag, row++, 1);
66
67 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
68 label->setParent(this);
69
70 gfx_tag_alt = new QLineEdit(this);
72
73 extra_layout->addWidget(label, row, 0);
74 extra_layout->addWidget(gfx_tag_alt, row++, 1);
75
76 label = new QLabel(QString::fromUtf8(R__("Activity graphics tag")));
77 label->setParent(this);
78
79 act_gfx = new QLineEdit(this);
80 connect(act_gfx, SIGNAL(returnPressed()), this, SLOT(act_gfx_given()));
81
82 extra_layout->addWidget(label, row, 0);
83 extra_layout->addWidget(act_gfx, row++, 1);
84
85 label = new QLabel(QString::fromUtf8(R__("Alt activity gfx tag")));
86 label->setParent(this);
87
88 act_gfx_alt = new QLineEdit(this);
90
91 extra_layout->addWidget(label, row, 0);
92 extra_layout->addWidget(act_gfx_alt, row++, 1);
93
94 label = new QLabel(QString::fromUtf8(R__("Second alt activity gfx tag")));
95 label->setParent(this);
96
97 act_gfx_alt2 = new QLineEdit(this);
99
100 extra_layout->addWidget(label, row, 0);
101 extra_layout->addWidget(act_gfx_alt2, row++, 1);
102
103 label = new QLabel(QString::fromUtf8(R__("Removal activity graphics tag")));
104 label->setParent(this);
105
106 rmact_gfx = new QLineEdit(this);
107 connect(rmact_gfx, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_given()));
108
109 extra_layout->addWidget(label, row, 0);
110 extra_layout->addWidget(rmact_gfx, row++, 1);
111
112 label = new QLabel(QString::fromUtf8(R__("Alt removal activity gfx tag")));
113 label->setParent(this);
114
115 rmact_gfx_alt = new QLineEdit(this);
117
118 extra_layout->addWidget(label, row, 0);
119 extra_layout->addWidget(rmact_gfx_alt, row++, 1);
120
121 label = new QLabel(QString::fromUtf8(R__("Second alt removal activity gfx tag")));
122 label->setParent(this);
123
124 rmact_gfx_alt2 = new QLineEdit(this);
126
127 extra_layout->addWidget(label, row, 0);
128 extra_layout->addWidget(rmact_gfx_alt2, row++, 1);
129
130 label = new QLabel(QString::fromUtf8(R__("Native to")));
131 natives_layout->addWidget(label, 0, 0);
132 for (int i = 0; i < game.control.num_unit_classes; i++) {
133 QCheckBox *check = new QCheckBox();
134
135 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
136 natives_layout->addWidget(label, i + 1, 0);
137
138 check->setChecked(BV_ISSET(extra->native_to, i));
139 natives_layout->addWidget(check, i + 1, 1);
140 }
141
142 rowcount = 0;
143 column = 0;
144 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
145 enum extra_flag_id flag = (enum extra_flag_id)i;
146 QCheckBox *check = new QCheckBox();
147
148 label = new QLabel(extra_flag_id_name(flag));
149 flag_layout->addWidget(label, rowcount, column + 1);
150
151 check->setChecked(BV_ISSET(extra->flags, flag));
152 flag_layout->addWidget(check, rowcount, column);
153
154 if (++rowcount >= FLAGROWS) {
155 column += 2;
156 rowcount = 0;
157 }
158 }
159
160 refresh();
161
162 main_layout->addLayout(extra_layout);
163 main_layout->addLayout(natives_layout);
164 main_layout->addLayout(flag_layout);
165
166 setLayout(main_layout);
167}
168
169/**********************************************************************/
173{
174 int rowcount;
175 int column;
176
177 // Save values from text fields.
186
188 for (int i = 0; i < game.control.num_unit_classes; i++) {
189 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
190
191 if (check->isChecked()) {
193 }
194 }
195
197 rowcount = 0;
198 column = 0;
199 for (int i = 0; i < EF_LAST_USER_FLAG; i++) {
200 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
201
202 if (check->isChecked()) {
203 BV_SET(extra->flags, i);
204 }
205
206 if (++rowcount >= FLAGROWS) {
207 rowcount = 0;
208 column += 2;
209 }
210 }
211
212 extra->ruledit_dlg = nullptr;
213}
214
215/**********************************************************************/
219{
220 gfx_tag->setText(extra->graphic_str);
221 gfx_tag_alt->setText(extra->graphic_alt);
222 act_gfx->setText(extra->activity_gfx);
223 act_gfx_alt->setText(extra->act_gfx_alt);
225 rmact_gfx->setText(extra->rmact_gfx);
228}
229
230/**********************************************************************/
234{
235 QByteArray tag_bytes = gfx_tag->text().toUtf8();
236
238}
239
240/**********************************************************************/
249
250/**********************************************************************/
259
260/**********************************************************************/
269
270/**********************************************************************/
279
280/**********************************************************************/
289
290/**********************************************************************/
299
300/**********************************************************************/
#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
void rmact_gfx_alt2_given()
edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in)
QGridLayout * flag_layout
Definition edit_extra.h:51
void rmact_gfx_given()
void act_gfx_alt2_given()
void refresh()
QLineEdit * act_gfx_alt2
Definition edit_extra.h:45
void gfx_tag_alt_given()
void closeEvent(QCloseEvent *cevent)
void rmact_gfx_alt_given()
QLineEdit * rmact_gfx_alt2
Definition edit_extra.h:48
QLineEdit * gfx_tag
Definition edit_extra.h:41
struct extra_type * extra
Definition edit_extra.h:40
QLineEdit * gfx_tag_alt
Definition edit_extra.h:42
QLineEdit * rmact_gfx
Definition edit_extra.h:46
QLineEdit * rmact_gfx_alt
Definition edit_extra.h:47
QLineEdit * act_gfx
Definition edit_extra.h:43
QGridLayout * natives_layout
Definition edit_extra.h:50
ruledit_gui * ui
Definition edit_extra.h:39
void act_gfx_given()
void gfx_tag_given()
QLineEdit * act_gfx_alt
Definition edit_extra.h:44
void act_gfx_alt_given()
char * incite_cost
Definition comments.c:74
#define FLAGROWS
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
#define EF_LAST_USER_FLAG
Definition extras.h:82
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
struct packet_ruleset_control control
Definition game.h:83
bv_unit_classes native_to
Definition extras.h:130
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:102
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
bv_extra_flags flags
Definition extras.h:132
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:103
char rmact_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:104
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:98
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:99
void * ruledit_dlg
Definition extras.h:92
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:101
char graphic_str[MAX_LEN_NAME]
Definition extras.h:97
#define sz_strlcpy(dest, src)
Definition support.h:189
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2476
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641