Freeciv-3.3
Loading...
Searching...
No Matches
tab_multiplier.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 "multipliers.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_multiplier.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
55 ui = ui_in;
56 selected = 0;
57
58 mpr_list = new QListWidget(this);
59
61 main_layout->addWidget(mpr_list);
62
63 mpr_layout->setSizeConstraint(QLayout::SetMaximumSize);
64
65 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
66 label->setParent(this);
67 rname = new QLineEdit(this);
68 rname->setText(R__("None"));
69 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
70 mpr_layout->addWidget(label, 0, 0);
71 mpr_layout->addWidget(rname, 0, 2);
72
73 label = new QLabel(QString::fromUtf8(R__("Name")));
74 label->setParent(this);
75 same_name = new QCheckBox();
76 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
77 name = new QLineEdit(this);
78 name->setText(R__("None"));
79 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
80 mpr_layout->addWidget(label, 1, 0);
81 mpr_layout->addWidget(same_name, 1, 1);
82 mpr_layout->addWidget(name, 1, 2);
83
84 reqs_button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
85 connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
86 mpr_layout->addWidget(reqs_button, 2, 2);
87
88 add_button = new QPushButton(QString::fromUtf8(R__("Add Multiplier")), this);
89 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
90 mpr_layout->addWidget(add_button, 4, 0);
92
93 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Multiplier")), this);
94 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
95 mpr_layout->addWidget(delete_button, 4, 2);
96 show_experimental(delete_button);
97
98 refresh();
100
101 main_layout->addLayout(mpr_layout);
102
103 setLayout(main_layout);
104}
105
106/**********************************************************************/
110{
111 mpr_list->clear();
112
115 = new QListWidgetItem(QString::fromUtf8(multiplier_rule_name(pmul)));
116
117 mpr_list->insertItem(multiplier_index(pmul), item);
119}
120
121/**********************************************************************/
125{
126 selected = pmul;
127
128 if (selected != 0) {
129 QString dispn = QString::fromUtf8(untranslated_name(&(pmul->name)));
130 QString rulen = QString::fromUtf8(multiplier_rule_name(pmul));
131
132 name->setText(dispn);
133 rname->setText(rulen);
134 if (dispn == rulen) {
135 name->setEnabled(false);
136 same_name->setChecked(true);
137 } else {
138 same_name->setChecked(false);
139 name->setEnabled(true);
140 }
141 } else {
142 name->setText(R__("None"));
143 rname->setText(R__("None"));
144 same_name->setChecked(true);
145 name->setEnabled(false);
146 }
147}
148
149/**********************************************************************/
153{
155
156 if (!select_list.isEmpty()) {
158
159 mn_bytes = select_list.at(0)->text().toUtf8();
161 }
162}
163
164/**********************************************************************/
168{
169 if (selected != nullptr) {
172
173 multipliers_iterate(pmul) {
174 if (pmul != selected && !pmul->ruledit_disabled) {
175 rname_bytes = rname->text().toUtf8();
176 if (!strcmp(multiplier_rule_name(pmul), rname_bytes.data())) {
177 ui->display_msg(R__("A multiplier with that rule name already exists!"));
178 return;
179 }
180 }
182
183 if (same_name->isChecked()) {
184 name->setText(rname->text());
185 }
186
187 name_bytes = name->text().toUtf8();
188 rname_bytes = rname->text().toUtf8();
189 names_set(&(selected->name), 0,
190 name_bytes.data(),
191 rname_bytes.data());
192 refresh();
193 }
194}
195
196/**********************************************************************/
215
216/**********************************************************************/
220{
221 if (multiplier_by_rule_name("New Multiplier") != nullptr) {
222 return false;
223 }
224
225 name_set(&(pmul->name), 0, "New Multiplier");
226 if (pmul->helptext != nullptr) {
227 strvec_clear(pmul->helptext);
228 }
229
230 return true;
231}
232
233/**********************************************************************/
237{
239
240 // Try to reuse freed multiplier slot
241 multipliers_iterate(pmul) {
242 if (pmul->ruledit_disabled) {
243 if (initialize_new_multiplier(pmul)) {
244 pmul->ruledit_disabled = false;
246 refresh();
247 }
248 return;
249 }
251
252 // Try to add completely new multiplier
254 return;
255 }
256
257 // num_multipliers must be big enough to hold new multiplier or
258 // multiplier_by_number() fails.
263
264 refresh();
265 } else {
266 game.control.num_multipliers--; // Restore
267 }
268}
269
270/**********************************************************************/
274{
275 name->setEnabled(!checked);
276 if (checked) {
277 name->setText(rname->text());
278 }
279}
280
281/**********************************************************************/
285{
286 if (selected != nullptr) {
287 req_edit *redit = new req_edit(ui, QString::fromUtf8(multiplier_rule_name(selected)),
288 &selected->reqs);
289
290 redit->show();
291 }
292}
void display_msg(const char *msg)
requirers_dlg * create_requirers(const char *title)
ruledit_gui * ui
tab_multiplier(ruledit_gui *ui_in)
void same_name_toggle(bool checked)
QLineEdit * name
QCheckBox * same_name
void update_multiplier_info(struct multiplier *pmul)
QListWidget * mpr_list
struct multiplier * selected
bool initialize_new_multiplier(struct multiplier *pmul)
QLineEdit * rname
char * incite_cost
Definition comments.c:76
#define MAX_NUM_MULTIPLIERS
Definition fc_types.h:55
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
const char * multiplier_rule_name(const struct multiplier *pmul)
struct multiplier * multiplier_by_rule_name(const char *name)
struct multiplier * multiplier_by_number(Multiplier_type_id id)
Definition multipliers.c:57
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_re_active_iterate(_mul_)
Definition multipliers.h:71
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
#define multipliers_re_active_iterate_end
Definition multipliers.h:75
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
Definition climisc.h:82
struct requirement_vector reqs
Definition multipliers.h:42
struct strvec * helptext
Definition multipliers.h:43
bool ruledit_disabled
Definition multipliers.h:34
struct name_translation name
Definition multipliers.h:33
bool is_multiplier_needed(struct multiplier *pmul, requirers_cb cb, void *data)
Definition validity.c:396