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 <QSpinBox>
23#include <QToolButton>
24
25// common
26#include "game.h"
27#include "terrain.h"
28
29// ruledit
30#include "ruledit.h"
31#include "ruledit_qt.h"
32#include "tab_tech.h"
33
34#include "edit_terrain.h"
35
36
37#define FLAGROWS 15
38
39/**********************************************************************/
43{
44 QHBoxLayout *main_layout = new QHBoxLayout(this);
46 QLabel *label;
47 int row = 0;
48 int rowcount;
49 int column;
50
51 ui = ui_in;
52 ter = ter_in;
53
56
57 setWindowTitle(QString::fromUtf8(terrain_rule_name(ter)));
58
59 label = new QLabel(QString::fromUtf8(R__("Move Cost")));
60 label->setParent(this);
61
62 mcost = new QSpinBox(this);
63 mcost->setRange(0, 100);
64 connect(mcost, SIGNAL(valueChanged(int)), this, SLOT(set_mcost_value(int)));
65
66 ter_layout->addWidget(label, row, 0);
67 ter_layout->addWidget(mcost, row++, 1);
68
69 label = new QLabel(QString::fromUtf8(R__("Defense Bonus %")));
70 label->setParent(this);
71
72 defense = new QSpinBox(this);
73 defense->setRange(0, 1000);
74 connect(defense, SIGNAL(valueChanged(int)), this, SLOT(set_defense_value(int)));
75
76 ter_layout->addWidget(label, row, 0);
77 ter_layout->addWidget(defense, row++, 1);
78
79 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
80 label->setParent(this);
81
82 gfx_tag = new QLineEdit(this);
83 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
84
85 ter_layout->addWidget(label, row, 0);
86 ter_layout->addWidget(gfx_tag, row++, 1);
87
88 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
89 label->setParent(this);
90
91 gfx_tag_alt = new QLineEdit(this);
93
94 ter_layout->addWidget(label, row, 0);
95 ter_layout->addWidget(gfx_tag_alt, row++, 1);
96
97 label = new QLabel(QString::fromUtf8(R__("Second alt graphics tag")));
98 label->setParent(this);
99
100 gfx_tag_alt2 = new QLineEdit(this);
102
103 ter_layout->addWidget(label, row, 0);
104 ter_layout->addWidget(gfx_tag_alt2, row++, 1);
105
106 label = new QLabel(QString::fromUtf8(R__("Native to")));
107 natives_layout->addWidget(label, 0, 0);
108 for (int i = 0; i < game.control.num_unit_classes; i++) {
109 QCheckBox *check = new QCheckBox();
110
111 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
112 natives_layout->addWidget(label, i + 1, 0);
113
114 check->setChecked(BV_ISSET(ter->native_to, i));
115 natives_layout->addWidget(check, i + 1, 1);
116 }
117
118 rowcount = 0;
119 column = 0;
120 for (int i = 0; i < TER_USER_LAST; i++) {
121 enum terrain_flag_id flag = (enum terrain_flag_id)i;
122 QCheckBox *check = new QCheckBox();
123
124 label = new QLabel(terrain_flag_id_name(flag));
125 flag_layout->addWidget(label, rowcount, column + 1);
126
127 check->setChecked(BV_ISSET(ter->flags, flag));
128 flag_layout->addWidget(check, rowcount, column);
129
130 if (++rowcount >= FLAGROWS) {
131 column += 2;
132 rowcount = 0;
133 }
134 }
135
136 refresh();
137
138 main_layout->addLayout(ter_layout);
139 main_layout->addLayout(natives_layout);
140 main_layout->addLayout(flag_layout);
141
142 setLayout(main_layout);
143}
144
145/**********************************************************************/
149{
150 int rowcount;
151 int column;
152
153 // Save values from text fields.
157
159 for (int i = 0; i < game.control.num_unit_classes; i++) {
160 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
161
162 if (check->isChecked()) {
164 }
165 }
166
168 rowcount = 0;
169 column = 0;
170 for (int i = 0; i < TER_USER_LAST; i++) {
171 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
172
173 if (check->isChecked()) {
174 BV_SET(ter->flags, i);
175 }
176
177 if (++rowcount >= FLAGROWS) {
178 rowcount = 0;
179 column += 2;
180 }
181 }
182
183 ter->ruledit_dlg = nullptr;
184}
185
186/**********************************************************************/
190{
191 mcost->setValue(ter->movement_cost);
192 defense->setValue(ter->defense_bonus);
193 gfx_tag->setText(ter->graphic_str);
194 gfx_tag_alt->setText(ter->graphic_alt);
195 gfx_tag_alt2->setText(ter->graphic_alt2);
196}
197
198/**********************************************************************/
202{
203 ter->movement_cost = value;
204
205 refresh();
206}
207
208/**********************************************************************/
212{
213 ter->defense_bonus = value;
214
215 refresh();
216}
217
218/**********************************************************************/
222{
223 QByteArray tag_bytes = gfx_tag->text().toUtf8();
224
226}
227
228/**********************************************************************/
237
238/**********************************************************************/
#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
char * incite_cost
Definition comments.c:74
#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
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:189
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:2476
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641