Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ADDON = ...
- local slots = {
- { name = "HeadSlot" },
- { name = "NeckSlot" },
- { name = "ShoulderSlot", canEnchant = true },
- { name = "BackSlot", canEnchant = true },
- { name = "ChestSlot", canEnchant = true },
- { name = "WristSlot", canEnchant = true },
- { name = "HandsSlot", canEnchant = true },
- { name = "WaistSlot" },
- { name = "LegsSlot", canEnchant = true },
- { name = "FeetSlot", canEnchant = true },
- { name = "Finger0Slot" },
- { name = "Finger1Slot" },
- { name = "Trinket0Slot" },
- { name = "Trinket1Slot" },
- { name = "MainHandSlot", canEnchant = true },
- { name = "SecondaryHandSlot", canEnchant = true },
- }
- for i = 1, #slots do
- slots[i].id = GetInventorySlotInfo(slots[i].name)
- end
- local LINE_HEIGHT, LINE_GAP = 20, 2
- ------------------------------------------------------------------------
- local Addon = CreateFrame("Frame", ADDON.."Frame", CharacterModelFrame)
- Addon:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, event, ...) end)
- Addon:RegisterEvent("PLAYER_REGEN_DISABLED")
- Addon:RegisterEvent("PLAYER_REGEN_ENABLED")
- Addon:Hide()
- local Toggle = CreateFrame("Button", ADDON.."ToggleButton", CharacterModelFrame)
- Toggle:SetPoint("TOPRIGHT", 0, -4)
- Toggle:SetSize(24, 24)
- Toggle:SetNormalTexture("Interface\\BUTTONS\\WHITE8X8")
- Toggle:GetNormalTexture():SetVertexColor(0.25, 0.25, 0.25)
- Toggle:SetFontString(Toggle:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"))
- Toggle:SetText("X")
- Addon.toggle = Toggle
- Toggle:SetScript("OnClick", function() Addon:SetShown(not Addon:IsShown()) end)
- ------------------------------------------------------------------------
- -- Event logic
- -- Player entered combat
- function Addon:PLAYER_REGEN_DISABLED()
- self:UnregisterEvent("SKILL_LINES_CHANGED")
- self:UnregisterEvent("UNIT_INVENTORY_CHANGED")
- end
- -- Player left combat
- function Addon:PLAYER_REGEN_ENABLED()
- self:RegisterEvent("SKILL_LINES_CHANGED")
- self:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player")
- self:SKILL_LINES_CHANGED()
- self:UNIT_INVENTORY_CHANGED()
- end
- -- Player's professions changed
- do
- local function CheckProfession(index, targetID, targetMinLevel)
- if index then
- local _, _, level, _, _, _, id = GetProfessionInfo(index)
- return id == targetID and level >= targetMinLevel
- end
- end
- function Addon:SKILL_LINES_CHANGED()
- local profession1, profession2 = GetProfessions()
- local hasEnchanting = CheckProfession(profession1, 333, 360) or CheckProfession(profession2, 333, 360)
- slots[11].canEnchant = hasEnchanting
- slots[12].canEnchant = hasEnchanting
- local hasBlacksmithing = CheckProfession(profession1, 164, 400) or CheckProfession(profession2, 164, 400)
- slots[6].canAddSocket = hasBlacksmithing
- slots[7].canAddSocket = hasBlacksmithing
- end
- end
- local GetNumSockets
- do
- local tooltip = CreateFrame("GameTooltip", ADDON.."ScanningTooltip", UIParent, "GameTooltipTemplate")
- tooltip:SetOwner(Addon, "ANCHOR_NONE")
- local textures = {}
- for i = 1, 10 do textures[i] = _G[ADDON.."ScanningTooltipTexture" .. i] end
- function GetNumSockets(slot, link)
- local n = 0
- if slot then
- tooltip:SetInventoryItem("player", slot)
- else
- tooltip:SetHyperlink(link)
- end
- for i = 1, 10 do
- if textures[i]:IsShown() then
- n = n + 1
- end
- end
- return n
- end
- end
- -- Player's inventory changed
- function Addon:UNIT_INVENTORY_CHANGED()
- local missing
- for i = 1, #slots do
- local slot = slots[i]
- slot.missingEnchant = nil
- slot.missingGem = nil
- slot.missingSocket = nil
- local itemLink = GetInventoryItemLink("player", slot.id)
- slot.itemLink = itemLink
- if itemLink then
- local _, itemID, enchantID, gem1, gem2, gem3, gem4 = strsplit(":", itemLink)
- local numSockets = GetNumSockets(slot.id)
- local numGems = (gem1 ~= "0" and 1 or 0) + (gem2 ~= "0" and 1 or 0) + (gem3 ~= "0" and 1 or 0) + (gem4 ~= "0" and 1 or 0)
- if numGems < numSockets then
- slot.missingGem = true
- missing = true
- end
- if slot.canEnchant and enchantID == "0" then
- slot.missingEnchant = true
- missing = true
- end
- if slot.canAddSocket and numSockets == GetNumSockets(nil, itemLink) then
- slot.missingSocket = true
- missing = true
- end
- end
- end
- local color = missing and RED_FONT_COLOR or GREEN_FONT_COLOR
- self.toggle:GetNormalTexture():SetVertexColor(color.r * 0.5, color.g * 0.5, color.b * 0.5)
- if self:IsShown() then
- self:UpdateDisplay()
- end
- end
- if not UnitAffectingCombat("player") then Addon:PLAYER_REGEN_ENABLED() end
- ------------------------------------------------------------------------
- -- Display logic
- Addon:SetScript("OnShow", function(self)
- self.toggle:Hide()
- self:UpdateDisplay()
- end)
- Addon:SetScript("OnHide", function(self)
- self.toggle:Show()
- end)
- function Addon:UpdateDisplay()
- if self.CreateDisplay then
- self:CreateDisplay()
- end
- local lineIndex = 0
- for i = 1, #slots do
- local slot = slots[i]
- if slot.itemLink and (slot.missingEnchant or slot.missingGem) then
- lineIndex = lineIndex + 1
- self.lines[lineIndex]:SetItem(slot)
- end
- end
- if lineIndex == 0 then
- self.title:SetText("|cff7fff7fYou are prepared!")
- self.scrollFrame:Hide()
- else
- self.title:SetText("|cffff7f7fYou are not prepared!")
- self.scrollFrame.scrollChild:SetHeight((LINE_HEIGHT + LINE_GAP) * lineIndex - LINE_GAP)
- self.scrollFrame:Show()
- end
- end
- ------------------------------------------------------------------------
- -- Display creation
- function Addon:CreateDisplay()
- self:SetPoint("BOTTOMLEFT", -3, 19)
- self:SetPoint("TOPRIGHT", 3, 1)
- self:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } })
- self:SetBackdropColor(0, 0, 0)
- self:SetBackdropBorderColor(1, 1, 1)
- local close = CreateFrame("Button", "$parentCloseButton", self, "UIPanelCloseButton")
- close:SetPoint("TOPRIGHT", 0, -2)
- close:SetScript("OnClick", function(this) self:Hide() end)
- self.close = close
- local title = self:CreateFontString(nil, "ARTWORK", "GameTooltipHeaderText")
- title:SetPoint("TOPLEFT", 8, -8)
- self.title = title
- local scrollFrame = CreateFrame("ScrollFrame", "$parentScrollFrame", self, "UIPanelScrollFrameTemplate")
- scrollFrame:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -4)
- scrollFrame:SetPoint("BOTTOMRIGHT", -28, 8)
- self.scrollFrame = scrollFrame
- scrollFrame.ScrollBar:EnableMouseWheel(true)
- scrollFrame.ScrollBar:SetScript("OnMouseWheel", function(self, direction)
- ScrollFrameTemplate_OnMouseWheel(scrollFrame, direction)
- end)
- local barBG = scrollFrame:CreateTexture(nil, "BACKGROUND", nil, -6)
- barBG:SetPoint("TOP")
- barBG:SetPoint("RIGHT", 25, 0)
- barBG:SetPoint("BOTTOM")
- barBG:SetWidth(26)
- barBG:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ScrollBar")
- barBG:SetTexCoord(0, 0.45, 0.1640625, 1)
- barBG:SetAlpha(0.5)
- local scrollChild = CreateFrame("Frame", nil, scrollFrame)
- scrollChild:SetSize(scrollFrame:GetWidth(), 100)
- scrollFrame:SetScrollChild(scrollChild)
- local function Line_OnEnter(this)
- this.highlight:Show()
- if this.slot then
- GameTooltip:SetOwner(this, "ANCHOR_NONE")
- GameTooltip:SetPoint("TOPLEFT", this, "TOPRIGHT", 0, -12)
- GameTooltip:SetInventoryItem("player", this.slot.id)
- if this.slot.missingEnchant then
- GameTooltip:AddLine("Missing enchant!")
- GameTooltip:AddTexture("Interface\\Icons\\Trade_Engraving")
- end
- if this.slot.missingGem then
- GameTooltip:AddLine("Missing gems!")
- GameTooltip:AddTexture("Interface\\Icons\\INV_Misc_Gem_01")
- end
- if this.slot.missingSocket then
- GameTooltip:AddLine("Missing extra socket!")
- GameTooltip:AddTexture("Interface\\ITEMSOCKETINGFRAME\\UI-EMPTYSOCKET-META")
- end
- GameTooltip:Show()
- end
- end
- local function Line_OnLeave(this)
- this.highlight:Hide()
- GameTooltip:Hide()
- end
- local function Line_OnHide(this)
- this.slot = nil
- this.icon:SetTexture("")
- this.text:SetText("")
- this.enchant:SetAlpha(1)
- this.gem:SetAlpha(1)
- this.socket:SetAlpha(1)
- this.socket:Hide()
- end
- local function Line_SetItem(this, slot)
- local name, _, quality, _, _, _, _, _, equipLoc, icon = GetItemInfo(slot.itemLink)
- if equipLoc == "INVTYPE_WEAPON" then
- equipLoc = slot.name == "MainHandSlot" and "INVTYPE_WEAPONMAINHAND" or "INVTYPE_WEAPONOFFHAND"
- end
- this.slot = slot
- this.icon:SetTexture(icon)
- this.enchant:SetAlpha(slot.missingEnchant and 1 or 0.25)
- this.gem:SetAlpha(slot.missingGem and 1 or 0.25)
- this.socket:SetShown(slot.canAddSocket)
- this.socket:SetAlpha(slot.missingSocket and 1 or 0.25)
- this.text:SetPoint("RIGHT", slot.canAddSocket and this.socket or this.enchant, "LEFT", -4, 0)
- this.text:SetText(_G[equipLoc])
- this:Show()
- end
- self.lines = setmetatable({}, { __index = function(t, i)
- local line = CreateFrame("Frame", nil, scrollChild)
- line:SetWidth(scrollChild:GetWidth())
- line:SetHeight(LINE_HEIGHT)
- if i > 1 then
- line:SetPoint("TOPLEFT", t[i - 1], "BOTTOMLEFT", 0, -LINE_GAP)
- else
- line:SetPoint("TOPLEFT", scrollChild)
- end
- line:EnableMouse(true)
- line:SetScript("OnEnter", Line_OnEnter)
- line:SetScript("OnLeave", Line_OnLeave)
- line:SetScript("OnHide", Line_OnHide)
- line:EnableMouseWheel(true)
- line:SetScript("OnMouseWheel", function(this, direction)
- ScrollFrameTemplate_OnMouseWheel(scrollFrame, direction)
- end)
- local icon = line:CreateTexture(nil, "ARTWORK")
- icon:SetPoint("LEFT")
- icon:SetSize(LINE_HEIGHT, LINE_HEIGHT)
- icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- line.icon = icon
- local gem = line:CreateTexture(nil, "ARTWORK")
- gem:SetPoint("RIGHT")
- gem:SetSize(LINE_HEIGHT, LINE_HEIGHT)
- gem:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- gem:SetTexture("Interface\\Icons\\INV_Misc_Gem_01")
- line.gem = gem
- local enchant = line:CreateTexture(nil, "ARTWORK")
- enchant:SetPoint("RIGHT", gem, "LEFT", -LINE_GAP, 0)
- enchant:SetSize(LINE_HEIGHT, LINE_HEIGHT)
- enchant:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- enchant:SetTexture("Interface\\Icons\\Trade_Engraving")
- line.enchant = enchant
- local socket = line:CreateTexture(nil, "ARTWORK")
- socket:SetPoint("RIGHT", enchant, "LEFT", -LINE_GAP, 0)
- socket:SetSize(LINE_HEIGHT, LINE_HEIGHT)
- socket:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- socket:SetTexture("Interface\\ITEMSOCKETINGFRAME\\UI-EMPTYSOCKET-META")
- line.socket = socket
- local text = line:CreateFontString(nil, "ARTWORK", "GameTooltipText")
- text:SetPoint("LEFT", icon, "RIGHT", 4, 0)
- line.text = text
- local highlight = line:CreateTexture(nil, "BACKGROUND")
- highlight:SetAllPoints(true)
- highlight:SetBlendMode("ADD")
- highlight:SetTexture([[Interface\QuestFrame\UI-QuestLogTitleHighlight]])
- highlight:SetVertexColor(0.2, 0.4, 0.8)
- highlight:Hide()
- line.highlight = highlight
- line.id = i
- line.SetItem = Line_SetItem
- t[i] = line
- return line
- end })
- self.CreateDisplay = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement