Advertisement
imcolinyo

merely trade hangout 2.0 script

Mar 5th, 2014
6,458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.23 KB | None | 0 0
  1. function showHint(txt)
  2. local m = Instance.new("Message", Workspace)
  3. m.Text = txt
  4. wait(5)
  5. m:Destroy()
  6. end
  7.  
  8. function numerify(n)
  9. if n == "null" or n == nil then
  10. return ""
  11. end
  12. if n < 1000 then
  13. return string.format("%d",n)
  14. elseif n <= 10000 then
  15. return string.format("%.1fk", n/1000)
  16. elseif n < 100000 then
  17. return string.format("%.1fk", n/1000)
  18. elseif n < 1000000 then
  19. return string.format("%.0fk", n/1000)
  20. else
  21. return string.format("%.2fm", n/1000000)
  22. end
  23. end
  24.  
  25. function calculateTextWidth(text, fontSize, font)
  26. --extremely expensive function
  27. --benchmark it?
  28. font = font or Enum.Font.SourceSans
  29. fontSize = fontSize or Enum.FontSize.Size18
  30. local label = Instance.new("TextLabel")
  31. label.Text = tostring(text)
  32. label.Position = UDim2.new(-1, 0, -1, 0)
  33. label.FontSize = fontSize
  34. label.Font = font
  35. label.Parent = script.Parent
  36. local width = label.TextBounds.X
  37. label:Destroy()
  38. return width
  39. end
  40.  
  41. --local DecodeJSON = LoadLibrary("RbxUtility").DecodeJSON
  42.  
  43. local Players = game:GetService("Players")
  44. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  45. local ClientModules = ReplicatedStorage:WaitForChild("ClientModules")
  46.  
  47. local Metro = require(ClientModules:WaitForChild("Metro"))
  48. local Time = require(ClientModules:WaitForChild("Time"))
  49. local Class = require(ClientModules:WaitForChild("Class"))
  50. local Limiteds = require(ClientModules:WaitForChild("Limiteds"))
  51. local Log = Class.Get("Log")
  52. local User = Class.Get("User")
  53.  
  54. local Player = Players.LocalPlayer
  55.  
  56. local Gui = script.Parent
  57.  
  58. --[[
  59. Limiteds:GetUserData(userId)
  60. Limiteds.UserDataUpdated:connect(function(userId) end)
  61.  
  62. Limiteds:GetList()
  63. Limiteds.ListUpdated:connect(function() end)
  64.  
  65. Limiteds:WishlistAdd(assetId)
  66. Limiteds:WishlistRemove(assetId)
  67. Limiteds:BlacklistAdd(assetId)
  68. Limiteds:BlacklistRemove(assetId)
  69. --]]
  70.  
  71. Limiteds.List = Limiteds:GetList()
  72.  
  73. Limiteds.ListUpdated:connect(function()
  74. print("The limiteds list was updated")
  75. Limiteds.List = Limiteds:GetList()
  76. end)
  77.  
  78. --[[
  79. Asset:GetName(id)
  80. Asset:NameContains(id,text)
  81. Asset:GetType(Id)
  82. Asset:GetRAP(id)
  83. --]]
  84.  
  85. local Asset = {}
  86.  
  87. function Asset:GetName(id)
  88. return Limiteds.List[id].Name
  89. end
  90.  
  91. function Asset:NameContains(id, text)
  92. local name = Asset:GetName(id):lower()
  93. local text = text:lower()
  94. return (string.find(name, text, 1, true) ~= nil)
  95. end
  96.  
  97. function Asset:GetType(id)
  98. return Limiteds.List[id].Type
  99. end
  100.  
  101. function Asset:GetRAP(id)
  102. if not Limiteds.List[id] then
  103. print("GetRAP: Asset not found in limiteds list.")
  104. return 0
  105. end
  106. return tonumber(Limiteds.List[id].RecentAveragePrice) or 0
  107. end
  108.  
  109. function Asset:GetImage(id)
  110. return "http://www.roblox.com/Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=110&ht=110&aid=" .. tostring(id)
  111. end
  112.  
  113. function Asset:GetTotalSold(id)
  114. if Limiteds.List[id] then
  115. return tonumber(Limiteds.List[id].TotalSold) or 0
  116. end
  117. return 0
  118. end
  119.  
  120. local ItemTooltip = {}
  121. ItemTooltip.Frame = nil
  122.  
  123. function ItemTooltip:Hide()
  124. if ItemTooltip.Frame then
  125. ItemTooltip.Frame:Destroy()
  126. end
  127. end
  128.  
  129. function ItemTooltip:Create(userAsset, element)
  130. if ItemTooltip.Frame then
  131. ItemTooltip.Frame:Destroy()
  132. end
  133.  
  134. local id = userAsset.Id
  135.  
  136. local name = Asset:GetName(id)
  137. local rap = Asset:GetRAP(id)
  138. local image = Asset:GetImage(id)
  139. local type = Asset:GetType(id)
  140. local totalSold = Asset:GetTotalSold(id)
  141.  
  142. local serials = ""
  143.  
  144. for i,v in pairs(userAsset.Copies) do
  145. local num
  146. if tonumber(v.SerialNumber) then
  147. num = "#" .. tostring(v.SerialNumber)
  148. else
  149. num = "N/A"
  150. end
  151. serials = serials .. ", " .. num
  152. end
  153. serials = string.sub(serials, 2, string.len(serials))
  154.  
  155. local mouseover = false
  156.  
  157. --[[local id = 16412796
  158. local name = "Sk8ter Boi"
  159. local rap = "704,831 R$"
  160. local totalSold = "1400"
  161. local type = "Hat"
  162. local image = "http://www.roblox.com/Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=110&ht=110&aid=" .. tostring(id)
  163. --]]
  164.  
  165. local margin = 5
  166.  
  167. local faved = false
  168. local notForSale = false
  169.  
  170. local tooltipSize = Vector2.new(350, 100)
  171.  
  172. local leftOffset = 23
  173.  
  174. local frame = Metro.Window(tooltipSize)
  175. frame.BackgroundTransparency = 0.3
  176. frame.Position = UDim2.new(0, element.AbsolutePosition.X + element.AbsoluteSize.X + leftOffset, 0 , element.AbsolutePosition.Y + (element.AbsoluteSize.Y * 0.5) + tooltipSize.Y * -0.5)
  177. frame.Parent = Gui
  178.  
  179. element.Changed:connect(function(prop)
  180. if prop == "AbsolutePosition" then
  181. frame.Position = UDim2.new(0, element.AbsolutePosition.X + element.AbsoluteSize.X + leftOffset, 0 , element.AbsolutePosition.Y + (element.AbsoluteSize.Y * 0.5) + tooltipSize.Y * -0.5)
  182. end
  183. end)
  184.  
  185. local imageSize = Vector2.new(100, 100)
  186. local textHeight = 16
  187.  
  188. local imageLabel = Instance.new("ImageLabel")
  189. imageLabel.BackgroundTransparency = 1
  190. imageLabel.Image = image
  191. imageLabel.Size = UDim2.new(0, imageSize.X, 0, imageSize.Y)
  192. imageLabel.Parent = frame
  193.  
  194. local nameLabel = Metro.Label(name,true)
  195. nameLabel.FontSize = Enum.FontSize.Size14
  196. nameLabel.Position = UDim2.new(0, imageSize.X + margin, 0, 0)
  197. nameLabel.Parent = frame
  198.  
  199. local assetType = Metro.Label("Type: " .. type)
  200. assetType.FontSize = Enum.FontSize.Size14
  201. assetType.Position = UDim2.new(0, imageSize.X + margin, 0, textHeight)
  202. assetType.Parent = frame
  203.  
  204. local totalSold = Metro.Label("Total Sold: " .. totalSold)
  205. totalSold.FontSize = Enum.FontSize.Size14
  206. totalSold.Position = UDim2.new(0, imageSize.X + margin, 0, textHeight*2)
  207. totalSold.Parent = frame
  208.  
  209. local rapLabel = Metro.Label("RAP: " .. numerify(rap))
  210. rapLabel.FontSize = Enum.FontSize.Size14
  211. rapLabel.Position = UDim2.new(0, imageSize.X + margin, 0, textHeight*3)
  212. rapLabel.Parent = frame
  213.  
  214. local serialNumbersLabel = Metro.Label("Serial Numbers:")
  215. serialNumbersLabel.FontSize = Enum.FontSize.Size14
  216. serialNumbersLabel.Position = UDim2.new(0, imageSize.X + margin, 0, textHeight*4)
  217. serialNumbersLabel.Parent = frame
  218.  
  219. local serialNumbers = Metro.Label(serials)
  220. serialNumbers.FontSize = Enum.FontSize.Size14
  221. serialNumbers.Position = UDim2.new(0, imageSize.X + margin, 0, textHeight*5)
  222. serialNumbers.Parent = frame
  223.  
  224. local buttonMargin = 2
  225. local buttonSize = 18
  226.  
  227. local starButton, setStarButtonState = Metro.StarButton(faved)
  228. starButton.Parent = imageLabel
  229. starButton.Position = UDim2.new(0, buttonMargin, 1, -1 * (buttonSize + buttonMargin))
  230. starButton.MouseButton1Click:connect(function()
  231. faved = not faved
  232. setStarButtonState(faved)
  233. end)
  234.  
  235. local notForSaleButton, setNotForSale = Metro.BlockButton(notForSale)
  236. notForSaleButton.Position = UDim2.new(0, buttonSize + buttonMargin * 2, 1, -1 * (buttonSize + buttonMargin))
  237. notForSaleButton.Parent = frame
  238. notForSaleButton.MouseButton1Click:connect(function()
  239. notForSale = not notForSale
  240. setNotForSale(notForSale)
  241. end)
  242.  
  243. frame.MouseEnter:connect(function()
  244. print("Mouse entered frame")
  245. mouseover = true
  246. end)
  247.  
  248. element.MouseLeave:connect(function()
  249. ---wait(0.05)
  250. --if mouseover then
  251. -- frame.MouseLeave:connect(function() frame:Destroy() end)
  252. --else
  253. --print("Mouse left button")
  254. frame:Destroy()
  255. --end
  256. end)
  257.  
  258. local minWidth = 250
  259. local nameWidth = imageSize.X + margin + calculateTextWidth(nameLabel.Text, nameLabel.FontSize, nameLabel.Font) + margin
  260.  
  261. local fullWidth = math.max(minWidth, nameWidth)
  262.  
  263. frame.Size = UDim2.new(0, fullWidth, 0, tooltipSize.Y)
  264.  
  265.  
  266. ItemTooltip.Frame = frame
  267. end
  268.  
  269. --[[
  270. Filter.Apply(list)
  271. Filter.Sort(list)
  272. Filter.Reset()
  273. --]]
  274.  
  275. local Filter = {
  276. AssetTypes = { "All", "Hat", "Gear", "Face" };
  277. AssetType = "All";
  278. SearchText = "";
  279. SortType = "RAP";
  280. SortAscending = false;
  281. }
  282.  
  283. function Filter:Apply(list)
  284. local results = {}
  285. for _,userAsset in pairs(list) do
  286. local id = userAsset.Id
  287. if Limiteds.List[id] and (Filter.AssetType == "All" or (Asset:GetType(id) == Filter.AssetType)) then
  288. if (Filter.SearchText == "" or Asset:NameContains(id,Filter.SearchText)) then
  289. table.insert(results, userAsset)
  290. end
  291. end
  292. end
  293. return results
  294. end
  295.  
  296. function Filter:GetSortFunction()
  297. if Filter.SortType == "RAP" then
  298. if Filter.SortAscending then
  299. return function(a,b)
  300. return Asset:GetRAP(a.Id) < Asset:GetRAP(b.Id)
  301. end
  302. else
  303. return function(a,b)
  304. return Asset:GetRAP(a.Id) > Asset:GetRAP(b.Id)
  305. end
  306. end
  307. elseif Filter.SortType == "Name" then
  308. if Filter.SortAscending then
  309. return function(a,b)
  310. return Asset:GetName(a.Id) < Asset:GetName(b.Id)
  311. end
  312. else
  313. return function(a,b)
  314. return Asset:GetName(a.Id) > Asset:GetName(b.Id)
  315. end
  316. end
  317. end
  318. end
  319.  
  320. function Filter:Sort(list)
  321. local sortFunction = Filter:GetSortFunction()
  322. table.sort(list, sortFunction)
  323. return list
  324. end
  325.  
  326. function Filter:Reset()
  327. Filter.AssetType = "All"
  328. Filter.SearchText = ""
  329. Filter.SortType = "RAP"
  330. Filter.SortAscending = false
  331. end
  332.  
  333.  
  334. -- for current player, we need both name and id
  335. -- we want to show whether the player is in-game
  336. -- we need to support out-of-server players
  337. -- connect to player added / player removing
  338.  
  339. local CurrentUser = {
  340. Player = nil;
  341. Id = nil;
  342. Name = nil;
  343. --Data = {};
  344. }
  345.  
  346. local SelectionBox = Instance.new("SelectionBox")
  347. SelectionBox.Color = BrickColor.new("Bright red")
  348. SelectionBox.Transparency = 0.5
  349. SelectionBox.Parent = Gui
  350.  
  351. CurrentUser.NameCache = {}
  352.  
  353. function CurrentUser:SetByPlayer(player)
  354. if player then
  355. CurrentUser.Player = player
  356. CurrentUser.Id = player.userId
  357. CurrentUser.Name = player.Name
  358. --CurrentUser.Data = Limiteds:GetUserData(Player.userId)
  359. end
  360. end
  361.  
  362. function CurrentUser:GetUserAssets()
  363. return Limiteds:GetUserData(CurrentUser.Id).UserAssets
  364. end
  365.  
  366. function CurrentUser:GetTotalRAP()
  367. local rap = 0
  368. local userAssets = CurrentUser:GetUserAssets()
  369. for _,userAsset in pairs(userAssets) do
  370. local id = userAsset.Id
  371. rap = rap + (#userAsset.Copies * Asset:GetRAP(id))
  372. end
  373. return rap
  374. end
  375.  
  376. function CurrentUser:SetByName(name)
  377. for _,player in pairs(Players:GetPlayers()) do
  378. if name == player.Name then
  379. CurrentUser:SetByPlayer(player)
  380. return
  381. end
  382. end
  383. if name == "ROBLOX" then
  384. CurrentUser.Name = "ROBLOX"
  385. CurrentUser.Id = 1
  386. return
  387. end
  388. CurrentUser.Player = nil
  389. CurrentUser.Name = nil
  390. CurrentUser.Id = nil
  391. end
  392.  
  393. ----------------------------------
  394.  
  395. local UpdateItemList = nil
  396.  
  397. --Create the GUI
  398.  
  399. local margin = 5
  400. local offset = Vector2.new(0,0)
  401.  
  402. function addOffset(x, y)
  403. offset = offset + Vector2.new(x,y)
  404. end
  405.  
  406. function resetOffset()
  407. offset = Vector2.new(0,0)
  408. end
  409.  
  410. function resetOffsetX()
  411. offset = Vector2.new(0,offset.Y)
  412. end
  413.  
  414. function resetOffsetY()
  415. offset = Vector2.new(offset.X,0)
  416. end
  417.  
  418. function getOffset()
  419. return UDim2.new(0, offset.X, 0, offset.Y)
  420. end
  421.  
  422. --Sizes
  423. local windowSize = Vector2.new(320, 360)
  424. local playerLabelSize = Vector2.new(50,20)
  425. local playerDropDownSize = Vector2.new(165,20)
  426. local itemSearchLabelSize = Vector2.new(50,20)
  427. local itemSearchSize = Vector2.new(100,20)
  428. local assetTypeDropDownSize = Vector2.new(60, 20)
  429. local itemLabelSize = Vector2.new(80,13)
  430.  
  431. local itemFrameHeight = 290
  432. local AssetRowHeight = 34
  433. local ValueWidth = 50
  434. local scrollWidth = 20
  435. local AssetTitleRowHeight = 24
  436. local maxNameWidth = 160
  437.  
  438. local windowOffscreen = UDim2.new(0, (-1 * windowSize.X - 1), 0.5, windowSize.Y / -2)
  439. local windowInscreen = UDim2.new(0, 0, 0.5, windowSize.Y / -2)
  440.  
  441. local windowShown = false
  442.  
  443. local window = Metro.Window(windowSize)
  444. window.Active = true
  445. window.Position = windowOffscreen
  446. window.BackgroundTransparency = 0.1
  447. window.Parent = Gui
  448.  
  449. local toggleButton = Instance.new("TextButton")
  450. toggleButton.Size = UDim2.new(0, 40, 1, 0)
  451. toggleButton.BackgroundColor3 = Color3.new(0,0,0)
  452. toggleButton.BackgroundTransparency = 0.5
  453. toggleButton.Position = UDim2.new(1, 0, 0, 0)
  454. toggleButton.TextTransparency = 0.5
  455. toggleButton.TextColor3 = Color3.new(255/255, 255/255, 255/255)
  456. toggleButton.Text = ">"
  457. toggleButton.FontSize = Enum.FontSize.Size48
  458. toggleButton.Parent = window
  459.  
  460. local tweenTime = 0.3
  461. local isTweening = false
  462.  
  463. function showGui()
  464. if isTweening or windowShown then return end
  465. isTweening = true
  466. windowShown = true
  467. --toggleButton.Text = "<"
  468. window:TweenPosition(windowInscreen, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, tweenTime, true)
  469.  
  470. Spawn(function()
  471. for i = 0.5, 1, 0.05 do
  472. toggleButton.BackgroundTransparency = i
  473. toggleButton.TextTransparency = i
  474. wait(tweenTime / 10)
  475. end
  476. end)
  477.  
  478. wait(tweenTime)
  479. isTweening = false
  480. toggleButton.Visible = false
  481. end
  482.  
  483. function hideGui()
  484. if isTweening or not windowShown then return end
  485. ItemTooltip:Hide()
  486. isTweening = true
  487. windowShown = false
  488. --toggleButton.Text = ">"
  489.  
  490. toggleButton.Visible = true
  491.  
  492. Spawn(function()
  493. for i = 1, 0.5, -0.05 do
  494. toggleButton.BackgroundTransparency = i
  495. toggleButton.TextTransparency = i
  496. wait(tweenTime / 10)
  497. end
  498. end)
  499.  
  500. window:TweenPosition(windowOffscreen, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, tweenTime, true)
  501. wait(tweenTime)
  502. isTweening = false
  503.  
  504. end
  505.  
  506. function toggleGui()
  507. if windowShown and not isTweening then
  508. hideGui()
  509. else
  510. showGui()
  511. end
  512. end
  513.  
  514. toggleButton.MouseButton1Click:connect(toggleGui)
  515. toggleButton.MouseEnter:connect(function()
  516. if windowShown == false then
  517. showGui()
  518. end
  519. end)
  520.  
  521. --[[local exitBtn = Metro.ExitButton(function() window:Remove() end)
  522. exitBtn.Parent = window--]]
  523.  
  524. addOffset(margin, margin)
  525.  
  526. local playerLabel = Metro.Label("player")
  527. playerLabel.Position = getOffset()
  528. playerLabel.Size = UDim2.new(0, playerLabelSize.X, 0, playerLabelSize.Y)
  529. playerLabel.Parent = window
  530.  
  531. addOffset(playerLabelSize.X, 0)
  532.  
  533. function selectedPlayerChanged(newName)
  534. local player = game:GetService("Players"):FindFirstChild(newName)
  535. if player then
  536. CurrentUser:SetByPlayer(player)
  537. elseif newName == "ROBLOX" then
  538. CurrentUser:SetByName("ROBLOX")
  539. end
  540. UpdateItemList()
  541. end
  542.  
  543. function selectedAssetTypeChanged(newType)
  544. Filter.AssetType = newType
  545. UpdateItemList()
  546. end
  547.  
  548. local playerDropDown, setCurrentPlayerName, updatePlayerChoices = Metro.DropDown({Player.Name}, function(updatedChoice) selectedPlayerChanged(updatedChoice) end)
  549. playerDropDown.Position = getOffset()
  550. playerDropDown.Size = UDim2.new(0, playerDropDownSize.X, 0, playerDropDownSize.Y)
  551. playerDropDown.Parent = window
  552.  
  553. addOffset(playerDropDownSize.X, 0)
  554. addOffset(margin, 0)
  555.  
  556. local rapLabel = Metro.Label("")
  557. rapLabel.Position = getOffset()
  558. rapLabel.Size = UDim2.new(0, playerLabelSize.X, 0, playerLabelSize.Y)
  559. rapLabel.Parent = window
  560.  
  561. resetOffsetX()
  562. addOffset(margin, 0)
  563.  
  564. addOffset(0,playerDropDownSize.Y)
  565. addOffset(0, margin*2)
  566.  
  567. local itemSearchLabel = Metro.Label("search")
  568. itemSearchLabel.Position = getOffset()
  569. itemSearchLabel.Size = UDim2.new(0, playerLabelSize.X, 0, playerLabelSize.Y)
  570. itemSearchLabel.Parent = window
  571.  
  572. addOffset(itemSearchLabelSize.X, 0)
  573.  
  574. local itemSearch, itemSearchFrame = Metro.Input()
  575. itemSearchFrame.Position = getOffset()
  576. itemSearchFrame.Size = UDim2.new(0, itemSearchSize.X, 0, itemSearchSize.Y)
  577. itemSearchFrame.Parent = window
  578.  
  579. addOffset(itemSearchSize.X, 0)
  580. addOffset(margin,0)
  581.  
  582. local itemTypeDropDown, setCurrentAssetType = Metro.DropDown(Filter.AssetTypes, selectedAssetTypeChanged)
  583. itemTypeDropDown.Parent = window
  584. itemTypeDropDown.Size = UDim2.new(0, assetTypeDropDownSize.X, 0, assetTypeDropDownSize.Y)
  585. itemTypeDropDown.Position = getOffset()
  586.  
  587. resetOffsetX()
  588. addOffset(margin,0)
  589. addOffset(0,itemSearchSize.Y)
  590.  
  591. local ItemFrame = Instance.new("Frame")
  592. ItemFrame.BackgroundTransparency = 1
  593. ItemFrame.Size = UDim2.new(1, -2*margin, 0, itemFrameHeight)
  594. ItemFrame.Position = getOffset()
  595. ItemFrame.Parent = window
  596.  
  597. local ItemScrollBar = Metro.ScrollBar()
  598. ItemScrollBar.Window.Size = UDim2.new(1, 0, 1, -1 * AssetTitleRowHeight)
  599. ItemScrollBar.Window.Position = UDim2.new(0, 0, 0, AssetTitleRowHeight)
  600. ItemScrollBar.SetMaxHeight(0)
  601. ItemScrollBar.Window.Parent = ItemFrame
  602.  
  603. local ItemNameLabel = Metro.LabelButton("name")
  604. ItemNameLabel.Parent = ItemFrame
  605. ItemNameLabel.Position = UDim2.new(0,AssetRowHeight,0,margin)
  606. ItemNameLabel.Size = UDim2.new(0, itemLabelSize.X, 0, itemLabelSize.Y)
  607.  
  608. local ItemValueLabel = Metro.LabelButton("rap v")
  609. ItemValueLabel.Parent = ItemFrame
  610. ItemValueLabel.Position = UDim2.new(1,-1*(ValueWidth+scrollWidth),0,margin)
  611. ItemValueLabel.Size = UDim2.new(0, ValueWidth, 0, 13)
  612.  
  613. local ItemLine = Instance.new("Frame")
  614. ItemLine.BackgroundColor3 = Color3.new(89/255, 89/255, 89/255)
  615. ItemLine.BorderSizePixel = 0
  616. ItemLine.Size = UDim2.new(1, 0, 0, 1)
  617. ItemLine.Position = UDim2.new(0, 0, 0, AssetTitleRowHeight)
  618. ItemLine.Parent = ItemFrame
  619.  
  620. function AssetRow(userAsset)
  621. local id = userAsset.Id
  622. local name = Asset:GetName(id)
  623. local rap = numerify(Asset:GetRAP(id))
  624. local copies = #userAsset.Copies
  625. --name,value,quantity
  626.  
  627. local quantityWidth = 25
  628. local imageWidth = AssetRowHeight
  629. local valueWidth = ValueWidth
  630.  
  631. local assetFrame = Instance.new("TextButton")
  632. assetFrame.Active = true
  633. assetFrame.Text = ""
  634. assetFrame.BackgroundTransparency = 1
  635. assetFrame.Size = UDim2.new(1, 0, 0, AssetRowHeight)
  636.  
  637. local assetImage = Instance.new("ImageLabel")
  638. assetImage.BackgroundTransparency = 1
  639. assetImage.Image = Asset:GetImage(id)
  640. assetImage.Size = UDim2.new(0,imageWidth,0,imageWidth)
  641. assetImage.Position = UDim2.new(0, 0, 0, 0)
  642. assetImage.Parent = assetFrame
  643.  
  644. if (copies > 1) then
  645. local assetQuantity = Instance.new("TextLabel")
  646. assetQuantity.TextXAlignment = Enum.TextXAlignment.Left
  647. assetQuantity.TextColor3 = Color3.new(0/255, 144/255, 224/255)
  648. assetQuantity.Font = Enum.Font.SourceSans
  649. assetQuantity.BackgroundTransparency = 1
  650. assetQuantity.TextStrokeTransparency = 0.2
  651. assetQuantity.FontSize = Enum.FontSize.Size14
  652. assetQuantity.Size = UDim2.new(0, quantityWidth - margin, 1, 0)
  653. assetQuantity.Position = UDim2.new(0, imageWidth + margin/2, 0, 0)
  654. assetQuantity.Parent = assetFrame
  655. assetQuantity.Text = "x" .. tostring(copies)
  656. end
  657.  
  658. --chop the name off if it's too long
  659. local nameFontSize = Enum.FontSize.Size14
  660.  
  661. local ellipses = "..."
  662. local ellipsesWidth = calculateTextWidth(ellipses,nameFontSize)
  663.  
  664. local textWidth = calculateTextWidth(name, nameFontSize)
  665. if (textWidth > maxNameWidth) then
  666. while (textWidth > maxNameWidth) do
  667. name = string.sub(name, 1, string.len(name) - 1)
  668. textWidth = calculateTextWidth(name .. ellipses, nameFontSize)
  669. end
  670. name = name .. ellipses
  671. end
  672.  
  673. local assetName = Metro.Label(name, true)
  674. assetName.Size = UDim2.new(1, -1 * (imageWidth + quantityWidth + valueWidth + margin + margin), 1, 0)
  675. assetName.Position = UDim2.new(0, imageWidth + quantityWidth + margin, 0, 0)
  676. assetName.FontSize = nameFontSize
  677. assetName.Parent = assetFrame
  678.  
  679. local assetValue = Metro.Label(rap,true)
  680. assetValue.Size = UDim2.new(0, valueWidth, 1, 0)
  681. assetValue.Position = UDim2.new(1, -1 * valueWidth, 0, 0)
  682. assetValue.Parent = assetFrame
  683.  
  684. assetFrame.MouseEnter:connect(function()
  685. ItemTooltip:Create(userAsset, assetFrame)
  686. end)
  687.  
  688. return assetFrame
  689. end
  690.  
  691. local ItemList = {}
  692. ItemList.Height = 0
  693. ItemList.RowHeight = 34
  694.  
  695. function ItemList:Clear()
  696. if ItemList.Cancel then
  697. ItemList.Cancel()
  698. end
  699. rapLabel.Text = ""
  700. ItemScrollBar.ContentFrame:ClearAllChildren()
  701. ItemList.Height = 0
  702. ItemScrollBar.SetMaxHeight(0)
  703. end
  704.  
  705. function ItemList:AddSeeMoreButton()
  706. local showButtonSize = Vector2.new(160, 20)
  707. local buttonFrame = Instance.new("Frame")
  708. buttonFrame.BackgroundTransparency = 1
  709. buttonFrame.Size = UDim2.new(1, 0, 0, ItemList.RowHeight)
  710.  
  711. local button = Metro.Button("Show more results")
  712. button.Position = UDim2.new(0.5, -0.5 * showButtonSize.X, 0.5, -0.5 * showButtonSize.Y)
  713. button.Size = UDim2.new(0, showButtonSize.X, 0, showButtonSize.Y)
  714. button.Parent = buttonFrame
  715. buttonFrame.Position = UDim2.new(0, 0, 0, ItemList.Height)
  716. buttonFrame.Parent = ItemScrollBar.ContentFrame
  717.  
  718. ItemScrollBar.SetMaxHeight(ItemList.Height + ItemList.RowHeight)
  719.  
  720. button.MouseButton1Click:wait()
  721.  
  722. ItemScrollBar.SetMaxHeight(ItemList.Height)
  723. buttonFrame:Destroy()
  724. end
  725.  
  726. function ItemList:AddItem(userAsset)
  727. local item = AssetRow(userAsset)
  728. item.Parent = ItemScrollBar.ContentFrame
  729. item.Position = UDim2.new(0, 0, 0, ItemList.Height)
  730. ItemList.Height = ItemList.Height + ItemList.RowHeight
  731. end
  732.  
  733. function ItemList:Populate()
  734. local spinner, closeSpinner = Metro.Spinner(false)
  735. spinner.Parent = ItemFrame
  736.  
  737. ItemList:Clear()
  738.  
  739. local aborted = false
  740.  
  741. local function loaded()
  742. if closeSpinner then
  743. closeSpinner()
  744. end
  745. end
  746.  
  747. local function abort()
  748. aborted = true
  749. ItemList.Cancel = nil
  750. loaded()
  751. end
  752.  
  753. ItemList.Cancel = abort
  754.  
  755. local tt = 0
  756. local getUserAssetTime = 0
  757. local filterTime = 0
  758. local sortTime = 0
  759. local getTotalRap = 0
  760. local createGuiTime = 0
  761.  
  762. tt = tick()
  763. local userAssets = CurrentUser:GetUserAssets()
  764. getUserAssetTime = tick() - tt
  765.  
  766. tt = tick()
  767. userAssets = Filter:Apply(userAssets)
  768. filterTime = tick() - tt
  769.  
  770. tt = tick()
  771. userAssets = Filter:Sort(userAssets)
  772. sortTime = tick() - tt
  773.  
  774.  
  775.  
  776. --calculate total RAP
  777. tt = tick()
  778. local totalRAP = CurrentUser:GetTotalRAP()
  779. getTotalRap = tick() - tt
  780. rapLabel.Text = numerify(totalRAP) .. " R$"
  781.  
  782. local itemsSoFar = 0
  783. local maxItems = 50 -- max items to render at once
  784. local hasHitMax = false
  785. local completed = false
  786.  
  787. tt = tick()
  788.  
  789. Spawn(function()
  790. for i,userAsset in pairs(userAssets) do
  791. if aborted then break end
  792. if Limiteds.List[userAsset.Id] then
  793. itemsSoFar = itemsSoFar + 1
  794. if (hasHitMax == false and itemsSoFar > maxItems) then
  795. --tell the main function to continue
  796. completed = true
  797. ItemList:AddSeeMoreButton()
  798. hasHitMax = true
  799. end
  800. ItemList:AddItem(userAsset)
  801. end
  802. end
  803. ItemScrollBar.SetMaxHeight(ItemList.Height)
  804. completed = true
  805. end)
  806.  
  807. while completed == false do
  808. wait(.01)
  809. end
  810.  
  811. createGuiTime = tick() - tt
  812.  
  813. local myStr = "assets: " .. tostring(getUserAssetTime) .. " filter: " .. tostring(filterTime) .. " sort: " .. tostring(sortTime) .. " rap: " .. tostring(getTotalRap) .. " gui: " .. tostring(createGuiTime)
  814. --showHint(myStr)
  815.  
  816. ItemList.Cancel = nil
  817. loaded()
  818. end
  819.  
  820. UpdateItemList = function()
  821. ItemList:Populate()
  822. end
  823.  
  824. function populatePlayerNames()
  825. playerNames = {"ROBLOX"}
  826. for _,player in pairs(game:GetService("Players"):GetPlayers()) do
  827. table.insert(playerNames, player.Name)
  828. end
  829. updatePlayerChoices(playerNames)
  830. end
  831.  
  832. populatePlayerNames()
  833.  
  834. Players.ChildAdded:connect(populatePlayerNames)
  835. Players.ChildRemoved:connect(populatePlayerNames)
  836.  
  837. --when itemSearch loses focus
  838. --when dropdown player is changed
  839. --when dropdown item list is changed
  840.  
  841. function updateSortLabels()
  842. local symbol
  843. if Filter.SortAscending then
  844. symbol = " v"
  845. else
  846. symbol = " ^"
  847. end
  848. if Filter.SortType == "Name" then
  849. ItemNameLabel.Text = "name" .. symbol
  850. ItemValueLabel.Text = "rap"
  851. else
  852. ItemValueLabel.Text = "rap" .. symbol
  853. ItemNameLabel.Text = "name"
  854. end
  855. end
  856.  
  857. ItemNameLabel.MouseButton1Click:connect(function()
  858. if Filter.SortType == "Name" then
  859. Filter.SortAscending = not Filter.SortAscending
  860. else
  861. Filter.SortType = "Name"
  862. end
  863. updateSortLabels()
  864. ItemList:Populate()
  865. end)
  866.  
  867. ItemValueLabel.MouseButton1Click:connect(function()
  868. if Filter.SortType == "RAP" then
  869. Filter.SortAscending = not Filter.SortAscending
  870. else
  871. Filter.SortType = "RAP"
  872. end
  873. updateSortLabels()
  874. ItemList:Populate()
  875. end)
  876.  
  877. CurrentUser:SetByPlayer(Player)
  878.  
  879. itemSearch.FocusLost:connect(function()
  880. Filter.SearchText = itemSearch.Text
  881. ItemList:Populate()
  882. end)
  883.  
  884. local mouse = Player:GetMouse()
  885.  
  886. function ReturnMouseOnPlayer()
  887. --Right Leg
  888. --Hat handle
  889. --nil
  890. local target = mouse.Target
  891. local player
  892.  
  893. if not (target and target.Parent and target.Parent.Parent) then
  894. player = nil
  895. else
  896. player = Players:GetPlayerFromCharacter(target.Parent) or Players:GetPlayerFromCharacter(target.Parent.Parent)
  897. end
  898.  
  899. if player and player.Character then
  900. SelectionBox.Adornee = player.Character
  901. else
  902. SelectionBox.Adornee = nil
  903. end
  904.  
  905. return player
  906. end
  907.  
  908. mouse.Button1Down:connect(function()
  909. local player = ReturnMouseOnPlayer()
  910. if player then
  911. ItemList:Clear()
  912. showGui()
  913. setCurrentPlayerName(player.Name)
  914. CurrentUser:SetByPlayer(player)
  915. ItemList:Populate()
  916. else
  917. hideGui()
  918. end
  919. end)
  920.  
  921. mouse.Move:connect(function()
  922. ReturnMouseOnPlayer()
  923. end)
  924.  
  925. ItemList:Populate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement