Adventure Game Studio

AGS Development => Engine Development => Topic started by: Crimson Wizard on Tue 18/11/2014 11:29:47

Title: Click/RunInteraction extension to script API
Post by: Crimson Wizard on Tue 18/11/2014 11:29:47
Hereby I state a proposal to add a bunch of clicking/interacting simulating functions to AGS, based on past user problems and suggestions.
E.g. this: http://www.adventuregamestudio.co.uk/forums/index.php?topic=48445.0

Mouse.Click(MouseButton)
Fires mouse click event. This should not do any extra tests, just make a click, as if human pressed mouse button.
For instance, this will also skip cutscenes and call on_mouse_click function.
Because of how AGS works this click will run only after current script has ended.
The click is performed at current mouse coordinates. Why: the on_mouse_click scripts use mouse.x and mouse.y to know where the click occured. If we let user define coordinates as well, the logic will be broken, so it is of little use.

ProcessClick -> Room.ProcessClick(x, y, mode)
Move global ProcessClick() function to Room class (as static method). This is not only further OO-ing, but will also make it more clear for users that this simulates only clicks on room contents (e.g. not on GUI).

GUI.ProcessClick(x, y, MouseButton)
Static method.
Simulates a mouse click on screen, but affects only GUI, as opposed to old (Room.)ProcessClick.
This should simulate click on GUI frames and their controls at given position.

GUI.Click(MouseButton), GUIButton.Click(MouseButton)
Object method.
Triggers OnClick event on GUI or GUIButton, if it is present. Compareable to RunInteraction.
Because of how AGS works the event functions will run only after current script has ended. RunInteraction() does the same. You may, however, queue multiple Clicks.
Title: Re: Click/RunInteraction extension to script API
Post by: Gurok on Tue 18/11/2014 11:43:06
I applaud the change from ProcessClick->Room.ProcessClick
Should GUI.OnClick() and GUIControl.OnClick() take a parameter for mouse button?
I understand you're following C# style syntax with OnClick, but to be honest, GUI.Click() and GUIControl.Click() are more immediately grokkable to me.
Title: Re: Click/RunInteraction extension to script API
Post by: Crimson Wizard on Tue 18/11/2014 11:56:50
Quote from: Gurok on Tue 18/11/2014 11:43:06
Should GUI.OnClick() and GUIControl.OnClick() take a parameter for mouse button?
Right, OnClick event has mouse button argument, so they shoould.

Quote from: Gurok on Tue 18/11/2014 11:43:06
I understand you're following C# style syntax with OnClick, but to be honest, GUI.Click() and GUIControl.Click() are more immediately grokkable to me.
No, I do not follow C# syntax... what is C# syntax? :)
Might go without "On" prefix, since this is not a delegate nor function pointer.
Title: Re: Click/RunInteraction extension to script API
Post by: Dualnames on Tue 18/11/2014 19:04:18
Please do implement that!
Title: Re: Click/RunInteraction extension to script API
Post by: Crimson Wizard on Sat 22/11/2014 22:50:00
Done, here's demo build:
http://www.mediafire.com/download/juxme6u8zds54uf/AGS-3.4.0.1--guiclicks-demo.zip
Code branch: https://github.com/ivan-mogilko/ags-refactoring/tree/feature-scapi-clicks

Based on 3.4.0.1 (.0.2 compilation has errors so I used lower version).
This will get to 3.4.0.3 release when its ready.

UPD: replaced package, fixing GUI.ProcessClick not activating inventory items.
Title: Re: Click/RunInteraction extension to script API
Post by: Monsieur OUXX on Mon 24/11/2014 12:09:39
Yes, yes, triple yes!

About the Click/OnClick debate: Is the function meant to simulate a click (as if the user clicked), or intercept a click?
If you simulate a click, then it sould be "Click". If you want to intercept a click and script some actions accordingly, it should be "OnClick"
Title: Re: Click/RunInteraction extension to script API
Post by: abstauber on Wed 03/12/2014 07:05:23
Whoops, almost forgot to add some praise to this thread. Hooray :D
Could this already make an appearance in AGS 3.4.0.3?
Title: Re: Click/RunInteraction extension to script API
Post by: Crimson Wizard on Wed 03/12/2014 13:07:59
Quote from: abstauber on Wed 03/12/2014 07:05:23
Whoops, almost forgot to add some praise to this thread. Hooray :D
Could this already make an appearance in AGS 3.4.0.3?
Yes, its already added to our code.
For 3.4.0.3 I will also add dialog extensions, but in order to release it we'd need fixes to monkey_05_06's Editor code. He seem to be busy with his school recently, but if he won't manage I'll try to make fixes myself.
Title: Re: Click/RunInteraction extension to script API
Post by: Dualnames on Sat 06/12/2014 23:41:41
So if i set mouse.position and use mouseclick, will it work perfectly as if i clicked myself on that position?
Title: Re: Click/RunInteraction extension to script API
Post by: Crimson Wizard on Sun 07/12/2014 00:17:49
Quote from: Dualnames on Sat 06/12/2014 23:41:41
So if i set mouse.position and use mouseclick, will it work perfectly as if i clicked myself on that position?
Yes it should.
It uses same technique as Plugin API's SimulateMouseClick.