interface_click

Started by Monsieur OUXX, Mon 14/12/2015 18:09:57

Previous topic - Next topic

Monsieur OUXX

So, at the moment:
- you can intercept a click in the room from somewhere else then the global script (add on_mouse_click in the Room script)
- you CANNOt intercept a click on a Gui or Gui button from somewhere else than the global script (except by umaking some tedious module that duplicates the coordinates and Z-order calculations)

That's really annoying. If you have many buttons in your gui, you have to create the even for ALL of them, and then add scripting in the global script for all of them.

Old function interface_click was allowing exactly that: intercept the click on a Button, but then process it wherever you like it (namely : a custom script).

How hard would it be to put it back?

 

Crimson Wizard

#1
An "interface_click" still works; if it did not, old games would not work with current engine.

It is called for buttons that do not have any event handlers, but it is only run in global script.
Upon testing this in AGS 2.72 I found that it worked same way.

If "interface_click" in global script is all you wanted, then no changes to AGS are required...


Quote from: Monsieur OUXX on Mon 14/12/2015 18:09:57If you have many buttons in your gui, you have to create the even for ALL of them, and then add scripting in the global script for all of them.
This is not precisely true, you may also have 1 handler for all buttons, and then delegate actual handling to custom script.
This will work almost same way as interface_click, except you still have to input the handler's name into every button property.

Monsieur OUXX

Quote from: Crimson Wizard on Tue 15/12/2015 10:12:29
you may also have 1 handler for all buttons, and then delegate actual handling to custom script.
This will work almost same way as interface_click, except you still have to input the handler's name into every button property.
I don't understand. Can you explain?
 

Crimson Wizard

Quote from: Monsieur OUXX on Tue 15/12/2015 17:24:41
Quote from: Crimson Wizard on Tue 15/12/2015 10:12:29
you may also have 1 handler for all buttons, and then delegate actual handling to custom script.
This will work almost same way as interface_click, except you still have to input the handler's name into every button property.
I don't understand. Can you explain?


Well, you may define 1 function in global script like:
Code: ags

function OnAnyButtonClick(GUIControl *control, MouseButton button)
{
}

And put this name into Events pane of every button. This will work practically same way as interface_click, with just more work, but on the other hand you will get button pointer and mouse button instead of GUI and button numeric Ids.

Monsieur OUXX

Oh, OK, I never noticed that the event handler actually received a pointer to the control that triggered it.
 

SMF spam blocked by CleanTalk