2011-03-10 09:08: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. */
|
2020-03-31 06:03:25 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
2011-03-12 17:07:57 +00:00
|
|
|
#include <engine/demo.h>
|
2011-03-10 09:08:14 +00:00
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/shared/config.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/textrender.h>
|
2011-03-10 09:08:14 +00:00
|
|
|
|
|
|
|
#include <game/generated/client_data.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
|
|
|
|
#include <game/client/animstate.h>
|
|
|
|
#include <game/client/render.h>
|
|
|
|
|
2020-04-01 05:52:44 +00:00
|
|
|
#include "camera.h"
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "spectator.h"
|
2011-03-10 09:08:14 +00:00
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
void CSpectator::ConKeySpectator(IConsole::IResult *pResult, void *pUserData)
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
|
|
|
CSpectator *pSelf = (CSpectator *)pUserData;
|
2015-08-26 17:35:00 +00:00
|
|
|
|
2015-07-26 16:21:51 +00:00
|
|
|
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_Active || pSelf->Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
2011-03-10 09:08:14 +00:00
|
|
|
pSelf->m_Active = pResult->GetInteger(0) != 0;
|
2015-08-26 17:35:00 +00:00
|
|
|
else
|
|
|
|
pSelf->m_Active = false;
|
2011-03-10 09:08:14 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
void CSpectator::ConSpectate(IConsole::IResult *pResult, void *pUserData)
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
|
|
|
((CSpectator *)pUserData)->Spectate(pResult->GetInteger(0));
|
|
|
|
}
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
void CSpectator::ConSpectateNext(IConsole::IResult *pResult, void *pUserData)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
|
|
|
CSpectator *pSelf = (CSpectator *)pUserData;
|
2011-04-04 08:42:36 +00:00
|
|
|
int NewSpectatorID;
|
|
|
|
bool GotNewSpectatorID = false;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-04-24 12:59:16 +00:00
|
|
|
int CurPos = -1;
|
2020-09-13 19:20:13 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
if(pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] && pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID == pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)
|
|
|
|
CurPos = i;
|
2014-04-24 12:59:16 +00:00
|
|
|
|
2011-04-03 23:27:23 +00:00
|
|
|
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-04-04 08:42:36 +00:00
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-24 12:59:16 +00:00
|
|
|
for(int i = CurPos + 1; i < MAX_CLIENTS; i++)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-04-04 08:42:36 +00:00
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-04-04 08:42:36 +00:00
|
|
|
if(!GotNewSpectatorID)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2014-04-24 12:59:16 +00:00
|
|
|
for(int i = 0; i < CurPos; i++)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-04-19 14:10:50 +00:00
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-04 08:42:36 +00:00
|
|
|
if(GotNewSpectatorID)
|
|
|
|
pSelf->Spectate(NewSpectatorID);
|
2011-04-03 23:27:23 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
void CSpectator::ConSpectatePrevious(IConsole::IResult *pResult, void *pUserData)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
|
|
|
CSpectator *pSelf = (CSpectator *)pUserData;
|
2011-04-04 08:42:36 +00:00
|
|
|
int NewSpectatorID;
|
|
|
|
bool GotNewSpectatorID = false;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-04-24 12:59:16 +00:00
|
|
|
int CurPos = -1;
|
2020-09-13 19:20:13 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
if(pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] && pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID == pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)
|
|
|
|
CurPos = i;
|
2014-04-24 12:59:16 +00:00
|
|
|
|
2011-04-03 23:27:23 +00:00
|
|
|
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int i = MAX_CLIENTS - 1; i > -1; i--)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-04-04 08:42:36 +00:00
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-24 12:59:16 +00:00
|
|
|
for(int i = CurPos - 1; i > -1; i--)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-04-04 08:42:36 +00:00
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-04-04 08:42:36 +00:00
|
|
|
if(!GotNewSpectatorID)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2014-04-24 12:59:16 +00:00
|
|
|
for(int i = MAX_CLIENTS - 1; i > CurPos; i--)
|
2011-04-03 23:27:23 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-04-03 23:27:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
NewSpectatorID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
|
|
|
GotNewSpectatorID = true;
|
2011-04-03 23:27:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-04 08:42:36 +00:00
|
|
|
if(GotNewSpectatorID)
|
|
|
|
pSelf->Spectate(NewSpectatorID);
|
2011-04-03 23:27:23 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 06:03:25 +00:00
|
|
|
void CSpectator::ConSpectateClosest(IConsole::IResult *pResult, void *pUserData)
|
|
|
|
{
|
|
|
|
CSpectator *pSelf = (CSpectator *)pUserData;
|
|
|
|
int NewSpectatorID = -1;
|
|
|
|
|
|
|
|
int IndexOfTeeBeingSpectated = -1;
|
2020-04-01 05:52:44 +00:00
|
|
|
vec2 CurPosition(pSelf->m_pClient->m_pCamera->m_Center);
|
|
|
|
if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID != SPEC_FREEVIEW)
|
2020-03-31 06:03:25 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
2020-03-31 06:03:25 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] && pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID == pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID)
|
2020-04-01 05:52:44 +00:00
|
|
|
{
|
|
|
|
IndexOfTeeBeingSpectated = i;
|
2020-09-13 19:20:13 +00:00
|
|
|
const CNetObj_Character &CurCharacter = pSelf->m_pClient->m_Snap.m_aCharacters[pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID].m_Cur;
|
2020-04-01 05:52:44 +00:00
|
|
|
CurPosition.x = CurCharacter.m_X;
|
|
|
|
CurPosition.y = CurCharacter.m_Y;
|
|
|
|
break;
|
|
|
|
}
|
2020-03-31 06:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-01 05:52:44 +00:00
|
|
|
int ClosestDistance = INT_MAX;
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
2020-03-31 06:03:25 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(i == IndexOfTeeBeingSpectated || !pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i] || pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2020-04-01 05:52:44 +00:00
|
|
|
continue;
|
2020-09-13 19:20:13 +00:00
|
|
|
int ClientID = pSelf->m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2020-04-01 05:52:44 +00:00
|
|
|
const CNetObj_Character &MaybeClosestCharacter = pSelf->m_pClient->m_Snap.m_aCharacters[ClientID].m_Cur;
|
|
|
|
int Distance = distance(CurPosition, vec2(MaybeClosestCharacter.m_X, MaybeClosestCharacter.m_Y));
|
|
|
|
if(NewSpectatorID == -1 || Distance < ClosestDistance)
|
2020-03-31 06:03:25 +00:00
|
|
|
{
|
2020-04-01 05:52:44 +00:00
|
|
|
NewSpectatorID = ClientID;
|
|
|
|
ClosestDistance = Distance;
|
2020-03-31 06:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(NewSpectatorID > -1)
|
|
|
|
pSelf->Spectate(NewSpectatorID);
|
|
|
|
}
|
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
CSpectator::CSpectator()
|
|
|
|
{
|
|
|
|
OnReset();
|
2014-06-16 12:44:00 +00:00
|
|
|
m_OldMouseX = m_OldMouseY = 0.0f;
|
2011-03-10 09:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpectator::OnConsoleInit()
|
|
|
|
{
|
2011-08-13 00:11:06 +00:00
|
|
|
Console()->Register("+spectate", "", CFGFLAG_CLIENT, ConKeySpectator, this, "Open spectator mode selector");
|
2015-12-28 15:14:52 +00:00
|
|
|
Console()->Register("spectate", "i[spectator-id]", CFGFLAG_CLIENT, ConSpectate, this, "Switch spectator mode");
|
2011-08-13 00:11:06 +00:00
|
|
|
Console()->Register("spectate_next", "", CFGFLAG_CLIENT, ConSpectateNext, this, "Spectate the next player");
|
|
|
|
Console()->Register("spectate_previous", "", CFGFLAG_CLIENT, ConSpectatePrevious, this, "Spectate the previous player");
|
2020-03-31 06:03:25 +00:00
|
|
|
Console()->Register("spectate_closest", "", CFGFLAG_CLIENT, ConSpectateClosest, this, "Spectate the closest player");
|
2011-03-10 09:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpectator::OnMouseMove(float x, float y)
|
|
|
|
{
|
|
|
|
if(!m_Active)
|
|
|
|
return false;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-02 22:36:07 +00:00
|
|
|
UI()->ConvertMouseMove(&x, &y);
|
2020-09-26 19:41:58 +00:00
|
|
|
m_SelectorMouse += vec2(x, y);
|
2011-03-10 09:08:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpectator::OnRelease()
|
|
|
|
{
|
|
|
|
OnReset();
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
void CSpectator::OnRender()
|
|
|
|
{
|
|
|
|
if(!m_Active)
|
|
|
|
{
|
|
|
|
if(m_WasActive)
|
|
|
|
{
|
|
|
|
if(m_SelectedSpectatorID != NO_SELECTION)
|
|
|
|
Spectate(m_SelectedSpectatorID);
|
2011-03-12 17:07:57 +00:00
|
|
|
m_WasActive = false;
|
2011-03-10 09:08:14 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2015-09-04 09:22:19 +00:00
|
|
|
if(!m_pClient->m_Snap.m_SpecInfo.m_Active && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
2011-07-11 10:02:45 +00:00
|
|
|
{
|
|
|
|
m_Active = false;
|
|
|
|
m_WasActive = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
m_WasActive = true;
|
|
|
|
m_SelectedSpectatorID = NO_SELECTION;
|
|
|
|
|
|
|
|
// draw background
|
2020-09-26 19:41:58 +00:00
|
|
|
float Width = 400 * 3.0f * Graphics()->ScreenAspect();
|
|
|
|
float Height = 400 * 3.0f;
|
2014-01-12 18:38:22 +00:00
|
|
|
float ObjWidth = 300.0f;
|
|
|
|
float FontSize = 20.0f;
|
|
|
|
float BigFontSize = 20.0f;
|
|
|
|
float StartY = -190.0f;
|
|
|
|
float LineHeight = 60.0f;
|
|
|
|
float TeeSizeMod = 1.0f;
|
|
|
|
float RoundRadius = 30.0f;
|
|
|
|
bool Selected = false;
|
|
|
|
int TotalPlayers = 0;
|
|
|
|
int PerLine = 8;
|
|
|
|
float BoxMove = -10.0f;
|
|
|
|
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!m_pClient->m_Snap.m_paInfoByDDTeamName[i] || m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2014-01-12 18:38:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
++TotalPlayers;
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(TotalPlayers > 32)
|
2014-01-12 18:38:22 +00:00
|
|
|
{
|
|
|
|
FontSize = 18.0f;
|
|
|
|
LineHeight = 30.0f;
|
|
|
|
TeeSizeMod = 0.7f;
|
|
|
|
PerLine = 16;
|
|
|
|
RoundRadius = 10.0f;
|
|
|
|
BoxMove = 3.0f;
|
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(TotalPlayers > 16)
|
2014-01-12 18:38:22 +00:00
|
|
|
{
|
|
|
|
ObjWidth = 600.0f;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->MapScreen(0, 0, Width, Height);
|
|
|
|
|
|
|
|
Graphics()->BlendNormal();
|
2012-08-12 10:41:50 +00:00
|
|
|
Graphics()->TextureClear();
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.3f);
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->DrawRoundRect(Width / 2.0f - ObjWidth, Height / 2.0f - 300.0f, ObjWidth * 2, 600.0f, 20.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
|
|
|
|
// clamp mouse position to selector area
|
2014-01-12 18:38:22 +00:00
|
|
|
m_SelectorMouse.x = clamp(m_SelectorMouse.x, -(ObjWidth - 20.0f), ObjWidth - 20.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
m_SelectorMouse.y = clamp(m_SelectorMouse.y, -280.0f, 280.0f);
|
|
|
|
|
|
|
|
// draw selections
|
2015-07-26 16:21:51 +00:00
|
|
|
if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FREEVIEW) ||
|
2020-09-26 19:41:58 +00:00
|
|
|
m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
2012-08-12 10:41:50 +00:00
|
|
|
Graphics()->TextureClear();
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->DrawRoundRect(Width / 2.0f - (ObjWidth - 20.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, 20.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
2015-07-26 16:21:51 +00:00
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FOLLOW)
|
|
|
|
{
|
2012-08-12 10:41:50 +00:00
|
|
|
Graphics()->TextureClear();
|
2015-07-26 16:21:51 +00:00
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->DrawRoundRect(Width / 2.0f - (ObjWidth - 310.0f), Height / 2.0f - 280.0f, 270.0f, 60.0f, 20.0f);
|
2015-07-26 16:21:51 +00:00
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_SelectorMouse.x >= -(ObjWidth - 20.0f) && m_SelectorMouse.x <= -(ObjWidth - 290 + 10.0f) &&
|
2011-03-10 09:08:14 +00:00
|
|
|
m_SelectorMouse.y >= -280.0f && m_SelectorMouse.y <= -220.0f)
|
|
|
|
{
|
|
|
|
m_SelectedSpectatorID = SPEC_FREEVIEW;
|
|
|
|
Selected = true;
|
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Selected ? 1.0f : 0.5f);
|
|
|
|
TextRender()->Text(0, Width / 2.0f - (ObjWidth - 60.0f), Height / 2.0f - 280.f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Free-View"), -1.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
|
2015-07-26 16:37:31 +00:00
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
2015-07-26 16:21:51 +00:00
|
|
|
{
|
|
|
|
Selected = false;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_SelectorMouse.x > -(ObjWidth - 290.0f) && m_SelectorMouse.x <= -(ObjWidth - 590.0f) &&
|
2015-07-26 16:21:51 +00:00
|
|
|
m_SelectorMouse.y >= -280.0f && m_SelectorMouse.y <= -220.0f)
|
|
|
|
{
|
|
|
|
m_SelectedSpectatorID = SPEC_FOLLOW;
|
|
|
|
Selected = true;
|
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Selected ? 1.0f : 0.5f);
|
|
|
|
TextRender()->Text(0, Width / 2.0f - (ObjWidth - 350.0f), Height / 2.0f - 280.0f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Follow"), -1.0f);
|
2015-07-26 16:21:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-12 18:38:22 +00:00
|
|
|
float x = -(ObjWidth - 30.0f), y = StartY;
|
2014-03-23 23:04:44 +00:00
|
|
|
|
|
|
|
int OldDDTeam = -1;
|
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
for(int i = 0, Count = 0; i < MAX_CLIENTS; ++i)
|
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
if(!m_pClient->m_Snap.m_paInfoByDDTeamName[i] || m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_Team == TEAM_SPECTATORS)
|
2011-03-10 09:08:14 +00:00
|
|
|
continue;
|
|
|
|
|
2013-12-31 21:15:38 +00:00
|
|
|
++Count;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(Count == PerLine + 1 || (Count > PerLine + 1 && (Count - 1) % PerLine == 0))
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
|
|
|
x += 290.0f;
|
|
|
|
y = StartY;
|
|
|
|
}
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
const CNetObj_PlayerInfo *pInfo = m_pClient->m_Snap.m_paInfoByDDTeamName[i];
|
2019-04-11 10:21:42 +00:00
|
|
|
int DDTeam = m_pClient->m_Teams.Team(pInfo->m_ClientID);
|
2014-03-23 23:04:44 +00:00
|
|
|
int NextDDTeam = 0;
|
|
|
|
|
|
|
|
for(int j = i + 1; j < MAX_CLIENTS; j++)
|
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
const CNetObj_PlayerInfo *pInfo2 = m_pClient->m_Snap.m_paInfoByDDTeamName[j];
|
2014-03-23 23:04:44 +00:00
|
|
|
|
|
|
|
if(!pInfo2 || pInfo2->m_Team == TEAM_SPECTATORS)
|
|
|
|
continue;
|
|
|
|
|
2019-04-11 10:21:42 +00:00
|
|
|
NextDDTeam = m_pClient->m_Teams.Team(pInfo2->m_ClientID);
|
2014-03-23 23:04:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(OldDDTeam == -1)
|
2014-03-23 23:04:44 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int j = i - 1; j >= 0; j--)
|
2014-03-23 23:04:44 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
const CNetObj_PlayerInfo *pInfo2 = m_pClient->m_Snap.m_paInfoByDDTeamName[j];
|
2014-03-23 23:04:44 +00:00
|
|
|
|
|
|
|
if(!pInfo2 || pInfo2->m_Team == TEAM_SPECTATORS)
|
|
|
|
continue;
|
|
|
|
|
2019-04-11 10:21:42 +00:00
|
|
|
OldDDTeam = m_pClient->m_Teams.Team(pInfo2->m_ClientID);
|
2014-03-23 23:04:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(DDTeam != TEAM_FLOCK)
|
2014-03-23 23:04:44 +00:00
|
|
|
{
|
2012-08-12 10:41:50 +00:00
|
|
|
Graphics()->TextureClear();
|
2014-03-23 23:04:44 +00:00
|
|
|
Graphics()->QuadsBegin();
|
2019-04-26 22:11:15 +00:00
|
|
|
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f));
|
|
|
|
Graphics()->SetColor(rgb);
|
2014-03-23 23:04:44 +00:00
|
|
|
|
|
|
|
int Corners = 0;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(OldDDTeam != DDTeam)
|
2014-03-23 23:04:44 +00:00
|
|
|
Corners |= CUI::CORNER_TL | CUI::CORNER_TR;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(NextDDTeam != DDTeam)
|
2014-03-23 23:04:44 +00:00
|
|
|
Corners |= CUI::CORNER_BL | CUI::CORNER_BR;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->DrawRoundRectExt(Width / 2.0f + x - 10.0f, Height / 2.0f + y + BoxMove, 270.0f, LineHeight, RoundRadius, Corners);
|
2014-03-23 23:04:44 +00:00
|
|
|
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
OldDDTeam = DDTeam;
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID) || (Client()->State() != IClient::STATE_DEMOPLAYBACK && m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID))
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
2012-08-12 10:41:50 +00:00
|
|
|
Graphics()->TextureClear();
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->DrawRoundRect(Width / 2.0f + x - 10.0f, Height / 2.0f + y + BoxMove, 270.0f, LineHeight, RoundRadius);
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
Selected = false;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_SelectorMouse.x >= x - 10.0f && m_SelectorMouse.x < x + 260.0f &&
|
|
|
|
m_SelectorMouse.y >= y - (LineHeight / 6.0f) && m_SelectorMouse.y < y + (LineHeight * 5.0f / 6.0f))
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
2020-09-13 19:20:13 +00:00
|
|
|
m_SelectedSpectatorID = m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID;
|
2011-03-10 09:08:14 +00:00
|
|
|
Selected = true;
|
|
|
|
}
|
2015-07-26 16:52:53 +00:00
|
|
|
float TeeAlpha;
|
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK &&
|
2020-09-13 19:20:13 +00:00
|
|
|
!m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID].m_Active)
|
2015-07-26 16:52:53 +00:00
|
|
|
{
|
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 0.25f);
|
|
|
|
TeeAlpha = 0.5f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Selected ? 1.0f : 0.5f);
|
2015-07-26 16:52:53 +00:00
|
|
|
TeeAlpha = 1.0f;
|
|
|
|
}
|
2020-09-13 19:20:13 +00:00
|
|
|
TextRender()->Text(0, Width / 2.0f + x + 50.0f, Height / 2.0f + y + BoxMove + (LineHeight - FontSize) / 2.f, FontSize, m_pClient->m_aClients[m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID].m_aName, 220.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
|
2011-05-05 00:00:43 +00:00
|
|
|
// flag
|
2020-09-13 19:20:13 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS &&
|
|
|
|
m_pClient->m_Snap.m_pGameDataObj && (m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed == m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID || m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue == m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID))
|
2011-05-05 00:00:43 +00:00
|
|
|
{
|
|
|
|
Graphics()->BlendNormal();
|
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
RenderTools()->SelectSprite(m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue == m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID ? SPRITE_FLAG_BLUE : SPRITE_FLAG_RED, SPRITE_FLAG_FLIP_X);
|
2011-05-05 00:00:43 +00:00
|
|
|
|
|
|
|
float Size = LineHeight;
|
2020-09-26 19:41:58 +00:00
|
|
|
IGraphics::CQuadItem QuadItem(Width / 2.0f + x - LineHeight / 5.0f, Height / 2.0f + y - LineHeight / 3.0f, Size / 2.0f, Size);
|
2011-05-05 00:00:43 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
|
|
|
|
2020-09-13 19:20:13 +00:00
|
|
|
CTeeRenderInfo TeeInfo = m_pClient->m_aClients[m_pClient->m_Snap.m_paInfoByDDTeamName[i]->m_ClientID].m_RenderInfo;
|
2014-01-12 18:38:22 +00:00
|
|
|
TeeInfo.m_Size *= TeeSizeMod;
|
2020-09-26 19:41:58 +00:00
|
|
|
RenderTools()->RenderTee(CAnimState::GetIdle(), &TeeInfo, EMOTE_NORMAL, vec2(1.0f, 0.0f), vec2(Width / 2.0f + x + 20.0f, Height / 2.0f + y + 20.0f), TeeAlpha);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
y += LineHeight;
|
|
|
|
}
|
2011-03-18 17:03:50 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
|
|
|
|
// draw cursor
|
2020-09-15 14:18:12 +00:00
|
|
|
Graphics()->WrapClamp();
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CURSOR].m_Id);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2020-09-26 19:41:58 +00:00
|
|
|
IGraphics::CQuadItem QuadItem(m_SelectorMouse.x + Width / 2.0f, m_SelectorMouse.y + Height / 2.0f, 48.0f, 48.0f);
|
2011-03-10 09:08:14 +00:00
|
|
|
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
2020-09-15 14:18:12 +00:00
|
|
|
Graphics()->WrapNormal();
|
2011-03-10 09:08:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpectator::OnReset()
|
|
|
|
{
|
|
|
|
m_WasActive = false;
|
|
|
|
m_Active = false;
|
|
|
|
m_SelectedSpectatorID = NO_SELECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpectator::Spectate(int SpectatorID)
|
|
|
|
{
|
2011-03-12 17:07:57 +00:00
|
|
|
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
m_pClient->m_DemoSpecID = clamp(SpectatorID, (int)SPEC_FOLLOW, MAX_CLIENTS - 1);
|
2011-03-12 17:07:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SpectatorID)
|
2011-03-10 09:08:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
CNetMsg_Cl_SetSpectatorMode Msg;
|
|
|
|
Msg.m_SpectatorID = SpectatorID;
|
|
|
|
Client()->SendPackMsg(&Msg, MSGFLAG_VITAL);
|
|
|
|
}
|