From 081d847ab67afcf2def54c77c8601af6b215b5b8 Mon Sep 17 00:00:00 2001 From: Poul Sander Date: Sat, 29 Jul 2023 21:59:17 +0200 Subject: [PATCH] Alt background. Tile support --- Game/data/sprites/sample_alt_gfx.sprite | 9 ++++++ Game/data/textures/alt_gfx/background.png | Bin 0 -> 6384 bytes source/code/main.cpp | 24 ++++++++++++---- source/code/themes.cpp | 33 ++++++++++++++++++++++ source/code/themes.hpp | 20 +++++++++++++ 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100755 Game/data/textures/alt_gfx/background.png diff --git a/Game/data/sprites/sample_alt_gfx.sprite b/Game/data/sprites/sample_alt_gfx.sprite index 23eb1add..4d9aaef3 100644 --- a/Game/data/sprites/sample_alt_gfx.sprite +++ b/Game/data/sprites/sample_alt_gfx.sprite @@ -10,5 +10,14 @@ "number_of_frames" : 1, "frame_time" : 1 } +,"background_sample" : { + "texture" : "alt_gfx/background", + "topx" : 0, + "topy" : 0, + "height" : 150, + "width" : 150, + "number_of_frames" : 1, + "frame_time" : 1 +} } diff --git a/Game/data/textures/alt_gfx/background.png b/Game/data/textures/alt_gfx/background.png new file mode 100755 index 0000000000000000000000000000000000000000..4040de3c945582a277598a9f3fdd1394ff3852f1 GIT binary patch literal 6384 zcmVaZn99oz?3+DSw~RCwCGTnR(tNUyZp?b}Jn0XYUHK!&+scfWoA|HnP4B(?1%P7E_UhRJZ4 zxLmDPOC`0V=vR&yFLCUgi|Ol_ULAiQIr&xZJo%q~8z+h9BllTGFR913Ns{~$mfqE3 z`fzle1h5zvqvW3wG&`+}iqCe0BPCF|2P%R@pj;e(5XLbczH+Q=B~HFnTrptwxr+D? za5ne>C`OfltB<3K^&z_4s)#qAxp2dv7;%)<2t| zD~GGfMcFDag1CJ)Tlfk?i(lfZ@<%w^dFQ=)2w}^Ow)fbG(peR|7G~Tc!ew!RG|MvK z1y=zAnF?Odbn-31V5>^$H3iFVymJT$a3gW#j5Wa|a1;_5E`4M<;bOj&9$`u-aUQ4g z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Zzl!~>fE|;eUK57nsb)PATQtjqLI3(_PU6|U;KD!R4UAgAY=iw_;<=`Ugmz>e<7 zzOdc(VKWxDF2P5ECc~7(ovEGKdYUi@8an zUZoTw>%3B^TFP);S~ll=ya*_jK*Y9fF^wA`ut!y&q;QsvoR9KkB@$^e;SDuBt5_=19&FvTUSg+La#kbyHChI4#d0q!AW`PqDva!F)dUPB zp-Y=beitlD$HVI9GlC^56@nR7*AV=1Hd0{U^Y3Eh0;o1+(pmx+R|nyH^q!uskxcQ8r66E*72^ zi+NN2=cvpDC+0a}P0UYJRwg*&nHE)1)i;aV^>Wr^>91e-Dpe-!xUjVr8bAbpppSAv zW9`kHb@KU{-5mb`D9yL+X+78p!^0Mpc-jXWK4slp2wmOYt(ViA>`&O0K3^))hZX5F zUzn`|PgQ}a!&T7vV!2q5x&HxcR}n(t*t3n`sfwt|ATmJ$qx_klMbP|#0gR%^R4~oH zrPQohXjDMNoS-OMsDJ+>sH{G$V;2;6^pZsKh!6r*6w<)_@wnvOWOZ`RAXtb)kI=r& z(q7i;PJaSbgkC8W1HG4ra%pjp3;dBt4B3Z!@IH=8RPFFwDFcR_D-!SU!4|xC;W!}+ z6s0;L*f)M_oglI{hv zP%6;}p4z(eD-S(AA*-!!1~v8+d*@5dZwhq|orU^iD$gZkeY#Fc2>tKO!RPuUU5RWy y@^sN*P@&Uqa2Ss*3pFX!u~Ix;RO7(zY5xy>!btfbjAsl00000 1.5) { - backgroundSixteenNineImage.DrawScaled(target, SDL_GetTicks(), 0, 0, globalData.xsize, globalData.ysize); + sago::SagoSprite background = globalData.spriteHolder->GetSprite(globalData.theme.background.background_sprite); + if ( (double)globalData.xsize/globalData.ysize > 1.5 && globalData.theme.background.background_sprite_16x9.length()) { + background = globalData.spriteHolder->GetSprite(globalData.theme.background.background_sprite_16x9); } - else { - backgroundImage.DrawScaled(target, SDL_GetTicks(), 0, 0, globalData.xsize, globalData.ysize); + if (globalData.theme.background.background_scale == ImgScale::Tile) { + int nextX = 0; + while (nextX < globalData.xsize) { + int nextY = 0; + while (nextY < globalData.ysize) { + background.Draw(target, SDL_GetTicks(), nextX, nextY); + nextY += background.GetHeight(); + } + nextX += background.GetWidth(); + } + return; } + background.DrawScaled(target, SDL_GetTicks(), 0, 0, globalData.xsize, globalData.ysize); } /** @@ -1182,6 +1193,7 @@ int main(int argc, char* argv[]) { std::cout << "Renderer: " << info.name << "\n"; } globalData.screen = renderer; + globalData.theme = getTheme(0); ResetFullscreen(); SetSDLIcon(sdlWindow); diff --git a/source/code/themes.cpp b/source/code/themes.cpp index 999da721..0b50be89 100644 --- a/source/code/themes.cpp +++ b/source/code/themes.cpp @@ -25,19 +25,47 @@ Source information and contacts persons can be found at #include "themes.hpp" #include +#include static std::vector themes(1); +static std::unordered_map background_data; static bool initialized = false; static size_t current_theme = 0; +static void InitBackGroundData() { + BackGroundData standard; + standard.background_name = "standard"; + standard.background_sprite = "background"; + standard.background_sprite_16x9 = "background_sixteen_nine"; + standard.background_scale = ImgScale::Stretch; + background_data["standard"] = standard; + BackGroundData alt_background; + alt_background.background_name = "alt_background"; + alt_background.background_sprite = "background_sample"; + alt_background.background_sprite_16x9 = ""; + alt_background.background_scale = ImgScale::Tile; + background_data["alt_background"] = alt_background; +} + +static void FillMissingFields(Theme &theme) { + if (theme.background.background_name.empty()) { + //If the theme does not define a background then use the standard. + theme.background = background_data["standard"]; + } +} + void InitThemes() { if (initialized) { return; } + InitBackGroundData(); themes.resize(1); //Add the default theme + FillMissingFields(themes[0]); Theme snow; snow.theme_name = "snow"; snow.back_board = "back_board_sample_snow"; + snow.background = background_data["alt_background"]; + FillMissingFields(snow); themes.push_back(snow); } @@ -47,3 +75,8 @@ Theme getNextTheme() { current_theme = current_theme % themes.size(); return themes.at(current_theme); } + +Theme getTheme(size_t theme_number) { + InitThemes(); + return themes.at(theme_number % themes.size()); +} diff --git a/source/code/themes.hpp b/source/code/themes.hpp index 7a5db3ca..34fe3003 100644 --- a/source/code/themes.hpp +++ b/source/code/themes.hpp @@ -25,9 +25,22 @@ Source information and contacts persons can be found at #include +enum class ImgScale { Stretch, + Tile, + Resize, + Cut }; + +struct BackGroundData { + std::string background_name = ""; + std::string background_sprite = ""; + std::string background_sprite_16x9 = ""; + ImgScale background_scale = ImgScale::Stretch; +}; + struct Theme { std::string theme_name = "standard"; std::string back_board = "back_board"; // Can also be "back_board_sample_snow" or "trans_cover" + BackGroundData background; }; /** @@ -35,3 +48,10 @@ struct Theme { * @return A copy of a theme */ Theme getNextTheme(); + +/** + * @brief getTheme returns a specific theme + * @param theme_number + * @return + */ +Theme getTheme(size_t theme_number);