Simplify emoji

This commit is contained in:
def 2017-10-28 09:06:53 +02:00
parent ebe894faef
commit 04820b44f8
4 changed files with 41 additions and 100 deletions

View file

@ -686,6 +686,8 @@ if(CLIENT)
components/debughud.h
components/effects.cpp
components/effects.h
components/emojis.cpp
components/emojis.h
components/emoticon.cpp
components/emoticon.h
components/flow.cpp

@ -1 +1 @@
Subproject commit fd5c2cd28c8e92e2b4b2f63f0ad2c02b837699fe
Subproject commit 3d28233cbc36a810e3164ace4bb61b62162519e5

View file

@ -552,29 +552,27 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
char aBuffer[64];
int Length = str_length(m_aLines[m_CurrentLine].m_aText);
//lookup for aliases of emojis
// lookup for aliases of emojis
for(int i = 0; i < Length; )
{
const char *pIndex1 = str_find(m_aLines[m_CurrentLine].m_aText + i, ":");
if (pIndex1 == NULL) break;
//prevents crashing when ":" is last character
if (m_aLines[m_CurrentLine].m_aText - pIndex1 + 1 == Length) break;
const char *pIndex2 = str_find(pIndex1 + 1, ":");
if (pIndex2 == NULL) break;
i = pIndex2 - m_aLines[m_CurrentLine].m_aText;
//prevents buffer overflow
if (pIndex2 - pIndex1 + 2 > 64) continue;
// prevents buffer overflow
if ((size_t)(pIndex2 - pIndex1 + 2) > sizeof(aBuffer)) continue;
str_copy(aBuffer, pIndex1, pIndex2 - pIndex1 + 2); // extra place for ":\0"
//skip "::" and those aliases containing space
// skip "::" and those aliases containing space
if (str_length(aBuffer) <= 2 || str_find(aBuffer, " ")) continue;
CEmojis::CEmoji const *pEmoji = m_pClient->m_pEmojis->GetByAlias(aBuffer);
if (pEmoji == NULL) continue;
//to prevent usage of the same ":"
// to prevent usage of the same ":"
i++;
CEmojis::CEmojiInfo Info;
@ -584,7 +582,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
m_aLines[m_CurrentLine].m_Emojis.add(Info);
}
//lookup for utf emojis
// lookup for utf emojis
for(int i = 0; i < m_pClient->m_pEmojis->Num(); i++)
{
int Offset = 0;
@ -603,29 +601,6 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
}
m_aLines[m_CurrentLine].m_Emojis.sort_range();
int Offset = 0;
for(int i = 0; i < Length; )
{
CEmojis::CEmojiInfo info;
bool Found = false;
for(int j = 0; j < m_aLines[m_CurrentLine].m_Emojis.size(); j++)
{
if(m_aLines[m_CurrentLine].m_Emojis[j].index >= i) {
Found = true;
info = m_aLines[m_CurrentLine].m_Emojis[j];
break;
}
}
int End = Found ? info.index : str_length(m_aLines[m_CurrentLine].m_aText);
str_copy(m_aLines[m_CurrentLine].m_aTextNoEmojis + Offset, m_aLines[m_CurrentLine].m_aText + i, End - i + 1);
Offset += End - i;
i = End;
if (Found) i += info.length;
}
char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team >= 2?"whisper":(m_aLines[m_CurrentLine].m_Team?"teamchat":"chat"), aBuf, Highlighted);
@ -805,8 +780,6 @@ void CChat::OnRender()
str_copy(aName, m_aLines[r].m_aName, sizeof(aName));
}
int Length = str_length(m_aLines[r].m_aText);
// get the y offset (calculate it if we haven't done that yet)
if(m_aLines[r].m_YOffset[OffsetType] < 0.0f)
{
@ -814,44 +787,29 @@ void CChat::OnRender()
Cursor.m_LineWidth = LineWidth;
TextRender()->TextEx(&Cursor, "", -1);
TextRender()->TextEx(&Cursor, aName, -1);
for (int i = 0; i < Length; )
int index = 0;
for(int j = 0; j < m_aLines[r].m_Emojis.size(); j++)
{
//Maybe replace with pointer?
CEmojis::CEmojiInfo info;
bool Found = false;
for(int j = 0; j < m_aLines[r].m_Emojis.size(); j++)
CEmojis::CEmojiInfo info = m_aLines[r].m_Emojis[j];
TextRender()->TextEx(&Cursor, &m_aLines[r].m_aText[index], info.index - index);
Cursor.m_X += Cursor.m_FontSize + (Cursor.m_EmojiX - Cursor.m_X);
if(Begin + Cursor.m_LineWidth < Cursor.m_X)
{
if(m_aLines[r].m_Emojis[j].index >= i) {
Found = true;
info = m_aLines[r].m_Emojis[j];
break;
}
}
char *pStart = &m_aLines[r].m_aText[i];
if(!Found)
{
TextRender()->TextEx(&Cursor, pStart, -1);
break;
}
else
{
TextRender()->TextEx(&Cursor, pStart, info.index - i);
Cursor.m_X += Cursor.m_FontSize + (Cursor.m_EmojiX - Cursor.m_X);
if(Begin + Cursor.m_LineWidth < Cursor.m_X)
{
Cursor.m_X = Cursor.m_StartX;
Cursor.m_Y += Cursor.m_FontSize;
Cursor.m_LineCount++;
}
i = info.index + info.length;
Cursor.m_X = Cursor.m_StartX;
Cursor.m_Y += Cursor.m_FontSize;
Cursor.m_LineCount++;
}
index = info.index + info.length;
}
TextRender()->TextEx(&Cursor, &m_aLines[r].m_aText[index], -1);
m_aLines[r].m_YOffset[OffsetType] = Cursor.m_Y + Cursor.m_FontSize;
}
y -= m_aLines[r].m_YOffset[OffsetType];
// cut off if msgs waste too much space
@ -929,43 +887,25 @@ void CChat::OnRender()
TextRender()->TextColor(rgb.r, rgb.g, rgb.b, Blend);
}
for (int i = 0; i < Length; )
int index = 0;
for(int j = 0; j < m_aLines[r].m_Emojis.size(); j++)
{
//maybe replace with pointer and remove "Found"?
CEmojis::CEmojiInfo info;
bool Found = false;
for(int j = 0; j < m_aLines[r].m_Emojis.size(); j++)
CEmojis::CEmojiInfo info = m_aLines[r].m_Emojis[j];
TextRender()->TextEx(&Cursor, &m_aLines[r].m_aText[index], info.index - index);
m_pClient->m_pEmojis->Render(info.m_ID, (Cursor.m_EmojiX) + Cursor.m_FontSize/2, Cursor.m_Y + Cursor.m_FontSize-2, Cursor.m_FontSize, Cursor.m_FontSize);
Cursor.m_X += Cursor.m_FontSize + (Cursor.m_EmojiX - Cursor.m_X);
if(Begin + Cursor.m_LineWidth < Cursor.m_X)
{
if(m_aLines[r].m_Emojis[j].index >= i) {
Found = true;
info = m_aLines[r].m_Emojis[j];
break;
}
}
char *pStart = &m_aLines[r].m_aText[i];
if(!Found)
{
TextRender()->TextEx(&Cursor, pStart, -1);
break;
}
else
{
TextRender()->TextEx(&Cursor, pStart, info.index - i);
m_pClient->m_pEmojis->Render(info.m_ID, (Cursor.m_EmojiX) + Cursor.m_FontSize/2, Cursor.m_Y + Cursor.m_FontSize-1, Cursor.m_FontSize, Cursor.m_FontSize);
Cursor.m_X += Cursor.m_FontSize + (Cursor.m_EmojiX - Cursor.m_X);
if(Begin + Cursor.m_LineWidth < Cursor.m_X)
{
Cursor.m_X = Cursor.m_StartX;
Cursor.m_Y += Cursor.m_FontSize;
Cursor.m_LineCount++;
}
i = info.index + info.length;
Cursor.m_X = Cursor.m_StartX;
Cursor.m_Y += Cursor.m_FontSize;
Cursor.m_LineCount++;
}
index = info.index + info.length;
}
TextRender()->TextEx(&Cursor, &m_aLines[r].m_aText[index], -1);
}
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);

View file

@ -26,7 +26,6 @@ class CChat : public CComponent
int m_NameColor;
char m_aName[64];
char m_aText[512];
char m_aTextNoEmojis[512];
bool m_Friend;
bool m_Highlighted;
sorted_array<CEmojis::CEmojiInfo> m_Emojis;