From a259c4f0cee151c269f629c2b2b5832b925e660d Mon Sep 17 00:00:00 2001 From: Larsj02 Date: Fri, 17 May 2024 10:57:30 +0200 Subject: [PATCH] Added coloring and Used Sockets / Max Sockets info for each Socket Type --- Constants.lua | 1 + Core.lua | 14 +++++++++++++- GemUtil.lua | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Constants.lua b/Constants.lua index 4461f21..dc70546 100644 --- a/Constants.lua +++ b/Constants.lua @@ -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"), diff --git a/Core.lua b/Core.lua index 5885a29..6263f6d 100644 --- a/Core.lua +++ b/Core.lua @@ -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") @@ -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) diff --git a/GemUtil.lua b/GemUtil.lua index 814d96e..b4f381f 100644 --- a/GemUtil.lua +++ b/GemUtil.lua @@ -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