Add grayed-out support to sliders

This commit is contained in:
nashmuhandes 2020-09-30 22:12:44 +08:00 committed by Christoph Oelckers
parent e2e176e0be
commit f467e4bc33

View file

@ -699,8 +699,9 @@ class OptionMenuSliderBase : OptionMenuItem
int mShowValue;
int mDrawX;
int mSliderShort;
CVar mGrayCheck;
protected void Init(String label, double min, double max, double step, int showval, Name command = 'none')
protected void Init(String label, double min, double max, double step, int showval, Name command = 'none', CVar graycheck = NULL)
{
Super.Init(label, command);
mMin = min;
@ -709,6 +710,7 @@ class OptionMenuSliderBase : OptionMenuItem
mShowValue = showval;
mDrawX = 0;
mSliderShort = 0;
mGrayCheck = graycheck;
}
virtual double GetSliderValue()
@ -720,18 +722,29 @@ class OptionMenuSliderBase : OptionMenuItem
{
}
bool IsGrayed(void)
{
return mGrayCheck != NULL && !mGrayCheck.GetInt();
}
override bool Selectable(void)
{
return !IsGrayed();
}
//=============================================================================
//
// Draw a slider. Set fracdigits negative to not display the current value numerically.
//
//=============================================================================
private void DrawSliderElement (int color, int x, int y, String str)
private void DrawSliderElement (int color, int x, int y, String str, bool grayed = false)
{
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 16 * CleanXfac_1, DTA_CellY, 16 * CleanYfac_1);
int overlay = grayed? Color(96, 48, 0, 0) : 0;
screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 16 * CleanXfac_1, DTA_CellY, 16 * CleanYfac_1, DTA_ColorOverlay, overlay);
}
protected void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent)
protected void DrawSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent, bool grayed = false)
{
String formater = String.format("%%.%df", fracdigits); // The format function cannot do the '%.*f' syntax.
String textbuf;
@ -753,21 +766,21 @@ class OptionMenuSliderBase : OptionMenuItem
if (!mSliderShort)
{
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12");
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 78) / range)) * 2 * CleanXfac_1), cy, "\x13");
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x11\x11\x11\x11\x11\x12", grayed);
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 78) / range)) * 2 * CleanXfac_1), cy, "\x13", grayed);
}
else
{
// On 320x200 we need a shorter slider
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12");
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 38) / range)) * 2 * CleanXfac_1), cy, "\x13");
DrawSliderElement(Font.CR_WHITE, x, cy, "\x10\x11\x11\x11\x11\x11\x12", grayed);
DrawSliderElement(Font.FindFontColor(gameinfo.mSliderColor), x + int((5 + ((ccur * 38) / range)) * 2 * CleanXfac_1), cy, "\x13", grayed);
right -= 5*8*CleanXfac;
}
if (fracdigits >= 0 && right + maxlen <= screen.GetWidth())
{
textbuf = String.format(formater, cur);
drawText(right, y, Font.CR_DARKGRAY, textbuf);
drawText(right, y, Font.CR_DARKGRAY, textbuf, grayed);
}
}
@ -775,9 +788,9 @@ class OptionMenuSliderBase : OptionMenuItem
//=============================================================================
override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected)
{
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor);
drawLabel(indent, y, selected? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, IsGrayed());
mDrawX = indent + CursorSpace();
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent, IsGrayed());
return indent;
}
@ -850,9 +863,9 @@ class OptionMenuItemSlider : OptionMenuSliderBase
{
CVar mCVar;
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1)
OptionMenuItemSlider Init(String label, Name command, double min, double max, double step, int showval = 1, CVar graycheck = NULL)
{
Super.Init(label, min, max, step, showval, command);
Super.Init(label, min, max, step, showval, command, graycheck);
mCVar =CVar.FindCVar(command);
return self;
}