-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow3.cpp
286 lines (215 loc) · 9.26 KB
/
mainwindow3.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
#include "mainwindow3.h"
#include "ui_mainwindow3.h"
#include "potiondisplay.h"
#include "carddisplay.h"
#include "custombutton.h"
#include "eventoverview.h"
#include "src/h/resourcemanager.h"
#include "src/h/utils.h"
#include <QTimer>
#include <QDebug>
MainWindow3::MainWindow3(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow3),
potionDisplay(new PotionDisplay()),
cardDisplay(new CardDisplay()),
eventDisplay(new EventDisplay()),
currentRun(nullptr)
{
ui->setupUi(this);
// Child windows
config = new Config("config.json");
optionsWindow = new Options(config);
tutorialWindow = new Tutorial();
aboutWindow = new About();
statsWindow = new StatisticsWindow(config);
referenceWindow = new ReferenceWindow();
// Testing
//eventOverview = new EventOverview();
// Add all the custom QWidgets
setupUI();
// Refresh timer
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, QOverload<>::of(&MainWindow3::refresh));
timer->start(1000);
}
MainWindow3::~MainWindow3()
{
delete ui;
}
void MainWindow3::setupUI() {
CustomButton* optionsButton = new CustomButton("Options", ResourceManager::getInstance().getIconOptions(), this);
CustomButton* statsButton = new CustomButton("Stats (WIP)", ResourceManager::getInstance().getIconStats(), this);
CustomButton* referenceButton = new CustomButton("Reference (WIP)", ResourceManager::getInstance().getIconReference(), this);
CustomButton* tutorialButton = new CustomButton("Tutorial", ResourceManager::getInstance().getIconHelp(), this);
this->ui->layout_options->addWidget(optionsButton);
this->ui->layout_options->addWidget(statsButton);
this->ui->layout_options->addWidget(referenceButton);
this->ui->layout_options->addWidget(tutorialButton);
// testing
// CustomButton* events = new CustomButton("Events", ResourceManager::getInstance().getIconHelp(), this);
// this->ui->layout_options->addWidget(events);
// connect(events, &QPushButton::clicked, this, &MainWindow3::showEventsWindow );
this->ui->layout_options->addStretch(1);
// Display tiles
this->ui->layout_potions->addWidget(potionDisplay);
this->ui->layout_cards->addWidget(cardDisplay);
this->ui->layout_events->addWidget(eventDisplay);
// Connections for the custom buttons
connect(optionsButton, &QPushButton::clicked, this, &MainWindow3::showOptionsWindow );
connect(statsButton, &QPushButton::clicked, this, &MainWindow3::showStatsWindow );
connect(referenceButton, &QPushButton::clicked, this, &MainWindow3::showReferenceWindow );
connect(tutorialButton, &QPushButton::clicked, this, &MainWindow3::showTutorialWindow );
}
void MainWindow3::refresh() {
QString savesDir = config->getSavesLocation();
QString recentSave = Utils::getMostRecentlyUpdatedFile(savesDir);
QString fullSavePath = savesDir.endsWith("/") ?
QString("%1%2").arg(savesDir, recentSave) :
QString("%1/%2").arg(savesDir, recentSave) ;
// Refresh if necessary
updateCurrentSaveData(fullSavePath);
}
void MainWindow3::updateCurrentSaveData(const QString& fullSavePath) {
// TODO: rewrite this awful horrendous code. it's really really awful
if (currentRun == nullptr || currentRun->differentFile(fullSavePath)) {
// Rebuild the old file if necessary
if (currentRun != nullptr)
delete currentRun;
currentRun = Run::build(fullSavePath);
// Couldn't understand the run file, so quit early
if (currentRun == nullptr)
return;
}
// Current run file still exists and nothing changed means we can quit early
else if (!currentRun->refresh()){
return;
}
// Update GUI text
ui->label_char->setText(currentRun->getCharNameAndFloor());
ui->label_boss_asc->setText(currentRun->getBossAndAsc());
ui->label_char_image->setPixmap(currentRun->getPixmap());
updateCurrentPotionInfo();
updateCurrentCardChances();
updateCurrentEventChances();
}
////////////////////////////////////////////////////////////////////////////////
void MainWindow3::updateCurrentPotionInfo() {
// Update the potion chance
int potion_chance = currentRun->getPotionChance() + 40;
int floor = currentRun->getCurrentFloor();
// TODO: verify this patch works
// boss chest floors
if (floor == 17 || floor == 34 || floor == 52) {
potion_chance = 40;
}
// boss fight floors (post fight only)
else if (currentRun->isPostCombat() && (floor == 16 || floor == 33 || floor == 51)) {
potion_chance = 40;
}
// BUGFIX: Special Relics (Sozu/WhiteBeast)
if (currentRun->hasSozuRelic())
potionDisplay->setText( QString("0% (SOZU)") );
else if (currentRun->hasWhiteBeastStatue())
potionDisplay->setText( QString("100% (WBS)") );
else
potionDisplay->setText( QString("%1\%").arg(potion_chance) );
// Write to file if desired
if (config->getPotionWrite()) {
writePotionFile(potion_chance, currentRun->hasSozuRelic(), currentRun->hasWhiteBeastStatue());
}
}
void MainWindow3::updateCurrentCardChances() {
int cbr = currentRun->getCBR();
int numCards = Utils::determineNumRewardCards(
currentRun->hasQuestionCard(),
currentRun->hasBustedCrown(),
currentRun->hasPrayerWheel()
);
int baseRareChance = Utils::determineRareChance( 3, currentRun->hasNloths() );
int baseEliteRareChance = Utils::determineRareChance( 10, currentRun->hasNloths() );
double rareChance = Utils::calculateProb(cbr, numCards, baseRareChance, Utils::RARE) * 100.0;
double eliteRareChance = Utils::calculateProb(cbr, numCards, baseEliteRareChance, Utils::RARE) * 100.0;
double uncChance = Utils::calculateProb(cbr, numCards, baseRareChance, Utils::UNCOMMON) * 100.0;
double eliteUncChance = Utils::calculateProb(cbr, numCards, baseEliteRareChance, Utils::UNCOMMON) * 100.0;
// Update UI
QString txt = QString("Rare Chance (Next %1 Cards)").arg(numCards);
ui->label_card_display->setText(txt);
cardDisplay->setRareChances(rareChance, eliteRareChance);
// ui->label_cc->setText(QString("%1\%").arg(QString::number(commonChance, 'f', 2)));
// ui->label_uc->setText(QString("%1\%").arg(QString::number(uncommonChance, 'f', 2)));
// ui->label_rc->setText(QString("%1\%").arg(QString::number(rareChance, 'f', 2)));
// Write to file if desired
if (config->getUncWrite())
writeUncFile(uncChance, eliteUncChance);
if (config->getRareWrite())
writeRareFile(rareChance, eliteRareChance);
}
void MainWindow3::updateCurrentEventChances() {
// Update the potion chance
//int potion_chance = currentRun->getPotionChance() + 40;
//int floor = currentRun->getCurrentFloor();
double monsterChance = currentRun->getMonsterChance() * 100.0;
double shopChance = currentRun->getShopChance() * 100.0;
double treasureChance = currentRun->getTreasureChance() * 100.0;
double eventChance = 100.0 - monsterChance - shopChance - treasureChance;
eventDisplay->setChances(eventChance, monsterChance, shopChance, treasureChance);
//TODO
// Write to file if desired
//if (config->getPotionWrite()) {
//writePotionFile(potion_chance, currentRun->hasSozuRelic(), currentRun->hasWhiteBeastStatue());
//}
}
void MainWindow3::writePotionFile(int chance, bool hasSozu, bool hasWhiteBeast) {
QString filename = config->getPotionLocation();
QString format("");
// Pick the proper format based on the strings written in the options menu
if (hasSozu && config->getSozuOverride())
format = Utils::formatPotion(chance, config->getSozuFormat());
else if (hasWhiteBeast && config->getWbsOverride())
format = Utils::formatPotion(chance, config->getWbsFormat());
else
format = Utils::formatPotion(chance, config->getPotionFormat());
qDebug() << "Final format string: " << format;
Utils::writeStringToFile(format, config->getPotionLocation());
}
void MainWindow3::writeUncFile(double uncChance, double eliteUncChance) {
QString format = Utils::formatStrings(
QString::number(uncChance, 'f', 2),
QString("$"),
config->getUncommonFormat()
);
format = Utils::formatStrings(
QString::number(eliteUncChance, 'f', 2),
QString("@"),
format
);
qDebug() << "Final format string: " << format;
Utils::writeStringToFile(format, config->getUncommonLocation());
}
void MainWindow3::writeRareFile(double rareChance, double eliteRareChance) {
QString format = Utils::formatStrings(
QString::number(rareChance, 'f', 2),
QString("$"),
config->getRareFormat()
);
format = Utils::formatStrings(
QString::number(eliteRareChance, 'f', 2),
QString("@"),
format
);
qDebug() << "Final format string: " << format;
Utils::writeStringToFile(format, config->getRareLocation());
}
////////////////////////////////////////////////////////////////////////////////
// Slots for showing child windows
void MainWindow3::showOptionsWindow() { optionsWindow->showWithConfig(); }
void MainWindow3::showTutorialWindow() { tutorialWindow->show(); }
void MainWindow3::showAboutWindow() { aboutWindow->show(); }
void MainWindow3::showStatsWindow() { statsWindow->show(); }
void MainWindow3::showReferenceWindow() { referenceWindow->show(); }
// testing
//void MainWindow3::showEventsWindow() { eventOverview->show(); }
void MainWindow3::shutdown() {
QApplication::closeAllWindows();
}