237 lines
6.8 KiB
C++
237 lines
6.8 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QApplication>
|
|
#include <QTimer>
|
|
#include <QMessageBox>
|
|
|
|
#include <Log.h>
|
|
|
|
#include "loadingwindow.h"
|
|
#include "x11helper.h"
|
|
|
|
#ifdef X11SUPPORT
|
|
#define INIT_X11HELPER new X11Helper(this)
|
|
#else
|
|
#define INIT_X11HELPER nullptr
|
|
#endif
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name()),
|
|
lolaa(conf.getConfig(), dd), lwin(new LoadingWindow(nullptr)),
|
|
dodgeQuestion(new QMessageBox(QMessageBox::Icon::Warning, MainWindow::tr("Dodge?"), MainWindow::tr("Are you sure you want to dodge?"), QMessageBox::Cancel | QMessageBox::Yes, this)),
|
|
x11Helper(INIT_X11HELPER) {
|
|
ui->setupUi(this);
|
|
|
|
QObject::connect(&dd, &DataDragon::fetchingChamp, lwin, &LoadingWindow::setChampion);
|
|
QObject::connect(&dd, &DataDragon::loading, lwin, &LoadingWindow::setProgress);
|
|
QObject::connect(&dd, &DataDragon::loading, this, &MainWindow::loadingStatus);
|
|
QObject::connect(lwin, &LoadingWindow::closed, &dd, &DataDragon::stop);
|
|
QObject::connect(lwin, &LoadingWindow::closed, qApp, &QCoreApplication::quit, Qt::ConnectionType::QueuedConnection);
|
|
dd.startThread();
|
|
|
|
QObject::connect(&lolaa, &LolAutoAccept::dodgePossible, ui->dodgeBtn, &QAbstractButton::setEnabled);
|
|
QObject::connect(ui->dodgeBtn, &QAbstractButton::pressed, dodgeQuestion, &QMessageBox::show);
|
|
QObject::connect(dodgeQuestion, &QMessageBox::accepted, &lolaa, &LolAutoAccept::dodge);
|
|
QObject::connect(&lolaa, &LolAutoAccept::statusChanged, this, &MainWindow::lolaaStatusChanged);
|
|
QObject::connect(&lolaa, &LolAutoAccept::positionChanged, this, &MainWindow::onPosChange);
|
|
|
|
QObject::connect(ui->hideLeague, &QCheckBox::stateChanged, this, &MainWindow::toggleLeagueVisibility);
|
|
|
|
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));
|
|
|
|
conf.load();
|
|
Config::RootConfig& rc = conf.getConfig();
|
|
|
|
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(rc.autoWriteText);
|
|
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
|
|
|
resizeEvent(nullptr);
|
|
|
|
lwin->show();
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
lolaa.stop();
|
|
conf.save();
|
|
|
|
delete this->ui;
|
|
}
|
|
|
|
void MainWindow::closeEvent([[maybe_unused]] QCloseEvent* event) {
|
|
lolaa.stop();
|
|
conf.save();
|
|
}
|
|
|
|
void MainWindow::resetSaveTimer() {
|
|
saveTimer->start();
|
|
qDebug() << "resetTimer";
|
|
}
|
|
|
|
void MainWindow::loadingStatus(float f) {
|
|
if(f >= 1.0 && lwin) {
|
|
// loading complete
|
|
|
|
// 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);
|
|
}
|
|
|
|
// load runepage images
|
|
ui->runesPage->setDataDragon(dd);
|
|
ui->runesPage->setConfig(conf);
|
|
|
|
// switch from loading window to main window
|
|
lwin->hide();
|
|
this->show();
|
|
lwin->deleteLater();
|
|
lwin = nullptr;
|
|
|
|
// a timer to delay the loading flag a short time until all other signals are processed
|
|
QTimer::singleShot(std::chrono::milliseconds(1), this, &MainWindow::initDone);
|
|
}
|
|
}
|
|
|
|
void MainWindow::toggleLeagueVisibility() {
|
|
if(x11Helper) {
|
|
const bool shouldBeHidden = ui->hideLeague->isChecked();
|
|
Window win = x11Helper->findWindow("League of Legends");
|
|
qInfo() << "LeagueClient win id:" << win;
|
|
if(win != 0) {
|
|
x11Helper->setMap(win, shouldBeHidden);
|
|
} else {
|
|
// TODO: show error in status bar?
|
|
// TODO: reset checkbox to unchecked?
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::toggleMainswitch(bool state) {
|
|
qDebug() << "mainswitch toggled: " << state;
|
|
|
|
if(state) {
|
|
ui->mainswitch->setCheckState(Qt::CheckState::PartiallyChecked);
|
|
ui->mainswitch->setEnabled(false);
|
|
|
|
// make sure the changes to the mainswitch are rendered, before going into the blocking call
|
|
QCoreApplication::processEvents();
|
|
|
|
// TODO: make this non blocking
|
|
if(!lolaa.init()) {
|
|
qCritical() << "League Client not found!";
|
|
ui->statusbar->showMessage(tr("League of Legends Client not found!"));
|
|
ui->mainswitch->setCheckState(Qt::CheckState::Unchecked);
|
|
ui->mainswitch->setEnabled(true);
|
|
return;
|
|
}
|
|
|
|
lolaa.run();
|
|
} else {
|
|
lolaa.stop();
|
|
ui->mainswitch->setCheckState(Qt::CheckState::PartiallyChecked);
|
|
ui->mainswitch->setEnabled(false);
|
|
}
|
|
}
|
|
|
|
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::autoWriteChanged() {
|
|
if( loading ) return;
|
|
|
|
bool enabled = ui->enableAutoWrite->isChecked();
|
|
const QString text = ui->autoWriteText->toPlainText();
|
|
|
|
lolaa.setAutoWriteText(enabled, text);
|
|
|
|
conf.getConfig().enabledAutoWrite = enabled;
|
|
conf.getConfig().autoWriteText = text;
|
|
|
|
resetSaveTimer();
|
|
}
|
|
|
|
void MainWindow::saveConfig() {
|
|
conf.save();
|
|
}
|
|
|
|
void MainWindow::initDone() {
|
|
loading = false;
|
|
qDebug() << "loading done";
|
|
}
|
|
|
|
void MainWindow::onPosChange(Position newpos) {
|
|
assert(newpos <= Position::UTILITY);
|
|
|
|
emit requestTabChange((int) newpos);
|
|
}
|
|
|
|
void MainWindow::lolaaStatusChanged(LolAutoAccept::Status status) {
|
|
qDebug() << "new status: " << (int) status;
|
|
|
|
switch(status) {
|
|
case LolAutoAccept::Status::Off:
|
|
this->ui->statusbar->showMessage(tr("Auto-Acceptor stoped!"));
|
|
break;
|
|
case LolAutoAccept::Status::Running:
|
|
this->ui->statusbar->showMessage(tr("Auto-Acceptor started!"));
|
|
break;
|
|
case LolAutoAccept::Status::Failed:
|
|
this->ui->statusbar->showMessage(tr("Auto-Acceptor failed!"));
|
|
break;
|
|
}
|
|
|
|
this->ui->mainswitch->setEnabled(true);
|
|
this->ui->mainswitch->setChecked(status == LolAutoAccept::Status::Running);
|
|
}
|