Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: monkey0506 on Sat 28/08/2010 17:09:31

Title: Editor plugin API - Update autocomplete? (precompile, events, room scripts..)
Post by: monkey0506 on Sat 28/08/2010 17:09:31
CJ told me off for using reflection to access things that aren't directly exposed in the plugin API, so I have a question. Is there any sort of precompile event exposed?

Also, I'm curious whether there's any way to access AGS event handler names, specifically for GUI event handlers. I don't need to invoke them (which I know editor plugins can't do of course), I just need to know the names. If possible, getting the parameter list as well would be nice.

I didn't see anything like either of these, but I just wanted to be sure I haven't overlooked anything.

The reason I'm asking for these specifically is that I've found a way to generically simulate clicks on GUIs from any script. It requires two helper functions, and the execution is delayed, but it works. Using data vectorization I can ensure that any simulated clicks called are run back in the correct order.

One of the helper functions directly references the event handler functions (this is why I need to know the function names) in the global script. The other is on_call in the room script.

The reason I want a precompile event is so that if the on_call function does not exist, or does have the required references, they can be added at compile time.

Delayed execution may not be optimal, true, but I think people might still find it useful to simulate GUI clicks outside of the GlobalScript (and later scripts).
Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: Calin Leafshade on Sat 28/08/2010 17:12:29
under what circumstances would a developer want to simulate a gui click?

you just refactor the click function into a seperate function and call that.
Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: monkey0506 on Sat 28/08/2010 17:47:45
The idea of this was to avoid having to move the handling code out of the global script. Developers might want to simulate GUI clicks for the exact same reasons they might ever use ProcessClick. I myself have used it when using the keyboard to control the cursor. As it stands you couldn't possibly do this outside of the global script without having to move the handling code (unless you import the functions into the room script or some such).

It's been requested many times that the event handlers could be moved to a different script directly in which case the need for the helper functions would be nulled, but a generic GUI.Click(MouseButton) method is still as useful as ProcessClick and InventoryItem.RunInteraction.
Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: Dualnames on Sat 28/08/2010 18:07:15
Quote from: Calin Leafshade on Sat 28/08/2010 17:12:29
under what circumstances would a developer want to simulate a gui click?

you just refactor the click function into a seperate function and call that.

Cause it would make the Cat lady interface keyboard-controlled coding 10000000000000000000% easier if that function existed. I would have just used a Process Click instead of all the other things.
Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: monkey0506 on Sat 28/08/2010 19:36:12
It would be technically possible to script a game-specific GUI.Click method like:

// TopScript.asc

void Click(this GUI*, MouseButton button) {
  if (this == gGui1) {
    // blah
  }
  else if (this == gGui2) {
    // blah
  }
}

// GlobalScript.asc

function gGui1_OnClick(MouseButton button) {
  gGui1.Click(button);
}

function gGui2_OnClick(MouseButton button) {
  gGui2.Click(button);
}


The thing I'm trying to effect is a generic function. Even if it just meant using an editor plugin to move the code at compile-time, that could still be managed generically.
Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: Pumaman on Sun 29/08/2010 16:52:22
Quote from: monkey_05_06 on Sat 28/08/2010 17:09:31
CJ told me off for using reflection to access things that aren't directly exposed in the plugin API, so I have a question. Is there any sort of precompile event exposed?

Not at the moment, no. I'll look into it for a future version.

QuoteAlso, I'm curious whether there's any way to access AGS event handler names, specifically for GUI event handlers. I don't need to invoke them (which I know editor plugins can't do of course), I just need to know the names. If possible, getting the parameter list as well would be nice.

Yes, this is accessible.

The IAGSEditor.CurrentGame.GUIs collection has all the GUIs in it, if the GUI is a normal GUI (rather than a Text Window) then it has an OnClick property (which is the only event that a GUI exposes):

            foreach (GUI gui in _editor.CurrentGame.GUIs)
            {
                NormalGUI normalGui = gui as NormalGUI;
                if (normalGui != null)
                {
                    string onClickHandler = normalGui.OnClick;
                    // TODO: use the onClick handler name
                }
            }

Title: Re: Editor plugin API - Precompile game and finding event handler names
Post by: monkey0506 on Sun 29/08/2010 17:33:24
Thanks CJ. There's not by chance a presave event is there? Seeing as the game is saved prior to every compilation. I presume you'd have mentioned it, but just wanted to be totally sure.

D'oh! It's been a bit since I was looking at the plugin API. There's the IEditorComponent.BeforeSaveGame event. That may actually be sufficient for my needs then..:=
Title: Re: Editor plugin API - Room scripts? (also precompile and AGS events)
Post by: monkey0506 on Fri 03/09/2010 07:26:06
Instead of creating a new thread I just thought I'd reuse this one.

I've been iterating the CurrentGame.Rooms list (which I've found to be UnloadedRooms), but whether I access it using a generic IRoom object or an UnloadedRoom object it seems that the Script property is always returning null. I'm trying to access the room script files to add/update the on_call function as needed.
Title: Re: Editor plugin API - Room scripts? (also precompile and AGS events)
Post by: Pumaman on Sun 05/09/2010 14:29:55
Quote from: monkey_05_06 on Sun 29/08/2010 17:33:24
D'oh! It's been a bit since I was looking at the plugin API. There's the IEditorComponent.BeforeSaveGame event. That may actually be sufficient for my needs then..:=

Ah yes, that should work for your purposes :)

QuoteI've been iterating the CurrentGame.Rooms list (which I've found to be UnloadedRooms), but whether I access it using a generic IRoom object or an UnloadedRoom object it seems that the Script property is always returning null. I'm trying to access the room script files to add/update the on_call function as needed.

The room scripts aren't loaded until the user tries to access them. The IRoom interface has a LoadScript() method which you can call if the Script property is null, which will load it for you.
Title: Re: Editor plugin API - Room scripts? (also precompile and AGS events)
Post by: monkey0506 on Tue 07/09/2010 03:35:40
Thanks. Without any documentation it's hard to tell what some of this is intended to do. :P
Title: Re: Editor plugin API - Update autocomplete? (precompile, events, room scripts..)
Post by: monkey0506 on Wed 08/09/2010 04:53:52
The BeforeSaveGame event is working nicely so far by the way. And of course, I have another question for you.

Is there any way to update the autocomplete (currently exposed to the plugin API)? I've seen the ScriptAutoCompleteData.Populated property, but I haven't been able to find anything that would cause it to become true (noting that although in the plugin I am not using reflection, I am still using it to try and find things).

For now I've worked around it by duplicating a fair amount of code as an alternative to reflection. I've reviewed it to make sure I know exactly what it's doing so as to avoid any funny results; since I've duplicated it there's no chance of any other bindings or such.

In any case, if I've overlooked anything it would be nice if you could kindly point me in the right direction please. 8)
Title: Re: Editor plugin API - Update autocomplete? (precompile, events, room scripts..)
Post by: Pumaman on Sun 19/09/2010 19:34:13
The main IAGSEditor interface has a RebuildAutocompleteCache() method which you can use to do this.