Jump to content

Recommended Posts

Hello, I have made a list box and added 4 different option in it. Like this:

//sg_dialogs.hpp
class sg_list_1{

	type = 5;
	idc = 5545;
	onLoad = [] spawn sg_fnc_openHelp;
	x = safeZoneX + safeZoneW * 0.343125;
	y = safeZoneY + safeZoneH * 0.37555556;
	w = safeZoneW * 0.10375;
	h = safeZoneH * 0.24;
	style = 16;
	colorBackground[] = {0.302,0.302,0.302,0.4683};
	colorDisabled[] = {0.302,0.302,0.302,0.4841};
	colorSelect[] = {1,1,1,1};
	colorText[] = {1,1,1,0.381};
	font = "PuristaMedium";
	maxHistoryDelay = 0;
	rowHeight = 0;
	sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
	soundSelect[] = {"\A3\ui_f\data\sound\RscListbox\soundSelect",0.09,1.0};
	class ListScrollBar{
		color[] = {1,1,1,1};
		thumb = "\A3\ui_f\data\gui\cfg\scrollbar\thumb_ca.paa";
		arrowFull = "\A3\ui_f\data\gui\cfg\scrollbar\arrowFull_ca.paa";
		arrowEmpty = "\A3\ui_f\data\gui\cfg\scrollbar\arrowEmpty_ca.paa";
		border = "\A3\ui_f\data\gui\cfg\scrollbar\border_ca.paa";
	};
};
//sg_fnc_help.sqf
sg_fnc_openHelp = {
    disableSerialization;
    lbClear 5545;
    {lbAdd[5545,_x]} forEach ["Spawn A Vehicle","Gun On Back","Jumping","Earplugs"];
};
//initPlayerLocal.sqf
call compile preprocessFile "scripts\sg_dialogs\sg_fnc_help.sqf";

It works and successfully adds the 4 items into the list box.

 

I am having a problem when I try to make it add text to the side of the list box depending on which list box item is selected.

I have another function which I am trying to make change the structured text:

//sg_fnc_help.sqf
sg_fnc_helpInfo = {
    _selectedLb = lbCurSel 5545;
        //2001 = idd for dialog. 5545 is idc for structured text.
    _lbText = ((findDisplay 2001) displayCtrl (5545));

    if (_selectedLb == 0) then{
        _lbText ctrlSetStructuredText parseText "You have selected Spawn A Vehicle.";
    };
    if (_selectedLb == 1) then{
        _lbText ctrlSetStructuredText parseText "You have selected Gun On Back.";
    };
};
//structured text I am trying to change - sg_dialogs.hpp
class sg_spawnVeh{
            type = 0;
            idc = 5546;
            x = safeZoneX + safeZoneW * 0.52375;
            y = safeZoneY + safeZoneH * 0.39222223;
            w = safeZoneW * 0.048125;
            h = safeZoneH * 0.02444445;
            style = 0;
            text = "";
            colorBackground[] = {0.302,0.302,0.302,0};
            colorText[] = {1,1,1,1};
            font = "PuristaMedium";
            sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
};

I don't get an error, nothing happens when I double click on any list box item. I haven't really used list boxes before today. Some help would be great!

Share this post


Link to post
Share on other sites
5 minutes ago, HazJ said:

Use _forEachIndex so it gets the current iteration.

https://community.bistudio.com/wiki/Magic_Variables#forEachIndex

Should it be something like this:

_selectedLb = lbCurSel 5545;

_selectedLb lbSetTextRight [_forEachIndex, "You have selected Spawn A Vehicle.", "You have selected Gun On Back."];

 

Share this post


Link to post
Share on other sites
Quote

_control lbSetTextRight [0, "iskoda"];

private _display = findDisplay 2001;
private _lb = _display displayCtrl 5545;
{
	_x params ["_leftText", "_rightText"];
	_lb lbAdd _leftText;
	_lb lbSetTextRight [_forEachIndex, _rightText];
} forEach
[
	["Item 1", "£200"],
	["Item 2", "£400"],
	["Item 3", "£600"]
];

