This commit is contained in:
2016-09-23 00:36:46 +02:00
parent 0cb3708671
commit 587a7e0d56
2 changed files with 1186 additions and 1107 deletions

View File

@ -49,18 +49,68 @@ MyEquipment = LibStub("AceAddon-3.0"):NewAddon("MyEquipment", "AceConsole-3.0",
local ME_Dialog = LibStub("AceConfigDialog-3.0") local ME_Dialog = LibStub("AceConfigDialog-3.0")
local ME_Cmd = LibStub("AceConfigCmd-3.0") local ME_Cmd = LibStub("AceConfigCmd-3.0")
-- Lua APIs
local pairs = pairs
local strlen, strsub, strfind, strtrim = string.len, string.sub, string.find, strtrim
local select = select
local tonumber = tonumber
-- WoW APIs
local _G = _G
local ChatEdit_InsertLink = ChatEdit_InsertLink
local CursorCanGoInSlot = CursorCanGoInSlot
local CursorUpdate = CursorUpdate
local DressUpItemLink = DressUpItemLink
local GetInventoryItemCooldown = GetInventoryItemCooldown
local GetInventoryItemCount = GetInventoryItemCount
local GetInventoryItemLink = GetInventoryItemLink
local GetInventoryItemTexture = GetInventoryItemTexture
local GetInventorySlotInfo = GetInventorySlotInfo
local InRepairMode = InRepairMode
local IsControlKeyDown = IsControlKeyDown
local IsInventoryItemLocked = IsInventoryItemLocked
local IsShiftKeyDown = IsShiftKeyDown
local PaperDollItemSlotButton_OnClick = PaperDollItemSlotButton_OnClick
local PaperDollItemSlotButton_OnEvent = PaperDollItemSlotButton_OnEvent
local PaperDollItemSlotButton_OnModifiedClick = PaperDollItemSlotButton_OnModifiedClick
local SetItemButtonCount = SetItemButtonCount
local SetItemButtonDesaturated = SetItemButtonDesaturated
local SetItemButtonTexture = SetItemButtonTexture
local SetItemButtonTextureVertexColor = SetItemButtonTextureVertexColor
local SetTooltipMoney = SetTooltipMoney
local ShowInspectCursor = ShowInspectCursor
local UnitHasRelicSlot = UnitHasRelicSlot
--Global variables that we don't cache, list them here for the mikk's Find Globals script
-- GLOBALS:
local function ColorConvertHexToDigit(h) local function ColorConvertHexToDigit(h)
if(strlen(h)~=6) then return 0,0,0 end if (strlen(h) ~= 6) then
local r={a=10,b=11,c=12,d=13,e=14,f=15} return 0, 0, 0
return ((tonumber(strsub(h,1,1)) or r[strsub(h,1,1)] or 0) * 16 + (tonumber(strsub(h,2,2)) or r[strsub(h,2,2)] or 0))/255, end
((tonumber(strsub(h,3,3)) or r[strsub(h,3,3)] or 0) * 16 + (tonumber(strsub(h,4,4)) or r[strsub(h,4,4)] or 0))/255,
((tonumber(strsub(h,5,5)) or r[strsub(h,5,5)] or 0) * 16 + (tonumber(strsub(h,6,6)) or r[strsub(h,6,6)] or 0))/255 local r = {
a = 10,
b = 11,
c = 12,
d = 13,
e = 14,
f = 15
}
return ((tonum(strsub(h, 1, 1)) or r[strsub(h, 1, 1)] or 0) * 16 + (tonum(strsub(h, 2, 2)) or r[strsub(h, 2, 2)] or 0)) / 255,
((tonum(strsub(h, 3, 3)) or r[strsub(h, 3, 3)] or 0) * 16 + (tonum(strsub(h, 4, 4)) or r[strsub(h, 4, 4)] or 0)) / 255,
((tonum(strsub(h, 5, 5)) or r[strsub(h, 5, 5)] or 0) * 16 + (tonum(strsub(h, 6, 6)) or r[strsub(h, 6, 6)] or 0)) / 255
end end
local function GetItemInfoFromLink(l) local function GetItemInfoFromLink(l)
if(not l) then return end if (not l) then
local c,id,il,n=select(3, strfind(l,"|cff(%x+)|Hitem:(%-?%d+)([^|]+)|h%[(.-)%]|h|r")) return
return n,c,id..il,id end
local c, t, id, il, n = select(3, strfind(l, "|cff(%x+)|H(%l+):(%-?%d+)([^|]+)|h%[(.-)%]|h|r"))
return n, c, id .. il, id, t
end end
local function tonum(val) local function tonum(val)
@ -331,7 +381,10 @@ end
function MyEquipment:LoadDropDown() function MyEquipment:LoadDropDown()
local dropDown = _G[self.frameName .. "CharSelectDropDown"] local dropDown = _G[self.frameName .. "CharSelectDropDown"]
local dropDownButton = _G[self.frameName .. "CharSelectDropDownButton"] local dropDownButton = _G[self.frameName .. "CharSelectDropDownButton"]
if not dropDown then return end if not dropDown then
return
end
local last_this = _G["this"] local last_this = _G["this"]
_G["this"] = dropDownButton _G["this"] = dropDownButton
UIDropDownMenu_Initialize(dropDown, self.UserDropDown_Initialize) UIDropDownMenu_Initialize(dropDown, self.UserDropDown_Initialize)
@ -345,11 +398,12 @@ function MyEquipment:UserDropDown_Initialize()
local this = self or _G.this local this = self or _G.this
local chars, charnum local chars, charnum
chars = MyEquipment:GetSortedCharList(MyEquipment.GetOpt("Sort")) chars = MyEquipment:GetSortedCharList(MyEquipment.GetOpt("Sort"))
charnum = getn(chars) charnum = #chars
if (charnum == 0) then if (charnum == 0) then
self.GetOpt("Player") -- self.GetOpt("Player")
return return
end end
local frame = this:GetParent():GetParent() local frame = this:GetParent():GetParent()
local selectedValue = UIDropDownMenu_GetSelectedValue(this) local selectedValue = UIDropDownMenu_GetSelectedValue(this)
@ -361,7 +415,10 @@ function MyEquipment:UserDropDown_Initialize()
["owner"] = frame.self, ["owner"] = frame.self,
["checked"] = nil, ["checked"] = nil,
} }
if selectedValue == info.value then info.checked = 1 end if selectedValue == info.value then
info.checked = 1
end
UIDropDownMenu_AddButton(info) UIDropDownMenu_AddButton(info)
end end
end end
@ -417,7 +474,7 @@ end
function MyEquipment:MyEquipmentItemSlotButton_OnLoad(widget) function MyEquipment:MyEquipmentItemSlotButton_OnLoad(widget)
widget:RegisterForDrag("LeftButton") widget:RegisterForDrag("LeftButton")
_G[widget:GetName() .. "NormalTexture"]:SetTexture("Interface\\AddOns\\MyBags\\Skin\\Button") _G[widget:GetName() .. "NormalTexture"]:SetTexture("Interface\\AddOns\\MyBags\\Skin\\Button")
widget.UpdateTooltip = widget.MyEquipmentItemSlotButton_OnEnter; widget.UpdateTooltip = widget.MyEquipmentItemSlotButton_OnEnter
end end
function MyEquipment:MyEquipmentItemSlotButton_OnEnter(widget) function MyEquipment:MyEquipmentItemSlotButton_OnEnter(widget)
@ -427,9 +484,13 @@ function MyEquipment:MyEquipmentItemSlotButton_OnEnter(widget)
local hasItem, hasCooldown, repairCost = GameTooltip:SetInventoryItem("player", widget:GetID()) local hasItem, hasCooldown, repairCost = GameTooltip:SetInventoryItem("player", widget:GetID())
if not hasItem then if not hasItem then
text = TEXT(_G[MYEQUIPMENT_SLOT[tonum(strsub(widget:GetName(), 21))]]) text = TEXT(_G[MYEQUIPMENT_SLOT[tonum(strsub(widget:GetName(), 21))]])
if widget.hasRelic then text = TEXT(_G["RELICSLOT"]) end if widget.hasRelic then
text = TEXT(_G["RELICSLOT"])
end
GameTooltip:SetText(text) GameTooltip:SetText(text)
end end
if (InRepairMode() and repairCost and (repairCost > 0)) then if (InRepairMode() and repairCost and (repairCost > 0)) then
GameTooltip:AddLine(TEXT(REPAIR_COST), "", 1, 1, 1) GameTooltip:AddLine(TEXT(REPAIR_COST), "", 1, 1, 1)
SetTooltipMoney(GameTooltip, repairCost) SetTooltipMoney(GameTooltip, repairCost)
@ -443,11 +504,19 @@ function MyEquipment:MyEquipmentItemSlotButton_OnEnter(widget)
local _, count, ID, _, quality, _, name = self:GetInfo(widget:GetID()) local _, count, ID, _, quality, _, name = self:GetInfo(widget:GetID())
if ID and ID ~= "" then if ID and ID ~= "" then
local hyperlink = self:GetHyperlink(ID) local hyperlink = self:GetHyperlink(ID)
if hyperlink then GameTooltip:SetHyperlink(hyperlink) end if hyperlink then
if IsControlKeyDown() and hyperlink then ShowInspectCursor() end GameTooltip:SetHyperlink(hyperlink)
end
if IsControlKeyDown() and hyperlink then
ShowInspectCursor()
end
else else
text = TEXT(_G[MYEQUIPMENT_SLOT[tonum(strsub(widget:GetName(), 21))]]) text = TEXT(_G[MYEQUIPMENT_SLOT[tonum(strsub(widget:GetName(), 21))]])
if widget.hasRelic then text = TEXT(_G["RELICSLOT"]) end if widget.hasRelic then
text = TEXT(_G["RELICSLOT"])
end
if name then -- it's a bleeding ammo slot if name then -- it's a bleeding ammo slot
text = name text = name
GameTooltip:SetText(text, ColorConvertHexToDigit(quality)) GameTooltip:SetText(text, ColorConvertHexToDigit(quality))
@ -481,7 +550,10 @@ function MyEquipment:MyEquipmentItemSlotButton_OnModifiedClick(widget, button)
elseif (IsShiftKeyDown()) then elseif (IsShiftKeyDown()) then
local ID = select(3, self:GetInfo(widget:GetID())) local ID = select(3, self:GetInfo(widget:GetID()))
local hyperLink local hyperLink
if ID then hyperLink = self:GetHyperlink(ID) end if ID then
hyperLink = self:GetHyperlink(ID)
end
if hyperLink then if hyperLink then
ChatEdit_InsertLink(hyperLink) ChatEdit_InsertLink(hyperLink)
end end
@ -506,6 +578,7 @@ function MyEquipment:MyEquipmentItemSlotButton_OnEvent(widget, event)
else else
widget:UnlockHighlight() widget:UnlockHighlight()
end end
return return
end end
end end
@ -545,6 +618,7 @@ function MyEquipment:LayoutEquipmentFrame(self)
if id and id ~= "" then if id and id ~= "" then
itemButton.hasItem = 1 itemButton.hasItem = 1
end end
if self.isLive then if self.isLive then
local start, duration, enable = GetInventoryItemCooldown("player", slot) local start, duration, enable = GetInventoryItemCooldown("player", slot)
local cooldown = _G[itemButton:GetName() .. "Cooldown"] local cooldown = _G[itemButton:GetName() .. "Cooldown"]
@ -553,16 +627,21 @@ function MyEquipment:LayoutEquipmentFrame(self)
SetItemButtonTextureVertexColor(itemButton, 0.4,0.4,0.4) SetItemButtonTextureVertexColor(itemButton, 0.4,0.4,0.4)
end end
end end
if value == "RANGEDSLOT" and hasRelic then if value == "RANGEDSLOT" and hasRelic then
itemButton.hasRelic = 1 itemButton.hasRelic = 1
end end
SetItemButtonTexture(itemButton, (texture or "")) SetItemButtonTexture(itemButton, (texture or ""))
SetItemButtonCount(itemButton, count) SetItemButtonCount(itemButton, count)
SetItemButtonDesaturated(itemButton, locked, 0.5, 0.5, 0.5) SetItemButtonDesaturated(itemButton, locked, 0.5, 0.5, 0.5)
if locked and locked ~= "" then if locked and locked ~= "" then
itemButton:LockHighlight() itemButton:LockHighlight()
self.watchLock = 1 self.watchLock = 1
else itemButton:UnlockHighlight() end else
itemButton:UnlockHighlight()
end
if quality and self.GetOpt("Border") then if quality and self.GetOpt("Border") then
SetItemButtonNormalTextureVertexColor(itemButton, ColorConvertHexToDigit(quality)) SetItemButtonNormalTextureVertexColor(itemButton, ColorConvertHexToDigit(quality))
else else
@ -572,7 +651,7 @@ function MyEquipment:LayoutEquipmentFrame(self)
end end
function MyEquipment:ME_ChatCommand(input) function MyEquipment:ME_ChatCommand(input)
if not input or input:trim() == "" then if not input or strtrim(input) == "" then
ME_Dialog:Open(self.name) ME_Dialog:Open(self.name)
else else
ME_Cmd.HandleCommand(MyEquipment, "myequipment", self.name, input) ME_Cmd.HandleCommand(MyEquipment, "myequipment", self.name, input)
@ -580,6 +659,7 @@ function MyEquipment:ME_ChatCommand(input)
end end
function MyEquipment:GetSortedCharList(sorttype, realm) function MyEquipment:GetSortedCharList(sorttype, realm)
local result = {}
--[[ --[[
if IsAddOnLoaded("DataStore_Inventory") then if IsAddOnLoaded("DataStore_Inventory") then
local realmname local realmname
@ -594,7 +674,6 @@ function MyEquipment:GetSortedCharList(sorttype, realm)
realmcount = 1 realmcount = 1
realmlist[1] = realm realmlist[1] = realm
end end
local result = {}
local idx = 0 local idx = 0
local i local i
local charname, charkey local charname, charkey
@ -609,7 +688,7 @@ function MyEquipment:GetSortedCharList(sorttype, realm)
end end
local swapped local swapped
local q, w local q, w
local x_time, y_time; local x_time, y_time
local charName, realmName local charName, realmName
repeat repeat
swapped = 0 swapped = 0
@ -635,7 +714,7 @@ function MyEquipment:GetSortedCharList(sorttype, realm)
end end
end end
until swapped == 0 until swapped == 0
return result
end end
]] ]]
return result
end end