mirror of
https://github.com/parnic/breakables.git
synced 2025-06-17 01:41:51 -05:00
- drycode attempt at creating one bar per profession for the case where someone has some combination of inscription, enchanting, and jewelcrafting. not tested in game at all
This commit is contained in:
159
Breakables.lua
159
Breakables.lua
@ -43,6 +43,9 @@ local buttonSize = 28
|
|||||||
|
|
||||||
local _G = _G
|
local _G = _G
|
||||||
|
|
||||||
|
-- can be 1 or 2
|
||||||
|
local numEligibleProfessions = 0
|
||||||
|
|
||||||
Breakables.optionsFrame = {}
|
Breakables.optionsFrame = {}
|
||||||
Breakables.justClicked = false
|
Breakables.justClicked = false
|
||||||
|
|
||||||
@ -102,11 +105,19 @@ function Breakables:OnEnable()
|
|||||||
self:RegisterEvents()
|
self:RegisterEvents()
|
||||||
|
|
||||||
if CanMill or CanProspect or CanDisenchant then
|
if CanMill or CanProspect or CanDisenchant then
|
||||||
|
if CanMill then
|
||||||
|
numEligibleProfessions = numEligibleProfessions + 1
|
||||||
|
end
|
||||||
|
if CanProspect then
|
||||||
|
numEligibleProfessions = numEligibleProfessions + 1
|
||||||
|
end
|
||||||
|
if CanDisenchant then
|
||||||
|
numEligibleProfessions = numEligibleProfessions + 1
|
||||||
|
end
|
||||||
|
|
||||||
self:CreateButtonFrame()
|
self:CreateButtonFrame()
|
||||||
if self.settings.hide then
|
if self.settings.hide then
|
||||||
if self.buttonFrame then
|
self:ToggleButtonFrameVisibility(false)
|
||||||
self.buttonFrame:Hide()
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
self:FindBreakables()
|
self:FindBreakables()
|
||||||
end
|
end
|
||||||
@ -116,6 +127,22 @@ function Breakables:OnEnable()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Breakables:ToggleButtonFrameVisibility(show)
|
||||||
|
for i=1,numEligibleProfessions do
|
||||||
|
if self.buttonFrame[i] then
|
||||||
|
if show == nil then
|
||||||
|
show = not self.buttonFrame[i]:IsVisible()
|
||||||
|
end
|
||||||
|
|
||||||
|
if not show then
|
||||||
|
self.buttonFrame[i]:Hide()
|
||||||
|
else
|
||||||
|
self.buttonFrame[i]:Show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Breakables:RegisterEvents()
|
function Breakables:RegisterEvents()
|
||||||
-- would have used ITEM_PUSH here, but that seems to fire after looting and before the bag actually gets the item
|
-- would have used ITEM_PUSH here, but that seems to fire after looting and before the bag actually gets the item
|
||||||
-- another alternative is to parse the chat msg, but that seems lame...however, that should only fire once as opposed to BAG_UPDATE's potential double-fire
|
-- another alternative is to parse the chat msg, but that seems lame...however, that should only fire once as opposed to BAG_UPDATE's potential double-fire
|
||||||
@ -166,7 +193,7 @@ end
|
|||||||
function Breakables:OnEnterCombat()
|
function Breakables:OnEnterCombat()
|
||||||
self.bCombat = true
|
self.bCombat = true
|
||||||
if self.settings.hideInCombat then
|
if self.settings.hideInCombat then
|
||||||
self.buttonFrame:Hide()
|
self:ToggleButtonFrameVisibility(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -216,10 +243,8 @@ function Breakables:GetOptions()
|
|||||||
if info.uiType == "cmd" then
|
if info.uiType == "cmd" then
|
||||||
print("|cff33ff99Breakables|r: set |cffffff78maxBreakables|r to " .. tostring(self.settings.hide))
|
print("|cff33ff99Breakables|r: set |cffffff78maxBreakables|r to " .. tostring(self.settings.hide))
|
||||||
end
|
end
|
||||||
if v then
|
self:ToggleButtonFrameVisibility(v)
|
||||||
self.buttonFrame:Hide()
|
if not v then
|
||||||
else
|
|
||||||
self.buttonFrame:Show()
|
|
||||||
self:FindBreakables()
|
self:FindBreakables()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -362,35 +387,49 @@ function Breakables:CreateButtonFrame()
|
|||||||
self.frame = CreateFrame("Frame")
|
self.frame = CreateFrame("Frame")
|
||||||
end
|
end
|
||||||
if not self.buttonFrame then
|
if not self.buttonFrame then
|
||||||
self.buttonFrame = CreateFrame("Button", "BreakablesButtonFrame1", self.frame, "SecureActionButtonTemplate")
|
self.buttonFrame = {}
|
||||||
end
|
end
|
||||||
self.buttonFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", self.settings.buttonFrameLeft, self.settings.buttonFrameTop)
|
|
||||||
|
|
||||||
if not self.buttonFrame.icon then
|
for i=1,numEligibleProfessions do
|
||||||
self.buttonFrame.icon = self.buttonFrame:CreateTexture(nil, "BACKGROUND")
|
if not self.buttonFrame[i] then
|
||||||
|
self.buttonFrame[i] = CreateFrame("Button", "BreakablesButtonFrame1", self.frame, "SecureActionButtonTemplate")
|
||||||
end
|
end
|
||||||
if CanMill or CanProspect or CanDisenchant then
|
self.buttonFrame[i]:SetPoint("TOPLEFT", UIParent, "TOPLEFT", self.settings.buttonFrameLeft, self.settings.buttonFrameTop)
|
||||||
self.buttonFrame:SetWidth(buttonSize * self.settings.buttonScale)
|
|
||||||
self.buttonFrame:SetHeight(buttonSize * self.settings.buttonScale)
|
|
||||||
|
|
||||||
self.buttonFrame:EnableMouse(true)
|
if CanMill and i == 1 or self.buttonFrame[1].type ~= BREAKABLE_HERB then
|
||||||
self.buttonFrame:RegisterForClicks("LeftButtonUp")
|
self.buttonFrame[i].type = BREAKABLE_HERB
|
||||||
|
elseif CanDisenchant and i == 1 or self.buttonFrame[1].type ~= BREAKABLE_DE then
|
||||||
|
self.buttonFrame[i].type = BREAKABLE_DE
|
||||||
|
elseif CanProspect and i == 1 or self.buttonFrame[1].type ~= BREAKABLE_ORE then
|
||||||
|
self.buttonFrame[i].type = BREAKABLE_ORE
|
||||||
|
end
|
||||||
|
|
||||||
self.buttonFrame:SetMovable(true)
|
if not self.buttonFrame[i].icon then
|
||||||
self.buttonFrame:RegisterForDrag("LeftButton")
|
self.buttonFrame[i].icon = self.buttonFrame[i]:CreateTexture(nil, "BACKGROUND")
|
||||||
self.buttonFrame:SetScript("OnMouseDown", function() self:OnMouseDown() end)
|
end
|
||||||
self.buttonFrame:SetScript("OnMouseUp", function() self:OnMouseUp() end)
|
if self.buttonFrame[i].type then
|
||||||
self.buttonFrame:SetClampedToScreen(true)
|
self.buttonFrame[i]:SetWidth(buttonSize * self.settings.buttonScale)
|
||||||
|
self.buttonFrame[i]:SetHeight(buttonSize * self.settings.buttonScale)
|
||||||
|
|
||||||
local spellName, _, texture = GetSpellInfo((CanMill and MillingId) or (CanProspect and ProspectingId) or DisenchantId)
|
self.buttonFrame[i]:EnableMouse(true)
|
||||||
|
self.buttonFrame[i]:RegisterForClicks("LeftButtonUp")
|
||||||
|
|
||||||
self.buttonFrame:SetAttribute("type1", "spell")
|
self.buttonFrame[i]:SetMovable(true)
|
||||||
self.buttonFrame:SetAttribute("spell1", spellName)
|
self.buttonFrame[i]:RegisterForDrag("LeftButton")
|
||||||
|
self.buttonFrame[i]:SetScript("OnMouseDown", function(frame) self:OnMouseDown(frame) end)
|
||||||
|
self.buttonFrame[i]:SetScript("OnMouseUp", function(frame) self:OnMouseUp(frame) end)
|
||||||
|
self.buttonFrame[i]:SetClampedToScreen(true)
|
||||||
|
|
||||||
self.buttonFrame.icon:SetTexture(texture)
|
local spellName, _, texture = GetSpellInfo((self.buttonFrame[i].type == BREAKABLE_HERB and MillingId) or (self.buttonFrame[i].type == BREAKABLE_ORE and ProspectingId) or DisenchantId)
|
||||||
self.buttonFrame.icon:SetAllPoints(self.buttonFrame)
|
|
||||||
|
self.buttonFrame[i]:SetAttribute("type1", "spell")
|
||||||
|
self.buttonFrame[i]:SetAttribute("spell1", spellName)
|
||||||
|
|
||||||
|
self.buttonFrame[i].icon:SetTexture(texture)
|
||||||
|
self.buttonFrame[i].icon:SetAllPoints(self.buttonFrame[i])
|
||||||
else
|
else
|
||||||
self.buttonFrame:SetTexture(nil)
|
self.buttonFrame[i]:SetTexture(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -399,29 +438,31 @@ function Breakables:ApplyScale()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i=1,numEligibleProfessions do
|
||||||
-- yes, setscale exists...but it was scaling buttonFrame and breakableButtons differently for some reason. this works better.
|
-- yes, setscale exists...but it was scaling buttonFrame and breakableButtons differently for some reason. this works better.
|
||||||
self.buttonFrame:SetWidth(buttonSize * self.settings.buttonScale)
|
self.buttonFrame[i]:SetWidth(buttonSize * self.settings.buttonScale)
|
||||||
self.buttonFrame:SetHeight(buttonSize * self.settings.buttonScale)
|
self.buttonFrame[i]:SetHeight(buttonSize * self.settings.buttonScale)
|
||||||
|
|
||||||
if self.breakableButtons then
|
if self.breakableButtons[i] then
|
||||||
for i=1,#self.breakableButtons do
|
for j=1,#self.breakableButtons[i] do
|
||||||
self.breakableButtons[i]:SetWidth(buttonSize * self.settings.buttonScale)
|
self.breakableButtons[i][j]:SetWidth(buttonSize * self.settings.buttonScale)
|
||||||
self.breakableButtons[i]:SetHeight(buttonSize * self.settings.buttonScale)
|
self.breakableButtons[i][j]:SetHeight(buttonSize * self.settings.buttonScale)
|
||||||
self.breakableButtons[i].text:SetFont(NumberFont_Outline_Med:GetFont(), self.settings.fontSize, "OUTLINE")
|
self.breakableButtons[i][j].text:SetFont(NumberFont_Outline_Med:GetFont(), self.settings.fontSize, "OUTLINE")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Breakables:OnMouseDown()
|
function Breakables:OnMouseDown(frame)
|
||||||
if IsShiftKeyDown() then
|
if IsShiftKeyDown() then
|
||||||
self.buttonFrame:StartMoving()
|
frame:StartMoving()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Breakables:OnMouseUp()
|
function Breakables:OnMouseUp(frame)
|
||||||
self.buttonFrame:StopMovingOrSizing()
|
frame:StopMovingOrSizing()
|
||||||
|
|
||||||
local _, _, _, xOff, yOff = self.buttonFrame:GetPoint(1)
|
local _, _, _, xOff, yOff = frame:GetPoint(1)
|
||||||
self.settings.buttonFrameLeft = xOff
|
self.settings.buttonFrameLeft = xOff
|
||||||
self.settings.buttonFrameTop = yOff
|
self.settings.buttonFrameTop = yOff
|
||||||
end
|
end
|
||||||
@ -459,21 +500,27 @@ function Breakables:FindBreakables(bag)
|
|||||||
self:SortBreakables(foundBreakables)
|
self:SortBreakables(foundBreakables)
|
||||||
|
|
||||||
for i=1,#foundBreakables do
|
for i=1,#foundBreakables do
|
||||||
local isDisenchantable = self:BreakableIsDisenchantable(foundBreakables[i][IDX_TYPE], foundBreakables[i][IDX_LEVEL])
|
|
||||||
if (CanDisenchant and isDisenchantable) or foundBreakables[i][IDX_COUNT] >= 5 then
|
|
||||||
if not self.breakableButtons then
|
if not self.breakableButtons then
|
||||||
self.breakableButtons = {}
|
self.breakableButtons = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i=1,numEligibleProfessions do
|
||||||
|
if not self.breakableButtons[i] then
|
||||||
|
self.breakableButtons[i] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if foundBreakables[i][IDX_TYPE] == self.buttonFrame[i].type then
|
||||||
|
local isDisenchantable = self:BreakableIsDisenchantable(foundBreakables[i][IDX_TYPE], foundBreakables[i][IDX_LEVEL])
|
||||||
|
if (CanDisenchant and isDisenchantable) or foundBreakables[i][IDX_COUNT] >= 5 then
|
||||||
numBreakableStacks = numBreakableStacks + 1
|
numBreakableStacks = numBreakableStacks + 1
|
||||||
|
|
||||||
local btn = self.breakableButtons[numBreakableStacks]
|
local btn = self.breakableButtons[i][numBreakableStacks]
|
||||||
if not self.breakableButtons[numBreakableStacks] then
|
if not self.breakableButtons[i][numBreakableStacks] then
|
||||||
self.breakableButtons[numBreakableStacks] = CreateFrame("Button", "BreakablesButtonStackFrame"..numBreakableStacks, self.buttonFrame, "SecureActionButtonTemplate")
|
self.breakableButtons[i][numBreakableStacks] = CreateFrame("Button", "BreakablesButtonStackFrame"..numBreakableStacks, self.buttonFrame[i], "SecureActionButtonTemplate")
|
||||||
|
|
||||||
btn = self.breakableButtons[numBreakableStacks]
|
btn = self.breakableButtons[i][numBreakableStacks]
|
||||||
|
|
||||||
btn:SetPoint("LEFT", numBreakableStacks == 1 and self.buttonFrame or self.breakableButtons[numBreakableStacks - 1], "RIGHT")
|
btn:SetPoint("LEFT", numBreakableStacks == 1 and self.buttonFrame[i] or self.breakableButtons[i][numBreakableStacks - 1], "RIGHT")
|
||||||
btn:SetWidth(buttonSize * self.settings.buttonScale)
|
btn:SetWidth(buttonSize * self.settings.buttonScale)
|
||||||
btn:SetHeight(buttonSize * self.settings.buttonScale)
|
btn:SetHeight(buttonSize * self.settings.buttonScale)
|
||||||
btn:EnableMouse(true)
|
btn:EnableMouse(true)
|
||||||
@ -515,21 +562,19 @@ function Breakables:FindBreakables(bag)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.breakableButtons and numBreakableStacks < #self.breakableButtons then
|
|
||||||
for i=numBreakableStacks+1,#self.breakableButtons do
|
|
||||||
self.breakableButtons[i]:Hide()
|
|
||||||
self.breakableButtons[i].icon:SetTexture(nil)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.buttonFrame then
|
for i=1,numEligibleProfessions do
|
||||||
if numBreakableStacks == 0 and self.settings.hideIfNoBreakables then
|
if self.breakableButtons[i] and numBreakableStacks < #self.breakableButtons[i] then
|
||||||
self.buttonFrame:Hide()
|
for j=numBreakableStacks+1,#self.breakableButtons[i] do
|
||||||
else
|
self.breakableButtons[i][j]:Hide()
|
||||||
self.buttonFrame:Show()
|
self.breakableButtons[i][j].icon:SetTexture(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:ToggleButtonFrameVisibility(not (numBreakableStacks == 0 and self.settings.hideIfNoBreakables))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Breakables:OnEnterBreakableButton(this, breakable)
|
function Breakables:OnEnterBreakableButton(this, breakable)
|
||||||
|
Reference in New Issue
Block a user