local R=require(script.Parent:WaitForChild("\066\097\115\101\084\101\115\116"))local s=require((script.Parent:WaitForChild("\067\111\109\109\111\110")):WaitForChild("\080\114\111\098\108\101\109\072\105\103\104\108\105\103\104\116\115"))local t=R:Extend()t:SetClassName("\083\117\114\102\097\099\101\071\117\105\083\099\114\111\108\108\105\110\103\070\114\097\109\101\084\101\115\116")function t.__new(R)R:InitializeSuper()R.Name="\083\117\114\102\097\099\101\071\117\105 \083\099\114\111\108\108\105\110\103\070\114\097\109\101\115"R.Icon="\078\079\078\069"R.Status="\078\111\116 \068\101\116\101\099\116\101\100"R.ProblemText="\083\099\114\111\108\108\105\110\103\070\114\097\109\101\115 \105\110 \083\117\114\102\097\099\101\071\117\105\115 \097\114\101 \100\105\102\102\105\099\117\108\116 \116\111 \117\115\101 \105\110 \086\082\044 \097\110\100 \097\114\101 \097\108\115\111 \112\114\111\098\108\101\109\097\116\105\099 \102\111\114 \099\111\110\115\111\108\101 \097\110\100 \109\111\098\105\108\101 \117\115\101\114\115\046"R.SolutionText="\078\111\116 \117\115\105\110\103 \083\099\114\111\108\108\105\110\103\070\114\097\109\101\115 \105\115 \116\104\101 \114\101\099\111\109\109\101\110\100\101\100 \097\112\112\114\111\097\099\104\046 \085\115\105\110\103 \112\097\103\101\115 \111\114 \117\115\105\110\103 \097\117\116\111-\115\099\114\111\108\108\105\110\103 \105\115 \114\101\099\111\109\109\101\110\100\101\100 \105\110\115\116\101\097\100\046"R.SurfaceGuiEvents={}R.SurfaceGuiProblems={}R.Highlights=s.new(R)game.DescendantRemoving:Connect(function(s)if not R.SurfaceGuiEvents[s]then return end for R,s in pairs(R.SurfaceGuiEvents[s])do s:Disconnect()end R.SurfaceGuiEvents[s]=nil R.SurfaceGuiProblems[s]=nil R:UpdateState()end)game.DescendantAdded:Connect(function(s)if R.SurfaceGuiEvents[s]then return end R:ConnectSurfaceGui(s)end)for s,t in pairs(game:GetDescendants())do R:ConnectSurfaceGui(t)end end function t.ConnectSurfaceGui(s,R)local t,W=pcall(function()return R:IsA("\083\117\114\102\097\099\101\071\117\105")end)if not t or not W then return end s.SurfaceGuiEvents[R]={}s.SurfaceGuiProblems[R]={}table.insert(s.SurfaceGuiEvents[R],R.DescendantAdded:Connect(function(t)if not t:IsA("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")then return end s.SurfaceGuiProblems[R][t]=true s:UpdateState()end))table.insert(s.SurfaceGuiEvents[R],R.DescendantRemoving:Connect(function(t)if not t:IsA("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")then return end s.SurfaceGuiProblems[R][t]=nil s:UpdateState()end))for t,W in pairs(R:GetDescendants())do if W:IsA("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")then s.SurfaceGuiProblems[R][W]=true s:UpdateState()end end end function t.UpdateState(R)local s={}for R,t in pairs(R.SurfaceGuiProblems)do for t,W in pairs(t)do table.insert(s,R)break end end if#s>0 then R.Icon="\087\065\082\078\073\078\071"R.Status="\080\114\111\098\108\101\109 \068\101\116\101\099\116\101\100"else R.Icon="\078\079\078\069"R.Status="\078\111\116 \068\101\116\101\099\116\101\100"end local t={}local W={}for R,s in pairs(s)do local V=s.Adornee or s.Parent and(s.Parent:IsA("\066\097\115\101\080\097\114\116")and s.Parent)if V and not W[V]then W[V]=true table.insert(t,V)end end R.Highlights.Objects=t end return t
--[[
TheNexusAvenger

Test for SurfaceGuis containing ScrollingFrames.
--]]

local BaseTest = require(script.Parent:WaitForChild("BaseTest"))
local ProblemHighlights = require(script.Parent:WaitForChild("Common"):WaitForChild("ProblemHighlights"))

