store and restore settings

This commit is contained in:
mrbesen 2022-07-03 00:31:13 +02:00
parent f35b8d6719
commit 4de7c57a46
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
12 changed files with 196 additions and 226 deletions

View File

@ -13,6 +13,7 @@ protected:
std::vector<uint32_t> champids; // not every stage has a champ
bool enabled = false;
uint32_t currentOffset = 0;
};
std::vector<Stage*> stages;
@ -36,7 +37,7 @@ public:
LolAutoAccept();
~LolAutoAccept();
void setChamps(std::vector<uint32_t> champs, State s);
void setChamps(const std::vector<uint32_t>& champs, State s);
void setEnabled(bool b, State s);
bool init(); // returns true on success
@ -46,6 +47,9 @@ public:
private:
void stopJoinThread();
void innerRun();
void resetAllOffsets();
uint32_t getNextChampOfState(State s);
using ownactions_t = std::vector<ClientAPI::ChampSelectAction>;
ownactions_t getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> actions);

View File

@ -26,11 +26,11 @@ private slots:
void toggleMainswitch(bool);
void aatoggled(bool);
void pptoggled(bool);
void ppedited(const QString&);
void ppedited();
void bantoggled(bool);
void banedited(const QString&);
void banedited();
void picktoggled(bool);
void pickedited(const QString&);
void pickedited();
private:
// returns empty string on no match

View File

@ -41,16 +41,15 @@ private slots:
void toggledinternal(int state);
void addChamp();
void removeChamp();
void moveUp();
void moveDown();
void moved();
signals:
void toggled(bool);
void championChanged(int position, const QString&);
void championsChanged();
private:
// delete all items
void resolveAndAddChamp(const std::string& name);
void resolveAndAddChamp(const std::string& name, bool emitchange = false);
void clear();
void updateEnabled();

View File

