LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Interface Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=3)
-   -   Trouble with window not triggering events (https://www.lotrointerface.com/forums/showthread.php?t=3654)

gillothrin 04-17-2017 08:28 AM

Trouble with window not triggering events
 
Hello,

I'm having trouble with Lotro.UI.Window events. I understand that there's some sort of caveat here but I seem to miss it.

Code:

MyWindow = class(Turbine.UI.Window());
function MyWindow:Constructor()
        Turbine.UI.Window.Constructor(self);       
        self.defaultWidth = 220;
        self.defaultHeight = 100;
        self:SetMinimumHeight(self.defaultHeight);
        self:SetSize(self.defaultWidth, self.defaultHeight);
        self:SetMouseVisible(true);
        self:SetWantsUpdates(true); -- seems like it doesn't do anything
        local bbg = Turbine.UI.Color(rgb(7),rgb(32),rgb(71));
        self:SetBackColor( bbg );
        self:SetPosition(100,100);
        self:SetVisible(true);
        Turbine.Shell.WriteLine((Dump(self.MouseDownHandler));
        --self.MouseDown = function(s,a) debug("MouseDown"); end; -- not working
        self.MouseDown = self.MouseDownHandler; -- not working
end

function MyWindow:MouseDownHandler(s,a)
        Turbine.Shell.WriteLine("MouseDownHandler");
end
--Not working either
--function MyWindow:MouseDown(s,a)
--        Turbine.Shell.WriteLine("MouseDown");
--end

So it paints but there are no events recorded. However any added control to the window works fine. To make sure that the windows answers, do I have to make sure it has a "shadow" control to get the events?

TIA

Thurallor 04-17-2017 11:52 AM

First, remove the "()" after Turbine.UI.Window in the first line. You're not deriving MyClass from an instance of Turbine.UI.Window, but from the class itself.

Second, if you've set "SetWantUpdates(true)", then you need to define an Update event handler, which will be called at each "tick".

Third, your MouseDown event handler won't get its arguments correctly:

Code:

function MyWindow:MouseDownHandler(s,a)
Since you used the ":" notation, the first argument will be silently consumed and assigned to the "self" local variable. You should remove the explicit "s" argument, so the arguments you want will go into "a".

Edit: In case it's not obvious, you also need to create an instance of MyWindow. Add "m = MyWindow();" at the end of your code.

gillothrin 04-17-2017 01:35 PM

The '()' I found out on my own, must have been a typo. Removed that and now it works fine.

The SetWantUpdates(true) was good information, perhaps good to get whats going on in the controls.

And good to know about the event arguments too.

Still struggeling with other aspects but thank you for you reply :)

Garan 04-19-2017 09:27 AM

You should probably work your way through the thread:
https://www.lotro.com/forums/showthr...gins-for-Noobs

it covers all of the basics from HelloWorld to more sophisticated issues such as event handling and cross Apartment communication with a number of code samples. You can also learn a lot from taking apart other plugins and experimenting.

While the thread is a bit old, it's still totally relevant, especially since the API hasn't changed in years (the last update was in November 2014) and according to SSG is not likely to ever get updated again. It was implemented as a volunteer "pet" project of a couple of Turbine devs, none of whom still work for SSG and SSG doesn't have the resources or the inclination to research the existing implementation in order to enhance it.

Thurallor 04-19-2017 10:19 AM

I second Garan's suggestion. That's how I started, and it was very helpful.

That guide, along with the Lua 5.1 manual and the API reference, is all you really need.


All times are GMT -5. The time now is 06:41 PM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI