Quantcast
Help on calling a switch function - WoWInterface
 
Thread Tools Display Modes
04-03-15, 12:49 AM   #1
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
Help on calling a switch function

Hi all,

I have posted an help / search request in the addons forum looking for addons that can disable the tooltip from the actionbars.

As usual, my question was kindly answered fast and correctly.

Here was the post:
http://www.wowinterface.com/forums/s...ad.php?t=52130

I have tried to go further and create a minimal addon that can automagically swap tooltip state combat base but I really have to understand that I have some limit in understand lua principles and basis :/

Here is the code:


Lua Code:
  1. -- tooltip code by munkdev
  2. -- [url]http://www.wowinterface.com/forums/showthread.php?t=52130[/url]
  3. -- Thanks :-)
  4.  
  5. local ADDON = ...
  6.  
  7. local TOOLTIPDISABLED = 0
  8. local prgname = "|cffffd200ToolTipDisable|r"
  9.  
  10. GameTooltip.HideAction = true
  11.  
  12. function GameTooltip:ToggleAction()
  13.    self.HideAction = not self.HideAction
  14. end
  15.  
  16. GameTooltip:HookScript("OnShow", function(self)
  17.       local actionButton = self:GetOwner() and self:GetOwner().HotKey
  18.       if actionButton and self.HideAction then
  19.          self:Hide()
  20.       end
  21. end)   
  22.  
  23.  
  24. local f = CreateFrame("Frame")
  25. f:SetScript("OnEvent", function ()
  26.  
  27.     if UnitAffectingCombat("player") == true then
  28.  
  29.         if TOOLTIPDISABLED == 0 then
  30.                 GameTooltip:ToggleAction()
  31.                 TOOLTIPDISABLED = 1
  32.         end
  33.    
  34.     else
  35.    
  36.         if TOOLTIPDISABLED == 1 then
  37.                 GameTooltip:ToggleAction()
  38.                 TOOLTIPDISABLED = 0
  39.         end
  40.     end
  41.  
  42. end)
  43. f:RegisterEvent("ACTIONBAR_UPDATE_STATE")
  44.  
  45.  
  46. SLASH_TTD1 = "/ttd";
  47. SlashCmdList["TTD"] = function()
  48.    
  49.         if TOOLTIPDISABLED == 1 then
  50.             TOOLTIPDISABLED = 0
  51.         else
  52.             TOOLTIPDISABLED = 1
  53.         end
  54.        
  55.         GameTooltip:ToggleAction()
  56.         print (prgname .. " ActionsBars Tooltips Switch")
  57.        
  58. end

The code is very ugly but it works even if half way, and it is a a good thing for now (at least it has no error :-)

1ST Problem:
- When it starts, it starts with tooltips disabled because I have not yet called the GameTooltip:ToggleAction().
Then it works as expected toggling enter/leaving from combat.

So first question is:
Is possible to call the GameTooltip:ToggleAction() only from inside the unit in combat event ?
I was not able to code in this way (but I have not yet fully understood the code by munkdev so :-)
And the choice of the event ACTIONBAR_UPDATE_STATE is the correct one or it is fired too many times ?


2ND Problem:
I am not so confident that the IF statement on the enter combat condition and exit condition are always true and so the conditions are always correctly evaluated. Can you suggest a better practice to manage such conditions ?

Thanks very much for any help or attention.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
04-03-15, 01:15 AM   #2
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
For complete information I have tried also a more minimalist approach.

The relevant part of the code is this one:

Lua Code:
  1. local UnitAffectingCombat, InCombatLockdown = UnitAffectingCombat, InCombatLockdown
  2.  
  3. local function hide(self)
  4.         self:Hide()
  5. end
  6.  
  7. local function show(self)
  8.         self:Show()
  9. end
  10.  
  11.  
  12. local f = CreateFrame("Frame")
  13. f:SetScript("OnEvent", function ()
  14.  
  15.     if (UnitAffectingCombat("player") or UnitAffectingCombat("pet") or InCombatLockdown()) then
  16.                 hooksecurefunc(GameTooltip, "SetAction", hide)
  17.     else
  18.                 hooksecurefunc(GameTooltip, "SetAction", show);
  19.     end
  20.  
  21. end)
  22. f:RegisterEvent("ACTIONBAR_UPDATE_STATE")

but it correctly remove tooltips when I enter in combat but never put them back :-) when I exit from it :-)

Thanks again :-)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
04-03-15, 03:47 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,111
I don't see any references or registering the events PLAYER_REGEN_ENABLED (out of combat) and PLAYER_REGEN_DISABLED (in combat).
  Reply With Quote