@ -96,6 +96,7 @@ QMAKE_CLEAN += $$TRANSLATIONSQM
unix {
$$PWD/linuxdeploy-x86_64.AppImage.commands = wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage && chmod u+x linuxdeploy-x86_64.AppImage
$$PWD/lolautoaccept.png.depends = $$PWD/lolautoaccept.svg
$$PWD/lolautoaccept.png.commands = inkscape -z -e $$PWD/lolautoaccept.png -w 512 -h 512 $$PWD/lolautoaccept.svg
appimg.depends = $$PWD/linuxdeploy-x86_64.AppImage $${TARGET} $$PWD/lolautoaccept.png

View File

@ -1,7 +0,0 @@
#!/bin/bash
rm -rf thirdparty/XInputSimulator/build
mkdir -p thirdparty/XInputSimulator/build
cd thirdparty/XInputSimulator/build/
cmake ../XInputSimulator/
make -j

View File

@ -12,6 +12,9 @@ ChampionSearch::~ChampionSearch() {
}
ChampRow* ChampionSearch::getSearchResult() {
if(ui->championList->count() == 1) {
return (ChampRow*) ui->championList->takeItem(0);
}
int row = ui->championList->currentRow();
return (ChampRow*) ui->championList->takeItem(row);
}

View File

@ -173,25 +173,10 @@ std::vector<const DataDragon::ChampData*> DataDragon::getMatchingChamp(const std
matches.resize(champs.size());
std::transform(champs.begin(), champs.end(), std::insert_iterator(matches, matches.begin()), std::bind(&matchChamp, std::placeholders::_1, lower));
{
Log::Entry e = Log::info << "matches content: ";
for(size_t m : matches) {
e << m << " ";
}
}
// find smallest element
std::vector<size_t> matches_sort = matches;
std::nth_element(matches_sort.begin(), matches_sort.begin(), matches_sort.end(), [](size_t a, size_t b) { return b < a; });
std::nth_element(matches_sort.begin(), matches_sort.begin(), matches_sort.end(), std::greater{});
size_t border = matches_sort.at(0);
{
Log::Entry e = Log::info << "matches_sort content: ";
for(size_t m : matches_sort) {
e << m << " ";
}
}
Log::trace << "border: " << border;
std::vector<const ChampData*> out;

View File

@ -23,14 +23,15 @@ LolAutoAccept::~LolAutoAccept() {
}
}
void LolAutoAccept::setChamps(std::vector<uint32_t> champs, State s) {
void LolAutoAccept::setChamps(const std::vector<uint32_t>& champs, State s) {
if(s == State::LOBBY || s >= State::GAME) {
Log::warn << "setChamps() called on invalid State";
return;
}
stages.at((int) s)->champids = champs;
Log::info << "set champs on state: " << (int) s;
stages.at((int) s)->currentOffset = 0;
Log::info << "set champs on state: " << (int) s << " count: " << champs.size();
}
void LolAutoAccept::setEnabled(bool b, State s) {
@ -97,6 +98,7 @@ void LolAutoAccept::innerRun() {
clientapi->acceptMatch();
}
}
resetAllOffsets();
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
champSelect();
}
@ -110,6 +112,28 @@ void LolAutoAccept::innerRun() {
}
}
void LolAutoAccept::resetAllOffsets() {
for(Stage* stage : stages) {
stage->currentOffset = 0;
}
}
uint32_t LolAutoAccept::getNextChampOfState(State s) {
assert(((int) s) >= 0 && s <= State::PICK);
auto stage = stages[(int) s];
int size = stage->champids.size();
if(size >= stage->currentOffset) {
// no champ to try left
Log::warn << "no champ left at stage: " << (int) s;
Log::warn << "stage size: " << stage->champids.size();
stage->currentOffset = 0;
return 0;
}
return stage->champids[stage->currentOffset++];
}
LolAutoAccept::ownactions_t LolAutoAccept::getOwnActions(int32_t cellid, const std::vector<ClientAPI::ChampSelectAction> actions) {
ownactions_t out;
for(const auto& it : actions) {
@ -130,7 +154,7 @@ void LolAutoAccept::prepickPhase(const ownactions_t& ownactions) {
Log::info << "pre-pick action anvailable: " << it.id << " champid: " << it.championID;
if(it.championID == 0) {
// try to prepick a champion
uint32_t champid = stages.at((int) State::PREPICK)->champids.at(0); // TODO: do on multi selection
uint32_t champid = getNextChampOfState(State::PREPICK);
Log::info << "try to prepick champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, false);
break;
@ -147,7 +171,7 @@ void LolAutoAccept::banPhase(const ownactions_t& ownactions) {
Log::info << "ban action anvailable: " << it.id << " champid: " << it.championID;
if(it.championID == 0) {
// try to ban a champion
uint32_t champid = stages.at((int) State::BAN)->champids.at(0); // TODO
uint32_t champid = getNextChampOfState(State::BAN);
Log::info << "try to ban champ: " << champid;
clientapi->setChampSelectAction(it.id, champid, true);
return;
@ -162,7 +186,7 @@ void LolAutoAccept::pickPhase(const ownactions_t& ownactions) {
for(auto it : ownactions) {
if(it.type == ClientAPI::ChampSelectActionType::PICK) {
Log::info << "pick action anvailable: " << it.id << " champid: " << it.championID;
uint32_t champid = stages.at((int) State::PICK)->champids.at(0); // TODO
uint32_t champid = getNextChampOfState(State::PICK);
if(it.championID != champid || !it.completed) {
// try to prepick a champion
Log::info << "try to pick champ: " << champid;

View File

@ -71,16 +71,27 @@ static std::vector<std::string> toChampionNameList(const std::vector<StageSettin
return out;
}
static std::vector<uint32_t> toChampionIDList(const std::vector<StageSettings::SelectedChamp>& scs) {
std::vector<uint32_t> out;
for(const StageSettings::SelectedChamp& sc : scs) {
out.push_back(sc.id);
}
return out;
}
void MainWindow::pptoggled(bool state) {
Log::info << "enablePrePick checkbox toggled " << state;
lolaa.setEnabled(state, LolAutoAccept::State::PREPICK);
conf.getConfig().prepick.enabled = state;
}
void MainWindow::ppedited(const QString& b) {
Log::info << "prepick edited: " << b.toStdString();
//lolaa.setChamps(dd.getBestMatchingChamp(b.toStdString()).key, LolAutoAccept::State::PREPICK);
conf.getConfig().prepick.champs = toChampionNameList(ui->prepickstage->getChampions());
void MainWindow::ppedited() {
Log::info << "prepick edited";
auto champs = ui->prepickstage->getChampions();
lolaa.setChamps(toChampionIDList(champs), LolAutoAccept::State::PREPICK);
conf.getConfig().prepick.champs = toChampionNameList(champs);
}
void MainWindow::bantoggled(bool state) {
@ -89,10 +100,11 @@ void MainWindow::bantoggled(bool state) {
conf.getConfig().ban.enabled = state;
}
void MainWindow::banedited(const QString& b) {
Log::info << "ban edited: " << b.toStdString();
//lolaa.setChamp(dd.getBestMatchingChamp(b.toStdString()).key, LolAutoAccept::State::BAN);
conf.getConfig().ban.champs = toChampionNameList(ui->banstage->getChampions());
void MainWindow::banedited() {
Log::info << "ban edited";
auto champs = ui->banstage->getChampions();
lolaa.setChamps(toChampionIDList(champs), LolAutoAccept::State::BAN);
conf.getConfig().ban.champs = toChampionNameList(champs);
}
void MainWindow::picktoggled(bool state) {
@ -101,8 +113,9 @@ void MainWindow::picktoggled(bool state) {
conf.getConfig().pick.enabled = state;
}
void MainWindow::pickedited(const QString& b) {
Log::info << "pick edited: " << b.toStdString();
//lolaa.setChamp(dd.getBestMatchingChamp(b.toStdString()).key, LolAutoAccept::State::PICK);
conf.getConfig().pick.champs = toChampionNameList(ui->pickstage->getChampions());
void MainWindow::pickedited() {
Log::info << "pick edited";
auto champs = ui->pickstage->getChampions();
lolaa.setChamps(toChampionIDList(champs), LolAutoAccept::State::PICK);
conf.getConfig().pick.champs = toChampionNameList(champs);
}

View File

@ -11,7 +11,6 @@
StageSettings::StageSettings(QWidget *parent) : QWidget(parent), ui(new Ui::StageSettings) {
ui->setupUi(this);
setMinimumSize(ui->gridLayout->minimumSize());
}
StageSettings::~StageSettings() {
@ -54,10 +53,7 @@ void StageSettings::setChampions(const std::vector<std::string>& champs) {
// add new champs
for(const std::string& champ : champs) {
auto champr = new ChampRow();
ui->championList->addItem(champr);
champr->setChamp(champ, 0, QPixmap("/home/yannis/.cache/lolautoaccept/square/Orianna.png")); // TODO
resolveAndAddChamp(champ, champ == champs.back());
}
}
@ -69,7 +65,7 @@ void StageSettings::addChamp(const std::string& champname, uint32_t id, QPixmap
auto champr = new ChampRow();
ui->championList->addItem(champr);
champr->setChamp(champname, id, icon); // TODO
champr->setChamp(champname, id, icon);
}
void StageSettings::toggledinternal(int state) {
@ -79,8 +75,8 @@ void StageSettings::toggledinternal(int state) {
void StageSettings::addChamp() {
Log::trace << "add champ";
// TODO: popup with champion search
// popup with champion search
ChampionSearch cs(dd, this);
int res = cs.exec();
Log::info << "championsearch result: " << res;
@ -88,10 +84,8 @@ void StageSettings::addChamp() {
auto cr = cs.getSearchResult();
if(cr) {
ui->championList->addItem(cr);
// TODO: emit value changed something
emit championsChanged();
}
} else {
// not accepted
}
}
@ -101,27 +95,21 @@ void StageSettings::removeChamp() {
delete ui->championList->takeItem(row);
}
void StageSettings::moveUp() {
Log::trace << "move up";
if(ui->championList->selectedItems().isEmpty()) return;
auto selection = ui->championList->selectedItems().at(0);
ui->championList->removeItemWidget(selection);
ui->championList->insertItem(0, selection);
void StageSettings::moved() {
Log::trace << "moved";
emit championsChanged();
}
void StageSettings::moveDown() {
Log::trace << "move down";
}
void StageSettings::resolveAndAddChamp(const std::string& name) {
void StageSettings::resolveAndAddChamp(const std::string& name, bool emitchange) {
if(dd) {
int count = 0;
auto cd = dd->getBestMatchingChamp(name, &count);
dd->getImageAsnyc(cd.id, [this, name, cd](QPixmap img) {
dd->getImageAsnyc(cd.id, [this, name, cd, emitchange](QPixmap img) {
addChamp(name, cd.key, img);
emit championChanged(0, QString::fromStdString(cd.name));
if(emitchange) {
emit championsChanged();
}
});
} else {
Log::error << __PRETTY_FUNCTION__ << " Datadragon not set!";
@ -139,7 +127,5 @@ void StageSettings::updateEnabled() {
ui->championList->setEnabled(active);
ui->addChampion->setEnabled(active);
ui->moveup->setEnabled(active);
ui->movedown->setEnabled(active);
ui->removeChampion->setEnabled(active);
}

View File

@ -58,7 +58,7 @@
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
<height>10</height>
</size>
</property>
<property name="name" stdset="0">
@ -80,7 +80,7 @@
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
<height>10</height>
</size>
</property>
<property name="name" stdset="0">
@ -102,7 +102,7 @@
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
<height>10</height>
</size>
</property>
<property name="name" stdset="0">
@ -135,7 +135,7 @@
<header>stagesettings.h</header>
<slots>
<signal>toggled(bool)</signal>
<signal>championChanged(QString)</signal>
<signal>championsChanged()</signal>
</slots>
</customwidget>
</customwidgets>
@ -153,7 +153,7 @@
<hints>
<hint type="sourcelabel">
<x>17</x>
<y>268</y>
<y>258</y>
</hint>
<hint type="destinationlabel">
<x>393</x>
@ -168,12 +168,12 @@
<slot>pptoggled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>170</x>
<y>343</y>
<x>252</x>
<y>338</y>
</hint>
<hint type="destinationlabel">
<x>279</x>
<y>140</y>
<x>296</x>
<y>309</y>
</hint>
</hints>
</connection>
@ -184,76 +184,12 @@
<slot>bantoggled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>140</x>
<y>418</y>
<x>227</x>
<y>413</y>
</hint>
<hint type="destinationlabel">
<x>277</x>
<y>292</y>
</hint>
</hints>
</connection>
<connection>
<sender>pickstage</sender>
<signal>toggled(bool)</signal>
<receiver>MainWindow</receiver>
<slot>picktoggled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>131</x>
<y>493</y>
</hint>
<hint type="destinationlabel">
<x>279</x>
<y>444</y>
</hint>
</hints>
</connection>
<connection>
<sender>prepickstage</sender>
<signal>championChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>ppedited(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>112</x>
<y>343</y>
</hint>
<hint type="destinationlabel">
<x>280</x>
<y>204</y>
</hint>
</hints>
</connection>
<connection>
<sender>banstage</sender>
<signal>championChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>banedited(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>145</x>
<y>418</y>
</hint>
<hint type="destinationlabel">
<x>280</x>
<y>344</y>
</hint>
</hints>
</connection>
<connection>
<sender>pickstage</sender>
<signal>championChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>pickedited(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>493</y>
</hint>
<hint type="destinationlabel">
<x>279</x>
<y>519</y>
<x>265</x>
<y>390</y>
</hint>
</hints>
</connection>
@ -265,7 +201,7 @@
<hints>
<hint type="sourcelabel">
<x>86</x>
<y>168</y>
<y>163</y>
</hint>
<hint type="destinationlabel">
<x>1</x>
@ -273,15 +209,79 @@
</hint>
</hints>
</connection>
<connection>
<sender>pickstage</sender>
<signal>toggled(bool)</signal>
<receiver>MainWindow</receiver>
<slot>picktoggled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>489</y>
</hint>
<hint type="destinationlabel">
<x>265</x>
<y>476</y>
</hint>
</hints>
</connection>
<connection>
<sender>pickstage</sender>
<signal>championsChanged()</signal>
<receiver>MainWindow</receiver>
<slot>pickedited()</slot>
<hints>
<hint type="sourcelabel">
<x>172</x>
<y>498</y>
</hint>
<hint type="destinationlabel">
<x>122</x>
<y>473</y>
</hint>
</hints>
</connection>
<connection>
<sender>banstage</sender>
<signal>championsChanged()</signal>
<receiver>MainWindow</receiver>
<slot>banedited()</slot>
<hints>
<hint type="sourcelabel">
<x>149</x>
<y>418</y>
</hint>
<hint type="destinationlabel">
<x>111</x>
<y>379</y>
</hint>
</hints>
</connection>
<connection>
<sender>prepickstage</sender>
<signal>championsChanged()</signal>
<receiver>MainWindow</receiver>
<slot>ppedited()</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>335</y>
</hint>
<hint type="destinationlabel">
<x>122</x>
<y>308</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>aatoggled(bool)</slot>
<slot>pptoggled(bool)</slot>
<slot>ppedited(QString)</slot>
<slot>ppedited()</slot>
<slot>bantoggled(bool)</slot>
<slot>picktoggled(bool)</slot>
<slot>banedited(QString)</slot>
<slot>pickedited(QString)</slot>
<slot>banedited()</slot>
<slot>pickedited()</slot>
<slot>toggleMainswitch(bool)</slot>
</slots>
</ui>

View File

@ -51,6 +51,24 @@
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addChampion">
<property name="text">
<string>Add Champion</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeChampion">
<property name="text">
<string>Remove Champion</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="championList">
<property name="sizePolicy">
@ -71,40 +89,17 @@
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addChampion">
<property name="text">
<string>Add Champion</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="moveup">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="movedown">
<property name="text">
<string>Move Down</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeChampion">
<property name="text">
<string>Remove Champion</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@ -138,8 +133,8 @@
<slot>addChamp()</slot>
<hints>
<hint type="sourcelabel">
<x>643</x>
<y>209</y>
<x>739</x>
<y>328</y>
</hint>
<hint type="destinationlabel">
<x>757</x>
@ -147,38 +142,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>moveup</sender>
<signal>clicked()</signal>
<receiver>StageSettings</receiver>
<slot>moveUp()</slot>
<hints>
<hint type="sourcelabel">
<x>683</x>
<y>371</y>
</hint>
<hint type="destinationlabel">
<x>758</x>
<y>401</y>
</hint>
</hints>
</connection>
<connection>
<sender>movedown</sender>
<signal>clicked()</signal>
<receiver>StageSettings</receiver>
<slot>moveDown()</slot>
<hints>
<hint type="sourcelabel">
<x>702</x>
<y>526</y>
</hint>
<hint type="destinationlabel">
<x>758</x>
<y>536</y>
</hint>
</hints>
</connection>
<connection>
<sender>removeChampion</sender>
<signal>clicked()</signal>
@ -186,8 +149,8 @@
<slot>removeChamp()</slot>
<hints>
<hint type="sourcelabel">
<x>717</x>
<y>691</y>
<x>739</x>
<y>598</y>
</hint>
<hint type="destinationlabel">
<x>758</x>
@ -197,13 +160,12 @@
</connection>
</connections>
<slots>
<signal>championChanged(QString)</signal>
<signal>toggled(bool)</signal>
<signal>championsChanged()</signal>
<slot>championChangedinternal(QString)</slot>
<slot>toggledinternal(int)</slot>
<slot>addChamp()</slot>
<slot>removeChamp()</slot>
<slot>moveUp()</slot>
<slot>moveDown()</slot>
<slot>moved()</slot>
</slots>
</ui>