From e1fd0d8d80a1e1d5c529d4aee78d11bcc186c9e7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 21 Aug 2020 22:40:09 +0200 Subject: [PATCH] - replaced most of the old text and graphics display functionality in Exhumed. --- source/exhumed/src/d_menu.cpp | 33 ++++++--------------- source/exhumed/src/exhumed.cpp | 54 ++++------------------------------ source/exhumed/src/exhumed.h | 4 --- source/exhumed/src/menu.cpp | 7 +++-- 4 files changed, 19 insertions(+), 79 deletions(-) diff --git a/source/exhumed/src/d_menu.cpp b/source/exhumed/src/d_menu.cpp index d12732d84..d79111d7d 100644 --- a/source/exhumed/src/d_menu.cpp +++ b/source/exhumed/src/d_menu.cpp @@ -36,6 +36,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS +void DrawRel(int tile, double x, double y, int shade = 0); + int handle1; @@ -53,14 +55,13 @@ int menu_Menu(int nVal) twod->ClearScreen(); - overwritesprite(160, 100, kSkullHead, 32, 3, kPalNormal); - overwritesprite(161, 130, kSkullJaw, 32, 3, kPalNormal); - - overwritesprite(160, 40, nLogoTile, 32, 3, kPalNormal); + DrawRel(kSkullHead, 160, 100, 32); + DrawRel(kSkullJaw, 161, 130, 32); + DrawRel(nLogoTile, 160, 40, 32); // draw the fire urn/lamp thingies - overwritesprite(50, 150, kTile3512 + dword_9AB5F, 32, 3, kPalNormal); - overwritesprite(270, 150, kTile3512 + ((dword_9AB5F + 2) & 3), 32, 3, kPalNormal); + DrawRel(kTile3512 + dword_9AB5F, 50, 150, 32); + DrawRel(kTile3512 + ((dword_9AB5F + 2) & 3), 270, 150, 32); HandleAsync(); D_ProcessEvents(); @@ -111,7 +112,7 @@ class PSMainMenu : public DListMenu else { auto nLogoTile = EXHUMED ? kExhumedLogo : kPowerslaveLogo; - overwritesprite(160, 40, nLogoTile, 32, 3, kPalNormal); + DrawRel(nLogoTile, 160, 40); } } }; @@ -196,25 +197,9 @@ FSavegameInfo GameInterface::GetSaveSig() return { SAVESIG_PS, MINSAVEVER_PS, SAVEVER_PS }; } -void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) -{ - if (text) - { - int height = 11; - - auto lines = FString(text).MakeUpper().Split("\n"); - int y = position - (height * lines.Size() / 2); - for (auto& l : lines) - { - int width = MyGetStringWidth(l); - myprintext(int(origin.X) + 160 - width / 2, int(origin.Y) + y, l, 0); - y += height; - } - } -} - void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text) { + // Fixme: should use the extracted font from the menu items DrawCenteredTextScreen(origin, text, 10, false); } diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 0734d8291..281bb8fbf 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -677,21 +677,6 @@ void HandleAsync() } -int MyGetStringWidth(const char *str) -{ - int nLen = strlen(str); - - int nWidth = 0; - - for (int i = 0; i < nLen; i++) - { - int nPic = seq_GetSeqPicnum(kSeqFont2, 0, str[i] - 32); - nWidth += tilesiz[nPic].x + 1; - } - - return nWidth; -} - void ResetPassword() { nCodeMin = nFirstPassword; @@ -1112,8 +1097,8 @@ void DoCredits() for (int i = nStart; i < nCreditsIndex; i++) { - int nWidth = MyGetStringWidth(gString[i]); - myprintext((320 - nWidth) / 2, y, gString[i], 0); + int nStringWidth = SmallFont->StringWidth(gString[i]); + DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, y, gString[i], DTA_FullscreenScale, FSMode_ScaleToFit43, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, TAG_DONE); y += 10; } @@ -1377,8 +1362,9 @@ static void GameDisplay(void) DrawStatusBar(); if (paused && !M_Active()) { - int nLen = MyGetStringWidth("PAUSED"); - myprintext((320 - nLen) / 2, 100, "PAUSED", 0); + auto tex = GStrings("TXTB_PAUSED"); + int nStringWidth = SmallFont->StringWidth(tex); + DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_ScaleToFit43, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, TAG_DONE); } if (M_Active()) { @@ -2268,14 +2254,6 @@ void mydeletesprite(int nSprite) } -void KeyFn1() -{ - menu_DoPlasma(); - overwritesprite(160, 100, kSkullHead, 0, 3, kPalNormal); - overwritesprite(161, 130, kSkullJaw, 0, 3, kPalNormal); - videoNextPage(); -} - extern int currentCinemaPalette; void DoGameOverScene() { @@ -2343,28 +2321,6 @@ int CopyCharToBitmap(char nChar, int nTile, int xPos, int yPos) return tilesiz[nFontTile].x + 1; } -// Note: strings passed should be uppercase -int myprintext(int x, int y, const char *str, int shade, int basepal) -{ - if (y < -15 || y >= 200) - return x; - - const char *c = str; - - while (*c != '\0') - { - int nTile = seq_GetSeqPicnum(kSeqFont2, 0, (*c) - 32); - overwritesprite(x, y, nTile, shade, 2, kPalNormal, basepal); - - int tileWidth = tilesiz[nTile].x; - - x += tileWidth + 1; - c++; - } - - return x; -} - void EraseScreen(int nVal) { // There's no other values than 0 ever coming through here. diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index f9efcfe3d..687af134c 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -191,9 +191,6 @@ void WaitTicks(int nTicks); void FadeIn(); void FadeOut(int bFadeMusic); -int myprintext(int x, int y, const char *str, int shade, int basepal = 0); -int MyGetStringWidth(const char *str); - void mychangespritesect(int nSprite, int nSector); void mydeletesprite(int nSprite); @@ -353,7 +350,6 @@ struct GameInterface : ::GameInterface void MenuClosed() override; void StartGame(FNewGameStartup& gs) override; FSavegameInfo GetSaveSig() override; - void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override; void DrawMenuCaption(const DVector2& origin, const char* text) override; bool LoadGame(FSaveGameNode* sv) override; bool SaveGame(FSaveGameNode* sv) override; diff --git a/source/exhumed/src/menu.cpp b/source/exhumed/src/menu.cpp index 06f884a28..80ca87138 100644 --- a/source/exhumed/src/menu.cpp +++ b/source/exhumed/src/menu.cpp @@ -35,6 +35,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "menu.h" #include "v_2ddrawer.h" #include "gamestate.h" +#include "statistics.h" +#include "v_draw.h" #include #include @@ -504,7 +506,7 @@ void ComputeCinemaText(int nLine) break; } - int nWidth = MyGetStringWidth(gString[linecount + nLine]); + int nWidth = SmallFont->StringWidth(gString[linecount + nLine]); nLeft[linecount] = 160 - nWidth / 2; linecount++; @@ -552,7 +554,7 @@ bool AdvanceCinemaText() while (i < linecount && y <= 199) { if (y >= -10) { - myprintext(nLeft[i], y, gString[line + i], 0, currentCinemaPalette); + DrawText(twod, SmallFont, CR_UNDEFINED, nLeft[i], y, gString[line + i], DTA_FullscreenScale, FSMode_ScaleToFit43, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, TAG_DONE); } i++; @@ -774,6 +776,7 @@ int showmap(short nLevel, short nLevelNew, short nLevelBest) menu_DrawTheMap(nLevel, nLevelNew, nLevelBest, [&](int lev){ gamestate = GS_LEVEL; selectedLevel = lev; + if (lev != nLevelNew) STAT_Cancel(); }); SyncScreenJob(); if (selectedLevel == 11) {