Originally Posted by Xrystal
Well, rigged up a mini addon, to create a scrolling frame to hold the tracker frame in and all seems fine except ...
I need that line that is commented out to keep the offset correct for my frame as otherwise the POI Icons and half of the check marks are too far left and are invisible. However, the moment I use that line it causes the taint message. This is a very basic version to my addon but visually it is useless without that offset being able to be used.
|
Give this a shot:
Code:
local addonName, addon = ...
local options = {
width = 445,
height = 130,
isMovable = true,
hasBorder = true,
-- scale = 1.1,
}
local scrollFrame = CreateFrame('ScrollFrame', "XrystalScrollFrame_ObjectivesTracker", UIParent, 'UIPanelScrollFrameTemplate')
scrollFrame:SetFrameStrata(ObjectiveTrackerFrame:GetFrameStrata())
scrollFrame:SetSize(options.width, options.height)
scrollFrame:SetPoint('CENTER', 10, -10)
if options.hasBorder then
local border = CreateFrame('Frame', nil, scrollFrame)
border:SetFrameLevel(scrollFrame:GetFrameLevel() - 1)
border:SetPoint('TOPLEFT', -10, 10)
border:SetPoint('BOTTOMRIGHT', 35, -10)
border:SetBackdrop({
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
border:SetBackdropBorderColor(1, 1, 0, 1)
border:SetBackdropColor(0, 0, 0, 1)
end
if options.isMovable then
scrollFrame:EnableMouse(true)
scrollFrame:SetMovable(true)
scrollFrame:SetUserPlaced(true)
scrollFrame:SetClampedToScreen(true)
scrollFrame:RegisterForDrag('LeftButton')
scrollFrame:SetScript('OnDragStart', scrollFrame.StartMoving)
scrollFrame:SetScript('OnDragStop', scrollFrame.StopMovingOrSizing)
scrollFrame:SetScript('OnHide', scrollFrame.StopMovingOrSizing)
end
if options.scale then
ObjectiveTrackerFrame:SetScale(options.scale)
end
local scrollBar = scrollFrame.ScrollBar
scrollBar:SetPoint('LEFT', frame, 'RIGHT', 5, 0)
local scrollChild = ObjectiveTrackerFrame.HeaderMenu.MinimizeButton
scrollChild:SetParent(UIParent)
scrollChild:ClearAllPoints()
scrollChild:SetPoint('TOPLEFT', scrollFrame)
scrollChild:SetSize(options.width - 30, 1080)
scrollChild:EnableMouse(false)
ObjectiveTrackerFrame:SetParent(scrollChild)
scrollFrame:SetScrollChild(scrollChild)
local frame = EnumerateFrames()
while frame do
if not frame.UIParentManageFramePositions then
frame = EnumerateFrames(frame)
else
hooksecurefunc(frame, 'UIParentManageFramePositions', function()
ObjectiveTrackerFrame:ClearAllPoints()
ObjectiveTrackerFrame:SetPoint('TOPLEFT', 30, 0)
ObjectiveTrackerFrame:SetPoint('BOTTOMRIGHT')
end)
frame = nil
end
end
ObjectiveTrackerFrame:SetScript('OnSizeChanged', nil)
local function SetScrollLimit(maxOffset)
scrollBar:SetMinMaxValues(0, maxOffset)
local offset = scrollBar:GetValue()
scrollBar.ScrollUpButton:SetEnabled(offset > 0.005)
scrollBar.ScrollDownButton:SetEnabled(maxOffset - offset > 0.005)
end
local function ScrollFrame_OnUpdate(self)
self:SetScript('OnUpdate', nil)
local modules, top = ObjectiveTrackerFrame.MODULES, ObjectiveTrackerFrame:GetTop()
local bottom = top
if modules then
for index = 1, #modules do
for _, block in pairs(modules[index].usedBlocks) do
for _, line in pairs(block.lines) do
if line.used then
local lineBottom = line:GetBottom() or top
if lineBottom < bottom then
bottom = lineBottom
end
end
end
end
end
end
local maxOffset = top - bottom - options.height
SetScrollLimit(maxOffset >= 0 and maxOffset or 0)
end
local inCombat
local function QueueScrollRangeUpdate()
if not inCombat then
scrollFrame:SetScript('OnUpdate', ScrollFrame_OnUpdate)
end
end
hooksecurefunc('ObjectiveTracker_Update', QueueScrollRangeUpdate)
scrollFrame:SetScript('OnHide', QueueScrollRangeUpdate)
scrollFrame:SetScript('OnEvent', function(self, event)
if event == 'PLAYER_REGEN_DISABLED' then
inCombat = true
self:SetScript('OnUpdate', nil)
SetScrollLimit(1080 - options.height)
else
inCombat = nil
self:SetScript('OnUpdate', ScrollFrame_OnUpdate)
end
end)
scrollFrame:RegisterEvent('PLAYER_REGEN_DISABLED')
scrollFrame:RegisterEvent('PLAYER_REGEN_ENABLED')
local function ClaimTexture(frame, texture, key)
texture:SetParent(frame)
texture:ClearAllPoints()
texture:SetAllPoints()
if key then
frame[key] = texture
end
end
local minimizeButton = CreateFrame('Button', nil, UIParent, 'SecureHandlerClickTemplate')
minimizeButton:SetFrameStrata(ObjectiveTrackerFrame:GetFrameStrata())
minimizeButton:SetFrameLevel(ObjectiveTrackerFrame:GetFrameLevel() + 2)
minimizeButton:SetPoint('TOPRIGHT', scrollFrame, 'TOPLEFT', 10, 7)
minimizeButton:SetSize(16, 16)
ClaimTexture(minimizeButton, scrollChild:GetNormalTexture(), "normalTexture")
ClaimTexture(minimizeButton, scrollChild:GetPushedTexture(), "pushedTexture")
ClaimTexture(minimizeButton, scrollChild:GetHighlightTexture())
scrollFrame:SetScript('OnHide', function()
minimizeButton.normalTexture:SetTexCoord(0, 0.5, 0, 0.5)
minimizeButton.pushedTexture:SetTexCoord(0.5, 1, 0, 0.5)
end)
scrollFrame:SetScript('OnShow', function()
minimizeButton.normalTexture:SetTexCoord(0, 0.5, 0.5, 1)
minimizeButton.pushedTexture:SetTexCoord(0.5, 1, 0.5, 1)
end)
minimizeButton:SetFrameRef("scrollFrame", scrollFrame)
minimizeButton:Execute([[
scrollFrame = self:GetFrameRef("scrollFrame")
self:SetAttribute("frameref-scrollFrame", nil)
]])
minimizeButton:SetAttribute('_onclick', [[
scrollFrame[scrollFrame:IsShown() and 'Hide' or 'Show'](scrollFrame)
]])
There are a couple issues with dynamically updating the scroll range but otherwise it seems to behave ok.