You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
14 KiB

local _, S = ...
local pairs, ipairs, string, type, time = pairs, ipairs, string, type, time
local function OnIconChanged(self)
local iconSize, borderThickness, iconShape
if self.list.gridView then
iconSize = S.Settings.Get("iconSizeGrid")
borderThickness = S.Settings.Get("iconBorderThicknessGrid")
iconShape = S.Settings.Get("iconShapeGrid")
else
iconSize = S.Settings.Get("iconSize")
borderThickness = S.Settings.Get("iconBorderThickness")
iconShape = S.Settings.Get("iconShape")
end
self.icon:SetSize(iconSize, iconSize)
self.iconMask:SetSize(iconSize, iconSize)
if iconShape == 0 then
self.icon:RemoveMaskTexture(self.iconMask)
self.iconBorder:SetTexture("Interface\\Addons\\Sorted\\Textures\\Item_Glow")
elseif iconShape == 1 then
self.icon:AddMaskTexture(self.iconMask)
self.iconBorder:SetTexture("Interface\\Addons\\Sorted\\Textures\\Circle_Mask")
end
self.iconBorder:SetSize(iconSize + borderThickness, iconSize + borderThickness)
end
local favoriteButtonTexSize = 0.21875
local function UpdateEntry(self)
self:OnIconChanged()
local iconBorders
if self.list.gridView then
iconBorders = S.Settings.Get("iconBordersGrid")
else
iconBorders = S.Settings.Get("iconBorders")
end
self.iconBorder:SetShown(iconBorders == 1)
local favorited = self:GetFavorited()
local x,y
if not favorited or favorited == 0 then
self.favoriteButton:GetNormalTexture():SetTexCoord(1,1,1,1)
x = 0
y = 0
self.favoriteButton:GetHighlightTexture():SetTexCoord(
x * favoriteButtonTexSize,
(x+1) * favoriteButtonTexSize,
y * favoriteButtonTexSize,
(y+1) * favoriteButtonTexSize
)
self.favoriteButton:GetPushedTexture():SetTexCoord(
x * favoriteButtonTexSize,
(x+1) * favoriteButtonTexSize,
y * favoriteButtonTexSize,
(y+1) * favoriteButtonTexSize
)
if self.mouseEntered then
self.favoriteButton.backdrop:SetTexCoord(0,favoriteButtonTexSize,favoriteButtonTexSize*2,favoriteButtonTexSize*3)
else
self.favoriteButton.backdrop:SetTexCoord(1,1,1,1)
end
else
x,y = (favorited - 1) % 4, floor((favorited - 1) / 4)
self.favoriteButton:GetNormalTexture():SetTexCoord(
x * favoriteButtonTexSize,
(x+1) * favoriteButtonTexSize,
y * favoriteButtonTexSize,
(y+1) * favoriteButtonTexSize
)
self.favoriteButton:GetHighlightTexture():SetTexCoord(
x * favoriteButtonTexSize,
(x+1) * favoriteButtonTexSize,
y * favoriteButtonTexSize,
(y+1) * favoriteButtonTexSize
)
self.favoriteButton:GetPushedTexture():SetTexCoord(
x * favoriteButtonTexSize,
(x+1) * favoriteButtonTexSize,
y * favoriteButtonTexSize,
(y+1) * favoriteButtonTexSize
)
self.favoriteButton.backdrop:SetTexCoord(1,1,1,1)
end
end
local function SetFiltered(self, filtered)
end
local function GetFavorited(self)
return 0
end
local function ToggleFavorited(self)
end
local function SetFavorited(self, value)
end
local function ClearFavorited(self)
end
local function Button_FollowMouseWithHighlight(self, elapsed)
local parent = self.parent
--self.highlight:ClearAllPoints()
local x,y = GetCursorPosition()
x = x / self:GetEffectiveScale()
y = y / self:GetEffectiveScale()
local x2,y2 = self:GetCenter()
parent.highlight:SetWidth(self:GetWidth() * 3)
parent.highlight:SetPoint("LEFT", self, "CENTER", (x - x2) - parent.highlight:GetWidth() / 2, y)
--self.highlight:SetPoint("TOP", UIParent, "BOTTOMLEFT", 0, y2 + self:GetHeight() / 2)
--self.highlight:SetPoint("BOTTOM", UIParent, "BOTTOMLEFT", 0, y2 - self:GetHeight() / 2)
end
local function AddFrameToColumn(self, frame, column)
self.columnElements[column] = frame
frame:SetPoint("TOP")
frame:SetPoint("BOTTOM")
frame:SetPoint("LEFT", self.list.columnHeadings[column])
frame:SetPoint("RIGHT", self.list.columnHeadings[column])
end
local function DetachFramesFromColumns(self)
for column, frame in pairs(self.columnElements) do
frame:ClearAllPoints()
frame:Hide()
end
end
local function AttachFramesToColumns(self)
for column, frame in pairs(self.columnElements) do
frame:SetPoint("TOP")
frame:SetPoint("BOTTOM")
frame:SetPoint("LEFT", self.list.columnHeadings[column])
frame:SetPoint("RIGHT", self.list.columnHeadings[column])
end
end
local function OnIconBorderSettingChanged(self, event, value)
self.iconBorder:SetShown(value > 0)
end
local function OnIconBorderThicknessSettingChanged(self, event)
local size
if self.list.gridView then
size = S.Settings.Get("iconSizeGrid") + S.Settings.Get("iconBorderThicknessGrid")
else
size = S.Settings.Get("iconSize") + S.Settings.Get("iconBorderThickness")
end
self.iconBorder:SetSize(size, size)
end
function S.CreateListEntry(list, template)
--local parent = CreateFrame("FRAME", nil, list.listFrame) -- For item entry buttons to function with Blizzard's code untainted, there must be a parent frame to hold the bag ID
--parent:SetAllPoints()
local self = CreateFrame("FRAME", nil, list.listFrame--[[parent, template]])
self.button = CreateFrame("BUTTON", nil, self, template)
self.button:ClearAllPoints()
self.button.parent = self
if template then -- Only want to inherit methods, not any textures or children
for k,v in pairs(self.button) do
if type(v) == "table" and v.Hide then
v:Hide()
v:ClearAllPoints()
end
end
if self.button:GetNormalTexture() then
self.button:SetNormalTexture("")
end
end
self:ClearAllPoints()
self.parentFrame = self:GetParent()
self.list = list
self.columnElements = {}
self.Update = UpdateEntry
self.SetFiltered = SetFiltered
self.GetFavorited = GetFavorited
self.ToggleFavorited = ToggleFavorited
self.ClearFavorited = ClearFavorited
self.SetFavorited = SetFavorited
self.AddFrameToColumn = AddFrameToColumn
self.DetachFramesFromColumns = DetachFramesFromColumns
self.AttachFramesToColumns = AttachFramesToColumns
self.OnIconChanged = OnIconChanged
--[[S.Utils.RunOnEvent(self, "SettingChanged-iconBorders", OnIconBorderSettingChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconBorderThickness", OnIconBorderThicknessSettingChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconSize", OnIconChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconBordersGrid", OnIconBorderSettingChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconBorderThicknessGrid", OnIconBorderThicknessSettingChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconSizeGrid", OnIconChanged)
self:HookScript("OnShow", OnIconChanged)]]
S.Utils.RunOnEvent(self, "SettingChanged-iconShape", OnIconChanged)
S.Utils.RunOnEvent(self, "SettingChanged-iconShapeGrid", OnIconChanged)
S.Utils.RunOnEvent(self, "LayoutChanged", OnIconChanged)
self.highlight = self.button:CreateTexture(nil, "OVERLAY")
self.highlight:SetTexture("Interface\\Addons\\Sorted\\Textures\\UI-Highlight")
self.highlight:SetPoint("TOP")
self.highlight:SetPoint("BOTTOM")
self.highlight:Hide()
--self:GetHighlightTexture():SetAlpha(0.8)
self.button:SetPushedTexture("Interface\\Addons\\Sorted\\Textures\\UI-Highlight")
self.button:GetPushedTexture():SetTexCoord(0.5, 0.6, 0, 1)
self:SetPoint("LEFT")
self:SetPoint("RIGHT")
self:SetHeight(20)
self.button:SetAllPoints()
self.button:Show()
local f = CreateFrame("FRAME", nil, self)
self.favoriteButton = CreateFrame("BUTTON", nil, f)
self.favoriteButton:SetPoint("CENTER")
self.favoriteButton:SetSize(18, 18)
self.favoriteButton:SetNormalTexture("Interface\\Addons\\Sorted\\Textures\\Favorite-Icons")
self.favoriteButton:SetHighlightTexture("Interface\\Addons\\Sorted\\Textures\\Favorite-Icons")
self.favoriteButton:SetPushedTexture("Interface\\Addons\\Sorted\\Textures\\Favorite-Icons")
self.favoriteButton.backdrop = self.favoriteButton:CreateTexture(nil, "BACKGROUND")
self.favoriteButton.backdrop:SetTexture("Interface\\Addons\\Sorted\\Textures\\Favorite-Icons")
self.favoriteButton.backdrop:SetAllPoints()
self.favoriteButton.parent = self
self.favoriteButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")
self.favoriteButton:SetScript("OnClick", function(self, button, down)
if button == "LeftButton" then
self.parent:ToggleFavorited()
elseif button == "RightButton" then
S.MarkerIconMenu.Show(self, self.parent:GetData().quality, self.parent:GetData().texture, self.parent.SetFavorited, self.parent, self.parent.ClearFavorited)
end
end)
self:AddFrameToColumn(f, "FAVORITES")
local iconSize = S.Settings.Get("iconSize")
f = CreateFrame("FRAME", "", self)
f:SetFrameLevel(self:GetFrameLevel() + 1)
self.icon = f:CreateTexture(nil, "ARTWORK")
self.icon:SetPoint("CENTER")
self.icon:SetSize(iconSize, iconSize)
self.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
self.iconMask = f:CreateMaskTexture()
self.iconMask:SetTexture("Interface\\Addons\\Sorted\\Textures\\Circle_Mask")
self.iconMask:SetPoint("CENTER")
self.iconMask:SetSize(iconSize, iconSize)
self.iconBorder = f:CreateTexture(nil, "BORDER")
self.iconBorder:SetTexture("Interface\\Addons\\Sorted\\Textures\\Circle_Mask")
self.iconBorder:SetPoint("CENTER")
self:AddFrameToColumn(f, "ICON")
f = CreateFrame("FRAME", "", self)
self.nameString = f:CreateFontString(nil, "OVERLAY", "SortedFont")
self.nameString:SetPoint("TOP", 0, -2)
self.nameString:SetPoint("BOTTOM", 0, 2)
self.nameString:SetPoint("LEFT", 2, 0)
self.nameString:SetPoint("RIGHT", -2, 0)
self.nameString:SetJustifyH("LEFT")
self.nameString:SetJustifyV("MIDDLE")
self:AddFrameToColumn(f, "NAME")
-- On mouse enter/leave, start/stop the mouse-following highlight texture
-- Also zoom the icon and move the name
self.button:SetScript("OnEnter", function(self)
local parent = self.parent
if not parent.list.gridView then
local favorited = parent:GetFavorited()
if not favorited or favorited == 0 then
parent.favoriteButton.backdrop:SetTexCoord(0,favoriteButtonTexSize,favoriteButtonTexSize*2,favoriteButtonTexSize*3)
end
parent.highlight:Show()
self:SetScript("OnUpdate", Button_FollowMouseWithHighlight)
end
parent.mouseEntered = true
if parent.columnElements["ICON"] and parent.nameString and not parent.filtered then
parent.columnElements["ICON"]:SetFrameLevel(parent:GetFrameLevel() + 5)
local size, extraSize, thickness
if parent.list.gridView then
size = S.Settings.Get("iconSizeGrid")
extraSize = S.Settings.Get("iconSizeGrid") * 0.5
thickness = S.Settings.Get("iconBorderThicknessGrid")
else
size = S.Settings.Get("iconSize")
extraSize = S.Settings.Get("iconSize") * 0.5
thickness = S.Settings.Get("iconBorderThickness")
end
size = size + extraSize
parent.icon:SetSize(size, size)
parent.iconMask:SetSize(size, size)
parent.iconBorder:Show()
parent.iconBorder:SetSize(size + thickness * 1.5, size + thickness * 1.5)
parent.iconBorder:SetVertexColor(parent.color2:GetRGB())
parent.nameString:SetPoint("LEFT", 2 + extraSize / 2, 0)
parent.nameString:SetTextColor(parent.color2:GetRGB())
end
end)
self.button:HookScript("OnLeave", function(self)
local parent = self.parent
if not parent.list.gridView then
parent.favoriteButton.backdrop:SetTexCoord(1,1,1,1)
end
parent.highlight:Hide()
self:SetScript("OnUpdate", nil)
parent.mouseEntered = false
if parent.columnElements["ICON"] then
parent.columnElements["ICON"]:SetFrameLevel(self:GetFrameLevel() + 1)
local size, thickness, iconBorders
if parent.list.gridView then
size = S.Settings.Get("iconSizeGrid")
thickness = S.Settings.Get("iconBorderThicknessGrid")
iconBorders = S.Settings.Get("iconBordersGrid")
else
size = S.Settings.Get("iconSize")
thickness = S.Settings.Get("iconBorderThickness")
iconBorders = S.Settings.Get("iconBorders")
end
parent.icon:SetSize(size, size)
parent.iconMask:SetSize(size, size)
parent.iconBorder:SetShown(S.Settings.Get("iconBorders") == 1)
parent.iconBorder:SetSize(size + thickness, size + thickness)
parent.nameString:SetPoint("LEFT", 2, 0)
if not parent.filtered then
parent.iconBorder:SetVertexColor(parent.color1:GetRGB())
parent.nameString:SetTextColor(parent.color1:GetRGB())
end
end
end)
return self
end