Jump to content
M1ke_SK

[solved] close dialog created with script

Recommended Posts

I have code where I crate dialog via script. I set action to close dialog for button _ctrl_button_close.

disableSerialization;

_ctrl_background = (findDisplay 46) ctrlCreate ["RscPicture", -1];
_ctrl_background ctrlSetPosition [0.438124 * safezoneW + safezoneX, 0.445 * safezoneH + safezoneY, 0.12375 * safezoneW, 0.11 * safezoneH];
_ctrl_background ctrlSetText "#(rgb,8,8,3)color(0,0,0,0.5)";
_ctrl_background ctrlCommit 0;

_ctrl_button_give = (findDisplay 46) ctrlCreate ["RscButton", -1];
_ctrl_button_give ctrlSetPosition [0.469062 * safezoneW + safezoneX, 0.511 * safezoneH + safezoneY, 0.061875 * safezoneW, 0.022 * safezoneH];
_ctrl_button_give ctrlSetText "GIVE";
_ctrl_button_give ctrlCommit 0;

_ctrl_button_close = (findDisplay 46) ctrlCreate ["RscButton", -1];
_ctrl_button_close ctrlSetPosition [0.551562 * safezoneW + safezoneX, 0.445 * safezoneH + safezoneY, 0.0103125 * safezoneW, 0.022 * safezoneH];
_ctrl_button_close ctrlSetText "X";
_ctrl_button_close buttonSetAction "closeDialog 0";
_ctrl_button_close ctrlCommit 0;

_ctrl_edit = (findDisplay 46) ctrlCreate ["RscEdit", -1];
_ctrl_edit ctrlSetPosition [0.45875 * safezoneW + safezoneX, 0.467 * safezoneH + safezoneY, 0.0825 * safezoneW, 0.022 * safezoneH];
_ctrl_edit setText "0";
_ctrl_edit ctrlCommit 0;

Problem: Can't close dialog with ESC key or close button (x).

 

Question: How to close dialog created with script?

 

 

Share this post


Link to post
Share on other sites

There is set action for button

 

_ctrl_button_close buttonSetAction "closeDialog 0";

But I cannot click on button or close it with ESC key.

Share this post


Link to post
Share on other sites

The problem is you are using the main game display 46. You'll have to destroy the controls one by one again with ctrlDelete.

 

For example:

disableSerialization;
{ctrlDelete _x} forEach [_ctrl_background, _ctrl_button_give, _ctrl_button_close, _ctrl_edit];

To close with escape: When you are creating your controls you can add an display eventhandler:

(findDisplay 46) displayAddEventHandler ["KeyDown", {if  ((_this select 1) == 1) then {/*Your code to close display*/}}];

Be careful to only add this EH once

Share this post


Link to post
Share on other sites
36 minutes ago, 7erra said:

The problem is you are using the main game display 46. You'll have to destroy the controls one by one again with ctrlDelete.

 

For example:


disableSerialization;
{ctrlDelete _x} forEach [_ctrl_background, _ctrl_button_give, _ctrl_button_close, _ctrl_edit];

To close with escape: When you are creating your controls you can add an display eventhandler:


(findDisplay 46) displayAddEventHandler ["KeyDown", {if  ((_this select 1) == 1) then {/*Your code to close display*/}}];

Be careful to only add this EH once

 

so I set IDCs for controls and added displayEventHandler

 

But I cannot enter value into RscEdit or interact with dialog.

 

disableSerialization;

_ctrl_background = (findDisplay 46) ctrlCreate ["RscPicture", 7001];
_ctrl_background ctrlSetPosition [0.438124 * safezoneW + safezoneX, 0.445 * safezoneH + safezoneY, 0.12375 * safezoneW, 0.11 * safezoneH];
_ctrl_background ctrlSetText "#(rgb,8,8,3)color(0,0,0,0.5)";
_ctrl_background ctrlCommit 0;

_ctrl_button_give = (findDisplay 46) ctrlCreate ["RscButton", 7002];
_ctrl_button_give ctrlSetPosition [0.469062 * safezoneW + safezoneX, 0.511 * safezoneH + safezoneY, 0.061875 * safezoneW, 0.022 * safezoneH];
_ctrl_button_give ctrlSetText "GIVE";
_ctrl_button_give ctrlCommit 0;

