XML radio button (init)

does anyone know how to initialize a group of radio buttons with a button other than the 1st (default) selected?

@Lance_Botelle

I got a checkbox button to init like so:

<UIButton name="PIA_ACTIVE_CB" x="220" y="8" style="SQUARE_CHECKBOX_BUTTON"
OnLeftClick='UIObject_Misc_ExecuteServerScript("gui_pia_bool","20",local:20)'
update="true" OnUpdate='UIButton_OnUpdate_SetCheckedIfLocalVarEquals(local:20,"true")' />

but can’t figure out how to get this to init:

<UIButton name="PIA_PRINT_OFF_RB" x="220" y="32" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="1"
OnLeftClick='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","off")'
update="true" OnUpdate='UIButton_OnUpdate_SetCheckedIfLocalVarEquals(local:21,"off")' />

<UIButton name="PIA_PRINT_CHAT_RB" x="220" y="56" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="2"
OnLeftClick='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","chat")'
update="true" OnUpdate='UIButton_OnUpdate_SetCheckedIfLocalVarEquals(local:21,"chat")' />

 
?

(if i have to am going to dynamically map the radio buttons, such that the selected option appears as the 1st button when the screen loads … just to be peevish … another option is to use a regular button that simply cycles through the options for that button-group)

Consider the radiobuttons like a sequential iteration … convert the/your current value to an id and store it on the module-object … when the gui opens the currently active id is at the top … when a button is selected, add the id of that button to the stored value and convert the result back to a proper gui-local

// gui_pia_open
    string sVal = GetCampaignString(PIA_DATABASE, db_PIA_FB);
    if (sVal == "") sVal = PRINT_NONE;
    SetLocalGUIVariable(oSelf, PIA_GUI_SCREEN, 21, sVal);

    if (sVal != PRINT_NONE) // else use defaults
    {
        string s0,s1,s2,s3; int iPrint;

        if (sVal == PRINT_CHAT)
        {
            s0 = "print chat";
            s1 = "print file";
            s2 = "print both";
            s3 = "print none";
            iPrint = 1;
        }
        else if (sVal == PRINT_FILE)
        {
            s0 = "print file";
            s1 = "print both";
            s2 = "print none";
            s3 = "print chat";
            iPrint = 2;
        }
        else if (sVal == PRINT_BOTH)
        {
            s0 = "print both";
            s1 = "print none";
            s2 = "print chat";
            s3 = "print file";
            iPrint = 3;
        }
        SetGUIObjectText(oSelf, PIA_GUI_SCREEN, "PIA_PRINT_0_TEXT", -1, s0);
        SetGUIObjectText(oSelf, PIA_GUI_SCREEN, "PIA_PRINT_1_TEXT", -1, s1);
        SetGUIObjectText(oSelf, PIA_GUI_SCREEN, "PIA_PRINT_2_TEXT", -1, s2);
        SetGUIObjectText(oSelf, PIA_GUI_SCREEN, "PIA_PRINT_3_TEXT", -1, s3);

        SetLocalInt(GetModule(), PIA_FB_TEMP, iPrint);
    }

 

<UIButton name="PIA_PRINT_0_RB" x="220" y="32" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="1"
OnSelected='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","0")' />
<UIText name="PIA_PRINT_0_TEXT" text="print none" x="250" y="32" width="64" height="20"
align="left" valign="middle" fontfamily="Default" style="bold" />

<UIButton name="PIA_PRINT_1_RB" x="220" y="56" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="2"
OnSelected='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","1")' />
<UIText name="PIA_PRINT_1_TEXT" text="print chat" x="250" y="56" width="64" height="20"
align="left" valign="middle" fontfamily="Default" style="bold" />

<UIButton name="PIA_PRINT_2_RB" x="220" y="80" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="3"
OnSelected='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","2")' />
<UIText name="PIA_PRINT_2_TEXT" text="print file" x="250" y="80" width="64" height="20"
align="left" valign="middle" fontfamily="Default" style="bold" />

