Skip to content

Commit

Permalink
Client: CCvarCheckButton: Only apply if was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tmp64 committed Dec 3, 2023
1 parent 050da46 commit f4deeab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/game/client/gameui/options/cvar_check_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ void CCvarCheckButton::ResetData()
bool val = !!m_pCvar->value;
if (m_bInverse)
val = !val;
BaseClass::SetSelected(val);

SetSelected(val);
m_bPendingChange = false;
}
}

void CCvarCheckButton::ApplyChanges()
{
if (m_pCvar)
if (m_pCvar && m_bPendingChange)
{
char buf[256];
bool val = IsSelected();
Expand All @@ -36,5 +38,14 @@ void CCvarCheckButton::ApplyChanges()

snprintf(buf, sizeof(buf), "%s \"%s\"", m_pCvar->name, (val ? "1" : "0"));
gEngfuncs.pfnClientCmd(buf);
m_bPendingChange = false;
}
}

void CCvarCheckButton::SetSelected(bool state)
{
BaseClass::SetSelected(state);

if (IsCheckButtonCheckable())
m_bPendingChange = true;
}
4 changes: 4 additions & 0 deletions src/game/client/gameui/options/cvar_check_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ class CCvarCheckButton : public vgui2::CheckButton
void ResetData();
void ApplyChanges();

// vgui2::CheckButton
virtual void SetSelected(bool state) override;

private:
cvar_t *m_pCvar = nullptr;
bool m_bInverse = false;
bool m_bPendingChange = false;
};

#endif

0 comments on commit f4deeab

Please sign in to comment.