Skip to content

Commit

Permalink
Implemented mGrayCheck and isGrayed() in OptionMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
jekyllgrim authored and coelckers committed Dec 30, 2023
1 parent cebf37b commit f8653c3
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions wadsrc/static/zscript/engine/ui/menu/optionmenuitems.zs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class OptionMenuItem : MenuItemBase
{
String mLabel;
bool mCentered;
CVar mGrayCheck;

protected void Init(String label, String command, bool center = false)
protected void Init(String label, String command, bool center = false, CVar graycheck = null)
{
Super.Init(0, 0, command);
mLabel = label;
mCentered = center;
mGrayCheck = graycheck;
}

protected void drawText(int x, int y, int color, String text, bool grayed = false)
Expand All @@ -66,12 +68,16 @@ class OptionMenuItem : MenuItemBase
Menu.DrawOptionText(indent + CursorSpace(), y, color, text, grayed, localize);
}


int CursorSpace()
{
return (14 * CleanXfac_1);
}

virtual bool IsGrayed()
{
return mGrayCheck != null && !mGrayCheck.GetInt();
}

override bool Selectable()
{
return true;
Expand All @@ -85,7 +91,7 @@ class OptionMenuItem : MenuItemBase
}

override bool MouseEvent(int type, int x, int y)
{
{
if (Selectable() && type == Menu.MOUSE_Release)
{
return Menu.GetCurrentMenu().MenuEvent(Menu.MKEY_Enter, true);
Expand Down Expand Up @@ -253,16 +259,14 @@ class OptionMenuItemOptionBase : OptionMenuItem
{
// command is a CVAR
Name mValues; // Entry in OptionValues table
CVar mGrayCheck;
int mCenter;

const OP_VALUES = 0x11001;

protected void Init(String label, Name command, Name values, CVar graycheck, int center)
{
Super.Init(label, command);
Super.Init(label, command, false, graycheck);
mValues = values;
mGrayCheck = graycheck;
mCenter = center;
}

Expand Down Expand Up @@ -339,11 +343,6 @@ class OptionMenuItemOptionBase : OptionMenuItem
return true;
}

virtual bool isGrayed()
{
return mGrayCheck != null && !mGrayCheck.GetInt();
}

override bool Selectable()
{
return !isGrayed();
Expand Down Expand Up @@ -699,18 +698,16 @@ 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', CVar graycheck = NULL)
{
Super.Init(label, command);
Super.Init(label, command, false, graycheck);
mMin = min;
mMax = max;
mStep = step;
mShowValue = showval;
mDrawX = 0;
mSliderShort = 0;
mGrayCheck = graycheck;
}

virtual double GetSliderValue()
Expand All @@ -722,11 +719,6 @@ class OptionMenuSliderBase : OptionMenuItem
{
}

virtual bool IsGrayed(void)
{
return mGrayCheck != NULL && !mGrayCheck.GetInt();
}

override bool Selectable(void)
{
return !IsGrayed();
Expand Down Expand Up @@ -900,17 +892,15 @@ class OptionMenuItemSlider : OptionMenuSliderBase
class OptionMenuItemColorPicker : OptionMenuItem
{
CVar mCVar;
CVar mGrayCheck;

const CPF_RESET = 0x20001;

OptionMenuItemColorPicker Init(String label, Name command, CVar graycheck = null)
{
Super.Init(label, command);
Super.Init(label, command, false, graycheck);
CVar cv = CVar.FindCVar(command);
if (cv != null && cv.GetRealType() != CVar.CVAR_Color) cv = null;
mCVar = cv;
mGrayCheck = graycheck;
return self;
}

Expand Down Expand Up @@ -966,11 +956,6 @@ class OptionMenuItemColorPicker : OptionMenuItem
return false;
}

virtual bool IsGrayed(void)
{
return mGrayCheck != NULL && !mGrayCheck.GetInt();
}

override bool Selectable()
{
return !isGrayed();
Expand All @@ -987,11 +972,12 @@ class OptionMenuItemColorPicker : OptionMenuItem

class OptionMenuFieldBase : OptionMenuItem
{
CVar mCVar;

void Init (String label, Name command, CVar graycheck = null)
{
Super.Init(label, command);
Super.Init(label, command, false, graycheck);
mCVar = CVar.FindCVar(mAction);
mGrayCheck = graycheck;
}

String GetCVarString()
Expand All @@ -1009,9 +995,8 @@ class OptionMenuFieldBase : OptionMenuItem

override int Draw (OptionMenuDescriptor d, int y, int indent, bool selected)
{
bool grayed = mGrayCheck != null && !mGrayCheck.GetInt();
drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed);
drawValue(indent, y, OptionMenuSettings.mFontColorValue, Represent(), grayed, false);
drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, isGrayed());
drawValue(indent, y, OptionMenuSettings.mFontColorValue, Represent(), isGrayed(), false);
return indent;
}

Expand All @@ -1036,11 +1021,8 @@ class OptionMenuFieldBase : OptionMenuItem

override bool Selectable()
{
return mGrayCheck == null || mGrayCheck.GetInt() != 0;
return !isGrayed();
}

CVar mCVar;
CVar mGrayCheck;
}

//=============================================================================
Expand Down Expand Up @@ -1142,7 +1124,6 @@ class OptionMenuItemNumberField : OptionMenuFieldBase
return String.format("%.3f", mCVar.GetFloat());
}


override bool MenuEvent (int mkey, bool fromcontroller)
{
if (mCVar)
Expand Down Expand Up @@ -1188,9 +1169,9 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider
String TextNegOne;
int mClickVal;

OptionMenuItemScaleSlider Init(String label, Name command, double min, double max, double step, String zero, String negone = "")
OptionMenuItemScaleSlider Init(String label, Name command, double min, double max, double step, String zero, String negone = "", CVar graycheck = null)
{
Super.Init(label, command, min, max, step, 0);
Super.Init(label, command, min, max, step, 0, graycheck);
mCVar =CVar.FindCVar(command);
TextZero = zero;
TextNEgOne = negone;
Expand All @@ -1207,12 +1188,12 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider
if ((Selection == 0 || Selection == -1) && mClickVal <= 0)
{
String text = Selection == 0? TextZero : Selection == -1? TextNegOne : "";
drawValue(indent, y, OptionMenuSettings.mFontColorValue, text);
drawValue(indent, y, OptionMenuSettings.mFontColorValue, text, isGrayed());
}
else
{
mDrawX = indent + CursorSpace();
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent);
DrawSlider (mDrawX, y, mMin, mMax, GetSliderValue(), mShowValue, indent, isGrayed());
}
return indent;
}
Expand Down

0 comments on commit f8653c3

Please sign in to comment.