mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-15 06:52:15 -07:00
Add navigation widget for budget and game changers.
This commit is contained in:
parent
375869f873
commit
2dd255f314
9 changed files with 43 additions and 33 deletions
|
|
@ -6,7 +6,7 @@
|
|||
EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCommanderDetailsDisplayWidget(
|
||||
QWidget *parent,
|
||||
const EdhrecCommanderApiResponseCommanderDetails &_commanderDetails,
|
||||
QUrl baseUrl)
|
||||
QString baseUrl)
|
||||
: QWidget(parent), commanderDetails(_commanderDetails)
|
||||
{
|
||||
layout = new QVBoxLayout(this);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
explicit EdhrecCommanderResponseCommanderDetailsDisplayWidget(
|
||||
QWidget *parent,
|
||||
const EdhrecCommanderApiResponseCommanderDetails &_commanderDetails,
|
||||
QUrl baseUrl);
|
||||
QString baseUrl);
|
||||
void retranslateUi();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
EdhrecCommanderApiResponseDisplayWidget::EdhrecCommanderApiResponseDisplayWidget(QWidget *parent,
|
||||
EdhrecCommanderApiResponse response,
|
||||
QUrl baseUrl)
|
||||
QString baseUrl)
|
||||
: QWidget(parent)
|
||||
{
|
||||
layout = new QHBoxLayout(this);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class EdhrecCommanderApiResponseDisplayWidget : public QWidget
|
|||
public:
|
||||
explicit EdhrecCommanderApiResponseDisplayWidget(QWidget *parent,
|
||||
EdhrecCommanderApiResponse response,
|
||||
QUrl baseUrl);
|
||||
QString baseUrl);
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
EdhrecCommanderApiResponseNavigationWidget::EdhrecCommanderApiResponseNavigationWidget(
|
||||
QWidget *parent,
|
||||
const EdhrecCommanderApiResponseCommanderDetails &_commanderDetails,
|
||||
QUrl baseUrl)
|
||||
QString baseUrl)
|
||||
: QWidget(parent), commanderDetails(_commanderDetails)
|
||||
{
|
||||
qInfo() << commanderDetails.getUrl();
|
||||
layout = new QGridLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ EdhrecCommanderApiResponseNavigationWidget::EdhrecCommanderApiResponseNavigation
|
|||
|
||||
for (int i = 0; i < gameChangerOptions.length(); i++) {
|
||||
QString option = gameChangerOptions.at(i);
|
||||
QString label = option.isEmpty() ? "Any" : option.at(0).toUpper() + option.mid(1);
|
||||
QString label = option.isEmpty() ? "All" : option.at(0).toUpper() + option.mid(1);
|
||||
QPushButton *btn = new QPushButton(label, this);
|
||||
gameChangerButtons[option] = btn;
|
||||
layout->addWidget(btn, 2, i);
|
||||
|
|
@ -76,7 +75,7 @@ EdhrecCommanderApiResponseNavigationWidget::EdhrecCommanderApiResponseNavigation
|
|||
}
|
||||
|
||||
retranslateUi();
|
||||
applyOptionsFromUrl(baseUrl.toString());
|
||||
applyOptionsFromUrl(baseUrl);
|
||||
}
|
||||
|
||||
void EdhrecCommanderApiResponseNavigationWidget::retranslateUi()
|
||||
|
|
@ -89,32 +88,46 @@ void EdhrecCommanderApiResponseNavigationWidget::retranslateUi()
|
|||
|
||||
void EdhrecCommanderApiResponseNavigationWidget::applyOptionsFromUrl(const QString &url)
|
||||
{
|
||||
// Example input: /commanders/kaalia-of-the-vast/core/budget
|
||||
QStringList parts = url.split('/', Qt::SkipEmptyParts);
|
||||
QString cleanedUrl = url;
|
||||
|
||||
// Remove base and file extension
|
||||
if (cleanedUrl.startsWith("https://json.edhrec.com/pages/"))
|
||||
cleanedUrl = cleanedUrl.mid(QString("https://json.edhrec.com/pages/").length());
|
||||
if (cleanedUrl.endsWith(".json"))
|
||||
cleanedUrl.chop(5);
|
||||
|
||||
// Expecting something like: "commanders/the-ur-dragon/core/expensive"
|
||||
QStringList parts = cleanedUrl.split('/', Qt::SkipEmptyParts);
|
||||
|
||||
// Make sure there's at least a base + commander name
|
||||
if (parts.size() < 2)
|
||||
return;
|
||||
|
||||
// Extract extra segments, if any
|
||||
QString commanderName = parts[1];
|
||||
QString gameChangerOpt, budgetOpt;
|
||||
|
||||
if (parts.size() >= 3)
|
||||
gameChangerOpt = parts[2]; // this would be "core", "upgraded", etc.
|
||||
if (parts.size() >= 4)
|
||||
budgetOpt = parts[3]; // "budget" or "expensive"
|
||||
// Define valid sets
|
||||
QSet<QString> validGameChangers = {"core", "upgraded", "optimized"};
|
||||
QSet<QString> validBudgets = {"budget", "expensive"};
|
||||
|
||||
// Defensive: only accept known values
|
||||
// Check remaining parts after commander
|
||||
for (int i = 2; i < parts.size(); ++i) {
|
||||
QString part = parts[i].toLower();
|
||||
if (validGameChangers.contains(part)) {
|
||||
gameChangerOpt = part;
|
||||
} else if (validBudgets.contains(part)) {
|
||||
budgetOpt = part;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate and apply
|
||||
if (!gameChangerButtons.contains(gameChangerOpt))
|
||||
gameChangerOpt = "";
|
||||
gameChangerOpt.clear();
|
||||
if (!budgetButtons.contains(budgetOpt))
|
||||
budgetOpt = "";
|
||||
budgetOpt.clear();
|
||||
|
||||
// Apply internal state
|
||||
selectedGameChanger = gameChangerOpt;
|
||||
selectedBudget = budgetOpt;
|
||||
|
||||
// Apply visual state
|
||||
updateOptionButtonSelection(gameChangerButtons, selectedGameChanger);
|
||||
updateOptionButtonSelection(budgetButtons, selectedBudget);
|
||||
}
|
||||
|
|
@ -139,12 +152,7 @@ void EdhrecCommanderApiResponseNavigationWidget::actRequestCommanderNavigation()
|
|||
|
||||
void EdhrecCommanderApiResponseNavigationWidget::actRequestComboNavigation()
|
||||
{
|
||||
QString url = "/combos/" + commanderDetails.getSanitized();
|
||||
if (!selectedGameChanger.isEmpty())
|
||||
url += "/" + selectedGameChanger;
|
||||
if (!selectedBudget.isEmpty())
|
||||
url += "/" + selectedBudget;
|
||||
emit requestUrl(url);
|
||||
emit requestUrl("/combos/" + commanderDetails.getSanitized());
|
||||
}
|
||||
|
||||
void EdhrecCommanderApiResponseNavigationWidget::actRequestAverageDeckNavigation()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public:
|
|||
explicit EdhrecCommanderApiResponseNavigationWidget(
|
||||
QWidget *parent,
|
||||
const EdhrecCommanderApiResponseCommanderDetails &_commanderDetails,
|
||||
QUrl baseUrl);
|
||||
QString baseUrl);
|
||||
void retranslateUi();
|
||||
void applyOptionsFromUrl(const QString &url);
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ void TabEdhRec::processApiJson(QNetworkReply *reply)
|
|||
EdhrecCommanderApiResponse deckData;
|
||||
deckData.fromJson(jsonObj);
|
||||
|
||||
displayWidget = new EdhrecCommanderApiResponseDisplayWidget(this, deckData, reply->url());
|
||||
displayWidget = new EdhrecCommanderApiResponseDisplayWidget(this, deckData, reply->url().toString());
|
||||
// flowWidget->addWidget(displayWidget);
|
||||
setCentralWidget(displayWidget);
|
||||
|
||||
|
|
|
|||
|
|
@ -215,7 +215,8 @@ void TabEdhRecMain::processApiJson(QNetworkReply *reply)
|
|||
if (responseUrl.startsWith("https://json.edhrec.com/pages/commanders/year.json")) {
|
||||
processTopCommandersResponse(jsonObj);
|
||||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/commanders/")) {
|
||||
processCommanderResponse(jsonObj);
|
||||
qInfo() << "Received top kek";
|
||||
processCommanderResponse(jsonObj, responseUrl);
|
||||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/cards/")) {
|
||||
processCommanderResponse(jsonObj);
|
||||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/tags/")) {
|
||||
|
|
@ -225,6 +226,7 @@ void TabEdhRecMain::processApiJson(QNetworkReply *reply)
|
|||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/top/year.json")) {
|
||||
processTopCardsResponse(jsonObj);
|
||||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/combos/")) {
|
||||
qInfo() << "Received combos";
|
||||
processCommanderResponse(jsonObj);
|
||||
} else if (responseUrl.startsWith("https://json.edhrec.com/pages/average-decks/")) {
|
||||
processAverageDeckResponse(jsonObj);
|
||||
|
|
@ -316,7 +318,7 @@ void TabEdhRecMain::processTopCommandersResponse(QJsonObject reply)
|
|||
mainLayout->setStretch(1, 1); // Make sure currentPageDisplay takes remaining space
|
||||
}
|
||||
|
||||
void TabEdhRecMain::processCommanderResponse(QJsonObject reply)
|
||||
void TabEdhRecMain::processCommanderResponse(QJsonObject reply, QString responseUrl)
|
||||
{
|
||||
EdhrecCommanderApiResponse deckData;
|
||||
deckData.fromJson(reply);
|
||||
|
|
@ -333,7 +335,7 @@ void TabEdhRecMain::processCommanderResponse(QJsonObject reply)
|
|||
currentPageLayout = new QVBoxLayout(currentPageDisplay);
|
||||
currentPageDisplay->setLayout(currentPageLayout);
|
||||
|
||||
auto display = new EdhrecCommanderApiResponseDisplayWidget(currentPageDisplay, deckData, QUrl(""));
|
||||
auto display = new EdhrecCommanderApiResponseDisplayWidget(currentPageDisplay, deckData, responseUrl);
|
||||
currentPageLayout->addWidget(display);
|
||||
|
||||
mainLayout->addWidget(currentPageDisplay);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void processApiJson(QNetworkReply *reply);
|
||||
void processCommanderResponse(QJsonObject reply, QString responseUrl = "");
|
||||
void processTopCardsResponse(QJsonObject reply);
|
||||
void processTopTagsResponse(QJsonObject reply);
|
||||
void processTopCommandersResponse(QJsonObject reply);
|
||||
|
|
@ -55,7 +56,6 @@ private:
|
|||
CardInfoPtr cardToQuery;
|
||||
EdhrecCommanderApiResponseDisplayWidget *displayWidget;
|
||||
|
||||
void processCommanderResponse(QJsonObject reply);
|
||||
};
|
||||
|
||||
#endif // TAB_EDHREC_MAIN_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue