|
| 1 | +local _G = getfenv(0) |
| 2 | + |
| 3 | +local lastMacroButtonMousedOver |
| 4 | +local numMacroIcons |
| 5 | +local availableMacroIcons = {} |
| 6 | + |
| 7 | +local function HookScript(frame, script, hook) |
| 8 | + local handler = frame:GetScript(script) |
| 9 | + frame:SetScript(script, function(a1, a2, a3, a4, a5, a6, a7) |
| 10 | + hook(function(a1, a2, a3, a4, a5, a6, a7) |
| 11 | + if handler then |
| 12 | + handler(a1, a2, a3, a4, a5, a6, a7) |
| 13 | + end |
| 14 | + end) |
| 15 | + end) |
| 16 | +end |
| 17 | + |
| 18 | +local function hooksecurefunc(arg1, arg2, arg3) |
| 19 | + if type(arg1) == "string" then |
| 20 | + arg1, arg2, arg3 = _G, arg1, arg2 |
| 21 | + end |
| 22 | + local orig = arg1[arg2] |
| 23 | + arg1[arg2] = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) |
| 24 | + local x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20 = orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) |
| 25 | + |
| 26 | + arg3(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) |
| 27 | + |
| 28 | + return x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20 |
| 29 | + end |
| 30 | +end |
| 31 | + |
| 32 | + |
| 33 | +local function customFind(str, pattern) |
| 34 | + local startIdx, endIdx = string.find(str, pattern) |
| 35 | + if startIdx then |
| 36 | + return string.sub(str, startIdx, endIdx) |
| 37 | + end |
| 38 | + return nil |
| 39 | +end |
| 40 | + |
| 41 | +function Iconic_MacroPopupFrame_Update() |
| 42 | + local macroPopupIcon, macroPopupButton |
| 43 | + local macroPopupOffset = FauxScrollFrame_GetOffset(MacroPopupScrollFrame) |
| 44 | + local numMacroIconsFound, filteredMacroIconID, macroIconID, texturePath, stringFound |
| 45 | + local userInput = string.lower(IconicFrame:GetText()) |
| 46 | + userInput = gsub(userInput, "%%", "") |
| 47 | + local filteredMacroIconIDs = {} |
| 48 | + |
| 49 | + for macroIconID = 1, numMacroIcons do |
| 50 | + texturePath = GetMacroIconInfo(macroIconID) |
| 51 | + if texturePath then |
| 52 | + local textureName = string.lower(customFind(texturePath, ".*\\(.*)")) |
| 53 | + stringFound = customFind(textureName, userInput) |
| 54 | + if stringFound then |
| 55 | + tinsert(filteredMacroIconIDs, macroIconID) |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | + numMacroIconsFound = table.getn(filteredMacroIconIDs) |
| 60 | + |
| 61 | + for buttonID = 1, NUM_MACRO_ICONS_SHOWN do |
| 62 | + macroPopupIcon = _G["MacroPopupButton" .. buttonID .. "Icon"] |
| 63 | + macroPopupButton = _G["MacroPopupButton" .. buttonID] |
| 64 | + filteredMacroIconID = (macroPopupOffset * NUM_ICONS_PER_ROW) + buttonID |
| 65 | + |
| 66 | + if filteredMacroIconID <= numMacroIconsFound then |
| 67 | + macroIconID = filteredMacroIconIDs[filteredMacroIconID] |
| 68 | + texturePath = GetMacroIconInfo(macroIconID) |
| 69 | + macroPopupIcon:SetTexture(texturePath) |
| 70 | + macroPopupButton:Show() |
| 71 | + else |
| 72 | + macroPopupIcon:SetTexture("") |
| 73 | + macroPopupButton:Hide() |
| 74 | + end |
| 75 | + |
| 76 | + if MacroPopupFrame.selectedIcon and (macroIconID == MacroPopupFrame.selectedIcon) then |
| 77 | + macroPopupButton:SetChecked(1) |
| 78 | + elseif MacroPopupFrame.selectedIconTexture == texturePath then |
| 79 | + macroPopupButton:SetChecked(1) |
| 80 | + else |
| 81 | + macroPopupButton:SetChecked(nil) |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + FauxScrollFrame_Update(MacroPopupScrollFrame, ceil(numMacroIconsFound / NUM_ICONS_PER_ROW), NUM_ICON_ROWS, MACRO_ICON_ROW_HEIGHT) |
| 86 | +end |
| 87 | + |
| 88 | +function Iconic_MacroPopupButton_OnEnter() |
| 89 | + if not customFind(this:GetName(), "MacroPopupButton") then |
| 90 | + return |
| 91 | + end |
| 92 | + local iconName = this:GetName() .. "Icon" |
| 93 | + local texturePath = _G[iconName]:GetTexture() |
| 94 | + if texturePath then |
| 95 | + local textureName = customFind(texturePath, ".*\\(.*)") |
| 96 | + local textureNameKeywords = gsub(textureName, "_", ", ") |
| 97 | + |
| 98 | + GameTooltip:SetOwner(this, "ANCHOR_RIGHT") |
| 99 | + GameTooltip:AddLine(textureNameKeywords) |
| 100 | + lastMacroButtonMousedOver = this |
| 101 | + GameTooltip:Show() |
| 102 | + end |
| 103 | +end |
| 104 | + |
| 105 | +local function Iconic_UpdateAfterScroll(frame) |
| 106 | + if not customFind(frame:GetName(), "MacroPopupButton") then |
| 107 | + return |
| 108 | + end |
| 109 | + local iconName = frame:GetName() .. "Icon" |
| 110 | + local texturePath = _G[iconName]:GetTexture() |
| 111 | + if texturePath then |
| 112 | + local textureName = customFind(texturePath, ".*\\(.*)") |
| 113 | + local textureNameKeywords = gsub(textureName, "_", ", ") |
| 114 | + |
| 115 | + GameTooltip:SetOwner(frame, "ANCHOR_RIGHT") |
| 116 | + GameTooltip:AddLine(textureNameKeywords) |
| 117 | + lastMacroButtonMousedOver = frame |
| 118 | + GameTooltip:Show() |
| 119 | + end |
| 120 | +end |
| 121 | + |
| 122 | +function Iconic_MacroPopupButton_OnLeave() |
| 123 | + GameTooltip:Hide() |
| 124 | + lastMacroButtonMousedOver = nil |
| 125 | +end |
| 126 | + |
| 127 | +function Iconic_MacroPopupButton_OnClick() |
| 128 | + local iconName = this:GetName() .. "Icon" |
| 129 | + local texturePath = _G[iconName]:GetTexture() |
| 130 | + if texturePath then |
| 131 | + MacroPopupFrame.selectedIcon = availableMacroIcons[texturePath] |
| 132 | + MacroFrameSelectedMacroButtonIcon:SetTexture(texturePath); |
| 133 | + MacroPopupOkayButton_Update(); |
| 134 | + MacroPopupFrame_Update(); |
| 135 | + end |
| 136 | +end |
| 137 | + |
| 138 | +function Iconic_TooltipRefresh() |
| 139 | + if arg1 then |
| 140 | + local scrollbar = getglobal("MacroPopupScrollFrameScrollBar"); |
| 141 | + scrollbar:SetValue(arg1); |
| 142 | + this.offset = floor((arg1 / MACRO_ICON_ROW_HEIGHT) + 0.5); |
| 143 | + Iconic_MacroPopupFrame_Update(); |
| 144 | + end |
| 145 | + if lastMacroButtonMousedOver then |
| 146 | + Iconic_UpdateAfterScroll(GetMouseFocus()) |
| 147 | + end |
| 148 | +end |
| 149 | + |
| 150 | +function Iconic_MacroPopupScroll_ResetPosition() |
| 151 | + if MacroPopupScrollFrame:GetVerticalScroll() > 0 then |
| 152 | + MacroPopupScrollFrame:SetVerticalScroll(0) |
| 153 | + end |
| 154 | +end |
| 155 | + |
| 156 | +if not IsAddOnLoaded("Blizzard_MacroUI") then |
| 157 | + LoadAddOn("Blizzard_MacroUI") |
| 158 | +end |
| 159 | + |
| 160 | +numMacroIcons = GetNumMacroIcons() |
| 161 | +for i = 1, numMacroIcons do |
| 162 | + local texture = GetMacroIconInfo(i) |
| 163 | + if texture then |
| 164 | + availableMacroIcons[texture] = i |
| 165 | + end |
| 166 | +end |
| 167 | + |
| 168 | +for i = 1, NUM_MACRO_ICONS_SHOWN do |
| 169 | + local MacroPopupButton = _G["MacroPopupButton" .. i] |
| 170 | + HookScript(MacroPopupButton, "OnEnter", Iconic_MacroPopupButton_OnEnter) |
| 171 | + HookScript(MacroPopupButton, "OnLeave", Iconic_MacroPopupButton_OnLeave) |
| 172 | + HookScript(MacroPopupButton, "OnClick", Iconic_MacroPopupButton_OnClick) |
| 173 | +end |
| 174 | + |
| 175 | +HookScript(MacroPopupScrollFrame, "OnVerticalScroll", Iconic_TooltipRefresh) |
| 176 | + |
| 177 | +hooksecurefunc(_G, "MacroPopupFrame_Update", Iconic_MacroPopupFrame_Update) |
0 commit comments