Jack

Member
Never come across this problem but I guess I've never needed to add multiple sets of radio buttons to a gump. What I mean is something like this:

ai.imgur.com_cBdOM4w.png

In that gump, the initial states of "Thursday" and "Non-Free Use, Magics" are in the pressed state. However when you select any radio button in the gump, it results in the initial states of the other two being blanked.

ai.imgur.com_iTU8CAg.png

In retrospect this should not have been surprising because there's seems to be no way to "group" radio buttons. The only way to add a radio button is by this method in Gump:

Code:
public void AddRadio( int x, int y, int inactiveID, int activeID, bool initialState, int switchID )

I assume there's no way to add multiple sets of radio button short of workarounds like using multiple gumps?
 
Jack, this is perfectly doable. I'm on my phone at the moment. If nobody else replies before I get to my pc in an hour or so, I'll give you an example.
 
I am not sure how they do it - but doesn't the ToT Gump have a dual set of buttons? [totadmin (scripts\gumps\totadmingump.cs)
 
Tukaram is right, it looks like the ToTAdminGump is a good example. Using boolean parameters for the button ID's, you should be able to have it work however you'd like with multiple groups. In the OnResponse you can set/reset the bools so however many different sets are active, and have the button ID's either change or remain constant.

Edit: Not sure if this accomplishes what you want now that I think about it, but it's a work around to have the same visual effect on the gump at the least.
 
Last edited:
Aww... now you know my secret. I can't write code - but sometimes I can edit it! :)

It is part of the learning curve.
 
Tukaram is right, it looks like the ToTAdminGump is a good example. Using boolean parameters for the button ID's, you should be able to have it work however you'd like with multiple groups. In the OnResponse you can set/reset the bools so however many different sets are active, and have the button ID's either change or remain constant.

Edit: Not sure if this accomplishes what you want now that I think about it, but it's a work around to have the same visual effect on the gump at the least.
This is the workaround I'm currently using, the downside of it is that the gump closes and reopens every time you click a button. It looks much nicer when the gump doesn't have to flash in the client every time a "radio" button is clicked.
 
This is the workaround I'm currently using, the downside of it is that the gump closes and reopens every time you click a button. It looks much nicer when the gump doesn't have to flash in the client every time a "radio" button is clicked.

At the risk of making you vomit - there is a possible way to make it LOOK like this isn't happening.

1) Player selects a radio button
2) Dummy gump gets created on top of current gump. It looks exactly like the original except everything on there is a non-functional image.
3) Old gump is closed
4) New gump appears on top of the dummy gump
5) Dummy gump is closed.
 
At the risk of making you vomit - there is a possible way to make it LOOK like this isn't happening.

1) Player selects a radio button
2) Dummy gump gets created on top of current gump. It looks exactly like the original except everything on there is a non-functional image.
3) Old gump is closed
4) New gump appears on top of the dummy gump
5) Dummy gump is closed.

I did consider this too but it would require the gump to be non movable, which I'm not a fan of. Seems odd that the client wouldn't support multiple sets of radio buttons!
 
Ok, I know it's been a while, but here is my workaround.
1) I created a array of GumpButtons to be more easy to find/add/remove the entities;
2) I created a class (inside the gump; it could be static variables or a structure, but I did this way) to persist some data that I wanted to reuse;
3) When I clicked on the button I set, under OnResponse, to stored all the data and then created another gump, but now with the button pressed(as a radio button).
Basically is that, of course I resumed what i actually did, so take a look at the script below. I didn't refactored or anything because I did it just now. Hope it solve your problems as it solved mine.

Code
Code:
//////////////////////////////////////////////////////////////////////
// Automatically generated by Bradley's GumpStudio and roadmaster's
// exporter.dll,  Special thanks goes to Daegon whose work the exporter
// was based off of, and Shadow wolf for his Template Idea.
//////////////////////////////////////////////////////////////////////
//#define RunUo2_0

using Server.Network;
using Server.Commands;

namespace Server.Gumps
{
    public class CustomCharGump : Gump
    {

        public class SheetInfos
        {
            public int ButtonID = 0;
            public int ChoosenCity { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
        }

        private Mobile caller;
        private SheetInfos sheetInfos;
        private int currentSelected;

        private GumpButton[] professionButtons;

       

        public static void Initialize()
        {
            CommandSystem.Register("CustomCharGump", AccessLevel.Administrator, new CommandEventHandler(_OnCommand));
        }

        [Usage("CustomCharGump")]
        [Description("Makes a call to your custom gump.")]
        public static void _OnCommand(CommandEventArgs e)
        {
            var caller = e.Mobile;

            if (caller.HasGump(typeof(CustomCharGump)))
                caller.CloseGump(typeof(CustomCharGump));
            caller.SendGump(new CustomCharGump(caller));
        }

        public CustomCharGump(Mobile from) : this()
        {
            caller = from;
            InitializeButtons();
            AddButtonEntries();
            LoadGumpElements();
        }

        public CustomCharGump(Mobile from, SheetInfos infos) : this()
        {
           
            sheetInfos = infos;
            caller = from;
            if(infos.ButtonID > 0)
            {
                SetButtonActive(infos.ButtonID);
            }
            else
            {
                InitializeButtons();
                AddButtonEntries();  
            }

            LoadGumpElements();
        }

