From 1e49f553609532328368aa84ca7c50af7a75bd82 Mon Sep 17 00:00:00 2001 From: tmp64 Date: Mon, 4 Dec 2023 18:50:35 +0700 Subject: [PATCH] Client: Options: HUD: Disable unsupported scales --- .../client/gameui/options/cvar_combo_box.cpp | 8 +++++--- src/game/client/gameui/options/cvar_combo_box.h | 3 ++- src/game/client/gameui/options/options_hud.cpp | 16 ++++++++++++---- src/game/client/hud.cpp | 8 ++++---- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/game/client/gameui/options/cvar_combo_box.cpp b/src/game/client/gameui/options/cvar_combo_box.cpp index 43bc20ff..5cfad657 100644 --- a/src/game/client/gameui/options/cvar_combo_box.cpp +++ b/src/game/client/gameui/options/cvar_combo_box.cpp @@ -12,10 +12,11 @@ CCVarComboBox::CCVarComboBox(vgui2::Panel *parent, const char *panelName, const } } -void CCVarComboBox::AddItem(const char *itemText, const char *cvarValue) +int CCVarComboBox::AddItem(const char *itemText, const char *cvarValue) { - BaseClass::AddItem(itemText, new KeyValues("Item", "value", cvarValue)); + int id = BaseClass::AddItem(itemText, new KeyValues("Item", "value", cvarValue)); SetNumberOfEditLines(GetMenu()->GetItemCount()); + return id; } void CCVarComboBox::ResetData() @@ -28,9 +29,10 @@ void CCVarComboBox::ResetData() for (int i = 0; i < itemCount; i++) { + // Null for disabled items KeyValues *pUserData = pMenu->GetItemUserData(i); - if (!strcmp(pUserData->GetString("value"), m_pCvar->string)) + if (pUserData && !strcmp(pUserData->GetString("value"), m_pCvar->string)) { // Found it ActivateItem(i); diff --git a/src/game/client/gameui/options/cvar_combo_box.h b/src/game/client/gameui/options/cvar_combo_box.h index 99fa000c..9999a0ec 100644 --- a/src/game/client/gameui/options/cvar_combo_box.h +++ b/src/game/client/gameui/options/cvar_combo_box.h @@ -13,7 +13,8 @@ class CCVarComboBox : public vgui2::ComboBox //! Adds an item to the combo box. //! @param itemText Disaply text. Can be localized. //! @param cvarValue CVar value. - void AddItem(const char *itemText, const char *cvarValue); + //! @returns Item ID. + int AddItem(const char *itemText, const char *cvarValue); void ResetData(); void ApplyChanges(); diff --git a/src/game/client/gameui/options/options_hud.cpp b/src/game/client/gameui/options/options_hud.cpp index 0cec1ad0..c5e94c47 100644 --- a/src/game/client/gameui/options/options_hud.cpp +++ b/src/game/client/gameui/options/options_hud.cpp @@ -46,10 +46,18 @@ CHudSubOptions::CHudSubOptions(vgui2::Panel *parent) m_pScaleBox = new CCVarComboBox(this, "ScaleBox", "hud_scale"); m_pScaleBox->AddItem("#BHL_AdvOptions_Hud_ScaleAuto", "0"); - m_pScaleBox->AddItem("50%", "1"); - m_pScaleBox->AddItem("100%", "2"); - m_pScaleBox->AddItem("200%", "3"); - m_pScaleBox->AddItem("400%", "5"); + + constexpr const char *SCALES[] = { "50%", "100%", "200%", "400%" }; + + for (int i = 1; i <= std::size(SCALES); i++) + { + char buf[16]; + snprintf(buf, sizeof(buf), "%d", i); + int itemId = m_pScaleBox->AddItem(SCALES[i - 1], buf); + + bool isSupported = i <= (int)gHUD.GetMaxHudScale(); + m_pScaleBox->SetItemEnabled(itemId, isSupported); + } LoadControlSettings(VGUI2_ROOT_DIR "resource/options/HudSubOptions.res"); m_pOpacityLabel->MoveToFront(); // Obscured by the slider diff --git a/src/game/client/hud.cpp b/src/game/client/hud.cpp index 73f21736..ef9806c5 100644 --- a/src/game/client/hud.cpp +++ b/src/game/client/hud.cpp @@ -113,10 +113,10 @@ struct HudScaleInfo //! The list of allowed HUD sizes. static constexpr HudScaleInfo HUD_SCALE_INFO[] = { - HudScaleInfo { 320, 240, EHudScale ::X05, "sprites/320hud1.spr" }, - HudScaleInfo { 640, 480, EHudScale ::X1, "sprites/640hud1.spr" }, - HudScaleInfo { 1280, 960, EHudScale ::X2, "sprites/1280/hud_bucket0.spr" }, - HudScaleInfo { 2560, 1920, EHudScale ::X4, "sprites/2560/hud_bucket0.spr" }, + HudScaleInfo { 320, 240, EHudScale::X05, "sprites/320hud1.spr" }, + HudScaleInfo { 640, 480, EHudScale::X1, "sprites/640hud1.spr" }, + HudScaleInfo { 1280, 960, EHudScale::X2, "sprites/1280/hud_bucket0.spr" }, + HudScaleInfo { 2560, 1920, EHudScale::X4, "sprites/2560/hud_bucket0.spr" }, }; extern cvar_t *cl_lw;