04-03-15, 08:29 AM   #4
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
Hi myrroddin,

Thanks very much for your kind reply.

I have tried to implement your suggestion and to rewrite the code in this way:

Lua Code:
  1. local ADDON = ...
  2.  
  3. local prgname = "|cffffd200ToolTipDisable|r"
  4.  
  5. local function hide(self)
  6.         print ("DEBUG: Hide")
  7.         self:Hide()
  8. end
  9.  
  10. local function show(self)
  11.         print ("DEBUG: Show")
  12.         self:Show()
  13. end
  14.  
  15.  
  16. local f = CreateFrame("Frame")
  17. f:SetScript("OnEvent", function(self, event, ...)
  18.    
  19.     if event == "PLAYER_REGEN_DISABLED" then
  20.                 hooksecurefunc(GameTooltip, "SetAction", hide)
  21.     end
  22.    
  23.     if event == "PLAYER_REGEN_ENABLED" then    
  24.                 hooksecurefunc(GameTooltip, "SetAction", show);
  25.     end
  26.  
  27. end)
  28. f:RegisterEvent("PLAYER_REGEN_DISABLED")
  29. f:RegisterEvent("PLAYER_REGEN_ENABLED")

It HIDE the tooltips when I go in combat but it doesn't show again when I exit from it .
Mah.

I am investigating a little bit more.


EDIT:

It continues to print a sequence of
DEBUG: Hide
DEBUG: Show
DEBUG: Hide
DEBUG: Show

Like the 2 events fire each others one by one very fast after exiting from combat.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-03-15 at 08:40 AM.
  Reply With Quote
04-03-15, 08:40 AM   #5
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
When you repeatedly call hooksecurefunc you will hook the function alot of times, it doesn't overwrite the earlier hooks. I'm not sure what order they're called in but it isn't a good way to do it anyways. I'd do something like:

Lua Code:
  1. local IN_COMBAT
  2.  
  3. hooksecurefunc(GameTooltip, "SetAction", function(self)
  4.     if (IN_COMBAT) then
  5.         self:Hide()
  6.     end
  7. end)
  8.  
  9. local f = CreateFrame("Frame")
  10. f:SetScript("OnEvent", function(self, event, ...)
  11.     if event == "PLAYER_REGEN_DISABLED" then
  12.         IN_COMBAT = true
  13.     elseif event == "PLAYER_REGEN_ENABLED" then    
  14.         IN_COMBAT = false
  15.     end
  16. end)
  17. f:RegisterEvent("PLAYER_REGEN_DISABLED")
  18. f:RegisterEvent("PLAYER_REGEN_ENABLED")
  Reply With Quote
04-03-15, 09:44 AM   #6
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
Thanks very much sticklord !!

It works like a charm.

Lua Code:
  1. -- Tooltip code and hooksecurefunc by sticklord
  2. -- Thanks !
  3. -- ideas and discussions here:
  4. -- [url]http://www.wowinterface.com/forums/showthread.php?p=307934[/url]
  5.  
  6. local ADDON = ...
  7.  
  8. local TOOLTIPDISABLED = 1
  9. local prgname = "|cffffd200HideToolTip|r"
  10. local IN_COMBAT
  11.  
  12. hooksecurefunc(GameTooltip, "SetAction", function(self)
  13.     if (IN_COMBAT and TOOLTIPDISABLED == 1) then
  14.         self:Hide()
  15.     end
  16. end)
  17.  
  18. local f = CreateFrame("Frame")
  19. f:SetScript("OnEvent", function(self, event, ...)
  20.     if event == "PLAYER_REGEN_DISABLED" then
  21.         IN_COMBAT = true
  22.     elseif event == "PLAYER_REGEN_ENABLED" then    
  23.         IN_COMBAT = false
  24.     end
  25. end)
  26. f:RegisterEvent("PLAYER_REGEN_DISABLED")
  27. f:RegisterEvent("PLAYER_REGEN_ENABLED")
  28.  
  29. print (prgname .. ": |cffffd200/htt|r to have tooltips back or hide again")
  30.  
  31. SLASH_HTT1 = "/htt";
  32. SlashCmdList["HTT"] = function()
  33.    
  34.         if TOOLTIPDISABLED == 1 then
  35.             TOOLTIPDISABLED = 0
  36.             print (prgname .. ": tooltips enabled in combat")
  37.         else           
  38.             TOOLTIPDISABLED = 1
  39.             print (prgname .. ": tooltips disabled in combat")
  40.         end
  41. end

I have added an option to temporary reenable them if sometime you need to read tooltip again.

Here is the full code.
Thanks really very much !
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help on calling a switch function

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