Not tested.

I use this syntax. Not sure which you should really use, technical details, etc... I know that lbSetTextRight only has the one syntax. Maybe @Larrow will know which to use? Usually one is for dialogs and the other not. However never seen LB use for non dialog. Doesn't make sense to do so?

Share this post


Link to post
Share on other sites
4 minutes ago, HazJ said:

private _lb = _display displayCtrl 5545;
{
	_x params ["_leftText", "_rightText"];
	_lb lbAdd _leftText;
	_lb lbSetTextRight [_forEachIndex, _rightText];
} forEach
[
	["Item 1", "£200"],
	["Item 2", "£400"],
	["Item 3", "£600"]
];

Not tested.

I use this syntax. Not sure which you should really use, technical details, etc... I know that lbSetTextRight only has the one syntax. Maybe @Larrow will know which to use? Usually one is for dialogs and the other not. However never seen LB use for non dialog. Doesn't make sense to do so?

Error Undefined Variable in expression: _display. Not really sure what that means. Hopefully, larrow can help with this too.

Share this post


Link to post
Share on other sites

I edited my post above. Forgot to add _display before.

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

I edited my post above. Forgot to add _display before.

That works great, but I think I may have explained myself wrong. I wanted the text to appear in a different box, which I thought that this did.

This screenshot might help show what I was trying to do: http://prntscr.com/mtto4b

Share this post


Link to post
Share on other sites

Oh, I guess I misunderstood too. Create another control type like you did before? Use RscText or RscStructuredText - Give it an IDC, adjust x/y/w/h values, etc...

class whatever : RscStructuredText
{
	// stuff...
};
_text = _display displayCtrl <IDC>; // Replace <IDC> with actual number
_text ctrlSetStructuredText parseText "You have selected Spawn A Vehicle.";

 

Share this post


Link to post
Share on other sites
20 minutes ago, HazJ said:

Oh, I guess I misunderstood too. Create another control type like you did before? Use RscText or RscStructuredText - Give it an IDC, adjust x/y/w/h values, etc...


class whatever : RscStructuredText
{
	// stuff...
};

_text = _display displayCtrl <IDC>; // Replace <IDC> with actual number
_text ctrlSetStructuredText parseText "You have selected Spawn A Vehicle.";

 

Sorry, I have just tried it and I still have no idea what is going on. There isn't an error that pops up just nothing happens.

Might help if I show you the stuff I have rn:

//sg_dialogs.hpp
class sg_helpInfoText_1:RscStructuredText{
	type = 0;
    idc = 5546;
    x = safeZoneX + safeZoneW * 0.4675;
    y = safeZoneY + safeZoneH * 0.38666667;
    w = safeZoneW * 0.126875;
    h = safeZoneH * 0.01;
    style = 0+2;
    text = "";
    colorBackground[] = {0.9412,0.5843,0.8549,0};
    colorText[] = {1,1,1,1};
    font = "PuristaMedium";
    sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 35) * 1);
    moving = false;
};
//sg_fnc_help.sqf
sg_fnc_openHelp = {
    disableSerialization;
    lbClear 5545;
    {lbAdd[5545,_x]} forEach ["Spawn A Vehicle","Gun On Back","Jumping","Earplugs"];
};

sg_fnc_helpInfo = {
    private _display = findDisplay 2001;

    _text = _display displayCtrl 5546; // Replace <IDC> with actual number
    _text ctrlSetStructuredText parseText "You have selected Spawn A Vehicle.";
};

Whenever I double click on the option in the list box, nothing happens.

Share this post


Link to post
Share on other sites

Add disableSerialization; in sg_fnc_helpInfo too. This should fix it but if that doesn't then:

