From e2eea6c3770e23b9d7d5329a1bfd73e310b4c676 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 2 Apr 2021 00:16:50 +0200 Subject: [PATCH] :sparkles: Load variable size heros.pcx and individual portraits closes #936 --- SourceX/DiabloUI/diabloui.cpp | 49 ++++++++++++++++++++++++++++++++++- SourceX/DiabloUI/selhero.cpp | 14 +++------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/SourceX/DiabloUI/diabloui.cpp b/SourceX/DiabloUI/diabloui.cpp index 371798538..c434632a6 100644 --- a/SourceX/DiabloUI/diabloui.cpp +++ b/SourceX/DiabloUI/diabloui.cpp @@ -428,6 +428,52 @@ bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect) return SDL_PointInRect(&point, &rect); } +void LoadHeros() +{ + LoadArt("ui_art\\heros.pcx", &ArtHero); + + const int portraitHeight = 76; + int portraitOrder[NUM_CLASSES + 1] = { 0, 1, 2, 2, 1, 0, 3 }; + if (ArtHero.h() >= portraitHeight * 6) { + portraitOrder[PC_MONK] = 3; + portraitOrder[PC_BARD] = 4; + portraitOrder[NUM_CLASSES] = 5; + } + if (ArtHero.h() >= portraitHeight * 7) { + portraitOrder[PC_BARBARIAN] = 6; + } + + SDL_Surface *heros = SDL_CreateRGBSurfaceWithFormat(0, ArtHero.w(), portraitHeight * (NUM_CLASSES + 1), 8, SDL_PIXELFORMAT_INDEX8); + + for (int i = 0; i <= NUM_CLASSES; i++) { + int offset = portraitOrder[i] * portraitHeight; + if (offset + portraitHeight > ArtHero.h()) { + offset = 0; + } + SDL_Rect src_rect = { 0, offset, ArtHero.w(), portraitHeight }; + SDL_Rect dst_rect = { 0, i * portraitHeight, ArtHero.w(), portraitHeight }; + SDL_BlitSurface(ArtHero.surface, &src_rect, heros, &dst_rect); + } + + Art ArtPortrait; + for (int i = 0; i <= NUM_CLASSES; i++) { + char portraitPath[18]; + sprintf(portraitPath, "ui_art\\hero%i.pcx", i); + LoadArt(portraitPath, &ArtPortrait); + if (ArtPortrait.surface == nullptr) + continue; + + SDL_Rect dst_rect = { 0, i * portraitHeight, ArtPortrait.w(), portraitHeight }; + SDL_BlitSurface(ArtPortrait.surface, nullptr, heros, &dst_rect); + ArtPortrait.Unload(); + } + + ArtHero.Unload(); + ArtHero.surface = heros; + ArtHero.frame_height = portraitHeight; + ArtHero.frames = NUM_CLASSES; +} + void LoadUiGFX() { if (gbIsHellfire) { @@ -439,7 +485,8 @@ void LoadUiGFX() LoadMaskedArt("ui_art\\focus.pcx", &ArtFocus[FOCUS_MED], 8); LoadMaskedArt("ui_art\\focus42.pcx", &ArtFocus[FOCUS_BIG], 8); LoadMaskedArt("ui_art\\cursor.pcx", &ArtCursor, 1, 0); - LoadArt("ui_art\\heros.pcx", &ArtHero, gbIsHellfire ? 6 : 4); + + LoadHeros(); } void UiInitialize() diff --git a/SourceX/DiabloUI/selhero.cpp b/SourceX/DiabloUI/selhero.cpp index 996e62943..71cb28e4b 100644 --- a/SourceX/DiabloUI/selhero.cpp +++ b/SourceX/DiabloUI/selhero.cpp @@ -96,11 +96,7 @@ void selhero_Free() void selhero_SetStats() { - int heroclass = selhero_heroInfo.heroclass; - if (heroclass == PC_BARBARIAN) { - heroclass = PC_WARRIOR; // The graphics is missing from heros.pcx - } - SELHERO_DIALOG_HERO_IMG->m_frame = heroclass; + SELHERO_DIALOG_HERO_IMG->m_frame = selhero_heroInfo.heroclass; snprintf(textStats[0], sizeof(textStats[0]), "%d", selhero_heroInfo.level); snprintf(textStats[1], sizeof(textStats[1]), "%d", selhero_heroInfo.strength); snprintf(textStats[2], sizeof(textStats[2]), "%d", selhero_heroInfo.magic); @@ -154,11 +150,7 @@ void selhero_Init() vecSelHeroDialog.push_back(new UiArtText(title, rect1, UIS_CENTER | UIS_BIG)); SDL_Rect rect2 = { (Sint16)(PANEL_LEFT + 30), (Sint16)(UI_OFFSET_Y + 211), 180, 76 }; - if (hellfire_mpq) { - SELHERO_DIALOG_HERO_IMG = new UiImage(&ArtHero, 5, rect2); - } else { - SELHERO_DIALOG_HERO_IMG = new UiImage(&ArtHero, 3, rect2); - } + SELHERO_DIALOG_HERO_IMG = new UiImage(&ArtHero, NUM_CLASSES, rect2); vecSelHeroDialog.push_back(SELHERO_DIALOG_HERO_IMG); SDL_Rect rect3 = { (Sint16)(PANEL_LEFT + 39), (Sint16)(UI_OFFSET_Y + 323), 110, 21 }; @@ -243,7 +235,7 @@ void selhero_List_Focus(int value) return; } - SELHERO_DIALOG_HERO_IMG->m_frame = hellfire_mpq ? 5 : 3; + SELHERO_DIALOG_HERO_IMG->m_frame = NUM_CLASSES; strncpy(textStats[0], "--", sizeof(textStats[0]) - 1); strncpy(textStats[1], "--", sizeof(textStats[1]) - 1); strncpy(textStats[2], "--", sizeof(textStats[2]) - 1);