Author Topic: MODULE: StandaloneClick 1.0 - GUI clicks and hovering, WITHOUT the global script  (Read 1280 times)

Monsieur OUXX

  • Mittens Vassal
  • Cavefish
  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
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: Adventure Game Studio
  1. // 1) Create your very own module
  2. // 2) Create your very own Gui, with any kind of control. For example:
  3. //      - a label called "MyLabel". You want to track the clicks on that one
  4. //      - another label called "StatusLine" where you want displayed the control being hovered
  5. // 3) In your module's initialization, add this :
  6. //      StandaloneClick.RegisterControl(MyLabel,  "this text will appear when the label is hovered");    
  7. // 4) In your module's repeatedly_execute_always(), add this:
  8. //        if (StandaloneClick.ClickDetected(eMouseLeft)) {
  9. //           GUIControl* c = StandaloneClick.GetClick(eMouseLeft);
  10. //           if (c==MyLabel)
  11. //             Display("you clicked on MyLabel with the left mouse button");
  12. //        }
  13. //
  14. //        StatusLine.Text = StandaloneClick.GetHoveredText();
  15. //
  16. // 5) Run the game. Click on your label, and move your mouse over it.
  17.  



Download module only (.scm)
Download demo game


EDIT : version 1.1
  - added "ClickDetected" to avoid confusing the absence of click with an actual click on nothing
« Last Edit: 14 Feb 2014, 13:26 by Monsieur OUXX »