_ctrl_button_close = (findDisplay 46) ctrlCreate ["RscButton", 7003];
_ctrl_button_close ctrlSetPosition [0.551562 * safezoneW + safezoneX, 0.445 * safezoneH + safezoneY, 0.0103125 * safezoneW, 0.022 * safezoneH];
_ctrl_button_close ctrlSetText "X";
_ctrl_button_close buttonSetAction "{ ctrlDelete ( (findDisplay 46) displayCtrl _x ); } forEach [7001, 7002, 7003, 7004];";
//_ctrl_button_close buttonSetAction "closeDialog 0";
_ctrl_button_close ctrlCommit 0;

_ctrl_edit = (findDisplay 46) ctrlCreate ["RscEdit", 7004];
_ctrl_edit ctrlSetPosition [0.45875 * safezoneW + safezoneX, 0.467 * safezoneH + safezoneY, 0.0825 * safezoneW, 0.022 * safezoneH];
_ctrl_edit ctrlSetText "0";
_ctrl_edit ctrlCommit 0;

my_custom_display_event_handler = (findDisplay 46) displayAddEventHandler [
	"KeyDown", 
	{
		 params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];

		 if (_dikCode == 1 && !_shift && !_ctrlKey && !_alt) then 
		 {
			{ ctrlDelete ( (findDisplay 46) displayCtrl _x ); } forEach [7001, 7002, 7003, 7004];
		 };
		 (findDisplay 46) displayRemoveEventHandler ["KeyDown", my_custom_display_event_handler];
	}
];

 

Share this post


Link to post
Share on other sites

Yeah because you are using a display as a base, not a dialog. Displays let you keep control over your mouse. You'd have to create a dialog for that. :f:

Share this post


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

Yeah because you are using a display as a base, not a dialog. Displays let you keep control over your mouse. You'd have to create a dialog for that. :f:

 

Is there a way to create dialog via script? How to use that ?

 

createDialog "MyCustomDialog";

 

Share this post


Link to post
Share on other sites

Yes. You have to define a dialog in the description.ext. Then you can call it with 

createDialog "YOUR_DIALOG";

I recommend doing some research on that topic because it is a bit more difficult. I also recomend the tutorial by Iceman77. If you are using this method you can also use

53 minutes ago, Grumpy Old Man said:

I'd take an educated guess and suggest the usage of closeDialog.

 

Cheers

and many more things. I've spent some time on dialogs because they are such a nice and versatile thing to have while also being a pain in the private parts.

 

On the other hand you could just create an empty dialog:

descritption.ext:

class YOUR_DIALOG
{
  idd = 1752; // Whatever number you like
  movingenable = 0;


  class controlsBackground
  {

  };
  class controls
  {

  };
};

This will give you control over you mouse and then you can create your controls. Remember to create your controls on the base of this dialog now and not display 46. In this case it would be 

_yourDialog = findDisplay 1752;

 

Share this post


Link to post
Share on other sites
2 minutes ago, 7erra said:

Yes. You have to define a dialog in the description.ext. Then you can call it with 


createDialog "YOUR_DIALOG";

I recommend doing some research on that topic because it is a bit more difficult. I also recomend the tutorial by Iceman77. If you are using this method you can also use

and many more things. I've spent some time on dialogs because they are such a nice and versatile thing to have while also being a pain in the private parts.

 

On the other hand you could just create an empty dialog:

descritption.ext:


class YOUR_DIALOG
{
  idd = 1752; // Whatever number you like
  movingenable = 0;


  class controlsBackground
  {

  };
  class controls
  {

  };
};

This will give you control over you mouse and then you can create your controls. Remember to create your controls on the base of this dialog now and not display 46. In this case it would be 


_yourDialog = findDisplay 1752;

 

 

I am familiar with creating dialogs in description.ext. But I am wondering if there is way to create dialog without defining it in description.

Share this post


Link to post
Share on other sites

You could createDialog one of the vanilla dialogs and add your own controls to it.
Like:

createDialog "RscDisplayHintC";
_disp = findDisplay 57;
{_x ctrlshow false;_x ctrlEnable false} foreach (allcontrols _disp);

ctrlcreate blah blah

 

  • Like 2

Share this post


Link to post
Share on other sites
33 minutes ago, Greenfist said:

You could createDialog one of the vanilla dialogs and add your own controls to it.
Like:


createDialog "RscDisplayHintC";
_disp = findDisplay 57;
{_x ctrlshow false;_x ctrlEnable false} foreach (allcontrols _disp);

ctrlcreate blah blah

 

 

Excellent !

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

×