<UIButton name="PIA_PRINT_3_RB" x="220" y="104" style="ROUND_RADIO_BUTTON" groupid="20" groupmemberid="4"
OnSelected='UIObject_Misc_ExecuteServerScript("gui_pia_radio","21","3")' />
<UIText name="PIA_PRINT_3_TEXT" text="print both" x="250" y="104" width="64" height="20"
align="left" valign="middle" fontfamily="Default" style="bold" />

 

// gui_pia_radio(int iLocal, int iCycle)
    string sPrint;
    switch ((GetLocalInt(GetModule(), PIA_FB_TEMP) + iCycle) % 4)
    {
        default:
        case 0: sPrint = PRINT_NONE; break;
        case 1: sPrint = PRINT_CHAT; break;
        case 2: sPrint = PRINT_FILE; break;
        case 3: sPrint = PRINT_BOTH; break;
    }
    SetLocalGUIVariable(OBJECT_SELF, PIA_GUI_SCREEN, iLocal, sPrint);

 
But id still like to know how to load a gui with a desired radiobutton selected …

Pia_Options

@kevL_s,

OK, having read your post again, I am not sure if this is what you were after, as it is still the “first” member of the group, but not necessarily the first button you have named.

EDIT: This is what I did when I wanted to start at a different button in my sequence … It is the group member ID: This defaults to button RADIO_5 being the “default”. So, reverse you groupmeberid sequence.

Basically, the first button (designated by groupmemberid) can also be “placed” anywhere in the XML to be the “default” button.

<! -- CREATE SOME RADIO BUTTONS -- >	

	<UIButton name="RADIO_1" x=42 y=50 buttontype=radio style="ROUND_RADIO_BUTTON" groupid=1 groupmemberid=5 OnSelected=UIObject_Misc_SetLocalVarString(local:0,"LUX")/>
	<UIButton name="RADIO_2" x=42 y=80 buttontype=radio style="ROUND_RADIO_BUTTON" groupid=1 groupmemberid=4 OnSelected=UIObject_Misc_SetLocalVarString(local:0,"EXP")/>
	<UIButton name="RADIO_3" x=42 y=110 buttontype=radio style="ROUND_RADIO_BUTTON" groupid=1 groupmemberid=3 OnSelected=UIObject_Misc_SetLocalVarString(local:0,"AVE")/>
	<UIButton name="RADIO_4" x=42 y=140 buttontype=radio style="ROUND_RADIO_BUTTON" groupid=1 groupmemberid=2 OnSelected=UIObject_Misc_SetLocalVarString(local:0,"CHP")/>
	<UIButton name="RADIO_5" x=42 y=170 buttontype=radio style="ROUND_RADIO_BUTTON" groupid=1 groupmemberid=1 OnSelected=UIObject_Misc_SetLocalVarString(local:0,"ABN")/>

However, I had a second idea that may work around particularly specifying the button on which to start (untested) … You could (perhaps), as the GUI opens, disable all buttons you do not want to be selected, which then forces the GUI to use/select the only available option, then enable the other options shortly after the GUI has finished opening. If even possible, it may require some careful timing and perhaps things like idleexpiretime is set low. I think this would work, as I do some things similar to this elsewhere I believe.

1 Like

good idea, Lance … but doesn’t work it seems :\

this should have shuffled the selected rb down to button3

    SetGUIObjectDisabled(OBJECT_SELF, PIA_GUI_SCREEN, "PIA_PRINT_0_RB", TRUE);
    SetGUIObjectDisabled(OBJECT_SELF, PIA_GUI_SCREEN, "PIA_PRINT_1_RB", TRUE);
    SetGUIObjectDisabled(OBJECT_SELF, PIA_GUI_SCREEN, "PIA_PRINT_2_RB", TRUE);
