Swap the backgrounds after vblank and properly handle "cancel" and "default" bg options

This commit is contained in:
Edoardo Lolletti 2025-08-21 00:15:07 +02:00
parent e88dc13af8
commit 0ad0dc18bc
3 changed files with 16 additions and 5 deletions

View File

@ -46,7 +46,7 @@ static const auto& getBackgroundList()
return bgs;
}
std::span<uint8_t> backgroundMenu()
std::optional<std::span<uint8_t>> backgroundMenu()
{
//top screen
clearScreen(&topScreen);
@ -88,15 +88,24 @@ std::span<uint8_t> backgroundMenu()
}
}
if(programEnd)
return std::nullopt;
auto selection = static_cast<size_t>(m->cursor);
if(selection > bgs.size())
if(selection == bgs.size())
return {};
else if (selection > bgs.size())
{
return std::nullopt;
}
try {
const auto res = parseGif(bgs[selection].second.data(), currentlyLoadedGif, bgGetGfxPtr(bgGifTop));
swiWaitForVBlank();
bgHide(topScreen.bgId);
bgShow(bgGifTop);
auto confirmed = (choiceBox("Confirm this background?") == YES);
swiWaitForVBlank();
bgShow(topScreen.bgId);
bgHide(bgGifTop);
if(confirmed)

View File

@ -2,8 +2,9 @@
#define BGMENU_H
#include <cstdint>
#include <optional>
#include <span>
std::span<uint8_t> backgroundMenu();
std::optional<std::span<uint8_t>> backgroundMenu();
#endif
#endif

View File

@ -620,7 +620,8 @@ void customBg() {
{
return;
}
customBgSpan = backgroundMenu();
if(auto newBg = backgroundMenu(); newBg.has_value())
customBgSpan = *newBg;
}
void doMainMenu(consoleInfo& info) {