mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-19 17:14:18 +00:00
Compare commits
5 commits
0f12044fcd
...
20cb02048d
Author | SHA1 | Date | |
---|---|---|---|
20cb02048d | |||
a5138c078e | |||
0d93b1add7 | |||
9963a3e3db | |||
d5be8d1633 |
|
@ -5,6 +5,8 @@
|
||||||
#include <engine/config.h>
|
#include <engine/config.h>
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
|
#include <game/client/components/chat.h>
|
||||||
|
#include <game/client/components/console.h>
|
||||||
#include <game/client/gameclient.h>
|
#include <game/client/gameclient.h>
|
||||||
|
|
||||||
static const ColorRGBA gs_BindPrintColor{1.0f, 1.0f, 0.8f, 1.0f};
|
static const ColorRGBA gs_BindPrintColor{1.0f, 1.0f, 0.8f, 1.0f};
|
||||||
|
@ -126,7 +128,7 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
|
||||||
});
|
});
|
||||||
if(ActiveBind == m_vActiveBinds.end())
|
if(ActiveBind == m_vActiveBinds.end())
|
||||||
{
|
{
|
||||||
const auto &&OnPress = [&](int Mask) {
|
const auto &&OnKeyPress = [&](int Mask) {
|
||||||
const char *pBind = m_aapKeyBindings[Mask][Event.m_Key];
|
const char *pBind = m_aapKeyBindings[Mask][Event.m_Key];
|
||||||
if(g_Config.m_ClSubTickAiming)
|
if(g_Config.m_ClSubTickAiming)
|
||||||
{
|
{
|
||||||
|
@ -141,14 +143,14 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
|
||||||
|
|
||||||
if(m_aapKeyBindings[ModifierMask][Event.m_Key])
|
if(m_aapKeyBindings[ModifierMask][Event.m_Key])
|
||||||
{
|
{
|
||||||
OnPress(ModifierMask);
|
OnKeyPress(ModifierMask);
|
||||||
Handled = true;
|
Handled = true;
|
||||||
}
|
}
|
||||||
else if(m_aapKeyBindings[MODIFIER_NONE][Event.m_Key] &&
|
else if(m_aapKeyBindings[MODIFIER_NONE][Event.m_Key] &&
|
||||||
ModifierMask != ((1 << MODIFIER_CTRL) | (1 << MODIFIER_SHIFT)) &&
|
ModifierMask != ((1 << MODIFIER_CTRL) | (1 << MODIFIER_SHIFT)) &&
|
||||||
ModifierMask != ((1 << MODIFIER_GUI) | (1 << MODIFIER_SHIFT)))
|
ModifierMask != ((1 << MODIFIER_GUI) | (1 << MODIFIER_SHIFT)))
|
||||||
{
|
{
|
||||||
OnPress(MODIFIER_NONE);
|
OnKeyPress(MODIFIER_NONE);
|
||||||
Handled = true;
|
Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,17 +168,30 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
|
||||||
|
|
||||||
if(Event.m_Flags & IInput::FLAG_RELEASE)
|
if(Event.m_Flags & IInput::FLAG_RELEASE)
|
||||||
{
|
{
|
||||||
|
const auto &&OnKeyRelease = [&](const CBindSlot &Bind) {
|
||||||
|
// Prevent binds from being deactivated while chat, console and menus are open, as these components will
|
||||||
|
// still allow key release events to be forwarded to this component, so the active binds can be cleared.
|
||||||
|
if(GameClient()->m_Chat.IsActive() ||
|
||||||
|
!GameClient()->m_GameConsole.IsClosed() ||
|
||||||
|
GameClient()->m_Menus.IsActive())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Have to check for nullptr again because the previous execute can unbind itself
|
||||||
|
if(!m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Console()->ExecuteLineStroked(0, m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key]);
|
||||||
|
};
|
||||||
|
|
||||||
// Release active bind that uses this primary key
|
// Release active bind that uses this primary key
|
||||||
auto ActiveBind = std::find_if(m_vActiveBinds.begin(), m_vActiveBinds.end(), [&](const CBindSlot &Bind) {
|
auto ActiveBind = std::find_if(m_vActiveBinds.begin(), m_vActiveBinds.end(), [&](const CBindSlot &Bind) {
|
||||||
return Event.m_Key == Bind.m_Key;
|
return Event.m_Key == Bind.m_Key;
|
||||||
});
|
});
|
||||||
if(ActiveBind != m_vActiveBinds.end())
|
if(ActiveBind != m_vActiveBinds.end())
|
||||||
{
|
{
|
||||||
// Have to check for nullptr again because the previous execute can unbind itself
|
OnKeyRelease(*ActiveBind);
|
||||||
if(m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key])
|
|
||||||
{
|
|
||||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key]);
|
|
||||||
}
|
|
||||||
m_vActiveBinds.erase(ActiveBind);
|
m_vActiveBinds.erase(ActiveBind);
|
||||||
Handled = true;
|
Handled = true;
|
||||||
}
|
}
|
||||||
|
@ -191,11 +206,7 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
|
||||||
});
|
});
|
||||||
if(ActiveModifierBind == m_vActiveBinds.end())
|
if(ActiveModifierBind == m_vActiveBinds.end())
|
||||||
break;
|
break;
|
||||||
// Have to check for nullptr again because the previous execute can unbind itself
|
OnKeyRelease(*ActiveModifierBind);
|
||||||
if(m_aapKeyBindings[ActiveModifierBind->m_ModifierMask][ActiveModifierBind->m_Key])
|
|
||||||
{
|
|
||||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[ActiveModifierBind->m_ModifierMask][ActiveModifierBind->m_Key]);
|
|
||||||
}
|
|
||||||
m_vActiveBinds.erase(ActiveModifierBind);
|
m_vActiveBinds.erase(ActiveModifierBind);
|
||||||
Handled = true;
|
Handled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,8 @@ void CHud::OnReset()
|
||||||
m_ServerRecord = -1.0f;
|
m_ServerRecord = -1.0f;
|
||||||
m_aPlayerRecord[0] = -1.0f;
|
m_aPlayerRecord[0] = -1.0f;
|
||||||
m_aPlayerRecord[1] = -1.0f;
|
m_aPlayerRecord[1] = -1.0f;
|
||||||
|
m_aLastPlayerSpeedChange[0] = ESpeedChange::NONE;
|
||||||
|
m_aLastPlayerSpeedChange[1] = ESpeedChange::NONE;
|
||||||
|
|
||||||
ResetHudContainers();
|
ResetHudContainers();
|
||||||
}
|
}
|
||||||
|
@ -1275,11 +1277,11 @@ void CHud::UpdateMovementInformationTextContainer(STextContainerIndex &TextConta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHud::RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, float X, float Y)
|
void CHud::RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, const ColorRGBA &Color, float X, float Y)
|
||||||
{
|
{
|
||||||
if(TextContainer.Valid())
|
if(TextContainer.Valid())
|
||||||
{
|
{
|
||||||
TextRender()->RenderTextContainer(TextContainer, TextRender()->DefaultTextColor(), TextRender()->DefaultTextOutlineColor(), X - TextRender()->GetBoundingBoxTextContainer(TextContainer).m_W, Y);
|
TextRender()->RenderTextContainer(TextContainer, Color, TextRender()->DefaultTextOutlineColor(), X - TextRender()->GetBoundingBoxTextContainer(TextContainer).m_W, Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1352,12 +1354,12 @@ void CHud::RenderMovementInformation(const int ClientId)
|
||||||
|
|
||||||
TextRender()->Text(xl, y, Fontsize, "X:", -1.0f);
|
TextRender()->Text(xl, y, Fontsize, "X:", -1.0f);
|
||||||
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[0], Fontsize, Pos.x, m_aaPlayerPositionText[0], sizeof(m_aaPlayerPositionText[0]));
|
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[0], Fontsize, Pos.x, m_aaPlayerPositionText[0], sizeof(m_aaPlayerPositionText[0]));
|
||||||
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[0], xr, y);
|
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[0], TextRender()->DefaultTextColor(), xr, y);
|
||||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||||
|
|
||||||
TextRender()->Text(xl, y, Fontsize, "Y:", -1.0f);
|
TextRender()->Text(xl, y, Fontsize, "Y:", -1.0f);
|
||||||
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[1], Fontsize, Pos.y, m_aaPlayerPositionText[1], sizeof(m_aaPlayerPositionText[1]));
|
UpdateMovementInformationTextContainer(m_aPlayerPositionContainers[1], Fontsize, Pos.y, m_aaPlayerPositionText[1], sizeof(m_aaPlayerPositionText[1]));
|
||||||
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[1], xr, y);
|
RenderMovementInformationTextContainer(m_aPlayerPositionContainers[1], TextRender()->DefaultTextColor(), xr, y);
|
||||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,14 +1371,14 @@ void CHud::RenderMovementInformation(const int ClientId)
|
||||||
const char aaCoordinates[][4] = {"X:", "Y:"};
|
const char aaCoordinates[][4] = {"X:", "Y:"};
|
||||||
for(int i = 0; i < 2; i++)
|
for(int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
TextRender()->TextColor(ColorRGBA(1, 1, 1, 1));
|
ColorRGBA Color(1, 1, 1, 1);
|
||||||
if(m_aLastPlayerSpeedChange[i] == ESpeedChange::INCREASE)
|
if(m_aLastPlayerSpeedChange[i] == ESpeedChange::INCREASE)
|
||||||
TextRender()->TextColor(ColorRGBA(0, 1, 0, 1));
|
Color = ColorRGBA(0, 1, 0, 1);
|
||||||
if(m_aLastPlayerSpeedChange[i] == ESpeedChange::DECREASE)
|
if(m_aLastPlayerSpeedChange[i] == ESpeedChange::DECREASE)
|
||||||
TextRender()->TextColor(ColorRGBA(1, 0.5f, 0.5f, 1));
|
Color = ColorRGBA(1, 0.5f, 0.5f, 1);
|
||||||
TextRender()->Text(xl, y, Fontsize, aaCoordinates[i], -1.0f);
|
TextRender()->Text(xl, y, Fontsize, aaCoordinates[i], -1.0f);
|
||||||
UpdateMovementInformationTextContainer(m_aPlayerSpeedTextContainers[i], Fontsize, i == 0 ? DisplaySpeedX : DisplaySpeedY, m_aaPlayerSpeedText[i], sizeof(m_aaPlayerSpeedText[i]));
|
UpdateMovementInformationTextContainer(m_aPlayerSpeedTextContainers[i], Fontsize, i == 0 ? DisplaySpeedX : DisplaySpeedY, m_aaPlayerSpeedText[i], sizeof(m_aaPlayerSpeedText[i]));
|
||||||
RenderMovementInformationTextContainer(m_aPlayerSpeedTextContainers[i], xr, y);
|
RenderMovementInformationTextContainer(m_aPlayerSpeedTextContainers[i], Color, xr, y);
|
||||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,7 +1391,7 @@ void CHud::RenderMovementInformation(const int ClientId)
|
||||||
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
y += MOVEMENT_INFORMATION_LINE_HEIGHT;
|
||||||
|
|
||||||
UpdateMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, Fontsize, DisplayAngle, m_aPlayerAngleText, sizeof(m_aPlayerAngleText));
|
UpdateMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, Fontsize, DisplayAngle, m_aPlayerAngleText, sizeof(m_aPlayerAngleText));
|
||||||
RenderMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, xr, y);
|
RenderMovementInformationTextContainer(m_PlayerAngleTextContainerIndex, TextRender()->DefaultTextColor(), xr, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class CHud : public CComponent
|
||||||
void RenderMovementInformation(const int ClientId);
|
void RenderMovementInformation(const int ClientId);
|
||||||
|
|
||||||
void UpdateMovementInformationTextContainer(STextContainerIndex &TextContainer, float FontSize, float Value, char *pPrevValue, size_t Size);
|
void UpdateMovementInformationTextContainer(STextContainerIndex &TextContainer, float FontSize, float Value, char *pPrevValue, size_t Size);
|
||||||
void RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, float X, float Y);
|
void RenderMovementInformationTextContainer(STextContainerIndex &TextContainer, const ColorRGBA &Color, float X, float Y);
|
||||||
|
|
||||||
void RenderGameTimer();
|
void RenderGameTimer();
|
||||||
void RenderPauseNotification();
|
void RenderPauseNotification();
|
||||||
|
|
|
@ -447,7 +447,9 @@ void CGameClient::OnUpdate()
|
||||||
Input()->ConsumeEvents([&](const IInput::CEvent &Event) {
|
Input()->ConsumeEvents([&](const IInput::CEvent &Event) {
|
||||||
for(auto &pComponent : m_vpInput)
|
for(auto &pComponent : m_vpInput)
|
||||||
{
|
{
|
||||||
if(pComponent->OnInput(Event))
|
// Events with flag `FLAG_RELEASE` must always be forwarded to all components so keys being
|
||||||
|
// released can be handled in all components also after some components have been disabled.
|
||||||
|
if(pComponent->OnInput(Event) && (Event.m_Flags & ~IInput::FLAG_RELEASE) != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -8667,7 +8667,9 @@ void CEditor::OnUpdate()
|
||||||
Input()->ConsumeEvents([&](const IInput::CEvent &Event) {
|
Input()->ConsumeEvents([&](const IInput::CEvent &Event) {
|
||||||
for(CEditorComponent &Component : m_vComponents)
|
for(CEditorComponent &Component : m_vComponents)
|
||||||
{
|
{
|
||||||
if(Component.OnInput(Event))
|
// Events with flag `FLAG_RELEASE` must always be forwarded to all components so keys being
|
||||||
|
// released can be handled in all components also after some components have been disabled.
|
||||||
|
if(Component.OnInput(Event) && (Event.m_Flags & ~IInput::FLAG_RELEASE) != 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Ui()->OnInput(Event);
|
Ui()->OnInput(Event);
|
||||||
|
|
Loading…
Reference in a new issue