Thread Tools Display Modes
08-24-19, 12:51 PM   #1
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Chat which only shows on MouseOver

Hello,

Im currently working on a mouse over chat:

Lua Code:
  1. local CORE = LybrialUI:GetCore();
  2. local FRAMES = CORE.FRAMES;
  3.  
  4. LybrialChat = LybrialUI:NewModule("Lybrial Chat", "AceHook-3.0");
  5.  
  6. local LybrialChat = LybrialChat;
  7.  
  8. LybrialChat.frame = nil;
  9. LybrialChat.chatFrames = {};
  10. LybrialChat.fadOut = true;
  11. LybrialChat.interval = 0.1;
  12. LybrialChat.elapsed = 0;
  13.  
  14. -- Lua Functions
  15. local _G = _G;
  16. local pairs = pairs;
  17.  
  18. -- WOW API
  19. local C_PetBattles = C_PetBattles;
  20. local InCombatLockdown = InCombatLockdown;
  21. local NUM_CHAT_WINDOWS = NUM_CHAT_WINDOWS;
  22. local tinsert = tinsert;
  23.  
  24. function LybrialChat:OnInitialize()
  25.     self.frame = FRAMES:CreateFrame("Frame", "LybrialUIChatFrame", FRAMES.UIParent, true);
  26.  
  27.     self:InitializeChatFrames();
  28.     self:OnUpdate();
  29. end
  30.  
  31. function LybrialChat:InitializeChatFrames()
  32.     tinsert(self.chatFrames, _G["ChatFrameChannelButton"]);
  33.     tinsert(self.chatFrames, _G["ChatFrameMenuButton"]);
  34.     tinsert(self.chatFrames, _G["QuickJoinToastButton"]);
  35.  
  36.     for _, frame in pairs(self.chatFrames) do
  37.         frame.setParent = true;
  38.     end
  39. end
  40.  
  41. function LybrialChat:OnEnable()
  42.     self.frame:SetScript("OnEnter", function(self)
  43.         self:SetMouseOverFade(true, true, true);
  44.     end);
  45.     self.frame:SetScript("OnLeave", function(self)
  46.         self:SetMouseOverFade(true, true, false);
  47.     end);
  48.     self.frame:SetScript("OnUpdate", self.GetChatFrames);
  49. end
  50.  
  51. function LybrialChat:OnUpdate()
  52.     self:OnUpdateChatFrames();
  53.     self:OnUpdateHooks();
  54. end
  55.  
  56. function LybrialChat:OnUpdateChatFrames()
  57.     for _, frame in pairs(self.chatFrames) do
  58.         if (frame.setParent) then
  59.             frame:SetParent(self.frame);
  60.         end
  61.     end
  62.  
  63.     self.frame:Show();
  64.  
  65.     if (self.fadOut) then
  66.         self.fadOut = false;
  67.         self.frame:SetMouseOverFade(true, true, false);
  68.     end
  69. end
  70.  
  71. function LybrialChat:OnUpdateHooks()
  72.     if (self.db.profile.enabled) then
  73.         for _, frame in pairs(self.chatFrames) do
  74.             self:AddMouseOverHook(frame);
  75.         end
  76.     else
  77.         for _, frame in pairs(self.chatFrames) do
  78.             self:RemoveMouseOverHook(frame);
  79.         end
  80.     end
  81. end
  82.  
  83. function LybrialChat:ValidateChatFrame(frame)
  84.     if ((not frame) or frame.isAdded) then
  85.         return false;
  86.     end
  87.  
  88.     if (not frame:IsVisible()) then
  89.         return false;
  90.     end
  91.  
  92.     return true;
  93. end
  94.  
  95. function LybrialChat:AddChatFrame(frame, setParent)
  96.     if (not LybrialChat:ValidateChatFrame(frame)) then
  97.         return ;
  98.     end
  99.  
  100.     self:AddMouseOverHook(frame);
  101.  
  102.     frame.isAdded = true;
  103.  
  104.     if (setParent) then
  105.         frame.setParent = true;
  106.     else
  107.         frame.setParent = false;
  108.     end
  109.  
  110.     tinsert(self.chatFrames, frame);
  111. end
  112.  
  113. function LybrialChat:AddMouseOverHook(frame)
  114.     if (not self:IsHooked(frame, "OnEnter")) then
  115.         self:HookScript(frame, "OnEnter", function()
  116.             LybrialChat.frame:SetMouseOverFade(true, LybrialChat.frame:IsShown(), true);
  117.         end);
  118.     end
  119.     if (not self:IsHooked(frame, "OnLeave")) then
  120.         self:HookScript(frame, "OnLeave", function()
  121.             LybrialChat.frame:SetMouseOverFade(true, LybrialChat.frame:IsShown(), false);
  122.         end);
  123.     end
  124. end
  125.  
  126. function LybrialChat:RemoveMouseOverHook(frame)
  127.     if (self:IsHooked(frame, "OnEnter")) then
  128.         self:Unhook(frame, "OnEnter");
  129.     end
  130.     if (self:IsHooked(frame, "OnLeave")) then
  131.         self:Unhook(frame, "OnLeave");
  132.     end
  133. end
  134.  
  135. function LybrialChat:GetChatFrames(elapsed)
  136.     LybrialChat.elapsed = (LybrialChat.elapsed + elapsed);
  137.  
  138.     if (LybrialChat.elapsed >= LybrialChat.interval) then
  139.         if (InCombatLockdown() or C_PetBattles.IsInBattle()) then
  140.             return ;
  141.         end
  142.  
  143.         for i = 1, NUM_CHAT_WINDOWS do
  144.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i], true);
  145.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i .. "Tab"], true);
  146.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i].ScrollBar, false);
  147.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i].ScrollToBottomButton, false);
  148.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i].FontStringContainer, false);
  149.             LybrialChat:AddChatFrame(_G["ChatFrame" .. i].ResizeButton, false);
  150.         end
  151.  
  152.         LybrialChat:OnUpdateChatFrames();
  153.         LybrialChat.elapsed = 0;
  154.     end
  155. end