//  SetGUIObjectDisabled(OBJECT_SELF, PIA_GUI_SCREEN, "PIA_PRINT_3_RB", TRUE);

 
but the group merely glitches out … w/ no selection
Pia_Options2

note I kept the test as simple as possible – eg. didn’t try to reset its current value etc. I just wanted to see if the selected button would shuffle itself down. They made things sooooooo difficult  ;)

But am more or less happy with my “remap the buttons” shenanigans

1 Like

@Lance_Botelle Note that the defn of ROUND_RADIO_BUTTON ( stylesheet.xml ) sets buttontype=radio already.
No need to be redundant :)

1 Like

@kevL_s,

Yes, I know I tend to overdo the XML stuff, but I find it easier to keep track like this sometimes. :slight_smile: I also edit some of those supporting XML scripts and (in case I lose track) I redo stuff just in case. It hampers me the other way as well of course. :wink:

Re my suggestion … I really thought I had managed this somehow somewhere … maybe I set them as disabled by default via the XML code somewhere (rather than via script) and then re-enabled … or set something within a pane than I “hid/deativated” until required. That stuff goes so far back now, I really have forgotten it … sorry about that.

However, if I happen to be going that way again, I will keep your point in mind and try to pay closer attention to what I have done and be sure to let you know.

RL is still rather hectic at the moment, but I am still managing some mod build now and then, so you never know, it may be something I come to sooner than later. Now to fix a light in RL! )

1 Like

no hurry or worries, Lance.

as you say, if you happen to see what ya did pls Let me know,

 
It’s a balmy 16° here. (yes that’s C) -> admire the plants and marvel at the birds

1 Like

Since the radiobuttons had issues refreshing/updating visually i went with checkboxes.

Pia_Options3

/wip

2 Likes

/waah i want Radio

turns out its easy to fake w/ Checkboxes by drawing them like radio buttons – I used local:21 for this (arbitrary, no conflicts).

 
 1. set a gui-local when the gui loads

	// print protocol (fake radio)
	sVal = GetCampaignString(PIA_DATABASE, "print_protocol");
	if (sVal == "") sVal = "none";
	SetLocalGUIVariable(oSelf, PIA_GUI_SCREEN, 21, sVal);

 2. and this is what a fake radio button looks like

	<UIButton name="PIA_PRINT_NONE_CB" x="0" y="33" style="ROUND_CHECKBOX_BUTTON"
	OnSelected='UIObject_Misc_SetLocalVarString(local:21,"none")'
	OnUpdate='UIButton_OnUpdate_SetCheckedIfLocalVarEquals(local:21,"none")' update="true" />
	<UIText name="PIA_PRINT_NONE_TEXT" text="print none" x="30" y="33" width="64" height="20"
	align="left" valign="middle" fontfamily="Default" style="2" />

 3. this is the event code when the gui closes (is accepted)

	OnLeftClick='UIObject_Misc_ExecuteServerScript("gui_pia_accept",local:21)'

 4. lastly the callback script

// 'gui_pia_accept'
void main(string sLocal21)
{
	SetCampaignString(PIA_DATABASE, "print_protocol", sLocal21);
}

 
Ofc there are many other checks &tc between there and here. But that appears to be the gist of it

Pia_Options5

3 Likes

@kevL_s,

Great! :+1:

Out of interest, what is this eventually going to be/do?

1 Like

hey Lance,

it’s a GUI frontend for the Pia

But the gui is only for my personal use (although am willing to share it to those who “know what they’re doing”) since it uses a campaign database instead of a 2da file – hence it requires an extra level of ‘mental maintenance’ in that the data needs to be consciously applied to a Module/Campaign rather than how things just run auto wrt/ the 2da file …

And the fact that i put it in the Options gui – next to the Level of Difficulty slider – increases the chance of bork beyond what I feel comfortable with for general use. So for now it looks like

The only thing left to do, i think, is transfer the database values to globals in globals.xml instead of locals on the Module-object …

3 Likes