mirror of https://github.com/mgba-emu/mgba.git
GBA Context: Add pause menu
This commit is contained in:
parent
178612a471
commit
3157a3d949
|
@ -7,6 +7,12 @@
|
|||
|
||||
#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 @@ void GBAGUIDeinit(struct GBAGUIRunner* runner) {
|
|||
}
|
||||
|
||||
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,11 +47,9 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
|||
if (runner->params.guiFinish) {
|
||||
runner->params.guiFinish();
|
||||
}
|
||||
GUIMenuItemListDeinit(&pauseMenu.items);
|
||||
return;
|
||||
}
|
||||
if (runner->params.guiFinish) {
|
||||
runner->params.guiFinish();
|
||||
}
|
||||
|
||||
// TODO: Message box API
|
||||
runner->params.drawStart();
|
||||
|
@ -55,22 +67,59 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
|||
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 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
|||
}
|
||||
GBAContextUnloadROM(&runner->context);
|
||||
}
|
||||
GUIMenuItemListDeinit(&pauseMenu.items);
|
||||
}
|
||||
|
|
|
@ -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 @@ int main() {
|
|||
352, 230,
|
||||
font, "/",
|
||||
_drawStart, _drawEnd, _pollInput,
|
||||
_guiPrepare, 0,
|
||||
_guiPrepare, _guiFinish,
|
||||
|
||||
GUI_PARAMS_TRAIL
|
||||
},
|
||||
|
@ -285,6 +286,12 @@ void _guiPrepare(void) {
|
|||
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 @@ void _gameLoaded(struct GBAGUIRunner* runner) {
|
|||
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 @@ void _prepareForFrame(struct GBAGUIRunner* runner) {
|
|||
}
|
||||
|
||||
void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
||||
UNUSED(runner);
|
||||
uint32_t color = 0xFFFFFF3F;
|
||||
if (!faded) {
|
||||
color |= 0xC0;
|
||||
|
@ -371,7 +375,11 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
|||
|
||||
_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();
|
||||
|
|
Loading…
Reference in New Issue