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

View File

@ -2,8 +2,9 @@
#define BGMENU_H #define BGMENU_H
#include <cstdint> #include <cstdint>
#include <optional>
#include <span> #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; return;
} }
customBgSpan = backgroundMenu(); if(auto newBg = backgroundMenu(); newBg.has_value())
customBgSpan = *newBg;
} }
void doMainMenu(consoleInfo& info) { void doMainMenu(consoleInfo& info) {