From b548783df2476098662b5585db15181a0f6cec98 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sat, 31 Dec 2022 02:12:57 +0100 Subject: [PATCH] preloader.cpp: make loading screen translatable This mainly adds loc::gettext calls and replaces SDL_snprintf by VFormat for the percentage. This commit is part of rewritten history of the localization branch. The original (unsquashed) commit history can be found here: https://github.com/Dav999-v/VVVVVV/tree/localization-orig --- desktop_version/src/preloader.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/preloader.cpp b/desktop_version/src/preloader.cpp index 099459d3..e52d071a 100644 --- a/desktop_version/src/preloader.cpp +++ b/desktop_version/src/preloader.cpp @@ -1,8 +1,11 @@ +#include "Constants.h" #include "Enums.h" #include "Game.h" #include "Graphics.h" +#include "Localization.h" #include "KeyPoll.h" #include "UtilityClass.h" +#include "VFormat.h" static int pre_fakepercent=0, pre_transition=30; static bool pre_startgame=false; @@ -51,6 +54,8 @@ void preloaderrenderfixed(void) void preloaderrender(void) { + bool print_percentage = false; + if(pre_transition>=30){ switch(pre_curcol) { case 0: @@ -97,11 +102,7 @@ void preloaderrender(void) FillRect(graphics.backBuffer, pre_frontrectx, pre_frontrecty, pre_frontrectw,pre_frontrecth, graphics.getRGB(0x3E,0x31,0xA2)); - if(pre_fakepercent==100){ - graphics.Print(282-(15*8), 204, "LOADING... " + help.String(int(pre_fakepercent))+"%", 124, 112, 218, false); - }else{ - graphics.Print(282-(14*8), 204, "LOADING... " + help.String(int(pre_fakepercent))+"%", 124, 112, 218, false); - } + print_percentage = true; //Render if (pre_startgame) { @@ -117,7 +118,20 @@ void preloaderrender(void) ClearSurface(graphics.backBuffer); FillRect(graphics.backBuffer, pre_frontrectx, pre_frontrecty, pre_frontrectw,pre_frontrecth, graphics.getRGB(0x3E,0x31,0xA2)); - graphics.Print(282-(15*8), 204, "LOADING... 100%", 124, 112, 218, false); + print_percentage = true; + } + + if (print_percentage) { + char buffer[SCREEN_WIDTH_CHARS + 1]; + vformat_buf( + buffer, sizeof(buffer), + loc::gettext("LOADING... {percent|digits=2|spaces}%"), + "percent:int", + pre_fakepercent + ); + + int percentage_len = graphics.len(buffer); + graphics.Print(282-percentage_len, 204, buffer, 124, 112, 218, false); } graphics.drawfade();