GBA Context: Add pause menu
Jeffrey Pfau jeffrey@endrift.com
Sun, 30 Aug 2015 16:51:40 -0700
2 files changed,
77 insertions(+),
19 deletions(-)
M
src/gba/context/gui-runner.c
→
src/gba/context/gui-runner.c
@@ -7,6 +7,12 @@ #include "gui-runner.h"
#include "util/gui/file-select.h" #include "util/gui/font.h" +#include "util/gui/menu.h" + +enum { + RUNNER_CONTINUE, + RUNNER_EXIT +}; void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) { GUIInit(&runner->params);@@ -24,6 +30,14 @@ GBAContextDeinit(&runner->context);
} void GBAGUIRunloop(struct GBAGUIRunner* runner) { + struct GUIMenu pauseMenu = { + .title = "Game Paused", + .index = 0, + }; + GUIMenuItemListInit(&pauseMenu.items, 0); + *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE }; + *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT }; + while (true) { if (runner->params.guiPrepare) { runner->params.guiPrepare();@@ -33,10 +47,8 @@ if (!GUISelectFile(&runner->params, path, sizeof(path), GBAIsROM)) {
if (runner->params.guiFinish) { runner->params.guiFinish(); } + GUIMenuItemListDeinit(&pauseMenu.items); return; - } - if (runner->params.guiFinish) { - runner->params.guiFinish(); } // TODO: Message box API@@ -55,22 +67,59 @@ GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_TEXT_CENTER, 0xFFFFFFFF, "Load failed!");
runner->params.drawEnd(); } } + if (runner->params.guiFinish) { + runner->params.guiFinish(); + } GBAContextStart(&runner->context); if (runner->gameLoaded) { runner->gameLoaded(runner); } - while (true) { - int guiKeys = runner->params.pollInput(); - if (guiKeys & (1 << GUI_INPUT_CANCEL)) { - break; + bool running = true; + while (running) { + while (true) { + int guiKeys = runner->params.pollInput(); + if (guiKeys & (1 << GUI_INPUT_CANCEL)) { + break; + } + uint16_t keys = runner->pollGameInput(runner); + if (runner->prepareForFrame) { + runner->prepareForFrame(runner); + } + GBAContextFrame(&runner->context, keys); + if (runner->drawFrame) { + runner->drawFrame(runner, false); + } } - uint16_t keys = runner->pollGameInput(runner); - if (runner->prepareForFrame) { - runner->prepareForFrame(runner); + + if (runner->params.guiPrepare) { + runner->params.guiPrepare(); } - GBAContextFrame(&runner->context, keys); - if (runner->drawFrame) { - runner->drawFrame(runner, false); + GUIInvalidateKeys(&runner->params); + while (true) { + struct GUIMenuItem item; + enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item); + if (reason == GUI_MENU_EXIT_ACCEPT) { + if (item.data == (void*) RUNNER_EXIT) { + running = false; + break; + } + if (item.data == (void*) RUNNER_CONTINUE) { + int keys = -1; + while (keys) { + GUIPollInput(&runner->params, 0, &keys); + } + break; + } + } else { + int keys = -1; + while (keys) { + GUIPollInput(&runner->params, 0, &keys); + } + break; + } + } + if (runner->params.guiFinish) { + runner->params.guiFinish(); } } GBAContextStop(&runner->context);@@ -79,4 +128,5 @@ runner->gameUnloaded(runner);
} GBAContextUnloadROM(&runner->context); } + GUIMenuItemListDeinit(&pauseMenu.items); }
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -35,6 +35,7 @@ static void _drawStart(void);
static void _drawEnd(void); static int _pollInput(void); static void _guiPrepare(void); +static void _guiFinish(void); static void _setup(struct GBAGUIRunner* runner); static void _gameLoaded(struct GBAGUIRunner* runner);@@ -160,7 +161,7 @@ .params = {
352, 230, font, "/", _drawStart, _drawEnd, _pollInput, - _guiPrepare, 0, + _guiPrepare, _guiFinish, GUI_PARAMS_TRAIL },@@ -285,6 +286,12 @@ guOrtho(proj, -20, 240, 0, 352, 0, 300);
GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC); } +void _guiFinish(void) { + Mtx44 proj; + guOrtho(proj, -10, VIDEO_VERTICAL_PIXELS + 10, 0, VIDEO_HORIZONTAL_PIXELS, 0, 300); + GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC); +} + void _setup(struct GBAGUIRunner* runner) { struct GBAOptions opts = { .useBios = true,@@ -326,10 +333,6 @@ }
sleep(1); } } - - Mtx44 proj; - guOrtho(proj, -10, VIDEO_VERTICAL_PIXELS + 10, 0, VIDEO_HORIZONTAL_PIXELS, 0, 300); - GX_LoadProjectionMtx(proj, GX_ORTHOGRAPHIC); } void _prepareForFrame(struct GBAGUIRunner* runner) {@@ -352,6 +355,7 @@ #endif
} void _drawFrame(struct GBAGUIRunner* runner, bool faded) { + UNUSED(runner); uint32_t color = 0xFFFFFF3F; if (!faded) { color |= 0xC0;@@ -371,7 +375,11 @@ DCFlushRange(texdest, 256 * 256 * BYTES_PER_PIXEL);
_drawStart(); - GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET); + if (faded) { + GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP); + } else { + GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_NOOP); + } GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_S16, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_InvalidateTexAll();