No errors when calling sg_fnc_helpInfo? Correct IDD and IDCs. Try using latest base defines here. Or share your RscStructuredText defines so I can check them. I notice you set style there, etc...

class sg_helpInfoText_1 : RscStructuredText
{
	idc = 5546;
	x = safeZoneX + safeZoneW * 0.4675;
	y = safeZoneY + safeZoneH * 0.38666667;
	w = safeZoneW * 0.126875;
	h = safeZoneH * 0.01;
	text = "Default text..."; // to see if issue is with SQF code setting new text
};

 

Share this post


Link to post
Share on other sites
10 minutes ago, HazJ said:

Add disableSerialization; in sg_fnc_helpInfo too. This should fix it but if that doesn't then:

No errors when calling sg_fnc_helpInfo? Correct IDD and IDCs. Try using latest base defines here. Or share your RscStructuredText defines so I can check them. I notice you set style there, etc...


class sg_helpInfoText_1 : RscStructuredText
{
	idc = 5546;
	x = safeZoneX + safeZoneW * 0.4675;
	y = safeZoneY + safeZoneH * 0.38666667;
	w = safeZoneW * 0.126875;
	h = safeZoneH * 0.01;
	text = "Default text..."; // to see if issue is with SQF code setting new text
};

 

I copied the RscStructuredText from the drop box and put it in my defines.hpp, and it still didn't work even with disableSerialization on/off.

I changed the text to 'Default' and it did show.

Share this post


Link to post
Share on other sites

Do you not even the default initial text? I just had a thought, do you have a background or another control there? It might be overlapping since I can see it. I just had to adjust the height value as it was extremely hard to read.

POtGtm1.jpg

// description.ext
#include "test.hpp" // in root
// test.hpp
class test
{
	idd = 113175;
	movingEnable = 1;
	onLoad = "";
	onUnload = "";
	class controls
	{
		class sg_helpInfoText_1 : RscStructuredText
		{
			idc = 5546;
			x = safeZoneX + safeZoneW * 0.4675;
			y = safeZoneY + safeZoneH * 0.38666667;
			w = safeZoneW * 0.126875;
			h = safeZoneH * 0.04; // adjusted this
			text = "Default text..."; // to see if issue is with SQF code setting new text
		};
	};
};

Confirm you can see it then we can look at the next thing.

Share this post


Link to post
Share on other sites
15 minutes ago, HazJ said:

Confirm you can see it then we can look at the next thing.

 

I could see it when I changed it to default:

class sg_helpInfoText_1:RscStructuredText{
        	type = 0;
        	idc = 5546;
        	x = safeZoneX + safeZoneW * 0.4675;
        	y = safeZoneY + safeZoneH * 0.38666667;
        	w = safeZoneW * 0.126875;
        	h = safeZoneH * 0.01;
        	style = 0+2;
        	text = "Default Text";
        	colorBackground[] = {0.9412,0.5843,0.8549,0};
        	colorText[] = {1,1,1,1};
        	font = "PuristaMedium";
        	sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 35) * 1);
        	moving = false;

        };

http://prntscr.com/mtu9s1

Share this post


Link to post
Share on other sites

Works for me? 10 is 10 seconds.

// description.ext
#include "test.hpp"
// test.hpp
class test
{
	idd = 2001;
	movingEnable = 1;
	onLoad = "[] spawn sg_fnc_helpInfo;";
	onUnload = "";
	class controls
	{
		class sg_helpInfoText_1 : RscStructuredText
		{
			idc = 5546;
			x = safeZoneX + safeZoneW * 0.4675;
			y = safeZoneY + safeZoneH * 0.38666667;
			w = safeZoneW * 0.126875;
			h = safeZoneH * 0.04;
			text = "Default text..."; // to see if issue is with SQF code setting new text
		};
	};
};
// init.sqf
sg_fnc_helpInfo =
{
	disableSerialization;
	private _display = findDisplay 2001;
	_text = _display displayCtrl 5546;
	_text ctrlSetStructuredText parseText "You have selected Spawn A Vehicle."; // instantly shows...
	// even with: _text ctrlCommit 10;
};
// It now seems that ctrlCommit isn't needed?

 

