1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Make new buttons moddable

This commit is contained in:
George King
2025-03-21 14:17:08 +01:00
committed by GitHub
parent fada0b9d74
commit 1123d944fc
2 changed files with 46 additions and 13 deletions

View File

@ -92,11 +92,33 @@ CCampaignScreen::CCampaignScreen(const JsonNode & config, std::string name)
maxPages = (campaigns.size() + campaignsPerPage - 1) / campaignsPerPage; maxPages = (campaigns.size() + campaignsPerPage - 1) / campaignsPerPage;
buttonNext = std::make_shared<CButton>(Point(340, 560), AnimationPath::builtin("campaigns/next"), std::make_pair("", ""), [this, name]() { switchPage(1, name); });
buttonNext->disable();
buttonPrev = std::make_shared<CButton>(Point(275, 560), AnimationPath::builtin("campaigns/back"), std::make_pair("", ""), [this, name]() { switchPage(-1, name); });
buttonPrev->disable(); if (!config[name]["nextbutton"].isNull())
{
buttonNext = std::make_shared<CButton>(
Point((int)config[name]["nextbutton"]["x"].Float(), (int)config[name]["nextbutton"]["y"].Float()),
AnimationPath::fromJson(config[name]["nextbutton"]["name"]),
std::make_pair("", ""),
[this, name]() { switchPage(1, name); }
);
buttonNext->setHoverable(true);
buttonNext->disable();
}
if (!config[name]["backbutton"].isNull())
{
buttonPrev = std::make_shared<CButton>(
Point((int)config[name]["backbutton"]["x"].Float(), (int)config[name]["backbutton"]["y"].Float()),
AnimationPath::fromJson(config[name]["backbutton"]["name"]),
std::make_pair("", ""),
[this, name]() { switchPage(-1, name); }
);
buttonPrev->setHoverable(true);
buttonPrev->disable();
}
if (!config[name]["exitbutton"].isNull()) if (!config[name]["exitbutton"].isNull())
{ {
@ -232,15 +254,18 @@ void CCampaignScreen::updateCampaignButtons(const JsonNode & parentConfig, const
} }
} }
if(maxId < campaigns.size()) if(buttonNext && buttonPrev)
buttonNext->enable(); {
else if (maxId < campaigns.size())
buttonNext->disable(); buttonNext->enable();
else
buttonNext->disable();
if(currentPage > 0) if (currentPage > 0)
buttonPrev->enable(); buttonPrev->enable();
else else
buttonPrev->disable(); buttonPrev->disable();
}
redraw(); redraw();
} }

View File

@ -64,6 +64,14 @@
ISelectionScreenInfo * SEL = nullptr; ISelectionScreenInfo * SEL = nullptr;
static void do_quit()
{
ENGINE->dispatchMainThread([]()
{
handleQuit(false);
});
}
CMenuScreen::CMenuScreen(const JsonNode & configNode) CMenuScreen::CMenuScreen(const JsonNode & configNode)
: CWindowObject(BORDERED), config(configNode) : CWindowObject(BORDERED), config(configNode)
{ {
@ -202,7 +210,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
break; break;
case 4: //exit case 4: //exit
{ {
return []() { CInfoWindow::showYesNoDialog(LIBRARY->generaltexth->allTexts[69], std::vector<std::shared_ptr<CComponent>>(), [](){GAME->onShutdownRequested(false);}, 0, PlayerColor(1)); }; return []() { CInfoWindow::showYesNoDialog(LIBRARY->generaltexth->allTexts[69], std::vector<std::shared_ptr<CComponent>>(), do_quit, 0, PlayerColor(1)); };
} }
break; break;
case 5: //highscores case 5: //highscores