diff --git a/include/runeaspektbutton.h b/include/runeaspektbutton.h index 92edeca..a21a250 100644 --- a/include/runeaspektbutton.h +++ b/include/runeaspektbutton.h @@ -27,6 +27,7 @@ signals: public slots: void buttonPressed(); void dataChanged(); // triggers a refresh + void checkSelection(uint32_t aspekt); // only used for rune styles private slots: void setShowSelection(bool selected); // show/hide the red border diff --git a/include/runeeditor.h b/include/runeeditor.h index 0b14adf..fbae762 100644 --- a/include/runeeditor.h +++ b/include/runeeditor.h @@ -41,6 +41,9 @@ public: signals: void selectionChanged(); + void selectPrimary(int aspektId); + void selectSecondary(int aspektId); + private: const RuneStyle* getRuneStyle(uint32_t id) const; RuneAspektButton* createStyleButton(const RuneStyle& rs, bool selected); diff --git a/src/runeaspektbutton.cpp b/src/runeaspektbutton.cpp index 9ab4bc2..af7b9ee 100644 --- a/src/runeaspektbutton.cpp +++ b/src/runeaspektbutton.cpp @@ -41,10 +41,15 @@ void RuneAspektButton::dataChanged() { setShowSelection(selection); } +void RuneAspektButton::checkSelection(uint32_t aspekt) { + qDebug() << "checkSelection: " << text() << aspekt << aspektId; + setShowSelection(aspekt == this->aspektId); +} + void RuneAspektButton::setShowSelection(bool selected) { if(selected) { setStyleSheet("border: 1px solid red;"); } else { setStyleSheet(""); } -} \ No newline at end of file +} diff --git a/src/runeeditor.cpp b/src/runeeditor.cpp index 089cb10..716f3d0 100644 --- a/src/runeeditor.cpp +++ b/src/runeeditor.cpp @@ -33,13 +33,14 @@ void RuneEditor::setClient(ClientAPI& client) { styles = client.getAllRuneStyles(); for(const RuneStyle& rs : styles) { - QPushButton* runeStyleBtn = createStyleButton(rs, rs.id == runepage.primaryStyle); + RuneAspektButton* runeStyleBtn = createStyleButton(rs, rs.id == runepage.primaryStyle); if(!runeStyleBtn) continue; QObject::connect(runeStyleBtn, &QPushButton::pressed, [this, id = rs.id](){ selectStyle(id); }); + QObject::connect(this, &RuneEditor::selectPrimary, runeStyleBtn, &RuneAspektButton::checkSelection); ui->style->addWidget(runeStyleBtn); } @@ -85,6 +86,8 @@ void RuneEditor::selectStyle(uint32_t id) { runepage.selectedAspects.clear(); runepage.selectedAspects.resize(9, 0); + emit selectPrimary(id); + clearLayout(ui->substyle); clearLayout(ui->stylePerks); clearLayout(ui->substylePerks); @@ -92,7 +95,7 @@ void RuneEditor::selectStyle(uint32_t id) { // populate substyles for(int subStyleId : style->allowedSubStyles) { const RuneStyle* substyle = getRuneStyle(subStyleId); - QPushButton* subStyleBtn = createStyleButton(*substyle, false); + RuneAspektButton* subStyleBtn = createStyleButton(*substyle, false); if(!subStyleBtn) continue; @@ -100,6 +103,8 @@ void RuneEditor::selectStyle(uint32_t id) { selectSubStyle(subStyleId); }); + QObject::connect(this, &RuneEditor::selectSecondary, subStyleBtn, &RuneAspektButton::checkSelection); + ui->substyle->addWidget(subStyleBtn); } @@ -116,6 +121,8 @@ void RuneEditor::selectSubStyle(uint32_t id) { if(substyle) { runepage.secondaryStyle = id; + emit selectSecondary(id); + clearLayout(ui->substylePerks); delete groups.at(4); @@ -189,12 +196,12 @@ RuneAspektButton* RuneEditor::createStyleButton(const RuneStyle& rs, bool select styleBtn->setText(rs.name); styleBtn->setToolTip(rs.tooltip); + styleBtn->setAspektId(rs.id); + if(selected) { styleBtn->setStyleSheet("border: 1px solid red;"); } - QObject::connect(this, &RuneEditor::selectionChanged, styleBtn, &RuneAspektButton::dataChanged); - return styleBtn; }