2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include <engine/shared/config.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/generated/client_data.h>
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/client/animstate.h>
|
|
|
|
#include "nameplates.h"
|
|
|
|
#include "controls.h"
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CNamePlates::RenderNameplate(
|
|
|
|
const CNetObj_Character *pPrevChar,
|
|
|
|
const CNetObj_Character *pPlayerChar,
|
|
|
|
const CNetObj_PlayerInfo *pPlayerInfo
|
2008-09-04 18:54:37 +00:00
|
|
|
)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float IntraTick = Client()->IntraGameTick();
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Position = mix(vec2(pPrevChar->m_X, pPrevChar->m_Y), vec2(pPlayerChar->m_X, pPlayerChar->m_Y), IntraTick);
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2011-01-04 12:11:01 +00:00
|
|
|
|
|
|
|
float FontSize = 18.0f + 20.0f * g_Config.m_ClNameplatesSize / 100.0f;
|
2008-09-04 18:54:37 +00:00
|
|
|
// render name plate
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!pPlayerInfo->m_Local)
|
2008-09-04 18:54:37 +00:00
|
|
|
{
|
|
|
|
float a = 1;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(g_Config.m_ClNameplatesAlways == 0)
|
|
|
|
a = clamp(1-powf(distance(m_pClient->m_pControls->m_TargetPos, Position)/200.0f,16.0f), 0.0f, 1.0f);
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
const char *pName = m_pClient->m_aClients[pPlayerInfo->m_ClientID].m_aName;
|
2011-01-04 12:11:01 +00:00
|
|
|
float tw = TextRender()->TextWidth(0, FontSize, pName, -1);
|
2010-12-15 12:31:27 +00:00
|
|
|
|
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, a);
|
|
|
|
if(m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_Flags&GAMEFLAG_TEAMS)
|
|
|
|
{
|
|
|
|
if(pPlayerInfo->m_Team == TEAM_RED)
|
|
|
|
TextRender()->TextColor(1.0f, 0.5f, 0.5f, a);
|
|
|
|
else if(pPlayerInfo->m_Team == TEAM_BLUE)
|
|
|
|
TextRender()->TextColor(0.7f, 0.7f, 1.0f, a);
|
|
|
|
}
|
|
|
|
|
2011-01-04 12:11:01 +00:00
|
|
|
TextRender()->Text(0, Position.x-tw/2.0f, Position.y-FontSize-38.0f, FontSize, pName, -1);
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(g_Config.m_Debug) // render client id when in debug aswell
|
2008-09-04 18:54:37 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
char aBuf[128];
|
2011-02-12 10:40:36 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf),"%d", pPlayerInfo->m_ClientID);
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->Text(0, Position.x, Position.y-90, 28.0f, aBuf, -1);
|
2008-09-04 18:54:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextColor(1,1,1,1);
|
2008-09-04 18:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CNamePlates::OnRender()
|
2008-09-04 18:54:37 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if (!g_Config.m_ClNameplates)
|
2008-09-04 18:54:37 +00:00
|
|
|
return;
|
2008-09-23 08:42:38 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
2008-09-04 18:54:37 +00:00
|
|
|
{
|
2008-09-23 08:42:38 +00:00
|
|
|
// only render active characters
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!m_pClient->m_Snap.m_aCharacters[i].m_Active)
|
2008-09-23 08:42:38 +00:00
|
|
|
continue;
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
const void *pInfo = Client()->SnapFindItem(IClient::SNAP_CURRENT, NETOBJTYPE_PLAYERINFO, i);
|
2008-09-04 18:54:37 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pInfo)
|
2008-09-23 08:42:38 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderNameplate(
|
|
|
|
&m_pClient->m_Snap.m_aCharacters[i].m_Prev,
|
|
|
|
&m_pClient->m_Snap.m_aCharacters[i].m_Cur,
|
|
|
|
(const CNetObj_PlayerInfo *)pInfo);
|
2008-09-04 18:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|