Jump to content
Pasi

Dialog Text change

Recommended Posts

Hello Community,

 

I want to change a custom text for klick on a button in a Listbox.

 

at the moment i have this code but i dont see the text in the Structurdetextbox

{
    private _index = _list lbAdd (_x select 0);
    _list lbSetData [_index, str _index];
    _list setVariable [str _index, _x select 3];
	ctrlSetText [7773, Format ["%1", _x select 2]];
	ctrlSetText [7774, Format ["%1", _x select 1]];
} forEach [_one, _two, _three];

every time when i select another point in the Listbox i want to change the text.

can anyone help me ?

 

Pasi

Share this post


Link to post
Share on other sites

Can you send a screenshot of your UI? I'm assuming you're working with a listbox and two structured text elements which you want to change depending on what element is selected in the listbox. The problem with ctrlSetText in this case is it's static. You'll have to work with something like onLBSelChanged if you want to change text depending on the currently selected listbox element.

Share this post


Link to post
Share on other sites

Yes, that is it would i like to do :)

 

Here is a picture and the Code from my dialog.

Dialog.png

 

 

Code:

	class controlsBackground
	{
		class MainBackground: life_RscText
		{
			idc = 1600;
			x = 0.29375 * safezoneW + safezoneX;
			y = 0.313 * safezoneH + safezoneY;
			w = 0.4125 * safezoneW;
			h = 0.418 * safezoneH;
			colorBackground[] = {0,0,0,0.7};
		};
	};
	
	class controls
	{
		class RscListbox_1500: Life_RscListbox
		{
			idc = 7771;
			x = 0.304062 * safezoneW + safezoneX;
			y = 0.335 * safezoneH + safezoneY;
			w = 0.211406 * safezoneW;
			h = 0.341 * safezoneH;
			
		};
		class RscButton_1601: life_RscButtonMenu
		{
			idc = 7772;
			text = "START";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {0,0,1,1};
			x = 0.613437 * safezoneW + safezoneX;
			y = 0.335 * safezoneH + safezoneY;
			w = 0.0825 * safezoneW;
			h = 0.066 * safezoneH;
		};
		class Descriptiontext: Life_RscStructuredText
		{
			idc = 7773;
			text = "";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {1,0,0,1};
			x = 0.530937 * safezoneW + safezoneX;
			y = 0.489 * safezoneH + safezoneY;
			w = 0.165 * safezoneW;
			h = 0.187 * safezoneH;
		};
		class Data: Life_RscStructuredText
		{
			idc = 7774;
			text = "";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {1,0,0,1};
			x = 0.530937 * safezoneW + safezoneX;
			y = 0.423 * safezoneH + safezoneY;
			w = 0.165 * safezoneW;
			h = 0.044 * safezoneH;
		};
	};
};

I dont have any Idea how i can do this :/

can you give me an example ?

Share this post


Link to post
Share on other sites

pls help me noone any idea ?

Up

Share this post


Link to post
Share on other sites

Hi,

 

you're going to have to bear with my here because I'd need 5 morning coffees before I could write any sort of coherent dialog code, so I'm going to just give you pointers instead and hopefully you'll be able to figure it out yourself.

So the idea is that if you want a dialog element (in your case the structured text) to change based on a listbox entry, you need to go at it in a specific order. Think sorta back-end and front-end. You were at it with lbSetData and setVariable etc, and that's the back-end stuff you have to do as the dialog initializes. Basically, each listbox entry (1, 2 and 3) gets values and data assigned to them (through lbSetData etc, if it's used) BEFORE the user sees the dialog. 

 

