Skip to content

Commit

Permalink
Client: Options: HUD: Disable unsupported scales
Browse files Browse the repository at this point in the history
  • Loading branch information
tmp64 committed Dec 4, 2023
1 parent cd89607 commit 1e49f55
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/game/client/gameui/options/cvar_combo_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/game/client/gameui/options/cvar_combo_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions src/game/client/gameui/options/options_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/game/client/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1e49f55

Please sign in to comment.