Share this post


Link to post
Share on other sites

@HazJ I am really confused then... If it works for you then what could I possibly be doing wrong?

 

I copied your .hpp test code to see if that was the problem and it still didn't work. In fact, I stopped seeing 'Default Text'. I even tried putting my functions in init.sqf instead of its own file but that didn't work either.

 

Share this post


Link to post
Share on other sites

My files:

//sg_dialogs.hpp
class sg_list_1
		{
			type = 5;
			idc = 5545;
			onLoad = [] spawn sg_fnc_openHelp;
            onLBDblClick = [] spawn sg_fnc_helpInfo;
			x = safeZoneX + safeZoneW * 0.343125;
			y = safeZoneY + safeZoneH * 0.37555556;
			w = safeZoneW * 0.10375;
			h = safeZoneH * 0.24;
			style = 16;
			colorBackground[] = {0.302,0.302,0.302,0.4683};
			colorDisabled[] = {0.302,0.302,0.302,0.4841};
			colorSelect[] = {1,1,1,1};
			colorText[] = {1,1,1,0.381};
			font = "PuristaMedium";
			maxHistoryDelay = 0;
			rowHeight = 0;
			sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
			soundSelect[] = {"\A3\ui_f\data\sound\RscListbox\soundSelect",0.09,1.0};
			class ListScrollBar
			{
				color[] = {1,1,1,1};
				thumb = "\A3\ui_f\data\gui\cfg\scrollbar\thumb_ca.paa";
				arrowFull = "\A3\ui_f\data\gui\cfg\scrollbar\arrowFull_ca.paa";
				arrowEmpty = "\A3\ui_f\data\gui\cfg\scrollbar\arrowEmpty_ca.paa";
				border = "\A3\ui_f\data\gui\cfg\scrollbar\border_ca.paa";

			};

		};
class sg_helpInfoText_1:RscStructuredText{
            type = 0;
            idc = 5546;
            x = safeZoneX + safeZoneW * 0.4675;
            y = safeZoneY + safeZoneH * 0.38666667;
            w = safeZoneW * 0.126875;
            h = safeZoneH * 0.01;
            style = 0+2;
            text = "Default Text";
            colorBackground[] = {0.9412,0.5843,0.8549,0};
            colorText[] = {1,1,1,1};
            font = "PuristaMedium";
            sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 35) * 1);
        };
	};
//initPlayerLocal.sqf
call compile preprocessFile "scripts\sg_dialogs\sg_fnc_help.sqf";
//sg_fnc_help.sqf
sg_fnc_openHelp = {
    disableSerialization;
    lbClear 5545;
    {lbAdd[5545,_x]} forEach ["Spawn A Vehicle","Gun On Back","Jumping","Earplugs"];
};

sg_fnc_helpInfo = {
    disableSerialization;
    private _display = findDisplay 2001;

    _text = _display displayCtrl 5546;
    _text ctrlSetStructuredText parseText "You have selected Spawn A Vehicle.";
};

 

Share this post


Link to post
Share on other sites

Here you go. Download example.

https://www.dropbox.com/s/yj9pm2bh12jbhcs/Example.VR.zip?dl=0

init.sqf:

// USE CfgFunctions
// https://community.bistudio.com/wiki/Arma_3_CfgFunctions

disableSerialization;

sg_fnc_openHelp =
{
	disableSerialization;
	private _display = findDisplay 2001;
	private _lb = _display displayCtrl 5545;
	[] spawn sg_fnc_helpInfo;
	lbClear _lb;
	{
		_lb lbAdd _x;
	} forEach
	[
		"Spawn A Vehicle",
		"Gun On Back",
		"Jumping",
		"Earplugs"
	];
	_lb ctrlAddEventHandler ["LBSelChanged",
	{
		params ["_control", "_selectedIndex"];
		private _display = findDisplay 2001;
		_text = _display displayCtrl 5546;
		_text ctrlSetStructuredText parseText format ["%1", _control lbText _selectedIndex];
	}];
};

