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

  • Unchained
    Custom (Classic)
    • Players
    • 144 Online
    • 257 Peak
  • UO Eventine
    Time Of Legends
    • Players
    • 85 Online
    • 137 Peak
  • The Crossroads
    Mondain's Legacy
    • Players
    • 64 Online
    • 138 Peak
  • Insane UO
    Endless Journey
    • Players
    • 59 Online
    • 101 Peak
  • UO: Felucca
    Renaissance
    • Players
    • 55 Online
    • 87 Peak
  • Arth
    Custom (Modern)
    • Players
    • 24 Online
    • 34 Peak
  • CALYPSO
    Custom (Modern)
    • Players
    • 23 Online
    • 30 Peak
  • UO Phoenix
    Custom (Classic)
    • Players
    • 21 Online
    • 35 Peak
  • UOItalia Reborn
    Custom
    • Players
    • 19 Online
    • 37 Peak
  • UO Enigma
    Custom (Modern)
    • Players
    • 19 Online
    • 172 Peak

Donations

Total amount
$0.00
Goal
$500.00
Back