Freeciv-3.1
Loading...
Searching...
No Matches
edit_terrain.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2023 The Freeciv Team
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 <QPushButton>
23#include <QSpinBox>
24#include <QToolButton>
25
26// common
27#include "game.h"
28#include "terrain.h"
29
30// ruledit
31#include "ruledit.h"
32#include "ruledit_qt.h"
33#include "tab_tech.h"
34
35#include "edit_terrain.h"
36
37
38#define FLAGROWS 15
39
40/**********************************************************************/
44{
45 QHBoxLayout *main_layout = new QHBoxLayout(this);
46 QGridLayout *ter_layout = new QGridLayout();
47 QLabel *label;
48 QPushButton *button;
49 int row = 0;
50 int rowcount;
51 int column;
52
53 ui = ui_in;
54 ter = ter_in;
55
56 natives_layout = new QGridLayout();
57 flag_layout = new QGridLayout();
58
59 setWindowTitle(QString::fromUtf8(terrain_rule_name(ter)));
60
61 label = new QLabel(QString::fromUtf8(R__("Move Cost")));
62 label->setParent(this);
63
64 mcost = new QSpinBox(this);
65 mcost->setRange(0, 100);
66 connect(mcost, SIGNAL(valueChanged(int)), this, SLOT(set_mcost_value(int)));
67
68 ter_layout->addWidget(label, row, 0);
69 ter_layout->addWidget(mcost, row++, 1);
70
71 label = new QLabel(QString::fromUtf8(R__("Defense Bonus %")));
72 label->setParent(this);
73
74 defense = new QSpinBox(this);
75 defense->setRange(0, 1000);
76 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
77
78 ter_layout->addWidget(label, row, 0);
79 ter_layout->addWidget(defense, row++, 1);
80
81 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
82 label->setParent(this);
83
84 gfx_tag = new QLineEdit(this);
85 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
86
87 ter_layout->addWidget(label, row, 0);
88 ter_layout->addWidget(gfx_tag, row++, 1);
89
90 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
91 label->setParent(this);
92
93 gfx_tag_alt = new QLineEdit(this);
94 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
95
96 ter_layout->addWidget(label, row, 0);
97 ter_layout->addWidget(gfx_tag_alt, row++, 1);
98
99 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
100 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
101 ter_layout->addWidget(button, row++, 1);
102
103 label = new QLabel(QString::fromUtf8(R__("Native to")));
104 natives_layout->addWidget(label, 0, 0);
105 for (int i = 0; i < game.control.num_unit_classes; i++) {
106 QCheckBox *check = new QCheckBox();
107
108 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
109 natives_layout->addWidget(label, i + 1, 0);
110
111 check->setChecked(BV_ISSET(ter->native_to, i));
112 natives_layout->addWidget(check, i + 1, 1);
113 }
114
115 rowcount = 0;
116 column = 0;
117 for (int i = 0; i < TER_USER_LAST; i++) {
118 enum terrain_flag_id flag = (enum terrain_flag_id)i;
119 QCheckBox *check = new QCheckBox();
120
121 label = new QLabel(terrain_flag_id_name(flag));
122 flag_layout->addWidget(label, rowcount, column + 1);
123
124 check->setChecked(BV_ISSET(ter->flags, flag));
125 flag_layout->addWidget(check, rowcount, column);
126
127 if (++rowcount >= FLAGROWS) {
128 column += 2;
129 rowcount = 0;
130 }
131 }
132
133 refresh();
134
135 main_layout->addLayout(ter_layout);
136 main_layout->addLayout(natives_layout);
137 main_layout->addLayout(flag_layout);
138
139 setLayout(main_layout);
140}
141
142/**********************************************************************/
145void edit_terrain::closeEvent(QCloseEvent *cevent)
146{
147 int rowcount;
148 int column;
149
150 close_help();
151
152 // Save values from text fields.
155
157 for (int i = 0; i < game.control.num_unit_classes; i++) {
158 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
159
160 if (check->isChecked()) {
161 BV_SET(ter->native_to, i);
162 }
163 }
164
166 rowcount = 0;
167 column = 0;
168 for (int i = 0; i < TER_USER_LAST; i++) {
169 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
170
171 if (check->isChecked()) {
172 BV_SET(ter->flags, i);
173 }
174
175 if (++rowcount >= FLAGROWS) {
176 rowcount = 0;
177 column += 2;
178 }
179 }
180
181 ter->ruledit_dlg = nullptr;
182}
183
184/**********************************************************************/
188{
189 mcost->setValue(ter->movement_cost);
190 defense->setValue(ter->defense_bonus);
191 gfx_tag->setText(ter->graphic_str);
192 gfx_tag_alt->setText(ter->graphic_alt);
193}
194
195/**********************************************************************/
199{
200 ter->movement_cost = value;
201
202 refresh();
203}
204
205/**********************************************************************/
209{
210 ter->defense_bonus = value;
211
212 refresh();
213}
214
215/**********************************************************************/
219{
220 QByteArray tag_bytes = gfx_tag->text().toUtf8();
221
222 sz_strlcpy(ter->graphic_str, tag_bytes);
223}
224
225/**********************************************************************/
229{
230 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
231
232 sz_strlcpy(ter->graphic_alt, tag_bytes);
233}
234
235/**********************************************************************/
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
void set_defense_value(int value)
struct terrain * ter
void gfx_tag_alt_given()
QSpinBox * defense
QLineEdit * gfx_tag_alt
QSpinBox * mcost
QGridLayout * flag_layout
ruledit_gui * ui
edit_terrain(ruledit_gui *ui_in, struct terrain *ter_in)
void closeEvent(QCloseEvent *cevent)
QGridLayout * natives_layout
void set_mcost_value(int value)
QLineEdit * gfx_tag
void close_help()
void open_help(struct strvec **help)
#define FLAGROWS
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:57
struct packet_ruleset_control control
Definition game.h:83
struct strvec * helptext
Definition terrain.h:249
bv_terrain_flags flags
Definition terrain.h:245
bv_unit_classes native_to
Definition terrain.h:243
int defense_bonus
Definition terrain.h:193
int movement_cost
Definition terrain.h:192
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:182
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:181
void * ruledit_dlg
Definition terrain.h:180
#define sz_strlcpy(dest, src)
Definition support.h:167
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2525
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693