Freeciv-3.3
Loading...
Searching...
No Matches
tab_good.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 "req_edit.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_good.h"
42
43/**********************************************************************/
47{
48 QVBoxLayout *main_layout = new QVBoxLayout(this);
50 QLabel *label;
51 QPushButton *effects_button;
52 QPushButton *add_button;
53 QPushButton *delete_button;
54 QPushButton *reqs_button;
55
56 ui = ui_in;
57 selected = 0;
58
59 good_list = new QListWidget(this);
60
62 main_layout->addWidget(good_list);
63
64 good_layout->setSizeConstraint(QLayout::SetMaximumSize);
65
66 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
67 label->setParent(this);
68 rname = new QLineEdit(this);
69 rname->setText(R__("None"));
70 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
71 good_layout->addWidget(label, 0, 0);
72 good_layout->addWidget(rname, 0, 2);
73
74 label = new QLabel(QString::fromUtf8(R__("Name")));
75 label->setParent(this);
76 same_name = new QCheckBox();
77 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
78 name = new QLineEdit(this);
79 name->setText(R__("None"));
80 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
81 good_layout->addWidget(label, 1, 0);
82 good_layout->addWidget(same_name, 1, 1);
83 good_layout->addWidget(name, 1, 2);
84
85 reqs_button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
86 connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
87 good_layout->addWidget(reqs_button, 2, 2);
88
89 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
90 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
91 good_layout->addWidget(effects_button, 3, 2);
92
93 add_button = new QPushButton(QString::fromUtf8(R__("Add Good")), this);
94 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
95 good_layout->addWidget(add_button, 4, 0);
97
98 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Good")), this);
99 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
100 good_layout->addWidget(delete_button, 4, 2);
101 show_experimental(delete_button);
102
103 refresh();
104 update_good_info(nullptr);
105
106 main_layout->addLayout(good_layout);
107
108 setLayout(main_layout);
109}
110
111/**********************************************************************/
115{
116 good_list->clear();
117
120 = new QListWidgetItem(QString::fromUtf8(goods_rule_name(pgood)));
121
122 good_list->insertItem(goods_index(pgood), item);
124}
125
126/**********************************************************************/
130{
131 selected = pgood;
132
133 if (selected != 0) {
134 QString dispn = QString::fromUtf8(untranslated_name(&(pgood->name)));
135 QString rulen = QString::fromUtf8(goods_rule_name(pgood));
136
137 name->setText(dispn);
138 rname->setText(rulen);
139 if (dispn == rulen) {
140 name->setEnabled(false);
141 same_name->setChecked(true);
142 } else {
143 same_name->setChecked(false);
144 name->setEnabled(true);
145 }
146 } else {
147 name->setText(R__("None"));
148 rname->setText(R__("None"));
149 same_name->setChecked(true);
150 name->setEnabled(false);
151 }
152}
153
154/**********************************************************************/
158{
160
161 if (!select_list.isEmpty()) {
163
164 gn_bytes = select_list.at(0)->text().toUtf8();
166 }
167}
168
169/**********************************************************************/
173{
174 if (selected != nullptr) {
177
179 if (pgood != selected && !pgood->ruledit_disabled) {
180 rname_bytes = rname->text().toUtf8();
181 if (!strcmp(goods_rule_name(pgood), rname_bytes.data())) {
182 ui->display_msg(R__("A good with that rule name already exists!"));
183 return;
184 }
185 }
187
188 if (same_name->isChecked()) {
189 name->setText(rname->text());
190 }
191
192 name_bytes = name->text().toUtf8();
193 rname_bytes = rname->text().toUtf8();
194 names_set(&(selected->name), 0,
195 name_bytes.data(),
196 rname_bytes.data());
197 refresh();
198 }
199}
200
201/**********************************************************************/
205{
206 if (selected != 0) {
208
211 return;
212 }
213
215
216 refresh();
217 update_good_info(nullptr);
218 }
219}
220
221/**********************************************************************/
225{
226 if (goods_by_rule_name("New Good") != nullptr) {
227 return false;
228 }
229
230 name_set(&(pgood->name), 0, "New Good");
231 BV_CLR_ALL(pgood->flags);
232 if (pgood->helptext != nullptr) {
233 strvec_clear(pgood->helptext);
234 }
235
236 return true;
237}
238
239/**********************************************************************/
243{
244 struct goods_type *new_good;
245
246 // Try to reuse freed good slot
248 if (pgood->ruledit_disabled) {
250 pgood->ruledit_disabled = false;
252 refresh();
253 }
254 return;
255 }
257
258 // Try to add completely new good
260 return;
261 }
262
263 // num_good_types must be big enough to hold new good or
264 // good_by_number() fails.
269
270 refresh();
271 } else {
272 game.control.num_goods_types--; // Restore
273 }
274}
275
276/**********************************************************************/
280{
281 name->setEnabled(!checked);
282 if (checked) {
283 name->setText(rname->text());
284 }
285}
286
287/**********************************************************************/
291{
292 if (selected != nullptr) {
293 ui->open_req_edit(QString::fromUtf8(goods_rule_name(selected)),
294 &selected->reqs);
295 }
296}
297
298/**********************************************************************/
302{
303 if (selected != nullptr) {
304 struct universal uni;
305
306 uni.value.good = selected;
307 uni.kind = VUT_GOOD;
308
309 ui->open_effect_edit(QString::fromUtf8(goods_rule_name(selected)),
310 &uni, EFMC_NORMAL);
311 }
312}
#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)
QListWidget * good_list
Definition tab_good.h:45
void edit_effects()
Definition tab_good.cpp:301
struct goods_type * selected
Definition tab_good.h:48
bool initialize_new_good(struct goods_type *pgood)
Definition tab_good.cpp:224
QLineEdit * name
Definition tab_good.h:43
tab_good(ruledit_gui *ui_in)
Definition tab_good.cpp:46
void refresh()
Definition tab_good.cpp:114
QCheckBox * same_name
Definition tab_good.h:46
void select_good()
Definition tab_good.cpp:157
QLineEdit * rname
Definition tab_good.h:44
void delete_now()
Definition tab_good.cpp:204
void name_given()
Definition tab_good.cpp:172
void edit_reqs()
Definition tab_good.cpp:290
void update_good_info(struct goods_type *pgood)
Definition tab_good.cpp:129
void add_now()
Definition tab_good.cpp:242
ruledit_gui * ui
Definition tab_good.h:39
void same_name_toggle(bool checked)
Definition tab_good.cpp:279
char * incite_cost
Definition comments.c:76
@ EFMC_NORMAL
Definition effect_edit.h:34
#define MAX_GOODS_TYPES
Definition fc_types.h:51
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
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:237
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
struct requirement_vector reqs
bool ruledit_disabled
struct name_translation name
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
struct goods_type * goods_by_rule_name(const char *name)
const char * goods_rule_name(struct goods_type *pgood)
Goods_type_id goods_index(const struct goods_type *pgood)
struct goods_type * goods_by_number(Goods_type_id id)
#define goods_type_iterate_end
#define goods_type_re_active_iterate_end
#define goods_type_iterate(_p)
#define goods_type_re_active_iterate(_p)
struct goods_type * good
Definition fc_types.h:559
bool is_good_needed(struct goods_type *pgood, requirers_cb cb, void *data)
Definition validity.c:287