-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachinesettings.cpp
289 lines (265 loc) · 10.9 KB
/
machinesettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include "machinesettings.h"
#include "ui_machinesettings.h"
void setIconForLabel(QString image_name, QLabel* label) {
QPixmap icon(image_name);
int w =32;
int h =32;
icon = icon.scaled(w,h, Qt::KeepAspectRatio);
label->setPixmap(icon);
}
MachineSettings::MachineSettings(QWidget *parent, int _type) :
QWidget(parent),
ui(new Ui::MachineSettings),
type(_type)
{
ui->setupUi(this);
//Radio button type layout
selectorBox = new QGroupBox;
typeSelectorGroup = new QButtonGroup;
QHBoxLayout* typeGroupLayout = new QHBoxLayout;
if (type == 1) {
typeSelector.push_back(new NoToggleRadioButton);
typeSelector[0]->setMinimumWidth(50);
typeSelectorGroup->addButton(typeSelector[0],0);
typeGroupLayout->addWidget(typeSelector[0]);
}
else {
for (int i = 0; i < type; i++) {
typeSelector.push_back(new QRadioButton);
typeSelector[i]->setMinimumWidth(50);
typeSelectorGroup->addButton(typeSelector[i],i);
typeGroupLayout->addWidget(typeSelector[i]);
}
}
for (int i = 0; i < type; i++) {
QObject::connect(typeSelector[i], SIGNAL(toggled(bool)),
this, SLOT(radioChanged(bool)));
}
selectorBox->setLayout(typeGroupLayout);
selectorBox->setFixedHeight(50);
//2x2 grid, column is Intermediate/Final
//rows are Productivity/Speed
speedConfigTable = new QTableWidget(2,2);
speedConfigTable->setFixedWidth(180);
speedConfigTable->setFixedHeight(180);
auto intColumnItem = new QTableWidgetItem;
intColumnItem->setSizeHint(QSize(50,50));
intColumnItem->setIcon(QIcon(":/intermediate-products.png"));
intColumnItem->setToolTip(QString("Recipes for intermediate products will use these bonuses."));
speedConfigTable->setHorizontalHeaderItem(0,intColumnItem);
auto finColumnItem = new QTableWidgetItem;
finColumnItem->setSizeHint(QSize(50,50));
finColumnItem->setIcon(QIcon(":/production.png"));
finColumnItem->setToolTip(QString("Recipes will use these bonuses if not listed as an intermediate product."));
speedConfigTable->setHorizontalHeaderItem(1, finColumnItem);
auto productivityIcon = new QTableWidgetItem;
productivityIcon->setSizeHint(QSize(50,50));
productivityIcon->setIcon(QIcon(":/icons/productivity-module.png"));
productivityIcon->setToolTip(QString("The productivity bonus, in terms of percent."));
speedConfigTable->setVerticalHeaderItem(0,productivityIcon);
speedConfigTable->verticalHeader()->setDefaultSectionSize(50);
speedConfigTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
auto speedIcon = new QTableWidgetItem;
speedIcon->setSizeHint(QSize(50,50));
speedIcon->setIcon(QIcon(":/icons/speed-module.png"));
speedIcon->setToolTip(QString("The speed bonus, in terms of percent."));
speedConfigTable->setVerticalHeaderItem(1,speedIcon);
speedConfigTable->horizontalHeader()->setDefaultSectionSize(50);
speedConfigTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
//set QLineEdits within table
for (int r = 0; r < 2; r++) {
for (int c = 0; c < 2 ; c++) {
QLineEdit* lineEdit = new QLineEdit;
auto min = std::numeric_limits<double>::min();
auto max = std::numeric_limits<double>::max();
auto validator = new QDoubleValidator(min,max,3);
lineEdit->setValidator(validator);
QObject::connect(lineEdit, SIGNAL(textEdited(QString)),
this, SLOT(lineTextEdited(QString)));
lineEdit->setStyleSheet("QLineEdit { border: none }");
lineEdit->setAlignment(Qt::AlignCenter);
speedConfigTable->setCellWidget(r,c,lineEdit);
}
}
QGridLayout* scene = new QGridLayout(this);
scene->addWidget(selectorBox,0,0,1,type);
scene->addWidget(speedConfigTable,1,0,1,4,Qt::AlignTop);
this->setLayout(scene);
}
void MachineSettings::lineTextEdited(QString) {
emit dataChanged();
}
void MachineSettings::radioChanged(bool) {
emit dataChanged();
}
void MachineSettings:: setBonuses(double intProd, double intSpd, double defProd, double defSpd) {
static_cast<QLineEdit*>(speedConfigTable->cellWidget(0,0))->setText(QString::number(intProd));
static_cast<QLineEdit*>(speedConfigTable->cellWidget(1,0))->setText(QString::number(intSpd));
static_cast<QLineEdit*>(speedConfigTable->cellWidget(0,1))->setText(QString::number(defProd));
static_cast<QLineEdit*>(speedConfigTable->cellWidget(1,1))->setText(QString::number(defSpd));
}
machine_config MachineSettings::getMachineConfig() {
machine_config c;
c.intermediate_products_boost.effectivity = static_cast<QLineEdit*>(speedConfigTable->cellWidget(0,0))->text().toDouble();
c.intermediate_products_boost.speed = static_cast<QLineEdit*>(speedConfigTable->cellWidget(1,0))->text().toDouble();
c.default_boosts.effectivity = static_cast<QLineEdit*>(speedConfigTable->cellWidget(0,1))->text().toDouble();
c.default_boosts.effectivity = static_cast<QLineEdit*>(speedConfigTable->cellWidget(1,1))->text().toDouble();
c.type = typeSelectorGroup->checkedId();
return c;
}
void MachineSettings::setIconForType(QString path, int i) {
QIcon icon(path);
typeSelector[i]->setIcon(icon);
}
MachineSettings::~MachineSettings()
{
delete ui;
}
MiningSettings::MiningSettings(QWidget* parent):
MachineSettings(parent,2)
{
setIconForType(tr(":/icons/burner-mining-drill"),0);
setIconForType(tr(":/icons/electric-mining-drill"),1);
typeSelector[1]->setChecked(true);
}
machine_config MiningSettings::getMachineConfig() {
auto config = MachineSettings::getMachineConfig();
config.base_speed = config.type;
return config;
}
machine_config SmeltingSettings::getMachineConfig() {
auto config = MachineSettings::getMachineConfig();
switch (config.type) {
case 0:
config.base_speed = 1;
break;
case 1:
case 2:
config.base_speed = 2;
break;
}
return config;
}
machine_config ChemistrySettings::getMachineConfig() {
auto config = MachineSettings::getMachineConfig();
switch (config.type)
case 0:
config.base_speed = 1.25;
return config;
}
machine_config AssemblingSettings::getMachineConfig() {
auto config = MachineSettings::getMachineConfig();
switch (config.type) {
case 0:
config.base_speed = 0.5;
break;
case 1:
config.base_speed = 0.75;
break;
case 2:
config.base_speed = 1.25;
break;
}
return config;
}
SmeltingSettings::SmeltingSettings(QWidget *parent):
MachineSettings(parent,3)
{
setIconForType(tr(":/icons/stone-furnace"),0);
setIconForType(tr(":/icons/steel-furnace"),1);
setIconForType(tr(":/icons/electric-furnace"),2);
typeSelector[2]->setChecked(true);
}
PumpjackSettings::PumpjackSettings(QWidget *parent):
MachineSettings(parent,1)
{
this->setIconForType(tr(":/icons/pumpjack"),0);
typeSelector[0]->setChecked(true);
oilRate = new QLineEdit;
QObject::connect(oilRate, SIGNAL(textEdited(QString)),
this, SLOT(lineTextEdited(QString)));
auto validator = new QDoubleValidator(0, std::numeric_limits<double>::max(),3);
oilRate->setValidator(validator);
QGridLayout* scene =static_cast<QGridLayout*>(this->layout());
QHBoxLayout* oilAndLabel = new QHBoxLayout;
QLabel* oilIcon = new QLabel;
oilIcon->setToolTip(tr("The amount of oil extracted per second from each pumpjack"));
setIconForLabel(tr(":/icons/crude-oil"),oilIcon);
oilAndLabel->addWidget(oilIcon,0, Qt::AlignRight);
oilAndLabel->addWidget(oilRate,0,Qt::AlignRight);
scene->addLayout(oilAndLabel,0,3,1,1);
}
RefinerySettings::RefinerySettings(QWidget* parent):
MachineSettings(parent,1)
{
typeSelector[0]->setChecked(true);
processSelectorGroup = new QButtonGroup;
QHBoxLayout* layout = new QHBoxLayout;
processSelector = new QGroupBox;
processSelector->setFixedHeight(50);
setIconForType(tr(":/icons/oil-refinery"),0);
for (int i = 0; i < 3; i++) {
processes.push_back(new QRadioButton);
QObject::connect(processes[i], SIGNAL(toggled(bool)),
this, SLOT(radioChanged(bool)));
processes[i]->setMinimumWidth(50);
processSelectorGroup->addButton(processes[i],i);
layout->insertWidget(i,processes[i]);
}
processes[0]->setIcon(QIcon(":/icons/basic-oil-processing"));
processes[0]->setToolTip("basic oil processing");
processes[1]->setIcon(QIcon(":/icons/advanced-oil-processing"));
processes[1]->setToolTip("Advanced oil processing");
processes[2]->setIcon(QIcon(":/icons/coal-liquefaction"));
processes[2]->setToolTip("Coal liquefaction");
processes[1]->setChecked(true);
processSelector->setLayout(layout);
QGridLayout* scene =static_cast<QGridLayout*>(this->layout());
scene->addWidget(processSelector,0,1,1,3);
crackBox = new QCheckBox;
QObject::connect(crackBox, SIGNAL(toggled(bool)), this, SLOT(radioChanged(bool)));
crackBox->setToolTip(tr("Enable cracking whenever possible. If this is disabled, there may be excessive fluid byproducts."));
crackBox->setIcon(QIcon(":/icons/light-oil-cracking-to-petroleum-gas"));
crackBox->setChecked(true);
scene->addWidget(crackBox,2,0,1,1);
}
ChemistrySettings::ChemistrySettings(QWidget* parent):
MachineSettings(parent,1)
{
typeSelector[0]->setChecked(true);
fuelSelectorGroup = new QButtonGroup;
setIconForType(tr(":/icons/chemical-plant"),0);
fuelSelector = new QGroupBox;
fuelSelector->setFixedHeight(50);
fuelSelector->setToolTip(tr("The selected fluid for the solid fuel recipe"));
QHBoxLayout* layout = new QHBoxLayout;
for (int i = 0; i < 3; i++) {
fuels.push_back(new QRadioButton);
fuels[i]->setMinimumWidth(50);
QObject::connect(fuels[i], SIGNAL(toggled(bool)),
this, SLOT(radioChanged(bool)));
fuelSelectorGroup->addButton(fuels[i],i);
layout->insertWidget(i,fuels[i]);
}
fuelSelector->setLayout(layout);
fuels[0]->setIcon(QIcon(":/icons/heavy-oil"));
fuels[1]->setIcon(QIcon(":/icons/light-oil"));
fuels[2]->setIcon(QIcon(":/icons/petroleum-gas"));
fuels[2]->setChecked(true);
QGridLayout* scene =static_cast<QGridLayout*>(this->layout());
scene->addWidget(fuelSelector,0,1,1,3);
}
AssemblingSettings::AssemblingSettings(QWidget *parent):
MachineSettings(parent,3)
{
typeSelector[2]->setChecked(true);
setIconForType(tr(":/icons/assembling-machine-1"),0);
setIconForType(tr(":/icons/assembling-machine-2"),1);
setIconForType(tr(":/icons/assembling-machine-3"),2);
}
RocketrySettings::RocketrySettings(QWidget *parent):
MachineSettings(parent,1)
{
typeSelector[0]->setChecked(true);
setIconForType(tr(":/icons/rocket-silo"),0);
}