Once the dialog's been initialized and the user can click through it, you can start to worry about what happens if the user selects different listbox entries. This is where your ctrlSetText bit comes in, because it's essentially front-end: it doesn't do anything but show the user some text. So what you want to use is a User Interface Eventhandler, more specifically onLBSelChanged, to catch if the user selects a new entry. This is the sort of tricky part, as you first of all have to find the corresponding structured text view (if you are, for example, doing a gear view), or, like in your case, you would probably need to stuff relevant data into the relevant structured text box. I have no idea what the two structured text boxes do in your case, so you'll have to figure it out on your own unfortunately. 

 

The onLBSelChanged EH I talked about earlier is best written into the dialog config itself. There's different commands like ctrlAddEventHandler, but these don't work as well as config-based commands. In the code below you'll see 2 things: onLoad (further up), and the onLBSelChanged EH. Think of the onLoad parameter (which can do whatever, could display a hint but most common is a function call / script execution) as the back-end stuff. Here, you do all your lbSetData, setVariable etc so it's there once the dialog has finished loading. The different Eventhandlers (which need to be assigned to each listbox individually) are the front-end stuff, they catch the selections made by the player. Always use _this, regardless of if you execVM or call/spawn a script, because it gives you the control (not the IDC, so you will have to use alternative syntax of many commands. More on that later) and the selected element index of the listbox. This allows you to change the structured textboxes as necessary.

 

You'll have to iterate through each listbox individually in the onLoad file, which might be a bit tricky considering you've also got multiple values you want assigned (apparently). Also, I would recommend using IDCs and not controls, as alternative syntax of many commands (so _control lbAdd "text" instead of lbAdd [_idc, "text"]) is unreliable mid-mission.

 

Here's the modified dialog code:

class Pasi_HUD {
	idd = 5500;
	movingenable = false;
	onLoad = "[] execVM 'dialog_init.sqf'";
class controlsBackground
	{
		class MainBackground: life_RscText
		{
			idc = 1600;
			x = 0.29375 * safezoneW + safezoneX;
			y = 0.313 * safezoneH + safezoneY;
			w = 0.4125 * safezoneW;
			h = 0.418 * safezoneH;
			colorBackground[] = {0,0,0,0.7};
		};
	};
	
	class controls
	{
		class RscListbox_1500: Life_RscListbox
		{
			idc = 7771;
			x = 0.304062 * safezoneW + safezoneX;
			y = 0.335 * safezoneH + safezoneY;
			w = 0.211406 * safezoneW;
			h = 0.341 * safezoneH;
			onLBSelChanged = "_this call fnc_changeText";
			
		};
		class RscButton_1601: life_RscButtonMenu
		{
			idc = 7772;
			text = "START";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {0,0,1,1};
			x = 0.613437 * safezoneW + safezoneX;
			y = 0.335 * safezoneH + safezoneY;
			w = 0.0825 * safezoneW;
			h = 0.066 * safezoneH;
		};
		class Descriptiontext: Life_RscStructuredText
		{
			idc = 7773;
			text = "";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {1,0,0,1};
			x = 0.530937 * safezoneW + safezoneX;
			y = 0.489 * safezoneH + safezoneY;
			w = 0.165 * safezoneW;
			h = 0.187 * safezoneH;
		};
		class Data: Life_RscStructuredText
		{
			idc = 7774;
			text = "";
			colorBackground[] = {0,0,0,0.7};
			colorText[] = {1,0,0,1};
			x = 0.530937 * safezoneW + safezoneX;
			y = 0.423 * safezoneH + safezoneY;
			w = 0.165 * safezoneW;
			h = 0.044 * safezoneH;
		};
	};
};

The idd can be changed as necessary up top, I just like 5500. I'd recommend setting one only if you have multiple dialogs, as you then may need to call the Pasi_HUD dialog again. The IDCs of the listboxes are extremely important, so don't set them to -1. You will need them later.

 

This is probably a really long-winded explanation that leads you nowhere but it's the best I can do atm. Morning coffee count is still only 3 after all :P 

I've done this for a mission of mine before, so if you want you can look through the code, but it's semi-complex as it uses a lot of different variables that are defined all over the place, so if it confuses you just ditch it.

