Freeciv-3.2
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);
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
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);
95
96 ter_layout->addWidget(label, row, 0);
97 ter_layout->addWidget(gfx_tag_alt, row++, 1);
98
99 label = new QLabel(QString::fromUtf8(R__("Second alt graphics tag")));
100 label->setParent(this);
101
102 gfx_tag_alt2 = new QLineEdit(this);
104
105 ter_layout->addWidget(label, row, 0);
106 ter_layout->addWidget(gfx_tag_alt2, row++, 1);
107
108 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
109 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
110 ter_layout->addWidget(button, row++, 1);
111
112 label = new QLabel(QString::fromUtf8(R__("Native to")));
113 natives_layout->addWidget(label, 0, 0);
114 for (int i = 0; i < game.control.num_unit_classes; i++) {
115 QCheckBox *check = new QCheckBox();
116
117 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
118 natives_layout->addWidget(label, i + 1, 0);
119
120 check->setChecked(BV_ISSET(ter->native_to, i));
121 natives_layout->addWidget(check, i + 1, 1);
122 }
123
124 rowcount = 0;
125 column = 0;
126 for (int i = 0; i < TER_USER_LAST; i++) {
127 enum terrain_flag_id flag = (enum terrain_flag_id)i;
128 QCheckBox *check = new QCheckBox();
129
130 label = new QLabel(terrain_flag_id_name(flag));
131 flag_layout->addWidget(label, rowcount, column + 1);
132
133 check->setChecked(BV_ISSET(ter->flags, flag));
134 flag_layout->addWidget(check, rowcount, column);
135
136 if (++rowcount >= FLAGROWS) {
137 column += 2;
138 rowcount = 0;
139 }
140 }
141
142 refresh();
143
144 main_layout->addLayout(ter_layout);
145 main_layout->addLayout(natives_layout);
146 main_layout->addLayout(flag_layout);
147
148 setLayout(main_layout);
149}
150
151/**********************************************************************/
155{
156 int rowcount;
157 int column;
158
159 close_help();
160
161 // Save values from text fields.
165
167 for (int i = 0; i < game.control.num_unit_classes; i++) {
168 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
169
170 if (check->isChecked()) {
172 }
173 }
174
176 rowcount = 0;
177 column = 0;
178 for (int i = 0; i < TER_USER_LAST; i++) {
179 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
180
181 if (check->isChecked()) {
182 BV_SET(ter->flags, i);
183 }
184
185 if (++rowcount >= FLAGROWS) {
186 rowcount = 0;
187 column += 2;
188 }
189 }
190
191 ter->ruledit_dlg = nullptr;
192}
193
194/**********************************************************************/
198{
199 mcost->setValue(ter->movement_cost);
200 defense->setValue(ter->defense_bonus);
201 gfx_tag->setText(ter->graphic_str);
202 gfx_tag_alt->setText(ter->graphic_alt);
203 gfx_tag_alt2->setText(ter->graphic_alt2);
204}
205
206/**********************************************************************/
210{
211 ter->movement_cost = value;
212
213 refresh();
214}
215
216/**********************************************************************/
220{
221 ter->defense_bonus = value;
222
223 refresh();
224}
225
226/**********************************************************************/
230{
231 QByteArray tag_bytes = gfx_tag->text().toUtf8();
232
234}
235
236/**********************************************************************/
245
246/**********************************************************************/
255
256/**********************************************************************/
#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)
QLineEdit * gfx_tag_alt2
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 gfx_tag_alt2_given()
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)
char * incite_cost
Definition comments.c:75
#define FLAGROWS
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
struct packet_ruleset_control control
Definition game.h:83
struct strvec * helptext
Definition terrain.h:263
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:189
bv_terrain_flags flags
Definition terrain.h:259
bv_unit_classes native_to
Definition terrain.h:257
int defense_bonus
Definition terrain.h:200
int movement_cost
Definition terrain.h:199
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:188
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:187
void * ruledit_dlg
Definition terrain.h:186
#define sz_strlcpy(dest, src)
Definition support.h:195
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2477
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641