mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 09:38:19 +00:00
refactor: use text containers to render movement information
closes #8622
This commit is contained in:
parent
cb9521d29f
commit
ec37efdcfd
|
@ -28,6 +28,13 @@ CHud::CHud()
|
|||
m_FrameTimeAvg = 0.0f;
|
||||
m_FPSTextContainerIndex.Reset();
|
||||
m_DDRaceEffectsTextContainerIndex.Reset();
|
||||
m_PlayerAngleTextContainerIndex.Reset();
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
m_aPlayerSpeedTextContainers[i].Reset();
|
||||
m_aPlayerPositionContainers[i].Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CHud::ResetHudContainers()
|
||||
|
@ -44,6 +51,12 @@ void CHud::ResetHudContainers()
|
|||
|
||||
TextRender()->DeleteTextContainer(m_FPSTextContainerIndex);
|
||||
TextRender()->DeleteTextContainer(m_DDRaceEffectsTextContainerIndex);
|
||||
TextRender()->DeleteTextContainer(m_PlayerAngleTextContainerIndex);
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_aPlayerSpeedTextContainers[i]);
|
||||
TextRender()->DeleteTextContainer(m_aPlayerPositionContainers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CHud::OnWindowResize()
|
||||
|
@ -1245,6 +1258,28 @@ inline float CHud::GetMovementInformationBoxHeight()
|
|||
return BoxHeight;
|
||||
}
|
||||
|
||||
void CHud::UpdateMovementInformationTextContainer(STextContainerIndex &TextContainer, float FontSize, float Value, char *pPrevValue, size_t Size)
|
||||
{
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", Value);
|
||||
|
||||
if(!TextContainer.Valid() || str_comp(pPrevValue, aBuf) != 0)
|
||||
{
|
||||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, 0, 0, FontSize, TEXTFLAG_RENDER);
|
||||
TextRender()->RecreateTextContainer(TextContainer, &Cursor, aBuf);
|
||||
str_copy(pPrevValue, aBuf, Size);
|
||||
}
|
||||
}
|
||||
|
||||
void CHud::RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, float X, float Y)
|
||||
{
|
||||
if(TextContainer.Valid())
|
||||
{
|
||||
TextRender()->RenderTextContainer(TextContainer, TextRender()->DefaultTextColor(), TextRender()->DefaultTextOutlineColor(), X - TextRender()->GetBoundingBoxTextContainer(TextContainer).m_W, Y);
|
||||
}
|
||||
}
|
||||
|
||||
void CHud::RenderMovementInformation(const int ClientId)
|
||||
{
|
||||
// Draw the infomations depending on settings: Position, speed and target angle
|
||||
|
@ -1303,28 +1338,9 @@ void CHud::RenderMovementInformation(const int ClientId)
|
|||
}
|
||||
float DisplayAngle = Angle * 180.0f / pi;
|
||||
|
||||
char aBuf[128];
|
||||
float w;
|
||||
|
||||
float y = StartY + LineSpacer * 2;
|
||||
float xl = StartX + 2;
|
||||
float xr = m_Width - 2;
|
||||
int DigitsIndex;
|
||||
|
||||
static float s_TextWidth0 = TextRender()->TextWidth(Fontsize, "0.00", -1, -1.0f);
|
||||
static float s_TextWidth00 = TextRender()->TextWidth(Fontsize, "00.00", -1, -1.0f);
|
||||
static float s_TextWidth000 = TextRender()->TextWidth(Fontsize, "000.00", -1, -1.0f);
|
||||
static float s_TextWidth0000 = TextRender()->TextWidth(Fontsize, "0000.00", -1, -1.0f);
|
||||
static float s_TextWidth00000 = TextRender()->TextWidth(Fontsize, "00000.00", -1, -1.0f);
|
||||
static float s_TextWidth000000 = TextRender()->TextWidth(Fontsize, "000000.00", -1, -1.0f);
|
||||
static float s_aTextWidth[6] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000, s_TextWidth000000};
|
||||
static float s_TextWidthMinus0 = TextRender()->TextWidth(Fontsize, "-0.00", -1, -1.0f);
|
||||
static float s_TextWidthMinus00 = TextRender()->TextWidth(Fontsize, "-00.00", -1, -1.0f);
|
||||
static float s_TextWidthMinus000 = TextRender()->TextWidth(Fontsize, "-000.00", -1, -1.0f);
|
||||
static float s_TextWidthMinus0000 = TextRender()->TextWidth(Fontsize, "-0000.00", -1, -1.0f);
|
||||
static float s_TextWidthMinus00000 = TextRender()->TextWidth(Fontsize, "-00000.00", -1, -1.0f);
|
||||
static float s_TextWidthMinus000000 = TextRender()->TextWidth(Fontsize, "-000000.00", -1, -1.0f);
|
||||
static float s_aTextWidthMinus[6] = {s_TextWidthMinus0, s_TextWidthMinus00, s_TextWidthMinus000, s_TextWidthMinus0000, s_TextWidthMinus00000, s_TextWidthMinus000000};
|
||||
|
||||
if(g_Config.m_ClShowhudPlayerPosition)
|
||||
{
|
||||
|
@ -1332,17 +1348,13 @@ void CHud::RenderMovementInformation(const int ClientId)
|
|||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
|
||||
TextRender()->Text(xl, y, Fontsize, "X:", -1.0f);
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", Pos.x);
|
||||
DigitsIndex = GetDigitsIndex(Pos.x, 5);
|
||||
w = (Pos.x < 0) ? s_aTextWidthMinus[DigitsIndex] : s_aTextWidth[DigitsIndex];
|
||||
TextRender()->Text(xr - w, y, Fontsize, aBuf, -1.0f);
|
||||
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[0], Fontsize, Pos.x, m_aaPlayerPositionText[0], sizeof(m_aaPlayerPositionText[0]));
|
||||
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[0], xr, y);
|
||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
|
||||
TextRender()->Text(xl, y, Fontsize, "Y:", -1.0f);
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", Pos.y);
|
||||
DigitsIndex = GetDigitsIndex(Pos.y, 5);
|
||||
w = (Pos.y < 0) ? s_aTextWidthMinus[DigitsIndex] : s_aTextWidth[DigitsIndex];
|
||||
TextRender()->Text(xr - w, y, Fontsize, aBuf, -1.0f);
|
||||
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[1], Fontsize, Pos.y, m_aaPlayerPositionText[1], sizeof(m_aaPlayerPositionText[1]));
|
||||
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[1], xr, y);
|
||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
}
|
||||
|
||||
|
@ -1352,17 +1364,13 @@ void CHud::RenderMovementInformation(const int ClientId)
|
|||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
|
||||
TextRender()->Text(xl, y, Fontsize, "X:", -1.0f);
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", DisplaySpeedX);
|
||||
DigitsIndex = GetDigitsIndex(DisplaySpeedX, 5);
|
||||
w = (DisplaySpeedX < 0) ? s_aTextWidthMinus[DigitsIndex] : s_aTextWidth[DigitsIndex];
|
||||
TextRender()->Text(xr - w, y, Fontsize, aBuf, -1.0f);
|
||||
UpdateMovementInformationTextContainer(m_aPlayerSpeedTextContainers[0], Fontsize, DisplaySpeedX, m_aaPlayerSpeedText[0], sizeof(m_aaPlayerSpeedText[0]));
|
||||
RenderMovementInformationTextContainer(m_aPlayerSpeedTextContainers[0], xr, y);
|
||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
|
||||
TextRender()->Text(xl, y, Fontsize, "Y:", -1.0f);
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", DisplaySpeedY);
|
||||
DigitsIndex = GetDigitsIndex(DisplaySpeedY, 5);
|
||||
w = (DisplaySpeedY < 0) ? s_aTextWidthMinus[DigitsIndex] : s_aTextWidth[DigitsIndex];
|
||||
TextRender()->Text(xr - w, y, Fontsize, aBuf, -1.0f);
|
||||
UpdateMovementInformationTextContainer(m_aPlayerSpeedTextContainers[1], Fontsize, DisplaySpeedY, m_aaPlayerSpeedText[1], sizeof(m_aaPlayerSpeedText[1]));
|
||||
RenderMovementInformationTextContainer(m_aPlayerSpeedTextContainers[1], xr, y);
|
||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
}
|
||||
|
||||
|
@ -1370,10 +1378,9 @@ void CHud::RenderMovementInformation(const int ClientId)
|
|||
{
|
||||
TextRender()->Text(xl, y, Fontsize, Localize("Angle:"), -1.0f);
|
||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||
str_format(aBuf, sizeof(aBuf), "%.2f", DisplayAngle);
|
||||
DigitsIndex = GetDigitsIndex(DisplayAngle, 5);
|
||||
w = (DisplayAngle < 0) ? s_aTextWidthMinus[DigitsIndex] : s_aTextWidth[DigitsIndex];
|
||||
TextRender()->Text(xr - w, y, Fontsize, aBuf, -1.0f);
|
||||
|
||||
UpdateMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, Fontsize, DisplayAngle, m_aPlayerAngleText, sizeof(m_aPlayerAngleText));
|
||||
RenderMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, xr, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,12 @@ class CHud : public CComponent
|
|||
SScoreInfo m_aScoreInfo[2];
|
||||
STextContainerIndex m_FPSTextContainerIndex;
|
||||
STextContainerIndex m_DDRaceEffectsTextContainerIndex;
|
||||
STextContainerIndex m_PlayerAngleTextContainerIndex;
|
||||
char m_aPlayerAngleText[128];
|
||||
STextContainerIndex m_aPlayerSpeedTextContainers[2];
|
||||
char m_aaPlayerSpeedText[2][128];
|
||||
STextContainerIndex m_aPlayerPositionContainers[2];
|
||||
char m_aaPlayerPositionText[2][128];
|
||||
|
||||
void RenderCursor();
|
||||
|
||||
|
@ -65,6 +71,9 @@ class CHud : public CComponent
|
|||
void RenderDummyActions();
|
||||
void RenderMovementInformation(const int ClientId);
|
||||
|
||||
void UpdateMovementInformationTextContainer(STextContainerIndex &TextContainer, float FontSize, float Value, char *pPrevValue, size_t Size);
|
||||
void RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, float X, float Y);
|
||||
|
||||
void RenderGameTimer();
|
||||
void RenderPauseNotification();
|
||||
void RenderSuddenDeath();
|
||||
|
|
Loading…
Reference in a new issue