Freeciv-3.2
Loading...
Searching...
No Matches
tab_terrains.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 "terrain.h"
34
35// ruledit
36#include "edit_terrain.h"
37#include "req_edit.h"
38#include "ruledit.h"
39#include "ruledit_qt.h"
40#include "validity.h"
41
42#include "tab_terrains.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 QPushButton *edit_button;
56 int row = 0;
57
58 ui = ui_in;
59 selected = 0;
60
61 terrain_list = new QListWidget(this);
62
64 main_layout->addWidget(terrain_list);
65
66 terrains_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 terrains_layout->addWidget(label, row, 0);
74 terrains_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 terrains_layout->addWidget(label, row, 0);
84 terrains_layout->addWidget(same_name, row, 1);
85 terrains_layout->addWidget(name, row++, 2);
86
87 edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this);
88 connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now()));
89 terrains_layout->addWidget(edit_button, row++, 2);
90
91 effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this);
92 connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects()));
93 terrains_layout->addWidget(effects_button, row++, 2);
94
95 add_button = new QPushButton(QString::fromUtf8(R__("Add Terrain")), this);
96 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
97 terrains_layout->addWidget(add_button, row, 0);
99
100 delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Terrain")), this);
101 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
102 terrains_layout->addWidget(delete_button, row++, 2);
103 show_experimental(delete_button);
104
105 refresh();
106 update_terrain_info(nullptr);
107
108 main_layout->addLayout(terrains_layout);
109
110 setLayout(main_layout);
111}
112
113/**********************************************************************/
117{
118 terrain_list->clear();
119
122 = new QListWidgetItem(QString::fromUtf8(terrain_rule_name(pterr)));
123
124 terrain_list->insertItem(terrain_index(pterr), item);
126}
127
128/**********************************************************************/
132{
133 selected = pterr;
134
135 if (selected != nullptr) {
136 QString dispn = QString::fromUtf8(untranslated_name(&(pterr->name)));
137 QString rulen = QString::fromUtf8(terrain_rule_name(pterr));
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 tn_bytes = select_list.at(0)->text().toUtf8();
168 }
169}
170
171/**********************************************************************/
175{
176 if (selected != nullptr) {
179
181 if (pterr != selected && !pterr->ruledit_disabled) {
182 rname_bytes = rname->text().toUtf8();
183 if (!strcmp(terrain_rule_name(pterr), rname_bytes.data())) {
184 ui->display_msg(R__("A terrain with that rule name already exists!"));
185 return;
186 }
187 }
189
190 if (same_name->isChecked()) {
191 name->setText(rname->text());
192 }
193
194 name_bytes = name->text().toUtf8();
195 rname_bytes = rname->text().toUtf8();
196 names_set(&(selected->name), 0,
197 name_bytes.data(),
198 rname_bytes.data());
199 refresh();
200 }
201}
202
203/**********************************************************************/
207{
208 if (selected != nullptr) {
210
213 return;
214 }
215
217
218 if (selected->ruledit_dlg != nullptr) {
219 ((edit_terrain *)selected->ruledit_dlg)->done(0);
220 }
221
222 refresh();
223 update_terrain_info(nullptr);
224 }
225}
226
227/**********************************************************************/
231{
232 if (terrain_by_rule_name("New Terrain") != nullptr) {
233 return false;
234 }
235
236 name_set(&(pterr->name), 0, "New Terrain");
237 BV_CLR_ALL(pterr->flags);
238 if (pterr->helptext != nullptr) {
239 strvec_clear(pterr->helptext);
240 }
241
242 return true;
243}
244
245/**********************************************************************/
249{
250 struct terrain *new_terr;
251
252 // Try to reuse freed terrain slot
254 if (pterr->ruledit_disabled) {
256 pterr->ruledit_disabled = false;
258 refresh();
259 }
260 return;
261 }
263
264 // Try to add completely new terrain
266 return;
267 }
268
269 // terrain_count must be big enough to hold new extra or
270 // terrain_by_number() fails.
275
276 refresh();
277 } else {
278 game.control.terrain_count--; // Restore
279 }
280}
281
282/**********************************************************************/
286{
287 name->setEnabled(!checked);
288 if (checked) {
289 name->setText(rname->text());
290 }
291}
292
293/**********************************************************************/
297{
298 if (selected != nullptr) {
299 struct universal uni;
300
301 uni.value.terrain = selected;
302 uni.kind = VUT_TERRAIN;
303
304 ui->open_effect_edit(QString::fromUtf8(terrain_rule_name(selected)),
305 &uni, EFMC_NORMAL);
306 }
307}
308
309/**********************************************************************/
313{
314 if (selected != nullptr) {
315 if (selected->ruledit_dlg == nullptr) {
317
318 edit->show();
320 } else {
321 ((edit_terrain *)selected->ruledit_dlg)->raise();
322 }
323 }
324}
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
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)
void same_name_toggle(bool checked)
QLineEdit * rname
tab_terrains(ruledit_gui *ui_in)
bool initialize_new_terrain(struct terrain *pterr)
QLineEdit * name
void select_terrain()
struct terrain * selected
void update_terrain_info(struct terrain *pterr)
QCheckBox * same_name
ruledit_gui * ui
QListWidget * terrain_list
char * incite_cost
Definition comments.c:75
@ EFMC_NORMAL
Definition effect_edit.h:34
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
#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
Definition climisc.h:82
struct name_translation name
Definition terrain.h:184
void * ruledit_dlg
Definition terrain.h:186
bool ruledit_disabled
Definition terrain.h:185
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:186
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:138
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
#define terrain_type_iterate(_p)
Definition terrain.h:373
#define terrain_re_active_iterate_end
Definition terrain.h:388
#define terrain_re_active_iterate(_p)
Definition terrain.h:384
#define terrain_type_iterate_end
Definition terrain.h:379
#define MAX_NUM_TERRAINS
Definition terrain.h:64
struct terrain * terrain
Definition fc_types.h:719
bool is_terrain_needed(struct terrain *pterr, requirers_cb cb, void *data)
Definition validity.c:331