This is already working quite good. There are just two things bothering me.

1. If I mouse over a chat channel name, a player name or an item name in the chat the chat
fades out. This happens because the on leave event is getting triggered. That means
channel name, player name and item name are different frames. I cant manage to find
out what frames. I need to hook them up too like I did with all the other frames.

2. In combat log there the following frame:
- CombatLogQuickButtonFrame
- CombatLogQuickButtonFrameButtonFrame1
- CombatLogQuickButtonFrameButtonFrame2
Hooking these three frames like I did with the other frames does not lead to the expected
result. So I suspect I need to hook another frame which I also cant find.

Any Chat Expert who has an idea?
  Reply With Quote
08-27-19, 02:45 AM   #2
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
A few years ago I made a similiar addon: https://github.com/Urtgard/Hide-Chat...aster/HCIC.lua

Probably not the best solution but maybe it helps.
  Reply With Quote
08-27-19, 09:23 AM   #3
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Originally Posted by Urtgard View Post
A few years ago I made a similiar addon: https://github.com/Urtgard/Hide-Chat...aster/HCIC.lua

Probably not the best solution but maybe it helps.
Yeah I found that AddOn too. Thx. However.. you do not handle those
chat channel, item links or player names in any way. Still your code works.
I did not understand why.
  Reply With Quote
08-27-19, 10:47 AM   #4
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
I use GetMouseFocus() to determine whether the mouse is still hovering above the chat.

First I check for names or links. If you hover over one of those f.messageInfo exists.

Next I check if the frame, its parent or grandparent is in my list of frames that are part of the chat (Chatframe1, ChatFrame1Tab, GeneralDockManager ... )
This list is created in the init() function.

If one of those checks is true I know I'm still hovering the chat and I don't have to call my FadeOut function.

Lua Code:
  1. local f = GetMouseFocus()
  2. if f then
  3.     if f.messageInfo then
  4.         return nil
  5.     end
  6.     if hcic:IsInArray(self.Frames, f) then
  7.         return nil
  8.     end
  9.     if f:GetParent() then
  10.         f = f:GetParent()
  11.         if hcic:IsInArray(self.Frames, f) then
  12.             return nil
  13.         end
  14.         if f:GetParent() then
  15.             f = f:GetParent()
  16.             if hcic:IsInArray(self.Frames, f) then
  17.                 return nil
  18.             end
  19.         end
  20.     end
  21. end
  Reply With Quote
08-27-19, 11:16 AM   #5
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Thank you. That explains it! I can use that to get it working!
  Reply With Quote
08-28-19, 07:09 PM   #6
sylvanaar
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 92
I did a lot of hacking on the chat while developing Prat.

Maybe I don't know what you are trying to do.

Did you know that behind every item link in the chatframe is an anonymous button?
  Reply With Quote
08-29-19, 07:28 AM   #7
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
Originally Posted by sylvanaar View Post
I did a lot of hacking on the chat while developing Prat.

Maybe I don't know what you are trying to do.

Did you know that behind every item link in the chatframe is an anonymous button?
No i did not know that. FStack is not showing them. But its working with mouse focus like Urtgard
posted. But there a lot of other minor things which are yet to find out. For example even though
the whole chat is not visible, the gold, silver and copper icons are still visible when they appear
in a chat message like the message you get when you repaired stuff ^^
  Reply With Quote
08-29-19, 11:21 AM   #8
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
I've had the same problem with Big Wigs icons in the chat.

That's why I not only change the alpha value (for smooth fades) but also completly hide the frames.

If you do it that way you'll need a transparent frame in the place of the chat to register when you're hovering over the chat and you can start the fade in.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Chat which only shows on MouseOver

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off