https://github.com/CER10TY/Modular-Campaign/tree/master/%40M.C/addons/Module_Camp/Module_Camp/missions/HubState.VR/operatorlist

Click through there, it's a lot of functions and dialogs (and none if it is very clean).

  • Like 1

Share this post


Link to post
Share on other sites

Maybe..

ctrlSetStructuredText [7773, formatText ["%1", _x select 2]];
if you know _one, _two, _three hold the correct values.

Share this post


Link to post
Share on other sites

Ok thank you i think i have now a little more Idea about that but now i have another problem...

 

I have the hpp modified like your example.

 

this is my dialog_init.

disableSerialization;
waitUntil {!isNull findDisplay 12345};
_display = findDisplay 12345;
_list = _display displayCtrl 7771;
_ctrlOK = _display displayCtrl 7772;

lbClear _list;

private ["_job1", "_job2", "_job3"];
_One= ["One","First Text","Second Text", {hint "First Text";}];
_Two = ["Two","First Text2","Second Text2", {hint "Second Text";}];
_Three = ["Three","First Text3","Second Text3", {hint "Third Text";}];
{
private _index = _list lbAdd (_x select 0);
_list lbSetData [_index, str _index];
_list setVariable [str _index, _x select 3];
} forEach [One, Two, Three];

also i have created a new file like your fnc_changeText.

 

Here is my code but i dont undestand where i can take the variables.

I want to set the Custom Text from that 3 variables in my dialog_init but i dont now how i can call them :/

 

changeText.sqf

disableSerialization;
waitUntil {!isNull findDisplay 12345};


_Jobdata = _this select 1;
_Jobtext = _this select 2;


ctrlSetStructuredText [7773, formatText ["%1", [_Jobtext]]];
ctrlSetStructuredText [7774, formatText ["%1", [_Jobdata]]];

Share this post


Link to post
Share on other sites

disableSerialization;

waitUntil {!isNull findDisplay 12345};

_display = findDisplay 12345;

_list = _display displayCtrl 7771;

_ctrlOK = _display displayCtrl 7772;

lbClear _list;

private _jobs = [

["One","First Text","Second Text", 'hint "First Text";'], //Place code as string

["Two","First Text2","Second Text2", 'hint "Second Text";'],

["Three","First Text3","Second Text3", 'hint "Third Text";']

];

{

private _index = _list lbAdd (_x select 0);

_list lbSetData [ _index, str _x ]; //Save array as a string

} forEach _jobs;

//Add event to listbox for when selection changes

_list ctrlAddEventHandler [ "LBSelChanged", {

params[ "_ctrl", "_index" ];

//Get data from selected listbox item, call compile string back into array

_data = call compile ( _ctrl lbData _index );

_data params[ "_title", "_descShort", "_descLong", "_code" ];

//Get parent display of listbox

_display = ctrlParent _ctrl;

//Display first and second text in StructuredText boxes

( _display displayCtrl 7773 ) ctrlSetStructuredText parseText _descShort;

( _display displayCtrl 7774 ) ctrlSetStructuredText parseText _descLong;

//Call the hint code of selected index when Start button is pressed

( _display displayCtrl 7772 ) buttonSetAction _code;

}];

Share this post


Link to post
Share on other sites

Now it says that a "[" is missed ??

I think he cant read the code out of the String ?

Share this post


Link to post
Share on other sites

Sorry i just formated the code wrong, need to wrap the hint text in double quotes

private _jobs = [
	["One","First Text","Second Text", 'hint ""First Text"";'], //Place code as string
	["Two","First Text2","Second Text2", 'hint ""Second Text"";'],
	["Three","First Text3","Second Text3", 'hint ""Third Text"";']
];

Share this post


Link to post
Share on other sites

WOW :D Nice thank you now it Works

 

Top Support :)

 

thank you Iarrow and tryteyker :)

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

×