Skip to content

Commit

Permalink
Added Frame to make Scrapping Items Easier
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsj02 committed May 22, 2024
1 parent 48bd9fd commit fd4afb7
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 16 deletions.
57 changes: 55 additions & 2 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local cache = Private.Cache
local settings = Private.Settings
local uiElements = Private.UIElements
local misc = Private.Misc
local scrapUtil = Private.ScrapUtil
local timeFormatter = CreateFromMixins(SecondsFormatterMixin);
timeFormatter:Init(1, 3, true, true);

Expand Down Expand Up @@ -143,7 +144,53 @@ local function bagItemInitiliazer(frame, data)
frame.clickable = clickable
frame.initialized = true
end
frame.clickable:UpdateClickable(true, "ITEM", data.itemID, true)
frame.clickable:UpdateClickable(true, "ITEM", data.itemID, true, data.itemLink)
end

local function createScrapFrame()
local scrapBagItems = uiElements:CreateBaseFrame(ScrappingMachineFrame, {
frameStyle = "Flat",
height = 250,
title = "Scrappable ",
points = {
{ "TOPLEFT", ScrappingMachineFrame, "BOTTOMLEFT", 0, -2 },
{ "TOPRIGHT", ScrappingMachineFrame, "BOTTOMRIGHT", 0, -2 },
}
})
local scrapItemsText = scrapBagItems:CreateFontString()
scrapItemsText:SetFontObject(const.FONT_OBJECTS.HEADING)
scrapItemsText:SetText("NOTHING TO USE")
scrapItemsText:SetPoint("CENTER", 0, -10)
scrapItemsText:Hide()
local allPointsScrap = {
CreateAnchor("TOPLEFT", scrapBagItems, "TOPLEFT", 25, -35),
CreateAnchor("BOTTOMRIGHT", scrapBagItems, "BOTTOMRIGHT", -25, 15)
}
local scrapItemScrollBox, scrapItemScrollView = uiElements:CreateScrollable(scrapBagItems, {
element_height = 45,
type = "GRID",
initializer = bagItemInitiliazer,
element_padding = 5,
elements_per_row = math.floor((ScrappingMachineFrame:GetWidth() - 50) / 50),
anchors = {
with_scroll_bar = allPointsScrap,
without_scroll_bar = allPointsScrap,
}
})
local function updateScrapItems()
if not scrapItemScrollBox:IsVisible() then return end
scrapItemScrollView:UpdateContentData({})
local scrappableItems = scrapUtil:GetScrappableItems()
for _, itemInfo in ipairs(scrappableItems) do
scrapItemScrollView:UpdateContentData(
{ { itemID = itemInfo.itemID, hideCount = true, itemLink = itemInfo.itemLink } }, true)
end
scrapBagItems:SetHeight(#scrappableItems > 0 and 250 or 75)
scrapItemsText:SetShown(#scrappableItems < 1)
end
scrapItemScrollBox:RegisterEvent("BAG_UPDATE_DELAYED")
scrapItemScrollBox:SetScript("OnEvent", updateScrapItems)
scrapItemScrollBox:SetScript("OnShow", updateScrapItems)
end

local function createFrame()
Expand Down Expand Up @@ -476,7 +523,8 @@ end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("SCRAPPING_MACHINE_ITEM_ADDED")
eventFrame:SetScript("OnEvent", function(_, event)
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", function(_, event, ...)
if event == "SCRAPPING_MACHINE_ITEM_ADDED" then
RunNextFrame(function()
local mun = ScrappingMachineFrame
Expand All @@ -489,6 +537,11 @@ eventFrame:SetScript("OnEvent", function(_, event)
end
end
end)
elseif event == "ADDON_LOADED" then
local addonName = ...
if addonName == "Blizzard_ScrappingMachineUI" then
createScrapFrame()
end
end
if event ~= "PLAYER_ENTERING_WORLD" then return end

Expand Down
3 changes: 2 additions & 1 deletion Remix Gem Helper.toc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Interface: 100207
## Version: 1.3.5
## Version: 1.4.0d
## Title: Remix Gem Helper
## Author: Rasu | Larsj_02
## DefaultState: enabled
Expand All @@ -14,5 +14,6 @@ Settings.lua
Misc.lua
GemUtil.lua
UIElements.lua
ScrapUtil.lua
Core.lua
CloakTooltip.lua
23 changes: 23 additions & 0 deletions ScrapUtil.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---@class RemixGemHelperPrivate
local Private = select(2, ...)
local const = Private.constants

local scrapUtil = {}
Private.ScrapUtil = scrapUtil

---@return table
function scrapUtil:GetScrappableItems()
local scrapable = {}
for bag = BACKPACK_CONTAINER, NUM_TOTAL_EQUIPPED_BAG_SLOTS do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local itemLoc = ItemLocation:CreateFromBagAndSlot(bag, slot)
if C_Item.DoesItemExist(itemLoc) and C_Item.CanScrapItem(itemLoc) then
tinsert(scrapable, {
itemID = C_Item.GetItemID(itemLoc),
itemLink = C_Item.GetItemLink(itemLoc)
})
end
end
end
return scrapable
end
35 changes: 22 additions & 13 deletions UIElements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,18 @@ function uiElements:CreateDropdown(parent, data)
return dropDown
end

function uiElements:AddTooltip(parent, tooltipText)
function uiElements:AddTooltip(parent, tooltipText, isHyperlink)
parent.tooltipText = tooltipText
parent.isHyperlink = isHyperlink
if parent.hasTooltip then return end
parent:HookScript("OnEnter", function(frame)
GameTooltip:SetOwner(frame, "ANCHOR_CURSOR_RIGHT")
GameTooltip:ClearLines()
GameTooltip:AddLine(frame.tooltipText, const.COLORS.WHITE:GetRGBA())
if frame.isHyperlink then
GameTooltip:SetHyperlink(frame.tooltipText)
else
GameTooltip:AddLine(frame.tooltipText, const.COLORS.WHITE:GetRGBA())
end
GameTooltip:Show()
end)
parent:HookScript("OnLeave", function()
Expand Down Expand Up @@ -244,11 +249,11 @@ local function updateItemCountOrSlot(self, event)
if not self:IsVisible() then return end
if not event or event == "ITEM_COUNT_CHANGED" then
local count = C_Item.GetItemCount(self.id)
self.count:SetText(count)
self.count:SetText((not self.hideCount and count > 1) and count or "")
self.icon:SetDesaturated(count < 1)
elseif event and event == "BAG_UPDATE_DELAYED" and self.isClickable then
local bagSlotString, bag, slot = getBagSlotString(self.id)
self:SetAttribute("item", bagSlotString)
self:SetAttribute("macrotext", "/use " .. bagSlotString)
local gemType = const.GEM_SOCKET_TYPE[self.id]
self.info = {
locIndex = bag,
Expand Down Expand Up @@ -317,7 +322,7 @@ function uiElements:CreateIcon(parent, data)
button.icon = icon
button.lastUpdate = 0

function button:UpdateClickable(isClickable, actionType, actionID, noExtract)
function button:UpdateClickable(isClickable, actionType, actionID, noExtract, hyperLink)
self:UnregisterAllEvents()
self:SetScript("OnEvent", nil)
self:SetScript("PreClick", nil)
Expand All @@ -329,9 +334,10 @@ function uiElements:CreateIcon(parent, data)
self.type = actionType
self.id = actionID
self.infoC = actionID
self.hideCount = hyperLink and true or false
if isClickable and actionType then
self:RegisterForClicks("AnyUp", "AnyDown")
self:SetAttribute("type", actionType:lower())
self:SetAttribute("type", actionType == "SPELL" and "spell" or "macro")
end
if not actionID then
icon:SetAtlas("bags-item-slot64")
Expand All @@ -344,20 +350,23 @@ function uiElements:CreateIcon(parent, data)
self:SetAttribute("spell", actionID)
end
Private.Cache:GetSpellInfo(actionID, function(spellInfo)
uiElements:AddTooltip(self,
string.format("%s\n%s%s", spellInfo.name, const.COLORS.GREY:GenerateHexColorMarkup(),
spellInfo.description))
uiElements:AddTooltip(self, spellInfo.link, true)
end)
self:RegisterEvent("SPELL_UPDATE_CHARGES")
self:SetScript("OnEvent", updateSpellCount)
updateSpellCount(self)
elseif actionType == "ITEM" then
icon:SetTexture(select(5, C_Item.GetItemInfoInstant(actionID)))
Private.Cache:GetItemInfo(actionID, function(itemInfo)
uiElements:AddTooltip(self,
string.format("%s%s", const.COLORS.GREY:GenerateHexColorMarkup(), itemInfo
.description))
self.infoC = itemInfo.link
if hyperLink then
uiElements:AddTooltip(self, hyperLink, true)
self.infoC = hyperLink
else
uiElements:AddTooltip(self,
string.format("%s%s", const.COLORS.GREY:GenerateHexColorMarkup(), itemInfo
.description))
self.infoC = itemInfo.link
end
end)
self:RegisterEvent("ITEM_COUNT_CHANGED")
self:RegisterEvent("BAG_UPDATE_DELAYED")
Expand Down

0 comments on commit fd4afb7

Please sign in to comment.