Some chat fixes

This commit is contained in:
Jupeyy 2020-10-22 22:21:19 +02:00
parent 2ba4d5d6cb
commit 13c5e039c9
4 changed files with 57 additions and 21 deletions

View file

@ -272,6 +272,11 @@ class CTextRender : public IEngineTextRender
m_RenderFlags = Flags;
}
virtual unsigned int GetRenderFlags()
{
return m_RenderFlags;
}
void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h, int OutlineCount)
{
for(int y = 0; y < h; y++)
@ -1056,6 +1061,9 @@ public:
++CharacterCounter;
}
if(DrawX > pCursor->m_LongestLineWidth)
pCursor->m_LongestLineWidth = DrawX;
}
if(NewLine)
@ -1164,16 +1172,10 @@ public:
TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size();
if(Graphics()->IsTextBufferingEnabled())
{
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
TextContainer.m_StringInfo.m_QuadBufferObjectIndex = Graphics()->CreateBufferObject(DataSize, pUploadData);
for(size_t i = 0; i < m_DefaultTextContainerInfo.m_Attributes.size(); ++i)
m_DefaultTextContainerInfo.m_Attributes[i].m_VertBufferBindingIndex = TextContainer.m_StringInfo.m_QuadBufferObjectIndex;
TextContainer.m_StringInfo.m_QuadBufferContainerIndex = Graphics()->CreateBufferContainer(&m_DefaultTextContainerInfo);
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
if((TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0)
{
UploadTextContainer(ContainerIndex);
}
}
TextContainer.m_LineCount = pCursor->m_LineCount;
@ -1438,7 +1440,7 @@ public:
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1)
if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1 && (TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0)
{
Graphics()->RecreateBufferObject(TextContainer.m_StringInfo.m_QuadBufferObjectIndex, DataSize, pUploadData);
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
@ -1700,6 +1702,20 @@ public:
FreeTextContainer(TextContainerIndex);
}
virtual void UploadTextContainer(int TextContainerIndex)
{
STextContainer &TextContainer = GetTextContainer(TextContainerIndex);
size_t DataSize = TextContainer.m_StringInfo.m_CharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_CharacterQuads[0];
TextContainer.m_StringInfo.m_QuadBufferObjectIndex = Graphics()->CreateBufferObject(DataSize, pUploadData);
for(size_t i = 0; i < m_DefaultTextContainerInfo.m_Attributes.size(); ++i)
m_DefaultTextContainerInfo.m_Attributes[i].m_VertBufferBindingIndex = TextContainer.m_StringInfo.m_QuadBufferObjectIndex;
TextContainer.m_StringInfo.m_QuadBufferContainerIndex = Graphics()->CreateBufferContainer(&m_DefaultTextContainerInfo);
Graphics()->IndicesNumRequiredNotify(TextContainer.m_StringInfo.m_QuadNum * 6);
}
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor)
{
STextContainer &TextContainer = GetTextContainer(TextContainerIndex);

View file

@ -25,6 +25,7 @@ enum ETextRenderFlags
TEXT_RENDER_FLAG_NO_OVERSIZE = 1 << 5,
TEXT_RENDER_FLAG_NO_FIRST_CHARACTER_X_BEARING = 1 << 6,
TEXT_RENDER_FLAG_NO_LAST_CHARACTER_ADVANCE = 1 << 7,
TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD = 1 << 8,
};
enum
@ -91,6 +92,7 @@ public:
virtual void SetCurFont(CFont *pFont) = 0;
virtual void SetRenderFlags(unsigned int Flags) = 0;
virtual unsigned int GetRenderFlags() = 0;
//
virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) = 0;
@ -102,6 +104,8 @@ public:
virtual void SetTextContainerSelection(int TextContainerIndex, const char *pText, int CursorPos, int SelectionStart, int SelectionEnd) = 0;
virtual void DeleteTextContainer(int TextContainerIndex) = 0;
virtual void UploadTextContainer(int TextContainerIndex) = 0;
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;

View file

