179 lines
4.8 KiB
C++
179 lines
4.8 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QTimer>
|
|
|
|
#include <Log.h>
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name().toStdString()),
|
|
lolaa(conf.getConfig(), dd, std::bind(&MainWindow::onFail, this), std::bind(&MainWindow::onPosChange, this, std::placeholders::_1)) {
|
|
ui->setupUi(this);
|
|
|
|
saveTimer->setInterval(std::chrono::minutes(1));
|
|
saveTimer->setSingleShot(true);
|
|
QObject::connect(saveTimer, &QTimer::timeout, this, &MainWindow::saveConfig);
|
|
|
|
ui->copyrightlabel->setText(ui->copyrightlabel->text().arg(LOLAA_VERSION));
|
|
|
|
lolaa.setOnRuneChangeFunc(std::bind(&RuneDisplay::setRunes, ui->runedisplay, std::placeholders::_1));
|
|
|
|
conf.load();
|
|
|
|
// for all tabs - set their config and datadragon
|
|
Config::RootConfig& rc = conf.getConfig();
|
|
for(int32_t tabnr = 0; tabnr < ui->tabWidget->count(); ++tabnr) {
|
|
SettingsTab* tab = (SettingsTab*) ui->tabWidget->widget(tabnr);
|
|
tab->setup(*rc.getPositionConfig(tab->getPosition()), &dd);
|
|
|
|
QObject::connect(tab, &SettingsTab::changed, this, &MainWindow::tabchanged);
|
|
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
|
}
|
|
|
|
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
|
lolaa.setEnabled(rc.enabledAutoAccept, LolAutoAccept::State::LOBBY);
|
|
|
|
ui->enableSmiteWarning->setChecked(rc.enabledSmiteWarn);
|
|
lolaa.setSmiteWarn(rc.enabledSmiteWarn);
|
|
|
|
ui->enableAutoWrite->setChecked(rc.enabledAutoWrite);
|
|
ui->autoWriteText->setText(QString::fromStdString(rc.autoWriteText));
|
|
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
|
|
|
resizeEvent(nullptr);
|
|
|
|
// a timer to delay the loading flag a short time until all other signals are processed
|
|
initDoneTimer = new QTimer(this);
|
|
initDoneTimer->setSingleShot(true);
|
|
initDoneTimer->setInterval(std::chrono::milliseconds(1)); // schedule for first event loop
|
|
QObject::connect(initDoneTimer, &QTimer::timeout, this, &MainWindow::initDone, Qt::QueuedConnection);
|
|
initDoneTimer->start();
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
lolaa.stop();
|
|
conf.save();
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::closeEvent([[maybe_unused]] QCloseEvent* event) {
|
|
conf.save();
|
|
}
|
|
|
|
void MainWindow::resizeEvent([[maybe_unused]] QResizeEvent *event) {
|
|
ui->verticalLayoutWidget->setMinimumSize(ui->centralwidget->size());
|
|
ui->verticalLayoutWidget->setMaximumSize(ui->centralwidget->size());
|
|
ui->verticalLayoutWidget->setMinimumSize(ui->centralwidget->size());
|
|
}
|
|
|
|
void MainWindow::resetSaveTimer() {
|
|
saveTimer->start();
|
|
qDebug() << "resetTimer";
|
|
}
|
|
|
|
void MainWindow::toggleMainswitch(bool state) {
|
|
qDebug() << "mainswitch toggled: " << state;
|
|
|
|
if(state) {
|
|
if(!lolaa.init()) {
|
|
Log::error << "League Client not found!";
|
|
ui->statusbar->showMessage(tr("League of Legends Client not found!"));
|
|
ui->mainswitch->setCheckState(Qt::CheckState::Unchecked);
|
|
return;
|
|
}
|
|
|
|
ui->runedisplay->setRuneMeta(lolaa.getRuneAspekts());
|
|
ui->runedisplay->setStyles(lolaa.getRuneStyles());
|
|
|
|
lolaa.run();
|
|
|
|
ui->statusbar->showMessage(tr("Auto-Acceptor started!"));
|
|
|
|
} else {
|
|
lolaa.stop();
|
|
ui->statusbar->showMessage(tr("Auto-Acceptor stoped!"));
|
|
}
|
|
}
|
|
|
|
void MainWindow::aatoggled(bool state) {
|
|
if( loading ) return;
|
|
|
|
qDebug() << "enableAll checkbox toggled " << state;
|
|
|
|
lolaa.setEnabled(state, LolAutoAccept::State::LOBBY);
|
|
conf.getConfig().enabledAutoAccept = state;
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::smitewarntoggled(bool state) {
|
|
if( loading ) return;
|
|
|
|
qDebug() << "smitewarn checkbox toggled " << state;
|
|
|
|
lolaa.setSmiteWarn(state);
|
|
conf.getConfig().enabledSmiteWarn = state;
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::tabtoggled(Position p, LolAutoAccept::State s, bool state) {
|
|
if( loading ) return;
|
|
|
|
qDebug() << "checkbox toggled " << state << " position: " << p << " state: " << (int) s;
|
|
|
|
lolaa.setEnabled(state, s);
|
|
lolaa.reload();
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
|
|
if( loading ) return;
|
|
|
|
qDebug() << "edited position: " << p << " state: " << (int) s;
|
|
|
|
lolaa.reload();
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::applyRunes() {
|
|
qDebug() << "applyRunes pressed";
|
|
|
|
lolaa.applyRunes();
|
|
}
|
|
|
|
void MainWindow::autoWriteChanged() {
|
|
if( loading ) return;
|
|
|
|
bool enabled = ui->enableAutoWrite->isChecked();
|
|
const std::string text = ui->autoWriteText->toPlainText().toStdString();
|
|
|
|
lolaa.setAutoWriteText(enabled, text);
|
|
|
|
conf.getConfig().enabledAutoWrite = enabled;
|
|
conf.getConfig().autoWriteText = text;
|
|
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::saveConfig() {
|
|
conf.save();
|
|
}
|
|
|
|
void MainWindow::initDone() {
|
|
loading = false;
|
|
initDoneTimer->deleteLater();
|
|
initDoneTimer = nullptr;
|
|
qDebug() << "loading done";
|
|
}
|
|
|
|
void MainWindow::onPosChange(Position newpos) {
|
|
assert(newpos <= Position::UTILITY);
|
|
|
|
emit requestTabChange((int) newpos);
|
|
}
|
|
|
|
void MainWindow::onFail() {
|
|
ui->mainswitch->setChecked(false);
|
|
ui->statusbar->showMessage(tr("Auto-Acceptor failed!"));
|
|
}
|
|
|