Freeciv-3.3
Loading...
Searching...
No Matches
tab_achievement.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 <QSpinBox>
26#include <QToolButton>
27
28// utility
29#include "fcintl.h"
30#include "log.h"
31
32// common
33#include "achievements.h"
34#include "game.h"
35
36// ruledit
37#include "req_edit.h"
38#include "ruledit.h"
39#include "ruledit_qt.h"
40#include "validity.h"
41
42#include "tab_achievement.h"
43
44/**********************************************************************/
48{
49 QVBoxLayout *main_layout = new QVBoxLayout(this);
51 QLabel *label;
52 QPushButton *effects_button;
53 QPushButton *add_button;
54 QPushButton *delete_button;
55 int row = 0;
56
57 ui = ui_in;
58 selected = nullptr;
59
60 ach_list = new QListWidget(this);
61
62 connect(ach_list,
64 main_layout->addWidget(ach_list);
65
66 ach_layout->setSizeConstraint(QLayout::SetMaximumSize);
67
68 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
69 label->setParent(this);
70 rname = new QLineEdit(this);
71 rname->setText(R__("None"));
72 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
73 ach_layout->addWidget(label, row, 0);
74 ach_layout->addWidget(rname, row++, 2);
75
76 label = new QLabel(QString::fromUtf8(R__("Name")));
77 label->setParent(this);
78 same_name = new QCheckBox();
79 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
80 name = new QLineEdit(this);
81 name->setText(R__("None"));
82 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
83 ach_layout->addWidget(label, row, 0);
84 ach_layout->addWidget(same_name, row, 1);
85 ach_layout->addWidget(name, row++, 2);
86
87 label = new QLabel(QString::fromUtf8(R__("Type")));
88 label->setParent(this);
89
91 type_menu = new QMenu();
92
93 for (int ach = 0; ach < ACHIEVEMENT_COUNT; ach++) {
94 type_menu->addAction(achievement_type_name(static_cast<enum achievement_type>(ach)));
95 }
96
97 connect(type_menu, SIGNAL(triggered(QAction *)),
98 this, SLOT(edit_type(QAction *)));
99
100 type_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
101 type_button->setPopupMode(QToolButton::MenuButtonPopup);
102 type_button->setMenu(type_menu);
103 type_button->setText(R__("None"));
104
105 ach_layout->addWidget(label, row, 0);
106 ach_layout->addWidget(type_button, row++, 2);
107
108 label = new QLabel(QString::fromUtf8(R__("Value")));
109 label->setParent(this);
110
111 value_box = new QSpinBox(this);
112 value_box->setRange(-1000, 1000);
113 connect(value_box, SIGNAL(valueChanged(int)), this, SLOT(set_value(int)));
114
115 ach_layout->addWidget(label, row, 0);
116 ach_layout->addWidget(value_box, row++, 2);
117
118 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
119 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
120 ach_layout->addWidget(effects_button, row++, 2);
121
122 add_button = new QPushButton(QString::fromUtf8(R__("Add Achievement")), this);
123 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
124 ach_layout->addWidget(add_button, row, 0);
126
127 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Achievement")),
128 this);
129 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
130 ach_layout->addWidget(delete_button, row++, 2);
131 show_experimental(delete_button);
132
133 refresh();
135
136 main_layout->addLayout(ach_layout);
137
138 setLayout(main_layout);
139}
140
141/**********************************************************************/
155
156/**********************************************************************/
160{
161 selected = pach;
162
163 if (selected != nullptr) {
164 QString dispn = QString::fromUtf8(untranslated_name(&(pach->name)));
165 QString rulen = QString::fromUtf8(achievement_rule_name(pach));
166 QString tname = QString::fromUtf8(achievement_type_name(pach->type));
167
168 name->setText(dispn);
169 rname->setText(rulen);
170 if (dispn == rulen) {
171 name->setEnabled(false);
172 same_name->setChecked(true);
173 } else {
174 same_name->setChecked(false);
175 name->setEnabled(true);
176 }
177
178 type_button->setText(tname);
179 value_box->setValue(pach->value);
180 } else {
181 name->setText(R__("None"));
182 rname->setText(R__("None"));
183 type_button->setText(R__("None"));
184 value_box->setValue(0);
185 same_name->setChecked(true);
186 name->setEnabled(false);
187 }
188}
189
190/**********************************************************************/
194{
196
197 if (!select_list.isEmpty()) {
199
200 gn_bytes = select_list.at(0)->text().toUtf8();
202 }
203}
204
205/**********************************************************************/
209{
210 if (selected != nullptr) {
213
215 if (pach != selected && !pach->ruledit_disabled) {
216 rname_bytes = rname->text().toUtf8();
218 ui->display_msg(R__("An achievement with that rule name already exists!"));
219 return;
220 }
221 }
223
224 if (same_name->isChecked()) {
225 name->setText(rname->text());
226 }
227
228 name_bytes = name->text().toUtf8();
229 rname_bytes = rname->text().toUtf8();
230 names_set(&(selected->name), 0,
231 name_bytes.data(),
232 rname_bytes.data());
233 refresh();
234 }
235}
236
237/**********************************************************************/
257
258/**********************************************************************/
262{
263 if (achievement_by_rule_name("New Achievement") != nullptr) {
264 return false;
265 }
266
267 name_set(&(pach->name), 0, "New Achievement");
268
269 return true;
270}
271
272/**********************************************************************/
276{
277 struct achievement *new_ach;
278
279 // Try to reuse freed achievement slot
281 if (pach->ruledit_disabled) {
283 pach->ruledit_disabled = false;
285 refresh();
286 }
287 return;
288 }
290
291 // Try to add completely new achievement
293 return;
294 }
295
296 // num_achievement_types must be big enough to hold new achievement or
297 // achievement_by_number() fails.
302
303 refresh();
304 } else {
306 }
307}
308
309/**********************************************************************/
313{
314 name->setEnabled(!checked);
315 if (checked) {
316 name->setText(rname->text());
317 }
318}
319
320/**********************************************************************/
324{
325 if (selected != nullptr) {
326 struct universal uni;
327
329 uni.kind = VUT_ACHIEVEMENT;
330
332 &uni, EFMC_NORMAL);
333 }
334}
335
336/**********************************************************************/
340{
341 enum achievement_type ach;
343
344 an_bytes = action->text().toUtf8();
346
347 if (selected != nullptr && achievement_type_is_valid(ach)) {
348 selected->type = ach;
349
350 // Show the changes.
352 refresh();
353 }
354}
355
356/**********************************************************************/
360{
361 if (selected != nullptr) {
362 selected->value = value;
363
364 // Show the changes.
366 }
367}
int achievement_index(const struct achievement *pach)
struct achievement * achievement_by_number(int id)
const char * achievement_rule_name(struct achievement *pach)
struct achievement * achievement_by_rule_name(const char *name)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
#define achievements_re_active_iterate(_p)
#define achievements_re_active_iterate_end
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)
bool initialize_new_achievement(struct achievement *pach)
void set_value(int value)
void update_achievement_info(struct achievement *pach)
QToolButton * type_button
void same_name_toggle(bool checked)
QCheckBox * same_name
tab_achievement(ruledit_gui *ui_in)
ruledit_gui * ui
QSpinBox * value_box
void edit_type(QAction *action)
QListWidget * ach_list
struct achievement * selected
QLineEdit * rname
char * incite_cost
Definition comments.c:76
@ EFMC_NORMAL
Definition effect_edit.h:34
#define MAX_ACHIEVEMENT_TYPES
Definition fc_types.h:53
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:61
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)
enum achievement_type type
struct name_translation name
bool ruledit_disabled
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
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
struct achievement * achievement
Definition fc_types.h:555
bool is_achievement_needed(struct achievement *pach, requirers_cb cb, void *data)
Definition validity.c:273