mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Refactor spectator UI input handling
Use `IInput::KeyPress` instead of event callback for mouse presses. Remove subsequently unnecessary `m_Clicked` variable.
This commit is contained in:
parent
846775c6b7
commit
ed53b1c6dc
|
@ -232,24 +232,6 @@ void CSpectator::OnRender()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_SelectedSpectatorId != NO_SELECTION)
|
|
||||||
{
|
|
||||||
// clicking a component
|
|
||||||
if(m_Clicked)
|
|
||||||
{
|
|
||||||
if(!GameClient()->m_MultiViewActivated)
|
|
||||||
Spectate(m_SelectedSpectatorId);
|
|
||||||
|
|
||||||
if(m_SelectedSpectatorId == MULTI_VIEW)
|
|
||||||
GameClient()->m_MultiViewActivated = true;
|
|
||||||
else if(m_SelectedSpectatorId == SPEC_FREEVIEW || m_SelectedSpectatorId == SPEC_FOLLOW)
|
|
||||||
GameClient()->m_MultiViewActivated = false;
|
|
||||||
|
|
||||||
if(!GameClient()->m_MultiViewActivated && m_SelectedSpectatorId >= 0 && m_SelectedSpectatorId < MAX_CLIENTS)
|
|
||||||
m_Clicked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!m_pClient->m_Snap.m_SpecInfo.m_Active && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
if(!m_pClient->m_Snap.m_SpecInfo.m_Active && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
||||||
{
|
{
|
||||||
m_Active = false;
|
m_Active = false;
|
||||||
|
@ -276,6 +258,8 @@ void CSpectator::OnRender()
|
||||||
float BoxMove = -10.0f;
|
float BoxMove = -10.0f;
|
||||||
float BoxOffset = 0.0f;
|
float BoxOffset = 0.0f;
|
||||||
|
|
||||||
|
const bool MousePressed = Input()->KeyPress(KEY_MOUSE_1);
|
||||||
|
|
||||||
for(const auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName)
|
for(const auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName)
|
||||||
{
|
{
|
||||||
if(!pInfo || pInfo->m_Team == TEAM_SPECTATORS)
|
if(!pInfo || pInfo->m_Team == TEAM_SPECTATORS)
|
||||||
|
@ -330,6 +314,11 @@ void CSpectator::OnRender()
|
||||||
{
|
{
|
||||||
m_SelectedSpectatorId = SPEC_FREEVIEW;
|
m_SelectedSpectatorId = SPEC_FREEVIEW;
|
||||||
FreeViewSelected = true;
|
FreeViewSelected = true;
|
||||||
|
if(MousePressed)
|
||||||
|
{
|
||||||
|
GameClient()->m_MultiViewActivated = false;
|
||||||
|
Spectate(m_SelectedSpectatorId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, FreeViewSelected ? 1.0f : 0.5f);
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, FreeViewSelected ? 1.0f : 0.5f);
|
||||||
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f), Height / 2.0f - 280.f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Free-View"), -1.0f);
|
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f), Height / 2.0f - 280.f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Free-View"), -1.0f);
|
||||||
|
@ -339,6 +328,10 @@ void CSpectator::OnRender()
|
||||||
{
|
{
|
||||||
m_SelectedSpectatorId = MULTI_VIEW;
|
m_SelectedSpectatorId = MULTI_VIEW;
|
||||||
MultiViewSelected = true;
|
MultiViewSelected = true;
|
||||||
|
if(MousePressed)
|
||||||
|
{
|
||||||
|
GameClient()->m_MultiViewActivated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, MultiViewSelected ? 1.0f : 0.5f);
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, MultiViewSelected ? 1.0f : 0.5f);
|
||||||
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f) + (ObjWidth * 2.0f / 3.0f), Height / 2.0f - 280.f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Multi-View"), -1.0f);
|
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f) + (ObjWidth * 2.0f / 3.0f), Height / 2.0f - 280.f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Multi-View"), -1.0f);
|
||||||
|
@ -351,6 +344,11 @@ void CSpectator::OnRender()
|
||||||
{
|
{
|
||||||
m_SelectedSpectatorId = SPEC_FOLLOW;
|
m_SelectedSpectatorId = SPEC_FOLLOW;
|
||||||
FollowSelected = true;
|
FollowSelected = true;
|
||||||
|
if(MousePressed)
|
||||||
|
{
|
||||||
|
GameClient()->m_MultiViewActivated = false;
|
||||||
|
Spectate(m_SelectedSpectatorId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, FollowSelected ? 1.0f : 0.5f);
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, FollowSelected ? 1.0f : 0.5f);
|
||||||
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f) + (ObjWidth * 2.0f * 2.0f / 3.0f), Height / 2.0f - 280.0f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Follow"), -1.0f);
|
TextRender()->Text(Width / 2.0f - (ObjWidth - 40.0f) + (ObjWidth * 2.0f * 2.0f / 3.0f), Height / 2.0f - 280.0f + (60.f - BigFontSize) / 2.f, BigFontSize, Localize("Follow"), -1.0f);
|
||||||
|
@ -426,7 +424,9 @@ void CSpectator::OnRender()
|
||||||
{
|
{
|
||||||
m_SelectedSpectatorId = m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientId;
|
m_SelectedSpectatorId = m_pClient->m_Snap.m_apInfoByDDTeamName[i]->m_ClientId;
|
||||||
PlayerSelected = true;
|
PlayerSelected = true;
|
||||||
if(GameClient()->m_MultiViewActivated && m_Clicked)
|
if(MousePressed)
|
||||||
|
{
|
||||||
|
if(GameClient()->m_MultiViewActivated)
|
||||||
{
|
{
|
||||||
if(GameClient()->m_MultiViewTeam == DDTeam)
|
if(GameClient()->m_MultiViewTeam == DDTeam)
|
||||||
{
|
{
|
||||||
|
@ -448,7 +448,11 @@ void CSpectator::OnRender()
|
||||||
Spectate(m_SelectedSpectatorId);
|
Spectate(m_SelectedSpectatorId);
|
||||||
m_MultiViewActivateDelay = Client()->LocalTime() + 0.3f;
|
m_MultiViewActivateDelay = Client()->LocalTime() + 0.3f;
|
||||||
}
|
}
|
||||||
m_Clicked = false;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Spectate(m_SelectedSpectatorId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float TeeAlpha;
|
float TeeAlpha;
|
||||||
|
@ -553,18 +557,3 @@ void CSpectator::SpectateClosest()
|
||||||
{
|
{
|
||||||
ConSpectateClosest(NULL, this);
|
ConSpectateClosest(NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSpectator::OnInput(const IInput::CEvent &Event)
|
|
||||||
{
|
|
||||||
if(m_Active && Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_MOUSE_1)
|
|
||||||
{
|
|
||||||
m_Clicked = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(Event.m_Flags & IInput::FLAG_RELEASE && Event.m_Key == KEY_MOUSE_1)
|
|
||||||
{
|
|
||||||
m_Clicked = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class CSpectator : public CComponent
|
||||||
|
|
||||||
bool m_Active;
|
bool m_Active;
|
||||||
bool m_WasActive;
|
bool m_WasActive;
|
||||||
bool m_Clicked;
|
|
||||||
|
|
||||||
int m_SelectedSpectatorId;
|
int m_SelectedSpectatorId;
|
||||||
vec2 m_SelectorMouse;
|
vec2 m_SelectorMouse;
|
||||||
|
@ -43,7 +42,6 @@ public:
|
||||||
virtual void OnRender() override;
|
virtual void OnRender() override;
|
||||||
virtual void OnRelease() override;
|
virtual void OnRelease() override;
|
||||||
virtual void OnReset() override;
|
virtual void OnReset() override;
|
||||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
|
||||||
|
|
||||||
void Spectate(int SpectatorId);
|
void Spectate(int SpectatorId);
|
||||||
void SpectateClosest();
|
void SpectateClosest();
|
||||||
|
|
Loading…
Reference in a new issue