Freeciv-3.3
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);
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
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
102 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Building")), this);
103 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
104 bldg_layout->addWidget(delete_button, 5, 2);
105
106 refresh();
107 update_bldg_info(nullptr);
108
109 main_layout->addLayout(bldg_layout);
110
111 setLayout(main_layout);
112}
113
114/**********************************************************************/
127
128/**********************************************************************/
132{
133 selected = pimpr;
134
135 if (selected != 0) {
136 QString dispn = QString::fromUtf8(untranslated_name(&(pimpr->name)));
137 QString rulen = QString::fromUtf8(improvement_rule_name(pimpr));
138
139 name->setText(dispn);
140 rname->setText(rulen);
141 if (dispn == rulen) {
142 name->setEnabled(false);
143 same_name->setChecked(true);
144 } else {
145 same_name->setChecked(false);
146 name->setEnabled(true);
147 }
148 } else {
149 name->setText(R__("None"));
150 rname->setText(R__("None"));
151 same_name->setChecked(true);
152 name->setEnabled(false);
153 }
154}
155
156/**********************************************************************/
160{
162
163 if (!select_list.isEmpty()) {
165
166 bn_bytes = select_list.at(0)->text().toUtf8();
168 }
169}
170
171/**********************************************************************/
175{
176 if (selected != nullptr) {
179
181 if (pimpr != selected && !pimpr->ruledit_disabled) {
182 rname_bytes = rname->text().toUtf8();
184 ui->display_msg(R__("A building with that rule name already "
185 "exists!"));
186 return;
187 }
188 }
190
191 if (same_name->isChecked()) {
192 name->setText(rname->text());
193 }
194
195 name_bytes = name->text().toUtf8();
196 rname_bytes = rname->text().toUtf8();
197 names_set(&(selected->name), 0,
198 name_bytes.data(),
199 rname_bytes.data());
200 refresh();
201 }
202}
203
204/**********************************************************************/
208{
209 if (selected != nullptr) {
211
214 return;
215 }
216
218
219 if (selected->ruledit_dlg != nullptr) {
220 ((edit_impr *)selected->ruledit_dlg)->done(0);
221 }
222
223 refresh();
224 update_bldg_info(nullptr);
225 }
226}
227
228/**********************************************************************/
232{
233 if (improvement_by_rule_name("New Building") != nullptr) {
234 return false;
235 }
236
237 name_set(&(pimpr->name), 0, "New Building");
238 BV_CLR_ALL(pimpr->flags);
239 if (pimpr->helptext != nullptr) {
240 strvec_clear(pimpr->helptext);
241 }
242
243 return true;
244}
245
246/**********************************************************************/
254{
255 struct impr_type *new_bldg;
256
257 // Try to reuse freed building slot
259 if (pimpr->ruledit_disabled) {
261 pimpr->ruledit_disabled = false;
263 refresh();
264 }
265 return;
266 }
268
269 // Try to add completely new building
271 return;
272 }
273
274 // num_impr_types must be big enough to hold new building or
275 // improvement_by_number() fails.
280
281 refresh();
282 } else {
283 game.control.num_impr_types--; // Restore
284 }
285}
286
287/**********************************************************************/
291{
292 name->setEnabled(!checked);
293 if (checked) {
294 name->setText(rname->text());
295 }
296}
297
298/**********************************************************************/
302{
303 if (selected != nullptr) {
304 ui->open_req_edit(QString::fromUtf8(improvement_rule_name(selected)),
305 &selected->reqs);
306 }
307}
308
309/**********************************************************************/
313{
314 if (selected != nullptr) {
315 struct universal uni;
316
317 uni.value.building = selected;
318 uni.kind = VUT_IMPROVEMENT;
319
321 &uni, EFMC_NORMAL);
322 }
323}
324
325/**********************************************************************/
329{
330 if (selected != nullptr) {
331 if (selected->ruledit_dlg == nullptr) {
333
334 edit->show();
336 } else {
337 ((edit_impr *)selected->ruledit_dlg)->raise();
338 }
339 }
340}
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
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
char * incite_cost
Definition comments.c:76
@ EFMC_NORMAL
Definition effect_edit.h:34
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
#define edit(pedit)
Definition widget_edit.h:34
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 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:53
struct requirement_vector reqs
Definition improvement.h:58
struct name_translation name
Definition improvement.h:52
void * ruledit_dlg
Definition improvement.h:54
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
const struct impr_type * building
Definition fc_types.h:546
bool is_building_needed(struct impr_type *pimpr, requirers_cb cb, void *data)
Definition validity.c:238