We have detected that cookies are not enabled on your browser. Please enable cookies to ensure the proper experience.
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Location
    Evernight
    Posts
    83

    Question How to hide a window on F12?

    For some reason the windows I created do not hide while pressing F12. Do I need to register to an event or so?

  2. #2
    Join Date
    Mar 2007
    Posts
    1,168
    This is something I have been meaning to add to my thread on writing plugins for noobs. Key press handling is a bit awkward in LotRO's implementation because the key events are not actually fired by key presses (we can not actually detect the pressing of a specific key), rather they are fired when the game engine performs a specific action, such as toggling the HUD. These actions are not hardwired to a specific key, but are associated with keys through the Keybinding section of the game Options. So, what you are really looking for is how to hide your window in response to the "Toggle HUD" action (which is by default associated with F12, but end users can remap the key mapping). While this may take a bit of getting used to, it prevents needing to know what the key bindings are. I just wish the events had been more appropriately named, such as "control.Action" rather than the confusing "control.KeyDown"

    To do this, you first have to have a control that has key events enabled. Below is a simple example with a window control called sampleWindow. In addition to not being able to detect an actual key stroke, we also can not detect the HUD state so we have to assume that the HUD is displayed when the plugin is loaded and track the state from there ourselves. I also include the related ability to hide the window in response to the Escape event (so called since it is usually bound to the Esc key). Notice that the Escape event is defined in the Turbine.UI.Lotro.Action enumeration but the Hud toggle event is not.

    Code:
    hudVisible=true; -- the actual HUD state is not exposed to Lua so we have to assume the HUD is visible when the plugin loads
    sampleWindowVisible=true; -- used to retain the state of the window for when the HUD is toggled back on
    sampleWindow=Turbine.UI.Lotro.Window()
    sampleWindow.KeyDown=function(sender, args)
      if ( args.Action == Turbine.UI.Lotro.Action.Escape ) then -- hide the window due to Escape
        sampleWindow:SetVisible( false );
      elseif ( args.Action == 268435635 ) then -- toggle HUD (the HUD action is not defined in the Turbine.UI.Lotro.Action enumeration although it should be)
        hudVisible=not hudVisible;
        if hudVisible then
          sampleWindow:SetVisible(sampleWindowVisible);
        else
          sampleWindowVisible=sampleWindow:IsVisible();
          sampleWindow:SetVisible(false);
        end
      end
    end
    
    sampleWindow:SetWantsKeyEvents(true); -- enable keyevents (Actions) for this control
    You can also just open the main.lua in most of my plugins and search for the key word "Escape" which will be at the beggining of the action event handler.
    Last edited by Garan; Dec 19 2012 at 03:30 PM. Reason: clarification

  3. #3
    Join Date
    Jun 2011
    Location
    Evernight
    Posts
    83
    Thanx for this and your thread on writing plugins. It helped me a lot the last few days. I'll play with this tomorrow morning.

    One question left though... I've got 10 windows drawn, does this mean I have to make all windows listen to a keypress? That sounds expensive to me. I guess it's better to create a hidden control or a custom event that will be triggered when needed and all windows can attach to that. If that makes sense.

    Other solution would be to rewrite the plugin and use only 2 windows.

  4. #4
    Join Date
    Mar 2007
    Posts
    1,168
    Quote Originally Posted by roufneck View Post
    Thanx for this and your thread on writing plugins. It helped me a lot the last few days. I'll play with this tomorrow morning.

    One question left though... I've got 10 windows drawn, does this mean I have to make all windows listen to a keypress? That sounds expensive to me. I guess it's better to create a hidden control or a custom event that will be triggered when needed and all windows can attach to that. If that makes sense.

    Other solution would be to rewrite the plugin and use only 2 windows.
    Fewer event handlers is usually better. Many of my plugins only have one handler for key events in the main window which tracks and controls the visibility of all other windows. There are of course exceptions and it all depends on your plugin's design and needs.

  5. #5
    Join Date
    Jun 2011
    Location
    Evernight
    Posts
    83
    Thanx. It's working. I made a hidden control that is listening to key presses and delegates to the other windows if needed.

    Is there also an action for alt+enter (changing to full screen and window mode) or even better... Detecting game window resize. Would be nice if the plugin replace the windows when the screen size changes.

  6. #6
    Join Date
    Mar 2007
    Posts
    1,168
    Quote Originally Posted by roufneck View Post
    Thanx. It's working. I made a hidden control that is listening to key presses and delegates to the other windows if needed.

    Is there also an action for alt+enter (changing to full screen and window mode) or even better... Detecting game window resize. Would be nice if the plugin replace the windows when the screen size changes.
    Unfortunately there does not seem to be any way to detect Display changes. It would be great if the Turbine.UI.Display object supported a .Changed event but it currently does not.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

This form's session has expired. You need to reload the page.

Reload