Add popups

This commit is contained in:
Miloslav Ciz 2025-02-21 16:09:14 +01:00
parent 6c38c2068f
commit f44204ce26
3 changed files with 80 additions and 41 deletions

View file

@ -1,7 +1,7 @@
=========== GENERAL ============== =========== GENERAL ==============
- add indication when CP is taken: in 1st man view it may be unclear if CP was - maybe remove setting string from menu (like music: 1) and use popups instead
taken or not otherwise (have just music and show "on" or "off" in popup)
- on 1st map the camera is obscured by the wall at the start, fix it somehow - on 1st map the camera is obscured by the wall at the start, fix it somehow
(not the best first impression) (not the best first impression)
- culling is very slow now, it showed that distance bailout can accelerate it - culling is very slow now, it showed that distance bailout can accelerate it
@ -38,8 +38,6 @@
- maybe each map could have a target time embedded: when beaten, the map would - maybe each map could have a target time embedded: when beaten, the map would
be marked as such be marked as such
- player name (modifiable via resource file) - player name (modifiable via resource file)
- popup messages? would be useful for several things: showing checkpoint times,
showing changes in menu etc.
- make the racing module usable by itself, e.g. to allow making tools for - make the racing module usable by itself, e.g. to allow making tools for
verifying replays etc., i.e. make the module measure time, count checkpoints verifying replays etc., i.e. make the module measure time, count checkpoints
etc. etc.
@ -56,6 +54,10 @@
=========== HANDLED ============== =========== HANDLED ==============
- add indication when CP is taken: in 1st man view it may be unclear if CP was
taken or not otherwise
- popup messages? would be useful for several things: showing checkpoint times,
showing changes in menu etc.
- allow stopping car rotation in air like in Trackmania - allow stopping car rotation in air like in Trackmania
- countdown and finish text sometimes seem to jump horizontally somehow - countdown and finish text sometimes seem to jump horizontally somehow
- add argc/argv to gameInit? could be used to quickly start maps, verify - add argc/argv to gameInit? could be used to quickly start maps, verify

92
game.h
View file

