Amethystx

ncBiggerMacros.lua

Jun 30th, 2013
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.12 KB | None | 0 0
  1. local function setbody(index, body)
  2.     if InCombatLockdown() then return end
  3.  
  4.     local button = _G["ExtraMacros"..index] or CreateFrame("Button", "ExtraMacros"..index, nil, "SecureActionButtonTemplate")
  5.     button:SetAttribute("type", "macro")
  6.     button:SetAttribute("macrotext", body)
  7. end
  8.  
  9. local function new()
  10.     if InCombatLockdown() then return end
  11.  
  12.     local index = 1
  13.     local iconTexture = GetSpellorMacroIconInfo(MacroPopupFrame.selectedIcon);
  14.     local text = MacroPopupEditBox:GetText();
  15.     text = string.gsub(text, "\"", "");
  16.  
  17.     if MacroPopupFrame.mode == "new" then
  18.         index = CreateMacro(text, iconTexture, nil, (MacroFrame.macroBase > 0));
  19.         local global, perchar = GetNumMacros()
  20.         if MacroFrame.macroBase == 0 then
  21.             for i = global - 1, index, -1 do
  22.                 StoredMacros[i + 1] = StoredMacros[i]
  23.             end
  24.             StoredMacros[index] = nil
  25.         else
  26.             for i = perchar + 36 - 1, index, -1 do
  27.                 StoredMacrosPerCharacter[i + 1] = StoredMacrosPerCharacter[i]
  28.             end
  29.             StoredMacrosPerCharacter[index] = nil
  30.         end
  31.     elseif MacroPopupFrame.mode == "edit" then
  32.         index = EditMacro(MacroFrame.selectedMacro, text, iconTexture);
  33.     end
  34.     MacroPopupFrame:Hide()
  35.     MacroFrame_SelectMacro(index)
  36.     MacroFrame_Update()
  37. end
  38.  
  39. local function save()
  40.     if InCombatLockdown() then return end
  41.  
  42.     if MacroFrame.textChanged and MacroFrame.selectedMacro then
  43.         local body = MacroFrameText:GetText()
  44.  
  45.         if body:len() < 256 then
  46.             if MacroFrame.macroBase == 0 then
  47.                 StoredMacros[MacroFrame.selectedMacro] = nil
  48.             else
  49.                 StoredMacrosPerCharacter[MacroFrame.selectedMacro] = nil
  50.             end
  51.  
  52.             EditMacro(MacroFrame.selectedMacro, nil, nil, body)
  53.         else
  54.             if MacroFrame.macroBase == 0 then
  55.                 StoredMacros[MacroFrame.selectedMacro] = body
  56.             else
  57.                 StoredMacrosPerCharacter[MacroFrame.selectedMacro] = body
  58.             end
  59.  
  60.             EditMacro(MacroFrame.selectedMacro, nil, nil, "/click ExtraMacros"..MacroFrame.selectedMacro)
  61.             setbody(MacroFrame.selectedMacro, body)
  62.          end
  63.  
  64.         MacroFrame.textChanged = nil
  65.     end
  66. end
  67.  
  68. local function delete()
  69.     if InCombatLockdown() then return end
  70.  
  71.     local selectedMacro = MacroFrame.selectedMacro
  72.     local global, perchar = GetNumMacros()
  73.  
  74.     DeleteMacro(selectedMacro)
  75.    
  76.     if MacroFrame.macroBase == 0 then
  77.         for i = selectedMacro, 35 do
  78.             StoredMacros[i] = StoredMacros[i + 1]
  79.             if StoredMacros[i] then
  80.                 EditMacro(i, nil, nil, "/click ExtraMacros"..i)
  81.             end
  82.         end
  83.         StoredMacros[global] = nil
  84.     else
  85.         for i = selectedMacro, 71 do
  86.             StoredMacrosPerCharacter[i] = StoredMacrosPerCharacter[i + 1]
  87.             if StoredMacrosPerCharacter[i] then
  88.                 EditMacro(i, nil, nil, "/click ExtraMacros"..i)
  89.             end
  90.         end
  91.         StoredMacrosPerCharacter[perchar] = nil
  92.     end
  93.  
  94.     -- the order of the return values (account macros, character macros) matches up with the IDs of the tabs
  95.     local numMacros = select(PanelTemplates_GetSelectedTab(MacroFrame), GetNumMacros())
  96.     if selectedMacro > numMacros + MacroFrame.macroBase then
  97.         selectedMacro = selectedMacro - 1
  98.     end
  99.  
  100.     if selectedMacro <= MacroFrame.macroBase then
  101.         MacroFrame.selectedMacro = nil
  102.     else
  103.         MacroFrame.selectedMacro = selectedMacro
  104.     end
  105.     MacroFrame_Update()
  106.     MacroFrameText:ClearFocus()
  107. end
  108.  
  109. local function update()
  110.     local numMacros
  111.     local numAccountMacros, numCharacterMacros = GetNumMacros()
  112.     local macroButtonName, macroButton, macroIcon, macroName
  113.     local name, texture, body
  114.     local selectedName, selectedBody, selectedIcon
  115.  
  116.     if MacroFrame.macroBase == 0 then
  117.         numMacros = numAccountMacros
  118.     else
  119.         numMacros = numCharacterMacros
  120.     end
  121.  
  122.     -- Macro List
  123.     local maxMacroButtons = max(MAX_ACCOUNT_MACROS, MAX_CHARACTER_MACROS)
  124.     for i=1, maxMacroButtons do
  125.         macroButtonName = "MacroButton"..i
  126.         macroButton = _G[macroButtonName]
  127.         macroIcon = _G[macroButtonName.."Icon"]
  128.         macroName = _G[macroButtonName.."Name"]
  129.         if i <= MacroFrame.macroMax then
  130.             if i <= numMacros then
  131.                 name, texture, body = GetMacroInfo(MacroFrame.macroBase + i)
  132.                 body = MacroFrame.macroBase==0 and StoredMacros[i] or MacroFrame.macroBase==36 and StoredMacrosPerCharacter[36 + i] or body -- load macro from database
  133.                 macroIcon:SetTexture(texture)
  134.                 macroName:SetText(name)
  135.                 macroButton:Enable()
  136.                 -- Highlight Selected Macro
  137.                 if MacroFrame.selectedMacro and i == (MacroFrame.selectedMacro - MacroFrame.macroBase) then
  138.                     macroButton:SetChecked(1)
  139.                     MacroFrameSelectedMacroName:SetText(name)
  140.                     MacroFrameText:SetText(body)
  141.                     MacroFrameSelectedMacroButton:SetID(i)
  142.                     MacroFrameSelectedMacroButtonIcon:SetTexture(texture)
  143.                     MacroPopupFrame.selectedIconTexture = gsub( strupper(texture), "INTERFACE\\ICONS\\", "");
  144.                 else
  145.                     macroButton:SetChecked(0)
  146.                 end
  147.             else
  148.                 macroButton:SetChecked(0)
  149.                 macroIcon:SetTexture("")
  150.                 macroName:SetText("")
  151.                 macroButton:Disable()
  152.             end
  153.             macroButton:Show()
  154.         else
  155.             macroButton:Hide()
  156.         end
  157.     end
  158.  
  159.     -- Macro Details
  160.     if MacroFrame.selectedMacro ~= nil then
  161.         MacroFrame_ShowDetails()
  162.         MacroDeleteButton:Enable()
  163.     else
  164.         MacroFrame_HideDetails()
  165.         MacroDeleteButton:Disable()
  166.     end
  167.      
  168.     --Update New Button
  169.     if numMacros < MacroFrame.macroMax then
  170.         MacroNewButton:Enable()
  171.     else
  172.         MacroNewButton:Disable()
  173.     end
  174.  
  175.     -- Disable Buttons
  176.     if MacroPopupFrame:IsShown() then
  177.         MacroEditButton:Disable()
  178.         MacroDeleteButton:Disable()
  179.     else
  180.         MacroEditButton:Enable()
  181.         MacroDeleteButton:Enable()
  182.     end
  183.  
  184.     if not MacroFrame.selectedMacro then
  185.         MacroDeleteButton:Disable()
  186.     end
  187. end
  188.  
  189. local holder = CreateFrame("Frame")
  190. holder:RegisterEvent("ADDON_LOADED")
  191. holder:SetScript("OnEvent", function(f, event, addon)
  192.     if addon == "ncBiggerMacros" then
  193.         StoredMacros = StoredMacros or {}
  194.         StoredMacrosPerCharacter = StoredMacrosPerCharacter or {}
  195.  
  196.         for index, body in pairs(StoredMacros) do
  197.             setbody(index, body)
  198.         end
  199.  
  200.         for index, body in pairs(StoredMacrosPerCharacter) do
  201.             setbody(index, body)
  202.         end
  203.     elseif addon=="Blizzard_MacroUI" then
  204.         MacroFrameText:SetMaxLetters(1024)
  205.         MACROFRAME_CHAR_LIMIT = MACROFRAME_CHAR_LIMIT:gsub("%d+", "1024")
  206.  
  207.         MacroFrame_SaveMacro = save
  208.         MacroFrame_DeleteMacro = delete
  209.         MacroFrame_Update = update
  210.         MacroPopupOkayButton_OnClick = new
  211.     end
  212. end)
Add Comment
Please, Sign In to add comment