Freeciv-3.3
Loading...
Searching...
No Matches
tab_tech.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 "tech.h"
34
35// ruledit
36#include "edit_tech.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_tech.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 *edit_button;
55 int row = 0;
56
57 ui = ui_in;
58 selected = 0;
59
60 tech_list = new QListWidget(this);
61
63 main_layout->addWidget(tech_list);
64
65 tech_layout->setSizeConstraint(QLayout::SetMaximumSize);
66
67 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
68 label->setParent(this);
69 rname = new QLineEdit(this);
70 rname->setText(R__("None"));
71 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
72 tech_layout->addWidget(label, row, 0);
73 tech_layout->addWidget(rname, row++, 2);
74
75 label = new QLabel(QString::fromUtf8(R__("Name")));
76 label->setParent(this);
77 same_name = new QCheckBox();
78 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
79 name = new QLineEdit(this);
80 name->setText(R__("None"));
81 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
82 tech_layout->addWidget(label, row, 0);
83 tech_layout->addWidget(same_name, row, 1);
84 tech_layout->addWidget(name, row++, 2);
85
86 edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this);
87 connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now()));
88 tech_layout->addWidget(edit_button, row++, 2);
89
90 label = new QLabel(QString::fromUtf8(R__("Req1")));
91 label->setParent(this);
93 req1_button->setParent(this);
95 connect(req1_button, SIGNAL(pressed()), this, SLOT(req1_jump()));
96 tech_layout->addWidget(label, row, 0);
97 tech_layout->addWidget(req1_button, row++, 2);
98
99 label = new QLabel(QString::fromUtf8(R__("Req2")));
100 label->setParent(this);
101 req2_button = new QToolButton();
103 connect(req2_button, SIGNAL(pressed()), this, SLOT(req2_jump()));
104 tech_layout->addWidget(label, row, 0);
105 tech_layout->addWidget(req2_button, row++, 2);
106
107 label = new QLabel(QString::fromUtf8(R__("Root Req")));
108 label->setParent(this);
110 root_req_button->setParent(this);
112 connect(root_req_button, SIGNAL(pressed()), this, SLOT(root_req_jump()));
113 tech_layout->addWidget(label, row, 0);
114 tech_layout->addWidget(root_req_button, row++, 2);
115
116 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
117 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
118 tech_layout->addWidget(effects_button, row++, 2);
119
120 add_button = new QPushButton(QString::fromUtf8(R__("Add tech")), this);
121 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
122 tech_layout->addWidget(add_button, row, 0);
123
124 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this tech")), this);
125 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
126 tech_layout->addWidget(delete_button, row++, 2);
127
128 refresh();
129 update_tech_info(nullptr);
130
131 main_layout->addLayout(tech_layout);
132
133 setLayout(main_layout);
134}
135
136/**********************************************************************/
153
154/**********************************************************************/
158{
159 QMenu *menu = new QMenu();
160
161 button->setToolButtonStyle(Qt::ToolButtonTextOnly);
162 button->setPopupMode(QToolButton::MenuButtonPopup);
163
164 switch (rn) {
165 case AR_ONE:
166 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(req1_menu(QAction *)));
167 break;
168 case AR_TWO:
169 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(req2_menu(QAction *)));
170 break;
171 case AR_ROOT:
172 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(root_req_menu(QAction *)));
173 break;
174 case AR_SIZE:
175 fc_assert(rn != AR_SIZE);
176 break;
177 }
178
179 button->setMenu(menu);
180
181 return menu;
182}
183
184/**********************************************************************/
188{
189 fill_menu->clear();
190
192 fill_menu->addAction(tech_name(padv));
194}
195
196/**********************************************************************/
200{
201 if (padv == A_NEVER) {
202 return QString::fromUtf8(R__("Never"));
203 }
204
205 return QString::fromUtf8(advance_rule_name(padv));
206}
207
208/**********************************************************************/
212{
213 selected = adv;
214
215 if (selected != nullptr) {
216 QString dispn = QString::fromUtf8(untranslated_name(&(adv->name)));
217 QString rulen = QString::fromUtf8(rule_name_get(&(adv->name)));
218
219 name->setText(dispn);
220 rname->setText(rulen);
221
222 if (dispn == rulen) {
223 name->setEnabled(false);
224 same_name->setChecked(true);
225 } else {
226 same_name->setChecked(false);
227 name->setEnabled(true);
228 }
229
230 req1_button->setText(tech_name(adv->require[AR_ONE]));
231 req2_button->setText(tech_name(adv->require[AR_TWO]));
232 root_req_button->setText(tech_name(adv->require[AR_ROOT]));
233 } else {
234 name->setText(R__("None"));
235 rname->setText(R__("None"));
236 // FIXME: Could these be translated, or do we depend on
237 // them matching English rule_name of tech "None"?
238 req1_button->setText("None");
239 req2_button->setText("None");
240 root_req_button->setText("None");
241 same_name->setChecked(true);
242 name->setEnabled(false);
243 }
244}
245
246/**********************************************************************/
250{
252
253 if (!select_list.isEmpty()) {
255
256 tn_bytes = select_list.at(0)->text().toUtf8();
258 }
259}
260
261/**********************************************************************/
270
271/**********************************************************************/
280
281/**********************************************************************/
290
291/**********************************************************************/
295{
296 struct advance *padv;
298
299 an_bytes = action->text().toUtf8();
301
302 if (padv != 0 && selected != 0) {
304
306 }
307}
308
309/**********************************************************************/
313{
314 struct advance *padv;
316
317 an_bytes = action->text().toUtf8();
319
320 if (padv != 0 && selected != 0) {
322
324 }
325}
326
327/**********************************************************************/
331{
332 struct advance *padv;
334
335 an_bytes = action->text().toUtf8();
337
338 if (padv != 0 && selected != 0) {
340
342 }
343}
344
345/**********************************************************************/
349{
350 if (selected != nullptr) {
353
355 if (padv != selected
356 && padv->require[AR_ONE] != A_NEVER) {
357 rname_bytes = rname->text().toUtf8();
358 if (!strcmp(advance_rule_name(padv), rname_bytes.data())) {
359 ui->display_msg(R__("A tech with that rule name already exists!"));
360 return;
361 }
362 }
364
365 if (same_name->isChecked()) {
366 name->setText(rname->text());
367 }
368
369 name_bytes = name->text().toUtf8();
370 rname_bytes = rname->text().toUtf8();
371 names_set(&(selected->name), 0,
372 name_bytes.data(),
373 rname_bytes.data());
374 refresh();
375 }
376}
377
378/**********************************************************************/
382{
383 if (selected != 0) {
385
388 return;
389 }
390
392
393 if (selected->ruledit_dlg != nullptr) {
394 ((edit_tech *)selected->ruledit_dlg)->done(0);
395 }
396
397 refresh();
398 update_tech_info(nullptr);
399 }
400}
401
402/**********************************************************************/
406{
408
409 if (advance_by_rule_name("New Tech") != nullptr) {
410 return false;
411 }
412
413 padv->require[AR_ONE] = none;
414 padv->require[AR_TWO] = none;
415 padv->require[AR_ROOT] = none;
416 name_set(&(padv->name), 0, "New Tech");
417 BV_CLR_ALL(padv->flags);
418 if (padv->helptext != nullptr) {
419 strvec_clear(padv->helptext);
420 }
421
422 return true;
423}
424
425/**********************************************************************/
429{
430 struct advance *new_adv;
431
432 // Try to reuse freed tech slot
434 if (padv->require[AR_ONE] == A_NEVER) {
437 refresh();
438 }
439 return;
440 }
442
443 // Try to add completely new tech
445 return;
446 }
447
448 // num_tech_types must be big enough to hold new tech or
449 // advance_by_number() fails.
454 refresh();
455 } else {
456 game.control.num_tech_types--; // Restore
457 }
458}
459
460/**********************************************************************/
464{
465 name->setEnabled(!checked);
466 if (checked) {
467 name->setText(rname->text());
468 }
469}
470
471/**********************************************************************/
475{
476 if (selected != nullptr) {
477 struct universal uni;
478
479 uni.value.advance = selected;
480 uni.kind = VUT_ADVANCE;
481
482 ui->open_effect_edit(QString::fromUtf8(advance_rule_name(selected)),
483 &uni, EFMC_NORMAL);
484 }
485}
486
487/**********************************************************************/
491{
492 if (selected != nullptr) {
493 if (selected->ruledit_dlg == nullptr) {
495
496 edit->show();
498 } else {
499 ((edit_tech *)selected->ruledit_dlg)->raise();
500 }
501 }
502}
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
void display_msg(const char *msg)
requirers_dlg * create_requirers(const char *title)
void open_effect_edit(QString target, struct universal *uni, enum effect_filter_main_class efmc)
QCheckBox * same_name
Definition tab_tech.h:62
QToolButton * root_req_button
Definition tab_tech.h:57
ruledit_gui * ui
Definition tab_tech.h:48
void edit_now()
Definition tab_tech.cpp:490
void same_name_toggle(bool checked)
Definition tab_tech.cpp:463
bool initialize_new_tech(struct advance *padv)
Definition tab_tech.cpp:405
void select_tech()
Definition tab_tech.cpp:249
QToolButton * req1_button
Definition tab_tech.h:55
QLineEdit * rname
Definition tab_tech.h:54
void req1_menu(QAction *action)
Definition tab_tech.cpp:294
void edit_effects()
Definition tab_tech.cpp:474
void refresh()
Definition tab_tech.cpp:139
struct advance * selected
Definition tab_tech.h:64
void delete_now()
Definition tab_tech.cpp:381
QMenu * req1
Definition tab_tech.h:58
static void techs_to_menu(QMenu *fill_menu)
Definition tab_tech.cpp:187
QLineEdit * name
Definition tab_tech.h:53
void add_now()
Definition tab_tech.cpp:428
QMenu * prepare_req_button(QToolButton *button, enum tech_req rn)
Definition tab_tech.cpp:157
void req2_jump()
Definition tab_tech.cpp:274
void req2_menu(QAction *action)
Definition tab_tech.cpp:312
void root_req_menu(QAction *action)
Definition tab_tech.cpp:330
void req1_jump()
Definition tab_tech.cpp:264
void root_req_jump()
Definition tab_tech.cpp:284
void name_given()
Definition tab_tech.cpp:348
QToolButton * req2_button
Definition tab_tech.h:56
QMenu * root_req
Definition tab_tech.h:60
tab_tech(ruledit_gui *ui_in)
Definition tab_tech.cpp:46
static QString tech_name(struct advance *padv)
Definition tab_tech.cpp:199
QListWidget * tech_list
Definition tab_tech.h:61
QMenu * req2
Definition tab_tech.h:59
void update_tech_info(struct advance *adv)
Definition tab_tech.cpp:211
char * incite_cost
Definition comments.c:76
@ EFMC_NORMAL
Definition effect_edit.h:34
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
#define edit(pedit)
Definition widget_edit.h:34
#define fc_assert(condition)
Definition log.h:177
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * rule_name_get(const struct name_translation *ptrans)
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 ruledit_qt_display_requirers(const char *msg, void *data)
void strvec_clear(struct strvec *psv)
void * ruledit_dlg
Definition tech.h:122
struct advance * require[AR_SIZE]
Definition tech.h:127
struct name_translation name
Definition tech.h:121
struct packet_ruleset_control control
Definition game.h:83
Definition climisc.h:82
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_re_active_iterate(_p)
Definition tech.h:277
#define A_NEVER
Definition tech.h:51
#define advance_iterate_all_end
Definition tech.h:275
tech_req
Definition tech.h:105
@ AR_TWO
Definition tech.h:107
@ AR_ROOT
Definition tech.h:108
@ AR_ONE
Definition tech.h:106
@ AR_SIZE
Definition tech.h:109
#define advance_re_active_iterate_end
Definition tech.h:281
#define advance_iterate_all(_p)
Definition tech.h:274
#define A_NONE
Definition tech.h:43
#define advance_iterate(_p)
Definition tech.h:271
#define advance_iterate_end
Definition tech.h:272
#define A_LAST
Definition tech.h:45
struct advance * advance
Definition fc_types.h:543
bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data)
Definition validity.c:199