Skip to content

Commit

Permalink
- added flag option menu item by Accensus.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Oct 24, 2020
1 parent 8872f86 commit bc2b0a0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/engine/sc_man.cpp
Expand Up @@ -529,7 +529,7 @@ bool FScanner::ScanString (bool tokens)
LastGotLine = Line;

// In case the generated scanner does not use marker, avoid compiler warnings.
marker;
// marker;
#include "sc_man_scanner.h"
LastGotToken = tokens;
return return_val;
Expand Down
1 change: 0 additions & 1 deletion src/common/fonts/font.cpp
Expand Up @@ -579,7 +579,6 @@ void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors)
{
usedcolors[pixels[x]]++;
}

}

//==========================================================================
Expand Down
62 changes: 62 additions & 0 deletions wadsrc/static/zscript/ui/menu/optionmenuitems.zs
Expand Up @@ -1234,3 +1234,65 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider

}

//=============================================================================
//
// Flag option by Accensus
//
//=============================================================================

class OptionMenuItemFlagOption : OptionMenuItemOption
{
int mBitShift;

OptionMenuItemFlagOption Init(String label, Name command, Name values, int bitShift, CVar greycheck = null, int center = 0)
{
Super.Init(label, command, values, greycheck, center);
mBitShift = bitShift;

return self;
}

override int GetSelection()
{
int Selection = 0;
int cnt = OptionValues.GetCount(mValues);
if (cnt > 0 && mCVar != null)
{
if (OptionValues.GetTextValue(mValues, 0).Length() == 0)
{
int CurrentFlags = mCVar.GetInt();

for (int i = 0; i < cnt; i++)
{
int OptionValue = int(OptionValues.GetValue(mValues, i));
if (CurrentFlags & (OptionValue << mBitShift))
{
Selection = i;
break;
}
}
}
}
return Selection;
}

override void SetSelection(int Selection)
{
int cnt = OptionValues.GetCount(mValues);
if (cnt > 0 && mCVar != null)
{
if (OptionValues.GetTextValue(mValues, 0).Length() == 0)
{
int OptionValue = int(OptionValues.GetValue(mValues, Selection));
int CurrentFlags = mCVar.GetInt();

switch (OptionValue)
{
case 0: CurrentFlags &= ~(1 << mBitShift); break;
case 1: CurrentFlags |= (1 << mBitShift); break;
}
mCVar.SetInt(CurrentFlags);
}
}
}
}

0 comments on commit bc2b0a0

Please sign in to comment.