Adventure Game Studio | Forums

AGS Support => Modules, Plugins & Tools => Topic started by: Monsieur OUXX on Tue 11/02/2014 16:41:51

Title: MODULE: StandaloneClick 1.0 - GUI clicks and hovering, WITHOUT the global script
Post by: Monsieur OUXX on Tue 11/02/2014 16:41:51
This is one of those modules that you won't understand at first glance why they can be very useful.

Imagine this : You need to intercept a click on a GUI Control. That happens every day. You can just use the AGS Editor, go to the "Events" pane of your GUI, and bind a custom script to "OnClick". AGS will create automatically a little function in the global script, where you can put all the custom instructions you need.

BUT now imagine that your favorite hobby in life is to release modules for AGS. Modules that come with their own little custom Gui. (for the example's sake: imagine you want to release a "custom saved games" gui: you'll need to release both the Gui and the module that controls it).

Problem: all the binding you did in the global script doesn't get exported alongside the .guf and .scm files. It can quickly get annoying to explain in the readme how to recreate all that got lost. You could retort: "to circumvent this, I export a demo game with both the gui and the module". Well, there are still situations where that's not satisfactory.

Now imagine this: on top of it, you want to implement a small hovering function (that is, when the mouse is over a control, you get the feedback somewhere).
It's very easy to code manually in your custom module. But it can quickly become a mess if you have many controls. Same thing for intercepting the clicks the way this module does it. Anybody can do it. But it's better if it's done once and for all, and moved out of your critical module.

Hence, this module. Import it in your project, and then use it as follows :

Code (ags) Select

// 1) Create your very own module
// 2) Create your very own Gui, with any kind of control. For example:
//      - a label called "MyLabel". You want to track the clicks on that one
//      - another label called "StatusLine" where you want displayed the control being hovered
// 3) In your module's initialization, add this :
//      StandaloneClick.RegisterControl(MyLabel,  "this text will appear when the label is hovered");   
// 4) In your module's repeatedly_execute_always(), add this:
//        if (StandaloneClick.ClickDetected(eMouseLeft)) {
//           GUIControl* c = StandaloneClick.GetClick(eMouseLeft);
//           if (c==MyLabel)
//             Display("you clicked on MyLabel with the left mouse button");
//        }
//
//        StatusLine.Text = StandaloneClick.GetHoveredText();
//
// 5) Run the game. Click on your label, and move your mouse over it.




Download module only (.scm) (https://www.dropbox.com/s/mjl2fap64ilyvak/standaloneClick1.1.scm)
Download demo game (https://www.dropbox.com/s/f5d9n020n8q8rrp/standaloneclick_demo%201.1.zip)


EDIT : version 1.1
  - added "ClickDetected" to avoid confusing the absence of click with an actual click on nothing