Continue menu

This commit is contained in:
Miloslav Ciz 2025-01-04 20:49:46 +01:00
parent 6bf3a950dc
commit 1efeee9c36
2 changed files with 68 additions and 57 deletions

38
game.h
View file

@ -358,6 +358,11 @@ void LCR_seekResourceByIndex(unsigned int index, char magicNumber)
while (index)
{
c = LCR_gameGetNextResourceFileChar();
if (c == 0)
return;
if (c == magicNumber)
index--;
@ -372,10 +377,9 @@ void LCR_seekResourceByIndex(unsigned int index, char magicNumber)
c != LCR_RESOURCE_FILE_SEPARATOR && c != 0);
}
void LCR_gameStartRun(void)
void LCR_gameStartRun(unsigned int mapIndex)
{
LCR_seekResourceByIndex(0,'M'); // TODO
LCR_seekResourceByIndex(mapIndex,'M');
LCR_mapLoadFromStr(LCR_gameGetNextResourceStrChar);
LCR_rendererLoadMap();
LCR_gameResetRun();
@ -389,6 +393,7 @@ void LCR_gameInit(void)
LCR_game.keyStates[i] = 0;
LCR_rendererInit();
LCR_racingInit();
LCR_audioInit();
@ -397,11 +402,6 @@ void LCR_gameInit(void)
LCR_game.resourceFile.loadedItemCount = 0;
LCR_game.resourceFile.itemsTotal = 0;
for (int i = 0; i < LCR_RESOURCE_ITEM_CHUNK; ++i)
for (int j = 0; j < LCR_MENU_STRING_SIZE; ++j)
LCR_game.resourceFile.loadedItemNames[i * LCR_MENU_STRING_SIZE + j] = 0;
LCR_game.menuSelectedTab = 0;
LCR_game.menuSelectedItem = 0;
@ -410,7 +410,10 @@ LCR_game.menuSelectedItem = 0;
LCR_game.nextRenderFrameTime = 0;
LCR_game.nextRacingTickTime = 0;
LCR_game.controlMode = LCR_CONTROL_MODE_DRIVE;
LCR_gameStartRun();
LCR_gameSetState(LCR_GAME_STATE_MENU);
LCR_currentMap.blockCount = 0; // means no map loaded
}
/**
@ -421,8 +424,6 @@ void LCR_gameLoadResourceFileChunk(unsigned int startIndex, char magicNumber)
{
LCR_LOG1("loading resources");
char c;
unsigned char state = 0;
@ -438,6 +439,7 @@ LCR_gameRewindResourceFile();
/* 3 iterations: in first we seek to the start index, in second we load the
names, in third we just read the rest to get the total count. */
for (int i = 0; i < 3; ++i)
{
while (1)
{
if (i == 0 && !startIndex)
@ -465,7 +467,9 @@ for (int i = 0; i < 3; ++i)
}
else if (i == 1 && state != 255)
{
if (c == LCR_RESOURCE_FILE_SEPARATOR2 ||
if (
c == LCR_RESOURCE_FILE_SEPARATOR ||
c == LCR_RESOURCE_FILE_SEPARATOR2 ||
state >= 1 + LCR_MENU_STRING_SIZE - 1)
{
state = 255;
@ -474,7 +478,7 @@ for (int i = 0; i < 3; ++i)
if (LCR_game.resourceFile.loadedItemCount >= LCR_RESOURCE_ITEM_CHUNK)
break;
}
else
LCR_game.resourceFile.loadedItemNames[LCR_MENU_STRING_SIZE *
LCR_game.resourceFile.loadedItemCount + state - 1] = c;
@ -485,6 +489,7 @@ for (int i = 0; i < 3; ++i)
state = 0;
}
}
}
void LCR_gameEnd(void)
{
@ -630,7 +635,7 @@ void LCR_gameHandleInput(void)
scrolled = 1;
}
}
else if (LCR_game.keyStates[LCR_KEY_B] == 1)
else if (LCR_game.keyStates[LCR_KEY_B] == 1 && LCR_currentMap.blockCount)
{
LCR_LOG1("menu quit");
LCR_gameSetState(LCR_GAME_STATE_RUN);
@ -653,6 +658,11 @@ void LCR_gameHandleInput(void)
break;
case 1:
LCR_gameStartRun(
LCR_game.resourceFile.firstItemIndex + LCR_game.menuSelectedItem);
break;
default: break;
}
}

View file

@ -1010,6 +1010,7 @@ uint8_t LCR_rendererInit(void)
LCR_renderer.frame = 0;
LCR_renderer.carModel = LCR_renderer.models + 8;
LCR_renderer.ghostModel = LCR_renderer.models + 9;
S3L_model3DInit(
@ -1747,7 +1748,7 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount,
}
i = stripHeight +
(stripHeight2 - LCR_rendererComputeTextHeight(4)) / 2;
(stripHeight2 - LCR_rendererComputeTextHeight(3)) / 2;
for (int j = 0; j < itemCount; ++j)
{
@ -1755,7 +1756,7 @@ void LCR_rendererDrawMenu(const char **items, unsigned char itemCount,
for (int y = i - 10; y < i + LCR_rendererComputeTextHeight(3) + 10; ++y)
for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4;
x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x)
LCR_drawPixelXYSafe(x,y,0x5c1b);
LCR_drawPixelXYSafe(x,y,0x5c1b + 4 * ((x & 0x10) == (y & 0x10)));
LCR_rendererDrawText(items[j],(LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(items[j],3)) / 2,i,0xffff,3);