Advertisement
suramraja1

geasd

Jun 29th, 2025 (edited)
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.96 KB | None | 0 0
  1. -- SERVICES & MODULES
  2. local Players = game:GetService("Players")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local UserInputService = game:GetService("UserInputService")
  5. local player = Players.LocalPlayer
  6.  
  7. local GetFarm = require(ReplicatedStorage.Modules.GetFarm)
  8. local MutationHandler = require(ReplicatedStorage.Modules:WaitForChild("MutationHandler"))
  9.  
  10. -- Helper function for mutation priority
  11. local function getMutationPriority(mutation)
  12.     local priorityMap = {
  13.         ["Moonlit"] = 6,
  14.         ["Choc"] = 5,
  15.         ["Shocked"] = 4,
  16.         ["Frozen"] = 3,
  17.         ["Chilled"] = 2,
  18.         ["Wet"] = 1,
  19.         ["None"] = 0
  20.     }
  21.    
  22.     -- Count mutations and assign a priority
  23.     if mutation == "None" then
  24.         return 0
  25.     end
  26.    
  27.     -- If it contains multiple mutations, count them
  28.     local count = 0
  29.     for w in mutation:gmatch("([^•]+)") do -- Changed to match bullet separator
  30.         count = count + 1
  31.     end
  32.    
  33.     -- Multiple mutations always have highest priority
  34.     if count > 1 then
  35.         return 100 + count
  36.     end
  37.    
  38.     -- Single mutation - look up its priority
  39.     for mutName, priority in pairs(priorityMap) do
  40.         if mutation:find(mutName) then
  41.             return priority
  42.         end
  43.     end
  44.    
  45.     return 0
  46. end
  47.  
  48. -- Helper function for variant priority
  49. local function getVariantPriority(variant)
  50.     local priorityMap = {
  51.         ["Rainbow"] = 3,
  52.         ["Gold"] = 2,
  53.         ["Normal"] = 1
  54.     }
  55.    
  56.     return priorityMap[variant] or 0
  57. end
  58.  
  59. -- GUI SETUP
  60. local playerGui = player:WaitForChild("PlayerGui")
  61.  
  62. -- Check if GUI already exists and remove it
  63. local existingGui = playerGui:FindFirstChild("FruitListGui")
  64. if existingGui then
  65.     existingGui:Destroy()
  66. end
  67.  
  68. -- State variables
  69. local currentSortColumn = "Fruit Name" -- Default sort by name
  70. local currentSortDir = "asc" -- Default ascending
  71. local allFruitsData = {} -- Will store all fruits data for sorting
  72. local isMinimized = false -- Track minimize state
  73. local originalSize -- Store original size when minimizing
  74.  
  75. local fruitListGui = Instance.new("ScreenGui")
  76. fruitListGui.Name = "FruitListGui"
  77. fruitListGui.ResetOnSpawn = false
  78. fruitListGui.Parent = playerGui
  79.  
  80. local mainFrame = Instance.new("Frame")
  81. mainFrame.Size = UDim2.new(0, 500, 0, 400)
  82. mainFrame.Position = UDim2.new(0.5, -250, 0.5, -200)
  83. mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
  84. mainFrame.BackgroundTransparency = 0.1
  85. mainFrame.Parent = fruitListGui
  86. mainFrame.Active = true
  87.  
  88. -- Store original size for minimizing
  89. originalSize = mainFrame.Size
  90.  
  91. -- Add rounded corners to main frame
  92. local mainCorner = Instance.new("UICorner")
  93. mainCorner.CornerRadius = UDim.new(0, 8)
  94. mainCorner.Parent = mainFrame
  95.  
  96. -- Title bar
  97. local titleBar = Instance.new("Frame")
  98. titleBar.Name = "TitleBar"
  99. titleBar.Size = UDim2.new(1, 0, 0, 30)
  100. titleBar.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
  101. titleBar.BorderSizePixel = 0
  102. titleBar.Parent = mainFrame
  103.  
  104. -- Add rounded corners to title bar (top corners only)
  105. local titleCorner = Instance.new("UICorner")
  106. titleCorner.CornerRadius = UDim.new(0, 8)
  107. titleCorner.Parent = titleBar
  108.  
  109. -- Make sure the title bar only rounds the top corners
  110. local bottomFrame = Instance.new("Frame")
  111. bottomFrame.Size = UDim2.new(1, 0, 0.5, 0)
  112. bottomFrame.Position = UDim2.new(0, 0, 0.5, 0)
  113. bottomFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
  114. bottomFrame.BorderSizePixel = 0
  115. bottomFrame.Parent = titleBar
  116.  
  117. local titleText = Instance.new("TextLabel")
  118. titleText.Name = "Title"
  119. titleText.Size = UDim2.new(1, -60, 1, 0)
  120. titleText.BackgroundTransparency = 1
  121. titleText.Text = "Farm Fruit List"
  122. titleText.Font = Enum.Font.SourceSansBold
  123. titleText.TextColor3 = Color3.fromRGB(255, 255, 255)
  124. titleText.TextSize = 18
  125. titleText.Parent = titleBar
  126.  
  127. -- Close button
  128. local closeButton = Instance.new("TextButton")
  129. closeButton.Name = "CloseButton"
  130. closeButton.Size = UDim2.new(0, 30, 0, 30)
  131. closeButton.Position = UDim2.new(1, -30, 0, 0)
  132. closeButton.BackgroundColor3 = Color3.fromRGB(200, 60, 60)
  133. closeButton.Text = "X"
  134. closeButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  135. closeButton.TextSize = 18
  136. closeButton.Font = Enum.Font.SourceSansBold
  137. closeButton.Parent = titleBar
  138.  
  139. -- Add rounded corners to close button
  140. local closeCorner = Instance.new("UICorner")
  141. closeCorner.CornerRadius = UDim.new(0, 6)
  142. closeCorner.Parent = closeButton
  143.  
  144. -- Minimize button
  145. local minimizeButton = Instance.new("TextButton")
  146. minimizeButton.Name = "MinimizeButton"
  147. minimizeButton.Size = UDim2.new(0, 30, 0, 30)
  148. minimizeButton.Position = UDim2.new(1, -65, 0, 0)
  149. minimizeButton.BackgroundColor3 = Color3.fromRGB(60, 60, 200)
  150. minimizeButton.Text = "-"
  151. minimizeButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  152. minimizeButton.TextSize = 22
  153. minimizeButton.Font = Enum.Font.SourceSansBold
  154. minimizeButton.Parent = titleBar
  155.  
  156. -- Add rounded corners to minimize button
  157. local minimizeCorner = Instance.new("UICorner")
  158. minimizeCorner.CornerRadius = UDim.new(0, 6)
  159. minimizeCorner.Parent = minimizeButton
  160.  
  161. -- Function to toggle minimize state
  162. local function toggleMinimize()
  163.     isMinimized = not isMinimized
  164.    
  165.     if isMinimized then
  166.         -- Store current size before minimizing
  167.         originalSize = mainFrame.Size
  168.        
  169.         -- Minimize GUI - just show title bar
  170.         mainFrame.Size = UDim2.new(0, 300, 0, 30)
  171.         minimizeButton.Text = "+"
  172.        
  173.         -- Hide content
  174.         if mainFrame:FindFirstChild("HeaderFrame") then
  175.             mainFrame.HeaderFrame.Visible = false
  176.         end
  177.         if mainFrame:FindFirstChild("ScrollingFrame") then
  178.             mainFrame.ScrollingFrame.Visible = false
  179.         end
  180.         if mainFrame:FindFirstChild("ResizeHandle") then
  181.             mainFrame.ResizeHandle.Visible = false
  182.         end
  183.     else
  184.         -- Restore GUI to original size
  185.         mainFrame.Size = originalSize
  186.         minimizeButton.Text = "-"
  187.        
  188.         -- Show content
  189.         if mainFrame:FindFirstChild("HeaderFrame") then
  190.             mainFrame.HeaderFrame.Visible = true
  191.         end
  192.         if mainFrame:FindFirstChild("ScrollingFrame") then
  193.             mainFrame.ScrollingFrame.Visible = true
  194.         end
  195.         if mainFrame:FindFirstChild("ResizeHandle") then
  196.             mainFrame.ResizeHandle.Visible = true
  197.         end
  198.     end
  199. end
  200.  
  201. -- Connect minimize button
  202. minimizeButton.MouseButton1Click:Connect(toggleMinimize)
  203.  
  204. -- Add keyboard shortcut (Left Ctrl) to toggle minimize
  205. UserInputService.InputBegan:Connect(function(input)
  206.     if input.KeyCode == Enum.KeyCode.LeftControl then
  207.         toggleMinimize()
  208.     end
  209. end)
  210.  
  211. -- Resize Handle
  212. local resizeHandle = Instance.new("Frame")
  213. resizeHandle.Size = UDim2.new(0, 24, 0, 24)
  214. resizeHandle.Position = UDim2.new(1, -24, 1, -24)
  215. resizeHandle.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  216. resizeHandle.BorderSizePixel = 0
  217. resizeHandle.Parent = mainFrame
  218. resizeHandle.Name = "ResizeHandle"
  219. resizeHandle.ZIndex = 10
  220.  
  221. local resizeCorner = Instance.new("UICorner")
  222. resizeCorner.CornerRadius = UDim.new(0, 8)
  223. resizeCorner.Parent = resizeHandle
  224.  
  225. -- IMPROVED DRAGGING IMPLEMENTATION
  226. local dragging = false
  227. local dragInput
  228. local dragStart
  229. local startPos
  230. local lastMousePos
  231. local lastGoalPos
  232.  
  233. local function updateDrag(input)
  234.     if dragging then
  235.         local delta = input.Position - dragStart
  236.         local position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X,
  237.                                    startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  238.        
  239.         -- Use a smoother movement with lerping
  240.         game:GetService("RunService").RenderStepped:Wait()
  241.         mainFrame.Position = position
  242.     end
  243. end
  244.  
  245. titleBar.InputBegan:Connect(function(input)
  246.     if input.UserInputType == Enum.UserInputType.MouseButton1 or
  247.        input.UserInputType == Enum.UserInputType.Touch then
  248.         dragging = true
  249.         dragStart = input.Position
  250.         startPos = mainFrame.Position
  251.         lastMousePos = Vector2.new(input.Position.X, input.Position.Y)
  252.        
  253.         -- Continue tracking even if mouse leaves the titleBar
  254.         input.Changed:Connect(function()
  255.             if input.UserInputState == Enum.UserInputState.End then
  256.                 dragging = false
  257.             end
  258.         end)
  259.     end
  260. end)
  261.  
  262. titleBar.InputChanged:Connect(function(input)
  263.     if input.UserInputType == Enum.UserInputType.MouseMovement or
  264.        input.UserInputType == Enum.UserInputType.Touch then
  265.         dragInput = input
  266.     end
  267. end)
  268.  
  269. UserInputService.InputChanged:Connect(function(input)
  270.     if input == dragInput and dragging then
  271.         updateDrag(input)
  272.     end
  273. end)
  274.  
  275. -- Resize Script
  276. local draggingResize = false
  277. local resizeStart
  278. local startSize
  279.  
  280. resizeHandle.InputBegan:Connect(function(input)
  281.     if input.UserInputType == Enum.UserInputType.MouseButton1 or
  282.        input.UserInputType == Enum.UserInputType.Touch then
  283.         draggingResize = true
  284.         resizeStart = input.Position
  285.         startSize = mainFrame.Size
  286.        
  287.         -- Track input end even outside the resize handle
  288.         input.Changed:Connect(function()
  289.             if input.UserInputState == Enum.UserInputState.End then
  290.                 draggingResize = false
  291.             end
  292.         end)
  293.     end
  294. end)
  295.  
  296. UserInputService.InputChanged:Connect(function(input)
  297.     if draggingResize and (input.UserInputType == Enum.UserInputType.MouseMovement or
  298.                           input.UserInputType == Enum.UserInputType.Touch) then
  299.         local delta = input.Position - resizeStart
  300.         local newWidth = math.max(400, startSize.X.Offset + delta.X)
  301.         local newHeight = math.max(300, startSize.Y.Offset + delta.Y)
  302.         mainFrame.Size = UDim2.new(0, newWidth, 0, newHeight)
  303.        
  304.         -- Store new size for when un-minimizing
  305.         originalSize = mainFrame.Size
  306.        
  307.         -- Recalculate scrolling frame size when resizing
  308.         local headerHeight = 30 -- title bar height
  309.         if mainFrame:FindFirstChild("HeaderFrame") and mainFrame:FindFirstChild("ScrollingFrame") then
  310.             mainFrame.ScrollingFrame.Size = UDim2.new(1, -20, 1, -(headerHeight + mainFrame.HeaderFrame.Size.Y.Offset + 20))
  311.         end
  312.     end
  313. end)
  314.  
  315. -- Close button logic
  316. closeButton.MouseButton1Click:Connect(function()
  317.     fruitListGui:Destroy()
  318. end)
  319.  
  320. -- Header Frame for column titles
  321. local headerFrame = Instance.new("Frame")
  322. headerFrame.Name = "HeaderFrame"
  323. headerFrame.Size = UDim2.new(1, -20, 0, 35)
  324. headerFrame.Position = UDim2.new(0, 10, 0, 40)
  325. headerFrame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  326. headerFrame.BackgroundTransparency = 0.5
  327. headerFrame.Parent = mainFrame
  328.  
  329. -- Add rounded corners to header frame
  330. local headerCorner = Instance.new("UICorner")
  331. headerCorner.CornerRadius = UDim.new(0, 6)
  332. headerCorner.Parent = headerFrame
  333.  
  334. -- Column Headers - SIMPLIFIED: only 4 columns now
  335. local columns = {"Fruit Name", "Variant", "Weight (kg)", "Mutations"}
  336. local columnWidths = {0.22, 0.18, 0.18, 0.42}  -- Give more space to mutations column
  337. local sortButtons = {}
  338.  
  339. -- Scrolling Frame for fruit list
  340. local scrollingFrame = Instance.new("ScrollingFrame")
  341. scrollingFrame.Name = "ScrollingFrame"
  342. scrollingFrame.Size = UDim2.new(1, -20, 1, -85)
  343. scrollingFrame.Position = UDim2.new(0, 10, 0, 85)
  344. scrollingFrame.BackgroundTransparency = 0.9
  345. scrollingFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
  346. scrollingFrame.BorderSizePixel = 0
  347. scrollingFrame.ScrollBarThickness = 8
  348. scrollingFrame.Parent = mainFrame
  349.  
  350. -- Refresh Button
  351. local refreshButton = Instance.new("TextButton")
  352. refreshButton.Name = "RefreshButton"
  353. refreshButton.Size = UDim2.new(0, 100, 0, 25)
  354. refreshButton.Position = UDim2.new(0, 10, 0, 3)
  355. refreshButton.BackgroundColor3 = Color3.fromRGB(60, 120, 60)
  356. refreshButton.Text = "Refresh"
  357. refreshButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  358. refreshButton.TextSize = 16
  359. refreshButton.Font = Enum.Font.SourceSansBold
  360. refreshButton.Parent = titleBar
  361.  
  362. -- Create a UICorner for the refresh button
  363. local refreshCorner = Instance.new("UICorner")
  364. refreshCorner.CornerRadius = UDim.new(0, 4)
  365. refreshCorner.Parent = refreshButton
  366.  
  367. -- Status label (for minimize tooltip)
  368. local statusLabel = Instance.new("TextLabel")
  369. statusLabel.Name = "StatusLabel"
  370. statusLabel.Size = UDim2.new(0, 200, 0, 20)
  371. statusLabel.Position = UDim2.new(0.5, -100, 0, -25)
  372. statusLabel.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  373. statusLabel.BackgroundTransparency = 0.2
  374. statusLabel.Text = "Press Left Ctrl to minimize"
  375. statusLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  376. statusLabel.TextSize = 14
  377. statusLabel.Font = Enum.Font.SourceSans
  378. statusLabel.Visible = false
  379. statusLabel.Parent = mainFrame
  380.  
  381. -- Add rounded corners to status label
  382. local statusCorner = Instance.new("UICorner")
  383. statusCorner.CornerRadius = UDim.new(0, 4)
  384. statusCorner.Parent = statusLabel
  385.  
  386. -- Show tooltip when hovering minimize button
  387. minimizeButton.MouseEnter:Connect(function()
  388.     statusLabel.Visible = true
  389. end)
  390.  
  391. minimizeButton.MouseLeave:Connect(function()
  392.     statusLabel.Visible = false
  393. end)
  394.  
  395. -- Function declaration for refreshFruitList (will be defined later)
  396. local refreshFruitList
  397.  
  398. -- Function to create sorted fruit list
  399. local function createSortedFruitList()
  400.     -- Clear existing list
  401.     for _, child in pairs(scrollingFrame:GetChildren()) do
  402.         if child:IsA("Frame") then
  403.             child:Destroy()
  404.         end
  405.     end
  406.    
  407.     -- Sort the fruits data based on current sort column and direction
  408.     table.sort(allFruitsData, function(a, b)
  409.         local aValue, bValue
  410.        
  411.         if currentSortColumn == "Fruit Name" then
  412.             aValue = a.name:lower()
  413.             bValue = b.name:lower()
  414.            
  415.         elseif currentSortColumn == "Variant" then
  416.             -- Sort by variant priority
  417.             aValue = getVariantPriority(a.variant)
  418.             bValue = getVariantPriority(b.variant)
  419.            
  420.         elseif currentSortColumn == "Mutations" then
  421.             -- Sort by mutation priority
  422.             aValue = getMutationPriority(a.mutations)
  423.             bValue = getMutationPriority(b.mutations)
  424.            
  425.         elseif currentSortColumn == "Weight (kg)" then
  426.             -- Use the raw numeric weight value instead of the string
  427.             aValue = a.weightNum or 0
  428.             bValue = b.weightNum or 0
  429.         else
  430.             return false
  431.         end
  432.        
  433.         if currentSortDir == "asc" then
  434.             return aValue < bValue
  435.         else
  436.             return aValue > bValue
  437.         end
  438.     end)
  439.    
  440.     -- Update sort button appearance
  441.     for colName, button in pairs(sortButtons) do
  442.         if colName == currentSortColumn then
  443.             button.Text = currentSortDir == "asc" and "▲" or "▼"
  444.             button.TextColor3 = Color3.fromRGB(255, 255, 100) -- Highlight active sort
  445.         else
  446.             button.Text = "◆"
  447.             button.TextColor3 = Color3.fromRGB(150, 150, 150) -- Dim inactive sorts
  448.         end
  449.     end
  450.    
  451.     local rowHeight = 50 -- Increased height for better mutation display
  452.     for i, fruitData in ipairs(allFruitsData) do
  453.         -- Create row frame
  454.         local rowFrame = Instance.new("Frame")
  455.         rowFrame.Name = "Row_" .. i
  456.         rowFrame.Size = UDim2.new(1, 0, 0, rowHeight)
  457.         rowFrame.Position = UDim2.new(0, 0, 0, (i-1) * rowHeight)
  458.         rowFrame.BackgroundColor3 = i % 2 == 0 and Color3.fromRGB(40, 40, 40) or Color3.fromRGB(35, 35, 35)
  459.         rowFrame.BackgroundTransparency = 0.3
  460.         rowFrame.Parent = scrollingFrame
  461.        
  462.         -- Add hover effect
  463.         rowFrame.InputBegan:Connect(function(input)
  464.             if input.UserInputType == Enum.UserInputType.MouseMovement then
  465.                 rowFrame.BackgroundTransparency = 0.1
  466.             end
  467.         end)
  468.        
  469.         rowFrame.InputEnded:Connect(function(input)
  470.             if input.UserInputType == Enum.UserInputType.MouseMovement then
  471.                 rowFrame.BackgroundTransparency = 0.3
  472.             end
  473.         end)
  474.        
  475.         -- Create columns in the row
  476.         local currentX = 0
  477.         local columnValues = {fruitData.name, fruitData.variant, fruitData.weight, fruitData.mutations}
  478.        
  479.         for j, columnValue in ipairs(columnValues) do
  480.             local cell = Instance.new("TextLabel")
  481.             cell.Name = "Column" .. j
  482.             cell.Size = UDim2.new(columnWidths[j], -10, 1, 0)
  483.             cell.Position = UDim2.new(currentX, 5, 0, 0)
  484.             cell.BackgroundTransparency = 1
  485.             cell.Font = Enum.Font.SourceSans
  486.             cell.TextColor3 = Color3.fromRGB(255, 255, 255)
  487.             cell.Text = tostring(columnValue)
  488.             cell.TextXAlignment = Enum.TextXAlignment.Left
  489.             cell.TextWrapped = true
  490.             cell.TextYAlignment = Enum.TextYAlignment.Top
  491.            
  492.             -- Special handling for mutations column (column 4)
  493.             if j == 4 then
  494.                 cell.TextSize = 14 -- Slightly smaller for more text
  495.                 cell.Font = Enum.Font.SourceSans
  496.                 -- Make sure mutations are fully visible
  497.                 if #tostring(columnValue) > 20 then
  498.                     cell.TextScaled = false -- Don't scale down, just wrap
  499.                 end
  500.             else
  501.                 cell.TextSize = 16
  502.                 cell.TextYAlignment = Enum.TextYAlignment.Center
  503.             end
  504.            
  505.             cell.Parent = rowFrame
  506.            
  507.             currentX = currentX + columnWidths[j]
  508.         end
  509.     end
  510.    
  511.     -- Update scrolling frame content size
  512.     scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, #allFruitsData * rowHeight)
  513.    
  514.     -- Update counter
  515.     titleText.Text = "Farm Fruit List - " .. #allFruitsData .. " Fruits"
  516. end
  517.  
  518. -- Column Headers
  519. local currentX = 0
  520. for i, columnName in ipairs(columns) do
  521.     local headerContainer = Instance.new("Frame")
  522.     headerContainer.Name = columnName:gsub(" ", "") .. "HeaderContainer"
  523.     headerContainer.Size = UDim2.new(columnWidths[i], 0, 1, 0)
  524.     headerContainer.Position = UDim2.new(currentX, 0, 0, 0)
  525.     headerContainer.BackgroundTransparency = 1
  526.     headerContainer.Parent = headerFrame
  527.    
  528.     local columnHeader = Instance.new("TextLabel")
  529.     columnHeader.Name = columnName:gsub(" ", "") .. "Header"
  530.     columnHeader.Size = UDim2.new(1, -25, 1, 0) -- Make room for sort button
  531.     columnHeader.Position = UDim2.new(0, 5, 0, 0)
  532.     columnHeader.BackgroundTransparency = 1
  533.     columnHeader.Font = Enum.Font.SourceSansBold
  534.     columnHeader.TextColor3 = Color3.fromRGB(255, 255, 255)
  535.     columnHeader.TextSize = 18
  536.     columnHeader.Text = columnName
  537.     columnHeader.TextXAlignment = Enum.TextXAlignment.Left
  538.     columnHeader.Parent = headerContainer
  539.    
  540.     -- Add sort button
  541.     local sortButton = Instance.new("TextButton")
  542.     sortButton.Name = "SortButton"
  543.     sortButton.Size = UDim2.new(0, 20, 0, 20)
  544.     sortButton.Position = UDim2.new(1, -25, 0.5, -10)
  545.     sortButton.BackgroundTransparency = 0.8
  546.     sortButton.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
  547.     sortButton.Text = columnName == currentSortColumn and "▲" or "◆" -- Triangle up for current sort, diamond for others
  548.     sortButton.TextColor3 = columnName == currentSortColumn
  549.                          and Color3.fromRGB(255, 255, 100)
  550.                          or Color3.fromRGB(150, 150, 150)
  551.     sortButton.TextSize = 14
  552.     sortButton.Font = Enum.Font.SourceSansBold
  553.     sortButton.Parent = headerContainer
  554.    
  555.     -- Add rounded corners to sort button
  556.     local sortCorner = Instance.new("UICorner")
  557.     sortCorner.CornerRadius = UDim.new(0, 4)
  558.     sortCorner.Parent = sortButton
  559.    
  560.     -- Store the sort button for later reference
  561.     sortButtons[columnName] = sortButton
  562.    
  563.     -- Sort button click handler
  564.     sortButton.MouseButton1Click:Connect(function()
  565.         if currentSortColumn == columnName then
  566.             -- Toggle direction if same column
  567.             currentSortDir = currentSortDir == "asc" and "desc" or "asc"
  568.         else
  569.             -- New column, default directions
  570.             currentSortColumn = columnName
  571.            
  572.             -- Special case: weight should default to descending (high to low)
  573.             if columnName == "Weight (kg)" then
  574.                 currentSortDir = "desc"
  575.             else
  576.                 -- Variant and mutation have special logic so desc is actually "best first"
  577.                 if columnName == "Variant" or columnName == "Mutations" then
  578.                     currentSortDir = "desc" -- Rainbow/Multiple mutations first
  579.                 else
  580.                     currentSortDir = "asc" -- A-Z for regular text
  581.                 end
  582.             end
  583.         end
  584.        
  585.         createSortedFruitList()
  586.     end)
  587.    
  588.     -- Add hover effect to sort button
  589.     sortButton.MouseEnter:Connect(function()
  590.         sortButton.BackgroundTransparency = 0.5
  591.     end)
  592.    
  593.     sortButton.MouseLeave:Connect(function()
  594.         sortButton.BackgroundTransparency = 0.8
  595.     end)
  596.    
  597.     currentX = currentX + columnWidths[i]
  598. end
  599.  
  600. -- Function to refresh the fruit list
  601. refreshFruitList = function()
  602.     -- Clear all fruit data
  603.     allFruitsData = {}
  604.    
  605.     -- Get player farm
  606.     local farm = GetFarm(player)
  607.     if not farm or not farm:FindFirstChild("Important") or not farm.Important:FindFirstChild("Plants_Physical") then
  608.         local errorLabel = Instance.new("TextLabel")
  609.         errorLabel.Size = UDim2.new(1, 0, 0, 30)
  610.         errorLabel.Position = UDim2.new(0, 0, 0, 0)
  611.         errorLabel.BackgroundTransparency = 1
  612.         errorLabel.TextColor3 = Color3.fromRGB(255, 100, 100)
  613.         errorLabel.Text = "Farm not found!"
  614.         errorLabel.Font = Enum.Font.SourceSansSemibold
  615.         errorLabel.TextSize = 18
  616.         errorLabel.Parent = scrollingFrame
  617.         return
  618.     end
  619.    
  620.     local plantsPhysical = farm.Important.Plants_Physical
  621.    
  622.     -- Loop through all tree types
  623.     for _, treeType in pairs(plantsPhysical:GetChildren()) do
  624.         local fruitsFolder = treeType:FindFirstChild("Fruits")
  625.         if fruitsFolder then
  626.             for _, fruitModel in pairs(fruitsFolder:GetChildren()) do
  627.                 if fruitModel:IsA("Model") then
  628.                     -- Get fruit attributes and properties
  629.                     local fruitName = fruitModel.Name
  630.                    
  631.                     -- Get variant (typically stored as a child)
  632.                     local variant = fruitModel:FindFirstChild("Variant")
  633.                     local variantText = variant and variant.Value or "Normal"
  634.                    
  635.                     -- Get weight
  636.                     local weight = fruitModel:FindFirstChild("Weight")
  637.                     local weightNum = weight and weight.Value or 0
  638.                     local weightValue = weight and string.format("%.2f kg", weightNum) or "? kg"
  639.                    
  640.                     -- Get mutations from attributes (using MutationHandler if available)
  641.                     local mutations = ""
  642.                     local success, mutationString = pcall(function()
  643.                         return MutationHandler:GetMutationsAsString(fruitModel) or ""
  644.                     end)
  645.                    
  646.                     if not success or mutationString == "" then
  647.                         -- Try checking attributes directly
  648.                         local mutationList = {}
  649.                         for attrName, value in pairs(fruitModel:GetAttributes()) do
  650.                             if value == true and typeof(value) == "boolean" then
  651.                                 -- Check only known mutation attributes
  652.                                 if attrName == "Shocked" or
  653.                                    attrName == "Frozen" or
  654.                                    attrName == "Wet" or
  655.                                    attrName == "Chilled" or
  656.                                    attrName == "Twisted" or
  657.                                    attrName == "Choc" or
  658.                                    attrName == "Burnt" or
  659.                                    attrName == "Moonlit" then
  660.                                    
  661.                                     table.insert(mutationList, attrName)
  662.                                 end
  663.                             end
  664.                         end
  665.                        
  666.                         if #mutationList > 0 then
  667.                             -- Sort mutations for consistent display
  668.                             table.sort(mutationList)
  669.                             mutations = table.concat(mutationList, " • ") -- Use bullet separator for better readability
  670.                         else
  671.                             mutations = "None"
  672.                         end
  673.                     else
  674.                         -- Format the mutation string for better readability
  675.                         if mutationString ~= "" then
  676.                             -- Replace commas with bullet points for better visual separation
  677.                             mutations = mutationString:gsub(", ", " • ")
  678.                         else
  679.                             mutations = "None"
  680.                         end
  681.                     end
  682.  
  683.                     -- Store fruit data for sorting
  684.                     table.insert(allFruitsData, {
  685.                         name = fruitName,
  686.                         variant = variantText,
  687.                         mutations = mutations,
  688.                         weight = weightValue,
  689.                         weightNum = weightNum, -- Store raw number for sorting
  690.                         model = fruitModel,
  691.                         treeName = treeType.Name
  692.                     })
  693.                 end
  694.             end
  695.         end
  696.     end
  697.    
  698.     -- Display sorted fruit list
  699.     createSortedFruitList()
  700. end
  701.  
  702. -- Connect the refresh button
  703. refreshButton.MouseButton1Click:Connect(refreshFruitList)
  704.  
  705. -- Handle refresh on unhide
  706. minimizeButton.MouseButton1Click:Connect(function()
  707.     if isMinimized then
  708.         -- Will refresh data when un-minimizing
  709.         task.delay(0.1, function()
  710.             refreshFruitList()
  711.         end)
  712.     end
  713. end)
  714.  
  715. -- Initial refresh
  716. refreshFruitList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement