-
Notifications
You must be signed in to change notification settings - Fork 7
/
mainwindow.cpp
405 lines (357 loc) · 17.1 KB
/
mainwindow.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "basic.h"
#include "settings.h"
#include "fileoperate.h"
#include "enchlist.h"
#include "itemlist.h"
#include "flowlist.h"
#include "calculator.h"
#include "checkupdate.h"
#include <QUrl>
#include <QDesktopServices>
#include <QTextEdit>
#include <QLayout>
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow{parent}
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(QString(PROGRAM_NAME_CN) + "-" + PROGRAM_NAME_EN + " v" + VERSION + " [" + AUTHOR + "]");
QLabel *labText = new QLabel(this);
labText->setText(STATEMENT);
ui->statusBar->addWidget(labText);
//Menu Bar Connection
connect(ui->actionSettings, &QAction::triggered, this, [=](){
Settings *w = new Settings(this);
w->setWindowTitle("设置 Settings");
w->setModal(true);
w->show();
if(w->exec() == Settings::Accepted)
qApp->exit(5201314);
});
connect(ui->actionHelp, &QAction::triggered, this, [=]{
QDesktopServices::openUrl(QUrl(QLatin1String("https://www.bilibili.com/video/BV11T4y1D7c2")));
});
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
connect(ui->actionWeapon, &QAction::triggered, this, [=](){
});
connect(ui->actionEnchantment, &QAction::triggered, this, [=](){
});
connect(ui->actionVersion, &QAction::triggered, this, [=](){
QDialog w;
QLabel *name = new QLabel(QString("* * * ") + PROGRAM_NAME_CN + " * * *\n* * * " + PROGRAM_NAME_EN + " * * *\n", &w);
name->setAlignment(Qt::AlignHCenter);
QLabel *ver = new QLabel(QString("Version: ") + VERSION, &w);
ver->setAlignment(Qt::AlignHCenter);
QLabel *author = new QLabel(QString("Author: ") + AUTHOR, &w);
author->setAlignment(Qt::AlignHCenter);
QPushButton *btn = new QPushButton("确定 Confirm", &w);
connect(btn, &QPushButton::clicked, &w, &QDialog::accept);
QVBoxLayout *layout = new QVBoxLayout(&w);
layout->addWidget(name);
layout->addWidget(ver);
layout->addWidget(author);
layout->addWidget(btn);
w.setFixedSize(320, 140);
w.setLayout(layout);
w.setModal(true);
w.show();
w.exec();
});
connect(ui->actionWebsite, &QAction::triggered, this, [=](){
QDesktopServices::openUrl(QUrl(QLatin1String(WEBSITE)));
});
//Tab Connection
connect(ui->tabWidget, &QTabWidget::currentChanged, this, [=](){
if(ui->OriginEnchantment->isChanged())
ui->NeededEnchantment->setWeapon(Basic::weapon[ui->InputItem->currentIndex()].name);
});
//Lists Connection
//Radio Button Connection
connect(ui->radioJE, &QRadioButton::clicked, this, [=](){
Basic::edition = 0;
ui->OriginEnchantment->refresh();
});
connect(ui->radioBE, &QRadioButton::clicked, this, [=](){
Basic::edition = 1;
ui->OriginEnchantment->refresh();
});
connect(ui->radioGA, &QRadioButton::clicked, this, [=](){
Basic::mode[0] = 0;
});
connect(ui->radioH, &QRadioButton::clicked, this, [=](){
Basic::mode[0] = 1;
});
connect(ui->radioE, &QRadioButton::clicked, this, [=](){
Basic::mode[0] = 2;
});
connect(ui->radioEB, &QRadioButton::clicked, this, [=](){
Basic::mode[1] = 0;
ui->groupBox_4->setTitle("需求的魔咒(Needed Enchantment)");
ui->NeededEnchantment->refresh();
});
connect(ui->radioAC, &QRadioButton::clicked, this, [=](){
Basic::mode[1] = 1;
ui->groupBox_4->setTitle("物品池(Item Pool)");
ui->NeededEnchantment->refresh();
});
//Combo Box Connection
connect(ui->InputItem, &QComboBox::currentIndexChanged, this, [=](){
Basic::OriginItem.name = ui->InputItem->currentText();
ui->OriginEnchantment->setWeapon(Basic::weapon[ui->InputItem->currentIndex()].name);
});
//Spin Box Connection
connect(ui->Durability_0, &QSpinBox::valueChanged, this, [=](){
Basic::OriginItem.duration = ui->Durability_0->value();
});
connect(ui->Penalty_0, &QSpinBox::valueChanged, this, [=](){
Basic::OriginItem.penalty = ui->Penalty_0->value();
});
//Check Box Connection
connect(ui->cbIgnoreFixing, &QCheckBox::clicked, this, [=](){
Basic::lever[0] = ui->cbIgnoreFixing->isChecked();
});
connect(ui->cbIgnorePWP, &QCheckBox::clicked, this, [=](){
Basic::lever[1] = ui->cbIgnorePWP->isChecked();
});
connect(ui->cbIgnoreCL, &QCheckBox::clicked, this, [=](){
Basic::lever[2] = ui->cbIgnoreCL->isChecked();
});
//Push Button Connection
connect(ui->btnExit, &QPushButton::clicked, this, &MainWindow::close);
connect(ui->btnReset, &QPushButton::clicked, this, [=](){
qApp->exit(5201314);
});
connect(ui->btnNext_1, &QPushButton::clicked, this, [=](){
ui->tabWidget->setCurrentIndex(1);
});
connect(ui->btnBack_2, &QPushButton::clicked, this, [=](){
ui->tabWidget->setCurrentIndex(0);
});
connect(ui->btnCalc_2, &QPushButton::clicked, this, [=](){
if(ui->NeededEnchantment->enchCount() == 0)
{
ui->btnCalc_2->setStyleSheet("color:red");
return;
}
else
ui->btnCalc_2->setStyleSheet("color:black");
QTime start_time = QTime::currentTime();
for(int i = 0; i < INIT_LENGTH; i++)
Basic::OriginItem.ench[i] = {};
for(int i = 0; i < Basic::origin_ench_l; i++)
Basic::OriginItem.ench[i] = Basic::origin_ench[i];
Calculator();
ui->OutputItem->setIcon(Basic::weapon[Basic::searchWeapon(Basic::OriginItem.name)].icon);
ui->OutputItem->setIconSize(QSize(64, 64));
ui->Durability_1->setText(QString::number(Basic::OutputItem.duration));
ui->Penalty_1->setText(QString::number(Basic::OutputItem.penalty));
ui->StepCount->setText(QString::number(Basic::flow_list_l));
Basic::sumCost = 0;
int step_max_cost = 0;
for(int i = 0; i < Basic::flow_list_l; i++)
{
Basic::sumCost += Basic::flow_list[i].cost;
step_max_cost = max(step_max_cost, Basic::flow_list[i].cost);
}
ui->CostLevel->setText(QString::number(Basic::sumCost));
if(step_max_cost < 40)
{
ui->Notice->setText("可行的!\nAvailable!");
ui->Notice->setStyleSheet("color:green");
}
else
{
ui->Notice->setText("过于昂贵!\nToo expensive!");
ui->Notice->setStyleSheet("color:red");
}
ui->EnchantingFlow->refresh();
ui->tabWidget->setCurrentIndex(2);
QTime stop_time = QTime::currentTime();
double num = (double)start_time.msecsTo(stop_time) / 1000;
ui->CalcTime->setText(QString::number(num, 'g', 3) + "s");
});
connect(ui->btnBack_3, &QPushButton::clicked, this, [=](){
ui->tabWidget->setCurrentIndex(1);
});
connect(ui->btnSave, &QPushButton::clicked, this, [=](){
FileOperate fo;
fo.saveExport();
});
connect(ui->OutputItem, &QPushButton::clicked, this, [=](){
QString info;
info += "- Name: " + Basic::OutputItem.name.replace('\n', ' ') + "\n";
info += "- Durability: " + QString::number(Basic::OutputItem.duration) + "\n";
info += "- Penalty: " + QString::number(Basic::OutputItem.penalty) + "\n";
info += "- Enchs: \n";
for (int i = 0; i < INIT_LENGTH; i++)
{
if (Basic::OutputItem.ench[i].name.isEmpty())
break;
info += "\t- " + Basic::OutputItem.ench[i].name + " " + Basic::IntToRoman(Basic::OutputItem.ench[i].lvl) + "\n";
}
QDialog dialog(this);
dialog.setWindowTitle("Details");
QPoint p = this->geometry().center();
dialog.setGeometry(p.x() - 256, p.y() - 256, 512, 512);
QVBoxLayout layout(&dialog);
layout.setContentsMargins(8, 8, 8, 8);
QTextEdit text(&dialog);
layout.addWidget(&text);
text.setMarkdown(info);
text.setReadOnly(true);
dialog.setModal(true);
dialog.show();
dialog.exec();
});
//Initialze & Load Files
initialize();
FileOperate fo;
fo.loadConfig();
if(Basic::config.default_edition == 0)
ui->radioJE->setChecked(true);
else
ui->radioBE->setChecked(true);
Basic::mode[0] = Basic::config.default_algorithm;
if(Basic::mode[0] == 0)
ui->radioGA->setChecked(true);
else if(Basic::mode[0] == 1)
ui->radioH->setChecked(true);
else
ui->radioE->setChecked(true);
if(Basic::config.enableCustomWe)
fo.loadWeapon();
if(Basic::config.enableCustomEn)
fo.loadEnchantmentTable();
if(Basic::config.autoCheckUpdate)
{
qDebug() << "autoCheckUpdate";
CheckUpdate *task = new CheckUpdate();
task->start(false);
}
//enable_reszie_window
if(Basic::config.enableReszieWindow)
{
QSizePolicy sp;
sp.setVerticalPolicy(QSizePolicy::Preferred);
this->setSizePolicy(sp);
this->setMinimumSize(QSize(1, 1));
this->setMaximumSize(QSize(QWIDGETSIZE_MAX,QWIDGETSIZE_MAX));
}
refresh();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initialize()
{
qDebug() << "Initializing...";
Basic::weapon_l = 14;
delete [] Basic::weapon;
Basic::weapon = new Weapon[Basic::weapon_l];
Basic::weapon[0] = {"剑\nSword",QIcon(":/icon/res/netherite_sword.png")};
Basic::weapon[1] = {"镐\nPickaxe",QIcon(":/icon/res/netherite_pickaxe.png")};
Basic::weapon[2] = {"斧\nAxe",QIcon(":/icon/res/netherite_axe.png")};
Basic::weapon[3] = {"铲\nShovel",QIcon(":/icon/res/netherite_shovel.png")};
Basic::weapon[4] = {"锄\nHoe",QIcon(":/icon/res/netherite_hoe.png")};
Basic::weapon[5] = {"头盔\nHelmet",QIcon(":/icon/res/netherite_helmet.png")};
Basic::weapon[6] = {"胸甲\nChestplate",QIcon(":/icon/res/netherite_chestplate.png")};
Basic::weapon[7] = {"护腿\nLeggings",QIcon(":/icon/res/netherite_leggings.png")};
Basic::weapon[8] = {"靴\nBoots",QIcon(":/icon/res/netherite_boots.png")};
Basic::weapon[9] = {"弓\nBow",QIcon(":/icon/res/bow.png")};
Basic::weapon[10] = {"弩\nCrossbow",QIcon(":/icon/res/crossbow_standby.png")};
Basic::weapon[11] = {"三叉戟\nTrident",QIcon(":/icon/res/trident.png")};
Basic::weapon[12] = {"钓鱼竿\nFishing Rod",QIcon(":/icon/res/fishing_rod.png")};
Basic::weapon[13] = {"重锤\nMace",QIcon(":/icon/res/mace.png")};
Basic::ench_table_l = 43;
delete [] Basic::ench_table;
Basic::ench_table = new EnchTable[Basic::ench_table_l];
Basic::ench_table[0] = {"水下速掘-aqua_affinity",1,{4,2},2,{},{0,0,0,0,0,1,0,0,0,0,0,0,0,0}};
Basic::ench_table[1] = {"节肢杀手-bane_of_arthropods",5,{2,1},2,{"锋利-sharpness","亡灵杀手-smite","致密-density","破甲-breach"},{1,0,1,0,0,0,0,0,0,0,0,0,0,1}};
Basic::ench_table[2] = {"爆炸保护-blast_protection",4,{4,2},2,{"火焰保护-fire_protection","弹射物保护-projectile_protection","保护-protection"},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[3] = {"引雷-channeling",1,{8,4},2,{"激流-riptide"},{0,0,0,0,0,0,0,0,0,0,0,1,0,0}};
Basic::ench_table[4] = {"绑定诅咒-binding_curse",1,{8,4},2,{},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[5] = {"消失诅咒-vanishing_curse",1,{8,4},2,{},{1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
Basic::ench_table[6] = {"深海探索者-depth_strider",3,{4,2},2,{"冰霜行者-frost_walker"},{0,0,0,0,0,0,0,0,1,0,0,0,0,0}};
Basic::ench_table[7] = {"效率-efficiency",5,{1,1},2,{},{0,1,1,1,1,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[8] = {"摔落保护-feather_falling",4,{2,1},2,{},{0,0,0,0,0,0,0,0,1,0,0,0,0,0}};
Basic::ench_table[9] = {"火焰附加-fire_aspect",2,{4,2},2,{},{1,0,0,0,0,0,0,0,0,0,0,0,0,1}};
Basic::ench_table[10] = {"火焰保护-fire_protection",4,{2,1},2,{"爆炸保护-blast_protection","弹射物保护-projectile_protection","保护-protection"},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[11] = {"火矢-flame",1,{4,2},2,{},{0,0,0,0,0,0,0,0,0,1,0,0,0,0}};
Basic::ench_table[12] = {"时运-fortune",3,{4,2},2,{"精准采集-silk_touch"},{0,1,1,1,1,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[13] = {"冰霜行者-frost_walker",2,{4,2},2,{"深海探索者-depth_strider"},{0,0,0,0,0,0,0,0,1,0,0,0,0,0}};
Basic::ench_table[14] = {"穿刺-impaling",5,{4,2},0,{},{0,0,0,0,0,0,0,0,0,0,0,1,0,0}};
Basic::ench_table[15] = {"无限-infinity",1,{8,4},2,{"经验修补-mending"},{0,0,0,0,0,0,0,0,0,1,0,0,0,0}};
Basic::ench_table[16] = {"击退-knockback",2,{2,1},2,{},{1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[17] = {"抢夺-looting",3,{4,2},2,{},{1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[18] = {"忠诚-loyalty",3,{1,1},2,{"激流-riptide"},{0,0,0,0,0,0,0,0,0,0,0,1,0,0}};
Basic::ench_table[19] = {"海之眷顾-luck_of_the_sea",3,{4,2},2,{},{0,0,0,0,0,0,0,0,0,0,0,0,1,0}};
Basic::ench_table[20] = {"饵钓-lure",3,{4,2},2,{},{0,0,0,0,0,0,0,0,0,0,0,0,1,0}};
Basic::ench_table[21] = {"经验修补-mending",1,{4,2},2,{"无限-infinity"},{1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
Basic::ench_table[22] = {"多重射击-multishot",1,{4,2},2,{"穿透-piercing"},{0,0,0,0,0,0,0,0,0,0,1,0,0,0}};
Basic::ench_table[23] = {"穿透-piercing",4,{1,1},2,{"多重射击-multishot"},{0,0,0,0,0,0,0,0,0,0,1,0,0,0}};
Basic::ench_table[24] = {"力量-power",5,{1,1},2,{},{0,0,0,0,0,0,0,0,0,1,0,0,0,0}};
Basic::ench_table[25] = {"弹射物保护-projectile_protection",4,{2,1},2,{"爆炸保护-blast_protection","火焰保护-fire_protection","保护-protection"},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[26] = {"保护-protection",4,{1,1},2,{"爆炸保护-blast_protection","火焰保护-fire_protection","弹射物保护-projectile_protection"},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[27] = {"冲击-punch",2,{4,2},2,{},{0,0,0,0,0,0,0,0,0,1,0,0,0,0}};
Basic::ench_table[28] = {"快速装填-quick_charge",3,{2,1},2,{},{0,0,0,0,0,0,0,0,0,0,1,0,0,0}};
Basic::ench_table[29] = {"水下呼吸-respiration",3,{4,2},2,{},{0,0,0,0,0,1,0,0,0,0,0,0,0,0}};
Basic::ench_table[30] = {"激流-riptide",3,{4,2},2,{"引雷-channeling","忠诚-loyalty"},{0,0,0,0,0,0,0,0,0,0,0,1,0,0}};
Basic::ench_table[31] = {"锋利-sharpness",5,{1,1},2,{"节肢杀手-bane_of_arthropods","亡灵杀手-smite","致密-density","破甲-breach"},{1,0,1,0,0,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[32] = {"精准采集-silk_touch",1,{8,4},2,{"时运-fortune"},{0,1,1,1,1,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[33] = {"亡灵杀手-smite",5,{2,1},2,{"节肢杀手-bane_of_arthropods","锋利-sharpness","致密-density","破甲-breach"},{1,0,1,0,0,0,0,0,0,0,0,0,0,1}};
Basic::ench_table[34] = {"灵魂疾行-soul_speed",3,{8,4},2,{},{0,0,0,0,0,0,0,0,1,0,0,0,0,0}};
Basic::ench_table[35] = {"横扫之刃-sweeping",3,{4,2},0,{},{1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
Basic::ench_table[36] = {"荆棘-thorns",3,{8,4},2,{},{0,0,0,0,0,1,1,1,1,0,0,0,0,0}};
Basic::ench_table[37] = {"耐久-unbreaking",3,{2,1},2,{},{1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
Basic::ench_table[38] = {"迅捷潜行-swift_sneak",3,{8,4},2,{},{0,0,0,0,0,0,0,1,0,0,0,0,0,0}};
Basic::ench_table[39] = {"穿刺-impaling",5,{2,1},1,{},{0,0,0,0,0,0,0,0,0,0,0,1,0,0}};
Basic::ench_table[40] = {"致密-density",5,{1,1},0,{"锋利-sharpness","节肢杀手-bane_of_arthropods","亡灵杀手-smite","破甲-breach"},{0,0,0,0,0,0,0,0,0,0,0,0,0,1}};
Basic::ench_table[41] = {"破甲-breach",4,{4,2},0,{"锋利-sharpness","节肢杀手-bane_of_arthropods","亡灵杀手-smite","致密-density"},{0,0,0,0,0,0,0,0,0,0,0,0,0,1}};
Basic::ench_table[42] = {"风爆-wind_burst",3,{4,2},0,{},{0,0,0,0,0,0,0,0,0,0,0,0,0,1}};
Basic::OriginItem.name = Basic::weapon[0].name;
Basic::OriginItem.duration = 100;
Basic::OriginItem.penalty = 0;
}
void MainWindow::refresh()
{
Basic::lever[0] = 0;
Basic::lever[1] = 0;
Basic::lever[2] = 0;
ui->InputItem->clear();
ui->InputItem->setIconSize(QSize(64,64));
for(int i = 0; i < Basic::weapon_l; i++)
{
ui->InputItem->addItem(Basic::weapon[i].icon, Basic::weapon[i].name);
}
ui->OriginEnchantment->setWeapon(Basic::weapon[ui->InputItem->currentIndex()].name);
ui->NeededEnchantment->setWeapon(Basic::weapon[ui->InputItem->currentIndex()].name);
}
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(!e->isAutoRepeat())
{
if(e->modifiers() == Qt::ControlModifier)
{
if(Basic::config.enableReszieWindow)
{
if(e->key() == Qt::Key_BracketLeft)
{
this->resize((int)(size().width()*0.95), (int)(size().height()*0.95));
}
else if(e->key() == Qt::Key_BracketRight)
{
this->resize((int)(size().width()*1.05), (int)(size().height()*1.05));
}
}
}
}
QMainWindow::keyPressEvent(e);
}
void MainWindow::keyReleaseEvent(QKeyEvent *e)
{
QMainWindow::keyReleaseEvent(e);
}