Freeciv-3.2
Loading...
Searching...
No Matches
tab_enablers.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 <QGridLayout>
20#include <QLineEdit>
21#include <QListWidget>
22#include <QMenu>
23#include <QMessageBox>
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_enablers.h"
41
43{
44public:
45 explicit fix_enabler_item(struct action_enabler *enabler);
46 virtual ~fix_enabler_item();
47 void close();
48
49 const void *item();
50 void *item_working_copy();
51 const char *name();
55 int num_vectors();
58 bool vector_in_item(const struct requirement_vector *vec);
59
60private:
64};
65
66/**********************************************************************/
89
90/**********************************************************************/
94{
95 QVBoxLayout *main_layout = new QVBoxLayout(this);
97 QLabel *label;
98 QPushButton *add_button;
99 int row = 0;
100
101 ui = ui_in;
102 connect(ui, SIGNAL(req_vec_may_have_changed(const requirement_vector *)),
104
105 selected = 0;
106
107 enabler_list = new QListWidget(this);
108
110 main_layout->addWidget(enabler_list);
111
112 enabler_layout->setSizeConstraint(QLayout::SetMaximumSize);
113
114 label = new QLabel(QString::fromUtf8(R__("Type")));
115 label->setParent(this);
116 enabler_layout->addWidget(label, row, 0);
117
118 type_button = new QToolButton();
119 type_menu = new QMenu();
120
121 action_iterate(act) {
122 type_menu->addAction(action_id_rule_name(act));
124
125 connect(type_menu, SIGNAL(triggered(QAction *)),
126 this, SLOT(edit_type(QAction *)));
127
128 type_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
129 type_button->setPopupMode(QToolButton::MenuButtonPopup);
130
131 type_button->setMenu(type_menu);
132 type_button->setText(R__("None"));
133
134 type_button->setEnabled(false);
135 enabler_layout->addWidget(type_button, row++, 1);
136
138 = new QPushButton(QString::fromUtf8(R__("Actor Requirements")), this);
139 connect(act_reqs_button, SIGNAL(pressed()),
140 this, SLOT(edit_actor_reqs()));
141 act_reqs_button->setEnabled(false);
142 enabler_layout->addWidget(act_reqs_button, row++, 1);
143
145 = new QPushButton(QString::fromUtf8(R__("Target Requirements")),
146 this);
147 connect(tgt_reqs_button, SIGNAL(pressed()),
148 this, SLOT(edit_target_reqs()));
149 tgt_reqs_button->setEnabled(false);
150 enabler_layout->addWidget(tgt_reqs_button, row++, 1);
151
152 add_button = new QPushButton(QString::fromUtf8(R__("Add Enabler")), this);
153 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
154 enabler_layout->addWidget(add_button, row, 0);
155
156 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Enabler")), this);
157 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
158 delete_button->setEnabled(false);
159 enabler_layout->addWidget(delete_button, row++, 1);
160
161 repair_button = new QPushButton(this);
162 connect(repair_button, SIGNAL(pressed()), this, SLOT(repair_now()));
163 repair_button->setEnabled(false);
164 repair_button->setText(QString::fromUtf8(R__("Enabler Issues")));
165 enabler_layout->addWidget(repair_button, row++, 1);
166
167 refresh();
168
169 main_layout->addLayout(enabler_layout);
170
171 setLayout(main_layout);
172}
173
174/**********************************************************************/
178{
179 int n = 0;
180
181 enabler_list->clear();
182
184 if (!enabler->ruledit_disabled) {
185 char buffer[512];
187
188 fc_snprintf(buffer, sizeof(buffer), "#%d: %s", n,
190
191 item = new QListWidgetItem(QString::fromUtf8(buffer));
192
193 enabler_list->insertItem(n++, item);
194
196
197 item->setSelected(enabler == selected);
198 }
200}
201
202/**********************************************************************/
206{
207 int i = 0;
208
210
211 if (selected != nullptr) {
213
214 type_button->setText(dispn);
215
216 type_button->setEnabled(true);
217 act_reqs_button->setEnabled(true);
218 tgt_reqs_button->setEnabled(true);
219
220 delete_button->setEnabled(true);
221
223 case RVPS_REPAIR:
224 // Offer to repair the enabler if it has a problem.
225 // TRANS: Fix an error in an action enabler.
226 repair_button->setText(QString::fromUtf8(R__("Repair Enabler")));
227 repair_button->setEnabled(TRUE);
228 break;
229 case RVPS_IMPROVE:
230 // TRANS: Fix a non error issue in an action enabler.
231 repair_button->setText(QString::fromUtf8(R__("Improve Enabler")));
232 repair_button->setEnabled(true);
233 break;
234 case RVPS_NO_PROBLEM:
235 repair_button->setText(QString::fromUtf8(R__("Enabler Issues")));
236 repair_button->setEnabled(false);
237 break;
238 }
239 } else {
240 type_button->setText(R__("None"));
241 type_button->setEnabled(false);
242
243 act_reqs_button->setEnabled(false);
244 tgt_reqs_button->setEnabled(false);
245
246 repair_button->setEnabled(false);
247 repair_button->setText(QString::fromUtf8(R__("Enabler Issues")));
248
249 delete_button->setEnabled(false);
250 }
251
252 // The enabler may have gotten (rid of) a problem.
255
256 if (item == nullptr) {
257 continue;
258 }
259
262}
263
264/**********************************************************************/
268{
269 int i = 0;
270
273
274 if (item != nullptr && item->isSelected()) {
276 }
278}
279
280/**********************************************************************/
284{
285 if (selected != nullptr) {
287
288 refresh();
289 update_enabler_info(nullptr);
290 }
291}
292
293/**********************************************************************/
297{
298 enabler->ruledit_disabled = false;
299
300 return true;
301}
302
303/**********************************************************************/
307{
309
310 // Try to reuse freed enabler slot
312 if (enabler->ruledit_disabled) {
315 refresh();
316 }
317 return;
318 }
320
321 // Try to add completely new enabler
323
326 new_enabler->action = (NUM_ACTIONS - 1);
327
329
331 refresh();
332}
333
334/**********************************************************************/
338{
339 if (selected == nullptr) {
340 // Nothing to repair
341 return;
342 }
343
345}
346
347/**********************************************************************/
352{
354 if (&enabler->actor_reqs == vec || &enabler->target_reqs == vec) {
356 }
358}
359
360/**********************************************************************/
364{
365 struct action *paction;
367
368 an_bytes = action->text().toUtf8();
370
371 if (selected != nullptr && paction != nullptr) {
372 // Must remove and add back because enablers are stored by action.
376
377 // Show the changes.
379 refresh();
380 }
381}
382
383/**********************************************************************/
387{
388 if (selected != nullptr) {
389 ui->open_req_edit(QString::fromUtf8(R__("Enabler (target)")),
391 }
392}
393
394/**********************************************************************/
398{
399 if (selected != nullptr) {
400 ui->open_req_edit(QString::fromUtf8(R__("Enabler (actor)")),
402 }
403}
404
405/**********************************************************************/
410{
411 char buf[MAX_LEN_NAME * 2];
413
415
416 /* Can't use QString::asprintf() as msys libintl.h defines asprintf()
417 * as a macro */
418 fc_snprintf(buf, sizeof(buf),
419 R__("action enabler for %s"), action_rule_name(paction));
420
421 // Don't modify the original until the user accepts
424
425 // As precise a title as possible
427}
428
429/**********************************************************************/
436
437/********************************************************************/
441{
442 delete this;
443}
444
445/********************************************************************/
450{
451 return current_enabler;
452}
453
454/********************************************************************/
462
463/**********************************************************************/
470{
471 return my_name.toUtf8().data();
472}
473
474/**********************************************************************/
490
491/**********************************************************************/
507
508/**********************************************************************/
523
524/********************************************************************/
530{
531 return 2;
532}
533
534/********************************************************************/
545
546/********************************************************************/
557
558/**********************************************************************/
565{
566 return (&current_enabler->actor_reqs == vec
567 || &current_enabler->target_reqs == vec);
568}
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:2679
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:2745
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2856
struct action * action_by_rule_name(const char *name)
Definition actions.c:1840
const char * action_rule_name(const struct action *action)
Definition actions.c:1977
const char * action_id_rule_name(action_id act_id)
Definition actions.c:2000
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:2255
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:2282
struct action_enabler * action_enabler_new(void)
Definition actions.c:2236
bool action_id_exists(const action_id act_id)
Definition actions.c:1829
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:2299
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:2267
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2832
#define action_enablers_iterate_end
Definition actions.h:519
#define enabler_get_action(_enabler_)
Definition actions.h:433
#define NUM_ACTIONS
Definition actions.h:315
#define action_iterate_end
Definition actions.h:465
#define action_enablers_iterate(_enabler_)
Definition actions.h:513
#define action_id(_act_)
Definition actions.h:661
#define action_iterate(_act_)
Definition actions.h:461
#define n
Definition astring.c:77
fix_enabler_item(struct action_enabler *enabler)
void apply_accepted_changes()
struct req_vec_problem * find_next_problem(void)
bool vector_in_item(const struct requirement_vector *vec)
requirement_vector_namer vector_namer()
virtual ~fix_enabler_item()
struct action_enabler * local_copy
const void * item()
struct action_enabler * current_enabler
requirement_vector_by_number vector_getter()
void * item_working_copy()
const char * name()
void open_req_vec_fix(req_vec_fix_item *item_info)
void open_req_edit(QString target, struct requirement_vector *preqs)
ruledit_gui * ui
void incoming_req_vec_change(const requirement_vector *vec)
void edit_type(QAction *action)
struct action_enabler * selected
QPushButton * act_reqs_button
QToolButton * type_button
void edit_actor_reqs()
tab_enabler(ruledit_gui *ui_in)
QPushButton * tgt_reqs_button
QMenu * type_menu
void edit_target_reqs()
void select_enabler()
QListWidget * enabler_list
QPushButton * delete_button
bool initialize_new_enabler(struct action_enabler *enabler)
QPushButton * repair_button
void update_enabler_info(struct action_enabler *enabler)
char * incite_cost
Definition comments.c:75
#define MAX_LEN_NAME
Definition fc_types.h:66
#define R__(String)
Definition fcintl.h:75
#define fc_assert_ret(condition)
Definition log.h:191
void mark_item(QListWidgetItem *item, enum req_vec_problem_seriousness problem_level)
req_vec_problem_seriousness
Definition req_vec_fix.h:35
@ RVPS_NO_PROBLEM
Definition req_vec_fix.h:36
@ RVPS_REPAIR
Definition req_vec_fix.h:38
@ RVPS_IMPROVE
Definition req_vec_fix.h:37
void req_vec_problem_free(struct req_vec_problem *issue)
const char *(* requirement_vector_namer)(req_vec_num_in_item number)
struct requirement_vector *(* requirement_vector_by_number)(const void *parent_item, req_vec_num_in_item number)
bool ruledit_disabled
Definition actions.h:428
action_id action
Definition actions.h:422
struct requirement_vector actor_reqs
Definition actions.h:423
struct requirement_vector target_reqs
Definition actions.h:424
Definition climisc.h:82
struct universal item
Definition climisc.h:83
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
static enum req_vec_problem_seriousness enabler_problem_level(struct action_enabler *enabler)