tass23

Member
In digging through my archives, I happened upon the start of a script project and I decided to finish it off this weekend. I have run into an issue though. The system is built using Buttons instead of Check boxes. Check boxes I know I can "count" in C# (info.Switches.Length), but can I "count" Buttons, like with an OnClick property? If Switches.Length works for Check boxes, what is it for Buttons?
 
Since buttons have unique ID's, you can track them in OnResponse, which is the closest thing you'll get to OnClick without using VNc's SuperGumps.

Buttons that have been clicked can be added to a List<int> to signify they were clicked.
They can also be removed from the list when clicked again.
This list would have to persist through gump refreshes, so your gump constructor would likely take a List<int> argument.

C#:
public class MyGump : Gump
{
    private List<int> _Selected;

    public MyGump(  )
        : this( null )
    { }

    public MyGump( List<int> selected )
    {
         _Selected = selected ?? new List<int>( );

         // Add body elements, buttons, etc...
    }

    public override void OnResponse( NetState state, RelayInfo info )
    {
         if( info.ButtonID > 0 ) // 0 or lower should "close"
         {
              if( _Selected.Contains( info.ButtonID ) )
              {
                   _Selected.Remove( info.ButtonID );
              }
              else
              {
                   _Selected.Add( info.ButtonID );
              }

              state.Mobile.SendGump( new MyGump( _Selected ) );
         }
    }
}

Logic would have to be added so that you can actually DO something with _Selected, otherwise this just acts as an example of how to make buttons work like checkboxes.
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back