Skip to content

Commit

Permalink
Added coloring and Used Sockets / Max Sockets info for each Socket Type
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsj02 committed May 17, 2024
1 parent 7c5373e commit a259c4f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ constants.SOCKET_TYPE_INFO = {
}
constants.COLORS = {
POSITIVE = CreateColorFromHexString("FF2ecc71"),
NEUTRAL = CreateColorFromHexString("FFf1c40f"),
NEGATIVE = CreateColorFromHexString("FFe74c3c"),
WHITE = CreateColorFromHexString("FFecf0f1"),
GREY = CreateColorFromHexString("FFbdc3c7"),
Expand Down
14 changes: 13 additions & 1 deletion Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ local function getItemGems(link)
return gemsList
end

local function getPercentColor(percent)
if percent == 100 then
return const.COLORS.POSITIVE
end
if percent >= 50 then
return const.COLORS.NEUTRAL
end
return const.COLORS.NEGATIVE
end

local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("SCRAPPING_MACHINE_ITEM_ADDED")
Expand Down Expand Up @@ -330,9 +340,11 @@ eventFrame:SetScript("OnEvent", function(_, event)
frame.Icon:SetTexture(icon)
frame.Name:SetTextColor(rowColor:GetRGBA())
if isHeader then
local used, maxS = gemUtil:GetSocketsInfo(name)
local col = getPercentColor(used / maxS * 100)
frame.Icon:SetDesaturated(false)
frame.Name:SetFontObject(const.FONT_OBJECTS.HEADING)
frame.Name:SetText(name)
frame.Name:SetText(string.format("%s (%s%d/%d|r)", name, col:GenerateHexColorMarkup(), used, maxS))
frame.Extract:Hide()
else
frame.Name:SetFontObject(const.FONT_OBJECTS.NORMAL)
Expand Down
21 changes: 21 additions & 0 deletions GemUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,30 @@ function gemUtil:GetFreeSocket(socketTypeName)
return equipmentSlot, socketSlot
end
end
CloseSocketInfo()
end
end

---@param socketTypeName string
---@return integer usedSlots
---@return integer maxSlots
function gemUtil:GetSocketsInfo(socketTypeName)
local usedSlots, maxSlots = 0, 0
for _, equipmentSlot in ipairs(const.SOCKET_EQUIPMENT_SLOTS) do
SocketInventoryItem(equipmentSlot)
for socketSlot = 1, GetNumSockets() do
if GetSocketTypes(socketSlot) == socketTypeName then
if GetExistingSocketInfo(socketSlot) then
usedSlots = usedSlots + 1
end
maxSlots = maxSlots + 1
end
end
CloseSocketInfo()
end
return usedSlots, maxSlots
end

---@param itemInfo table
---@param locType "BAG"|"SOCKET"
---@param locIndex integer
Expand Down

0 comments on commit a259c4f

Please sign in to comment.