Originally Posted by Caetan0
friends,
I have this addon that whenever I go into combat, the windows of the minimap and chat are invisible.
Code:
local HiC = CreateFrame("Frame", "HiC", UIParent)
function HiC.OnEvent(self, event)
if event == "PLAYER_REGEN_DISABLED" then
GeneralDockManager:Hide()
DEFAULT_CHAT_FRAME:Hide()
FriendsMicroButton:Hide()
ChatFrameMenuButton:Hide()
MinimapCluster:Hide()
else
GeneralDockManager:Show()
DEFAULT_CHAT_FRAME:Show()
FriendsMicroButton:Show()
ChatFrameMenuButton:Show()
MinimapCluster:Show()
end
end
HiC:SetScript("OnEvent", HiC.OnEvent)
HiC:RegisterEvent("PLAYER_REGEN_ENABLED")
HiC:RegisterEvent("PLAYER_REGEN_DISABLED")
The problem is that often, when I go into combat, the chat window remains visible, Would anyone know what might be?
|
This should work, as other chat frames (ie ChatFrame2 etc) seem to inherit their behavior from ChatFrame1. Although, I'm pretty sure that FriendsMicroButton and ChatFrameMenuButton are parented to ChatFrame1 anyway, so you can probably remove the lines for them:
Lua Code:
local HiC = CreateFrame("Frame", "HiC", UIParent)
function HiC.OnEvent(self, event)
if event == "PLAYER_REGEN_DISABLED" then
GeneralDockManager:Hide()
ChatFrame1:Hide()
MinimapCluster:Hide()
else
GeneralDockManager:Show()
ChatFrame1:Show()
MinimapCluster:Show()
end
end
HiC:SetScript("OnEvent", HiC.OnEvent)
HiC:RegisterEvent("PLAYER_REGEN_ENABLED")
HiC:RegisterEvent("PLAYER_REGEN_DISABLED")
From what I've learned about OnUpdate, you should try and always use a counter, but if you're checking that the counter >= 0.0 (or that the counter is more than or equal to zero) then it may as well not exist.
If ever you are tempted to use OnUpdate, I suggest that you change you're line to:
Lua Code:
combate = combate + elapsed
if combate >= 1 then
-- input your code
combate = 0 -- reset your counter to 0 after your code has been input
end
That way, your OnUpdate code will only be read once per second as opposed to 60 times per second (with a frame rate of 60).