Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ constexpr const char *BTNS_LOCALIZE[MMBTN__TOTAL] = {
"#GameUI_GameMenu_Quit",
};

static const char *BINDNAME_TO_ROOTBUTTONACTION_MAP[CNeoRoot::ROOTBUTTONACTION__TOTAL] = {
"", // ROOTBUTTONACTION_NIL (skip over in loop)
"neo_toggleconsole", // ROOTBUTTONACTION_TOGGLECONSOLE
"neo_mp3", // ROOTBUTTONACTION_MP3
};

CNeoRoot::CNeoRoot(VPANEL parent)
: EditablePanel(nullptr, "NeoRootPanel")
, m_panelCaptureInput(new CNeoRootInput(this))
Expand Down Expand Up @@ -632,12 +638,34 @@ void CNeoRoot::OnRelayedKeyCodeTyped(vgui::KeyCode code)
return;
}

// Refresh every time, because else if the user unbinds or rebinds the key, it will still incorrectly be mapped there.
// NEO FIXME (Rain): We do not currently support binding multiple buttons for the same command;
// if the user does: bind a foo; bind b foo; then only the latest bind will work.
m_ns.keys.bcConsole = gameuifuncs->GetButtonCodeForBind("neo_toggleconsole");
// NEO NOTE (nullsystem): There doesn't seem to be callbacks to check on updated
// keybinds and neither would ClientModeShared::KeyInput pick up neo_mp3,
// so timed and only on typed so it doesn't go checking on all buttons everytime
if (m_flHtBtnCodeUpdate <= gpGlobals->realtime)
{
m_htButtonCodeToAction.RemoveAll();
for (int iBc = KEY_FIRST; iBc <= BUTTON_CODE_LAST; ++iBc)
{
const ButtonCode_t bc = static_cast<ButtonCode_t>(iBc);
const char *pszBinding = gameuifuncs->GetBindingForButtonCode(bc);
// Only needed it for binds used for neo_root
if (pszBinding)
{
for (int i = (ROOTBUTTONACTION_NIL + 1); i < ROOTBUTTONACTION__TOTAL; ++i)
{
if (0 == V_strcmp(pszBinding, BINDNAME_TO_ROOTBUTTONACTION_MAP[i]))
{
m_htButtonCodeToAction.Insert(bc, static_cast<ERootButtonAction>(i));
break;
}
}
}
}
m_flHtBtnCodeUpdate = gpGlobals->realtime + 1.0f;
}

if (code == m_ns.keys.bcConsole && code != KEY_BACKQUOTE)
if (KEY_BACKQUOTE != code
&& ROOTBUTTONACTION_TOGGLECONSOLE == m_htButtonCodeToAction.Get(code, ROOTBUTTONACTION_NIL))
{
// NEO JANK (nullsystem): Prevent toggle being handled twice causing it to not really open.
// This can happen if using the default ` due to the engine enacting this all the time, however calling
Expand Down Expand Up @@ -1270,7 +1298,9 @@ void CNeoRoot::MainLoopRoot(const MainLoopParam param)
}

// Play/Pause button
if (NeoUI::Button(mps->bPlaying ? L"II" : L"\u25B6").bPressed)
if (NeoUI::Button(mps->bPlaying ? L"II" : L"\u25B6").bPressed
|| (NeoUI::MODE_KEYPRESSED == g_uiCtx.eMode
&& ROOTBUTTONACTION_MP3 == m_htButtonCodeToAction.Get(g_uiCtx.eCode, ROOTBUTTONACTION_NIL)))
{
mps->flagsPlayStateNext = (mps->bPlaying)
? NeoMP3::PLAYSTATE_FLAG_PAUSED : NeoMP3::PLAYSTATE_FLAG_PLAY;
Expand Down
12 changes: 12 additions & 0 deletions src/game/client/neo/ui/neo_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ class CNeoRoot : public vgui::EditablePanel, public CGameEventListener
float m_flAutoJoinLastAttempt = 0.0f;
CNeoServerPing m_serverPingAutoJoin = {};
CNeoServerPing m_serverPingEnter = {};

enum ERootButtonAction
{
ROOTBUTTONACTION_NIL = 0,
ROOTBUTTONACTION_TOGGLECONSOLE,
ROOTBUTTONACTION_MP3,

ROOTBUTTONACTION__TOTAL,
};

float m_flHtBtnCodeUpdate = 0.0f;
CUtlHashtable<int, ERootButtonAction> m_htButtonCodeToAction;
};

extern CNeoRoot *g_pNeoRoot;
47 changes: 32 additions & 15 deletions src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void NeoSettingsInit(NeoSettings *ns)
auto *conbind = &keys->vBinds[keys->iBindsSize++];
V_strcpy_safe(conbind->szBindingCmd, "neo_toggleconsole");
V_wcscpy_safe(conbind->wszDisplayText, L"Developer console bind");
conbind->bSkipSecondary = true;

