local addonName,addonData = ...
local myScrollFrame
addonData.Options = {
FrameWidth = 500,
FrameHeight = 150,
IsMovable = true,
HasBorder = true,
}
addonData.SetMovable = function(self,frame)
if not frame then return end
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart",function(self)
self:StartMoving()
end)
frame:SetScript("OnDragStop",function(self)
self:StopMovingOrSizing()
self:SetUserPlaced(true)
self:SetClampedToScreen(true)
end)
frame:SetScript("OnHide",function(self)
self:StopMovingOrSizing()
self:SetUserPlaced(true)
self:SetClampedToScreen(true)
end)
end
addonData.AddBorder = function(self,frame)
local border = CreateFrame("Frame",_G[frame:GetName().."Border"],frame)
border:SetFrameLevel(frame:GetFrameLevel()-1)
border:SetFrameStrata(frame:GetFrameStrata())
border:ClearAllPoints()
border:SetPoint("TOPLEFT",-10,10)
border:SetPoint("BOTTOMRIGHT",35,-10)
local backDrop = {
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:SetBackdrop(backDrop)
border:SetBackdropBorderColor( 1, 1, 0, 1 )
border:SetBackdropColor( 0, 0, 0, 1 )
frame.border = border
end
addonData.BuildScrollFrame = function(self,name,parent,options)
parent = parent or UIParent
local frame = CreateFrame("ScrollFrame",name,parent,"UIPanelScrollFrameTemplate")
frame.ScrollBar = _G[frame:GetName() .. "ScrollBar"];
frame.ScrollBar:SetPoint("LEFT",frame,"RIGHT",5,0)
frame:SetWidth(options.FrameWidth - 55)
frame:SetHeight(options.FrameHeight - 20)
if options.HasBorder then
self:AddBorder(frame)
end
if options.IsMovable then
self:SetMovable(frame)
if not frame:SetUserPlaced() then
frame:SetPoint("CENTER",parent,"CENTER",10,-10)
end
else
frame:SetPoint("CENTER",parent,"CENTER",10,-10)
end
ScrollFrame_OnLoad(frame)
frame:UpdateScrollChildRect()
frame:SetScript("OnScrollRangeChanged",function(self,xrange,yrange)
ScrollFrame_OnScrollRangeChanged(self, xrange, yrange)
self:UpdateScrollChildRect()
end)
frame:SetScript("OnVerticalScroll",function(self,offset)
addonData:OnVerticalScroll(frame,offset)
self:UpdateScrollChildRect()
end)
frame:SetScript("OnMouseWheel",function(self,delta)
ScrollFrameTemplate_OnMouseWheel(self, delta)
self:UpdateScrollChildRect()
end)
return frame
end
addonData.OnVerticalScroll = function(self,frame,offset)
if offset == 0 then return end
local scrollbar = _G[frame:GetName().."ScrollBar"];
scrollbar:SetValue(offset);
local min;
local max;
min, max = scrollbar:GetMinMaxValues();
if ( offset == 0 ) then
_G[scrollbar:GetName().."ScrollUpButton"]:Disable();
else
_G[scrollbar:GetName().."ScrollUpButton"]:Enable();
end
if ((scrollbar:GetValue() - max) == 0) then
_G[scrollbar:GetName().."ScrollDownButton"]:Disable();
else
_G[scrollbar:GetName().."ScrollDownButton"]:Enable();
end
end
local function CreateScrollFrame()
myScrollFrame = addonData:BuildScrollFrame("XrystalScrollFrame_ObjectivesTracker",UIParent,addonData.Options)
end
local OTFMoving
hooksecurefunc(ObjectiveTrackerFrame, "SetPoint", function(self)
if not myScrollFrame then return end
if OTFMoving then return end
OTFMoving = true
self:SetMovable(true)
self:SetUserPlaced(true)
self:ClearAllPoints()
self:SetPoint("TOPLEFT", myScrollFrame, "TOPLEFT", 30, 0)
self:SetScale(1.1)
self:SetWidth(addonData.Options.FrameWidth - 30)
self:SetHeight(1000)
myScrollFrame:SetScrollChild(self)
self:SetMovable(false)
OTFMoving = nil
end)
--DEFAULT_OBJECTIVE_TRACKER_MODULE.blockOffsetX = 30
CreateScrollFrame()