Freeciv-3.1
Loading...
Searching...
No Matches
tab_building.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 <QListWidget>
23#include <QMenu>
24#include <QPushButton>
25#include <QToolButton>
26
27// utility
28#include "fcintl.h"
29#include "log.h"
30
31// common
32#include "game.h"
33#include "improvement.h"
34
35// ruledit
36#include "edit_impr.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_building.h"
42
43/**********************************************************************/
47{
48 QVBoxLayout *main_layout = new QVBoxLayout(this);
49 QGridLayout *bldg_layout = new QGridLayout();
50 QLabel *label;
51 QPushButton *add_button;
52 QPushButton *delete_button;
53 QPushButton *reqs_button;
54 QPushButton *effects_button;
55 QPushButton *edit_button;
56
57 ui = ui_in;
58 selected = 0;
59
60 bldg_list = new QListWidget(this);
61
62 connect(bldg_list, SIGNAL(itemSelectionChanged()), this, SLOT(select_bldg()));
63 main_layout->addWidget(bldg_list);
64
65 bldg_layout->setSizeConstraint(QLayout::SetMaximumSize);
66
67 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
68 label->setParent(this);
69 rname = new QLineEdit(this);
70 rname->setText(R__("None"));
71 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
72 bldg_layout->addWidget(label, 0, 0);
73 bldg_layout->addWidget(rname, 0, 2);
74
75 label = new QLabel(QString::fromUtf8(R__("Name")));
76 label->setParent(this);
77 same_name = new QCheckBox();
78 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
79 name = new QLineEdit(this);
80 name->setText(R__("None"));
81 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
82 bldg_layout->addWidget(label, 1, 0);
83 bldg_layout->addWidget(same_name, 1, 1);
84 bldg_layout->addWidget(name, 1, 2);
85
86 edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this);
87 connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now()));
88 bldg_layout->addWidget(edit_button, 2, 2);
89
90 reqs_button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
91 connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
92 bldg_layout->addWidget(reqs_button, 3, 2);
93
94 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
95 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
96 bldg_layout->addWidget(effects_button, 4, 2);
97
98 add_button = new QPushButton(QString::fromUtf8(R__("Add Building")), this);
99 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now2()));
100 bldg_layout->addWidget(add_button, 5, 0);
101 show_experimental(add_button);
102
103 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Building")), this);
104 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
105 bldg_layout->addWidget(delete_button, 5, 2);
106 show_experimental(delete_button);
107
108 refresh();
109 update_bldg_info(nullptr);
110
111 main_layout->addLayout(bldg_layout);
112
113 setLayout(main_layout);
114}
115
116/**********************************************************************/
120{
121 bldg_list->clear();
122
124 QListWidgetItem *item = new QListWidgetItem(improvement_rule_name(pimpr));
125
126 bldg_list->insertItem(improvement_index(pimpr), item);
128}
129
130/**********************************************************************/
134{
135 selected = pimpr;
136
137 if (selected != 0) {
138 QString dispn = QString::fromUtf8(untranslated_name(&(pimpr->name)));
139 QString rulen = QString::fromUtf8(improvement_rule_name(pimpr));
140
141 name->setText(dispn);
142 rname->setText(rulen);
143 if (dispn == rulen) {
144 name->setEnabled(false);
145 same_name->setChecked(true);
146 } else {
147 same_name->setChecked(false);
148 name->setEnabled(true);
149 }
150 } else {
151 name->setText(R__("None"));
152 rname->setText(R__("None"));
153 same_name->setChecked(true);
154 name->setEnabled(false);
155 }
156}
157
158/**********************************************************************/
162{
163 QList<QListWidgetItem *> select_list = bldg_list->selectedItems();
164
165 if (!select_list.isEmpty()) {
166 QByteArray bn_bytes;
167
168 bn_bytes = select_list.at(0)->text().toUtf8();
170 }
171}
172
173/**********************************************************************/
177{
178 if (selected != nullptr) {
179 QByteArray name_bytes;
180 QByteArray rname_bytes;
181
182 improvement_iterate(pimpr) {
183 if (pimpr != selected && !pimpr->ruledit_disabled) {
184 rname_bytes = rname->text().toUtf8();
185 if (!strcmp(improvement_rule_name(pimpr), rname_bytes.data())) {
186 ui->display_msg(R__("A building with that rule name already "
187 "exists!"));
188 return;
189 }
190 }
192
193 if (same_name->isChecked()) {
194 name->setText(rname->text());
195 }
196
197 name_bytes = name->text().toUtf8();
198 rname_bytes = rname->text().toUtf8();
199 names_set(&(selected->name), 0,
200 name_bytes.data(),
201 rname_bytes.data());
202 refresh();
203 }
204}
205
206/**********************************************************************/
210{
211 if (selected != nullptr) {
212 requirers_dlg *requirers;
213
216 return;
217 }
218
220
221 if (selected->ruledit_dlg != nullptr) {
222 ((edit_impr *)selected->ruledit_dlg)->done(0);
223 }
224
225 refresh();
226 update_bldg_info(nullptr);
227 }
228}
229
230/**********************************************************************/
234{
235 if (improvement_by_rule_name("New Building") != nullptr) {
236 return false;
237 }
238
239 name_set(&(pimpr->name), 0, "New Building");
240 BV_CLR_ALL(pimpr->flags);
241 if (pimpr->helptext != nullptr) {
242 strvec_clear(pimpr->helptext);
243 }
244
245 return true;
246}
247
248/**********************************************************************/
252{
253 struct impr_type *new_bldg;
254
255 // Try to reuse freed building slot
256 improvement_iterate(pimpr) {
257 if (pimpr->ruledit_disabled) {
258 if (initialize_new_bldg(pimpr)) {
259 pimpr->ruledit_disabled = false;
260 update_bldg_info(pimpr);
261 refresh();
262 }
263 return;
264 }
266
267 // Try to add completely new building
269 return;
270 }
271
272 // num_impr_types must be big enough to hold new building or
273 // improvement_by_number() fails.
276 if (initialize_new_bldg(new_bldg)) {
277 update_bldg_info(new_bldg);
278
279 refresh();
280 } else {
281 game.control.num_impr_types--; // Restore
282 }
283}
284
285/**********************************************************************/
289{
290 name->setEnabled(!checked);
291 if (checked) {
292 name->setText(rname->text());
293 }
294}
295
296/**********************************************************************/
300{
301 if (selected != nullptr) {
302 ui->open_req_edit(QString::fromUtf8(improvement_rule_name(selected)),
303 &selected->reqs);
304 }
305}
306
307/**********************************************************************/
311{
312 if (selected != nullptr) {
313 struct universal uni;
314
315 uni.value.building = selected;
316 uni.kind = VUT_IMPROVEMENT;
317
319 &uni, EFMC_NORMAL);
320 }
321}
322
323/**********************************************************************/
327{
328 if (selected != nullptr) {
329 if (selected->ruledit_dlg == nullptr) {
331
332 edit->show();
334 } else {
335 ((edit_impr *)selected->ruledit_dlg)->raise();
336 }
337 }
338}
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
void display_msg(const char *msg)
void open_req_edit(QString target, struct requirement_vector *preqs)
requirers_dlg * create_requirers(const char *title)
void open_effect_edit(QString target, struct universal *uni, enum effect_filter_main_class efmc)
struct impr_type * selected
QCheckBox * same_name
bool initialize_new_bldg(struct impr_type *pimpr)
ruledit_gui * ui
void update_bldg_info(struct impr_type *pimpr)
tab_building(ruledit_gui *ui_in)
QListWidget * bldg_list
QLineEdit * rname
void same_name_toggle(bool checked)
QLineEdit * name
@ EFMC_NORMAL
Definition effect_edit.h:33
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:57
struct impr_type * improvement_by_number(const Impr_type_id id)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
struct impr_type * improvement_by_rule_name(const char *name)
#define improvement_re_active_iterate_end
#define improvement_iterate_end
#define improvement_re_active_iterate(_p)
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * untranslated_name(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:216
void ruledit_qt_display_requirers(const char *msg, void *data)
void strvec_clear(struct strvec *psv)
struct packet_ruleset_control control
Definition game.h:83
bool ruledit_disabled
Definition improvement.h:71
struct requirement_vector reqs
Definition improvement.h:75
struct strvec * helptext
Definition improvement.h:82
struct name_translation name
Definition improvement.h:70
bv_impr_flags flags
Definition improvement.h:81
void * ruledit_dlg
Definition improvement.h:72
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
const struct impr_type * building
Definition fc_types.h:598
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:228
#define edit(pedit)
Definition widget_edit.h:34