storing runepages
This commit is contained in:
parent
ef36280894
commit
4aa35ff4e1
|
@ -30,6 +30,7 @@ public:
|
|||
|
||||
struct RunePageConfig {
|
||||
RunePageConfig();
|
||||
RunePageConfig(QString name, const RunePage& rp);
|
||||
RunePageConfig(const QJsonObject&);
|
||||
operator QJsonObject() const;
|
||||
|
||||
|
@ -45,12 +46,12 @@ public:
|
|||
std::shared_ptr<Config::PositionConfig> getPositionConfig(Position position);
|
||||
|
||||
std::vector<std::shared_ptr<PositionConfig>> positionConfigs;
|
||||
std::vector<::RunePage*> runePages;
|
||||
std::vector<std::shared_ptr<RunePageConfig>> runePages;
|
||||
|
||||
bool enabledAutoAccept;
|
||||
bool enabledSmiteWarn;
|
||||
bool enabledAutoWrite;
|
||||
std::string autoWriteText;
|
||||
QString autoWriteText;
|
||||
};
|
||||
|
||||
Config();
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace Ui {
|
||||
class RuneManager;
|
||||
}
|
||||
|
@ -18,12 +20,18 @@ public:
|
|||
explicit RuneManager(QWidget* parent = nullptr);
|
||||
~RuneManager();
|
||||
|
||||
void setConfig(Config& config);
|
||||
|
||||
private slots:
|
||||
void loadRunes();
|
||||
void setRunesEnabled(bool enabled);
|
||||
|
||||
void clientRunePageRenamed(QListWidgetItem* item);
|
||||
|
||||
void saveRunePageAA(int id, QString name, const RunePage& rp);
|
||||
|
||||
private:
|
||||
Ui::RuneManager* ui;
|
||||
std::shared_ptr<ClientAPI> client;
|
||||
Config* config = nullptr;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QListWidget>
|
||||
|
||||
#include "clientapi.h"
|
||||
#include "config.h"
|
||||
|
||||
namespace Ui {
|
||||
class RunePageList;
|
||||
|
@ -26,11 +27,17 @@ public:
|
|||
constexpr void setOther(QListWidget* other) { this->other = other; }
|
||||
|
||||
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:
|
||||
virtual void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
void addRunepageItem(QString name, int id, const ::RunePage& rp, bool isCurrent = false);
|
||||
|
||||
Ui::RunePageList* ui;
|
||||
QListWidget* other = nullptr;
|
||||
bool isClient;
|
||||
|
|
|
@ -87,6 +87,8 @@ Config::RunePageConfig::operator QJsonObject() const {
|
|||
|
||||
Config::RootConfig::RootConfig() {}
|
||||
|
||||
Config::RunePageConfig::RunePageConfig(QString name, const RunePage& rp) : name(name), runepage(rp) {}
|
||||
|
||||
Config::RootConfig::RootConfig(const QJsonObject& j) {
|
||||
if(j.contains("version")) {
|
||||
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);
|
||||
enabledSmiteWarn = getValue(j, "enabledSmiteWarn", true);
|
||||
enabledAutoWrite = getValue(j, "enabledAutoWrite", false);
|
||||
autoWriteText = getValue<std::string>(j, "autoWriteText");
|
||||
autoWriteText = getValue<QString>(j, "autoWriteText");
|
||||
}
|
||||
|
||||
Config::RootConfig::operator QJsonObject() const {
|
||||
|
@ -126,11 +140,17 @@ Config::RootConfig::operator QJsonObject() const {
|
|||
positionarr.push_back((QJsonObject) *pos.get());
|
||||
}
|
||||
|
||||
QJsonArray runepagesArr;
|
||||
for(std::shared_ptr<RunePageConfig> rp : runePages) {
|
||||
runepagesArr.push_back((QJsonObject) *rp);
|
||||
}
|
||||
|
||||
out["positions"] = positionarr;
|
||||
out["runepages"] = runepagesArr;
|
||||
out.insert("enabledAutoAccept", enabledAutoAccept);
|
||||
out.insert("enabledSmiteWarn", enabledSmiteWarn);
|
||||
out.insert("enabledAutoWrite", enabledAutoWrite);
|
||||
out.insert("autoWriteText", QString::fromStdString(autoWriteText));
|
||||
out.insert("autoWriteText", autoWriteText);
|
||||
out.insert("version", 1);
|
||||
|
||||
return out;
|
||||
|
|
|
@ -30,6 +30,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui
|
|||
QObject::connect(tab, &SettingsTab::toggled, this, &MainWindow::tabtoggled);
|
||||
}
|
||||
|
||||
ui->runesPage->setConfig(conf);
|
||||
|
||||
ui->enableAll->setChecked(rc.enabledAutoAccept);
|
||||
lolaa.setEnabled(rc.enabledAutoAccept, LolAutoAccept::State::LOBBY);
|
||||
|
||||
|
@ -37,8 +39,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui
|
|||
lolaa.setSmiteWarn(rc.enabledSmiteWarn);
|
||||
|
||||
ui->enableAutoWrite->setChecked(rc.enabledAutoWrite);
|
||||
ui->autoWriteText->setText(QString::fromStdString(rc.autoWriteText));
|
||||
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText);
|
||||
ui->autoWriteText->setText(rc.autoWriteText);
|
||||
lolaa.setAutoWriteText(rc.enabledAutoWrite, rc.autoWriteText.toStdString());
|
||||
|
||||
resizeEvent(nullptr);
|
||||
|
||||
|
@ -143,9 +145,9 @@ void MainWindow::autoWriteChanged() {
|
|||
if( loading ) return;
|
||||
|
||||
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().autoWriteText = text;
|
||||
|
|
|
@ -14,6 +14,8 @@ RuneManager::RuneManager(QWidget* parent) : QWidget(parent), ui(new Ui::RuneMana
|
|||
ui->listClientRunes->setOther(ui->listaaRunes);
|
||||
ui->listaaRunes->setOther(ui->listClientRunes);
|
||||
|
||||
QObject::connect(ui->listaaRunes, &RunePageList::runepageChanged, this, &RuneManager::saveRunePageAA);
|
||||
|
||||
loadRunes();
|
||||
}
|
||||
|
||||
|
@ -21,6 +23,11 @@ RuneManager::~RuneManager() {
|
|||
delete this->ui;
|
||||
}
|
||||
|
||||
void RuneManager::setConfig(Config& config) {
|
||||
this->config = &config;
|
||||
ui->listaaRunes->loadRunePages(config.getConfig().runePages);
|
||||
}
|
||||
|
||||
void RuneManager::loadRunes() {
|
||||
if(!client) {
|
||||
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) {
|
||||
clear();
|
||||
for(const ClientAPI::RunePage& rp : pages) {
|
||||
QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(rp.name));
|
||||
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);
|
||||
addItem(item);
|
||||
if(rp.isCurrent) {
|
||||
item->setSelected(true);
|
||||
}
|
||||
addRunepageItem(QString::fromStdString(rp.name), rp.id, rp.runepage, rp.isCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
void RunePageList::loadRunePages(const std::vector<std::shared_ptr<Config::RunePageConfig>>& pages) {
|
||||
clear();
|
||||
for(size_t i = 0; i < pages.size(); ++i) {
|
||||
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();
|
||||
return;
|
||||
}
|
||||
qDebug() << "data: " << selected.at(0)->data(RoleId);
|
||||
QListWidgetItem* item = selected.at(0);
|
||||
qDebug() << "data: " << item->data(RoleId);
|
||||
|
||||
// compare rune pages for duplicates?
|
||||
|
||||
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