while (bufAct.IsValid() && keys->iBindsSize < ARRAYSIZE(keys->vBinds))
{
Expand Down Expand Up @@ -222,6 +223,7 @@ void NeoSettingsInit(NeoSettings *ns)
V_strcpy_safe(bind->szBindingCmd, szBindingCmd);
V_wcscpy_safe(bind->wszDisplayText, wszDispText);
bind->bcDefault = BUTTON_CODE_NONE;
bind->bSkipSecondary = false;
}
}
AssertMsg(keys->iBindsSize < ARRAYSIZE(keys->vBinds), "Bump the size of the vBinds array");
Expand Down Expand Up @@ -490,15 +492,18 @@ void NeoSettingsRestore(NeoSettings *ns, const NeoSettings::Keys::Flags flagsKey
auto hdl = htAllBinds.Find(bind->szBindingCmd);
if (hdl != htAllBinds.InvalidHandle())
{
const auto &bcVal = htAllBinds.Element(hdl);
const int iMaxIdxBc = Min(bcVal.iSize, MAX_BCVAL);
for (int idxBc = 0; idxBc < iMaxIdxBc; ++idxBc)
if (false == bind->bSkipSecondary)
{
const ButtonCode_t bc = bcVal.list[idxBc];
if (bc != bind->bcCurrent)
const auto &bcVal = htAllBinds.Element(hdl);
const int iMaxIdxBc = Min(bcVal.iSize, MAX_BCVAL);
for (int idxBc = 0; idxBc < iMaxIdxBc; ++idxBc)
{
bind->bcSecondaryNext = bind->bcSecondaryCurrent = bc;
break;
const ButtonCode_t bc = bcVal.list[idxBc];
if (bc != bind->bcCurrent)
{
bind->bcSecondaryNext = bind->bcSecondaryCurrent = bc;
break;
}
}
}
}
Expand Down Expand Up @@ -727,6 +732,9 @@ void NeoSettingsRestore(NeoSettings *ns, const NeoSettings::Keys::Flags flagsKey
}
}

// NEO TODO (nullsystem): For now the settings UI only exposes consoles as a
// single keybind and this also deals with a single bind. Trying to enforce
// multiple neo_toggleconsole binds doesn't seem to work here?
void NeoToggleConsoleEnforce()
{
// NEO JANK (nullsystem): Try to unbind toggleconsole when possible
Expand Down Expand Up @@ -826,8 +834,6 @@ void NeoSettingsSave(const NeoSettings *ns)
bind->bcCurrent = bind->bcNext;
bind->bcSecondaryCurrent = bind->bcSecondaryNext;
}
// Reset the cache to none so it'll refresh on next KeyCodeTyped
const_cast<NeoSettings::Keys *>(pKeys)->bcConsole = KEY_NONE;
}
{
const NeoSettings::Mouse *pMouse = &ns->mouse;
Expand Down Expand Up @@ -1198,7 +1204,11 @@ void NeoSettings_Keys(NeoSettings *ns)
}
else
{
NeoUI::BeginMultiWidgetHighlighter(3);
if (bind.bSkipSecondary)
{
NeoUI::SetPerRowLayout(2, NeoUI::ROWLAYOUT_TWOSPLIT);
}
NeoUI::BeginMultiWidgetHighlighter(bind.bSkipSecondary ? 2 : 3);
NeoUI::Label(bind.wszDisplayText);
wchar_t wszBindBtnName[64];
const char *szBindBtnName = g_pInputSystem->ButtonCodeToString(bind.bcNext);
Expand All @@ -1208,14 +1218,21 @@ void NeoSettings_Keys(NeoSettings *ns)
ns->iNextBinding = i;
ns->bNextBindingSecondary = false;
}
const char *szBindSecondaryBtnName = g_pInputSystem->ButtonCodeToString(bind.bcSecondaryNext);
g_pVGuiLocalize->ConvertANSIToUnicode(szBindSecondaryBtnName, wszBindBtnName, sizeof(wszBindBtnName));
if (NeoUI::Button(wszBindBtnName).bPressed)
if (false == bind.bSkipSecondary)
{
ns->iNextBinding = i;
ns->bNextBindingSecondary = true;
const char *szBindSecondaryBtnName = g_pInputSystem->ButtonCodeToString(bind.bcSecondaryNext);
g_pVGuiLocalize->ConvertANSIToUnicode(szBindSecondaryBtnName, wszBindBtnName, sizeof(wszBindBtnName));
if (NeoUI::Button(wszBindBtnName).bPressed)
{
ns->iNextBinding = i;
ns->bNextBindingSecondary = true;
}
}
NeoUI::EndMultiWidgetHighlighter();
if (bind.bSkipSecondary)
{
NeoUI::SetPerRowLayout(ARRAYSIZE(KEYS_LAYOUT), KEYS_LAYOUT);
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/game/client/neo/ui/neo_root_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ struct NeoSettings
ButtonCode_t bcDefault;
ButtonCode_t bcSecondaryNext;
ButtonCode_t bcSecondaryCurrent;
bool bSkipSecondary = false;
};
Bind vBinds[NEO_BINDS_TOTAL];
int iBindsSize = 0;

// Will be checked often so cached
ButtonCode_t bcConsole;

enum Flags
{
NONE = 0,
Expand Down
4 changes: 3 additions & 1 deletion src/game/client/neo/ui/neo_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <filesystem.h>
#include <stb_image.h>
#include <materialsystem/imaterial.h>
#include <IGameUIFuncs.h>

#include "neo_misc.h"

Expand Down Expand Up @@ -2217,7 +2218,7 @@ void Progress(const float flValue, const float flMin, const float flMax)

void ProgressDrag(float *flValue, const float flMin, const float flMax)
{
const auto wdgState = BeginWidget(WIDGETFLAG_MOUSE | WIDGETFLAG_MARKACTIVE);
auto wdgState = BeginWidget(WIDGETFLAG_MOUSE | WIDGETFLAG_MARKACTIVE);
if (wdgState.bInView)
{
switch (c->eMode)
Expand All @@ -2239,6 +2240,7 @@ void ProgressDrag(float *flValue, const float flMin, const float flMax)
c->iActive = c->iWidget;
c->iActiveSection = c->iSection;
c->eMousePressedStart = MOUSESTART_SLIDER;
wdgState.bActive = true;
}
} [[fallthrough]];
case MODE_MOUSEMOVED:
Expand Down
Loading