ui stuff, StageSettings Widget

This commit is contained in:
mrbesen 2022-04-21 00:47:57 +02:00
parent ffd745f446
commit 82a4997e90
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
14 changed files with 550 additions and 37 deletions

View File

@ -6,6 +6,8 @@
"${workspaceFolder}/src/",
"${workspaceFolder}/thirdparty/Log/",
"${workspaceFolder}/include/**",
"${workspaceFolder}/ui/**",
"/usr/include/x86_64-linux-gnu/qt5/**",
"/usr/include/opencv4/**"
],

View File

@ -5,6 +5,7 @@
#include "matcher.h"
#include <xinputsimulator.h>
#include <thread>
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();
};

View File

@ -2,20 +2,30 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include <thread>
#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

View File

@ -9,6 +9,46 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#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;

41
include/stagesettings.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef STAGESETTINGS_H
#define STAGESETTINGS_H
#include <QWidget>
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

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,11 +1,30 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
#include <Log.h>
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());
}

44
src/stagesettings.cpp Normal file
View File

@ -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);
}

View File

@ -8,22 +8,69 @@
<source>LoL-Auto-Accept</source>
<translation>LoL-Auto-Accept</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="27"/>
<source>Enable LoL-Auto-Accept</source>
<translation>Aktiviere LoL-Auto-Accept</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="46"/>
<source>PrePick</source>
<translation>Pre Pick</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="58"/>
<source>Enable PrePick</source>
<translation>Aktivire Pre Pick</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="81"/>
<source>Champion:</source>
<translation>Champion:</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="101"/>
<source>Ban</source>
<translation>Bannen</translation>
</message>
</context>
<context>
<name>QMessageBox</name>
<message>
<source>Client not found</source>
<translation type="vanished">Leage of Legends Client wurde nicht gefunden!</translation>
</message>
<message>
<location filename="../src/main.cpp" line="38"/>
<source>League of Legends Client not found!</source>
<translation type="unfinished">League of Legends Client nicht gefunden!</translation>
<translation type="obsolete">League of Legends Client nicht gefunden!</translation>
</message>
<message>
<location filename="../src/main.cpp" line="39"/>
<source>Open the client and retry or close.</source>
<translation>Starte den Client und wiederhole oder Fenster schließen.</translation>
<translation type="vanished">Starte den Client und wiederhole oder Fenster schließen.</translation>
</message>
</context>
<context>
<name>StageSettings</name>
<message>
<location filename="../ui/stagesettings.ui" line="14"/>
<source>Form</source>
<translation></translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="20"/>
<source>GroupBox</source>
<translation></translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="26"/>
<source>Champion:</source>
<translation>Champion:</translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="43"/>
<source>CheckBox</source>
<translation></translation>
</message>
<message>
<location filename="../src/stagesettings.cpp" line="19"/>
<source>Enable %1</source>
<translation>Aktiviere %1</translation>
</message>
</context>
</TS>

View File

@ -8,18 +8,69 @@
<source>LoL-Auto-Accept</source>
<translation>LoL-Auto-Accept</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="27"/>
<source>Enable LoL-Auto-Accept</source>
<translation>Enable LoL-Auto-Accept</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="46"/>
<source>PrePick</source>
<translation>Pre Pick</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="58"/>
<source>Enable PrePick</source>
<translation>Enable Pre Pick</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="81"/>
<source>Champion:</source>
<translation>Champion:</translation>
</message>
<message>
<location filename="../ui/mainwindow.ui" line="101"/>
<source>Ban</source>
<translation>Ban</translation>
</message>
</context>
<context>
<name>QMessageBox</name>
<message>
<location filename="../src/main.cpp" line="38"/>
<source>League of Legends Client not found!</source>
<translation>League of Legends Client not found!</translation>
<translation type="vanished">League of Legends Client not found!</translation>
</message>
<message>
<location filename="../src/main.cpp" line="39"/>
<source>Open the client and retry or close.</source>
<translation>Open the client and retry or close.</translation>
<translation type="vanished">Open the client and retry or close.</translation>
</message>
</context>
<context>
<name>StageSettings</name>
<message>
<location filename="../ui/stagesettings.ui" line="14"/>
<source>Form</source>
<translation></translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="20"/>
<source>GroupBox</source>
<translation></translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="26"/>
<source>Champion:</source>
<translation>Champion:</translation>
</message>
<message>
<location filename="../ui/stagesettings.ui" line="43"/>
<source>CheckBox</source>
<translation></translation>
</message>
<message>
<location filename="../src/stagesettings.cpp" line="19"/>
<source>Enable %1</source>
<translation>Enable %1</translation>
</message>
</context>
</TS>

View File

@ -13,7 +13,96 @@
<property name="windowTitle">
<string>LoL-Auto-Accept</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>731</width>
<height>491</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="enableAll">
<property name="text">
<string>Enable LoL-Auto-Accept</string>
</property>
</widget>
</item>
<item>
<widget class="StageSettings" name="prepickstage" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="name" stdset="0">
<string>Pre Pick</string>
</property>
<property name="state" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="StageSettings" name="banstage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="name" stdset="0">
<string>Ban</string>
</property>
<property name="state" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="StageSettings" name="pickstage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="name" stdset="0">
<string>Pick</string>
</property>
<property name="state" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@ -26,6 +115,35 @@
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>StageSettings</class>
<extends>QWidget</extends>
<header>stagesettings.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>enableAll</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>aatoggled(int)</slot>
<hints>
<hint type="sourcelabel">
<x>15</x>
<y>50</y>
</hint>
<hint type="destinationlabel">
<x>393</x>
<y>54</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>aatoggled(int)</slot>
<slot>pptoggled(int)</slot>
<slot>ppedited(QString)</slot>
</slots>
</ui>

92
ui/stagesettings.ui Normal file
View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StageSettings</class>
<widget class="QWidget" name="StageSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Champion:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="minimumSize">
<size>
<width>160</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>lineEdit</sender>
<signal>textEdited(QString)</signal>
<receiver>StageSettings</receiver>
<slot>championChangedinternal(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>193</x>
<y>212</y>
</hint>
<hint type="destinationlabel">
<x>250</x>
<y>329</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBox</sender>
<signal>stateChanged(int)</signal>
<receiver>StageSettings</receiver>
<slot>toggledinternal(int)</slot>
<hints>
<hint type="sourcelabel">
<x>79</x>
<y>109</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>296</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<signal>championChanged(QString)</signal>
<slot>championChangedinternal(QString)</slot>
<slot>toggledinternal(int)</slot>
</slots>
</ui>