local SurfaceGuiScrollingFrameTest = BaseTest:Extend()
SurfaceGuiScrollingFrameTest:SetClassName("SurfaceGuiScrollingFrameTest")



--[[
Creates the test.
--]]
function SurfaceGuiScrollingFrameTest:__new()
    self:InitializeSuper()

    --Set up the initial state.
    self.Name = "SurfaceGui ScrollingFrames"
    self.Icon = "NONE"
    self.Status = "Not Detected"
    self.ProblemText = "ScrollingFrames in SurfaceGuis are difficult to use in VR, and are also problematic for console and mobile users."
    self.SolutionText = "Not using ScrollingFrames is the recommended approach. Using pages or using auto-scrolling is recommended instead."
    self.SurfaceGuiEvents = {}
    self.SurfaceGuiProblems = {}
    self.Highlights = ProblemHighlights.new(self)

    --Connect SurfaceGuis in the game.
    game.DescendantRemoving:Connect(function(Ins)
        if not self.SurfaceGuiEvents[Ins] then return end
        for _,Event in pairs(self.SurfaceGuiEvents[Ins]) do
            Event:Disconnect()
        end
        self.SurfaceGuiEvents[Ins] = nil
        self.SurfaceGuiProblems[Ins] = nil
        self:UpdateState()
    end)
    game.DescendantAdded:Connect(function(Ins)
        if self.SurfaceGuiEvents[Ins] then return end
        self:ConnectSurfaceGui(Ins)
    end)
    for _,Ins in pairs(game:GetDescendants()) do
        self:ConnectSurfaceGui(Ins)
    end
end

--[[
Connects a SurfaceGui.
--]]
function SurfaceGuiScrollingFrameTest:ConnectSurfaceGui(SurfaceGui)
    --Use a pcall to determine the type. game exposes non-usable instances.
    local Worked,Return = pcall(function()
        return SurfaceGui:IsA("SurfaceGui")
    end)
    if not Worked or not Return then return end

    --Connect the events.
    self.SurfaceGuiEvents[SurfaceGui] = {}
    self.SurfaceGuiProblems[SurfaceGui] = {}
    table.insert(self.SurfaceGuiEvents[SurfaceGui],SurfaceGui.DescendantAdded:Connect(function(Ins)
        if not Ins:IsA("ScrollingFrame") then return end
        self.SurfaceGuiProblems[SurfaceGui][Ins] = true
        self:UpdateState()
    end))
    table.insert(self.SurfaceGuiEvents[SurfaceGui],SurfaceGui.DescendantRemoving:Connect(function(Ins)
        if not Ins:IsA("ScrollingFrame") then return end
        self.SurfaceGuiProblems[SurfaceGui][Ins] = nil
        self:UpdateState()
    end))

    --Connect the existing instances.
    for _,Ins in pairs(SurfaceGui:GetDescendants()) do
        if Ins:IsA("ScrollingFrame") then
            self.SurfaceGuiProblems[SurfaceGui][Ins] = true
            self:UpdateState()
        end
    end
end

--[[
Updates the state.
--]]
function SurfaceGuiScrollingFrameTest:UpdateState()
    --Determine the problematic SurfaceGuis.
    local SurfaceGuis = {}
    for SurfaceGui,FrameProblemsMap in pairs(self.SurfaceGuiProblems) do
        for _,_ in pairs(FrameProblemsMap) do
            table.insert(SurfaceGuis,SurfaceGui)
            break
        end
    end

    --Set the state if there is a problematic SurfaceGui and it wasn't set already.
    if #SurfaceGuis > 0 then
        self.Icon = "WARNING"
        self.Status = "Problem Detected"
    else
        self.Icon = "NONE"
        self.Status = "Not Detected"
    end

    --Get the parts to adorn.
    local AdornParts = {}
    local AdornPartsMap = {}
    for _,SurfaceGui in pairs(SurfaceGuis) do
        local Adornee = SurfaceGui.Adornee or (SurfaceGui.Parent and SurfaceGui.Parent:IsA("BasePart") and SurfaceGui.Parent)
        if Adornee and not AdornPartsMap[Adornee] then
            AdornPartsMap[Adornee] = true
            table.insert(AdornParts,Adornee)
        end
    end
    self.Highlights.Objects = AdornParts
end



return SurfaceGuiScrollingFrameTest