From ed9b10529968e458ce01a2d1d6213118f6b10083 Mon Sep 17 00:00:00 2001 From: Vladimir Olteanu Date: Wed, 14 Jul 2021 11:08:53 +0300 Subject: [PATCH] DiabloUI: make UiArtText follow mutating char* --- Source/DiabloUI/diabloui.cpp | 2 +- Source/DiabloUI/selgame.cpp | 2 +- Source/DiabloUI/selhero.cpp | 2 +- Source/DiabloUI/ui_item.h | 21 ++++++++++++++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index f0199bbcb..94fa658ac 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -725,7 +725,7 @@ void Render(UiText *uiText) void Render(const UiArtText *uiArtText) { - DrawArtStr(uiArtText->m_text, uiArtText->m_rect, uiArtText->m_iFlags); + DrawArtStr(uiArtText->text(), uiArtText->m_rect, uiArtText->m_iFlags); } void Render(const UiImage *uiImage) diff --git a/Source/DiabloUI/selgame.cpp b/Source/DiabloUI/selgame.cpp index eecd9e184..ab6ed100f 100644 --- a/Source/DiabloUI/selgame.cpp +++ b/Source/DiabloUI/selgame.cpp @@ -139,7 +139,7 @@ void selgame_GameSelection_Select(int value) UiAddLogo(&vecSelGameDialog); SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 24), (Sint16)(UI_OFFSET_Y + 161), 590, 35 }; - vecSelGameDialog.push_back(std::make_unique(title, rect1, UIS_CENTER | UIS_BIG)); + vecSelGameDialog.push_back(std::make_unique(&title, rect1, UIS_CENTER | UIS_BIG)); SDL_Rect rect2 = { (Sint16)(PANEL_LEFT + 34), (Sint16)(UI_OFFSET_Y + 211), 205, 33 }; vecSelGameDialog.push_back(std::make_unique(selgame_Label, rect2, UIS_CENTER | UIS_BIG)); diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index 27cb89150..886d0674c 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -466,7 +466,7 @@ void selhero_Init() vecSelDlgItems.clear(); SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 24), (Sint16)(UI_OFFSET_Y + 161), 590, 35 }; - vecSelHeroDialog.push_back(std::make_unique(title, rect1, UIS_CENTER | UIS_BIG)); + vecSelHeroDialog.push_back(std::make_unique(&title, rect1, UIS_CENTER | UIS_BIG)); SDL_Rect rect2 = { (Sint16)(PANEL_LEFT + 30), (Sint16)(UI_OFFSET_Y + 211), 180, 76 }; auto heroImg = std::make_unique(&ArtHero, static_cast(enum_size::value), rect2); diff --git a/Source/DiabloUI/ui_item.h b/Source/DiabloUI/ui_item.h index 60fa26a13..548078bf3 100644 --- a/Source/DiabloUI/ui_item.h +++ b/Source/DiabloUI/ui_item.h @@ -135,15 +135,30 @@ class UiArtText : public UiItemBase { public: UiArtText(const char *text, SDL_Rect rect, int flags = 0) : UiItemBase(rect, flags) + , m_text(text) + { + m_type = UI_ART_TEXT; + }; + + UiArtText(const char **ptext, SDL_Rect rect, int flags = 0) + : UiItemBase(rect, flags) + , m_ptext(ptext) { m_type = UI_ART_TEXT; - m_text = text; }; + const char *text() const + { + if (m_text != nullptr) + return m_text; + return *m_ptext; + } + ~UiArtText() {}; - //private: - const char *m_text; +private: + const char *m_text = nullptr; + const char **m_ptext = nullptr; }; //=============================================================================