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 <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/**********************************************************************/
42edit_terrain::edit_terrain(ruledit_gui *ui_in, struct terrain *ter_in) : QDialog()
43{
44 QHBoxLayout *main_layout = new QHBoxLayout(this);
45 QGridLayout *ter_layout = new QGridLayout();
46 QLabel *label;
47 int row = 0;
48 int rowcount;
49 int column;
50
51 ui = ui_in;
52 ter = ter_in;
53
54 natives_layout = new QGridLayout();
55 flag_layout = new QGridLayout();
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);
92 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
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__("Native to")));
98 natives_layout->addWidget(label, 0, 0);
99 for (int i = 0; i < game.control.num_unit_classes; i++) {
100 QCheckBox *check = new QCheckBox();
101
102 label = new QLabel(uclass_rule_name(uclass_by_number(i)));
103 natives_layout->addWidget(label, i + 1, 0);
104
105 check->setChecked(BV_ISSET(ter->native_to, i));
106 natives_layout->addWidget(check, i + 1, 1);
107 }
108
109 rowcount = 0;
110 column = 0;
111 for (int i = 0; i < TER_USER_LAST; i++) {
112 enum terrain_flag_id flag = (enum terrain_flag_id)i;
113 QCheckBox *check = new QCheckBox();
114
115 label = new QLabel(terrain_flag_id_name(flag));
116 flag_layout->addWidget(label, rowcount, column + 1);
117
118 check->setChecked(BV_ISSET(ter->flags, flag));
119 flag_layout->addWidget(check, rowcount, column);
120
121 if (++rowcount >= FLAGROWS) {
122 column += 2;
123 rowcount = 0;
124 }
125 }
126
127 refresh();
128
129 main_layout->addLayout(ter_layout);
130 main_layout->addLayout(natives_layout);
131 main_layout->addLayout(flag_layout);
132
133 setLayout(main_layout);
134}
135
136/**********************************************************************/
139 void edit_terrain::closeEvent(QCloseEvent *cevent)
140{
141 int rowcount;
142 int column;
143
144 // Save values from text fields.
145 gfx_tag_given();
146 gfx_tag_alt_given();
147
148 BV_CLR_ALL(ter->native_to);
149 for (int i = 0; i < game.control.num_unit_classes; i++) {
150 QCheckBox *check = static_cast<QCheckBox *>(natives_layout->itemAtPosition(i + 1, 1)->widget());
151
152 if (check->isChecked()) {
153 BV_SET(ter->native_to, i);
154 }
155 }
156
157 BV_CLR_ALL(ter->flags);
158 rowcount = 0;
159 column = 0;
160 for (int i = 0; i < TER_USER_LAST; i++) {
161 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
162
163 if (check->isChecked()) {
164 BV_SET(ter->flags, i);
165 }
166
167 if (++rowcount >= FLAGROWS) {
168 rowcount = 0;
169 column += 2;
170 }
171 }
172
173 ter->ruledit_dlg = nullptr;
174}
175
176/**********************************************************************/
179 void edit_terrain::refresh()
180{
181 mcost->setValue(ter->movement_cost);
182 defense->setValue(ter->defense_bonus);
183 gfx_tag->setText(ter->graphic_str);
184 gfx_tag_alt->setText(ter->graphic_alt);
185}
186
187/**********************************************************************/
190 void edit_terrain::set_mcost_value(int value)
191{
192 ter->movement_cost = value;
193
194 refresh();
195}
196
197/**********************************************************************/
200 void edit_terrain::set_defense_value(int value)
201{
202 ter->defense_bonus = value;
203
204 refresh();
205}
206
207/**********************************************************************/
210 void edit_terrain::gfx_tag_given()
211{
212 QByteArray tag_bytes = gfx_tag->text().toUtf8();
213
214 sz_strlcpy(ter->graphic_str, tag_bytes);
215}
216
217/**********************************************************************/
220 void edit_terrain::gfx_tag_alt_given()
221{
222 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
223
224 sz_strlcpy(ter->graphic_alt, tag_bytes);
225}
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:200
edit_terrain::gfx_tag_given
void gfx_tag_given()
Definition edit_terrain.cpp:210
edit_terrain::ter
struct terrain * ter
Definition edit_terrain.h:40
edit_terrain::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_terrain.cpp:220
edit_terrain::defense
QSpinBox * defense
Definition edit_terrain.h:42
edit_terrain::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_terrain.h:44
edit_terrain::mcost
QSpinBox * mcost
Definition edit_terrain.h:41
edit_terrain::flag_layout
QGridLayout * flag_layout
Definition edit_terrain.h:47
edit_terrain::ui
ruledit_gui * ui
Definition edit_terrain.h:39
edit_terrain::edit_terrain
edit_terrain(ruledit_gui *ui_in, struct terrain *ter_in)
Definition edit_terrain.cpp:42
edit_terrain::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_terrain.cpp:139
edit_terrain::refresh
void refresh()
Definition edit_terrain.cpp:179
edit_terrain::natives_layout
QGridLayout * natives_layout
Definition edit_terrain.h:46
edit_terrain::set_mcost_value
void set_mcost_value(int value)
Definition edit_terrain.cpp:190
edit_terrain::gfx_tag
QLineEdit * gfx_tag
Definition edit_terrain.h:43
ruledit_gui
Definition ruledit_qt.h:96
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::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