-
Notifications
You must be signed in to change notification settings - Fork 0
/
configpages.cpp
261 lines (225 loc) · 9.19 KB
/
configpages.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
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QComboBox>
#include "configpages.h"
#include "configure.h"
ConfigPage::ConfigPage(QWidget *parent) :
QWidget(parent)
{
}
GeneralPage::GeneralPage(QWidget *parent) :
ConfigPage(parent)
{
// note banner
QLabel *noteLabel = new QLabel(tr("<i>Note:: All the changes are applied only to new created Scenes or Spirits.</i>"));
// scene size
QGroupBox *sizeGroup = new QGroupBox(tr("Scene Size"));
QLabel *widthLabel = new QLabel(tr("width"));
widthEdit = new QLineEdit(g_config.getValue("Scene/Size/Width").toString());
widthEdit->setToolTip(tr("int (>0), unit: grid"));
QLabel *heightLabel = new QLabel(tr("height"));
heightEdit = new QLineEdit(g_config.getValue("Scene/Size/Height").toString());
heightEdit->setToolTip(tr("int (>0), unit: grid"));
QGridLayout *sizeLayout = new QGridLayout;
sizeLayout->addWidget(widthLabel, 0, 0);
sizeLayout->addWidget(widthEdit, 0, 1);
sizeLayout->addWidget(heightLabel, 1, 0);
sizeLayout->addWidget(heightEdit, 1, 1);
sizeGroup->setLayout(sizeLayout);
// hunt diagram
// QGroupBox *huntGroup = new QGroupBox(tr("Hunting Diagram"));
// HuntDia *huntDia = new HuntDia(this);
// QVBoxLayout *huntLayout = new QVBoxLayout;
// huntLayout->addWidget(huntDia);
// huntGroup->setLayout(huntLayout);
QPushButton *defaultButton = new QPushButton(tr("Default"));
connect(defaultButton, SIGNAL(clicked()), this, SLOT(resetDefault()));
QHBoxLayout *defaultLayout = new QHBoxLayout;
defaultLayout->addWidget(defaultButton, 0, Qt::AlignRight);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(noteLabel);
mainLayout->addSpacing(10);
mainLayout->addWidget(sizeGroup);
// mainLayout->setSpacing(10);
// mainLayout->addWidget(huntGroup);
mainLayout->addStretch(1);
mainLayout->addLayout(defaultLayout);
setLayout(mainLayout);
}
void GeneralPage::applyConfig()
{
bool ok = false;
int scene_size_width = widthEdit->text().toInt(&ok);
if (ok)
g_config.setValue("Scene/Size/Width", scene_size_width);
int scene_size_height = heightEdit->text().toInt(&ok);
if (ok)
g_config.setValue("Scene/Size/Height", scene_size_height);
}
void GeneralPage::resetDefault()
{
widthEdit->setText("512");
heightEdit->setText("256");
}
AvatarSpiritPage::AvatarSpiritPage(QWidget *parent) :
ConfigPage(parent)
{
// life
QGroupBox *lifeGroup = new QGroupBox(tr("Default Life Value"));
QLabel *mouseLifeLabel = new QLabel(tr("Mouse Life"));
mouseLifeEdit = new QLineEdit(g_config.getValue("AvatarSpirit/Life/Mouse").toString());
mouseLifeEdit->setToolTip(tr("float (>0)"));
QLabel *catLifeLabel = new QLabel(tr("Cat Life"));
catLifeEdit = new QLineEdit(g_config.getValue("AvatarSpirit/Life/Cat").toString());
catLifeEdit->setToolTip(tr("float (>0)"));
QLabel *elephantLifeLabel = new QLabel(tr("Elephant Life"));
elephantLifeEdit = new QLineEdit(g_config.getValue("AvatarSpirit/Life/Elephant").toString());
elephantLifeEdit->setToolTip(tr("float (>0)"));
QGridLayout *lifeLayout = new QGridLayout;
lifeLayout->addWidget(mouseLifeLabel, 0, 0);
lifeLayout->addWidget(mouseLifeEdit, 0, 1);
lifeLayout->addWidget(catLifeLabel, 1, 0);
lifeLayout->addWidget(catLifeEdit, 1, 1);
lifeLayout->addWidget(elephantLifeLabel, 2, 0);
lifeLayout->addWidget(elephantLifeEdit, 2, 1);
lifeGroup->setLayout(lifeLayout);
// sharing
QGroupBox *shareGroup = new QGroupBox(tr("Default Sharing Params"));
QLabel *rangeLabel = new QLabel(tr("Share Range"));
rangeEdit = new QLineEdit(g_config.getValue("AvatarSpirit/ShareParams/ShareRange").toString());
rangeEdit->setToolTip(tr("int (>=0, 0 to turn off sharing)"));
QLabel *freqLabel = new QLabel(tr("Share Freq"));
freqEdit = new QLineEdit(g_config.getValue("AvatarSpirit/ShareParams/ShareFreq").toString());
freqEdit->setToolTip(tr("int (>0)"));
QGridLayout *shareLayout = new QGridLayout;
shareLayout->addWidget(rangeLabel, 0, 0);
shareLayout->addWidget(rangeEdit, 0, 1);
shareLayout->addWidget(freqLabel, 1, 0);
shareLayout->addWidget(freqEdit, 1, 1);
shareGroup->setLayout(shareLayout);
// gamcs params
QGroupBox *paramsGroup = new QGroupBox(tr("Default GAMCS Parameters"));
QLabel *drLabel = new QLabel(tr("Discount Rate"));
drEdit = new QLineEdit(g_config.getValue("AvatarSpirit/GAMCSParams/DiscountRate").toString());
drEdit->setToolTip(tr("float (>=0, <1)"));
QLabel *acuLabel = new QLabel(tr("Accuracy"));
acuEdit = new QLineEdit(g_config.getValue("AvatarSpirit/GAMCSParams/Accuracy").toString());
acuEdit->setToolTip(tr("float (>=0)"));
QLabel *lmLabel = new QLabel(tr("Learning Mode"));
lmCombo = new QComboBox;
lmCombo->addItem(tr("Online"));
lmCombo->addItem(tr("Explore"));
if (g_config.getValue("AvatarSpirit/GAMCSParams/LearningMode").toString() == "Explore")
lmCombo->setCurrentIndex(1);
else // online is the default
lmCombo->setCurrentIndex(0);
QGridLayout *paramsLayout = new QGridLayout;
paramsLayout->addWidget(drLabel, 0, 0);
paramsLayout->addWidget(drEdit, 0, 1);
paramsLayout->addWidget(acuLabel, 1, 0);
paramsLayout->addWidget(acuEdit, 1, 1);
paramsLayout->addWidget(lmLabel, 2, 0);
paramsLayout->addWidget(lmCombo, 2, 1);
paramsGroup->setLayout(paramsLayout);
QPushButton *defaultButton = new QPushButton(tr("Default"));
connect(defaultButton, SIGNAL(clicked()), this, SLOT(resetDefault()));
QHBoxLayout *defaultLayout = new QHBoxLayout;
defaultLayout->addWidget(defaultButton, 0, Qt::AlignRight);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(lifeGroup);
mainLayout->addSpacing(10);
mainLayout->addWidget(shareGroup);
mainLayout->addSpacing(10);
mainLayout->addWidget(paramsGroup);
mainLayout->addStretch(1);
mainLayout->addLayout(defaultLayout);
setLayout(mainLayout);
}
void AvatarSpiritPage::applyConfig()
{
bool ok = false;
float mouse_life = mouseLifeEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("AvatarSpirit/Life/Mouse", mouse_life);
float cat_life = catLifeEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("AvatarSpirit/Life/Cat", cat_life);
float elephant_life = elephantLifeEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("AvatarSpirit/Life/Elephant", elephant_life);
int share_range = rangeEdit->text().toInt(&ok);
if (ok)
g_config.setValue("AvatarSpirit/ShareParams/ShareRange", share_range);
int share_freq = freqEdit->text().toInt(&ok);
if (ok)
g_config.setValue("AvatarSpirit/ShareParams/ShareFreq", share_freq);
float dr = drEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("AvatarSpirit/GAMCSParams/DiscountRate", dr);
float acu = acuEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("AvatarSpirit/GAMCSParams/Accuracy", acu);
QString lm = lmCombo->currentText();
g_config.setValue("AvatarSpirit/GAMCSParams/LearningMode", lm);
}
void AvatarSpiritPage::resetDefault()
{
mouseLifeEdit->setText("30");
catLifeEdit->setText("50");
elephantLifeEdit->setText("100");
rangeEdit->setText("5");
freqEdit->setText("5");
drEdit->setText("0.9");
acuEdit->setText("0.001");
lmCombo->setCurrentIndex(0);
}
StaticSpiritPage::StaticSpiritPage(QWidget *parent) :
ConfigPage(parent)
{
// life
QGroupBox *lifeGroup = new QGroupBox(tr("Default Life Value"));
QLabel *cheeseLifeLabel = new QLabel(tr("Cheese Life"));
cheeseLifeEdit = new QLineEdit(g_config.getValue("StaticSpirit/Life/Cheese").toString());
cheeseLifeEdit->setToolTip(tr("float (>0)"));
QLabel *nailLifeLabel = new QLabel(tr("Nail Life"));
nailLifeEdit = new QLineEdit(g_config.getValue("StaticSpirit/Life/Nail").toString());
nailLifeEdit->setToolTip(tr("float (>0)"));
QGridLayout *lifeLayout = new QGridLayout;
lifeLayout->addWidget(cheeseLifeLabel, 0, 0);
lifeLayout->addWidget(cheeseLifeEdit, 0, 1);
lifeLayout->addWidget(nailLifeLabel, 1, 0);
lifeLayout->addWidget(nailLifeEdit, 1, 1);
lifeGroup->setLayout(lifeLayout);
QPushButton *defaultButton = new QPushButton(tr("Default"));
connect(defaultButton, SIGNAL(clicked()), this, SLOT(resetDefault()));
QHBoxLayout *defaultLayout = new QHBoxLayout;
defaultLayout->addWidget(defaultButton, 0, Qt::AlignRight);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(lifeGroup);
mainLayout->addStretch(1);
mainLayout->addLayout(defaultLayout);
setLayout(mainLayout);
}
void StaticSpiritPage::applyConfig()
{
bool ok = false;
float cheese_life = cheeseLifeEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("StaticSpirit/Life/Cheese", cheese_life);
float nail_life = nailLifeEdit->text().toFloat(&ok);
if (ok)
g_config.setValue("StaticSpirit/Life/Nail", nail_life);
}
void StaticSpiritPage::resetDefault()
{
cheeseLifeEdit->setText("15");
nailLifeEdit->setText("1.5");
}
HuntDia::HuntDia(QWidget *parent) :
QTableView(parent)
{
}