Skip to content

Commit

Permalink
Let some scrollbars have out of range values
Browse files Browse the repository at this point in the history
This is necessary because options like mouse sensivity get replaced with their scrollbar max value every time you open their settings page.
  • Loading branch information
CherryEx committed Jul 16, 2024
1 parent 76acb6f commit 438541b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/game/client/components/menus_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ float CMenus::RenderSettingsControlsMouse(CUIRect View)

View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UI()->DoScrollbarOption(&Config()->m_InpMousesens, &Config()->m_InpMousesens, &Button, Localize("In-game mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale);
UI()->DoScrollbarOption(&Config()->m_InpMousesens, &Config()->m_InpMousesens, &Button, Localize("In-game mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_NO_STRICT_RANGE);

View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UI()->DoScrollbarOption(&Config()->m_UiMousesens, &Config()->m_UiMousesens, &Button, Localize("Menu mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale);
UI()->DoScrollbarOption(&Config()->m_UiMousesens, &Config()->m_UiMousesens, &Button, Localize("Menu mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_NO_STRICT_RANGE);

return BackgroundHeight;
}
Expand Down Expand Up @@ -217,12 +217,12 @@ float CMenus::RenderSettingsControlsJoystick(CUIRect View)
{
View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UI()->DoScrollbarOption(&Config()->m_JoystickSens, &Config()->m_JoystickSens, &Button, Localize("In-game joystick sensitivity"), 1, 500, &CUI::ms_LogarithmicScrollbarScale);
UI()->DoScrollbarOption(&Config()->m_JoystickSens, &Config()->m_JoystickSens, &Button, Localize("In-game joystick sensitivity"), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_NO_STRICT_RANGE);
}

View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
UI()->DoScrollbarOption(&Config()->m_UiJoystickSens, &Config()->m_UiJoystickSens, &Button, Localize("Menu/Editor joystick sensitivity"), 1, 500, &CUI::ms_LogarithmicScrollbarScale);
UI()->DoScrollbarOption(&Config()->m_UiJoystickSens, &Config()->m_UiJoystickSens, &Button, Localize("Menu/Editor joystick sensitivity"), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_NO_STRICT_RANGE);

View.HSplitTop(Spacing, 0, &View);
View.HSplitTop(ButtonHeight, &Button, &View);
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/menus_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView)
Config()->m_ClAutoDemoRecord ^= 1;

if(Config()->m_ClAutoDemoRecord)
UI()->DoScrollbarOption(&Config()->m_ClAutoDemoMax, &Config()->m_ClAutoDemoMax, &ClientRight, Localize("Max"), 0, 1000, &CUI::ms_LogarithmicScrollbarScale, true);
UI()->DoScrollbarOption(&Config()->m_ClAutoDemoMax, &Config()->m_ClAutoDemoMax, &ClientRight, Localize("Max"), 0, 1000, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_INFINITE);

Client.HSplitTop(Spacing, 0, &Client);
Client.HSplitTop(ButtonHeight, &ClientLeft, &Client);
Expand All @@ -986,7 +986,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView)
Config()->m_ClAutoScreenshot ^= 1;

if(Config()->m_ClAutoScreenshot)
UI()->DoScrollbarOption(&Config()->m_ClAutoScreenshotMax, &Config()->m_ClAutoScreenshotMax, &ClientRight, Localize("Max"), 0, 1000, &CUI::ms_LogarithmicScrollbarScale, true);
UI()->DoScrollbarOption(&Config()->m_ClAutoScreenshotMax, &Config()->m_ClAutoScreenshotMax, &ClientRight, Localize("Max"), 0, 1000, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_INFINITE);

MainView.HSplitTop(10.0f, 0, &MainView);

Expand Down
8 changes: 7 additions & 1 deletion src/game/client/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,10 @@ float CUI::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
return ReturnValue;
}

void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale, bool Infinite)
void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale, unsigned char Options)
{
const bool Infinite = Options & CUI::SCROLLBAR_INFINITE;
const bool NoRangeEnforcement = Options & CUI::SCROLLBAR_NO_STRICT_RANGE;
int Value = *pOption;
if(Infinite)
{
Expand Down Expand Up @@ -736,6 +738,10 @@ void CUI::DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect,

ScrollBar.VMargin(4.0f, &ScrollBar);
Value = pScale->ToAbsolute(DoScrollbarH(pID, &ScrollBar, pScale->ToRelative(Value, Min, Max)), Min, Max);
if (NoRangeEnforcement && ((Value == Min && *pOption < Min) || (Value == Max && *pOption > Max)))
{
Value = *pOption;
}
if(Infinite && Value == Max)
Value = 0;

Expand Down
8 changes: 7 additions & 1 deletion src/game/client/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,15 @@ class CUI
// scrollbars
float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current);
float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current);
void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, bool Infinite = false);
void DoScrollbarOption(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, const IScrollbarScale *pScale = &ms_LinearScrollbarScale, unsigned char Options = 0);
void DoScrollbarOptionLabeled(const void *pID, int *pOption, const CUIRect *pRect, const char *pStr, const char *apLabels[], int NumLabels, const IScrollbarScale *pScale = &ms_LinearScrollbarScale);

enum
{
SCROLLBAR_INFINITE = 1 << 0,
SCROLLBAR_NO_STRICT_RANGE = 1 << 1,
};

// tooltips
void DoTooltip(const void *pID, const CUIRect *pRect, const char *pText);
void RenderTooltip();
Expand Down

0 comments on commit 438541b

Please sign in to comment.