Skip to content

Commit

Permalink
Warning when about to scrap a socketed item
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsj02 committed May 17, 2024
1 parent 78cabd9 commit 7c5373e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"CATEGORIES",
"show",
"AddonCompartmentFrame",
"ItemSocketingSocket1"
"ItemSocketingSocket1",
"ScrappingMachineFrame",
"LinkUtil",
"RunNextFrame"
]
}
34 changes: 30 additions & 4 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,38 @@ local function createCheckButton(parent, data)
checkButton:SetPushedAtlas("checkbox-minimal")
return checkButton
end
local function getItemGems(link)
local _, linkOptions = LinkUtil.ExtractLink(link)
local item = { strsplit(":", linkOptions) }
local gemsList = {}
for i = 1, 4 do
local gem = tonumber(item[i + 2])
if gem then
tinsert(gemsList, gem)
end
end
return gemsList
end

local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:SetScript("OnEvent", function()
eventFrame:UnregisterAllEvents()
eventFrame:SetScript("OnEvent", nil)
eventFrame:RegisterEvent("SCRAPPING_MACHINE_ITEM_ADDED")
eventFrame:SetScript("OnEvent", function(_, event)
if event == "SCRAPPING_MACHINE_ITEM_ADDED" then
RunNextFrame(function()
local mun = ScrappingMachineFrame
for f in pairs(mun.ItemSlots.scrapButtons.activeObjects) do
if f.itemLink then
local gemsList = getItemGems(f.itemLink)
if #gemsList > 0 then
UIErrorsFrame:AddExternalErrorMessage("YOU ARE ABOUT TO DESTROY A SOCKETED ITEM!")
end
end
end
end)
end
if event ~= "PLAYER_ENTERING_WORLD" then return end
eventFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
---@class GemsFrame : Frame
---@field CloseButton Button
---@field SetTitle fun(self:GemsFrame, title:string)
Expand All @@ -105,7 +131,7 @@ eventFrame:SetScript("OnEvent", function()

local highlightSlot = CreateFrame("Frame", nil, UIParent)
highlightSlot:SetFrameStrata("TOOLTIP")
local hsTex = highlightSlot:CreateTexture(nil)
local hsTex = highlightSlot:CreateTexture()
hsTex:SetAllPoints()
hsTex:SetAtlas("CosmeticIconFrame")

Expand Down

0 comments on commit 7c5373e

Please sign in to comment.