@ -259,6 +259,8 @@ static inline void LCR_gameDrawPixelXYSafe(unsigned int x, unsigned int y,
#define LCR_FREE_CAMERA_TURN_STEP 1 #define LCR_FREE_CAMERA_TURN_STEP 1
#endif #endif
#define LCR_POPUP_STR_SIZE 16
struct struct
{ {
uint8_t state; uint8_t state;
@ -275,6 +277,9 @@ struct
continuously held. */ continuously held. */
uint32_t runTimeMS; ///< Current time of the run uint32_t runTimeMS; ///< Current time of the run
char popupStr[LCR_POPUP_STR_SIZE];
uint8_t popupCountdown;
struct struct
{ {
uint8_t selectedTab; uint8_t selectedTab;
@ -340,6 +345,26 @@ void LCR_gameDrawPixel(unsigned long index, uint16_t color)
#endif #endif
} }
void LCR_gamePopupMessage(const char *str)
{
if (*str == 0)
{
LCR_game.popupCountdown = 0;
return;
}
for (uint8_t i = 0; i < LCR_POPUP_STR_SIZE - 1; ++i)
{
LCR_game.popupStr[i] = str[i];
if (str[i] == 0)
break;
}
LCR_game.popupCountdown =
(LCR_SETTING_POPUP_DURATION * LCR_SETTING_FPS) / 1000;
}
void LCR_gameDrawPixelXYUnsafe(unsigned int x, unsigned int y, void LCR_gameDrawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color) uint16_t color)
{ {
@ -886,6 +911,9 @@ void LCR_gameInit(int argc, const char **argv)
LCR_game.menu.selectedTab = 0; LCR_game.menu.selectedTab = 0;
LCR_game.menu.selectedItem = 0; LCR_game.menu.selectedItem = 0;
LCR_game.popupCountdown = 0;
LCR_game.popupStr[LCR_POPUP_STR_SIZE - 1] = 0;
LCR_game.frame = 0; LCR_game.frame = 0;
LCR_game.musicOn = LCR_SETTING_MUSIC; LCR_game.musicOn = LCR_SETTING_MUSIC;
LCR_game.nextRenderFrameTime = 0; LCR_game.nextRenderFrameTime = 0;
@ -1024,6 +1052,18 @@ void LCR_gameTimeToStr(uint32_t timeMS, char *str)
str[2] = '\''; str[2] = '\'';
} }
LCR_gameDrawPopupMessage(void)
{
int textH = LCR_rendererComputeTextHeight(4);
int textW = LCR_rendererComputeTextWidth(LCR_game.popupStr,4);
LCR_rendererDrawRect((LCR_EFFECTIVE_RESOLUTION_X - textW) / 2 - 6,4,
textW + 12,textH + 8,0xffff,1);
LCR_rendererDrawText(LCR_game.popupStr,(LCR_EFFECTIVE_RESOLUTION_X - textW)
/ 2,8,0x0700,4);
}
void LCR_gameDraw3DView(void) void LCR_gameDraw3DView(void)
{ {
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
@ -1071,17 +1111,6 @@ void LCR_gameDraw3DView(void)
switch (LCR_game.state) switch (LCR_game.state)
{ {
case LCR_GAME_STATE_RUN_STARTING:
str[0] = '0' + LCR_SETTING_COUNTDOWN_SECONDS -
(LCR_game.time - LCR_game.stateStartTime) / 1000;
str[1] = 0;
LCR_rendererDrawText(str,
(LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererComputeTextWidth(str,8)) / 2,
LCR_EFFECTIVE_RESOLUTION_Y / 2
,0x0707,8);
break;
default: default:
{ {
int val = LCR_carSpeedKMH(); int val = LCR_carSpeedKMH();
@ -1280,7 +1309,17 @@ void LCR_gameHandleInput(void)
case LCR_GAME_STATE_RUN_STARTING: case LCR_GAME_STATE_RUN_STARTING:
if (LCR_game.time - LCR_game.stateStartTime if (LCR_game.time - LCR_game.stateStartTime
>= 1000 * LCR_SETTING_COUNTDOWN_SECONDS) >= 1000 * LCR_SETTING_COUNTDOWN_SECONDS)
{
LCR_gameSetState(LCR_GAME_STATE_RUN); LCR_gameSetState(LCR_GAME_STATE_RUN);
LCR_gamePopupMessage("");
}
else
{
LCR_game.popupStr[0] = '0' + LCR_SETTING_COUNTDOWN_SECONDS -
(LCR_game.time - LCR_game.stateStartTime) / 1000;
LCR_game.popupStr[1] = 0;
LCR_gamePopupMessage(LCR_game.popupStr);
}
// fall through // fall through
default: default:
@ -1393,11 +1432,14 @@ uint8_t LCR_gameStep(uint32_t time)
if (events & LCR_RACING_EVENT_CP_TAKEN) if (events & LCR_RACING_EVENT_CP_TAKEN)
{ {
int carBlock[3]; int carBlock[3];
char str[10];
LCR_LOG1("CP taken"); LCR_LOG1("CP taken");
LCR_racingGetCarBlockCoords(carBlock); LCR_racingGetCarBlockCoords(carBlock);
LCR_rendererMarkTakenCP(carBlock[0],carBlock[1],carBlock[2]); LCR_rendererMarkTakenCP(carBlock[0],carBlock[1],carBlock[2]);
LCR_audioPlaySound(LCR_SOUND_CLICK); LCR_audioPlaySound(LCR_SOUND_CLICK);
LCR_gameTimeToStr(LCR_game.runTimeMS,str);
LCR_gamePopupMessage(str);
} }
else if (events & LCR_RACING_EVENT_FINISHED && else if (events & LCR_RACING_EVENT_FINISHED &&
LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
@ -1453,6 +1495,12 @@ LCR_replayOutputStr(_LCR_gameDataCharWrite);
LCR_game.menu.itemCount + 1,LCR_game.menu.selectedItem); LCR_game.menu.itemCount + 1,LCR_game.menu.selectedItem);
else else
LCR_gameDraw3DView(); LCR_gameDraw3DView();
if (LCR_game.popupCountdown)
{
LCR_gameDrawPopupMessage();
LCR_game.popupCountdown--;
}
} }
else else
{ {
@ -1464,25 +1512,9 @@ LCR_replayOutputStr(_LCR_gameDataCharWrite);
{ {
// show the "loading" screen // show the "loading" screen
LCR_rendererDrawRect( LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_LOADING]);
LCR_EFFECTIVE_RESOLUTION_X / 8 - 2, LCR_game.popupCountdown = 2;
LCR_EFFECTIVE_RESOLUTION_Y / 3 - 2, LCR_gameDrawPopupMessage();
LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4 + 4,
LCR_EFFECTIVE_RESOLUTION_Y - 2 * LCR_EFFECTIVE_RESOLUTION_Y / 3 + 4,
0x0000,0);
LCR_rendererDrawRect(
LCR_EFFECTIVE_RESOLUTION_X / 8,
LCR_EFFECTIVE_RESOLUTION_Y / 3,
LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4,
LCR_EFFECTIVE_RESOLUTION_Y - 2 * LCR_EFFECTIVE_RESOLUTION_Y / 3,
0xffff,0);
LCR_rendererDrawText(LCR_texts[LCR_TEXTS_LOADING],
(LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(LCR_texts[LCR_TEXTS_LOADING],4)) / 2,
(LCR_EFFECTIVE_RESOLUTION_Y -
LCR_rendererComputeTextHeight(4)) / 2,0x0000,4);
} }
if (sleep) if (sleep)

View file

@ -178,7 +178,7 @@
#ifndef LCR_SETTING_COUNTDOWN_SECONDS #ifndef LCR_SETTING_COUNTDOWN_SECONDS
/** Run start countdown length in seconds. */ /** Run start countdown length in seconds. */
#define LCR_SETTING_COUNTDOWN_SECONDS 1 // for release make 3 #define LCR_SETTING_COUNTDOWN_SECONDS 3 // for release make 3
#endif #endif
#ifndef LCR_SETTING_MAP_CHUNK_RELOAD_INTERVAL #ifndef LCR_SETTING_MAP_CHUNK_RELOAD_INTERVAL
@ -228,4 +228,9 @@
#define LCR_SETTING_CRASH_SOUNDS 1 #define LCR_SETTING_CRASH_SOUNDS 1
#endif #endif
#ifndef LCR_SETTING_POPUP_DURATION
/** Duration of popup messages in milliseconds. */
#define LCR_SETTING_POPUP_DURATION 2500
#endif
#endif // guard #endif // guard