forked from MrBesen/lolautoaccept
storing runepages
This commit is contained in:
parent
ef36280894
commit
4aa35ff4e1
|
@ -30,6 +30,7 @@ public:
|
||||||
|
|
||||||
struct RunePageConfig {
|
struct RunePageConfig {
|
||||||
RunePageConfig();
|
RunePageConfig();
|
||||||
|
RunePageConfig(QString name, const RunePage& rp);
|
||||||
RunePageConfig(const QJsonObject&);
|
RunePageConfig(const QJsonObject&);
|
||||||
operator QJsonObject() const;
|
operator QJsonObject() const;
|
||||||
|
|
||||||
|
@ -45,12 +46,12 @@ public:
|
||||||
std::shared_ptr<Config::PositionConfig> getPositionConfig(Position position);
|
std::shared_ptr<Config::PositionConfig> getPositionConfig(Position position);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PositionConfig>> positionConfigs;
|
std::vector<std::shared_ptr<PositionConfig>> positionConfigs;
|
||||||
std::vector<::RunePage*> runePages;
|
std::vector<std::shared_ptr<RunePageConfig>> runePages;
|
||||||
|
|
||||||
bool enabledAutoAccept;
|
bool enabledAutoAccept;
|
||||||
bool enabledSmiteWarn;
|
bool enabledSmiteWarn;
|
||||||
bool enabledAutoWrite;
|
bool enabledAutoWrite;
|
||||||
std::string autoWriteText;
|
QString autoWriteText;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config();
|
Config();
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RuneManager;
|
class RuneManager;
|
||||||
}
|
}
|
||||||
|
@ -18,12 +20,18 @@ public:
|
||||||
explicit RuneManager(QWidget* parent = nullptr);
|
explicit RuneManager(QWidget* parent = nullptr);
|
||||||
~RuneManager();
|
~RuneManager();
|
||||||
|
|
||||||
|
void setConfig(Config& config);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadRunes();
|
void loadRunes();
|
||||||
void setRunesEnabled(bool enabled);
|
void setRunesEnabled(bool enabled);
|
||||||
|
|
||||||
void clientRunePageRenamed(QListWidgetItem* item);
|
void clientRunePageRenamed(QListWidgetItem* item);
|
||||||
|
|
||||||
|
void saveRunePageAA(int id, QString name, const RunePage& rp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::RuneManager* ui;
|
Ui::RuneManager* ui;
|
||||||
std::shared_ptr<ClientAPI> client;
|
std::shared_ptr<ClientAPI> client;
|
||||||
|
Config* config = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
|
||||||
#include "clientapi.h"
|
#include "clientapi.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RunePageList;
|
class RunePageList;
|
||||||
|
@ -26,11 +27,17 @@ public:
|
||||||
constexpr void setOther(QListWidget* other) { this->other = other; }
|
constexpr void setOther(QListWidget* other) { this->other = other; }
|
||||||
|
|
||||||
void loadRunePages(const std::vector<ClientAPI::RunePage>& pages);
|
void loadRunePages(const std::vector<ClientAPI::RunePage>& pages);
|
||||||
|
void loadRunePages(const std::vector<std::shared_ptr<Config::RunePageConfig>>& pages);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void runepageChanged(int id, QString name, const RunePage& rp);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void dropEvent(QDropEvent* event) override;
|
virtual void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addRunepageItem(QString name, int id, const ::RunePage& rp, bool isCurrent = false);
|
||||||
|
|
||||||
Ui::RunePageList* ui;
|
Ui::RunePageList* ui;
|
||||||
QListWidget* other = nullptr;
|
QListWidget* other = nullptr;
|
||||||
bool isClient;
|
bool isClient;
|
||||||
|
|
|
@ -87,6 +87,8 @@ Config::RunePageConfig::operator QJsonObject() const {
|
||||||
|
|
||||||
Config::RootConfig::RootConfig() {}
|
Config::RootConfig::RootConfig() {}
|
||||||
|
|
||||||
|
Config::RunePageConfig::RunePageConfig(QString name, const RunePage& rp) : name(name), runepage(rp) {}
|
||||||
|
|
||||||
Config::RootConfig::RootConfig(const QJsonObject& j) {
|
Config::RootConfig::RootConfig(const QJsonObject& j) {
|
||||||
if(j.contains("version")) {
|
if(j.contains("version")) {
|
||||||
int version = j["version"].toInt();
|
int version = j["version"].toInt();
|
||||||
|
@ -112,10 +114,22 @@ Config::RootConfig::RootConfig(const QJsonObject& j) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto runepagesRef = j["runepages"];
|
||||||
|
if(runepagesRef.isArray()) {
|
||||||
|
QJsonArray jpages = runepagesRef.toArray();
|
||||||
|
|
||||||
|
runePages.reserve(jpages.size());
|
||||||
|
for(QJsonValue val : jpages) {
|
||||||
|
if(val.isObject()) {
|
||||||
|
runePages.push_back(std::make_shared<RunePageConfig>(val.toObject()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enabledAutoAccept = getValue(j, "enabledAutoAccept", true);
|
enabledAutoAccept = getValue(j, "enabledAutoAccept", true);
|
||||||
enabledSmiteWarn = getValue(j, "enabledSmiteWarn", true);
|
enabledSmiteWarn = getValue(j, "enabledSmiteWarn", true);
|
||||||
enabledAutoWrite = getValue(j, "enabledAutoWrite", false);
|
enabledAutoWrite = getValue(j, "enabledAutoWrite", false);
|
||||||
autoWriteText = getValue<std::string>(j, "autoWriteText");
|
autoWriteText = getValue<QString>(j, "autoWriteText");
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::RootConfig::operator QJsonObject() const {
|
Config::RootConfig::operator QJsonObject() const {
|
||||||
|
@ -126,11 +140,17 @@ Config::RootConfig::operator QJsonObject() const {
|
||||||
positionarr.push_back((QJsonObject) *pos.get());
|
positionarr.push_back((QJsonObject) *pos.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonArray runepagesArr;
|
||||||
|
for(std::shared_ptr<RunePageConfig> rp : runePages) {
|
||||||
|
runepagesArr.push_back((QJsonObject) *rp);
|
||||||
|
}
|
||||||
|
|
||||||
out["positions"] = positionarr;
|
out["positions"] = positionarr;
|
||||||
|
out["runepages"] = runepagesArr;
|
||||||
out.insert("enabledAutoAccept", enabledAutoAccept);
|
out.insert("enabledAutoAccept", enabledAutoAccept);
|
||||||
out.insert("enabledSmiteWarn", enabledSmiteWarn);
|
out.insert("enabledSmiteWarn", enabledSmiteWarn);
|
||||||
out.insert("enabledAutoWrite", enabledAutoWrite);
|
out.insert("enabledAutoWrite", enabledAutoWrite);
|
||||||
out.insert("autoWriteText", QString::fromStdString(autoWriteText));
|
out.insert("autoWriteText", autoWriteText);
|
||||||
out.insert("version", 1);
|
out.insert("version", 1);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
|
@ -30,6 +30,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui
|
||||||
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui->runesPage->setConfig(conf);
|
||||||
|
|
||||||
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
||||||
lolaa.setEnabled(rc.enabledAutoAccept, LolAutoAccept::State::LOBBY);
|
lolaa.setEnabled(rc.enabledAutoAccept, LolAutoAccept::State::LOBBY);
|
||||||
|
|
||||||
|
@ -37,8 +39,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui
|
||||||
lolaa.setSmiteWarn(rc.enabledSmiteWarn);
|
lolaa.setSmiteWarn(rc.enabledSmiteWarn);
|
||||||
|
|
||||||
ui->enableAutoWrite->setChecked(rc.enabledAutoWrite);
|
ui->enableAutoWrite->setChecked(rc.enabledAutoWrite);
|
||||||
ui->autoWriteText->setText(QString::fromStdString(rc.autoWriteText));
|
ui->autoWriteText->setText(rc.autoWriteText);
|
||||||
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText.toStdString());
|
||||||
|
|
||||||
resizeEvent(nullptr);
|
resizeEvent(nullptr);
|
||||||
|
|
||||||
|
@ -143,9 +145,9 @@ void MainWindow::autoWriteChanged() {
|
||||||
if( loading ) return;
|
if( loading ) return;
|
||||||
|
|
||||||
bool enabled = ui->enableAutoWrite->isChecked();
|
bool enabled = ui->enableAutoWrite->isChecked();
|
||||||
const std::string text = ui->autoWriteText->toPlainText().toStdString();
|
const QString text = ui->autoWriteText->toPlainText();
|
||||||
|
|
||||||
lolaa.setAutoWriteText(enabled, text);
|
lolaa.setAutoWriteText(enabled, text.toStdString());
|
||||||
|
|
||||||
conf.getConfig().enabledAutoWrite = enabled;
|
conf.getConfig().enabledAutoWrite = enabled;
|
||||||
conf.getConfig().autoWriteText = text;
|
conf.getConfig().autoWriteText = text;
|
||||||
|
|
|
@ -14,6 +14,8 @@ RuneManager::RuneManager(QWidget* parent) : QWidget(parent), ui(new Ui::RuneMana
|
||||||
ui->listClientRunes->setOther(ui->listaaRunes);
|
ui->listClientRunes->setOther(ui->listaaRunes);
|
||||||
ui->listaaRunes->setOther(ui->listClientRunes);
|
ui->listaaRunes->setOther(ui->listClientRunes);
|
||||||
|
|
||||||
|
QObject::connect(ui->listaaRunes, &RunePageList::runepageChanged, this, &RuneManager::saveRunePageAA);
|
||||||
|
|
||||||
loadRunes();
|
loadRunes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +23,11 @@ RuneManager::~RuneManager() {
|
||||||
delete this->ui;
|
delete this->ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuneManager::setConfig(Config& config) {
|
||||||
|
this->config = &config;
|
||||||
|
ui->listaaRunes->loadRunePages(config.getConfig().runePages);
|
||||||
|
}
|
||||||
|
|
||||||
void RuneManager::loadRunes() {
|
void RuneManager::loadRunes() {
|
||||||
if(!client) {
|
if(!client) {
|
||||||
auto ca = ClientAccess::find();
|
auto ca = ClientAccess::find();
|
||||||
|
@ -66,3 +73,26 @@ void RuneManager::clientRunePageRenamed(QListWidgetItem* item) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuneManager::saveRunePageAA(int id, QString name, const RunePage& rp) {
|
||||||
|
if(!config) return;
|
||||||
|
|
||||||
|
Config::RootConfig& rc = config->getConfig();
|
||||||
|
auto& pages = rc.runePages;
|
||||||
|
if(id == -1) {
|
||||||
|
// int newId = pages.size();
|
||||||
|
pages.push_back(std::make_shared<Config::RunePageConfig>(name, rp));
|
||||||
|
} else {
|
||||||
|
if((int) pages.size() > id && id >= 0) {
|
||||||
|
pages.at(id)->runepage = rp;
|
||||||
|
} else {
|
||||||
|
// unkown id
|
||||||
|
qWarning() << "unknown runepage id:" << id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config->save();
|
||||||
|
|
||||||
|
// reload runes
|
||||||
|
ui->listaaRunes->loadRunePages(pages);
|
||||||
|
}
|
||||||
|
|
|
@ -16,15 +16,15 @@ RunePageList::~RunePageList() {
|
||||||
void RunePageList::loadRunePages(const std::vector<ClientAPI::RunePage>& pages) {
|
void RunePageList::loadRunePages(const std::vector<ClientAPI::RunePage>& pages) {
|
||||||
clear();
|
clear();
|
||||||
for(const ClientAPI::RunePage& rp : pages) {
|
for(const ClientAPI::RunePage& rp : pages) {
|
||||||
QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(rp.name));
|
addRunepageItem(QString::fromStdString(rp.name), rp.id, rp.runepage, rp.isCurrent);
|
||||||
item->setData(RoleId, (uint) rp.id);
|
}
|
||||||
item->setData(RolePointer, (qulonglong) new ::RunePage(rp.runepage));
|
}
|
||||||
item->setToolTip(QString("id: %0").arg(rp.id));
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
void RunePageList::loadRunePages(const std::vector<std::shared_ptr<Config::RunePageConfig>>& pages) {
|
||||||
addItem(item);
|
clear();
|
||||||
if(rp.isCurrent) {
|
for(size_t i = 0; i < pages.size(); ++i) {
|
||||||
item->setSelected(true);
|
std::shared_ptr<Config::RunePageConfig> rp = pages.at(i);
|
||||||
}
|
addRunepageItem(rp->name, i, rp->runepage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,30 @@ void RunePageList::dropEvent(QDropEvent* event) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "data: " << selected.at(0)->data(RoleId);
|
QListWidgetItem* item = selected.at(0);
|
||||||
|
qDebug() << "data: " << item->data(RoleId);
|
||||||
|
|
||||||
// compare rune pages for duplicates?
|
// compare rune pages for duplicates?
|
||||||
|
|
||||||
QListWidget::dropEvent(event);
|
QListWidget::dropEvent(event);
|
||||||
|
|
||||||
|
// save change
|
||||||
|
QString name = item->text();
|
||||||
|
const RunePage* oldPage = (RunePage*) item->data(RolePointer).toULongLong();
|
||||||
|
|
||||||
|
emit runepageChanged(-1, name, *oldPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunePageList::addRunepageItem(QString name, int id, const ::RunePage& rp, bool isCurrent) {
|
||||||
|
QListWidgetItem* item = new QListWidgetItem(name);
|
||||||
|
item->setData(RoleId, (uint) id);
|
||||||
|
item->setData(RolePointer, (qulonglong) new ::RunePage(rp));
|
||||||
|
if(id != -1) {
|
||||||
|
item->setToolTip(QString("id: %0").arg(id));
|
||||||
|
}
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||||
|
if(isCurrent) {
|
||||||
|
item->setSelected(true);
|
||||||
|
}
|
||||||
|
addItem(item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue