Thread Tools Display Modes
Prev Previous Post   Next Post Next
10-20-15, 11:14 AM   #1
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
Need help with a addons I try to make

I try to make this bottombar for a person on Reddit

the main addon is a infobar but I have trouble with the proffession bar.
I try to fade the icons out if the daily cooldown has been used

I have created a code but it does not work properly, I have to hover the frame before the icon fades, and the tooltip is acting wierd
Lua Code:
  1. local addon, ns = ...
  2. local cfg = ns.cfg
  3. local unpack = unpack
  4. --------------------------------------------------------------
  5. if not cfg.show.tradeSkill then return end
  6.  
  7. local proffessions = {
  8.     ['ALCHEMY'] = {"Alchemical Catalyst", "Secrets of Draenor Alchemy", "Northrend Alchemy Research"},
  9.     ['BLACKSMITHING'] = {"Truesteel Ignot", "Secrets of Draenor Blacksmithing"},
  10.     ['ENCHANTING'] = {"Temporal Crystal", "Secrets of Draenor Enchanting"},
  11.     ['ENGINEERING'] = {"Gearsoring Parts", "Secrets of Draenor Engineering"},
  12.     ['INSCRIPTION'] = {"War Paints", "Secrets of Draenor Inscription","Draenor Merchant Order"},
  13.     ['JEWEL CRAFTING'] = {"Taladite Crystal", "Secrets of Draenor Jewelcrafting"},
  14.     ['LEATHERWORKING'] = {"Burnished Leather", "Secrets of Draenor Leatherworking"},
  15.     ['TAILORING'] = {"Hexweave Cloth", "Secrets of Draenor Tailoring"},
  16. }
  17.  
  18. local prof1OnCooldown = false
  19. local prof2OnCooldown = false
  20.  
  21. local tradeSkillFrame = CreateFrame("Frame",nil, cfg.SXUIframe)
  22. tradeSkillFrame:SetPoint("LEFT", cfg.SXUIframe, "CENTER", 120,0)
  23. tradeSkillFrame:SetSize(16, 16)
  24. ---------------------------------------------------------------------
  25. local primaryTradeSkillFrame = CreateFrame("BUTTON",nil, tradeSkillFrame)
  26. primaryTradeSkillFrame:SetSize(16, 16)
  27. primaryTradeSkillFrame:SetPoint("LEFT")
  28. primaryTradeSkillFrame:EnableMouse(true)
  29. primaryTradeSkillFrame:RegisterForClicks("AnyUp")
  30.  
  31. local primaryTradeSkillIcon = primaryTradeSkillFrame:CreateTexture(nil,"OVERLAY",nil,7)
  32. primaryTradeSkillIcon:SetSize(16, 16)
  33. primaryTradeSkillIcon:SetPoint("LEFT")
  34. primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  35.  
  36. local primaryTradeSkillText = primaryTradeSkillFrame:CreateFontString(nil, "OVERLAY")
  37. primaryTradeSkillText:SetFont(cfg.font, cfg.core.normalFontSize)
  38. primaryTradeSkillText:SetPoint("RIGHT",primaryTradeSkillFrame,2,0 )
  39. primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  40.  
  41. local primaryTradeSkillStatusbar = CreateFrame("StatusBar", nil, primaryTradeSkillFrame)
  42. primaryTradeSkillStatusbar:SetStatusBarTexture(1,1,1)
  43. primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
  44. primaryTradeSkillStatusbar:SetPoint("TOPLEFT", primaryTradeSkillText, "BOTTOMLEFT",0,-2)
  45.  
  46. local primaryTradeSkillStatusbarBG = primaryTradeSkillStatusbar:CreateTexture(nil,"BACKGROUND",nil,7)
  47. primaryTradeSkillStatusbarBG:SetPoint("TOPLEFT", primaryTradeSkillText, "BOTTOMLEFT",0,-2)
  48. primaryTradeSkillStatusbarBG:SetTexture(unpack(cfg.color.inactive))
  49.  
  50. primaryTradeSkillFrame:SetScript("OnEnter", function()
  51.     if InCombatLockdown() then return end
  52.     GameTooltip:SetOwner(tradeSkillFrame, cfg.tooltipPos)
  53.     for i=1,GetNumTradeSkills() do
  54.         local cooldown = GetTradeSkillCooldown(i)
  55.         if cooldown then
  56.             local name = GetTradeSkillInfo(i)
  57.             GameTooltip:AddDoubleLine(name, SecondsToTime(cooldown), 1, 1, 0, 1, 1, 1)         
  58.         end
  59.     end
  60.    
  61.     primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.hover))
  62.     primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.hover))
  63.     GameTooltip:Show()
  64. end)
  65.  
  66. primaryTradeSkillFrame:SetScript("OnLeave", function()
  67.     if prof1OnCooldown then
  68.         primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
  69.         primaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
  70.     else
  71.         primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  72.         primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  73.     end
  74.     primaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
  75.     if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end
  76. end)
  77.  
  78. primaryTradeSkillFrame:SetScript("OnClick", function(self, button, down)
  79.     if InCombatLockdown() then return end
  80.     if button == "LeftButton" then
  81.         local prof1, prof2 = GetProfessions()
  82.         if prof1 then
  83.             if (GetProfessionInfo(prof1) == ('Herbalism')) then
  84.                 ToggleSpellBook(BOOKTYPE_PROFESSION)   
  85.             elseif(GetProfessionInfo(prof1) == ('Skinning')) then
  86.                 ToggleSpellBook(BOOKTYPE_PROFESSION)   
  87.             elseif(GetProfessionInfo(prof1) == ('Mining')) then
  88.                 CastSpellByName("Smelting")
  89.             else   
  90.                 CastSpellByName((GetProfessionInfo(prof1)))
  91.             end
  92.         end
  93.     elseif button == "RightButton" then
  94.         ToggleSpellBook(BOOKTYPE_PROFESSION)
  95.     end
  96. end)
  97. ---------------------------------------------------------------------
  98. local secondaryTradeSkillFrame = CreateFrame("BUTTON",nil, tradeSkillFrame)
  99. secondaryTradeSkillFrame:SetPoint("RIGHT")
  100. secondaryTradeSkillFrame:SetSize(16, 16)
  101. secondaryTradeSkillFrame:EnableMouse(true)
  102. secondaryTradeSkillFrame:RegisterForClicks("AnyUp")
  103.  
  104. local secondaryTradeSkillIcon = secondaryTradeSkillFrame:CreateTexture(nil,"OVERLAY",nil,7)
  105. secondaryTradeSkillIcon:SetSize(16, 16)
  106. secondaryTradeSkillIcon:SetPoint("LEFT")
  107. secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  108.  
  109. local secondaryTradeSkillText = secondaryTradeSkillFrame:CreateFontString(nil, "OVERLAY")
  110. secondaryTradeSkillText:SetFont(cfg.font, cfg.core.normalFontSize)
  111. secondaryTradeSkillText:SetPoint("LEFT", secondaryTradeSkillIcon,"RIGHT",2,0)
  112. secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  113.  
  114. local secondaryTradeSkillStatusbar = CreateFrame("StatusBar", nil, secondaryTradeSkillFrame)
  115. secondaryTradeSkillStatusbar:SetStatusBarTexture(1,1,1)
  116. secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
  117. secondaryTradeSkillStatusbar:SetPoint("TOPLEFT", secondaryTradeSkillText, "BOTTOMLEFT",0,-2)
  118.  
  119. local secondaryTradeSkillStatusbarBG = secondaryTradeSkillStatusbar:CreateTexture(nil,"BACKGROUND",nil,7)
  120. secondaryTradeSkillStatusbarBG:SetPoint("TOPLEFT", secondaryTradeSkillText, "BOTTOMLEFT",0,-2)
  121. secondaryTradeSkillStatusbarBG:SetTexture(unpack(cfg.color.inactive))
  122.  
  123. secondaryTradeSkillFrame:SetScript("OnEnter", function()
  124.     if InCombatLockdown() then return end
  125.     GameTooltip:SetOwner(tradeSkillFrame, cfg.tooltipPos)
  126.     for i=1,GetNumTradeSkills() do
  127.         local cooldown = GetTradeSkillCooldown(i)
  128.         if cooldown then
  129.             local name = GetTradeSkillInfo(i)
  130.             GameTooltip:AddDoubleLine(name, SecondsToTime(cooldown), 1, 1, 0, 1, 1, 1)         
  131.         end
  132.     end
  133.     secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.hover))
  134.     secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.hover))
  135.     GameTooltip:Show()
  136. end)
  137.  
  138. secondaryTradeSkillFrame:SetScript("OnLeave", function()
  139.     if prof2OnCooldown then
  140.         secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
  141.         secondaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
  142.     else
  143.         secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  144.         secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  145.     end
  146.     secondaryTradeSkillStatusbar:SetStatusBarColor(unpack(cfg.color.normal))
  147.     if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end
  148. end)
  149.  
  150. secondaryTradeSkillFrame:SetScript("OnClick", function(self, button, down)
  151.     if InCombatLockdown() then return end
  152.     if button == "LeftButton" then
  153.         local prof1, prof2 = GetProfessions()
  154.         if prof2 then
  155.             if (GetProfessionInfo(prof2) == ('Herbalism')) then
  156.                 ToggleSpellBook(BOOKTYPE_PROFESSION)   
  157.             elseif(GetProfessionInfo(prof2) == ('Skinning')) then
  158.                 ToggleSpellBook(BOOKTYPE_PROFESSION)   
  159.             elseif(GetProfessionInfo(prof2) == ('Mining')) then
  160.                 CastSpellByName("Smelting")
  161.             else   
  162.                 CastSpellByName((GetProfessionInfo(prof2)))
  163.             end
  164.         end
  165.     elseif button == "RightButton" then
  166.         ToggleSpellBook(BOOKTYPE_PROFESSION)
  167.     end
  168. end)
  169. ---------------------------------------------------------------------
  170.  
  171. local eventframe = CreateFrame("Frame")
  172. eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
  173. eventframe:RegisterEvent("TRADE_SKILL_UPDATE")
  174. eventframe:RegisterEvent("TRAINER_CLOSED")
  175. eventframe:RegisterEvent("SPELLS_CHANGED")
  176. eventframe:RegisterUnitEvent("UNIT_SPELLCAST_STOP", "player")
  177.  
  178. eventframe:SetScript("OnEvent", function(self,event, ...)
  179.     local prof1, prof2 = GetProfessions()
  180.     if prof1 then
  181.         local prof1Name, _, prof1Rank, prof1MaxRank = GetProfessionInfo(prof1)
  182.         prof1Name = string.upper(prof1Name)
  183.         primaryTradeSkillText:SetText(prof1Name)
  184.         primaryTradeSkillIcon:SetTexture(cfg.mediaFolder.."profession\\"..prof1Name)
  185.         if prof1Rank == prof1MaxRank then
  186.             primaryTradeSkillStatusbar:Hide()
  187.         else
  188.             primaryTradeSkillStatusbar:SetMinMaxValues(0, prof1MaxRank)
  189.             primaryTradeSkillStatusbar:SetValue(prof1Rank)
  190.         end
  191.         primaryTradeSkillFrame:SetSize(primaryTradeSkillText:GetStringWidth()+18, 16)
  192.         primaryTradeSkillStatusbar:SetSize(primaryTradeSkillText:GetStringWidth(),3)
  193.         primaryTradeSkillStatusbarBG:SetSize(primaryTradeSkillText:GetStringWidth(),3)
  194.         primaryTradeSkillFrame:Show()
  195.         primaryTradeSkillFrame:EnableMouse(true)
  196.        
  197.         for i=1,GetNumTradeSkills() do
  198.             local cooldown = GetTradeSkillCooldown(i)
  199.             if cooldown then
  200.                 local name = GetTradeSkillInfo(i)
  201.                 for k, v in pairs(proffessions) do
  202.                     for u = 1, #v do
  203.                         if k == prof1Name then
  204.                             if v[u] == name then
  205.                                 if not prof1OnCooldown then prof1OnCooldown = true end
  206.                                 primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
  207.                                 primaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
  208.                             end
  209.                         else
  210.                             primaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  211.                             primaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  212.                         end
  213.                     end
  214.                 end
  215.             end
  216.         end
  217.     else
  218.         primaryTradeSkillFrame:Hide()
  219.         primaryTradeSkillFrame:EnableMouse(false)
  220.     end
  221.    
  222.     if prof2 then
  223.         local prof2Name, _, rank, maxRank = GetProfessionInfo(prof2)
  224.         prof2Name = string.upper(prof2Name)
  225.         secondaryTradeSkillText:SetText(prof2Name)
  226.         secondaryTradeSkillIcon:SetTexture(cfg.mediaFolder.."profession\\"..prof2Name)
  227.         if rank == maxRank then
  228.             secondaryTradeSkillStatusbar:Hide()
  229.         end
  230.         secondaryTradeSkillStatusbar:SetMinMaxValues(0, maxRank)
  231.         secondaryTradeSkillStatusbar:SetValue(rank)
  232.         secondaryTradeSkillFrame:SetSize(secondaryTradeSkillText:GetStringWidth()+18, 16)
  233.         secondaryTradeSkillStatusbar:SetSize(secondaryTradeSkillText:GetStringWidth(),3)
  234.         secondaryTradeSkillStatusbarBG:SetSize(secondaryTradeSkillText:GetStringWidth(),3)
  235.         secondaryTradeSkillFrame:Show()
  236.         secondaryTradeSkillFrame:EnableMouse(true)
  237.        
  238.         for i=1,GetNumTradeSkills() do
  239.             local cooldown = GetTradeSkillCooldown(i)
  240.             if cooldown then
  241.                 local name = GetTradeSkillInfo(i)
  242.                 for k, v in pairs(proffessions) do
  243.                     for u = 1, #v do
  244.                         if k == prof2Name then
  245.                             if v[u] == name then
  246.                                 if not prof2OnCooldown then prof2OnCooldown = true end
  247.                                 secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
  248.                                 secondaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
  249.                             else
  250.                                 secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  251.                                 secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  252.                             end
  253.                         end
  254.                     end
  255.                 end
  256.             end
  257.         end
  258.     end
  259.     tradeSkillFrame:SetSize((primaryTradeSkillFrame:GetWidth())+(secondaryTradeSkillFrame:GetWidth()+4), 16)
  260. end)

EDIT: Got the proffession frame to work, just needed to rearrange some things.
Lua Code:
  1. for i=1,GetNumTradeSkills() do
  2.             local cooldown = GetTradeSkillCooldown(i)
  3.             if cooldown then
  4.                 local name = GetTradeSkillInfo(i)
  5.                 for k, v in pairs(proffessions) do
  6.                     for u = 1, #v do
  7.                         if k == prof2Name then
  8.                             if v[u] == name then
  9.                                 if not prof2OnCooldown then prof2OnCooldown = true end
  10.                                 secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.inactive))
  11.                                 secondaryTradeSkillText:SetTextColor(unpack(cfg.color.inactive))
  12.                                 if not prof2OnCooldown then
  13.                                     secondaryTradeSkillIcon:SetVertexColor(unpack(cfg.color.normal))
  14.                                     secondaryTradeSkillText:SetTextColor(unpack(cfg.color.normal))
  15.                                 end
  16.                             end
  17.                         end
  18.                     end
  19.                 end
  20.                
  21.             end
  22.         end



Also I would like to add to the gold frame that the hover shows gold earned this session, today and weekly, also shows gold across all characters on server with total at the bottom like the post say, but I have NO clue on how to make saved variables for that.
The code I use now

Lua Code:
  1. local addon, ns = ...
  2. local cfg = ns.cfg
  3. local unpack = unpack
  4. --------------------------------------------------------------
  5. if not cfg.show.gold then return end
  6.  
  7. local goldFrame = CreateFrame("BUTTON",nil, cfg.SXUIframe)
  8. goldFrame:SetPoint("RIGHT",-210,0)
  9. goldFrame:SetSize(16, 16)
  10. goldFrame:EnableMouse(true)
  11. goldFrame:RegisterForClicks("AnyUp")
  12.  
  13. local goldIcon = goldFrame:CreateTexture(nil,"OVERLAY",nil,7)
  14. goldIcon:SetPoint("LEFT")
  15. goldIcon:SetTexture(cfg.mediaFolder.."datatexts\\gold")
  16. goldIcon:SetVertexColor(unpack(cfg.color.normal))
  17.  
  18. local goldText = goldFrame:CreateFontString(nil, "OVERLAY")
  19. goldText:SetFont(cfg.font, cfg.core.normalFontSize)
  20. goldText:SetPoint("RIGHT", goldFrame,2,0)
  21. goldText:SetTextColor(unpack(cfg.color.normal))
  22.  
  23. goldFrame:SetScript("OnEnter", function()
  24.     if InCombatLockdown() then return end
  25.     goldIcon:SetVertexColor(unpack(cfg.color.hover))
  26.     GameTooltip:SetOwner(goldFrame, cfg.tooltipPos)
  27.     GameTooltip:AddLine("[|cff6699FFGold|r]")
  28.     GameTooltip:AddLine(" ")
  29.     ---------------------------------------------------
  30.     local money = GetMoney()
  31.     local moneyIcon = GetCoinIcon(money)
  32.     local g, s, c = abs(money/10000), abs(mod(money/100, 100)), abs(mod(money, 100))
  33.     if ( g < 1 ) then g = "" else g = string.format("|cffffffff%d|cffffd700g|r ", g) end
  34.     if ( s < 1 ) then s = "" else s = string.format("|cffffffff%d|cffc7c7cfs|r ", s) end
  35.     c = string.format("|cffffffff%d|cffeda55fc|r ", c)
  36.    
  37.     GameTooltip:AddDoubleLine("Current Gold",("%s%s%s"):format(g,s,c))
  38.    
  39.     GameTooltip:Show()
  40. end)
  41.  
  42. goldFrame:SetScript("OnLeave", function() if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end goldIcon:SetVertexColor(unpack(cfg.color.normal)) end)
  43.  
  44. goldFrame:SetScript("OnClick", function(self, button, down)
  45.     if InCombatLockdown() then return end
  46.     if button == "LeftButton" then
  47.         OpenAllBags()
  48.     elseif button == "RightButton" then
  49.         CloseAllBags()
  50.     end
  51. end)
  52.  
  53. local eventframe = CreateFrame("Frame")
  54. eventframe:RegisterEvent("PLAYER_LOGIN")
  55. eventframe:RegisterEvent("PLAYER_ENTERING_WORLD")
  56. eventframe:RegisterEvent("PLAYER_MONEY")
  57. eventframe:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
  58. eventframe:RegisterEvent("SEND_MAIL_COD_CHANGED")
  59. eventframe:RegisterEvent("PLAYER_TRADE_MONEY")
  60. eventframe:RegisterEvent("TRADE_MONEY_CHANGED")
  61. eventframe:RegisterEvent("TRADE_LOGOUT")
  62.  
  63. eventframe:SetScript("OnEvent", function(self,event, ...)
  64. if event == ("PLAYER_LOGIN") then
  65. local sessionGold = 0
  66. end
  67.  
  68.     local money = GetMoney()
  69.        
  70.     local g, s, c = abs(money/10000), abs(mod(money/100, 100)), abs(mod(money, 100))
  71.  
  72.     if g > 1 then
  73.         goldText:SetText(floor(g).."g")
  74.     elseif s > 1 then
  75.         goldText:SetText(floor(s).."s")
  76.     else
  77.         goldText:SetText(floor(c).."c")
  78.     end
  79.     goldFrame:SetSize(goldText:GetStringWidth()+18, 16)
  80. end)

Last edited by saxitoxin : 10-20-15 at 01:33 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Need help with a addons I try to make

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