WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Is is possible to has a OnEnter Script and propagate or unregister mouse clicks? (https://www.wowinterface.com/forums/showthread.php?t=58719)

OverCraft 05-06-21 12:04 PM

Is is possible to has a OnEnter Script and propagate or unregister mouse clicks?
 
I want to make a frame that has a OnEnter/OnLeave Script with a funciton to make a frame bigger and print more info on it, and at the same time be able to keep moving the character camera op top of the frame with the right mouse click as the frame doesn't exist.

In other words, i need to propagate mouseclicks, or unbind mouse clicks from a frame, but OnEnter Script at the same time binds the mouseclicks too.

Test code:
Code:

    local f = CreateFrame("Frame",nil,UIParent)
    f.tex = f:CreateTexture()
    f.tex:SetAllPoints(f)
    f.tex:SetColorTexture(0.5, 0.2, 1 , 0.5)
    f:SetSize(300,200)
    f:SetPoint("CENTER")
    f:SetScript ("OnEnter", function(self) print ("myfunc")  end)

With
Code:

f:SetPropagateKeyboardInput(true)
    f:EnableMouse(false)

not working and mouse isn't a keyboard :(. EnableMouse(false) removes OnEnter Script.

Making the frame a button and
Code:

f:RegisterForClicks()
void RegisterForClicks not working

I tried to manually move the camera with
Code:

f:SetScript("OnMouseDown",function (self,button) if button=="RightButton" then CameraOrSelectOrMoveStart()  end end)
f:SetScript("OnMouseUp",function (self,button) if button=="RightButton" then  CameraOrSelectOrMoveStop()  end end)

They are protected and I cannot use them

and same thing with
Code:

MouselookStart()
MouselookStop()

And I think they are not even related with the camera movement.

I got no more ideas, need some help of you. Thanks!

Xrystal 05-06-21 12:35 PM

Unfortunately OnEnter and OnLeave doesn't involve a mouse button being clicked. The frame is interactive.

However, you can register for OnMouseDown or OnMouseUp and check for a specific button being clicked to interact with the frame only on left click. However, whether that allows you to click behind it with the right mouse button is another thing. As you have been doing, all you can do is try things out. Which by the looks of your post you have tried to do.

Hopefully if someone has done what you want they can either point you to an addon that has it working for you to look at or can talk through how they did it.

As far as I am aware a frame is either interactive or non-interactive based on whether you have chosen to use the mouse with it or just using it as an overlay display like a hud.

Fizzlemizz 05-06-21 01:14 PM

You said moving the camera so this might give you something to start/work with (as currently coded, requires mouseleft to be held down to move the camera but it's up to you):
Lua Code:
  1. local f = CreateFrame("Button", "SomeOnEnterFrame", WorldFrame)
  2. f:SetSize(200, 200)
  3. f:SetPoint("TOPLEFT")
  4. f.t = f:CreateTexture()
  5. f.t:SetAllPoints()
  6. f.t:SetTexture("abc")
  7. f:RegisterForClicks("LeftButtonDown", "LeftButtonUp")
  8. f:SetScript("OnEnter", function(self)
  9.     print("Entered")
  10.     self:SetSize(400, 400)
  11. end)
  12. f:SetScript("OnLeave", function(self)
  13.     print("Left")
  14.     if self.MouseLooking or MouseIsOver(self) then
  15.         return
  16.     end
  17.     self:SetSize(200, 200)
  18. end)
  19. f:SetScript("OnClick", function(self, button, down)
  20.     if down then
  21.         if not self.MouseLooking then
  22.             self.MouseLooking = true
  23.             MouselookStart()
  24.         else
  25.             self.MouseLooking = nil
  26.             MouselookStop()
  27.         end
  28.     end
  29. end)
  30. WorldFrame:HookScript("OnMouseUp", function(self, button)
  31.     if SomeOnEnterFrame.MouseLooking then
  32.         SomeOnEnterFrame:Click(button, true)
  33.     end
  34. end)
... or not.

You can't have MouseLook "running" and interact with UI elements at the same time using the mouse.

If MouseLook gets "stuck on" while figuring out all the ins and outs you might need to address, clicking both buttons should unlock it.

OverCraft 05-06-21 02:42 PM

Quote:

Originally Posted by Fizzlemizz (Post 339044)
You said moving the camera so this might give you something to start/work with (requires mouseleft to be held down to move the camera):
Lua Code:
  1. local f = CreateFrame("Button", "SomeOnEnterFrame", WorldFrame)
  2. f:SetSize(200, 200)
  3. f:SetPoint("TOPLEFT")
  4. f.t = f:CreateTexture()
  5. f.t:SetAllPoints()
  6. f.t:SetTexture("abc")
  7. f:RegisterForClicks("LeftButtonDown", "LeftButtonUp")
  8. f:SetScript("OnEnter", function(self)
  9.     print("Entered")
  10.     self:SetSize(400, 400)
  11. end)
  12. f:SetScript("OnLeave", function(self)
  13.     print("Left")
  14.     if self.MouseLooking or MouseIsOver(self) then
  15.         return
  16.     end
  17.     self:SetSize(200, 200)
  18. end)
  19. f:SetScript("OnClick", function(self, button, down)
  20.     if down then
  21.         if not self.MouseLooking then
  22.             self.MouseLooking = true
  23.             MouselookStart()
  24.         else
  25.             self.MouseLooking = nil
  26.             MouselookStop()
  27.         end
  28.     end
  29. end)
  30. WorldFrame:HookScript("OnMouseUp", function(self, button)
  31.     if SomeOnEnterFrame.MouseLooking then
  32.         SomeOnEnterFrame:Click(button, true)
  33.     end
  34. end)
... or not.

If MouseLook gets "stuck on" while figuring out all the ins and outs you might need to address, clicking both buttons should unlock it.

Thanks a lot, i was very close to it but never heared about WorldFrame. Do you think it is possible to use rightclick to do that and leftclick with the same behaviour as WorldFrame does? clicking object, targeting units etc.. ? To be a complete transparent frame.

Fizzlemizz 05-06-21 02:45 PM

WorldFrame is where the focus goes when entering MouseLook.

Once you enter MouseLook you lose the cursor just like running using both buttons down (which is essentially a protected StartMoving + MouseLookStart).

Edit: I might have over (or under) interpreted the last question.

Fizzlemizz 05-06-21 04:29 PM

Maybe your looking for something more like:

Lua Code:
  1. local f = CreateFrame("Frame", "SomeOnEnterFrame")
  2. f:SetSize(200, 200)
  3. f:SetPoint("TOPLEFT")
  4. f.t = f:CreateTexture()
  5. f.t:SetAllPoints()
  6. f.t:SetTexture("abc")
  7. f.t:SetAlpha(0.4)
  8. f:SetScript("OnUpdate", function(self)
  9.     if MouseIsOver(self) then
  10.         if not self.BigSize then
  11.             self.BigSize = true
  12.             self:SetSize(400, 400)
  13.         end
  14.     else
  15.         if self.BigSize then
  16.             self.BigSize = nil
  17.             self:SetSize(200, 200)
  18.         end
  19.     end
  20. end)
Depending on what else you want to do with the frame.

The setting of BigSize could also include whatever you wanted to do OnEnter/OnLeave.

Vrul 05-07-21 07:14 AM

Quote:

Originally Posted by OverCraft (Post 339042)
I want to make a frame that has a OnEnter/OnLeave Script with a funciton to make a frame bigger and print more info on it, and at the same time be able to keep moving the character camera op top of the frame with the right mouse click as the frame doesn't exist.

Blizzard added that functionality awhile ago:
Lua Code:
  1. local f = CreateFrame("Frame",nil,UIParent)
  2. f.tex = f:CreateTexture()
  3. f.tex:SetAllPoints(f)
  4. f.tex:SetColorTexture(0.5, 0.2, 1 , 0.5)
  5. f:SetSize(300,200)
  6. f:SetPoint("CENTER")
  7. f:SetScript ("OnEnter", function(self) print("OnEnter")  end)
  8. f:SetScript ("OnLeave", function(self) print("OnLeave")  end)
  9. f:EnableMouse(false)
  10. f:SetMouseMotionEnabled(true)
The order of the last four lines is important. Setting a script dealing with the mouse automatically enables the mouse. So set your OnEnter/OnLeave scripts, then disable the mouse, and finally enable motion scripts only.

Xrystal 05-07-21 07:49 AM

So, even though you later disable the mouse, because you have set up the scripts it will work for those actions ? And, nice find with the SetMouseMotionEnabled function. Not seen that one yet myself.

Quote:

Originally Posted by Vrul (Post 339052)
Blizzard added that functionality awhile ago:
Lua Code:
  1. local f = CreateFrame("Frame",nil,UIParent)
  2. f.tex = f:CreateTexture()
  3. f.tex:SetAllPoints(f)
  4. f.tex:SetColorTexture(0.5, 0.2, 1 , 0.5)
  5. f:SetSize(300,200)
  6. f:SetPoint("CENTER")
  7. f:SetScript ("OnEnter", function(self) print("OnEnter")  end)
  8. f:SetScript ("OnLeave", function(self) print("OnLeave")  end)
  9. f:EnableMouse(false)
  10. f:SetMouseMotionEnabled(true)
The order of the last four lines is important. Setting a script dealing with the mouse automatically enables the mouse. So set your OnEnter/OnLeave scripts, then disable the mouse, and finally enable motion scripts only.


OverCraft 05-07-21 09:39 PM

Quote:

Originally Posted by Vrul (Post 339052)
Blizzard added that functionality awhile ago:
Lua Code:
  1. local f = CreateFrame("Frame",nil,UIParent)
  2. f.tex = f:CreateTexture()
  3. f.tex:SetAllPoints(f)
  4. f.tex:SetColorTexture(0.5, 0.2, 1 , 0.5)
  5. f:SetSize(300,200)
  6. f:SetPoint("CENTER")
  7. f:SetScript ("OnEnter", function(self) print("OnEnter")  end)
  8. f:SetScript ("OnLeave", function(self) print("OnLeave")  end)
  9. f:EnableMouse(false)
  10. f:SetMouseMotionEnabled(true)
The order of the last four lines is important. Setting a script dealing with the mouse automatically enables the mouse. So set your OnEnter/OnLeave scripts, then disable the mouse, and finally enable motion scripts only.

The @Fizzlemizz OnUpdate idea was good, but a little too agressive. This is actually the cleanest version, very nice trick :eek: Thanks everybody for the help!


All times are GMT -6. The time now is 06:53 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI