Continue menu

This commit is contained in:
Miloslav Ciz 2025-01-02 20:17:15 +01:00
parent a30be11bf9
commit 9e0cb3c944
3 changed files with 92 additions and 17 deletions

View file

@ -16,6 +16,22 @@
#include <stdint.h> #include <stdint.h>
#include "map.h" #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 = static const char *LCR_internalResourceFile =
"testmap;" "testmap;"
"0 :*H1k0J" "0 :*H1k0J"
@ -61,10 +77,8 @@ static const char *LCR_internalResourceFile =
" map end " " map end "
"#map2;1 :*H1k0J :,s0s0 :fd190 " "#map2;1 :*H1k0J :,s0s0 :fd190 "
; ;
#define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image #define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image
#define LCR_IMAGE_STORE_SIZE (LCR_IMAGE_SIZE * LCR_IMAGE_SIZE + 256 * 2) #define LCR_IMAGE_STORE_SIZE (LCR_IMAGE_SIZE * LCR_IMAGE_SIZE + 256 * 2)

78
game.h
View file

@ -175,9 +175,14 @@ uint8_t LCR_gameGetNextAudioSample(void);
#define LCR_GAME_STATE_RUN_FINISHED 0x03 #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 #define LCR_MENU_STRING_SIZE 16
struct struct
{ {
uint8_t state; uint8_t state;
@ -194,6 +199,9 @@ struct
frames for which the key has been frames for which the key has been
continuously held. */ continuously held. */
uint8_t menuSelectedTab;
uint8_t menuSelectedItem;
struct struct
{ {
int state; ///< -1 if reading external res. f., else pos. 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.frame = 0;
LCR_game.musicVolume = 255; LCR_game.musicVolume = 255;
LCR_game.nextRenderFrameTime = 0; LCR_game.nextRenderFrameTime = 0;
@ -519,8 +530,37 @@ uint8_t LCR_gameStep(uint32_t time)
case LCR_GAME_STATE_MENU: case LCR_GAME_STATE_MENU:
paused = 1; 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); LCR_gameSetState(LCR_GAME_STATE_RUN);
}
break; break;
@ -550,6 +590,7 @@ uint8_t LCR_gameStep(uint32_t time)
else if (LCR_game.keyStates[LCR_KEY_B] == 30) else if (LCR_game.keyStates[LCR_KEY_B] == 30)
LCR_gameResetRun(); LCR_gameResetRun();
*/ */
LCR_GameUnit offsets[5]; LCR_GameUnit offsets[5];
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
@ -642,18 +683,29 @@ uint8_t LCR_gameStep(uint32_t time)
while (time >= LCR_game.nextRenderFrameTime) while (time >= LCR_game.nextRenderFrameTime)
LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS; 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[] = items[0] = LCR_texts[LCR_game.menuSelectedTab];
{
"menu","absa","sasas","sasqw" switch (LCR_game.menuSelectedTab)
}; {
case 0:
LCR_rendererDrawMenu(aaa,4,2); for (int i = 0; i < 5; ++i)
} items[1 + i] = LCR_texts[4 + i];
else
LCR_gameDraw3DView(); itemCount = 6;
break;
default: break;
}
LCR_rendererDrawMenu(items,itemCount,LCR_game.menuSelectedItem);
}
else
LCR_gameDraw3DView();
} }
else else
{ {

View file

@ -1718,12 +1718,18 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount,
++i; ++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 for (int y = 0; y < stripHeight2; ++y) // strip with arrows
{ {
int limit = y > stripHeight2 / 2 ? int limit = y > stripHeight2 / 2 ?
(stripHeight2 / 2 - y) : (y - stripHeight2 / 2); (stripHeight2 / 2 - y) : (y - stripHeight2 / 2);
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x) for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
{ {
LCR_drawPixel(i,(x > LCR_EFFECTIVE_RESOLUTION_X / 4 - limit && LCR_drawPixel(i,(x > LCR_EFFECTIVE_RESOLUTION_X / 4 - limit &&
@ -1732,6 +1738,7 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount,
i++; i++;
} }
} }
#endif
while (i < LCR_EFFECTIVE_RESOLUTION_Y * LCR_EFFECTIVE_RESOLUTION_X) 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) 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 y = i - 10; y < i + LCR_rendererComputeTextHeight(4) + 10; ++y)
for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4; for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4;
x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x) 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); i += LCR_rendererComputeTextHeight(7);
} }
#if !LCR_SETTING_POTATO_GRAPHICS
LCR_rendererBlitImage(21,(LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererBlitImage(21,(LCR_EFFECTIVE_RESOLUTION_X -
LCR_IMAGE_SIZE * (stripHeight / LCR_IMAGE_SIZE)) / 2,0, LCR_IMAGE_SIZE * (stripHeight / LCR_IMAGE_SIZE)) / 2,0,
stripHeight / LCR_IMAGE_SIZE,0xffff); stripHeight / LCR_IMAGE_SIZE,0xffff);
#endif
} }
void LCR_rendererCameraReset(void) void LCR_rendererCameraReset(void)