Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/edit_terrain.cpp Source File

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/**********************************************************************/
43edit_terrain::edit_terrain(ruledit_gui *ui_in, struct terrain *ter_in) : values_dlg()
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/**********************************************************************/
145 void edit_terrain::closeEvent(QCloseEvent *cevent)
146{
147 int rowcount;
148 int column;
149
150 close_help();
151
152 // Save values from text fields.
153 gfx_tag_given();
154 gfx_tag_alt_given();
155
156 BV_CLR_ALL(ter->native_to);
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
165 BV_CLR_ALL(ter->flags);
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/**********************************************************************/
187 void edit_terrain::refresh()
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/**********************************************************************/
198 void edit_terrain::set_mcost_value(int value)
199{
200 ter->movement_cost = value;
201
202 refresh();
203}
204
205/**********************************************************************/
208 void edit_terrain::set_defense_value(int value)
209{
210 ter->defense_bonus = value;
211
212 refresh();
213}
214
215/**********************************************************************/
218 void edit_terrain::gfx_tag_given()
219{
220 QByteArray tag_bytes = gfx_tag->text().toUtf8();
221
222 sz_strlcpy(ter->graphic_str, tag_bytes);
223}
224
225/**********************************************************************/
228 void edit_terrain::gfx_tag_alt_given()
229{
230 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
231
232 sz_strlcpy(ter->graphic_alt, tag_bytes);
233}
234
235/**********************************************************************/
238 void edit_terrain::helptext()
239{
240 open_help(&ter->helptext);
241}
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
edit_terrain::set_defense_value
void set_defense_value(int value)
Definition edit_terrain.cpp:208
edit_terrain::gfx_tag_given
void gfx_tag_given()
Definition edit_terrain.cpp:218
edit_terrain::helptext
void helptext()
Definition edit_terrain.cpp:238
edit_terrain::ter
struct terrain * ter
Definition edit_terrain.h:43
edit_terrain::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_terrain.cpp:228
edit_terrain::defense
QSpinBox * defense
Definition edit_terrain.h:45
edit_terrain::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_terrain.h:47
edit_terrain::mcost
QSpinBox * mcost
Definition edit_terrain.h:44
edit_terrain::flag_layout
QGridLayout * flag_layout
Definition edit_terrain.h:50
edit_terrain::ui
ruledit_gui * ui
Definition edit_terrain.h:42
edit_terrain::edit_terrain
edit_terrain(ruledit_gui *ui_in, struct terrain *ter_in)
Definition edit_terrain.cpp:43
edit_terrain::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_terrain.cpp:145
edit_terrain::refresh
void refresh()
Definition edit_terrain.cpp:187
edit_terrain::natives_layout
QGridLayout * natives_layout
Definition edit_terrain.h:49
edit_terrain::set_mcost_value
void set_mcost_value(int value)
Definition edit_terrain.cpp:198
edit_terrain::gfx_tag
QLineEdit * gfx_tag
Definition edit_terrain.h:46
ruledit_gui
Definition ruledit_qt.h:96
values_dlg
Definition values_dlg.h:28
values_dlg::close_help
void close_help()
Definition values_dlg.cpp:60
values_dlg::open_help
void open_help(struct strvec **help)
Definition values_dlg.cpp:38
FLAGROWS
#define FLAGROWS
Definition edit_extra.cpp:35
edit_terrain.h
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:57
game.h
ruledit.h
ruledit_qt.h
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
packet_ruleset_control::num_unit_classes
int num_unit_classes
Definition packets_gen.h:1455
terrain
Definition terrain.h:176
terrain::helptext
struct strvec * helptext
Definition terrain.h:249
terrain::flags
bv_terrain_flags flags
Definition terrain.h:245
terrain::native_to
bv_unit_classes native_to
Definition terrain.h:243
terrain::defense_bonus
int defense_bonus
Definition terrain.h:193
terrain::movement_cost
int movement_cost
Definition terrain.h:192
terrain::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:182
terrain::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:181
terrain::ruledit_dlg
void * ruledit_dlg
Definition terrain.h:180
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
tab_tech.h
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
terrain.h
uclass_by_number
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2524
uclass_rule_name
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693