lolautoaccept/src/mainwindow.cpp

121 lines
3.4 KiB
C++
Raw Normal View History

2022-04-20 00:54:10 +02:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2022-04-21 00:47:57 +02:00
#include <Log.h>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), dd(QLocale().name().toStdString()),
2022-07-29 00:05:22 +02:00
lolaa(conf.getConfig(), dd, std::bind(&MainWindow::onFail, this), std::bind(&MainWindow::onPosChange, this, std::placeholders::_1)) {
2022-04-20 00:54:10 +02:00
ui->setupUi(this);
2022-04-23 00:39:45 +02:00
lolaa.setOnRuneChangeFunc(std::bind(&RuneDisplay::setRunes, ui->runedisplay, std::placeholders::_1));
2022-04-24 01:27:46 +02:00
conf.load();
2022-07-04 00:30:00 +02:00
// 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);
2022-07-04 00:30:00 +02:00
QObject::connect(tab, SIGNAL( changed(Position, LolAutoAccept::State) ), this, SLOT( tabchanged(Position, LolAutoAccept::State) ));
QObject::connect(tab, SIGNAL( toggled(Position, LolAutoAccept::State, bool) ), this, SLOT( tabtoggled(Position, LolAutoAccept::State, bool) ));
}
2022-04-24 01:27:46 +02:00
ui->enableAll->setChecked(rc.enabledAutoAccept);
2022-04-24 14:06:27 +02:00
lolaa.setEnabled(rc.enabledAutoAccept, LolAutoAccept::State::LOBBY);
2022-07-03 16:44:07 +02:00
2022-08-26 13:47:21 +02:00
ui->enableSmiteWarning->setChecked(rc.enabledSmiteWarn);
lolaa.setSmiteWarn(rc.enabledSmiteWarn);
2022-07-03 16:44:07 +02:00
resizeEvent(nullptr);
2022-04-20 00:54:10 +02:00
}
MainWindow::~MainWindow() {
2022-04-21 00:47:57 +02:00
lolaa.stop();
2022-04-24 01:27:46 +02:00
conf.save();
2022-04-21 00:47:57 +02:00
2022-04-20 00:54:10 +02:00
delete ui;
}
2022-04-24 12:15:58 +02:00
void MainWindow::closeEvent([[maybe_unused]] QCloseEvent* event) {
2022-04-24 01:27:46 +02:00
conf.save();
}
2022-07-03 16:44:07 +02:00
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());
}
2022-04-21 19:33:46 +02:00
void MainWindow::toggleMainswitch(bool state) {
Log::info << "mainswitch toggled: " << state;
2022-07-03 16:44:07 +02:00
2022-04-21 19:33:46 +02:00
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;
}
2022-07-09 01:01:51 +02:00
ui->runedisplay->setRuneMeta(lolaa.getRuneAspekts());
2022-07-10 15:56:09 +02:00
ui->runedisplay->setStyles(lolaa.getRuneStyles());
2022-07-09 01:01:51 +02:00
2022-04-21 19:33:46 +02:00
lolaa.run();
2022-07-09 01:01:51 +02:00
2022-04-21 19:33:46 +02:00
ui->statusbar->showMessage(tr("Auto-Acceptor started!"));
2022-07-09 01:01:51 +02:00
2022-04-21 19:33:46 +02:00
} else {
lolaa.stop();
ui->statusbar->showMessage(tr("Auto-Acceptor stoped!"));
}
}
void MainWindow::aatoggled(bool state) {
2022-04-21 00:47:57 +02:00
Log::info << "enableAll checkbox toggled " << state;
2022-04-24 14:06:27 +02:00
lolaa.setEnabled(state, LolAutoAccept::State::LOBBY);
2022-04-24 01:27:46 +02:00
conf.getConfig().enabledAutoAccept = state;
2022-04-21 00:47:57 +02:00
}
2022-08-26 13:47:21 +02:00
void MainWindow::smitewarntoggled(bool state) {
Log::info << "smitewarn checkbox toggled " << state;
lolaa.setSmiteWarn(state);
conf.getConfig().enabledSmiteWarn = state;
}
2022-07-04 00:30:00 +02:00
void MainWindow::tabtoggled(Position p, LolAutoAccept::State s, bool state) {
2022-07-04 17:50:18 +02:00
Log::info << "checkbox toggled " << state << " position: " << p << " state: " << (int) s;
2022-04-21 18:35:18 +02:00
2022-07-04 22:59:48 +02:00
if(s == LolAutoAccept::State::LOBBY) {
lolaa.setEnabled(state, s);
}
lolaa.reload();
2022-04-21 18:35:18 +02:00
}
2022-07-04 00:30:00 +02:00
void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
2022-07-04 17:50:18 +02:00
Log::info << "edited position: " << p << " state: " << (int) s;
2022-04-21 18:35:18 +02:00
2022-07-04 22:59:48 +02:00
lolaa.reload();
}
2022-07-09 01:01:51 +02:00
void MainWindow::applyRunes() {
Log::info << "applyRunes pressed";
lolaa.applyRunes();
}
2022-07-04 22:59:48 +02:00
void MainWindow::onPosChange(Position newpos) {
2022-07-17 00:21:15 +02:00
assert(newpos <= Position::UTILITY);
emit requestTabChange((int) newpos);
2022-04-21 18:35:18 +02:00
}
2022-07-09 01:01:51 +02:00
2022-07-29 00:05:22 +02:00
void MainWindow::onFail() {
ui->mainswitch->setChecked(false);
ui->statusbar->showMessage(tr("Auto-Acceptor failed!"));
}