PDA

View Full Version : A request for all plugin authors


Emberleaf
05-31-2011, 02:38 PM
Hello all,

I have a (relatively) small request for all you amazing plugin authors out there. If your plugin has a visible toggle button (or any other visible aspect, really) associated with it, could you please (if possible) make it so this disappears like the rest of the UI when F12 is pressed? It would sure make taking screenshots a lot easier. I realize that I could simply unload the plugins in question, but sometimes I'm trying to capture something in a split second and...well...you get the idea.

Thanks in advance, and please keep up the awesome work!

Digital_Utopia
05-31-2011, 04:31 PM
Hello all,

I have a (relatively) small request for all you amazing plugin authors out there. If your plugin has a visible toggle button (or any other visible aspect, really) associated with it, could you please (if possible) make it so this disappears like the rest of the UI when F12 is pressed? It would sure make taking screenshots a lot easier. I realize that I could simply unload the plugins in question, but sometimes I'm trying to capture something in a split second and...well...you get the idea.

Thanks in advance, and please keep up the awesome work!

I think that's a fair request - and to help out, below is an example of how to do so:


self.KeyDown = function(sender,args)
if (args.Action == 268435635)then
if(self.myPlugin:IsVisible()==true)then
self.myPlugin:SetVisible(false)
else
self.myPlugin:SetVisible(true)
end
end
end


In this example "myPlugin" would obviously be the main window that your plugin is displayed in, and the code would exist in whatever class you generated this window in.

Now, for both the OP and other authors, there is one caveat. The action alone only tells the author whether someone has pressed the key that shows/hides the UI, with no information pertaining to the actual state of the UI at the time. Now with this (unlike UI positioning) it isn't so bad, as it is unlikely that someone would be able to load a plugin with the UI hidden. Even still, the author should provide some option to assist the user in "syncing" the plugin with the game.

MrJackdaw
05-31-2011, 04:35 PM
Or, if you use the Dragbar class - this seems to be automatic!

D.H1cks
05-31-2011, 06:06 PM
Yup, I did this for the travel window's toggle button. It is a fair request.

Emberleaf
05-31-2011, 07:09 PM
Yup, I did this for the travel window's toggle button. It is a fair request.

And I, for one, greatly appreciate it! Now, if we can get the MoorMap and Lotro Compendium plugins to follow suit, I will be one very happy little hobbit. =P

Fortunis
06-02-2011, 08:25 AM
Is this number/amount the same for all nationality of keyboard.

(args.Action == 268435635)

because i cant get it to acknowledge that the f12 key has been pressed.

Garan
06-02-2011, 10:09 AM
And I, for one, greatly appreciate it! Now, if we can get the MoorMap and Lotro Compendium plugins to follow suit, I will be one very happy little hobbit. =P

MoorMap has had this functionality for many months, as has AltInventory. Due to the fact that there is no way to detect the UI state, I've chosen not to hide the minimized button when the HUD is clear as that would innevitably lead to someone getting confused when they load their plugins with the UI already hidden (such as by binding PluginManager to a quickslot). Instead I provided the option of eliminating the minimized button and using a chat command which can be bound to a quickslot. If you go to the options and uncheck the "Show Icon When Minimized" option you can then bind the toggle command ("/moormap toggle") to a quickslot and the icon will no longer show when you use the Escape action (typically bound to Esc) or toggle the HUD (typically bound to F12). This eliminates any inconsistent behavior from the Plugin due to the fact that Turbine does not expose the state of the UI (which I really hope Turbine changes but there's MANY more important things for them to fix first).

Garan
06-02-2011, 10:13 AM
Is this number/amount the same for all nationality of keyboard.

(args.Action == 268435635)

because i cant get it to acknowledge that the f12 key has been pressed.
It's not bound to a key so keyboard and nationality are irrelevant. 268435635 is the code bound to the "toggle HUD" action which in turn is bound to a distinct keystroke in the keybindings. Go to your Options dialog (typically Ctrl+O), select "Key Mapping" on the right side, then scroll down until you see the "Toggle HUD On/Off" action entry. Whatever key is mapped to that action is what will clear your HUD and fire the KeyDown event with args.Action=268435635

Fortunis
06-02-2011, 10:19 AM
Ty for your replies. I noticed the typo and tried SetVisible and IsVisible. Also im aware of the keybind and it is F12 for me, so thats not the issue, and as youve pointed out to me that its nothing to do with a keypress signature, rather the lotro code. It leaves me wondering why it aint working for me :s

I placed a Turbine.Shell.WriteLine command in its structure but got nothing.

Garan
06-02-2011, 10:30 AM
Ty for your replies. I noticed the typo and tried SetVisible and IsVisible. Also im aware of the keybind and it is F12 for me, so thats not the issue, and as youve pointed out to me that its nothing to do with a keypress signature, rather the lotro code. It leaves me wondering why it aint working for me :s

I placed a Turbine.Shell.WriteLine command in its structure but got nothing.
And I gather you didn't take the "self.myPlugin" literally. That needs to be replaced by a reference to the actual window being affected.

Did you put the WriteLine inside the If statement or just inside the start of the function definition - if it's just inside the function, you should get responses from any action event, such as showing bags, hitting escape, etc. If you aren't getting that, then you need to check where you are defining the function and be sure you don't already have another .KeyDown function defined elsewhere for that control. Oh and be sure you didn't SetWantsKeyEvents(false) for that control.

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
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
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:


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.

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
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):

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.