        public CustomCharGump() : base(0, 0)
        {
            this.Closable = false;
            this.Disposable = false;
            this.Dragable = true;
            this.Resizable = false;
            AddPage(0);
            AddBackground(148, 30, 422, 545, 9300);
            AddLabel(179, 63, 0, @"First Name");
            AddLabel(321, 507, 37, @"");
            AddButton(321, 540, 247, 248, 0, GumpButtonType.Reply, 0);
            AddLabel(183, 396, 0, @"Hunter");
            AddLabel(280, 396, 0, @"Carpenter");
            AddLabel(393, 396, 0, @"Noble");
            AddLabel(478, 396, 0, @"Mercenary");
            AddLabel(185, 499, 0, @"Sailor");
            AddLabel(292, 499, 0, @"Knight");
            AddLabel(379, 499, 0, @"Blacksmith");
            AddLabel(472, 499, 0, @"Broken Lord");
            AddHtml(565, 43, 201, 524, @"
<b>Olar</b>
vai Cagar", (bool)true, (bool)true);
            AddLabel(302, 278, 0, @"Choose Profession");

            InitializeButtons();
        }

        private void LoadGumpElements()
        {
           
            AddBackground(172, 92, 162, 25, 9350);
            AddTextEntry(175, 94, 157, 23, 0, 0, sheetInfos != null ? sheetInfos.FirstName : @"", 10);
            AddLabel(389, 63, 0, @"Last Name");
            AddBackground(382, 92, 162, 25, 9350);
            AddTextEntry(385, 94, 157, 23, 0, 2, sheetInfos != null ? sheetInfos.LastName : @"", 10);
            AddRadio(181, 187, 209, 208, sheetInfos != null ? sheetInfos.ChoosenCity == 1 ? true : false : true, 1);
            AddLabel(302, 150, 0, @"Choose Kingdom");
            AddLabel(204, 187, 0, @"Britannia");
            AddRadio(181, 216, 209, 208, sheetInfos != null ? sheetInfos.ChoosenCity == 2 ? true : false : false, 2);
            AddLabel(204, 216, 0, @"Trinsic");
            AddRadio(181, 245, 209, 208, sheetInfos != null ? sheetInfos.ChoosenCity == 3 ? true : false : false, 3);
            AddLabel(204, 245, 0, @"Skara Brae");
        }

        public override void OnResponse(NetState sender, RelayInfo info)
        {
            var sheet = new SheetInfos();
            Mobile from = sender.Mobile;

            TextRelay entry0 = info.GetTextEntry(0);
            sheet.FirstName = (entry0 == null ? "" : entry0.Text.Trim());


            TextRelay entry2 = info.GetTextEntry(2);
            sheet.LastName = (entry2 == null ? "" : entry2.Text.Trim());

            if(info.ButtonID != 0)
            {
                for(int i = 0; i < info.Switches.Length; i++)
                {
                    if(info.IsSwitched(info.Switches[i]))
                    {
                        sheet.ChoosenCity = info.Switches[i];
                    }
                }
                sheet.ButtonID = info.ButtonID;
                //SetButtonActive(info.ButtonID);
                caller.SendGump(new CustomCharGump(caller,sheet));

            }
        }

        private void InitializeButtons()
        {
            professionButtons = new GumpButton[8];
            professionButtons[0] = new GumpButton(176, 329, 5575, 5576, 1, GumpButtonType.Reply, 0);
            professionButtons[1] = new GumpButton(283, 329, 5559, 5560, 2, GumpButtonType.Reply, 0);
            professionButtons[2] = new GumpButton(382, 329, 5571, 5572, 3, GumpButtonType.Reply, 0);
            professionButtons[3] = new GumpButton(481, 329, 5577, 5578, 4, GumpButtonType.Reply, 0);
            professionButtons[4] = new GumpButton(176, 431, 5565, 5566, 5, GumpButtonType.Reply, 0);
            professionButtons[5] = new GumpButton(283, 431, 5587, 5588, 6, GumpButtonType.Reply, 0);
            professionButtons[6] = new GumpButton(382, 431, 5555, 5556, 7, GumpButtonType.Reply, 0);
            professionButtons[7] = new GumpButton(481, 431, 5573, 5574, 8, GumpButtonType.Reply, 0);

        }

        private void SetButtonActive(int buttonID)
        {
            switch(buttonID)
            {
                case 1:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[0] = new GumpButton(176, 329, 5576, 5576, 1, GumpButtonType.Page, 0);
                        AddButtonEntries();
                        break;
                    }
                case 2:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[1] = new GumpButton(283, 329, 5560, 5560, 2, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 3:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[2] = new GumpButton(382, 329, 5572, 5572, 3, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 4:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[3] = new GumpButton(481, 329, 5578, 5578, 4, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 5:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[4] = new GumpButton(176, 431, 5566, 5566, 5, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 6:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[5] = new GumpButton(283, 431, 5588, 5588, 6, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 7:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[6] = new GumpButton(382, 431, 5556, 5556, 7, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }
                case 8:
                    {
                        RemoveButtonEntries();
                        InitializeButtons();
                        professionButtons[7] = new GumpButton(481, 431, 5574, 5574, 8, GumpButtonType.Reply, 0);
                        AddButtonEntries();
                        break;
                    }

            }
        }

        private void RemoveButtonEntries()
        {
            for (int i = 0; i < professionButtons.Length; i++)
            {
                this.Entries.Remove(professionButtons[i]);
            }
        }

        private void AddButtonEntries()
        {
            for (int i = 0; i < professionButtons.Length; i++)
            {
                this.Add(professionButtons[i]);
            }
        }
    }
}

Some printscreen:
upload_2016-12-29_17-12-16.png
upload_2016-12-29_17-13-4.png
 
In relation to the original post, AddGroup( int ) is what is used to group check-boxes and radio buttons separately.
I don't think it affects the GumpResponse data, but it does cause the client to treat different sets of radios independently from one-another.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back