From 82a4997e909860c770391862971a1b041db42021 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Thu, 21 Apr 2022 00:47:57 +0200 Subject: [PATCH] ui stuff, StageSettings Widget --- .vscode/c_cpp_properties.json | 2 + include/lolautoaccept.h | 15 +++++ include/mainwindow.h | 16 ++++- include/screen.h | 40 +++++++++++ include/stagesettings.h | 41 ++++++++++++ lolautoaccept.pro | 8 ++- src/lolautoaccept.cpp | 50 ++++++++++++-- src/main.cpp | 14 +--- src/mainwindow.cpp | 21 +++++- src/stagesettings.cpp | 44 ++++++++++++ ts/de_DE.ts | 63 +++++++++++++++--- ts/en.ts | 59 ++++++++++++++-- ui/mainwindow.ui | 122 +++++++++++++++++++++++++++++++++- ui/stagesettings.ui | 92 +++++++++++++++++++++++++ 14 files changed, 550 insertions(+), 37 deletions(-) create mode 100644 include/stagesettings.h create mode 100644 src/stagesettings.cpp create mode 100644 ui/stagesettings.ui diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 92e59b6..2281d71 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,6 +6,8 @@ "${workspaceFolder}/src/", "${workspaceFolder}/thirdparty/Log/", "${workspaceFolder}/include/**", + "${workspaceFolder}/ui/**", + "/usr/include/x86_64-linux-gnu/qt5/**", "/usr/include/opencv4/**" ], diff --git a/include/lolautoaccept.h b/include/lolautoaccept.h index 58bc536..c135627 100644 --- a/include/lolautoaccept.h +++ b/include/lolautoaccept.h @@ -5,6 +5,7 @@ #include "matcher.h" #include +#include class LolAutoAccept { private: @@ -20,8 +21,13 @@ private: std::string prepick; std::string ban; std::string pick; + bool autoacceptenabled = false; + bool prepickenabled = false; + bool banenabled = false; + bool pickenabled = false; bool shouldrun = false; + std::thread lolaathread; enum class State { LOBBY, @@ -40,12 +46,21 @@ private: void pickFirst(const std::string& search); public: LolAutoAccept(); + ~LolAutoAccept(); void setPrePick(const std::string& prePick); void setBan(const std::string& ban); void setPick(const std::string& pick); + void setAutoAcceptEnabled(bool b); + void setPrePickEnabled(bool b); + void setBanEnabled(bool b); + void setPickEnabled(bool b); bool init(); // returns true on success void run(); void stop(); + +private: + void stopJoinThread(); + void innerRun(); }; \ No newline at end of file diff --git a/include/mainwindow.h b/include/mainwindow.h index 274dd1b..cd5da44 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -2,20 +2,30 @@ #define MAINWINDOW_H #include +#include + +#include "lolautoaccept.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE -class MainWindow : public QMainWindow -{ +class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QWidget *parent = nullptr); + MainWindow(LolAutoAccept& lolaa, QWidget *parent = nullptr); ~MainWindow(); +private slots: + void aatoggled(int); + void pptoggled(int); + void ppedited(const QString&); + private: Ui::MainWindow *ui; + LolAutoAccept& lolaa; + std::thread lolaathread; }; + #endif // MAINWINDOW_H diff --git a/include/screen.h b/include/screen.h index a61d98a..8f1d789 100644 --- a/include/screen.h +++ b/include/screen.h @@ -9,6 +9,46 @@ #include #include +#undef Bool +#undef CursorShape +#undef None +#undef KeyPress +#undef KeyRelease +#undef ButtonPress +#undef ButtonRelease +#undef MotionNotify +#undef EnterNotify +#undef LeaveNotify +#undef FocusIn +#undef FocusOut +#undef KeymapNotify +#undef Expose +#undef GraphicsExpose +#undef NoExpose +#undef VisibilityNotify +#undef CreateNotify +#undef DestroyNotify +#undef UnmapNotify +#undef MapNotify +#undef MapRequest +#undef ReparentNotify +#undef ConfigureNotify +#undef ConfigureRequest +#undef GravityNotify +#undef ResizeRequest +#undef CirculateNotify +#undef CirculateRequest +#undef PropertyNotify +#undef SelectionClear +#undef SelectionRequest +#undef SelectionNotify +#undef ColormapNotify +#undef ClientMessage +#undef MappingNotify +#undef GenericEvent +#undef LASTEvent +#undef FontChange + class ScreenShot { private: Display* display = nullptr; diff --git a/include/stagesettings.h b/include/stagesettings.h new file mode 100644 index 0000000..e5566d4 --- /dev/null +++ b/include/stagesettings.h @@ -0,0 +1,41 @@ +#ifndef STAGESETTINGS_H +#define STAGESETTINGS_H + +#include + +namespace Ui { + class StageSettings; +} + +class StageSettings : public QWidget { + Q_OBJECT + + Q_PROPERTY(QString name READ getName WRITE setName) + Q_PROPERTY(bool state READ getState WRITE setState NOTIFY toggled) + Q_PROPERTY(QString champion READ getChampion WRITE setChampion NOTIFY championChanged) + +public: + explicit StageSettings(QWidget *parent = nullptr); + ~StageSettings(); + + QString getName() const; + void setName(const QString& n); + + bool getState() const; + void setState(bool); + + QString getChampion() const; + void setChampion(const QString& str); +private slots: + void championChangedinternal(const QString& str); + void toggledinternal(int state); + +signals: + void toggled(bool); + void championChanged(const QString&); + +private: + Ui::StageSettings *ui; +}; + +#endif // STAGESETTINGS_H diff --git a/lolautoaccept.pro b/lolautoaccept.pro index bc6ee78..5eb5ca2 100644 --- a/lolautoaccept.pro +++ b/lolautoaccept.pro @@ -30,6 +30,7 @@ SOURCES += \ src/matcher.cpp \ src/scaleableinputs.cpp \ src/screen.cpp \ + src/stagesettings.cpp \ thirdparty/Log/Log.cpp # mainwindow.cpp @@ -41,6 +42,7 @@ HEADERS += \ include/matcher.h \ include/scaleableinputs.h \ include/screen.h \ + include/stagesettings.h \ thirdparty/Log/Log.h # mainwindow.h @@ -50,7 +52,8 @@ UI_DIR = ui/ OBJECTS_DIR = build/ FORMS += \ - ui/mainwindow.ui + ui/mainwindow.ui \ + ui/stagesettings.ui INCLUDEPATH += $$PWD/include/ \ $$PWD/thirdparty/Log/ \ @@ -67,7 +70,8 @@ TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/ts/, .ts) TRANSLATIONSQM = $$prependAll(LANGUAGES, $$PWD/ts/, .qm) makelang.commands = lrelease $$_PRO_FILE_ -QMAKE_EXTRA_TARGETS += makelang +updatelang.commands = lupdate $$_PRO_FILE_ +QMAKE_EXTRA_TARGETS += makelang updatelang PRE_TARGETDEPS += makelang QMAKE_CLEAN += $$TRANSLATIONSQM diff --git a/src/lolautoaccept.cpp b/src/lolautoaccept.cpp index 317f7ec..55286cf 100644 --- a/src/lolautoaccept.cpp +++ b/src/lolautoaccept.cpp @@ -132,6 +132,13 @@ LolAutoAccept::LolAutoAccept() : acceptmatcher("imgs/Accept.png"), arrowmatcher( banmatcher.setOffset(1232, 90); } +LolAutoAccept::~LolAutoAccept() { + stopJoinThread(); + + delete screen; + screen = nullptr; +} + void LolAutoAccept::setPrePick(const std::string& prePick) { prepick = prePick; } @@ -144,6 +151,23 @@ void LolAutoAccept::setPick(const std::string& pick) { this->pick = pick; } +void LolAutoAccept::setAutoAcceptEnabled(bool b) { + autoacceptenabled = b; +} + +void LolAutoAccept::setPrePickEnabled(bool b) { + prepickenabled = b; +} + +void LolAutoAccept::setBanEnabled(bool b) { + banenabled = b; +} + +void LolAutoAccept::setPickEnabled(bool b) { + pickenabled = b; +} + + bool LolAutoAccept::init() { if(screen) return true; @@ -169,7 +193,27 @@ bool LolAutoAccept::init() { } void LolAutoAccept::run() { + // make sure its not running + stopJoinThread(); + if(!screen) return; + + lolaathread = std::thread(&LolAutoAccept::innerRun, this); +} + +void LolAutoAccept::stop() { + shouldrun = false; +} + +void LolAutoAccept::stopJoinThread() { + stop(); + + if(lolaathread.joinable()) { + lolaathread.join(); + } +} + +void LolAutoAccept::innerRun() { lastacceptmatch = {false}; shouldrun = true; @@ -190,10 +234,4 @@ void LolAutoAccept::run() { Log::info << "iteration took: " << (dur.count() * 1000 ) << " ms"; std::this_thread::sleep_for(std::chrono::milliseconds(800)); } - - delete screen; -} - -void LolAutoAccept::stop() { - shouldrun = false; } diff --git a/src/main.cpp b/src/main.cpp index 996f236..7926b35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,11 +28,8 @@ int main(int argc, char** argv) { } else { Log::warn << "translation not found"; } - MainWindow win; - - lolaa.setPrePick("morgana"); - lolaa.setBan("akshan"); - + MainWindow win(lolaa); +/* while(!lolaa.init()) { QMessageBox warn; warn.setWindowTitle(MainWindow::tr("LoL-Auto-Accept")); @@ -47,16 +44,11 @@ int main(int argc, char** argv) { } } - std::thread lolaathread(&LolAutoAccept::run, &lolaa); + */ win.show(); int ret = app.exec(); - lolaa.stop(); - if(lolaathread.joinable()) { - lolaathread.join(); - } - Log::stop(); return ret; } \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9824e07..6add3da 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,11 +1,30 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + +#include + +MainWindow::MainWindow(LolAutoAccept& lolaa, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), lolaa(lolaa) { ui->setupUi(this); } MainWindow::~MainWindow() { + lolaa.stop(); + delete ui; } +void MainWindow::aatoggled(int state) { + Log::info << "enableAll checkbox toggled " << state; + + lolaa.setAutoAcceptEnabled(state == Qt::CheckState::Checked); +} + +void MainWindow::pptoggled(int state) { + Log::info << "enablePrePick checkbox toggled " << state; + lolaa.setPrePickEnabled(state == Qt::CheckState::Checked); +} + +void MainWindow::ppedited(const QString& newtext) { + lolaa.setPrePick(newtext.toStdString()); +} diff --git a/src/stagesettings.cpp b/src/stagesettings.cpp new file mode 100644 index 0000000..dd074e9 --- /dev/null +++ b/src/stagesettings.cpp @@ -0,0 +1,44 @@ +#include "stagesettings.h" +#include "ui_stagesettings.h" + +StageSettings::StageSettings(QWidget *parent) : QWidget(parent), ui(new Ui::StageSettings) { + ui->setupUi(this); + setMinimumSize(ui->gridLayout->minimumSize()); +} + +StageSettings::~StageSettings() { + delete ui; +} + +QString StageSettings::getName() const { + return ui->groupBox->title(); +} + +void StageSettings::setName(const QString& n) { + ui->groupBox->setTitle(n); + ui->checkBox->setText(tr("Enable %1").arg(n)); +} + +bool StageSettings::getState() const { + return ui->checkBox->checkState() == Qt::CheckState::Checked; +} + +void StageSettings::setState(bool b) { + ui->checkBox->setCheckState(b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); +} + +QString StageSettings::getChampion() const { + return ui->lineEdit->text(); +} + +void StageSettings::setChampion(const QString& str) { + ui->lineEdit->setText(str); +} + +void StageSettings::championChangedinternal(const QString& str) { + emit championChanged(str); +} + +void StageSettings::toggledinternal(int state) { + emit toggled(state == Qt::CheckState::Checked); +} diff --git a/ts/de_DE.ts b/ts/de_DE.ts index 7117994..e53614e 100644 --- a/ts/de_DE.ts +++ b/ts/de_DE.ts @@ -8,22 +8,69 @@ LoL-Auto-Accept LoL-Auto-Accept + + + Enable LoL-Auto-Accept + Aktiviere LoL-Auto-Accept + + + + PrePick + Pre Pick + + + + Enable PrePick + Aktivire Pre Pick + + + + Champion: + Champion: + + + + Ban + Bannen + QMessageBox - Client not found - Leage of Legends Client wurde nicht gefunden! - - - League of Legends Client not found! - League of Legends Client nicht gefunden! + League of Legends Client nicht gefunden! - Open the client and retry or close. - Starte den Client und wiederhole oder Fenster schließen. + Starte den Client und wiederhole oder Fenster schließen. + + + + StageSettings + + + Form + + + + + GroupBox + + + + + Champion: + Champion: + + + + CheckBox + + + + + Enable %1 + Aktiviere %1 diff --git a/ts/en.ts b/ts/en.ts index 105d8d2..b00a9d0 100644 --- a/ts/en.ts +++ b/ts/en.ts @@ -8,18 +8,69 @@ LoL-Auto-Accept LoL-Auto-Accept + + + Enable LoL-Auto-Accept + Enable LoL-Auto-Accept + + + + PrePick + Pre Pick + + + + Enable PrePick + Enable Pre Pick + + + + Champion: + Champion: + + + + Ban + Ban + QMessageBox - League of Legends Client not found! - League of Legends Client not found! + League of Legends Client not found! - Open the client and retry or close. - Open the client and retry or close. + Open the client and retry or close. + + + + StageSettings + + + Form + + + + + GroupBox + + + + + Champion: + Champion: + + + + CheckBox + + + + + Enable %1 + Enable %1 diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 1a621a4..6153667 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -13,7 +13,96 @@ LoL-Auto-Accept - + + + + + 10 + 50 + 731 + 491 + + + + + + + Enable LoL-Auto-Accept + + + + + + + true + + + + 0 + 0 + + + + + 200 + 0 + + + + Pre Pick + + + false + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + Ban + + + false + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + Pick + + + false + + + + + + @@ -26,6 +115,35 @@ + + + StageSettings + QWidget +
stagesettings.h
+
+
- + + + enableAll + stateChanged(int) + MainWindow + aatoggled(int) + + + 15 + 50 + + + 393 + 54 + + + + + + aatoggled(int) + pptoggled(int) + ppedited(QString) + diff --git a/ui/stagesettings.ui b/ui/stagesettings.ui new file mode 100644 index 0000000..b20bfb2 --- /dev/null +++ b/ui/stagesettings.ui @@ -0,0 +1,92 @@ + + + StageSettings + + + + 0 + 0 + 400 + 300 + + + + + + + + + + + + + + + + Champion: + + + + + + + + 160 + 0 + + + + + + + + + + + + + + + + + + + + lineEdit + textEdited(QString) + StageSettings + championChangedinternal(QString) + + + 193 + 212 + + + 250 + 329 + + + + + checkBox + stateChanged(int) + StageSettings + toggledinternal(int) + + + 79 + 109 + + + 20 + 296 + + + + + + championChanged(QString) + championChangedinternal(QString) + toggledinternal(int) + +