diff --git a/assets.h b/assets.h index 7884a92..d15e664 100644 --- a/assets.h +++ b/assets.h @@ -16,6 +16,22 @@ #include #include "map.h" +static const char *LCR_texts[] = +{ + // menu tabs: + "main menu", + "play map", + "view repl", + "play repl", + + // main menu items: + "camera", + "music", + "sound", + "save repl", + "exit" +}; + static const char *LCR_internalResourceFile = "testmap;" "0 :*H1k0J" @@ -61,10 +77,8 @@ static const char *LCR_internalResourceFile = " map end " "#map2;1 :*H1k0J :,s0s0 :fd190 " - ; - #define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image #define LCR_IMAGE_STORE_SIZE (LCR_IMAGE_SIZE * LCR_IMAGE_SIZE + 256 * 2) diff --git a/game.h b/game.h index c5d4a68..e973397 100644 --- a/game.h +++ b/game.h @@ -175,9 +175,14 @@ uint8_t LCR_gameGetNextAudioSample(void); #define LCR_GAME_STATE_RUN_FINISHED 0x03 -#define LCR_RESOURCE_ITEM_CHUNK 8 +// TODO: move to consts? +#define LCR_MENU_MAX_ITEMS 9 +#define LCR_RESOURCE_ITEM_CHUNK (LCR_MENU_MAX_ITEMS - 1) +#define LCR_MENU_TABS 4 #define LCR_MENU_STRING_SIZE 16 + + struct { uint8_t state; @@ -194,6 +199,9 @@ struct frames for which the key has been continuously held. */ + uint8_t menuSelectedTab; + uint8_t menuSelectedItem; + struct { int state; ///< -1 if reading external res. f., else pos. @@ -396,6 +404,9 @@ for (int i = 0; i < LCR_RESOURCE_ITEM_CHUNK; ++i) } +LCR_game.menuSelectedTab = 0; +LCR_game.menuSelectedItem = 0; + LCR_game.frame = 0; LCR_game.musicVolume = 255; LCR_game.nextRenderFrameTime = 0; @@ -519,8 +530,37 @@ uint8_t LCR_gameStep(uint32_t time) case LCR_GAME_STATE_MENU: paused = 1; - if (LCR_game.keyStates[LCR_KEY_B] == 1) + if (LCR_game.keyStates[LCR_KEY_RIGHT] == 1) + { + LCR_LOG1("menu tab right"); + LCR_game.menuSelectedTab = + (LCR_game.menuSelectedTab + 1) % LCR_MENU_TABS; + LCR_game.menuSelectedItem = 0; + } + else if (LCR_game.keyStates[LCR_KEY_LEFT] == 1) + { + LCR_LOG1("menu tab left"); + LCR_game.menuSelectedTab = + (LCR_game.menuSelectedTab + LCR_MENU_TABS - 1) % LCR_MENU_TABS; + LCR_game.menuSelectedItem = 0; + } + else if (LCR_game.keyStates[LCR_KEY_UP] == 1) + { + LCR_LOG1("menu item up"); + LCR_game.menuSelectedItem -= LCR_game.menuSelectedItem ? 1 : 0; + } + else if (LCR_game.keyStates[LCR_KEY_DOWN] == 1) + { + LCR_LOG1("menu item down"); + LCR_game.menuSelectedItem += + (LCR_game.menuSelectedItem < (LCR_game.menuSelectedTab ? + LCR_game.resourceFile.loadedItemCount : 5) - 1) ? 1 : 0; + } + else if (LCR_game.keyStates[LCR_KEY_B] == 1) + { + LCR_LOG1("menu quit"); LCR_gameSetState(LCR_GAME_STATE_RUN); + } break; @@ -550,6 +590,7 @@ uint8_t LCR_gameStep(uint32_t time) else if (LCR_game.keyStates[LCR_KEY_B] == 30) LCR_gameResetRun(); */ + LCR_GameUnit offsets[5]; for (int i = 0; i < 5; ++i) @@ -642,18 +683,29 @@ uint8_t LCR_gameStep(uint32_t time) while (time >= LCR_game.nextRenderFrameTime) LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS; -if (LCR_game.state == LCR_GAME_STATE_MENU) -{ + if (LCR_game.state == LCR_GAME_STATE_MENU) + { + const char *items[LCR_MENU_MAX_ITEMS]; + uint8_t itemCount = 1; -const char *aaa[] = -{ - "menu","absa","sasas","sasqw" -}; - -LCR_rendererDrawMenu(aaa,4,2); -} -else - LCR_gameDraw3DView(); + items[0] = LCR_texts[LCR_game.menuSelectedTab]; + + switch (LCR_game.menuSelectedTab) + { + case 0: + for (int i = 0; i < 5; ++i) + items[1 + i] = LCR_texts[4 + i]; + + itemCount = 6; + break; + + default: break; + } + + LCR_rendererDrawMenu(items,itemCount,LCR_game.menuSelectedItem); + } + else + LCR_gameDraw3DView(); } else { diff --git a/renderer.h b/renderer.h index 5ceedeb..522c340 100644 --- a/renderer.h +++ b/renderer.h @@ -1718,12 +1718,18 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount, ++i; } +#if LCR_SETTING_POTATO_GRAPHICS + while (i < stripHeight * LCR_EFFECTIVE_RESOLUTION_X) + { + LCR_drawPixel(i,0x73ae); + ++i; + } +#else for (int y = 0; y < stripHeight2; ++y) // strip with arrows { int limit = y > stripHeight2 / 2 ? (stripHeight2 / 2 - y) : (y - stripHeight2 / 2); - for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x) { LCR_drawPixel(i,(x > LCR_EFFECTIVE_RESOLUTION_X / 4 - limit && @@ -1732,6 +1738,7 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount, i++; } } +#endif while (i < LCR_EFFECTIVE_RESOLUTION_Y * LCR_EFFECTIVE_RESOLUTION_X) { @@ -1744,7 +1751,7 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount, for (int j = 0; j < itemCount; ++j) { - if (j == selectedItem) + if (j == selectedItem + 1) for (int y = i - 10; y < i + LCR_rendererComputeTextHeight(4) + 10; ++y) for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4; x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x) @@ -1759,9 +1766,11 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount, i += LCR_rendererComputeTextHeight(7); } +#if !LCR_SETTING_POTATO_GRAPHICS LCR_rendererBlitImage(21,(LCR_EFFECTIVE_RESOLUTION_X - LCR_IMAGE_SIZE * (stripHeight / LCR_IMAGE_SIZE)) / 2,0, stripHeight / LCR_IMAGE_SIZE,0xffff); +#endif } void LCR_rendererCameraReset(void)