Freeciv-3.3
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 "edit_gov.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_gov.h"
42
43/**********************************************************************/
47{
48 QVBoxLayout *main_layout = new QVBoxLayout(this);
50 QLabel *label;
51 QPushButton *button;
52 int row = 0;
53
54 ui = ui_in;
55 selected = 0;
56
57 gov_list = new QListWidget(this);
58
59 connect(gov_list, SIGNAL(itemSelectionChanged()), this, SLOT(select_gov()));
60 main_layout->addWidget(gov_list);
61
62 gov_layout->setSizeConstraint(QLayout::SetMaximumSize);
63
64 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
65 label->setParent(this);
66 rname = new QLineEdit(this);
67 rname->setText(R__("None"));
68 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
69 gov_layout->addWidget(label, row, 0);
70 gov_layout->addWidget(rname, row++, 2);
71
72 label = new QLabel(QString::fromUtf8(R__("Name")));
73 label->setParent(this);
74 same_name = new QCheckBox();
75 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
76 name = new QLineEdit(this);
77 name->setText(R__("None"));
78 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
79 gov_layout->addWidget(label, row, 0);
80 gov_layout->addWidget(same_name, row, 1);
81 gov_layout->addWidget(name, row++, 2);
82
83 button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this);
84 connect(button, SIGNAL(pressed()), this, SLOT(edit_now()));
85 gov_layout->addWidget(button, row++, 2);
86
87 button = new QPushButton(QString::fromUtf8(R__("Requirements")), this);
88 connect(button, SIGNAL(pressed()), this, SLOT(edit_reqs()));
89 gov_layout->addWidget(button, row++, 2);
90
91 button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
92 connect(button, SIGNAL(pressed()), this, SLOT(edit_effects()));
93 gov_layout->addWidget(button, row++, 2);
94
95 button = new QPushButton(QString::fromUtf8(R__("Add Government")), this);
96 connect(button, SIGNAL(pressed()), this, SLOT(add_now()));
97 gov_layout->addWidget(button, row, 0);
98 show_experimental(button);
99
100 button = new QPushButton(QString::fromUtf8(R__("Remove this Government")), this);
101 connect(button, SIGNAL(pressed()), this, SLOT(delete_now()));
102 gov_layout->addWidget(button, row++, 2);
103 show_experimental(button);
104
105 refresh();
106 update_gov_info(nullptr);
107
108 main_layout->addLayout(gov_layout);
109
110 setLayout(main_layout);
111}
112
113/**********************************************************************/
117{
118 gov_list->clear();
119
122 = new QListWidgetItem(QString::fromUtf8(government_rule_name(pgov)));
123
124 gov_list->insertItem(government_index(pgov), item);
126}
127
128/**********************************************************************/
132{
133 selected = pgov;
134
135 if (selected != 0) {
136 QString dispn = QString::fromUtf8(untranslated_name(&(pgov->name)));
137 QString rulen = QString::fromUtf8(government_rule_name(pgov));
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 gn_bytes = select_list.at(0)->text().toUtf8();
168 }
169}
170
171/**********************************************************************/
175{
176 if (selected != nullptr) {
179
181 if (pgov != selected && !pgov->ruledit_disabled) {
182 rname_bytes = rname->text().toUtf8();
184 ui->display_msg(R__("A government 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 != 0) {
211
214 return;
215 }
216
218
219 if (selected->ruledit_dlg != nullptr) {
220 ((edit_gov *)selected->ruledit_dlg)->done(0);
221 }
222
223 refresh();
224 update_gov_info(nullptr);
225 }
226}
227
228/**********************************************************************/
232{
233 if (selected != nullptr) {
234 if (selected->ruledit_dlg == nullptr) {
236
237 edit->show();
239 } else {
240 ((edit_gov *)selected->ruledit_dlg)->raise();
241 }
242 }
243}
244
245/**********************************************************************/
249{
250 if (government_by_rule_name("New Government") != nullptr) {
251 return false;
252 }
253
254 name_set(&(pgov->name), 0, "New Government");
255 if (pgov->helptext != nullptr) {
256 strvec_clear(pgov->helptext);
257 }
258
259 return true;
260}
261
262/**********************************************************************/
266{
267 struct government *new_gov;
268
269 // Try to reuse freed government slot
271 if (pgov->ruledit_disabled) {
273 pgov->ruledit_disabled = false;
275 refresh();
276 }
277 return;
278 }
280
281 // Try to add completely new government
283 return;
284 }
285
286 // government_count must be big enough to hold new government or
287 // government_by_number() fails.
292
293 refresh();
294 } else {
295 game.control.government_count--; // Restore
296 }
297}
298
299/**********************************************************************/
303{
304 name->setEnabled(!checked);
305 if (checked) {
306 name->setText(rname->text());
307 }
308}
309
310/**********************************************************************/
314{
315 if (selected != nullptr) {
316 ui->open_req_edit(QString::fromUtf8(government_rule_name(selected)),
317 &selected->reqs);
318 }
319}
320
321/**********************************************************************/
325{
326 if (selected != nullptr) {
327 struct universal uni;
328
329 uni.value.govern = selected;
330 uni.kind = VUT_GOVERNMENT;
331
333 &uni, EFMC_NORMAL);
334 }
335}
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:207
tab_gov(ruledit_gui *ui_in)
Definition tab_gov.cpp:46
QLineEdit * rname
Definition tab_gov.h:44
void edit_effects()
Definition tab_gov.cpp:324
QLineEdit * name
Definition tab_gov.h:43
void add_now()
Definition tab_gov.cpp:265
bool initialize_new_gov(struct government *pgov)
Definition tab_gov.cpp:248
void update_gov_info(struct government *pgov)
Definition tab_gov.cpp:131
void edit_reqs()
Definition tab_gov.cpp:313
struct government * selected
Definition tab_gov.h:48
void refresh()
Definition tab_gov.cpp:116
void edit_now()
Definition tab_gov.cpp:231
void same_name_toggle(bool checked)
Definition tab_gov.cpp:302
void name_given()
Definition tab_gov.cpp:174
QListWidget * gov_list
Definition tab_gov.h:45
ruledit_gui * ui
Definition tab_gov.h:39
void select_gov()
Definition tab_gov.cpp:159
QCheckBox * same_name
Definition tab_gov.h:46
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
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:124
#define governments_re_active_iterate(_p)
Definition government.h:129
#define governments_re_active_iterate_end
Definition government.h:133
#define governments_iterate_end
Definition government.h:127
#define edit(pedit)
Definition widget_edit.h:34
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
Definition government.h:62
void * ruledit_dlg
Definition government.h:56
bool ruledit_disabled
Definition government.h:55
struct name_translation name
Definition government.h:54
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
struct government * govern
Definition fc_types.h:545
bool is_government_needed(struct government *pgov, requirers_cb cb, void *data)
Definition validity.c:358