Advertisement
TaylorsRus

CatalogueManager

Mar 4th, 2024
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.27 KB | None | 0 0
  1. local CatalogueManager = {}
  2.  
  3. local MarketplaceService = game:GetService("MarketplaceService")
  4. local InputService = game:GetService("UserInputService")
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6. local SoundService = game:GetService("SoundService")
  7. local InsertService = game:GetService("InsertService")
  8.  
  9. local Player = game:GetService("Players").LocalPlayer
  10. local Mouse = Player:GetMouse()
  11. local Camera = workspace.CurrentCamera
  12.  
  13. local PlayerGui = Player:WaitForChild("PlayerGui")
  14. local AccessoryHold = ReplicatedStorage:WaitForChild("AccessoryHold")
  15. local Config = ReplicatedStorage:WaitForChild("Config")
  16. local Events = ReplicatedStorage:WaitForChild("Events")
  17.  
  18. local ProductData = require(Config:WaitForChild("Product"))
  19.  
  20. local RequestData = Events:WaitForChild("RequestData")
  21. local SendRequest = Events:WaitForChild("SendRequest")
  22.  
  23. local CatalogueGui = PlayerGui:WaitForChild("CatalogueGui")
  24. local MainFrame = CatalogueGui:WaitForChild("MainFrame")
  25.  
  26. local ScrollingFrame = MainFrame:WaitForChild("ScrollingFrame")
  27. local SearchRibbon = MainFrame:WaitForChild("SearchRibbon")
  28. local TabsRibbon = MainFrame:WaitForChild("TabsRibbon")
  29. local TextBox = SearchRibbon:WaitForChild("TextBox")
  30.  
  31. local Designer = workspace:WaitForChild("Designer")
  32. local Avatar = Designer:WaitForChild("Avatar")
  33.  
  34. local Humanoid, HumRP = Avatar:WaitForChild("Humanoid"),
  35.     Avatar:WaitForChild("HumanoidRootPart")
  36.  
  37. local ItemAssociations = {
  38.     Head = {
  39.         "Hat",
  40.         "Hair",
  41.         "Face",
  42.         "Neck",
  43.         "Eyebrow",
  44.         "Eyelash"
  45.     },
  46.     Torso = {
  47.         "Neck",
  48.         "Shoulder",
  49.         "Front",
  50.         "Back",
  51.         "Waist",
  52.         "TShirt",
  53.         "Shirt",
  54.         "Pants",
  55.         "Jacket",
  56.         "Sweater",
  57.         "Unknown",
  58.     },
  59.     Arms = {
  60.         "TShirt",
  61.         "Shirt",
  62.         "Jacket",
  63.         "Sweater",
  64.     },
  65.     Legs = {
  66.         "Waist",
  67.         "Pants",
  68.         "Shorts",
  69.         "LeftShoe",
  70.         "RightShoe",
  71.         "DressSkirt"
  72.     }
  73. }
  74.  
  75. local CatalogueData = {}
  76. local CatalogueConnections = {
  77.     --[[ View = {
  78.             Cell = {
  79.                 Base = {
  80.                     --// Connections on the cell itself
  81.                     ConnectionName = RbxScriptSignal
  82.                 },
  83.                 Any other keys will be separate objects within the cell, which
  84.                 will also have a table of connections.
  85.                
  86.                 ex; Try = {
  87.                     MouseButton1Click = RbxScriptSignal
  88.                 }
  89.             }
  90.         }]]
  91. }
  92. --// Scale values, not offset.
  93. local HORIZONTAL_GAP = .247
  94. local VERTICAL_GAP = .359
  95.  
  96. local CELL_BASE_TRANSPARENCY = .5
  97. local CELL_HOVER_TRANSPARENCY = .4
  98. local CELL_ACTIVATED_TRANSPARENCY = .25
  99.  
  100. --// Both values are percentage based on ViewportSize
  101. local MOUSE_PORTION_X_OFFSET = .4
  102. local MOUSE_PORTION_X_SIZE = 50
  103. local MOUSE_PORTION_Y_SIZE = 90
  104.  
  105. local AVATAR_ROTATION_SPEED = .5
  106.  
  107. local EQUIP_COLOR = Color3.fromRGB(49, 43, 162)
  108. local TAKE_OFF_COLOR = Color3.fromRGB(150, 44, 44)
  109.  
  110. local FirstItem = true
  111. local MouseInScreenPortion = false
  112. local MouseHoldingScreenPortion = false
  113.  
  114. local LastMousePosition = 0
  115. local InitialClick = true
  116.  
  117. local function VisualizeScreenPortion(PortionWidth, PortionHeight, PortionPosition)
  118.     local ScreenGui = Instance.new("ScreenGui")
  119.     local PortionFrame = Instance.new("Frame")
  120.    
  121.     ScreenGui.Name = "ScreenPortionDEBUG"
  122.     ScreenGui.IgnoreGuiInset = true
  123.    
  124.     PortionFrame.Position = UDim2.new(0, PortionPosition.X, 0, PortionPosition.Y)
  125.     PortionFrame.Size = UDim2.new(0, PortionWidth, 0, PortionHeight)
  126.     PortionFrame.BackgroundTransparency = .75
  127.    
  128.     PortionFrame.Parent = ScreenGui
  129.     ScreenGui.Parent = PlayerGui
  130. end
  131.  
  132. local function ScaleToOffset(X, Y, ParentFrame)
  133.     local ViewportSize = Camera.ViewportSize
  134.  
  135.     X = ParentFrame ~= nil and X * ParentFrame.AbsoluteSize.X
  136.         or X * ViewportSize.X
  137.     Y = ParentFrame ~= nil and Y * ParentFrame.AbsoluteSize.Y
  138.         or Y * ViewportSize.Y
  139.     return X, Y
  140. end
  141.  
  142. local function OffsetToScale(X, Y, ParentFrame)
  143.     local ViewportSize = Camera.ViewportSize
  144.    
  145.     X = ParentFrame ~= nil and X / ParentFrame.AbsoluteSize.X
  146.         or X / ViewportSize.X
  147.     Y = ParentFrame ~= nil and Y / ParentFrame.AbsoluteSize.Y
  148.         or Y / ViewportSize.Y
  149.     return X, Y
  150. end
  151.  
  152. local function CompareIndicies(A, B)
  153.     local NameA = CatalogueData[A].Name:lower()
  154.     local NameB = CatalogueData[B].Name:lower()
  155.  
  156.     return NameA < NameB
  157. end
  158.  
  159. local function GetConvertedGeometryOfGuiObject(GuiObject, Geometry, Type)
  160.     local ConvertFunction = Type == "Offset" and ScaleToOffset
  161.         or Type == "Scale" and OffsetToScale
  162.    
  163.     local InitialGeometry = GuiObject[Geometry]
  164.     local InitialX, InitialY = InitialGeometry.X[Type], InitialGeometry.Y[Type]
  165.     if Type == "Offset" then
  166.         InitialX, InitialY = InitialX / 1000, InitialY / 1000
  167.     end
  168.    
  169.     local NewX, NewY = ConvertFunction(InitialX, InitialY, GuiObject.Parent)
  170.     local NewGeometry = Type == "Offset" and UDim2.new(0, NewX, 0, NewY) or
  171.             Type == "Scale" and UDim2.new(NewX, 0, NewY, 0)
  172.     return NewGeometry
  173. end
  174.  
  175. local function ConvertCatalogueToOffset()
  176.     for _,View in ipairs(ScrollingFrame:GetChildren()) do
  177.         for _,Gui in ipairs(View:GetDescendants()) do
  178.             --// We look for GuiButton and Frame so we don't have cutoff at the bottom for the details of the cell.
  179.             if not Gui:IsA("GuiButton") and not Gui:IsA("Frame") then
  180.                 continue
  181.             end
  182.  
  183.             local Details = Gui:FindFirstChild("Details")
  184.             local GuiSize, GuiPosition = Gui.Size, Gui.Position
  185.  
  186.             local NewSize = GetConvertedGeometryOfGuiObject(Gui, "Size", "Offset")
  187.             local NewPosition = GetConvertedGeometryOfGuiObject(Gui, "Position", "Offset")
  188.            
  189.             warn(`NewSize: {NewSize}, NewPosition: {NewPosition}`)
  190.             if NewSize ~= UDim2.new(0, 0, 0, 0) then
  191.                 Gui.Size = NewSize
  192.             end
  193.             if NewPosition ~= UDim2.new(0, 0, 0, 0) then
  194.                 Gui.Position = NewPosition
  195.             end
  196.            
  197.             if not Details then
  198.                 continue
  199.             end
  200.             for _,Label in ipairs(Details:GetChildren()) do
  201.                 NewSize = GetConvertedGeometryOfGuiObject(Gui, "Size", "Scale")
  202.                 NewPosition = GetConvertedGeometryOfGuiObject(Gui, "Position", "Scale")
  203.                
  204.                 if NewSize ~= UDim2.new(0, 0, 0, 0) then
  205.                     Gui.Size = NewSize
  206.                 end
  207.                 Gui.Position = NewPosition
  208.             end
  209.         end
  210.     end
  211.     --// Repeat for the details of the frame, after the parent has been scaled
  212. end
  213.  
  214. local function SortCatalogueAlpabetically()
  215.     local SortedCatalogue = {}
  216.     local CatalogueIndicies = {}
  217.  
  218.     for Index,_ in ipairs(CatalogueData) do
  219.         CatalogueIndicies[Index] = Index
  220.     end
  221.     table.sort(CatalogueIndicies, CompareIndicies)
  222.  
  223.     for _,Index in ipairs(CatalogueIndicies) do
  224.         table.insert(SortedCatalogue, CatalogueData[Index])
  225.     end
  226.     CatalogueData = {}
  227.  
  228.     for _,Data in ipairs(SortedCatalogue) do
  229.         table.insert(CatalogueData, Data)
  230.     end
  231. end
  232.  
  233. local function EnableCorrectViewFrame(Tab)
  234.     local SearchFrame = ScrollingFrame:FindFirstChild("Search")
  235.     local ViewFrame, EnabledLine = nil
  236.     if Tab ~= nil then
  237.         ViewFrame = ScrollingFrame:FindFirstChild(Tab.Name)
  238.         Tab.EnabledLine.BackgroundTransparency = 0
  239.  
  240.         if SearchFrame then
  241.             SearchFrame:Destroy()
  242.         end
  243.     else
  244.         ViewFrame = SearchFrame
  245.     end
  246.    
  247.     for _,OtherViewFrame in ipairs(ScrollingFrame:GetChildren()) do
  248.         if not OtherViewFrame:IsA("Frame") or OtherViewFrame == ViewFrame or OtherViewFrame.Name == "Search" then
  249.             continue
  250.         end
  251.         local OtherEnabledLine = TabsRibbon[OtherViewFrame.Name].EnabledLine
  252.  
  253.         OtherEnabledLine.BackgroundTransparency = 1
  254.         OtherViewFrame.Visible = false
  255.     end
  256.  
  257.     if ViewFrame and not ViewFrame.Visible then
  258.         ViewFrame.Visible = true
  259.     end
  260. end
  261.  
  262. local function EquipAsset(Try)
  263.     local Cell = Try.Parent
  264.     local AssetId = Cell:GetAttribute("AssetId")
  265.  
  266.     for _,AssetData in ipairs(CatalogueData) do
  267.         local Id = AssetData.AssetId       
  268.         if Id == AssetId then
  269.             SendRequest:FireServer("AddAccessoryToDesigner", AssetId)
  270.         end
  271.     end
  272.    
  273.     Try.BackgroundColor3 = TAKE_OFF_COLOR
  274.     Try.Text = "Take Off"
  275. end
  276.  
  277. local function DeEquipAsset(Try)
  278.     local Cell = Try.Parent
  279.     local Accessories = Humanoid:GetAccessories()
  280.     local AssetId = Cell:GetAttribute("AssetId")
  281.    
  282.     for _,Accessory in Accessories do
  283.         if Accessory:GetAttribute("AssetId") ~= AssetId then
  284.             continue
  285.         end  
  286.         Accessory:Destroy()
  287.     end
  288.    
  289.     Try.BackgroundColor3 = EQUIP_COLOR
  290.     Try.Text = "Try On"
  291. end
  292.  
  293. local function BuyMouseButton1Click(Buy)
  294.     local Cell = Buy.Parent
  295.     local AssetId = Cell:GetAttribute("AssetId")
  296.    
  297.     SendRequest:FireServer("PromptPurchase", AssetId)
  298. end
  299.  
  300. local function TryMouseButton1Click(Try)
  301.     local Cell = Try.Parent
  302.     local AssetId = Cell:GetAttribute("AssetId")
  303.  
  304.     local AssetEquipped = Cell:GetAttribute("Equipped")
  305.     local ResultingFunction = not AssetEquipped and EquipAsset
  306.         or DeEquipAsset
  307.    
  308.     ResultingFunction(Try) 
  309.     Cell:SetAttribute("Equipped", not AssetEquipped)
  310. end
  311.  
  312.  
  313. local function HideAllCellButtons(View)
  314.     for _,Cell in ipairs(View:GetChildren()) do
  315.         for _,Button in ipairs(Cell:GetChildren()) do
  316.             if not Button:IsA("GuiButton") then
  317.                 continue
  318.             end
  319.  
  320.             Button.Visible = false
  321.         end
  322.     end
  323. end
  324.  
  325. local function CellMouseEntered(Cell)
  326.     local Sound = _G.GetSound("Hover")
  327.     Sound.Parent = SoundService
  328.     Sound:Destroy()
  329.  
  330.     Cell.BackgroundTransparency = CELL_HOVER_TRANSPARENCY
  331. end
  332.  
  333. local function CellMouseLeft(Cell)
  334.     Cell.BackgroundTransparency = CELL_BASE_TRANSPARENCY
  335. end
  336.  
  337. local function CellMouse1Click(Cell)
  338.     local Click = _G.GetSound("Click")
  339.     local View = Cell.Parent
  340.     local Buy, Try = Cell.Buy, Cell.Try
  341.  
  342.     local Activated = nil
  343.  
  344.     --// First, we disable all cells Buy and Try buttons.
  345.     HideAllCellButtons(View)
  346.  
  347.     --// Then, we can enable our cells Buy and Try buttons.
  348.     print("CellMouse1Click ran.")
  349.     for _,Button in ipairs({Buy, Try}) do
  350.         Activated = Button.Visible
  351.         print(not Activated)
  352.         Button.Visible = not Activated
  353.     end
  354.  
  355.     local NewCellTransparency = Activated and CELL_ACTIVATED_TRANSPARENCY or CELL_BASE_TRANSPARENCY
  356.     Cell.BackgroundTransparency = NewCellTransparency
  357.     Click.Parent = SoundService
  358.     Click:Destroy()
  359. end
  360.  
  361. local function CellButtonMouse1Click(Button)
  362.     local Cell = Button.Parent
  363.     local Buy, Try = Cell.Buy, Cell.Try
  364.  
  365.     local Click = _G.GetSound("Click")
  366.    
  367.     local Function = Button.Name == "Buy" and BuyMouseButton1Click
  368.         or TryMouseButton1Click
  369.    
  370.     Function(Button)
  371.  
  372.     Buy.Visible, Try.Visible = false, false
  373.     Cell.BackgroundTransparency = CELL_BASE_TRANSPARENCY
  374.     Click.Parent = SoundService
  375.     Click:Destroy()
  376. end
  377.  
  378. local function EstablishCellConnections(Cell)
  379.     local View = Cell.Parent
  380.     local Try, Buy = Cell:WaitForChild("Try"),
  381.         Cell:WaitForChild("Buy")
  382.  
  383.     local ViewConnections = CatalogueConnections[View.Name]
  384.         ViewConnections.Base = {}
  385.         ViewConnections.Try = {}
  386.         ViewConnections.Buy = {}
  387.        
  388.     local BaseConnections = ViewConnections.Base
  389.     local TryConnections, BuyConnections = ViewConnections.Try, ViewConnections.Buy
  390.  
  391.     BaseConnections.MouseEnter = Cell.MouseEnter:Connect(function()
  392.         CellMouseEntered(Cell)
  393.     end)
  394.     BaseConnections.MouseLeave = Cell.MouseLeave:Connect(function()
  395.         CellMouseLeft(Cell)
  396.     end)
  397.     BaseConnections.Mouse1Click = Cell.MouseButton1Click:Connect(function()
  398.         CellMouse1Click(Cell)
  399.     end)
  400.    
  401.     for _,Button in ipairs({Try, Buy}) do
  402.         ViewConnections[Button.Name].Mouse1Click = Button.MouseButton1Click:Connect(function()
  403.             CellButtonMouse1Click(Button)
  404.         end)
  405.     end
  406. end
  407.  
  408. local function EstablishTabConnections(Tab)
  409.     Tab.MouseEnter:Connect(function()
  410.         local Sound = _G.GetSound("Hover")
  411.         Sound.Parent = SoundService
  412.         Sound:Destroy()
  413.  
  414.         Tab.ImageTransparency = .35
  415.     end)
  416.     Tab.MouseLeave:Connect(function()
  417.         Tab.ImageTransparency = 0
  418.     end)   
  419.     Tab.MouseButton1Click:Connect(function()
  420.         if Tab:GetAttribute("Enabled") then
  421.             return
  422.         end
  423.  
  424.         local Sound = _G.GetSound("Click")
  425.         Sound.Parent = SoundService
  426.         Sound:Destroy()
  427.  
  428.         Tab:SetAttribute("Enabled", true)
  429.         for _,OtherTab in ipairs(TabsRibbon:GetChildren()) do
  430.             if OtherTab == Tab then
  431.                 continue
  432.             end
  433.             Tab:SetAttribute("Enabled", false)
  434.         end
  435.         EnableCorrectViewFrame(Tab)
  436.     end)
  437. end
  438.  
  439.  
  440. local function EstablishViewConnections(View)
  441.     CatalogueConnections[View.Name] = {}
  442.     local ViewConnections = CatalogueConnections[View.Name]
  443.     for _,Cell in ipairs(View:GetChildren()) do
  444.  
  445.         ViewConnections[Cell.Name] = {}
  446.         ViewConnections.Base = {}
  447.         ViewConnections.Try = {}
  448.         ViewConnections.Buy = {}
  449.  
  450.         EstablishCellConnections(Cell)     
  451.     end
  452. end
  453.  
  454. local function CreateCatalogueCell(View)
  455.     local ViewFrame = ScrollingFrame[View.Name]
  456.     local FirstItem = ViewFrame:GetAttribute("FirstItem")
  457.  
  458.     local Column, Row = ViewFrame:GetAttribute("Column"),
  459.         ViewFrame:GetAttribute("Row")
  460.     local PreviousCellName = "Cell"..tostring(Row).."-"..(tostring(Column))
  461.  
  462.     local NewColumn = Column < 4 and Column + 1 or 1
  463.     local NewRow = NewColumn == 1 and Row + 1 or Row
  464.     local NewCellName = "Cell"..tostring(NewRow).."-"..tostring(NewColumn)
  465.  
  466.     local PreviousCell = ViewFrame[PreviousCellName]
  467.     local NewCell = PreviousCell:Clone()
  468.     if NewCell.Name:match("-(.)") == "4" then
  469.         NewCell = ViewFrame["Cell"..tostring(Row).."-1"]:Clone()
  470.     end
  471.  
  472.     local CurrentPosition = NewCell.Position
  473.     CurrentPosition = UDim2.fromScale(OffsetToScale(CurrentPosition.X.Offset, CurrentPosition.Y.Offset, ScrollingFrame))
  474.  
  475.     local NewPosition = NewRow == Row and UDim2.new(CurrentPosition.X.Scale + HORIZONTAL_GAP, 0, CurrentPosition.Y.Scale, 0)
  476.         or UDim2.new(CurrentPosition.X.Scale, 0, CurrentPosition.Y.Scale + VERTICAL_GAP, 0)
  477.     NewPosition = UDim2.fromOffset(ScaleToOffset(NewPosition.X.Scale, NewPosition.Y.Scale, ScrollingFrame))
  478.  
  479.     if FirstItem then
  480.         NewPosition = CurrentPosition
  481.         NewCellName = "Cell1-1"
  482.         NewColumn, NewRow = 1, 1
  483.  
  484.         ViewFrame:SetAttribute("FirstItem", false)
  485.         PreviousCell:Destroy()
  486.     end
  487.  
  488.     NewCell.Name = NewCellName
  489.     NewCell.Position = NewPosition
  490.     NewCell.Parent = ViewFrame 
  491.  
  492.     ViewFrame:SetAttribute("Column", NewColumn)
  493.     ViewFrame:SetAttribute("Row", NewRow)
  494.  
  495.     return NewCell
  496. end
  497.  
  498. --// Try and implement the search function into this functionality.
  499. local function CreateCatalogueView(View)
  500.     local ViewFrame = ScrollingFrame[View.Name]
  501.    
  502.     for _,AssetData in ipairs(CatalogueData) do
  503.         local AssetId, AssetName = AssetData.AssetId, AssetData.Name   
  504.         local Accessory = AssetData.Accessory
  505.         if Accessory == nil then
  506.             continue
  507.         end
  508.  
  509.         local AccessoryType = Accessory.AccessoryType
  510.         local CorrectAssetType = View.Name == "All" and true
  511.             or table.find(ItemAssociations[View.Name], AccessoryType.Name)
  512.         if not CorrectAssetType then
  513.             continue
  514.         end    
  515.  
  516.         local Name, Price = AssetData.Name, AssetData.PriceInRobux
  517.  
  518.         local Cell = CreateCatalogueCell(View)
  519.         local Details = Cell.Details
  520.         local NameLabel, PriceLabel = Details.Label, Details.Price     
  521.  
  522.         Cell.Image = `rbxthumb://type=Asset&id={AssetId}&w=420&h=420`
  523.         Cell:SetAttribute("AssetId", AssetId)
  524.         Cell:SetAttribute("Name", Name)
  525.  
  526.         NameLabel.Text, PriceLabel.Text = Name, tostring(Price)
  527.     end
  528.     EstablishViewConnections(ViewFrame)
  529.     --ConvertCatalogueToOffset()
  530. end
  531.  
  532. local function LoadAllAccessories()
  533.     for _,AssetData in ipairs(CatalogueData) do
  534.         local AssetId = AssetData.AssetId
  535.  
  536.         local AccessoryLoaded = RequestData:InvokeServer("LoadAccessory", AssetId)
  537.         if not AccessoryLoaded then
  538.             continue
  539.         end
  540.  
  541.         local Accessory = AccessoryHold:FindFirstChildOfClass("Accessory")
  542.         local AccessoryType = Accessory.AccessoryType
  543.         if AccessoryType == nil then
  544.             continue
  545.         end
  546.  
  547.         AssetData.Accessory = Accessory
  548.         Accessory.Parent = nil
  549.     end
  550. end
  551.  
  552. local function LoadCatalogueData()
  553.     for _,AssetId in ipairs(ProductData) do
  554.         table.insert(CatalogueData, MarketplaceService:GetProductInfo(AssetId))
  555.     end
  556.     SortCatalogueAlpabetically()
  557.     LoadAllAccessories()
  558. end
  559.  
  560. local function RemoveCellsFromSearchResult(View, Result)   
  561.     for _,Cell in ipairs(View:GetChildren()) do
  562.         local AssetName = string.lower(Cell:GetAttribute("Name") or "")
  563.         local NameContainsSearch = string.find(AssetName, Result)
  564.  
  565.         if not NameContainsSearch then
  566.             Cell:Destroy()
  567.         else
  568.             Cell.Position = UDim2.new(0, 0, 0, 0)
  569.         end
  570.     end
  571. end
  572.  
  573. local function PositionBunchedCells(View)
  574.     local PreviousCell = nil
  575.  
  576.     for _,Cell in ipairs(View:GetChildren()) do
  577.         local Row, Column = View:GetAttribute("Row") or 1,
  578.             View:GetAttribute("Column") or 1
  579.         local NewColumn = (Column + 1 <= 4 and Column + 1) or 1
  580.         if PreviousCell == nil then
  581.             NewColumn = 1
  582.         end
  583.         local NewRow = (NewColumn == 1 and Row + 1) or Row
  584.  
  585.         local CurrentPosition = PreviousCell and PreviousCell.Position or Cell.Position
  586.         CurrentPosition = UDim2.fromScale(OffsetToScale(CurrentPosition.X.Offset, CurrentPosition.Y.Offset, ScrollingFrame))
  587.  
  588.         local NewPosition = NewRow == Row and UDim2.new(CurrentPosition.X.Scale + HORIZONTAL_GAP, 0, CurrentPosition.Y.Scale, 0)
  589.             or UDim2.new(0, 0, CurrentPosition.Y.Scale + VERTICAL_GAP, 0)
  590.         NewPosition = UDim2.fromOffset(ScaleToOffset(NewPosition.X.Scale, NewPosition.Y.Scale, ScrollingFrame))
  591.  
  592.         if PreviousCell == nil then
  593.             NewPosition = UDim2.new(0, 0, 0, 0)
  594.         end
  595.  
  596.         Cell.Name = "Cell"..Row.."-"..Column
  597.         Cell.Position = NewPosition
  598.  
  599.         View:SetAttribute("Row", NewRow)
  600.         View:SetAttribute("Column", NewColumn)
  601.         PreviousCell = Cell
  602.     end
  603.  
  604.     --ConvertCatalogueToOffset()
  605. end
  606.  
  607. local function ValidateSearchResults()
  608.     local Result = TextBox.Text
  609.     Result = string.lower(Result)
  610.  
  611.     local OldView = ScrollingFrame:FindFirstChild("Search")
  612.     if OldView then
  613.         OldView:Destroy()
  614.     end
  615.    
  616.     if Result == "" then
  617.         EnableCorrectViewFrame("All")
  618.         return
  619.     end
  620.    
  621.     local NewView = ScrollingFrame.All:Clone()     
  622.     NewView.Name = "Search"
  623.     NewView.Parent = ScrollingFrame
  624.     NewView:SetAttribute("Row", 1)
  625.     NewView:SetAttribute("Column", 1)
  626.  
  627.     RemoveCellsFromSearchResult(NewView, Result)   
  628.     PositionBunchedCells(NewView)
  629.     EnableCorrectViewFrame()
  630.  
  631.     for _,ViewFrame in ipairs(ScrollingFrame:GetChildren()) do
  632.         if ViewFrame == NewView then
  633.             continue
  634.         end
  635.         ViewFrame.Visible = false
  636.     end
  637. end
  638.  
  639. local function PlayRadioMusic(Radio)
  640.     local Playlist = _G.GetSound("Music")
  641.     local DistortionEffect = Instance.new("DistortionSoundEffect")
  642.         DistortionEffect.Level = .4
  643.        
  644.     task.spawn(function()
  645.         while true do task.wait()
  646.             local SongValues = _G.ArrayFromDictionary(Playlist)
  647.            
  648.             for Name, Song in Playlist do
  649.                 local RandomIndex = math.random(1, #SongValues)
  650.                 local RandomSong = SongValues[RandomIndex]
  651.                
  652.                 if Song ~= RandomSong then
  653.                     continue
  654.                 end
  655.                
  656.                 table.remove(SongValues, RandomIndex)
  657.                 Song.PlayOnRemove = false
  658.                 Song.Volume = 1
  659.                 Song.Parent = Radio
  660.                 Song:Play()
  661.                
  662.                 warn(`Now playing: {Name}`)
  663.                 Song.Ended:Wait()
  664.                 Song:Destroy()
  665.             end
  666.         end
  667.     end)
  668. end
  669.  
  670. local function IsMouseInScreenPortion()
  671.     local MousePosition = InputService:GetMouseLocation()
  672.     local ViewportSize = Camera.ViewportSize
  673.     local ScreenWidth, ScreenHeight = ViewportSize.X, ViewportSize.Y
  674.  
  675.     local PortionWidth = ScreenWidth * MOUSE_PORTION_X_SIZE / 100
  676.     local PortionHeight = ScreenHeight * MOUSE_PORTION_Y_SIZE / 100
  677.  
  678.     local PortionXStart = ScreenWidth - PortionWidth - (ScreenWidth * MOUSE_PORTION_X_OFFSET / 100)
  679.     local PortionYStart = (ScreenHeight - PortionHeight) / 2
  680.     local PortionYEnd = ScreenHeight - PortionYStart
  681.  
  682.     local PortionPosition = Vector2.new(PortionXStart, PortionYStart)
  683.     return (
  684.         MousePosition.X >= PortionXStart and MousePosition.X <= ScreenWidth and
  685.             MousePosition.Y >= PortionYStart and MousePosition.Y <= PortionYEnd
  686.     )
  687. end
  688.  
  689.  
  690. local function MouseEnteredScreenPortion()
  691.     local IsMouseInScreenPortion = IsMouseInScreenPortion()
  692.     local StateChanged = (IsMouseInScreenPortion and not MouseInScreenPortion)
  693.         or (not IsMouseInScreenPortion and MouseInScreenPortion)   
  694.     if not StateChanged then
  695.         return
  696.     end
  697.  
  698.     MouseInScreenPortion = IsMouseInScreenPortion
  699.     if not MouseInScreenPortion then
  700.         MouseHoldingScreenPortion = false
  701.     end
  702. end
  703.  
  704. local function RotateAvatar()
  705.     local MousePosition = InputService:GetMouseLocation().X
  706.  
  707.     if InitialClick then
  708.         InitialClick = false
  709.         LastMousePosition = MousePosition
  710.         return
  711.     end
  712.    
  713.     local MouseDelta = MousePosition - (LastMousePosition or MousePosition)
  714.     local RotationAngle = math.rad(MouseDelta * AVATAR_ROTATION_SPEED)
  715.  
  716.     Avatar:SetPrimaryPartCFrame(HumRP.CFrame * CFrame.Angles(0, RotationAngle, 0))
  717.     LastMousePosition = MousePosition
  718. end
  719.  
  720. local function OnMouseMove()
  721.     MouseEnteredScreenPortion()
  722.    
  723.     if (MouseInScreenPortion and MouseHoldingScreenPortion) then
  724.         RotateAvatar()
  725.     end
  726. end
  727.  
  728. local function EstablishMouseConnections()
  729.     Mouse.Move:Connect(OnMouseMove)
  730.    
  731.     for _,InputState in ipairs({"InputBegan", "InputEnded"}) do
  732.         InputService[InputState]:Connect(function(Input)
  733.             local IsMouse1Input = Input.UserInputType == Enum.UserInputType.MouseButton1
  734.             local MouseDown = InputState == "InputBegan" and true or false
  735.             if not IsMouse1Input or (not MouseInScreenPortion) then
  736.                 return
  737.             end
  738.            
  739.             MouseHoldingScreenPortion = MouseDown
  740.             if not MouseDown then
  741.                 InitialClick = true
  742.             end
  743.         end)
  744.     end
  745. end
  746.  
  747. local function InitCatalogue()
  748.     local Scene = workspace:WaitForChild("Designer")
  749.     local CameraPart = Scene:WaitForChild("Camera")
  750.     local RadioPart = Scene:WaitForChild("Radio")
  751.  
  752.     Camera.CFrame = CameraPart.CFrame
  753.     EstablishMouseConnections()
  754.     PlayRadioMusic(RadioPart)
  755.  
  756.     LoadCatalogueData()
  757.     for _,Tab in ipairs(TabsRibbon:GetChildren()) do
  758.         if not Tab:IsA("GuiButton") then
  759.             continue
  760.         end
  761.         CreateCatalogueView(Tab)
  762.         EstablishTabConnections(Tab)
  763.     end
  764.     EnableCorrectViewFrame(TabsRibbon.All)
  765.    
  766.     CatalogueGui.Enabled = true
  767. end
  768.  
  769. function CatalogueManager.Initialize()
  770.     TextBox:GetPropertyChangedSignal("Text"):Connect(ValidateSearchResults)
  771.     InitCatalogue()
  772. end
  773.  
  774. return CatalogueManager
  775.  
  776.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement