Freeciv-3.2
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 <QToolButton>
26
27// utility
28#include "fcintl.h"
29#include "log.h"
30
31// common
32#include "achievements.h"
33#include "game.h"
34
35// ruledit
36#include "req_edit.h"
37#include "ruledit.h"
38#include "ruledit_qt.h"
39#include "validity.h"
40
41#include "tab_achievement.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
55 ui = ui_in;
56 selected = nullptr;
57
58 ach_list = new QListWidget(this);
59
60 connect(ach_list,
62 main_layout->addWidget(ach_list);
63
64 ach_layout->setSizeConstraint(QLayout::SetMaximumSize);
65
66 label = new QLabel(QString::fromUtf8(R__("Rule Name")));
67 label->setParent(this);
68 rname = new QLineEdit(this);
69 rname->setText(R__("None"));
70 connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given()));
71 ach_layout->addWidget(label, 0, 0);
72 ach_layout->addWidget(rname, 0, 2);
73
74 label = new QLabel(QString::fromUtf8(R__("Name")));
75 label->setParent(this);
76 same_name = new QCheckBox();
77 connect(same_name, SIGNAL(toggled(bool)), this, SLOT(same_name_toggle(bool)));
78 name = new QLineEdit(this);
79 name->setText(R__("None"));
80 connect(name, SIGNAL(returnPressed()), this, SLOT(name_given()));
81 ach_layout->addWidget(label, 1, 0);
82 ach_layout->addWidget(same_name, 1, 1);
83 ach_layout->addWidget(name, 1, 2);
84
85 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
86 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
87 ach_layout->addWidget(effects_button, 3, 2);
88
89 add_button = new QPushButton(QString::fromUtf8(R__("Add Achievement")), this);
90 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
91 ach_layout->addWidget(add_button, 4, 0);
93
94 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Achievement")),
95 this);
96 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
97 ach_layout->addWidget(delete_button, 4, 2);
98 show_experimental(delete_button);
99
100 refresh();
102
103 main_layout->addLayout(ach_layout);
104
105 setLayout(main_layout);
106}
107
108/**********************************************************************/
122
123/**********************************************************************/
127{
128 selected = pach;
129
130 if (selected != 0) {
131 QString dispn = QString::fromUtf8(untranslated_name(&(pach->name)));
132 QString rulen = QString::fromUtf8(achievement_rule_name(pach));
133
134 name->setText(dispn);
135 rname->setText(rulen);
136 if (dispn == rulen) {
137 name->setEnabled(false);
138 same_name->setChecked(true);
139 } else {
140 same_name->setChecked(false);
141 name->setEnabled(true);
142 }
143 } else {
144 name->setText(R__("None"));
145 rname->setText(R__("None"));
146 same_name->setChecked(true);
147 name->setEnabled(false);
148 }
149}
150
151/**********************************************************************/
155{
157
158 if (!select_list.isEmpty()) {
160
161 gn_bytes = select_list.at(0)->text().toUtf8();
163 }
164}
165
166/**********************************************************************/
170{
171 if (selected != nullptr) {
174
176 if (pach != selected && !pach->ruledit_disabled) {
177 rname_bytes = rname->text().toUtf8();
179 ui->display_msg(R__("An achievement with that rule name already exists!"));
180 return;
181 }
182 }
184
185 if (same_name->isChecked()) {
186 name->setText(rname->text());
187 }
188
189 name_bytes = name->text().toUtf8();
190 rname_bytes = rname->text().toUtf8();
191 names_set(&(selected->name), 0,
192 name_bytes.data(),
193 rname_bytes.data());
194 refresh();
195 }
196}
197
198/**********************************************************************/
218
219/**********************************************************************/
223{
224 if (achievement_by_rule_name("New Achievement") != nullptr) {
225 return false;
226 }
227
228 name_set(&(pach->name), 0, "New Achievement");
229
230 return true;
231}
232
233/**********************************************************************/
237{
238 struct achievement *new_ach;
239
240 // Try to reuse freed achievement slot
242 if (pach->ruledit_disabled) {
244 pach->ruledit_disabled = false;
246 refresh();
247 }
248 return;
249 }
251
252 // Try to add completely new achievement
254 return;
255 }
256
257 // num_achievement_types must be big enough to hold new achievement or
258 // achievement_by_number() fails.
263
264 refresh();
265 } else {
267 }
268}
269
270/**********************************************************************/
274{
275 name->setEnabled(!checked);
276 if (checked) {
277 name->setText(rname->text());
278 }
279}
280
281/**********************************************************************/
285{
286 if (selected != nullptr) {
287 struct universal uni;
288
290 uni.kind = VUT_ACHIEVEMENT;
291
293 &uni, EFMC_NORMAL);
294 }
295}
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 update_achievement_info(struct achievement *pach)
void same_name_toggle(bool checked)
QCheckBox * same_name
tab_achievement(ruledit_gui *ui_in)
ruledit_gui * ui
QListWidget * ach_list
struct achievement * selected
QLineEdit * rname
char * incite_cost
Definition comments.c:74
@ 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:62
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 name_translation name
bool ruledit_disabled
struct packet_ruleset_control control
Definition game.h:83
Definition climisc.h:80
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
struct achievement * achievement
Definition fc_types.h:726
bool is_achievement_needed(struct achievement *pach, requirers_cb cb, void *data)
Definition validity.c:273