From 50ceea3f0a9862f3206a6cc4de85e27f4899d71a Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Fri, 7 Mar 2025 16:18:25 +0100 Subject: [PATCH] Adjust GUI to different resolutions --- TODO.txt | 3 +++ game.h | 38 ++++++++++++++++++++----------------- media/manual.txt | 49 ++++++++++++++++++++++++++++-------------------- renderer.h | 15 +++++++++++---- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/TODO.txt b/TODO.txt index 1374ac9..88b119a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,7 @@ =========== GENERAL ============== +- on tiny map 1 maybe add a few block below the first sharp ramp to prevent + those nasty piercing bugs - car deglitch idea: deglitch only if the middle joint collided this frame? - some kinda easteregg in menu or smt - make the U-ramp map taller due to new physics @@ -21,6 +23,7 @@ count - bonus maps in the external file (also 5?) - map types: + - purely falling map - traveling salesman kind of maze, with fans n shit - city map? - some kinda buggy bumpy downhill diff --git a/game.h b/game.h index b00e9e1..c72d5d1 100644 --- a/game.h +++ b/game.h @@ -264,6 +264,11 @@ static inline void LCR_gameDrawPixelXYSafe(unsigned int x, unsigned int y, #define LCR_POPUP_STR_SIZE 16 + +#define LCR_GUI_GAP \ + ((LCR_EFFECTIVE_RESOLUTION_X + LCR_EFFECTIVE_RESOLUTION_Y) / 128) + + struct { uint8_t state; @@ -1056,22 +1061,20 @@ void LCR_gameTimeToStr(uint32_t timeMS, char *str) void LCR_gameDrawPopupMessage(void) { -#define TEXT_SIZE 5 -#define OFFSET_V (LCR_EFFECTIVE_RESOLUTION_Y / 6) -#define TEXT_PAD (LCR_EFFECTIVE_RESOLUTION_Y / 64) +#define _TEXT_SIZE 5 +#define _OFFSET_V (LCR_EFFECTIVE_RESOLUTION_Y / 6) - int textH = LCR_rendererComputeTextHeight(TEXT_SIZE); - int textW = LCR_rendererComputeTextWidth(LCR_game.popupStr,TEXT_SIZE); + int textH = LCR_rendererComputeTextHeight(_TEXT_SIZE); + int textW = LCR_rendererComputeTextWidth(LCR_game.popupStr,_TEXT_SIZE); - LCR_rendererDrawRect((LCR_EFFECTIVE_RESOLUTION_X - textW - 2 * TEXT_PAD) / 2, - OFFSET_V,textW + 2 * TEXT_PAD,textH + 2 * TEXT_PAD,0xffff,1); + LCR_rendererDrawRect((LCR_EFFECTIVE_RESOLUTION_X - textW - 2 * LCR_GUI_GAP) + / 2,_OFFSET_V,textW + 2 * LCR_GUI_GAP,textH + 2 * LCR_GUI_GAP,0xffff,1); LCR_rendererDrawText(LCR_game.popupStr,(LCR_EFFECTIVE_RESOLUTION_X - textW) - / 2,OFFSET_V + TEXT_PAD,0x0300,TEXT_SIZE); + / 2,_OFFSET_V + LCR_GUI_GAP,0x0300,_TEXT_SIZE); -#undef TEXT_PAD -#undef OFFSET_V -#undef TEXT_SIZE +#undef _OFFSET_V +#undef _TEXT_SIZE } void LCR_gameDraw3DView(void) @@ -1134,14 +1137,15 @@ void LCR_gameDraw3DView(void) str[3] = 0; LCR_rendererDrawText(str,LCR_EFFECTIVE_RESOLUTION_X - - LCR_rendererComputeTextWidth(str,2) - 20, - LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - 20,0,2); + LCR_rendererComputeTextWidth(str,2) - LCR_GUI_GAP, + LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - + LCR_GUI_GAP,0,2); LCR_gameTimeToStr(LCR_timeTicksToMS(LCR_game.runTime),str); if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) - LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - - LCR_rendererComputeTextHeight(2) - 45,0,2); + LCR_rendererDrawText(str,LCR_GUI_GAP,LCR_EFFECTIVE_RESOLUTION_Y - + LCR_rendererComputeTextHeight(2) - 3 * LCR_GUI_GAP,0,2); else LCR_rendererDrawText(str,((LCR_EFFECTIVE_RESOLUTION_X - LCR_rendererComputeTextWidth(str,4)) / 2), @@ -1151,8 +1155,8 @@ void LCR_gameDraw3DView(void) LCR_gameTimeToStr(LCR_currentMap.targetTime * LCR_RACING_TICK_MS,str); - LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - - LCR_rendererComputeTextHeight(2) - 20,0x4208,2); + LCR_rendererDrawText(str,LCR_GUI_GAP,LCR_EFFECTIVE_RESOLUTION_Y - + LCR_rendererComputeTextHeight(2) - LCR_GUI_GAP,0x4208,2); break; } diff --git a/media/manual.txt b/media/manual.txt index 47de801..f12e29a 100644 --- a/media/manual.txt +++ b/media/manual.txt @@ -7,13 +7,14 @@ by drummyfish, released under CC0 1.0, public domain ~~~ GENERAL ~~~ Licar is a relatively simple 3D stunt racing game inspired by other popular -games of this genre. Unlike most games in existence, Licar is completely free -as in freedom (meaning its source code is available for any use), gratis, and -its focus lies on being well programmed by employing minimalism and rejecting -harmful "modern" programming practice. The game aims to seflessly bring -happiness to all people, even those who have no money, own only very old and -weak computers etc. It is not a commercial product and has been made purely out -of love by a single man. +games of this genre. Unlike most games in existence, Licar is completely libre, +free as in freedom (meaning its source code is available for any use whatsoever), +gratis (free of cost), and its focus lies on being well programmed by employing +minimalism and rejecting harmful "modern" programming practice. The game aims to +seflessly bring happiness to all people who might enjoy it, even those who have +no money, own only very old and weak computers etc. It is not a commercial +product and has been made purely out of love by a single man. It is also more +than a game, for example it can be used for educational purposes. The game runs on many platforms and comes in different versions depending on what the platforms allow. Some versions may have more features or visual @@ -71,7 +72,7 @@ speed, times at checkpoints etc. Controls are extremely simple. The car is only controlled by 4 directional keys: up (accelerate), down (deccelerate, reverse), left (steer left) and right (steer right). There are two additional keys, A and B (depending on your -platform these may be e.g. the K and L letter or RETURN and SPACE keys), for +platform these may be e.g. the K and L letter or RETURN and ESCAPE keys), for restarting runs and handling menu. PRO TIP: pressing brake while in air stops the car's horizontal rotation! @@ -96,15 +97,16 @@ replay data. For example a map named "mymap" will start with "Mmymap;". ~~~ CONFIGURATION ~~~ -The game offers a very high level of configuration and customization. Very basic -settings (such as turning the music off or switching between windowed and -fullscreen mode) are accessible either in the game menu, or as a commandline -flag (run the game with -h flag to see the options). All other settings, -however, are kept at the source code level and so changing them requires -recompiling the whole game from source code (which is nonetheless very simple). -All user settings, along with their descriptions, are located in the settings.h -source file. The game also comes in several precompiled versions with different -settings. +The game offers a very high level of configuration and customization, and those +with at least basic programming skill will be able to implement any changes +imaginable. Very basic settings (such as turning the music off or switching +between windowed and fullscreen mode) are accessible either in the game menu, +or as a commandline flag (run the game with -h flag to see the options). All +other settings, however, are kept at the source code level and so changing them +requires recompiling the whole game from source code (which is nonetheless very +simple). All user settings, along with their descriptions, are located in the +settings.h source file. The game also comes in several precompiled versions with +different settings. ~~~ REPLAYS ~~~ @@ -141,7 +143,7 @@ and/or flipped. Additionally each block also has a material (concrete, grass, ...). The finish, checkpoints and car start position can also be seen as block. The format of the map data string is described in the map.h file, refer to it -for details. In short: TODO +for details. In short: TODO (also small example) Under the asset directory there is a helper file for Blender (a FOSS 3D editor) with which a map layout can be comfortably created. But Blender is not required @@ -150,12 +152,12 @@ or -- for simpler maps -- it may be possible to just imagine them in one's head. The "workflow" for making maps is roughly the following: -1. Drawing the map (in Blender, on paper, ...). +1. Drawing the map (in Blender, on paper, with Lego, ...). 2. Rewriting this to the map text format in the data file. The edited map should be the very last item in the data file so that it can be quickly loaded with the -M command line argument. 3. Testing the map in game. This is easily done by running the game with -M - argument (and possibly also other arguments, e.g. to start with free camera) + argument (and possibly also other ones, e.g. -c3 to start with free camera) to instantly load the edited map. If something needs changing, we return to 1. or 2. @@ -170,3 +172,10 @@ most difficult tasks to create a flawless physics engine. We apologize for any frustration but unless you want to fix this yourself, you'll have to just accept it, the game is meant to be a simple entertainment. In other words this is a feature :) + +Q: I have some other question. + +A: My email is currently drummyfish@disroot.org, feel free to ask me anything, +but please remember I am not very social and don't enjoy too much engaging in +smalltalk or lengthy discussions about worldviews etcetc. + diff --git a/renderer.h b/renderer.h index 6293653..36383b2 100644 --- a/renderer.h +++ b/renderer.h @@ -1871,20 +1871,27 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items, s2++; } +#define _MENU_ITEM_HEIGHT (LCR_EFFECTIVE_RESOLUTION_Y / 20) +#define _FONT_SIZE (2 + LCR_EFFECTIVE_RESOLUTION_Y / 512) + if (j == selectedItem + 1) - for (int y = i - 10; y < i + LCR_rendererComputeTextHeight(3) + 10; ++y) + for (int y = i - 7; y < i + LCR_rendererComputeTextHeight(_FONT_SIZE) + 7; + ++y) for (int x = LCR_EFFECTIVE_RESOLUTION_X / 4; x < LCR_EFFECTIVE_RESOLUTION_X - LCR_EFFECTIVE_RESOLUTION_X / 4; ++x) LCR_gameDrawPixelXYSafe(x,y,0x5c1b + 4 * ((x & 0x10) == (y & 0x10))); LCR_rendererDrawText(s,(LCR_EFFECTIVE_RESOLUTION_X - - LCR_rendererComputeTextWidth(s,3)) / 2,i, - (j == 0 || j == selectedItem + 1) ? 0xf79c : textColor,3); + LCR_rendererComputeTextWidth(s,_FONT_SIZE)) / 2,i, + (j == 0 || j == selectedItem + 1) ? 0xf79c : textColor,_FONT_SIZE); if (j == 0) i = stripHeight + stripHeight2; - i += LCR_rendererComputeTextHeight(5); + i += _MENU_ITEM_HEIGHT; + +#undef _FONT_SIZE +#undef _MENU_ITEM_HEIGHT } #if !LCR_SETTING_POTATO_GRAPHICS