From ad7ca97ae1d6c0c23116f3960240e0501f9ce29a Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 1 Jul 2022 17:17:18 +0100 Subject: [PATCH] Fix black background palette (#4831) Diablo and Hellfire have different palettes in `ui_art\black.pcx`. We now ship our own tiny `black.pcx` that takes priority over the other ones. This `black.pcx` had the Diablo palette which resulted in an incorrect palette in the Settings screen. Split our own `black.pcx` file into `black_diablo.pcx` and `black_hellfire.pcx` and load the correct one depending on the mode. --- CMake/Assets.cmake | 3 +- .../ui_art/{black.pcx => black_diablo.pcx} | Bin .../assets/ui_art/black_hellfire.pcx | Bin 0 -> 899 bytes Source/DiabloUI/diabloui.cpp | 27 +++++++++++++----- Source/DiabloUI/diabloui.h | 1 + Source/DiabloUI/dialogs.cpp | 4 +-- Source/DiabloUI/progress.cpp | 2 +- Source/DiabloUI/selok.cpp | 2 +- Source/DiabloUI/selyesno.cpp | 2 +- Source/DiabloUI/settingsmenu.cpp | 2 +- 10 files changed, 28 insertions(+), 15 deletions(-) rename Packaging/resources/assets/ui_art/{black.pcx => black_diablo.pcx} (100%) create mode 100644 Packaging/resources/assets/ui_art/black_hellfire.pcx diff --git a/CMake/Assets.cmake b/CMake/Assets.cmake index 0ad621bab..7226b12c1 100644 --- a/CMake/Assets.cmake +++ b/CMake/Assets.cmake @@ -159,7 +159,8 @@ set(devilutionx_assets gendata/cutstartw.pcx Levels/L1Data/SklKngT.dun Levels/L2Data/BonechaT.dun - ui_art/black.pcx + ui_art/black_diablo.pcx + ui_art/black_hellfire.pcx ui_art/creditsw.pcx ui_art/dvl_but_sml.pcx ui_art/dvl_lrpopup.pcx diff --git a/Packaging/resources/assets/ui_art/black.pcx b/Packaging/resources/assets/ui_art/black_diablo.pcx similarity index 100% rename from Packaging/resources/assets/ui_art/black.pcx rename to Packaging/resources/assets/ui_art/black_diablo.pcx diff --git a/Packaging/resources/assets/ui_art/black_hellfire.pcx b/Packaging/resources/assets/ui_art/black_hellfire.pcx new file mode 100644 index 0000000000000000000000000000000000000000..d1cb7cf7c21f7c3a80825085313666375a7be560 GIT binary patch literal 899 zcmb7@Ur19?9LImttsU*CcX`!2y{@ZX^Gb8g9JP_A!#!*?YK6A>C(@LmGEk8qDQ!q9 zr6Qq;R=9y0O1-2H8l)2pt+A+{?7_t9A&IDgzFE7St%4rwcRuI)`~H4E&Urc~RwhC4 zJKRxQl0W{Rvm^@s|IpvJV^a7c+ZRbbQu%z#BsP{G_=5wcM6W4fsWfh`JY}_se}5-W z5gRRF$#DP+hFSolO74o4)Tc|j_C?)DmNse8Xo{>$Bb!M>H&4oahcJ>#F+vnZG=&%% za||VLv=m8Ecp^naP&hD_VoVfc3R4uKC`=P*M9~yY6GJf!IZn|GF$9`rD3(PmLo+PR zvc%IIOK}|L!iM2EhUaKLtSrwnJWrGpcvc`P5O}q~sfnryf|j5qsC8OFM^s19>Ir&+ zu8>ej(3cQO2!$q7iP>zjTFo|_xvb3QaFkV7J8EjG>+5S=t_F`swA)3V4@o5702Tpm z0oVbQVq_5F`Cz1b8=w*(3qbtg5x?6*dwlQDJb%%F6o|OP|r$ZZI_D=bz8bHDzQJD3xjP@mMZ@ z{_^we{JLjqb!hBK@4%z>>t1Ken4@msw4)2@ei>qh%7^mdkAX|^=h6jzXGKMY)oLv&D$-~)DwRs1P=sGLLI=VcUcdg9xEJ(#C*5whNctj(kwh|aBz^*( C#O=iZ literal 0 HcmV?d00001 diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 72c9602f2..e296a6e2f 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -673,8 +673,22 @@ Sint16 GetCenterOffset(Sint16 w, Sint16 bw) return (bw - w) / 2; } +bool UiLoadBlackBackground() +{ + LoadBackgroundArt(gbIsHellfire ? "ui_art\\black_hellfire.pcx" : "ui_art\\black_diablo.pcx"); + + if (!ArtBackground) + return false; + + // We only needed the black background for the palette, can now deallocate it. + ArtBackground = std::nullopt; + + return true; +} + void LoadBackgroundArt(const char *pszFile, int frames) { + ArtBackground = std::nullopt; SDL_Color pPal[256]; ArtBackground = LoadPcxSpriteSheetAsset(pszFile, static_cast(frames), /*transparentColor=*/std::nullopt, pPal); if (!ArtBackground) @@ -700,14 +714,13 @@ void LoadBackgroundArt(const char *pszFile, int frames) void UiAddBackground(std::vector> *vecDialog) { - int uiPositionY = GetUIRectangle().position.y; + const SDL_Rect rect = MakeSdlRect(0, GetUIRectangle().position.y, 0, 0); if (ArtBackgroundWidescreen) { - SDL_Rect rectw = MakeSdlRect(0, uiPositionY, 0, 0); - vecDialog->push_back(std::make_unique(PcxSprite { *ArtBackgroundWidescreen }, rectw, UiFlags::AlignCenter)); + vecDialog->push_back(std::make_unique(PcxSprite { *ArtBackgroundWidescreen }, rect, UiFlags::AlignCenter)); + } + if (ArtBackground) { + vecDialog->push_back(std::make_unique(PcxSpriteSheet { *ArtBackground }.sprite(0), rect, UiFlags::AlignCenter)); } - - SDL_Rect rect = MakeSdlRect(0, uiPositionY, 0, 0); - vecDialog->push_back(std::make_unique(PcxSpriteSheet { *ArtBackground }.sprite(0), rect, UiFlags::AlignCenter)); } void UiAddLogo(std::vector> *vecDialog) @@ -769,7 +782,7 @@ void DrawSelector(const SDL_Rect &rect) void UiClearScreen() { - if (gnScreenWidth > 640) // Background size + if (!ArtBackground || gnScreenWidth > PcxSpriteSheet { *ArtBackground }.width() || gnScreenHeight > PcxSpriteSheet { *ArtBackground }.frameHeight()) SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000); } diff --git a/Source/DiabloUI/diabloui.h b/Source/DiabloUI/diabloui.h index 05042db48..5bb9c94dd 100644 --- a/Source/DiabloUI/diabloui.h +++ b/Source/DiabloUI/diabloui.h @@ -96,6 +96,7 @@ bool UiItemMouseEvents(SDL_Event *event, const std::vector> *vecDialog); void UiAddLogo(std::vector> *vecDialog); diff --git a/Source/DiabloUI/dialogs.cpp b/Source/DiabloUI/dialogs.cpp index a3703727c..fec3003ee 100644 --- a/Source/DiabloUI/dialogs.cpp +++ b/Source/DiabloUI/dialogs.cpp @@ -55,9 +55,7 @@ std::optional LoadDialogSprite(bool hasCaption, bool isError) bool Init(string_view caption, string_view text, bool error, bool renderBehind) { if (!renderBehind) { - ArtBackground = std::nullopt; - LoadBackgroundArt("ui_art\\black.pcx"); - if (!ArtBackground) { + if (!UiLoadBlackBackground()) { if (SDL_ShowCursor(SDL_ENABLE) <= -1) LogError("{}", SDL_GetError()); } diff --git a/Source/DiabloUI/progress.cpp b/Source/DiabloUI/progress.cpp index c41c81bfe..52b7a8064 100644 --- a/Source/DiabloUI/progress.cpp +++ b/Source/DiabloUI/progress.cpp @@ -30,7 +30,7 @@ void DialogActionCancel() void ProgressLoadBackground() { - LoadBackgroundArt("ui_art\\black.pcx"); + UiLoadBlackBackground(); ArtPopupSm = LoadPcxAsset("ui_art\\spopup.pcx"); ArtProgBG = LoadPcxAsset("ui_art\\prog_bg.pcx"); } diff --git a/Source/DiabloUI/selok.cpp b/Source/DiabloUI/selok.cpp index cf3becc1c..4d81b681d 100644 --- a/Source/DiabloUI/selok.cpp +++ b/Source/DiabloUI/selok.cpp @@ -43,7 +43,7 @@ void selok_Esc() void UiSelOkDialog(const char *title, const char *body, bool background) { if (!background) { - LoadBackgroundArt("ui_art\\black.pcx"); + UiLoadBlackBackground(); } else { if (!gbIsSpawn) { LoadBackgroundArt("ui_art\\mainmenu.pcx"); diff --git a/Source/DiabloUI/selyesno.cpp b/Source/DiabloUI/selyesno.cpp index 0b33c7562..7ff62982b 100644 --- a/Source/DiabloUI/selyesno.cpp +++ b/Source/DiabloUI/selyesno.cpp @@ -42,7 +42,7 @@ void SelyesnoEsc() bool UiSelHeroYesNoDialog(const char *title, const char *body) { - LoadBackgroundArt("ui_art\\black.pcx"); + UiLoadBlackBackground(); UiAddBackground(&vecSelYesNoDialog); UiAddLogo(&vecSelYesNoDialog); diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 0f17f3b99..3164d33ce 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -247,7 +247,7 @@ void UiSettingsMenu() do { endMenu = false; - LoadBackgroundArt("ui_art\\black.pcx"); + UiLoadBlackBackground(); LoadScrollBar(); UiAddBackground(&vecDialog); UiAddLogo(&vecDialog);