Quantcast
Help on calling a switch function - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 

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