annotate Modules/PaperDoll.lua @ 85:1196b8175674

missing "else" control
author Nenue
date Tue, 18 Oct 2016 13:16:57 -0400
parents 65ec88b30eb8
children 74e714637d6a
rev   line source
Nenue@62 1 -- Veneer
Nenue@62 2 -- PaperDoll.lua
Nenue@62 3 -- Created: 8/16/2016 8:18 AM
Nenue@62 4 -- %file-revision%
Nenue@80 5 -- Displays the item level and modifications of character sheet equipment, including artifact power
Nenue@62 6
Nenue@62 7 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent)
Nenue@75 8 local vn, print = LibStub("LibKraken").register(Veneer, plugin)
Nenue@62 9
Nenue@64 10 local slot_anchors = {
Nenue@64 11 [1] = 'TOPLEFT',
Nenue@64 12 [2] = 'TOPLEFT',
Nenue@64 13 [3] = 'TOPLEFT',
Nenue@64 14 [15] = 'TOPLEFT',
Nenue@64 15 [5] = 'TOPLEFT',
Nenue@64 16 [9] = 'TOPLEFT',
Nenue@62 17
Nenue@64 18 [10] = 'TOPRIGHT',
Nenue@64 19 [6] = 'TOPRIGHT',
Nenue@64 20 [7] = 'TOPRIGHT',
Nenue@64 21 [8] = 'TOPRIGHT',
Nenue@64 22 [11] = 'TOPRIGHT',
Nenue@64 23 [12] = 'TOPRIGHT',
Nenue@64 24 [13] = 'TOPRIGHT',
Nenue@64 25 [14] = 'TOPRIGHT',
Nenue@64 26
Nenue@64 27 [16] = 'BOTTOMRIGHT',
Nenue@64 28 [17] = 'BOTTOMLEFT',
Nenue@64 29 }
Nenue@64 30
Nenue@64 31 local slot_relative = {
Nenue@64 32 [1] = 'TOPRIGHT',
Nenue@64 33 [2] = 'TOPRIGHT',
Nenue@64 34 [3] = 'TOPRIGHT',
Nenue@64 35 [15] = 'TOPRIGHT',
Nenue@64 36 [5] = 'TOPRIGHT',
Nenue@64 37 [9] = 'TOPRIGHT',
Nenue@64 38
Nenue@64 39 [10] = 'TOPLEFT',
Nenue@64 40 [6] = 'TOPLEFT',
Nenue@64 41 [7] = 'TOPLEFT',
Nenue@64 42 [8] = 'TOPLEFT',
Nenue@64 43 [11] = 'TOPLEFT',
Nenue@64 44 [12] = 'TOPLEFT',
Nenue@64 45 [13] = 'TOPLEFT',
Nenue@64 46 [14] = 'TOPLEFT',
Nenue@64 47
Nenue@64 48 [16] = 'TOPRIGHT',
Nenue@64 49 [17] = 'TOPLEFT',
Nenue@64 50 }
Nenue@64 51 local ticker
Nenue@64 52 local vnslot = {}
Nenue@64 53 local pendingSlots = {}
Nenue@64 54
Nenue@65 55
Nenue@80 56 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo
Nenue@80 57 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank
Nenue@80 58 local tooltip = CreateFrame('GameTooltip', 'VeneerTooltip', UIParent, 'GameTooltipTemplate')
Nenue@71 59 local jewel = {}
Nenue@80 60
Nenue@80 61 local artifactBar_OnEvent = function (self)
Nenue@80 62 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo()
Nenue@80 63 if not itemID then
Nenue@80 64 self:Hide()
Nenue@80 65 return
Nenue@80 66 end
Nenue@80 67
Nenue@80 68 local numRelicSlots = C_ArtifactUI.GetNumRelicSlots() or 0;
Nenue@80 69
Nenue@80 70
Nenue@80 71 local pointsAvailable = 0
Nenue@80 72 local nextRankCost = GetCostForPointAtRank(pointsSpent + pointsAvailable) or 0
Nenue@80 73
Nenue@80 74 while totalXP >= nextRankCost do
Nenue@80 75 totalXP = totalXP - nextRankCost
Nenue@80 76 pointsAvailable = pointsAvailable + 1
Nenue@80 77 nextRankCost = GetCostForPointAtRank(pointsSpent + pointsAvailable) or 0
Nenue@80 78 end
Nenue@80 79 self.Header:SetText(name)
Nenue@81 80 self.Level:SetText((pointsAvailable >= 1) and (pointsSpent .. ' ('.. pointsAvailable..')') or (pointsSpent))
Nenue@80 81 self.ProgressText:SetFormattedText("|cFF00FFFF%d|r / %d", totalXP, nextRankCost)
Nenue@80 82
Nenue@80 83 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()*(totalXP/nextRankCost), 0)
Nenue@80 84 self.ProgressBar:SetColorTexture(1,.5,0)
Nenue@80 85
Nenue@80 86 self:Show()
Nenue@80 87 end
Nenue@80 88
Nenue@80 89
Nenue@80 90 local artifactBar = CreateFrame('Frame', 'VnPaperDollArtifact', CharacterModelFrame, 'VeneerStatusBarTemplate')
Nenue@80 91 artifactBar:ClearAllPoints()
Nenue@80 92 artifactBar:SetHeight(28)
Nenue@80 93 artifactBar:SetPoint('LEFT', CharacterModelFrame, 'LEFT', 30, 0)
Nenue@80 94 artifactBar:SetPoint('RIGHT', CharacterModelFrame, 'RIGHT', -30, 0)
Nenue@80 95 artifactBar:SetPoint('BOTTOM', CharacterMainHandSlotFrame, 'TOP', 0, 1)
Nenue@80 96 artifactBar.ProgressBG:SetColorTexture(0.5, 0.5, 0.5)
Nenue@80 97 artifactBar.Header:Show()
Nenue@80 98 artifactBar:RegisterEvent('ARTIFACT_UPDATE')
Nenue@80 99 artifactBar:SetScript('OnEvent', artifactBar_OnEvent)
Nenue@80 100
Nenue@80 101 plugin.artifactBar = artifactBar
Nenue@80 102 print(CharacterMainHandSlotFrame:GetPoint(1))
Nenue@80 103 print(artifactBar:GetPoint(3))
Nenue@80 104
Nenue@80 105 for i = 1, 3 do
Nenue@80 106 local relicSlot = CreateFrame('Frame', 'VnPaperDollRelic'..i, artifactBar)
Nenue@80 107 relicSlot:SetSize(40,40)
Nenue@80 108 relicSlot:SetPoint('BOTTOM', artifactBar, 'TOP', (i-2)*40, 24)
Nenue@80 109 relicSlot.relicArt = relicSlot:CreateTexture(nil, 'BACKGROUND')
Nenue@80 110 artifactBar['RelicSlot'..i] = relicSlot
Nenue@80 111 end
Nenue@80 112
Nenue@80 113
Nenue@80 114 artifactBar:EnableMouse(true)
Nenue@80 115 artifactBar:SetScript('OnMouseUp', function()
Nenue@80 116 SocketInventoryItem(16)
Nenue@80 117 end)
Nenue@80 118
Nenue@64 119 local UpdateVeneer = function(itemslot, frame)
Nenue@64 120 local slot = itemslot:GetID()
Nenue@64 121 if itemslot.hasItem then
Nenue@80 122 local unit = frame.target.unit or 'player'
Nenue@80 123 frame.link = GetInventoryItemLink(unit, slot)
Nenue@80 124 tooltip:SetOwner(frame, 'ANCHOR_NONE')
Nenue@80 125 tooltip:SetInventoryItem(unit, slot)
Nenue@80 126 tooltip:Show()
Nenue@80 127 --print(tooltip:NumLines())
Nenue@80 128 if tooltip:NumLines() >= 3 then
Nenue@71 129
Nenue@80 130 local ilvl
Nenue@80 131 if _G['VeneerTooltipTextLeft2'] then
Nenue@80 132 ilvl = _G['VeneerTooltipTextLeft2']:GetText():match("Item Level (%d+)")
Nenue@80 133 --print('l2', ilvl)
Nenue@80 134 end
Nenue@62 135
Nenue@80 136 if _G['VeneerTooltipTextLeft3'] then
Nenue@80 137 if not ilvl then
Nenue@80 138 ilvl = _G['VeneerTooltipTextLeft3']:GetText():match("Item Level (%d+)")
Nenue@80 139 --print('l3', ilvl)
Nenue@80 140 end
Nenue@80 141 end
Nenue@64 142
Nenue@80 143 if ilvl then
Nenue@80 144 frame.label:SetText(ilvl)
Nenue@62 145 end
Nenue@62 146 end
Nenue@80 147
Nenue@80 148 local quality = GetInventoryItemQuality(unit, slot)
Nenue@80 149 if slot == 16 and quality == LE_ITEM_QUALITY_ARTIFACT then
Nenue@80 150 artifactBar_OnEvent(plugin.artifactBar)
Nenue@71 151 end
Nenue@71 152
Nenue@71 153
Nenue@80 154
Nenue@71 155
Nenue@62 156 frame:Show()
Nenue@62 157 else
Nenue@62 158 frame:Hide()
Nenue@62 159 end
Nenue@62 160 end
Nenue@62 161
Nenue@76 162 local UpdateNext = function(frame)
Nenue@76 163
Nenue@76 164 plugin.next(function()
Nenue@76 165 print('updating', frame:GetName())
Nenue@76 166 UpdateVeneer(frame:GetParent(), frame)
Nenue@76 167 end)
Nenue@76 168 end
Nenue@76 169
Nenue@76 170
Nenue@64 171 local UpdateAll = function()
Nenue@64 172 for index, frame in pairs(vnslot) do
Nenue@64 173 if frame:IsVisible() then
Nenue@64 174 print('forcing', index, frame:GetName())
Nenue@76 175 UpdateNext(frame)
Nenue@64 176 end
Nenue@64 177 end
Nenue@64 178 end
Nenue@64 179
Nenue@71 180
Nenue@64 181 -- PaperDollFrame is separate from InspectUI handlers
Nenue@64 182 local PaperDollItemSlotButton_Update = function(self)
Nenue@64 183 local name = self:GetName()
Nenue@64 184 local slot = self:GetID()
Nenue@64 185 if not slot_anchors[slot] then
Nenue@64 186 return
Nenue@64 187 end
Nenue@80 188 print(self:GetName())
Nenue@64 189
Nenue@64 190 local frame = _G[name .. 'Veneer']
Nenue@64 191
Nenue@64 192 if not frame then
Nenue@64 193
Nenue@64 194 frame = CreateFrame('Frame', name..'Veneer', self)
Nenue@64 195 vnslot[slot] = frame
Nenue@64 196
Nenue@64 197 frame.label = frame:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFont')
Nenue@64 198 frame.gemslot = {}
Nenue@64 199
Nenue@64 200
Nenue@80 201 frame.target = self
Nenue@71 202 frame.gemslot = {}
Nenue@80 203 frame:SetAllPoints(self)
Nenue@80 204 frame:SetParent(self)
Nenue@80 205 frame.label:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 2, 2)
Nenue@64 206
Nenue@64 207 tinsert(pendingSlots, frame)
Nenue@64 208 end
Nenue@66 209
Nenue@80 210 UpdateVeneer(self, frame)
Nenue@80 211
Nenue@64 212 end
Nenue@64 213
Nenue@80 214 local PaperDollFrame_UpdateStats = function()
Nenue@80 215
Nenue@80 216 end
Nenue@64 217
Nenue@64 218
Nenue@64 219
Nenue@65 220 plugin.event = function(self, event, ...)
Nenue@80 221 print(self, event, ...)
Nenue@64 222
Nenue@65 223 if event == 'PLAYER_EQUIPMENT_CHANGED' then
Nenue@65 224 local slot, hasItem = ...
Nenue@65 225 if vnslot[slot] then
Nenue@65 226 UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot])
Nenue@80 227
Nenue@65 228 end
Nenue@64 229
Nenue@66 230 elseif event == 'PLAYER_ENTERING_WORLD' then
Nenue@66 231 UpdateAll()
Nenue@66 232
Nenue@65 233 end
Nenue@65 234
Nenue@64 235 end
Nenue@80 236 local artifactBarCreated
Nenue@80 237 plugin.init = function()
Nenue@80 238 LoadAddOn('Blizzard_ArtifactUI')
Nenue@80 239 end
Nenue@66 240
Nenue@72 241 --plugin:SetScript('OnEvent', plugin.event)
Nenue@65 242 plugin:RegisterEvent('PLAYER_EQUIPMENT_CHANGED')
Nenue@66 243 plugin:RegisterEvent('PLAYER_ENTERING_WORLD')
Nenue@64 244
Nenue@66 245
Nenue@80 246 hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
Nenue@80 247
Nenue@80 248 hooksecurefunc("PaperDollFrame_UpdateStats", PaperDollFrame_UpdateStats)