--[[ button.__atlaslootinfo = { type = "item", itemID = 123, spellID = 123, achievmentID = 123, petID = 123, questID = 123, mountID = 123, } ]] -- Functions local _G = getfenv(0) -- Libraries local assert, type, tonumber, tostring = assert, type, tonumber, tostring local next, pairs = next, pairs local str_sub, str_format, str_len, str_match = string.sub, string.format, string.len, string.match local UnitFactionGroup = UnitFactionGroup local CreateFrame = CreateFrame local CreateColor = CreateColor local ALName, ALPrivate = ... local AtlasLoot = _G.AtlasLoot local Button = {} local Proto = {} local API = {} AtlasLoot.Button = Button Button.Proto = Proto Button.API = API local AL = AtlasLoot.Locales local GetAlTooltip = AtlasLoot.Tooltip.GetTooltip local DEFAULT_BACKGROUND_COLOR = {0.82, 0.82, 0.82, 0.4} -- UnitFactionGroup("player") "Alliance", "Horde", "Neutral" or nil. -- :SetAtlas() local WOW_HEAD_LINK, WOW_HEAD_LINK_LOC if AtlasLoot:GetGameVersion() == AtlasLoot.BC_VERSION_NUM then WOW_HEAD_LINK, WOW_HEAD_LINK_LOC = "https://tbc.wowhead.com/%s=%d", "https://%s.tbc.wowhead.com/%s=%d" elseif AtlasLoot:GetGameVersion() == AtlasLoot.WRATH_VERSION_NUM then --WOW_HEAD_LINK, WOW_HEAD_LINK_LOC = "https://wotlk.wowhead.com/%s=%d", "https://%s.wotlk.wowhead.com/%s=%d" WOW_HEAD_LINK, WOW_HEAD_LINK_LOC = "https://www.wowhead.com/wotlk/%s=%d", "https://%s.wowhead.com/wotlk/%s=%d" else WOW_HEAD_LINK, WOW_HEAD_LINK_LOC = "https://classic.wowhead.com/%s=%d", "https://%s.classic.wowhead.com/%s=%d" end local WOW_HEAD_LOCALE local FACTION_INFO_IS_SET_ID = 998 local IGNORE_THIS_BUTTON_ID = 999 local FACTION_TEXTURES = { [0] = "MountJournalIcons-Horde", [1] = "MountJournalIcons-Alliance" } local PLAYER_FACTION_ID = 0 local LOOT_BORDER_BY_QUALITY_AL = {} local BUTTON_COUNT = 0 local SEC_BUTTON_COUNT = 0 local button_types, extra_button_types, button_types_index, extra_button_types_index = {}, {}, {}, {} local STANDART_TABLE = { "Name", "Description", "Extra" } local STANDART_FORMAT_TABLE = { "Item", "Item" } for i = 1,#STANDART_TABLE do STANDART_FORMAT_TABLE[#STANDART_FORMAT_TABLE+1] = STANDART_TABLE[i] end function Button.Init() PLAYER_FACTION_ID = UnitFactionGroup("player") == "Horde" and 0 or 1 for k, v in pairs(LOOT_BORDER_BY_QUALITY) do LOOT_BORDER_BY_QUALITY_AL[k] = v end LOOT_BORDER_BY_QUALITY_AL[1] = ALPrivate.IMAGE_PATH.."loottoast-itemborder-white" LOOT_BORDER_BY_QUALITY_AL["gold"] = "loottoast-itemborder-gold" -- Setup WoW Head locale local locale = GetLocale() if locale == "deDE" then WOW_HEAD_LOCALE = "de" elseif locale == "esMX" then WOW_HEAD_LOCALE = "es" elseif locale == "esES" then WOW_HEAD_LOCALE = "es" elseif locale == "frFR" then WOW_HEAD_LOCALE = "fr" elseif locale == "itIT" then WOW_HEAD_LOCALE = "it" elseif locale == "ptBR" then WOW_HEAD_LOCALE = "pt" elseif locale == "ruRU" then WOW_HEAD_LOCALE = "ru" elseif locale == "koKR" then WOW_HEAD_LOCALE = "ko" elseif locale == "zhCN" then WOW_HEAD_LOCALE = "cn" elseif locale == "zhTW" then WOW_HEAD_LOCALE = "cn" end end AtlasLoot:AddInitFunc(Button.Init) function Button:GetWoWHeadLocale() return WOW_HEAD_LOCALE end function Button:CreateFormatTable(tab) for i = 1,#STANDART_TABLE do tab[#tab+1] = STANDART_TABLE[i] end return tab end function Button:AddChatLink(link) if ChatFrameEditBox and ChatFrameEditBox:IsVisible() then ChatFrameEditBox:Insert(link) else ChatEdit_InsertLink(link) end end function Button:OpenWoWHeadLink(button, type, id) if id and type and AtlasLoot.db.enableWoWHeadIntegration and type then if AtlasLoot.db.useEnglishWoWHead or not WOW_HEAD_LOCALE then Button:CopyBox_Show(button, format(WOW_HEAD_LINK, type, id)) else Button:CopyBox_Show(button, format(WOW_HEAD_LINK_LOC, WOW_HEAD_LOCALE, type, id)) end end end local function Button_OnEnter(self) if self.type == "secButton" then if button_types[self.obj.__atlaslootinfo.secType[1]] and button_types[self.obj.__atlaslootinfo.secType[1]].OnEnter then button_types[self.obj.__atlaslootinfo.secType[1]].OnEnter(self) end else if button_types[self.__atlaslootinfo.type[1]] and button_types[self.__atlaslootinfo.type[1]].OnEnter then button_types[self.__atlaslootinfo.type[1]].OnEnter(self) end end end local function Button_OnLeave(self) if self.type == "secButton" then if button_types[self.obj.__atlaslootinfo.secType[1]] and button_types[self.obj.__atlaslootinfo.secType[1]].OnLeave then button_types[self.obj.__atlaslootinfo.secType[1]].OnLeave(self) end else if button_types[self.__atlaslootinfo.type[1]] and button_types[self.__atlaslootinfo.type[1]].OnLeave then button_types[self.__atlaslootinfo.type[1]].OnLeave(self) end end end local function Button_OnClick(self, button) -- down) if not button then return end if self.type == "secButton" then if button_types[self.obj.__atlaslootinfo.secType[1]] and button_types[self.obj.__atlaslootinfo.secType[1]].OnMouseAction then button_types[self.obj.__atlaslootinfo.secType[1]].OnMouseAction(self, button) end else if button_types[self.__atlaslootinfo.type[1]] and button_types[self.__atlaslootinfo.type[1]].OnMouseAction then button_types[self.__atlaslootinfo.type[1]].OnMouseAction(self, button) end end end local function Button_OnMouseWheel(self, delta) if not delta then return end Button_OnClick(self, delta == 1 and "MouseWheelUp" or "MouseWheelDown") end local function Button_SetNormalTexture(self, texture) self.icon:SetTexture(texture) end local function Button_ForceSetText(self, text, force) if force == true then -- single force self.forcedTextSet = true self:Ori_SetText(text) elseif force == false then -- remove text force self.forcedTextSet = false elseif text == nil then -- reset self:Ori_SetText(nil) self.forcedTextSet = false elseif not self.forcedTextSet then self:Ori_SetText(text) end end local function Button_Overlay_SetQualityBorder(self, qualityID) if qualityID == 1 then self:SetTexture(LOOT_BORDER_BY_QUALITY_AL[qualityID]) else self:SetAtlas(LOOT_BORDER_BY_QUALITY_AL[qualityID] or LOOT_BORDER_BY_QUALITY_AL[LE_ITEM_QUALITY_UNCOMMON]) end if not LOOT_BORDER_BY_QUALITY_AL[qualityID] then self:SetDesaturated(true) else self:SetDesaturated(false) end self:Show() end Button.Button_Overlay_SetQualityBorder = Button_Overlay_SetQualityBorder local function Button_Overlay_SetAchievementBorder(self, set, isGuildAc) if not set then self:SetTexCoord(0,1,0,1) self:SetPoint("TOPLEFT", self.icon, "TOPLEFT") self:SetPoint("BOTTOMRIGHT", self.icon, "BOTTOMRIGHT") return end if isGuildAc then self:SetTexture(452110) self:SetTexCoord(0.25976563, 0.40820313, 0.50000000, 0.64453125) else self:SetTexture(130656) self:SetTexCoord(0, 0.5625, 0, 0.5625) end local resize = ((self.icon:GetHeight() * 1.2) - self.icon:GetHeight()) / 2 self:SetPoint("TOPLEFT", self.icon, "TOPLEFT", -resize, resize) self:SetPoint("BOTTOMRIGHT", self.icon, "BOTTOMRIGHT", resize, -resize) self:SetSize(self.icon:GetWidth()*1.2, self.icon:GetHeight()*1.2) self:Show() end Button.Button_Overlay_SetAchievementBorder = Button_Overlay_SetAchievementBorder --/run AtlasLoot.Button:Create():SetContentTable({ 1, 104939 }) function Button:Create() BUTTON_COUNT = BUTTON_COUNT + 1 local buttonName = "AtlasLoot_Button_"..BUTTON_COUNT local button = CreateFrame("BUTTON", buttonName) button:SetWidth(270) button:SetHeight(28) button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD") --button:SetNormalTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight") --button:RegisterForClicks("LeftButtonDown", "RightButtonDown") button:EnableMouseWheel(true) button:RegisterForClicks("AnyDown") --"AnyUp", button:SetScript("OnEnter", Button_OnEnter) button:SetScript("OnLeave", Button_OnLeave) button:SetScript("OnClick", Button_OnClick) button:SetScript("OnMouseWheel", Button_OnMouseWheel) -- background button.background = button:CreateTexture(buttonName.."_background", "BACKGROUND") button.background:SetAllPoints(button) button.background:SetColorTexture(unpack(DEFAULT_BACKGROUND_COLOR)) button.background:Hide() -- highlight Background local highlightBg = button:CreateTexture(buttonName.."_highlightBg") highlightBg:SetPoint("TOPLEFT", button, "TOPLEFT", 0, 0) highlightBg:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -(button:GetWidth()/2), 0) highlightBg:SetColorTexture(1,0,0) highlightBg:SetGradient("HORIZONTAL", CreateColor(1, 1, 1, 0.45), CreateColor(1, 1, 1, 0)) highlightBg:Hide() button.highlightBg = highlightBg -- Icon button.icon = button:CreateTexture(buttonName.."_icon") button.icon:SetDrawLayer("ARTWORK", 0) button.icon:SetPoint("TOPLEFT", button, "TOPLEFT", 1, -1) button.icon:SetHeight(26) button.icon:SetWidth(26) button.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark") --[[ button.icon.glow = CreateFrame("FRAME") button.icon.glow:ClearAllPoints() button.icon.glow:SetParent(button) button.icon.glow:SetHeight(26) button.icon.glow:SetWidth(26) button.icon.glow:SetAllPoints(button.icon) ActionButton_ShowOverlayGlow(button.icon.glow) --ActionButton_HideOverlayGlow(self) button.qualityBorder = button:CreateTexture(buttonName.."_qualityBorder") button.qualityBorder:SetPoint("TOPLEFT", button.icon, "TOPLEFT") button.qualityBorder:SetPoint("BOTTOMRIGHT", button.icon, "BOTTOMRIGHT") button.qualityBorder:SetTexture("Interface\\Common\\WhiteIconFrame") button.qualityBorder:Hide() ]]-- -- secButtonTexture button.overlay = button:CreateTexture(buttonName.."_overlay") button.overlay:SetDrawLayer(button.icon:GetDrawLayer(), 2) button.overlay:SetPoint("TOPLEFT", button.icon, "TOPLEFT") button.overlay:SetPoint("BOTTOMRIGHT", button.icon, "BOTTOMRIGHT") button.overlay:Hide() button.overlay.icon = button.icon button.overlay.SetQualityBorder = Button_Overlay_SetQualityBorder button.overlay.SetAchievementBorder = Button_Overlay_SetAchievementBorder button.completed = button:CreateTexture(buttonName.."_completed") button.completed:SetDrawLayer(button.icon:GetDrawLayer(), 1) button.completed:SetPoint("BOTTOMRIGHT", button.icon) button.completed:SetHeight(20) button.completed:SetWidth(20) button.completed:SetTexture("Interface\\RaidFrame\\ReadyCheck-Ready") button.completed:Hide() button.phaseIndicator = button:CreateTexture(buttonName.."_phaseIndicator") button.phaseIndicator:SetDrawLayer(button.icon:GetDrawLayer(), 3) button.phaseIndicator:SetPoint("TOPLEFT", button.icon) button.phaseIndicator:SetPoint("BOTTOMRIGHT", button.icon) button.phaseIndicator:Hide() button.favourite = button:CreateTexture(buttonName.."_favourite") button.favourite:SetDrawLayer(button.icon:GetDrawLayer(), 3) button.favourite:SetPoint("TOPLEFT", button.icon, -2, 2) button.favourite:SetHeight(20) button.favourite:SetWidth(20) button.favourite:SetAtlas("VignetteKill") button.favourite:Hide() -- ItemName button.name = button:CreateFontString(buttonName.."_name", "ARTWORK", "GameFontNormal") button.name:SetPoint("TOPLEFT", button.icon, "TOPRIGHT", 3, 0) button.name:SetJustifyH("LEFT") button.name:SetText("") button.name:SetWidth(230) button.name:SetHeight(12) button.name.Ori_SetText = button.name.SetText button.name.SetText = Button_ForceSetText -- ExtraText button.extra = button:CreateFontString(buttonName.."_extra", "ARTWORK", "GameFontNormalSmall") button.extra:SetPoint("TOPLEFT", button.name, "BOTTOMLEFT", 0, -1) button.extra:SetJustifyH("LEFT") button.extra:SetText("") button.extra:SetWidth(230) button.extra:SetHeight(10) button.extra:SetTextColor(1, 1, 1, 1) button.extra.Ori_SetText = button.extra.SetText button.extra.SetText = Button_ForceSetText -- counter button.count = button:CreateFontString(buttonName.."_count", "ARTWORK", "AtlasLoot_ItemAmountFont") button.count:SetDrawLayer(button.icon:GetDrawLayer(), 1) button.count:SetPoint("BOTTOMRIGHT", button.icon, "BOTTOMRIGHT", -1, 1) button.count:SetJustifyH("RIGHT") button.count:SetHeight(15) button.count:SetText(15) button.count:Hide() -- secButton