[MENUDEF] Flag-based option item.

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

[MENUDEF] Flag-based option item.

Postby Accensus » Sat Oct 17, 2020 4:38 am

Something like compatibility flags but not hardcoded. I'm using a modified version of OptionMenuItemOption here, but as of the time of this post I've had to blatantly copy-paste this class over four times in the time span of a month to use it in other mods. Can something like this be added natively?

Example of the code above used in MENUDEF:
Code: Select allExpand view
StaticText "----- Visibility Options -----", "Teal"
VisibilityOption "Player Name", "wt_lite_adv_visibility", "OnOff", 0
VisibilityOption "Total Kills", "wt_lite_adv_visibility", "OnOff", 1
VisibilityOption "Genocide Rank", "wt_lite_adv_visibility", "OnOff", 2
VisibilityOption "Genocide Medal", "wt_lite_adv_visibility", "OnOff", 3
VisibilityOption "Player Rank", "wt_lite_adv_visibility", "OnOff", 4
VisibilityOption "Player Experience", "wt_lite_adv_visibility", "OnOff", 5
VisibilityOption "Player Medal", "wt_lite_adv_visibility", "OnOff", 6
StaticText ""
VisibilityOption "Weapon Name", "wt_lite_adv_visibility", "OnOff", 7
VisibilityOption "Weapon Rank", "wt_lite_adv_visibility", "OnOff", 8
VisibilityOption "Weapon Kills", "wt_lite_adv_visibility", "OnOff", 9
VisibilityOption "Weapon Medals", "wt_lite_adv_visibility", "OnOff", 10
User avatar
Accensus
Vector, locked in.
 
Joined: 11 Feb 2016
Location: Somalia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [MENUDEF] Flag-based option item.

Postby Graf Zahl » Sat Oct 17, 2020 4:56 am

If you can clean up your code to be generically usable, there's no reason not to add it.
The entire menu is script code anyway, so there's no reason to redo it all over again.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: [MENUDEF] Flag-based option item.

Postby Accensus » Sat Oct 17, 2020 5:17 am

How's this?

Code: Select allExpand view
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);
         }
      }
   }
}

What I did was remove the comment and made the name more generic. Also added "graycheck" and "center" because those were missing for some reason.
Not sure if there's anything else I could do.
User avatar
Accensus
Vector, locked in.
 
Joined: 11 Feb 2016
Location: Somalia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests