Freeciv-3.2
Loading...
Searching...
No Matches
tab_gov.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 "government.h"
34
35// ruledit
36#include "ruledit.h"
37#include "ruledit_qt.h"
38#include "validity.h"
39
40#include "tab_gov.h"
41
42/**********************************************************************/
46{
47 QVBoxLayout *main_layout = new QVBoxLayout(this);
49 QLabel *label;
50 QPushButton *effects_button;
51 QPushButton *add_button;
52 QPushButton *delete_button;
53 QPushButton *reqs_button;
54
55 ui = ui_in;
56 selected = 0;
57
58 gov_list = new QListWidget(this);
59
60 connect(gov_list, SIGNAL(itemSelectionChanged()), this, SLOT(select_gov()));
61 main_layout->addWidget(gov_list);
62
63 gov_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 gov_layout->addWidget(label, 0, 0);
71 gov_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 gov_layout->addWidget(label, 1, 0);
81 gov_layout->addWidget(same_name, 1, 1);
82 gov_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 gov_layout->addWidget(reqs_button, 2, 2);
87
88 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
89 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
90 gov_layout->addWidget(effects_button, 3, 2);
91
92 add_button = new QPushButton(QString::fromUtf8(R__("Add Government")), this);
93 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
94 gov_layout->addWidget(add_button, 4, 0);
96
97 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Government")), this);
98 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
99 gov_layout->addWidget(delete_button, 4, 2);
100 show_experimental(delete_button);
101
102 refresh();
103 update_gov_info(nullptr);
104
105 main_layout->addLayout(gov_layout);
106
107 setLayout(main_layout);
108}
109
110/**********************************************************************/
114{
115 gov_list->clear();
116
119 = new QListWidgetItem(QString::fromUtf8(government_rule_name(pgov)));
120
121 gov_list->insertItem(government_index(pgov), item);
123}
124
125/**********************************************************************/
129{
130 selected = pgov;
131
132 if (selected != 0) {
133 QString dispn = QString::fromUtf8(untranslated_name(&(pgov->name)));
134 QString rulen = QString::fromUtf8(government_rule_name(pgov));
135
136 name->setText(dispn);
137 rname->setText(rulen);
138 if (dispn == rulen) {
139 name->setEnabled(false);
140 same_name->setChecked(true);
141 } else {
142 same_name->setChecked(false);
143 name->setEnabled(true);
144 }
145 } else {
146 name->setText(R__("None"));
147 rname->setText(R__("None"));
148 same_name->setChecked(true);
149 name->setEnabled(false);
150 }
151}
152
153/**********************************************************************/
157{
159
160 if (!select_list.isEmpty()) {
162
163 gn_bytes = select_list.at(0)->text().toUtf8();
165 }
166}
167
168/**********************************************************************/
172{
173 if (selected != nullptr) {
176
178 if (pgov != selected && !pgov->ruledit_disabled) {
179 rname_bytes = rname->text().toUtf8();
181 ui->display_msg(R__("A government with that rule name already "
182 "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_gov_info(nullptr);
218 }
219}
220
221/**********************************************************************/
225{
226 if (government_by_rule_name("New Government") != nullptr) {
227 return false;
228 }
229
230 name_set(&(pgov->name), 0, "New Government");
231
232 return true;
233}
234
235/**********************************************************************/
239{
240 struct government *new_gov;
241
242 // Try to reuse freed government slot
244 if (pgov->ruledit_disabled) {
246 pgov->ruledit_disabled = false;
248 refresh();
249 }
250 return;
251 }
253
254 // Try to add completely new government
256 return;
257 }
258
259 // government_count must be big enough to hold new government or
260 // government_by_number() fails.
265
266 refresh();
267 } else {
268 game.control.government_count--; // Restore
269 }
270}
271
272/**********************************************************************/
276{
277 name->setEnabled(!checked);
278 if (checked) {
279 name->setText(rname->text());
280 }
281}
282
283/**********************************************************************/
287{
288 if (selected != nullptr) {
289 ui->open_req_edit(QString::fromUtf8(government_rule_name(selected)),
290 &selected->reqs);
291 }
292}
293
294/**********************************************************************/
298{
299 if (selected != nullptr) {
300 struct universal uni;
301
302 uni.value.govern = selected;
303 uni.kind = VUT_GOVERNMENT;
304
306 &uni, EFMC_NORMAL);
307 }
308}
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)
void delete_now()
Definition tab_gov.cpp:204
tab_gov(ruledit_gui *ui_in)
Definition tab_gov.cpp:45
QLineEdit * rname
Definition tab_gov.h:44
void edit_effects()
Definition tab_gov.cpp:297
QLineEdit * name
Definition tab_gov.h:43
void add_now()
Definition tab_gov.cpp:238
bool initialize_new_gov(struct government *pgov)
Definition tab_gov.cpp:224
void update_gov_info(struct government *pgov)
Definition tab_gov.cpp:128
void edit_reqs()
Definition tab_gov.cpp:286
struct government * selected
Definition tab_gov.h:48
void refresh()
Definition tab_gov.cpp:113
void same_name_toggle(bool checked)
Definition tab_gov.cpp:275
void name_given()
Definition tab_gov.cpp:171
QListWidget * gov_list
Definition tab_gov.h:45
ruledit_gui * ui
Definition tab_gov.h:39
void select_gov()
Definition tab_gov.cpp:156
QCheckBox * same_name
Definition tab_gov.h:46
char * incite_cost
Definition comments.c:74
@ 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:62
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
struct government * government_by_rule_name(const char *name)
Definition government.c:55
#define governments_iterate(NAME_pgov)
Definition government.h:120
#define governments_re_active_iterate(_p)
Definition government.h:125
#define governments_re_active_iterate_end
Definition government.h:129
#define governments_iterate_end
Definition government.h:123
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)
struct packet_ruleset_control control
Definition game.h:83
struct requirement_vector reqs
Definition government.h:58
bool ruledit_disabled
Definition government.h:55
struct name_translation name
Definition government.h:54
Definition climisc.h:80
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
struct government * govern
Definition fc_types.h:716
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:358