3069: Recreate score hud when any score changed r=Learath2 a=def-

Fixes problem with too long strings because we display the score centered

Thanks to ExP for report:
![screenshot_2020-10-11_17-18-45](https://user-images.githubusercontent.com/2335377/95682429-7a2b3380-0be5-11eb-8186-c1dbf922b960.png)

Fixed:
![screenshot-20201011@171419](https://user-images.githubusercontent.com/2335377/95682443-88794f80-0be5-11eb-9d10-79ea5df785c0.png)
![screenshot-20201011@171423](https://user-images.githubusercontent.com/2335377/95682441-857e5f00-0be5-11eb-805a-8312e43f5ba1.png)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-10-11 15:45:35 +00:00 committed by GitHub
commit 1d961a262f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -357,12 +357,12 @@ void CHud::RenderScoreHud()
aScore[t][0] = 0; aScore[t][0] = 0;
} }
bool RecreateScore[2] = {str_comp(aScore[0], m_aScoreInfo[0].m_aScoreText) != 0, str_comp(aScore[1], m_aScoreInfo[1].m_aScoreText) != 0}; bool RecreateScores = str_comp(aScore[0], m_aScoreInfo[0].m_aScoreText) != 0 || str_comp(aScore[1], m_aScoreInfo[1].m_aScoreText) != 0;
bool RecreateRect = ForceScoreInfoInit; bool RecreateRect = ForceScoreInfoInit;
for(int t = 0; t < 2; t++) for(int t = 0; t < 2; t++)
{ {
if(RecreateScore[t]) if(RecreateScores)
{ {
m_aScoreInfo[t].m_ScoreTextWidth = TextRender()->TextWidth(0, 14.0f, aScore[t], -1, -1.0f); m_aScoreInfo[t].m_ScoreTextWidth = TextRender()->TextWidth(0, 14.0f, aScore[t], -1, -1.0f);
mem_copy(m_aScoreInfo[t].m_aScoreText, aScore[t], sizeof(m_aScoreInfo[t].m_aScoreText)); mem_copy(m_aScoreInfo[t].m_aScoreText, aScore[t], sizeof(m_aScoreInfo[t].m_aScoreText));
@ -414,13 +414,13 @@ void CHud::RenderScoreHud()
if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1) if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1)
Graphics()->RenderQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex, -1); Graphics()->RenderQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex, -1);
if(RecreateScore[t]) if(RecreateScores)
{ {
if(m_aScoreInfo[t].m_TextScoreContainerIndex != -1) if(m_aScoreInfo[t].m_TextScoreContainerIndex != -1)
TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex); TextRender()->DeleteTextContainer(m_aScoreInfo[t].m_TextScoreContainerIndex);
CTextCursor Cursor; CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, Whole - ScoreWidthMax + (ScoreWidthMax - m_aScoreInfo[t].m_ScoreTextWidth) / 2 - Split, StartY + t * 20 + (18.f - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER); TextRender()->SetCursor(&Cursor, Whole - ScoreWidthMax + (ScoreWidthMax - m_aScoreInfo[t].m_ScoreTextWidth) - Split, StartY + t * 20 + (18.f - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER);
Cursor.m_LineWidth = -1; Cursor.m_LineWidth = -1;
m_aScoreInfo[t].m_TextScoreContainerIndex = TextRender()->CreateTextContainer(&Cursor, aScore[t]); m_aScoreInfo[t].m_TextScoreContainerIndex = TextRender()->CreateTextContainer(&Cursor, aScore[t]);
} }