LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Interface Requests (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=5)
-   -   A request for all plugin authors (https://www.lotrointerface.com/forums/showthread.php?t=1515)

Fortunis 06-02-2011 10:40 AM

self.myplugin was changed.
writeline i placed in a few places. before, in and after IF statement (nothing)
writeline placed outside this function ( i got spammed )
This function is defined in the update part of the LUA, which gets called alot.
SetWantsKeyEvents havnt been used

Digital_Utopia 06-02-2011 11:55 AM

Quote:

Originally Posted by Garan (Post 6566)
Digital_Utopia's example has two small typos, where it says ":setVisible" it needs to be ":SetVisible" and "isVisible" should be "IsVisible"

aaand fixed. I will keep my opinions about starting off function names with uppercase letters to myself :p

Digital_Utopia 06-02-2011 12:01 PM

Quote:

Originally Posted by Fortunis (Post 6570)
SetWantsKeyEvents havnt been used

And that is likely the problem. Anything you want to respond to key events needs to call SetWantsKeyEvents(true).

so in the case of my original example, you would need to precede it with the following line for it to work:

Code:

self.SetWantsKeyEvents(true);
Otherwise, just like handling mouse events, or update events, if you don't call the appropriate "SetWants" function to set it to true- the event will never fire.

Fortunis 06-02-2011 12:12 PM

K, thanks. Ill give that a go then :)

Fortunis 06-02-2011 01:16 PM

Ok, i got it to work and tweaked it to do everything i need it to for Mouse Cursor Highlighter Advanced.

Decided to post my part of the code for others to get an idea of what to add/do..
  • OptionsWindow is the menu window
  • mcha is the mouse cursor highlighter
  • WasOn and WasOnn are variables to help the code know that they were on previously, so they appear when F12 brings the UI back to visible.
The two IF statement parts at the bottom (outside the function) couldnt be introduced into the function code as this contradicted each other and caused either the option window to stay on even after trying to close it via the cross in its upper right, or do a few other anomolies.

Code:

self:SetWantsKeyEvents(true);
   
    self.KeyDown = function(sender,args)
   
        if (args.Action == 268435635)then
            if(OptionsWindow:IsVisible() == true)then
                WasOn = 1;
            elseif WasOn == 1 then
                OptionsWindow:SetVisible(true);
                WasOn = 0;
            end
            if(mcha:IsVisible() == true)then
                WasOnn = 1;
            elseif WasOnn == 1 then
                WasOnn = 0;
            end
        end
   
    end
   
    if WasOn == 1 then
        OptionsWindow:SetVisible(false);
    end
   
    if WasOnn == 1 then
        mcha:SetVisible(false);
    else
        mcha:SetVisible(true);
    end


Emberleaf 06-05-2011 08:58 AM

Quote:

Originally Posted by Garan (Post 6566)
MoorMap has had this functionality for many months, as has AltInventory..

Well...I feel dumb now. :P

Thanks for clueing me in, Garan! Your plugin is insanely awesome!!

Equendil 07-13-2011 12:15 PM

In case it helps, I'm using the following in my plugins, so I can manage my windows generically for F12 and Escape (the actual version I use also handles CTRL+\ for my drag bars, but I stripped that here):

Code:

import "Turbine.UI";

-- WindowManager lets us handles HUD toggling ("F12") and 'Escape" actions in a global manner
-- Managed windows will be made visible/invisible/closed based on those events.

-- WindowManager is a global unique instance

-- Actions not defined in Turbine.UI.Lotro.Action
local ActionToggleDisplay = 0x100000B3;

-- local class, we don't want anyone else to reify this
local Manager = class( Turbine.UI.Window );
function Manager:Constructor()
        Turbine.UI.Window.Constructor( self );

        -- weak table so we don't prevent windows from being garbage collected
        self.windows = setmetatable({}, {__mode="k"});
        self.closeableWindows = setmetatable({}, {__mode="k"});
       
        -- status
        self.visibleHUD = true;
       
        -- action handler
        self:SetWantsKeyEvents(true);
        self.KeyDown = function( sender, args )
                if args.Action == ActionToggleDisplay then -- toggle display
                        -- if the display was visible, save the visibility status of managedwindows
                        if self.visibleHUD then
                                for window, visible in pairs( self.windows ) do
                                        self.windows[window] = window:IsVisible()
                                end
                        end
                       
                        self.visibleHUD = not self.visibleHUD;
                       
                        -- update visibility of all managed windows
                        for window, visibility in pairs( self.windows ) do
                                window:SetVisible( self.visibleHUD and visibility );
                        end
                elseif args.Action == Turbine.UI.Lotro.Action.Escape then
                        for window, v in pairs( self.closeableWindows ) do
                                window:Close();
                        end
                        return;
                end
        end
end

-- manage a window
function Manager:ManageWindow( window, closeOnEscape )
        self.windows[window] = window:IsVisible();
        window:SetVisible( self.visibleHUD and window:IsVisible() );
       
        if closeOnEscape == nil or closeOnEscape == true then -- default = close on escape
                self.closeableWindows[window] = true;
        end
end

function Manager:IsGUIVisible()
        return self.visibleHUD;
end

-- create a unique instance of the window manager
WindowManager = Manager();

I then only have to call WindowManager:ManageWindow( window, <closeOnEscape> ) in my plugins, to have windows be made invisible/visible on F12 and be closed on ESC if <closeOnEscape> is true (or nil, default behaviour).

Note: I use weak references to 'managed' windows so as to not prevent the garbage collector from getting rid of unused windows.


All times are GMT -5. The time now is 08:08 AM.

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