View Single Post
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