@ -972,21 +972,28 @@ void CChat::OnPrepareLines()
TextRender()->SetCursor(&Cursor, TextBegin, 0.0f, FontSize, 0);
Cursor.m_LineWidth = LineWidth;
Cursor.m_X += RealMsgPaddingTee;
if(m_aLines[r].m_Friend && g_Config.m_ClMessageFriend)
if(m_aLines[r].m_ClientID >= 0 && m_aLines[r].m_aName[0] != '\0')
{
TextRender()->TextEx(&Cursor, "", -1);
Cursor.m_X += RealMsgPaddingTee;
if(m_aLines[r].m_Friend && g_Config.m_ClMessageFriend)
{
TextRender()->TextEx(&Cursor, "", -1);
}
}
TextRender()->TextEx(&Cursor, aName, -1);
if(m_aLines[r].m_TimesRepeated > 0)
TextRender()->TextEx(&Cursor, aCount, -1);
TextRender()->TextEx(&Cursor, ": ", -1);
if(m_aLines[r].m_ClientID >= 0 && m_aLines[r].m_aName[0] != '\0')
{
TextRender()->TextEx(&Cursor, ": ", -1);
}
CTextCursor AppendCursor = Cursor;
AppendCursor.m_StartX = Cursor.m_X;
AppendCursor.m_LineWidth -= (Cursor.m_LongestLineWidth - Cursor.m_StartX);
TextRender()->TextEx(&AppendCursor, m_aLines[r].m_aText, -1);
@ -1002,6 +1009,9 @@ void CChat::OnPrepareLines()
// the position the text was created
m_aLines[r].m_TextYOffset = y + RealMsgPaddingY / 2.f;
int CurRenderFlags = TextRender()->GetRenderFlags();
TextRender()->SetRenderFlags(CurRenderFlags | ETextRenderFlags::TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD);
// reset the cursor
TextRender()->SetCursor(&Cursor, TextBegin, m_aLines[r].m_TextYOffset, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = LineWidth;
@ -1091,6 +1101,7 @@ void CChat::OnPrepareLines()
TextRender()->TextColor(Color);
CTextCursor AppendCursor = Cursor;
AppendCursor.m_LineWidth -= (Cursor.m_LongestLineWidth - Cursor.m_StartX);
AppendCursor.m_StartX = Cursor.m_X;
if(m_aLines[r].m_TextContainerIndex == -1)
@ -1102,8 +1113,12 @@ void CChat::OnPrepareLines()
{
float Height = m_aLines[r].m_YOffset[OffsetType];
Graphics()->SetColor(1, 1, 1, 1);
m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, AppendCursor.m_LongestLineWidth - Begin + RealMsgPaddingX, Height, RealMsgPaddingY, CUI::CORNER_ALL);
m_aLines[r].m_QuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Begin, y, (AppendCursor.m_LongestLineWidth - TextBegin) + RealMsgPaddingX * 1.5f, Height, MESSAGE_ROUNDING, CUI::CORNER_ALL);
}
TextRender()->SetRenderFlags(CurRenderFlags);
if(m_aLines[r].m_TextContainerIndex != -1)
TextRender()->UploadTextContainer(m_aLines[r].m_TextContainerIndex);
}
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
@ -1262,7 +1277,7 @@ void CChat::OnRender()
float RowHeight = FONT_SIZE + RealMsgPaddingY;
float OffsetTeeY = MESSAGE_TEE_SIZE / 2.0f;
float FullHeightMinusTee = RowHeight - MESSAGE_TEE_SIZE;
float TWSkinUnreliableOffset = 0.5f; // teeworlds skins were always a bit in the ground
float TWSkinUnreliableOffset = 1.0f; // teeworlds skins were always a bit in the ground
CAnimState *pIdleState = CAnimState::GetIdle();
RenderTools()->RenderTee(pIdleState, &RenderInfo, EMOTE_NORMAL, vec2(1, 0.1f), vec2(x + (RealMsgPaddingX + MESSAGE_TEE_SIZE) / 2.0f, y + OffsetTeeY + FullHeightMinusTee / 2.0f + TWSkinUnreliableOffset), Blend);

View file

@ -12,11 +12,12 @@ class CChat : public CComponent
CLineInput m_Input;
static constexpr float MESSAGE_PADDING_X = 5.0f;
static constexpr float MESSAGE_TEE_SIZE = 8.0f;
static constexpr float MESSAGE_TEE_SIZE = 7.0f;
static constexpr float MESSAGE_TEE_PADDING_RIGHT = 0.5f;
static constexpr float FONT_SIZE = 6.0f;
static constexpr float MESSAGE_PADDING_Y = 3.f;
static_assert(FONT_SIZE + MESSAGE_PADDING_Y >= 8.0f, "Corners for background chat are too huge for this combination of font size and message padding.");
static constexpr float MESSAGE_PADDING_Y = 1.0f;
static constexpr float MESSAGE_ROUNDING = 3.0f;
static_assert(FONT_SIZE + MESSAGE_PADDING_Y >= MESSAGE_ROUNDING * 2.0f, "Corners for background chat are too huge for this combination of font size and message padding.");
enum
{