sg_fnc_helpInfo =
{
	disableSerialization;
	private _display = findDisplay 2001;
	_text = _display displayCtrl 5546;
	_text ctrlSetStructuredText parseText "Default";
};

waitUntil {!isNull findDisplay 46};

createDialog "test";

hintSilent "Click on an item from the listbox.";

description.ext:

#include "defines.hpp"
#include "test.hpp"

test.hpp:

class test
{
	idd = 2001;
	movingEnable = 1;
	onLoad = "[] spawn sg_fnc_openHelp;";
	onUnload = "";
	class controls
	{
		class sg_list_1 : RscListbox
		{
			idc = 5545;
			x = safeZoneX + safeZoneW * 0.343125;
			y = safeZoneY + safeZoneH * 0.37555556;
			w = safeZoneW * 0.10375;
			h = safeZoneH * 0.24;
			sizeEx = (((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1);
			rowHeight = 0;
			font = "PuristaMedium";
			colorText[] = {1, 1, 1, 0.381};
			colorSelect[] = {1, 1, 1, 1};
			colorBackground[] = {0.302, 0.302, 0.302, 0.4683};
			colorDisabled[] = {0.302, 0.302, 0.302, 0.4841};
		};
		class sg_helpInfoText_1 : RscStructuredText
		{
			idc = 5546;
			x = safeZoneX + safeZoneW * 0.4675;
			y = safeZoneY + safeZoneH * 0.38666667;
			w = safeZoneW * 0.126875;
			h = safeZoneH * 0.04;
			text = "Initial";
		};
	};
};

defines.hpp:

https://www.dropbox.com/s/pgfk0n14fiq98m4/GUI_defines_1.88.hpp?dl=1

https://community.bistudio.com/wiki/Arma_3_CfgFunctions

I recommend moving structure. Currently threw everything in init.sqf for quick example/testing. How I do it personally is for each UI, I have one function that has everything relevant. All code, UI EHs, etc...

  • Like 1

Share this post


Link to post
Share on other sites

@HazJ Thanks for the mission download, I'm not sure what I did wrong but it seemed to fix whatever I did. 

 

I Understand this line is changing the structuredText to the name of the List Box Option selected?

_text ctrlSetStructuredText parseText format ["%1", _control lbText _selectedIndex];

How would I make it so whenever you clicked on an option I could write in what they see instead of them seeing the name of the option they clicked?

Share this post


Link to post
Share on other sites

A few ways. First that springs to mind is a switch block.

switch (_control lbText _selectedIndex) do
{
	case "Spawn A Vehicle" :
	{
		_text ctrlSetStructuredText parseText "Some vehicle...";
	};
	case "Gun on Back" :
	{
		_text ctrlSetStructuredText parseText "...";
	};
	default
	{
		// default...
		_text ctrlSetStructuredText parseText "Test";
	};
};

https://community.bistudio.com/wiki/switch_do

Share this post


Link to post
Share on other sites
8 minutes ago, HazJ said:

A few ways. First that springs to mind is a switch block.


switch (_control lbText _selectedIndex) do
{
	case "Spawn A Vehicle" :
	{
		_text ctrlSetStructuredText parseText "Some vehicle...";
	};
	case "Gun on Back" :
	{
		_text ctrlSetStructuredText parseText "...";
	};
	default
	{
		// default...
		_text ctrlSetStructuredText parseText "Test";
	};
};

https://community.bistudio.com/wiki/switch_do

Sorry, where would I add this?

I tried replacing it with _lb ctrlAddEventHandler and it gave some error.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×