From af63c975c7705b0539699773cd4c6d52eac09f68 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Wed, 21 Sep 2022 13:47:08 +0200 Subject: [PATCH] autowrite implemented --- include/clientapi.h | 2 +- include/config.h | 2 + include/lolautoaccept.h | 4 ++ include/mainwindow.h | 1 + src/config.cpp | 4 ++ src/lolautoaccept.cpp | 22 ++++++-- src/mainwindow.cpp | 12 +++++ ui/mainwindow.ui | 114 ++++++++++++++++++++++++++++++++++++---- 8 files changed, 148 insertions(+), 13 deletions(-) diff --git a/include/clientapi.h b/include/clientapi.h index 82cab44..d476a98 100644 --- a/include/clientapi.h +++ b/include/clientapi.h @@ -97,7 +97,7 @@ public: int32_t championID = 0; int32_t championPickIntentID = 0; int64_t summonerID = 0; - int64_t spell1Id = 0; // 4 = flash, 6 = ghost, 7 = heal, 11 = smite, 12 = teleport, 14 = ignite + int64_t spell1Id = 0; // 4 = flash, 6 = ghost, 7 = heal, 11 = smite, 12 = teleport, 13 = klarheitz, 14 = ignite, 32 = snowball int64_t spell2Id = 0; ChampSelectCell(); diff --git a/include/config.h b/include/config.h index afcd7db..5bf9628 100644 --- a/include/config.h +++ b/include/config.h @@ -38,6 +38,8 @@ public: bool enabledAutoAccept; bool enabledSmiteWarn; + bool enabledAutoWrite; + std::string autoWriteText; }; Config(); diff --git a/include/lolautoaccept.h b/include/lolautoaccept.h index 06820ad..2613328 100644 --- a/include/lolautoaccept.h +++ b/include/lolautoaccept.h @@ -49,6 +49,9 @@ protected: bool nextApplyRunes = false; bool smiteWarnEnabled = true; + bool autoWriteTextEnabled = false; + bool autoWriteTextDone = false; + std::string autoWriteText; std::string chatid; // the chatid of the chat from the champselect std::chrono::time_point lastMessageSent; @@ -77,6 +80,7 @@ public: const std::vector& getRuneStyles(); void applyRunes(); void setOnRuneChangeFunc(onruneschange_func on); + void setAutoWriteText(bool enabled, const std::string& text = {}); private: void stopJoinThread(); diff --git a/include/mainwindow.h b/include/mainwindow.h index f5bea9b..9aef2af 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -32,6 +32,7 @@ private slots: void tabchanged(Position, LolAutoAccept::State); void applyRunes(); + void autoWriteChanged(); signals: void requestTabChange(int tabindex); diff --git a/src/config.cpp b/src/config.cpp index 4b12fb4..22918c5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -88,6 +88,8 @@ Config::RootConfig::RootConfig(const QJsonObject& j) { enabledAutoAccept = getValue(j, "enabledAutoAccept", true); enabledSmiteWarn = getValue(j, "enabledSmiteWarn", true); + enabledAutoWrite = getValue(j, "enabledAutoWrite", false); + autoWriteText = getValue(j, "autoWriteText"); } Config::RootConfig::operator QJsonObject() const { @@ -101,6 +103,8 @@ Config::RootConfig::operator QJsonObject() const { out["positions"] = positionarr; out.insert("enabledAutoAccept", enabledAutoAccept); out.insert("enabledSmiteWarn", enabledSmiteWarn); + out.insert("enabledAutoWrite", enabledAutoWrite); + out.insert("autoWriteText", QString::fromStdString(autoWriteText)); return out; } diff --git a/src/lolautoaccept.cpp b/src/lolautoaccept.cpp index c557a90..921464b 100644 --- a/src/lolautoaccept.cpp +++ b/src/lolautoaccept.cpp @@ -107,6 +107,12 @@ void LolAutoAccept::setOnRuneChangeFunc(onruneschange_func on) { onRuneschange = on; } +void LolAutoAccept::setAutoWriteText(bool enabled, const std::string& text) { + autoWriteTextEnabled = enabled; + autoWriteTextDone = false; + autoWriteText = text; +} + void LolAutoAccept::stopJoinThread() { stop(); @@ -119,10 +125,10 @@ void LolAutoAccept::stopJoinThread() { void LolAutoAccept::innerRun() { shouldrun = true; - auto convs = clientapi->getAllConversations(); - Log::info << "got " << convs.size() << " conversations"; - try { + auto convs = clientapi->getAllConversations(); + Log::info << "got " << convs.size() << " conversations"; + while(shouldrun) { uint32_t extrasleep = 800; auto start = std::chrono::high_resolution_clock::now(); @@ -207,6 +213,7 @@ void LolAutoAccept::resetAllOffsets() { currentPositionSet = false; lastPickedChamp = 0; chatid.clear(); + autoWriteTextDone = false; } void LolAutoAccept::resetRunes() { @@ -442,6 +449,15 @@ void LolAutoAccept::champSelect() { if(nextApplyRunes) { applyRunes_internal(pickedChamp, pos); } + + // check for autowriteText + if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.empty()) { + const std::string& chatid = getChatid(); + if(!chatid.empty()) { + clientapi->sendMessage(chatid, autoWriteText); + autoWriteTextDone = true; + } + } } void LolAutoAccept::smiteWarning(const std::vector& cells) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index eece646..6911ab2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi 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); } @@ -107,6 +111,14 @@ void MainWindow::applyRunes() { lolaa.applyRunes(); } +void MainWindow::autoWriteChanged() { + 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; +} + void MainWindow::onPosChange(Position newpos) { assert(newpos <= Position::UTILITY); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 4faaa7e..5077a5d 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 452 - 645 + 465 + 635 @@ -66,6 +66,53 @@ + + + + Auto Write + + + + + + + + 0 + 0 + + + + + 16777215 + 80 + + + + + 0 + 0 + + + + Qt::WheelFocus + + + QFrame::Sunken + + + QTextEdit::NoWrap + + + false + + + Qt::LinksAccessibleByMouse|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + autowriteText + + + @@ -150,8 +197,8 @@ 0 0 - 452 - 21 + 465 + 24 @@ -223,8 +270,8 @@ 86 - 407 - 145 + 408 + 380 @@ -239,7 +286,7 @@ 599 - 458 + 452 576 @@ -251,8 +298,8 @@ smitewarntoggled(bool) - 190 - 77 + 191 + 111 201 @@ -260,6 +307,54 @@ + + enableAutoWrite + clicked(bool) + MainWindow + autoWriteChanged() + + + 182 + 130 + + + 441 + 147 + + + + + autoWriteText + textChanged() + MainWindow + autoWriteChanged() + + + 315 + 169 + + + 347 + 146 + + + + + enableAutoWrite + toggled(bool) + autoWriteText + setEnabled(bool) + + + 88 + 131 + + + 86 + 168 + + + requestTabChange(int) @@ -269,5 +364,6 @@ toggleMainswitch(bool) applyRunes() smitewarntoggled(bool) + autoWriteChanged()