diff --git a/public/asset/1 b/public/asset/1 index 764f5c6..bb48ce0 100644 --- a/public/asset/1 +++ b/public/asset/1 @@ -70,26 +70,22 @@ else end if game.CoreGui.Version >= 3 then - waitForProperty(game,"PlaceId") - local inRightPlace = true - for i,v in ipairs(backpackTestPlaces) do - if v == game.PlaceId then - inRightPlace = true - break - end + -- Backpack Builder, creates most of the backpack gui + scriptContext:AddCoreScript(12,screenGui,"CoreScripts/BackpackScripts/BackpackBuilder") + + waitForChild(screenGui,"CurrentLoadout") + waitForChild(screenGui,"Backpack") + local Backpack = screenGui.Backpack + + -- Manager handles all big backpack state changes, other scripts subscribe to this and do things accordingly + if game.CoreGui.Version >= 7 then + scriptContext:AddCoreScript(13,Backpack,"CoreScripts/BackpackScripts/BackpackManager") end - waitForChild(game,"Players") - waitForProperty(game.Players,"LocalPlayer") - if game.Players.LocalPlayer.userId == 7210880 or game.Players.LocalPlayer.userId == 0 then inRightPlace = true end - - if not inRightPlace then return end -- restricting availability of backpack - - -- Backpack Builder - scriptContext:AddCoreScript(12,screenGui,"BackpackBuilder") - waitForChild(screenGui,"CurrentLoadout") - waitForChild(screenGui.CurrentLoadout,"TempSlot") - waitForChild(screenGui.CurrentLoadout.TempSlot,"SlotNumber") - -- Backpack Script - scriptContext:AddCoreScript(13,screenGui.CurrentLoadout,"BackpackScript") + -- Backpack Gear (handles all backpack gear tab stuff) + game:GetService("ScriptContext"):AddCoreScript(14,Backpack,"CoreScripts/BackpackScripts/BackpackGear") + -- Loadout Script, used for gear hotkeys + scriptContext:AddCoreScript(15,screenGui.CurrentLoadout,"CoreScripts/BackpackScripts/LoadoutScript") + -- Wardrobe script handles all character dressing operations + scriptContext:AddCoreScript(16,Backpack,"CoreScripts/BackpackScripts/BackpackWardrobe") end \ No newline at end of file diff --git a/public/asset/12 b/public/asset/12 index 007a8c9..aafc465 100644 --- a/public/asset/12 +++ b/public/asset/12 @@ -1,5 +1,6 @@ %12% ---- ATTENTION!!! There are site-specific ids at the end of this script!!!!!!!!!!!!!!!!!!!! +-- This script creates almost all gui elements found in the backpack (warning: there are a lot!) +-- TODO: automate this process if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client @@ -76,6 +77,23 @@ TempSlot.Parent = CurrentLoadout GearReference.Name = "GearReference" GearReference.RobloxLocked = true GearReference.Parent = TempSlot + + local ToolTipLabel = Instance.new("TextLabel") + ToolTipLabel.Name = "ToolTipLabel" + ToolTipLabel.RobloxLocked = true + ToolTipLabel.Text = "" + ToolTipLabel.BackgroundTransparency = 0.5 + ToolTipLabel.BorderSizePixel = 0 + ToolTipLabel.Visible = false + ToolTipLabel.TextColor3 = Color3.new(1,1,1) + ToolTipLabel.BackgroundColor3 = Color3.new(0,0,0) + ToolTipLabel.TextStrokeTransparency = 0 + ToolTipLabel.Font = Enum.Font.ArialBold + ToolTipLabel.FontSize = Enum.FontSize.Size14 + --ToolTipLabel.TextWrap = true + ToolTipLabel.Size = UDim2.new(1,60,0,20) + ToolTipLabel.Position = UDim2.new(0,-30,0,-30) + ToolTipLabel.Parent = TempSlot local Kill = Instance.new("BoolValue") Kill.Name = "Kill" @@ -136,12 +154,13 @@ TempSlot.Parent = CurrentLoadout --- Great, now lets make the inventory! local Backpack = Instance.new("Frame") +Backpack.RobloxLocked = true Backpack.Visible = false Backpack.Name = "Backpack" Backpack.Position = UDim2.new(0.5,0,0.5,0) -Backpack.Size = UDim2.new(0,0,0,0) -Backpack.Style = Enum.FrameStyle.RobloxSquare -Backpack.RobloxLocked = true +Backpack.BackgroundColor3 = Color3.new(0,0,0) +Backpack.BackgroundTransparency = 0.08 +Backpack.BorderSizePixel = 0 Backpack.Parent = gui Backpack.Active = true @@ -164,49 +183,146 @@ Backpack.Active = true local Tabs = Instance.new("Frame") Tabs.Name = "Tabs" - Tabs.Visible = false + Tabs.Visible = true Tabs.RobloxLocked = true Tabs.BackgroundColor3 = Color3.new(0,0,0) - Tabs.BackgroundTransparency = 0.5 + Tabs.BackgroundTransparency = 0.08 Tabs.BorderSizePixel = 0 - Tabs.Position = UDim2.new(0,-8,-0.1,-8) - Tabs.Size = UDim2.new(1,16,0.1,0) + Tabs.Position = UDim2.new(0,0,-0.1,-4) + Tabs.Size = UDim2.new(1,0,0.1,4) Tabs.Parent = Backpack -- Tabs Children - local InventoryButton = Instance.new("ImageButton") + + local tabLine = Instance.new("Frame") + tabLine.RobloxLocked = true + tabLine.Name = "TabLine" + tabLine.BackgroundColor3 = Color3.new(53/255, 53/255, 53/255) + tabLine.BorderSizePixel = 0 + tabLine.Position = UDim2.new(0,5,1,-4) + tabLine.Size = UDim2.new(1,-10,0,4) + tabLine.ZIndex = 2 + tabLine.Parent = Tabs + + local InventoryButton = Instance.new("TextButton") InventoryButton.RobloxLocked = true InventoryButton.Name = "InventoryButton" - InventoryButton.Size = UDim2.new(0.12,0,1,0) - InventoryButton.Style = Enum.ButtonStyle.RobloxButton + InventoryButton.Size = UDim2.new(0,60,0,30) + InventoryButton.Position = UDim2.new(0,7,1,-31) + InventoryButton.BackgroundColor3 = Color3.new(1,1,1) + InventoryButton.BorderColor3 = Color3.new(1,1,1) + InventoryButton.Font = Enum.Font.ArialBold + InventoryButton.FontSize = Enum.FontSize.Size18 + InventoryButton.Text = "Gear" + InventoryButton.AutoButtonColor = false + InventoryButton.TextColor3 = Color3.new(0,0,0) InventoryButton.Selected = true + InventoryButton.Active = true + InventoryButton.ZIndex = 3 InventoryButton.Parent = Tabs - -- InventoryButton Children - local InventoryText = Instance.new("TextLabel") - InventoryText.RobloxLocked = true - InventoryText.Name = "InventoryText" - InventoryText.BackgroundTransparency = 1 - InventoryText.Font = Enum.Font.ArialBold - InventoryText.FontSize = Enum.FontSize.Size18 - InventoryText.Position = UDim2.new(0,-7,0,-7) - InventoryText.Size = UDim2.new(1,14,1,14) - InventoryText.Text = "Gear" - InventoryText.TextColor3 = Color3.new(1,1,1) - InventoryText.Parent = InventoryButton + if game.CoreGui.Version >= 8 then + local WardrobeButton = Instance.new("TextButton") + WardrobeButton.RobloxLocked = true + WardrobeButton.Name = "WardrobeButton" + WardrobeButton.Size = UDim2.new(0,90,0,30) + WardrobeButton.Position = UDim2.new(0,77,1,-31) + WardrobeButton.BackgroundColor3 = Color3.new(0,0,0) + WardrobeButton.BorderColor3 = Color3.new(1,1,1) + WardrobeButton.Font = Enum.Font.ArialBold + WardrobeButton.FontSize = Enum.FontSize.Size18 + WardrobeButton.Text = "Wardrobe" + WardrobeButton.AutoButtonColor = false + WardrobeButton.TextColor3 = Color3.new(1,1,1) + WardrobeButton.Selected = false + WardrobeButton.Active = true + WardrobeButton.Parent = Tabs + end local closeButton = Instance.new("TextButton") closeButton.RobloxLocked = true closeButton.Name = "CloseButton" closeButton.Font = Enum.Font.ArialBold closeButton.FontSize = Enum.FontSize.Size24 - closeButton.Position = UDim2.new(1,-33,0,2) + closeButton.Position = UDim2.new(1,-33,0,4) closeButton.Size = UDim2.new(0,30,0,30) closeButton.Style = Enum.ButtonStyle.RobloxButton - closeButton.Text = "X" + closeButton.Text = "" closeButton.TextColor3 = Color3.new(1,1,1) closeButton.Parent = Tabs - + closeButton.Modal = true + + --closeButton child + local XImage = Instance.new("ImageLabel") + XImage.RobloxLocked = true + XImage.Name = "XImage" + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=75547445") + XImage.Image = "http://www.roblox.com/asset/?id=75547445" --TODO: move to rbxasset + XImage.BackgroundTransparency = 1 + XImage.Position = UDim2.new(-.25,-1,-.25,-1) + XImage.Size = UDim2.new(1.5,2,1.5,2) + XImage.ZIndex = 2 + XImage.Parent = closeButton + + -- Generic Search gui used across backpack + local SearchFrame = Instance.new("Frame") + SearchFrame.RobloxLocked = true + SearchFrame.Name = "SearchFrame" + SearchFrame.BackgroundTransparency = 1 + SearchFrame.Position = UDim2.new(1,-220,0,2) + SearchFrame.Size = UDim2.new(0,220,0,24) + SearchFrame.Parent = Backpack + + -- SearchFrame Children + local SearchButton = Instance.new("ImageButton") + SearchButton.RobloxLocked = true + SearchButton.Name = "SearchButton" + SearchButton.Size = UDim2.new(0,25,0,25) + SearchButton.BackgroundTransparency = 1 + SearchButton.Image = "rbxasset://textures/ui/SearchIcon.png" + SearchButton.Parent = SearchFrame + + local SearchBoxFrame = Instance.new("TextButton") + SearchBoxFrame.RobloxLocked = true + SearchBoxFrame.Position = UDim2.new(0,25,0,0) + SearchBoxFrame.Size = UDim2.new(1,-28,0,26) + SearchBoxFrame.Name = "SearchBoxFrame" + SearchBoxFrame.Text = "" + SearchBoxFrame.Style = Enum.ButtonStyle.RobloxButton + SearchBoxFrame.Parent = SearchFrame + + -- SearchBoxFrame Children + local SearchBox = Instance.new("TextBox") + SearchBox.RobloxLocked = true + SearchBox.Name = "SearchBox" + SearchBox.BackgroundTransparency = 1 + SearchBox.Font = Enum.Font.ArialBold + SearchBox.FontSize = Enum.FontSize.Size12 + SearchBox.Position = UDim2.new(0,-5,0,-5) + SearchBox.Size = UDim2.new(1,10,1,10) + SearchBox.TextColor3 = Color3.new(1,1,1) + SearchBox.TextXAlignment = Enum.TextXAlignment.Left + SearchBox.ZIndex = 2 + SearchBox.TextWrap = true + SearchBox.Text = "Search..." + SearchBox.Parent = SearchBoxFrame + + + local ResetButton = Instance.new("TextButton") + ResetButton.RobloxLocked = true + ResetButton.Visible = false + ResetButton.Name = "ResetButton" + ResetButton.Position = UDim2.new(1,-26,0,3) + ResetButton.Size = UDim2.new(0,20,0,20) + ResetButton.Style = Enum.ButtonStyle.RobloxButtonDefault + ResetButton.Text = "X" + ResetButton.TextColor3 = Color3.new(1,1,1) + ResetButton.Font = Enum.Font.ArialBold + ResetButton.FontSize = Enum.FontSize.Size18 + ResetButton.ZIndex = 3 + ResetButton.Parent = SearchFrame + +------------------------------- GEAR ------------------------------------------------------- local Gear = Instance.new("Frame") Gear.Name = "Gear" Gear.RobloxLocked = true @@ -215,84 +331,22 @@ Backpack.Active = true Gear.Parent = Backpack -- Gear Children + local AssetsList = Instance.new("Frame") + AssetsList.RobloxLocked = true + AssetsList.Name = "AssetsList" + AssetsList.BackgroundTransparency = 1 + AssetsList.Size = UDim2.new(0.2,0,1,0) + AssetsList.Style = Enum.FrameStyle.RobloxSquare + AssetsList.Visible = false + AssetsList.Parent = Gear + local GearGrid = Instance.new("Frame") GearGrid.RobloxLocked = true GearGrid.Name = "GearGrid" GearGrid.Size = UDim2.new(0.69,0,1,0) - GearGrid.Style = Enum.FrameStyle.RobloxSquare + GearGrid.BackgroundTransparency = 1 GearGrid.Parent = Gear - - -- GearGrid Children - local ResetFrame = Instance.new("Frame") - ResetFrame.RobloxLocked = true - ResetFrame.Name = "ResetFrame" - ResetFrame.Visible = false - ResetFrame.BackgroundTransparency = 1 - ResetFrame.Size = UDim2.new(0,32,0,64) - ResetFrame.Parent = GearGrid - - -- ResetFrame Children - local ResetImageLabel = Instance.new("ImageLabel") - ResetImageLabel.RobloxLocked = true - ResetImageLabel.Name = "ResetImageLabel" - ResetImageLabel.Image = "rbxasset://textures/ui/ResetIcon.png" - ResetImageLabel.BackgroundTransparency = 1 - ResetImageLabel.Position = UDim2.new(0,0,0,-12) - ResetImageLabel.Size = UDim2.new(0.8,0,0.79,0) - ResetImageLabel.ZIndex = 2 - ResetImageLabel.Parent = ResetFrame - local ResetButtonBorder = Instance.new("TextButton") - ResetButtonBorder.RobloxLocked = true - ResetButtonBorder.Name = "ResetButtonBorder" - ResetButtonBorder.Position = UDim2.new(0,-3,0,-7) - ResetButtonBorder.Size = UDim2.new(1,0,0.64,0) - ResetButtonBorder.Style = Enum.ButtonStyle.RobloxButton - ResetButtonBorder.Text = "" - ResetButtonBorder.Parent = ResetFrame - - - local SearchFrame = Instance.new("Frame") - SearchFrame.RobloxLocked = true - SearchFrame.Name = "SearchFrame" - SearchFrame.BackgroundTransparency = 1 - SearchFrame.Position = UDim2.new(1,-150,0,0) - SearchFrame.Size = UDim2.new(0,150,0,25) - SearchFrame.Parent = GearGrid - - -- SearchFrame Children - local SearchButton = Instance.new("ImageButton") - SearchButton.RobloxLocked = true - SearchButton.Name = "SearchButton" - SearchButton.Size = UDim2.new(0,25,0,25) - SearchButton.BackgroundTransparency = 1 - SearchButton.Image = "rbxasset://textures/ui/SearchIcon.png" - SearchButton.Parent = SearchFrame - - local SearchBoxFrame = Instance.new("TextButton") - SearchBoxFrame.RobloxLocked = true - SearchBoxFrame.Position = UDim2.new(0,26,0,0) - SearchBoxFrame.Size = UDim2.new(0,121,0,25) - SearchBoxFrame.Name = "SearchBoxFrame" - SearchBoxFrame.Text = "" - SearchBoxFrame.Style = Enum.ButtonStyle.RobloxButton - SearchBoxFrame.Parent = SearchFrame - - -- SearchBoxFrame Children - local SearchBox = Instance.new("TextBox") - SearchBox.RobloxLocked = true - SearchBox.Name = "SearchBox" - SearchBox.BackgroundTransparency = 1 - SearchBox.Font = Enum.Font.ArialBold - SearchBox.FontSize = Enum.FontSize.Size12 - SearchBox.Position = UDim2.new(0,-5,0,-5) - SearchBox.Size = UDim2.new(1,10,1,10) - SearchBox.TextColor3 = Color3.new(1,1,1) - SearchBox.TextXAlignment = Enum.TextXAlignment.Left - SearchBox.ZIndex = 2 - SearchBox.TextWrap = true - SearchBox.Text = "Search..." - SearchBox.Parent = SearchBoxFrame local GearButton = Instance.new("ImageButton") GearButton.RobloxLocked = true @@ -335,8 +389,8 @@ Backpack.Active = true local GearGridScrollingArea = Instance.new("Frame") GearGridScrollingArea.RobloxLocked = true GearGridScrollingArea.Name = "GearGridScrollingArea" - GearGridScrollingArea.Position = UDim2.new(0.7,0,0,0) - GearGridScrollingArea.Size = UDim2.new(0,17,1,0) + GearGridScrollingArea.Position = UDim2.new(0.7,0,0,35) + GearGridScrollingArea.Size = UDim2.new(0,17,1,-45) GearGridScrollingArea.BackgroundTransparency = 1 GearGridScrollingArea.Parent = Gear @@ -385,14 +439,14 @@ Backpack.Active = true LoadoutsList.Size = UDim2.new(1,-17,0.85,-2) LoadoutsList.Style = Enum.FrameStyle.RobloxSquare LoadoutsList.Parent = GearLoadouts - - + local GearPreview = Instance.new("Frame") GearPreview.RobloxLocked = true GearPreview.Name = "GearPreview" GearPreview.Position = UDim2.new(0.7,23,0,0) - GearPreview.Size = UDim2.new(0.3,-23,0.5,-1) - GearPreview.Style = Enum.FrameStyle.RobloxRound + GearPreview.Size = UDim2.new(0.3,-28,0.5,-1) + GearPreview.BackgroundTransparency = 1 + GearPreview.ZIndex = 7 GearPreview.Parent = Gear -- GearPreview Children @@ -402,6 +456,7 @@ Backpack.Active = true GearStats.BackgroundTransparency = 1 GearStats.Position = UDim2.new(0,0,0.75,0) GearStats.Size = UDim2.new(1,0,0.25,0) + GearStats.ZIndex = 8 GearStats.Parent = GearPreview -- GearStats Children @@ -416,6 +471,7 @@ Backpack.Active = true GearName.Text = "" GearName.TextColor3 = Color3.new(1,1,1) GearName.TextWrap = true + GearName.ZIndex = 9 GearName.Parent = GearStats local GearImage = Instance.new("ImageLabel") @@ -425,6 +481,7 @@ Backpack.Active = true GearImage.BackgroundTransparency = 1 GearImage.Position = UDim2.new(0.125,0,0,0) GearImage.Size = UDim2.new(0.75,0,0.75,0) + GearImage.ZIndex = 8 GearImage.Parent = GearPreview --GearImage Children @@ -437,6 +494,7 @@ Backpack.Active = true GearIcons.Position = UDim2.new(0.4,2,0.85,-2) GearIcons.Size = UDim2.new(0.6,0,0.15,0) GearIcons.Visible = false + GearIcons.ZIndex = 9 GearIcons.Parent = GearImage -- GearIcons Children @@ -470,8 +528,264 @@ Backpack.Active = true AttributeThreeImage.Position = UDim2.new(0.75,0,0,0) AttributeThreeImage.Parent = GearIcons +------------------------------- WARDROBE ------------------------------------------------------- + if game.CoreGui.Version < 8 then + -- no need for this to stick around, we aren't ready for wardrobe + script:remove() + return + end --- Backpack Resizer (handles all backpack resizing junk) -game:GetService("ScriptContext"):AddCoreScript(11,Backpack,"BackpackResizer") - + local function makeCharFrame(frameName, parent) + local frame = Instance.new("Frame") + frame.RobloxLocked = true + frame.Size = UDim2.new(1,0,1,-70) + frame.Position = UDim2.new(0,0,0,20) + frame.Name = frameName + frame.BackgroundTransparency = 1 + frame.Parent = parent + frame.Visible = false + return frame + end + local function makeZone( zoneName, image, size, position, parent ) + local zone = Instance.new("ImageLabel") + zone.RobloxLocked = true + zone.Name = zoneName + zone.Image = image + zone.Size = size + zone.BackgroundTransparency = 1 + zone.Position = position + zone.Parent = parent + return zone + end + local function makeStyledButton( buttonName, size, position, parent, buttonStyle ) + local button = Instance.new("ImageButton") + button.RobloxLocked = true + button.Name = buttonName + button.Size = size + button.Position = position + if buttonStyle then + button.Style = buttonStyle + else + button.BackgroundColor3 = Color3.new(0,0,0) + button.BorderColor3 = Color3.new(1,1,1) + end + button.Parent = parent + return button + end + local function makeTextLabel( TextLabelName,text,position,parent ) + local label = Instance.new("TextLabel") + label.RobloxLocked = true + label.BackgroundTransparency = 1 + label.Size = UDim2.new(0,32,0,14) + label.Name = TextLabelName + label.Font = Enum.Font.Arial + label.TextColor3 = Color3.new(1,1,1) + label.FontSize = Enum.FontSize.Size14 + label.Text = text + label.Position = position + label.Parent = parent + end + + + local Wardrobe = Instance.new("Frame") + Wardrobe.Name = "Wardrobe" + Wardrobe.RobloxLocked = true + Wardrobe.BackgroundTransparency = 1 + Wardrobe.Visible = false + Wardrobe.Size = UDim2.new(1,0,1,0) + Wardrobe.Parent = Backpack + + local AssetList = Instance.new("Frame") + AssetList.RobloxLocked = true + AssetList.Name = "AssetList" + AssetList.Position = UDim2.new(0,4,0,5) + AssetList.Size = UDim2.new(0,85,1,-5) + AssetList.BackgroundTransparency = 1 + AssetList.Visible = true + AssetList.Parent = Wardrobe + + local PreviewAssetFrame = Instance.new("Frame") + PreviewAssetFrame.RobloxLocked = true + PreviewAssetFrame.Name = "PreviewAssetFrame" + PreviewAssetFrame.BackgroundTransparency = 1 + PreviewAssetFrame.Position = UDim2.new(1,-240,0,30) + PreviewAssetFrame.Size = UDim2.new(0,250,0,250) + PreviewAssetFrame.Parent = Wardrobe + + local PreviewAssetBacking = Instance.new("TextButton") + PreviewAssetBacking.RobloxLocked = true + PreviewAssetBacking.Name = "PreviewAssetBacking" + PreviewAssetBacking.Active = false + PreviewAssetBacking.Text = "" + PreviewAssetBacking.AutoButtonColor = false + PreviewAssetBacking.Size = UDim2.new(1,0,1,0) + PreviewAssetBacking.Style = Enum.ButtonStyle.RobloxButton + PreviewAssetBacking.Visible = false + PreviewAssetBacking.ZIndex = 9 + PreviewAssetBacking.Parent = PreviewAssetFrame + + local PreviewAssetImage = Instance.new("ImageLabel") + PreviewAssetImage.RobloxLocked = true + PreviewAssetImage.Name = "PreviewAssetImage" + PreviewAssetImage.BackgroundTransparency = 0.8 + PreviewAssetImage.Position = UDim2.new(0.5,-100,0,0) + PreviewAssetImage.Size = UDim2.new(0,200,0,200) + PreviewAssetImage.BorderSizePixel = 0 + PreviewAssetImage.ZIndex = 10 + PreviewAssetImage.Parent = PreviewAssetBacking + + local AssetNameLabel = Instance.new("TextLabel") + AssetNameLabel.Name = "AssetNameLabel" + AssetNameLabel.RobloxLocked = true + AssetNameLabel.BackgroundTransparency = 1 + AssetNameLabel.Position = UDim2.new(0,0,1,-20) + AssetNameLabel.Size = UDim2.new(0.5,0,0,24) + AssetNameLabel.ZIndex = 10 + AssetNameLabel.Font = Enum.Font.Arial + AssetNameLabel.Text = "" + AssetNameLabel.TextColor3 = Color3.new(1,1,1) + AssetNameLabel.TextScaled = true + AssetNameLabel.Parent = PreviewAssetBacking + + local AssetTypeLabel = AssetNameLabel:clone() + AssetTypeLabel.RobloxLocked = true + AssetTypeLabel.Name = "AssetTypeLabel" + AssetTypeLabel.TextScaled = false + AssetTypeLabel.FontSize = Enum.FontSize.Size18 + AssetTypeLabel.Position = UDim2.new(0.5,3,1,-20) + AssetTypeLabel.Parent = PreviewAssetBacking + + + + local PreviewButton = Instance.new("TextButton") + PreviewButton.RobloxLocked = true + PreviewButton.Name = "PreviewButton" + PreviewButton.Text = "Rotate" + PreviewButton.BackgroundColor3 = Color3.new(0,0,0) + PreviewButton.BackgroundTransparency = 0.5 + PreviewButton.BorderColor3 = Color3.new(1,1,1) + PreviewButton.Position = UDim2.new(1.2,-62,1,-50) + PreviewButton.Size = UDim2.new(0,125,0,50) + PreviewButton.Font = Enum.Font.ArialBold + PreviewButton.FontSize = Enum.FontSize.Size24 + PreviewButton.TextColor3 = Color3.new(1,1,1) + PreviewButton.TextWrapped = true + PreviewButton.TextStrokeTransparency = 0 + PreviewButton.Parent = Wardrobe + + local CharacterPane = Instance.new("Frame") + CharacterPane.RobloxLocked = true + CharacterPane.Name = "CharacterPane" + CharacterPane.Position = UDim2.new(1,-220,0,32) + CharacterPane.Size = UDim2.new(0,220,1,-40) + CharacterPane.BackgroundTransparency = 1 + CharacterPane.Visible = true + CharacterPane.Parent = Wardrobe + + --CharacterPane Children + local FaceFrame = makeCharFrame("FacesFrame", CharacterPane) + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=75460621") + makeZone("FaceZone","http://www.roblox.com/asset/?id=75460621",UDim2.new(0,157,0,137),UDim2.new(0.5,-78,0.5,-68),FaceFrame) + makeStyledButton("Face",UDim2.new(0,64,0,64),UDim2.new(0.5,-32,0.5,-135),FaceFrame) + + local HeadFrame = makeCharFrame("HeadsFrame", CharacterPane) + makeZone("FaceZone","http://www.roblox.com/asset/?id=75460621",UDim2.new(0,157,0,137),UDim2.new(0.5,-78,0.5,-68),HeadFrame) + makeStyledButton("Head",UDim2.new(0,64,0,64),UDim2.new(0.5,-32,0.5,-135),HeadFrame) + + local HatsFrame = makeCharFrame("HatsFrame", CharacterPane) + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=75457888") + local HatsZone = makeZone("HatsZone","http://www.roblox.com/asset/?id=75457888",UDim2.new(0,186,0,184),UDim2.new(0.5,-93,0.5,-100), HatsFrame) + makeStyledButton("Hat1Button",UDim2.new(0,64,0,64),UDim2.new(0,-1,0,-1),HatsZone,Enum.ButtonStyle.RobloxButton) + makeStyledButton("Hat2Button",UDim2.new(0,64,0,64),UDim2.new(0,63,0,-1),HatsZone,Enum.ButtonStyle.RobloxButton) + makeStyledButton("Hat3Button",UDim2.new(0,64,0,64),UDim2.new(0,127,0,-1),HatsZone,Enum.ButtonStyle.RobloxButton) + + local PantsFrame = makeCharFrame("PantsFrame", CharacterPane) + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=75457920") + makeZone("PantsZone","http://www.roblox.com/asset/?id=75457920",UDim2.new(0,121,0,99),UDim2.new(0.5,-60,0.5,-100),PantsFrame) + + local pantFrame = Instance.new("Frame") + pantFrame.RobloxLocked = true + pantFrame.Size = UDim2.new(0,25,0,56) + pantFrame.Position = UDim2.new(0.5,-26,0.5,0) + pantFrame.BackgroundColor3 = Color3.new(0,0,0) + pantFrame.BorderColor3 = Color3.new(1,1,1) + pantFrame.Name = "PantFrame" + pantFrame.Parent = PantsFrame + + local otherPantFrame = pantFrame:clone() + otherPantFrame.Position = UDim2.new(0.5,3,0.5,0) + otherPantFrame.RobloxLocked = true + otherPantFrame.Parent = PantsFrame + + local CurrentPants = Instance.new("ImageButton") + CurrentPants.RobloxLocked = true + CurrentPants.BackgroundTransparency = 1 + CurrentPants.ZIndex = 2 + CurrentPants.Name = "CurrentPants" + CurrentPants.Position = UDim2.new(0.5,-31,0.5,-4) + CurrentPants.Size = UDim2.new(0,54,0,59) + CurrentPants.Parent = PantsFrame + + local MeshFrame = makeCharFrame("PackagesFrame", CharacterPane) + local torsoButton = makeStyledButton("TorsoMeshButton", UDim2.new(0,64,0,64),UDim2.new(0.5,-32,0.5,-110),MeshFrame,Enum.ButtonStyle.RobloxButton) + makeTextLabel("TorsoLabel","Torso",UDim2.new(0.5,-16,0,-25),torsoButton) + local leftLegButton = makeStyledButton("LeftLegMeshButton", UDim2.new(0,64,0,64),UDim2.new(0.5,0,0.5,-25),MeshFrame,Enum.ButtonStyle.RobloxButton) + makeTextLabel("LeftLegLabel","Left Leg",UDim2.new(0.5,-16,0,-25),leftLegButton) + local rightLegButton = makeStyledButton("RightLegMeshButton", UDim2.new(0,64,0,64),UDim2.new(0.5,-64,0.5,-25),MeshFrame,Enum.ButtonStyle.RobloxButton) + makeTextLabel("RightLegLabel","Right Leg",UDim2.new(0.5,-16,0,-25),rightLegButton) + local rightArmButton = makeStyledButton("RightArmMeshButton", UDim2.new(0,64,0,64),UDim2.new(0.5,-96,0.5,-110),MeshFrame,Enum.ButtonStyle.RobloxButton) + makeTextLabel("RightArmLabel","Right Arm",UDim2.new(0.5,-16,0,-25),rightArmButton) + local leftArmButton = makeStyledButton("LeftArmMeshButton", UDim2.new(0,64,0,64),UDim2.new(0.5,32,0.5,-110),MeshFrame,Enum.ButtonStyle.RobloxButton) + makeTextLabel("LeftArmLabel","Left Arm",UDim2.new(0.5,-16,0,-25),leftArmButton) + + local TShirtFrame = makeCharFrame("T-ShirtsFrame",CharacterPane) + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=75460642") + makeZone("TShirtZone","http://www.roblox.com/asset/?id=75460642",UDim2.new(0,121,0,154),UDim2.new(0.5,-60,0.5,-100),TShirtFrame) + makeStyledButton("TShirtButton", UDim2.new(0,64,0,64),UDim2.new(0.5,-32,0.5,-64),TShirtFrame) + + + local ShirtFrame = makeCharFrame("ShirtsFrame", CharacterPane) + makeZone("ShirtZone","http://www.roblox.com/asset/?id=75460642",UDim2.new(0,121,0,154),UDim2.new(0.5,-60,0.5,-100),ShirtFrame) + makeStyledButton("ShirtButton", UDim2.new(0,64,0,64),UDim2.new(0.5,-32,0.5,-64),ShirtFrame) + + + local ColorFrame = makeCharFrame("ColorFrame", CharacterPane) + game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=76049888") + local ColorZone = makeZone("ColorZone","http://www.roblox.com/asset/?id=76049888", UDim2.new(0,120,0,150),UDim2.new(0.5,-60,0.5,-100),ColorFrame) + makeStyledButton("Head",UDim2.new(0.26,0,0.19,0),UDim2.new(0.37,0,0.02,0),ColorZone).AutoButtonColor = false + makeStyledButton("LeftArm",UDim2.new(0.19,0,0.36,0),UDim2.new(0.78,0,0.26,0),ColorZone).AutoButtonColor = false + makeStyledButton("RightArm",UDim2.new(0.19,0,0.36,0),UDim2.new(0.025,0,0.26,0),ColorZone).AutoButtonColor = false + makeStyledButton("Torso",UDim2.new(0.43,0,0.36,0),UDim2.new(0.28,0,0.26,0),ColorZone).AutoButtonColor = false + makeStyledButton("RightLeg",UDim2.new(0.19,0,0.31,0),UDim2.new(0.275,0,0.67,0),ColorZone).AutoButtonColor = false + makeStyledButton("LeftLeg",UDim2.new(0.19,0,0.31,0),UDim2.new(0.525,0,0.67,0),ColorZone).AutoButtonColor = false + + -- Character Panel label (shows what category we are currently browsing) + local CategoryLabel = Instance.new("TextLabel") + CategoryLabel.RobloxLocked = true + CategoryLabel.Name = "CategoryLabel" + CategoryLabel.BackgroundTransparency = 1 + CategoryLabel.Font = Enum.Font.ArialBold + CategoryLabel.FontSize = Enum.FontSize.Size18 + CategoryLabel.Position = UDim2.new(0,0,0,-7) + CategoryLabel.Size = UDim2.new(1,0,0,20) + CategoryLabel.TextXAlignment = Enum.TextXAlignment.Center + CategoryLabel.Text = "All" + CategoryLabel.TextColor3 = Color3.new(1,1,1) + CategoryLabel.Parent = CharacterPane + + --Save Button + local SaveButton = Instance.new("TextButton") + SaveButton.RobloxLocked = true + SaveButton.Name = "SaveButton" + SaveButton.Size = UDim2.new(0.6,0,0,50) + SaveButton.Position = UDim2.new(0.2,0,1,-50) + SaveButton.Style = Enum.ButtonStyle.RobloxButton + SaveButton.Selected = false + SaveButton.Font = Enum.Font.ArialBold + SaveButton.FontSize = Enum.FontSize.Size18 + SaveButton.Text = "Save" + SaveButton.TextColor3 = Color3.new(1,1,1) + SaveButton.Parent = CharacterPane + +-- no need for this to stick around script:remove() \ No newline at end of file diff --git a/public/asset/13 b/public/asset/13 index 84cdf31..4417d00 100644 --- a/public/asset/13 +++ b/public/asset/13 @@ -1,11 +1,13 @@ %13% -if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client +-- This script manages context switches in the backpack (Gear to Wardrobe, etc.) and player state changes. Also manages global functions across different tabs (currently only search) +if game.CoreGui.Version < 7 then return end -- peace out if we aren't using the right client --- A couple of necessary functions +-- basic functions local function waitForChild(instance, name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end + return instance:FindFirstChild(name) end local function waitForProperty(instance, property) while not instance[property] do @@ -13,816 +15,347 @@ local function waitForProperty(instance, property) end end - - - - ---- Begin Locals +-- don't do anything if we are in an empty game waitForChild(game,"Players") +if #game.Players:GetChildren() < 1 then + game.Players.ChildAdded:wait() +end +-- make sure everything is loaded in before we do anything +-- get our local player waitForProperty(game.Players,"LocalPlayer") local player = game.Players.LocalPlayer -waitForChild(game, "LocalBackpack") -game.LocalBackpack:SetOldSchoolBackpack(false) -local currentLoadout = script.Parent -local maxNumLoadoutItems = 10 -waitForChild(currentLoadout.Parent,"Backpack") -local guiBackpack = currentLoadout.Parent.Backpack +------------------------ Locals ------------------------------ +local backpack = script.Parent +waitForChild(backpack,"Gear") -local characterChildAddedCon = nil -local backpackChildCon = nil +local screen = script.Parent.Parent +assert(screen:IsA("ScreenGui")) -local debounce = script.Parent.Debounce +waitForChild(backpack, "Tabs") +waitForChild(backpack.Tabs, "CloseButton") +local closeButton = backpack.Tabs.CloseButton -local waitingOnEnlarge = nil +waitForChild(backpack.Tabs, "InventoryButton") +local inventoryButton = backpack.Tabs.InventoryButton +if game.CoreGui.Version >= 8 then + waitForChild(backpack.Tabs, "WardrobeButton") + local wardrobeButton = backpack.Tabs.WardrobeButton +end +waitForChild(backpack.Parent,"ControlFrame") +local backpackButton = waitForChild(backpack.Parent.ControlFrame,"BackpackButton") +local currentTab = "gear" -local canSaveLoadout = true +local searchFrame = waitForChild(backpack,"SearchFrame") +waitForChild(backpack.SearchFrame,"SearchBoxFrame") +local searchBox = waitForChild(backpack.SearchFrame.SearchBoxFrame,"SearchBox") +local searchButton = waitForChild(backpack.SearchFrame,"SearchButton") +local resetButton = waitForChild(backpack.SearchFrame,"ResetButton") -local enlargeFactor = 1.18 -local buttonSizeEnlarge = UDim2.new(1 * enlargeFactor,0,1 * enlargeFactor,0) -local buttonSizeNormal = UDim2.new(1,0,1,0) -local enlargeOverride = true +local canToggle = true +local readyForNextEvent = true +local backpackIsOpen = false +local active = true -local guiTweenSpeed = 0.5 +local humanoidDiedCon = nil -for i = 0, 9 do - game:GetService("GuiService"):AddKey(tostring(i)) -- register our keys +local guiTweenSpeed = 0.25 -- how quickly we open/close the backpack + +local searchDefaultText = "Search..." +local tilde = "~" +local backquote = "`" + +------------------------ End Locals --------------------------- + + +---------------------------------------- Public Event Setup ---------------------------------------- + +function createPublicEvent(eventName) + assert(eventName, "eventName is nil") + assert(tostring(eventName),"eventName is not a string") + + local newEvent = Instance.new("BindableEvent") + newEvent.Name = tostring(eventName) + newEvent.Parent = script + + return newEvent end -local gearSlots = {} -for i = 1, maxNumLoadoutItems do - gearSlots[i] = "empty" +function createPublicFunction(funcName, invokeFunc) + assert(funcName, "funcName is nil") + assert(tostring(funcName), "funcName is not a string") + assert(invokeFunc, "invokeFunc is nil") + assert(type(invokeFunc) == "function", "invokeFunc should be of type 'function'") + + local newFunction = Instance.new("BindableFunction") + newFunction.Name = tostring(funcName) + newFunction.OnInvoke = invokeFunc + newFunction.Parent = script + + return newFunction end -local inventory = {} -local lastLoadout = {} ---- End Locals +-- Events +local resizeEvent = createPublicEvent("ResizeEvent") +local backpackOpenEvent = createPublicEvent("BackpackOpenEvent") +local backpackCloseEvent = createPublicEvent("BackpackCloseEvent") +local tabClickedEvent = createPublicEvent("TabClickedEvent") +local searchRequestedEvent = createPublicEvent("SearchRequestedEvent") +---------------------------------------- End Public Event Setup ---------------------------------------- +--------------------------- Internal Functions ---------------------------------------- +function deactivateBackpack() + backpack.Visible = false + active = false +end +function activateBackpack() + initHumanoidDiedConnections() + active = true + backpack.Visible = backpackIsOpen +end --- Begin Functions -local function kill(prop,con,gear) - if con then con:disconnect() end - if prop == true and gear then - reorganizeLoadout(gear,false) +function initHumanoidDiedConnections() + if humanoidDiedCon then + humanoidDiedCon:disconnect() end + waitForProperty(game.Players.LocalPlayer,"Character") + waitForChild(game.Players.LocalPlayer.Character,"Humanoid") + humanoidDiedCon = game.Players.LocalPlayer.Character.Humanoid.Died:connect(deactivateBackpack) end -function removeGear(gear) - local emptySlot = nil - for i = 1, #gearSlots do - if gearSlots[i] == gear and gear.Parent ~= nil then - emptySlot = i - break - end - end - if emptySlot then - if gearSlots[emptySlot].GearReference.Value then - if gearSlots[emptySlot].GearReference.Value.Parent == game.Players.LocalPlayer.Character then -- if we currently have this equipped, unequip it - gearSlots[emptySlot].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack - end - - if gearSlots[emptySlot].GearReference.Value:IsA("HopperBin") and gearSlots[emptySlot].GearReference.Value.Active then -- this is an active hopperbin - gearSlots[emptySlot].GearReference.Value:Disable() - gearSlots[emptySlot].GearReference.Value.Active = false - end - end - - gearSlots[emptySlot] = "empty" - - local centerizeX = gear.Size.X.Scale/2 - local centerizeY = gear.Size.Y.Scale/2 - gear:TweenSizeAndPosition(UDim2.new(0,0,0,0), - UDim2.new(gear.Position.X.Scale + centerizeX,gear.Position.X.Offset,gear.Position.Y.Scale + centerizeY,gear.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/4,true) - delay(guiTweenSpeed/2, - function() - gear:remove() - end) - end +local hideBackpack = function() + backpackIsOpen = false + readyForNextEvent = false + backpackButton.Selected = false + resetSearch() + backpackCloseEvent:Fire(currentTab) + backpack.Tabs.Visible = false + searchFrame.Visible = false + backpack:TweenSizeAndPosition(UDim2.new(0,0,0,0),UDim2.new(0.5,0,0.5,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, guiTweenSpeed, true, + function() + game.GuiService:RemoveCenterDialog(backpack) + backpack.Visible = false + backpackButton.Selected = false + end) + delay(guiTweenSpeed,function() + game.GuiService:RemoveCenterDialog(backpack) + backpack.Visible = false + backpackButton.Selected = false + canToggle = true + end) end -function insertGear(gear, addToSlot) - local pos = nil - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - pos = i - break - end - end +function showBackpack() + game.GuiService:AddCenterDialog(backpack, Enum.CenterDialogType.PlayerInitiatedDialog, + function() + backpack.Visible = true + backpackButton.Selected = true + end, + function() + backpack.Visible = false + backpackButton.Selected = false + end) + backpack.Visible = true + backpackButton.Selected = true + backpack:TweenSizeAndPosition(UDim2.new(0.55, 0, 0.76, 0),UDim2.new(0.225, 0, 0.09, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, guiTweenSpeed, true) + delay(guiTweenSpeed,function() + backpack.Tabs.Visible = true + searchFrame.Visible = true + backpackOpenEvent:Fire(currentTab) + canToggle = true + end) +end - if pos == 1 and gearSlots[1] ~= "empty" then gear:remove() return end -- we are currently full, can't add in +function toggleBackpack() + if not game.Players.LocalPlayer then return end + if not game.Players.LocalPlayer["Character"] then return end + + if not canToggle then return end + if not readyForNextEvent then return end + readyForNextEvent = false + canToggle = false + + backpackIsOpen = not backpackIsOpen + + if backpackIsOpen then + showBackpack() else - pos = addToSlot - -- push all gear down one slot - local start = 1 - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - start = i - break - end - end - for i = start, pos + 1, -1 do - gearSlots[i] = gearSlots[i - 1] - if i == 10 then - gearSlots[i].SlotNumber.Text = "0" - gearSlots[i].SlotNumberDownShadow.Text = "0" - gearSlots[i].SlotNumberUpShadow.Text = "0" - else - gearSlots[i].SlotNumber.Text = i - gearSlots[i].SlotNumberDownShadow.Text = i - gearSlots[i].SlotNumberUpShadow.Text = i - end - end - end - - gearSlots[pos] = gear - if pos ~= maxNumLoadoutItems then - if(type(tostring(pos)) == "string") then - local posString = tostring(pos) - gear.SlotNumber.Text = posString - gear.SlotNumberDownShadow.Text = posString - gear.SlotNumberUpShadow.Text = posString - end - else -- tenth gear doesn't follow mathematical pattern :( - gear.SlotNumber.Text = "0" - gear.SlotNumberDownShadow.Text = "0" - gear.SlotNumberUpShadow.Text = "0" - end - gear.Visible = true - - local con = nil - con = gear.Kill.Changed:connect(function(prop) kill(prop,con,gear) end) -end - - -function reorganizeLoadout(gear, inserting, equipped, addToSlot) - if inserting then -- add in gear - insertGear(gear, addToSlot) - else - removeGear(gear) - end - if gear ~= "empty" then gear.ZIndex = 1 end -end - -function checkToolAncestry(child,parent) - if child:IsA("Tool") or child:IsA("HopperBin") then - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then - if parent == nil then - gearSlots[i].Kill.Value = true - return false - elseif child.Parent == player.Character then - gearSlots[i].Selected = true - return true - elseif child.Parent == player.Backpack then - if child:IsA("Tool") or child:IsA("HopperBin") then gearSlots[i].Selected = false end - return true - else - gearSlots[i].Kill.Value = true - return false - end - return true - end - end + backpackButton.Selected = false + hideBackpack() end end -function removeAllEquippedGear(physGear) - local stuff = player.Character:GetChildren() - for i = 1, #stuff do - if ( stuff[i]:IsA("Tool") or stuff[i]:IsA("HopperBin") ) and stuff[i] ~= physGear then - if stuff[i]:IsA("Tool") then stuff[i].Parent = player.Backpack end - if stuff[i]:IsA("HopperBin") then - stuff[i]:Disable() - end - end +function closeBackpack() + if backpackIsOpen then + toggleBackpack() end end -function hopperBinSwitcher(numKey, physGear) - if not physGear then return end +function setSelected(tab) + assert(tab) + assert(tab:IsA("TextButton")) + + tab.BackgroundColor3 = Color3.new(1,1,1) + tab.TextColor3 = Color3.new(0,0,0) + tab.Selected = true + tab.ZIndex = 3 +end - physGear:ToggleSelect() +function setUnselected(tab) + assert(tab) + assert(tab:IsA("TextButton")) + + tab.BackgroundColor3 = Color3.new(0,0,0) + tab.TextColor3 = Color3.new(1,1,1) + tab.Selected = false + tab.ZIndex = 1 +end - if gearSlots[numKey] == "empty" then return end - - if not physGear.Active then - gearSlots[numKey].Selected = false - normalizeButton(gearSlots[numKey]) - else - gearSlots[numKey].Selected = true - enlargeButton(gearSlots[numKey]) +function updateTabGui(selectedTab) + assert(selectedTab) + + if selectedTab == "gear" then + setSelected(inventoryButton) + setUnselected(wardrobeButton) + elseif selectedTab == "wardrobe" then + setSelected(wardrobeButton) + setUnselected(inventoryButton) end end -function toolSwitcher(numKey) - - if not gearSlots[numKey] then return end - local physGear = gearSlots[numKey].GearReference.Value - if physGear == nil then return end - - removeAllEquippedGear(physGear) -- we don't remove this gear, as then we get a double switcheroo - - local key = numKey - if numKey == 0 then key = 10 end - - for i = 1, #gearSlots do - if gearSlots[i] and gearSlots[i] ~= "empty" and i ~= key then - normalizeButton(gearSlots[i]) - gearSlots[i].Selected = false - if gearSlots[i].GearReference and gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value:IsA("HopperBin") and gearSlots[i].GearReference.Value.Active then - gearSlots[i].GearReference.Value:ToggleSelect() - end - end - end - - if physGear:IsA("HopperBin") then - hopperBinSwitcher(numKey,physGear) - else - if physGear.Parent == player.Character then - physGear.Parent = player.Backpack - - if gearSlots[numKey] ~= "empty" then - gearSlots[numKey].Selected = false - normalizeButton(gearSlots[numKey]) - end - else - physGear.Parent = player.Character - gearSlots[numKey].Selected = true - - enlargeButton(gearSlots[numKey]) - end - end +function mouseLeaveTab(button) + assert(button) + assert(button:IsA("TextButton")) + + if button.Selected then return end + + button.BackgroundColor3 = Color3.new(0,0,0) end - -function activateGear(num) - local numKey = nil - if num == "0" then - numKey = 10 -- why do lua indexes have to start at 1? :( - else - numKey = tonumber(num) - end - - if(numKey == nil) then return end - - if gearSlots[numKey] ~= "empty" then - toolSwitcher(numKey) - end +function mouseOverTab(button) + assert(button) + assert(button:IsA("TextButton")) + + if button.Selected then return end + + button.BackgroundColor3 = Color3.new(39/255,39/255,39/255) end +function newTabClicked(tabName) + assert(tabName) + tabName = string.lower(tabName) + currentTab = tabName + + updateTabGui(tabName) + tabClickedEvent:Fire(tabName) + resetSearch() +end -enlargeButton = function(button) - if button.Size.Y.Scale > 1 then return end - if not button.Parent then return end - if not button.Selected then return end +function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i] ~= button then - normalizeButton(gearSlots[i]) - end +function splitByWhitespace(text) + if type(text) ~= "string" then return nil end + + local terms = {} + for token in string.gmatch(text, "[^%s]+") do + if string.len(token) > 0 then + table.insert(terms,token) + end end + return terms +end - if not enlargeOverride then - waitingOnEnlarge = button +function resetSearchBoxGui() + resetButton.Visible = false + searchBox.Text = searchDefaultText +end + +function doSearch() + local searchText = searchBox.Text + if searchText == "" then + resetSearch() return end - - if button:IsA("ImageButton") or button:IsA("TextButton") then - button.ZIndex = 2 - local centerizeX = -(buttonSizeEnlarge.X.Scale - button.Size.X.Scale)/2 - local centerizeY = -(buttonSizeEnlarge.Y.Scale - button.Size.Y.Scale)/2 - button:TweenSizeAndPosition(buttonSizeEnlarge, - UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/5,enlargeOverride) - end + searchText = trim(searchText) + resetButton.Visible = true + termTable = splitByWhitespace(searchText) + searchRequestedEvent:Fire(searchText) -- todo: replace this with termtable when table passing is possible end -normalizeAllButtons = function() - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i] ~= button then - normalizeButton(gearSlots[i],0.1) - end - end +function resetSearch() + resetSearchBoxGui() + searchRequestedEvent:Fire() end - -normalizeButton = function(button, speed) - if not button then return end - if button.Size.Y.Scale <= 1 then return end - if button.Selected then return end - if not button.Parent then return end - - local moveSpeed = speed - if moveSpeed == nil or type(moveSpeed) ~= "number" then moveSpeed = guiTweenSpeed/5 end - - if button:IsA("ImageButton") or button:IsA("TextButton") then - button.ZIndex = 1 - local inverseEnlarge = 1/enlargeFactor - local centerizeX = -(buttonSizeNormal.X.Scale - button.Size.X.Scale)/2 - local centerizeY = -(buttonSizeNormal.Y.Scale - button.Size.Y.Scale)/2 - button:TweenSizeAndPosition(buttonSizeNormal, - UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,moveSpeed,enlargeOverride) - end +local backpackReady = function() + readyForNextEvent = true end -waitForDebounce = function() - if debounce.Value then - debounce.Changed:wait() - end +--------------------------- End Internal Functions ------------------------------------- + + +------------------------------ Public Functions Setup ------------------------------------- +createPublicFunction("CloseBackpack", hideBackpack) +createPublicFunction("BackpackReady", backpackReady) +------------------------------ End Public Functions Setup --------------------------------- + + +------------------------ Connections/Script Main ------------------------------------------- + +inventoryButton.MouseButton1Click:connect(function() newTabClicked("gear") end) +inventoryButton.MouseEnter:connect(function() mouseOverTab(inventoryButton) end) +inventoryButton.MouseLeave:connect(function() mouseLeaveTab(inventoryButton) end) + +if game.CoreGui.Version >= 8 then + wardrobeButton.MouseButton1Click:connect(function() newTabClicked("wardrobe") end) + wardrobeButton.MouseEnter:connect(function() mouseOverTab(wardrobeButton) end) + wardrobeButton.MouseLeave:connect(function() mouseLeaveTab(wardrobeButton) end) end -function pointInRectangle(point,rectTopLeft,rectSize) - if point.x > rectTopLeft.x and point.x < (rectTopLeft.x + rectSize.x) then - if point.y > rectTopLeft.y and point.y < (rectTopLeft.y + rectSize.y) then - return true - end - end - return false -end +closeButton.MouseButton1Click:connect(closeBackpack) -function swapGear(gearClone,toFrame) - local toFrameChildren = toFrame:GetChildren() - if #toFrameChildren == 1 then - if toFrameChildren[1]:FindFirstChild("SlotNumber") then - - local toSlot = tonumber(toFrameChildren[1].SlotNumber.Text) - local gearCloneSlot = tonumber(gearClone.SlotNumber.Text) - if toSlot == 0 then toSlot = 10 end - if gearCloneSlot == 0 then gearCloneSlot = 10 end - - gearSlots[toSlot] = gearClone - gearSlots[gearCloneSlot] = toFrameChildren[1] - - toFrameChildren[1].SlotNumber.Text = gearClone.SlotNumber.Text - toFrameChildren[1].SlotNumberDownShadow.Text = gearClone.SlotNumber.Text - toFrameChildren[1].SlotNumberUpShadow.Text = gearClone.SlotNumber.Text - - local subString = string.sub(toFrame.Name,5) - gearClone.SlotNumber.Text = subString - gearClone.SlotNumberDownShadow.Text = subString - gearClone.SlotNumberUpShadow.Text = subString - - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) - toFrameChildren[1].Position = UDim2.new(toFrameChildren[1].Position.X.Scale,0,toFrameChildren[1].Position.Y.Scale,0) - - toFrameChildren[1].Parent = gearClone.Parent - gearClone.Parent = toFrame - end - else - local slotNum = tonumber(gearClone.SlotNumber.Text) - if slotNum == 0 then slotNum = 10 end - gearSlots[slotNum] = "empty" -- reset this gear slot - - local subString = string.sub(toFrame.Name,5) - gearClone.SlotNumber.Text = subString - gearClone.SlotNumberDownShadow.Text = subString - gearClone.SlotNumberUpShadow.Text = subString - - local toSlotNum = tonumber(gearClone.SlotNumber.Text) - if toSlotNum == 0 then toSlotNum = 10 end - gearSlots[toSlotNum] = gearClone - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) - gearClone.Parent = toFrame - end -end - -function resolveDrag(gearClone,x,y) - local mousePoint = Vector2.new(x,y) - - local frame = gearClone.Parent - local frames = frame.Parent:GetChildren() - - for i = 1, #frames do - if frames[i]:IsA("Frame") then - if pointInRectangle(mousePoint, frames[i].AbsolutePosition,frames[i].AbsoluteSize) then - swapGear(gearClone,frames[i]) - --saveGearPositions() - return true - end - end - end - - if x < frame.AbsolutePosition.x or x > ( frame.AbsolutePosition.x + frame.AbsoluteSize.x ) then - reorganizeLoadout(gearClone,false) - --saveGearPositions() - return false - elseif y < frame.AbsolutePosition.y or y > ( frame.AbsolutePosition.y + frame.AbsoluteSize.y ) then - reorganizeLoadout(gearClone,false) - --saveGearPositions() - return false - else - if dragBeginPos then gearClone.Position = dragBeginPos end - return -1 - end -end - -function saveGearPositions() - if not canSaveLoadout then return end - - lastLoadout = {} - for i = 1, #gearSlots do - if gearSlots[i] and gearSlots[i] ~= "empty" then - lastLoadout[i] = gearSlots[i] - end - end -end - -function unequipAllItems(dontEquipThis) - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value ~= dontEquipThis then - if gearSlots[i].GearReference.Value:IsA("HopperBin") then - gearSlots[i].GearReference.Value:Disable() - elseif gearSlots[i].GearReference.Value:IsA("Tool") then - gearSlots[i].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack - end - gearSlots[i].Selected = false - end - end -end - -function showToolTip(button, tip) - if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then - button.ToolTipLabel.Text = tostring(tip) - local xSize = button.ToolTipLabel.TextBounds.X + 6 - button.ToolTipLabel.Size = UDim2.new(0,xSize,0,20) - button.ToolTipLabel.Position = UDim2.new(0.5,-xSize/2,0,-30) - button.ToolTipLabel.Visible = true - end -end - -function hideToolTip(button, tip) - if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then - button.ToolTipLabel.Visible = false - end -end - -local addingPlayerChild = function(child, equipped, addToSlot, inventoryGearButton) - waitForDebounce() - debounce.Value = true - - if not child:IsA("Tool") then - if not child:IsA("HopperBin") then - debounce.Value = false - return -- we don't care about anything besides tools (sigh...) - end - end - - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then -- we already have gear, do nothing - debounce.Value = false - return - end - end - end - - - local gearClone = currentLoadout.TempSlot:clone() - gearClone.Name = child.Name - gearClone.GearImage.Image = child.TextureId - if gearClone.GearImage.Image == "" then - gearClone.GearText.Text = child.Name - end - gearClone.GearReference.Value = child - - gearClone.MouseEnter:connect(function() - pcall(function() if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then - showToolTip(gearClone, gearClone.GearReference.Value.ToolTip) - end - end) - end) - - gearClone.MouseLeave:connect(function() - pcall(function() if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then - hideToolTip(gearClone, gearClone.GearReference.Value.ToolTip) - end - end) - end) - - gearClone.RobloxLocked = true - - local slotToMod = -1 - - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - slotToMod = i - break - end - end - else - slotToMod = addToSlot - end - - if slotToMod == - 1 then -- No available slot to add in! - debounce.Value = false - return - end - - local slotNum = slotToMod % 10 - local parent = currentLoadout:FindFirstChild("Slot"..tostring(slotNum)) - gearClone.Parent = parent - - if inventoryGearButton then - local absolutePositionFinal = inventoryGearButton.AbsolutePosition - local currentAbsolutePosition = gearClone.AbsolutePosition - local diff = absolutePositionFinal - currentAbsolutePosition - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,diff.x,gearClone.Position.Y.Scale,diff.y) - gearClone.ZIndex = 4 - end - - if addToSlot then - reorganizeLoadout(gearClone, true, equipped, addToSlot) - else - reorganizeLoadout(gearClone, true) - end - - if gearClone.Parent == nil then debounce.Value = false return end -- couldn't fit in (hopper is full!) - - if equipped then - gearClone.Selected = true - unequipAllItems(child) - delay(guiTweenSpeed + 0.01,function() -- if our gear is equipped, we will want to enlarge it when done moving - if gearClone:FindFirstChild("GearReference") and ( (gearClone.GearReference.Value:IsA("Tool") and gearClone.GearReference.Value.Parent == player.Character) or - (gearClone.GearReference.Value:IsA("HopperBin") and gearClone.GearReference.Value.Active == true) ) then - enlargeButton(gearClone) - end - end) - end - - local dragBeginPos = nil - local clickCon, buttonDeleteCon, mouseEnterCon, mouseLeaveCon, dragStop, dragBegin = nil - clickCon = gearClone.MouseButton1Click:connect(function() if not gearClone.Draggable then activateGear(gearClone.SlotNumber.Text) end end) - mouseEnterCon = gearClone.MouseEnter:connect(function() - if guiBackpack.Visible then - gearClone.Draggable = true - end - end) - dragBegin = gearClone.DragBegin:connect(function(pos) - dragBeginPos = pos - gearClone.ZIndex = 7 - local children = gearClone:GetChildren() - for i = 1, #children do - if children[i]:IsA("TextLabel") then - if string.find(children[i].Name,"Shadow") then - children[i].ZIndex = 8 - else - children[i].ZIndex = 9 - end - elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then - children[i].ZIndex = 7 - end - end - end) - dragStop = gearClone.DragStopped:connect(function(x,y) - if gearClone.Selected then - gearClone.ZIndex = 2 - else - gearClone.ZIndex = 1 - end - local children = gearClone:GetChildren() - for i = 1, #children do - if children[i]:IsA("TextLabel") then - if string.find(children[i].Name,"Shadow") then - children[i].ZIndex = 3 - else - children[i].ZIndex = 4 - end - elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then - children[i].ZIndex = 2 - end - end - resolveDrag(gearClone,x,y) - end) - mouseLeaveCon = gearClone.MouseLeave:connect(function() - gearClone.Draggable = false - end) - buttonDeleteCon = gearClone.AncestryChanged:connect(function() - if gearClone.Parent and gearClone.Parent.Parent == currentLoadout then return end - if clickCon then clickCon:disconnect() end - if buttonDeleteCon then buttonDeleteCon:disconnect() end - if mouseEnterCon then mouseEnterCon:disconnect() end - if mouseLeaveCon then mouseLeaveCon:disconnect() end - if dragStop then dragStop:disconnect() end - if dragBegin then dragBegin:disconnect() end - end) -- this probably isn't necessary since objects are being deleted (probably), but this might still leak just in case - - local childCon = nil - local childChangeCon = nil - childCon = child.AncestryChanged:connect(function(newChild,parent) - if not checkToolAncestry(newChild,parent) then - if childCon then childCon:disconnect() end - if childChangeCon then childChangeCon:disconnect() end - removeFromInventory(child) - elseif parent == game.Players.LocalPlayer.Backpack then - normalizeButton(gearClone) - end - end) - - childChangeCon = child.Changed:connect(function(prop) - if prop == "Name" then - if gearClone and gearClone.GearImage.Image == "" then - gearClone.GearText.Text = child.Name - end - elseif prop == "Active" then - if child and child:IsA("HopperBin") then - if not child.Active then - gearClone.Selected = false - normalizeButton(gearClone) - end - end - end - end) - - debounce.Value = false - -end - -function addToInventory(child) - if not child:IsA("Tool") or not child:IsA("HopperBin") then return end - - local slot = nil - for i = 1, #inventory do - if inventory[i] and inventory[i] == child then return end - if not inventory[i] then slot = i end - end - if slot then - inventory[slot] = child - elseif #inventory < 1 then - inventory[1] = child - else - inventory[#inventory + 1] = child - end -end - -function removeFromInventory(child) - for i = 1, #inventory do - if inventory[i] == child then - table.remove(inventory,i) - inventory[i] = nil - end - end -end - --- these next two functions are used for safe guarding --- when we are waiting for character to come back after dying -function activateLoadout() - currentLoadout.Visible = true -end - -function deactivateLoadout() - currentLoadout.Visible = false -end - -function setupBackpackListener() - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end - backpackChildCon = player.Backpack.ChildAdded:connect(function(child) - addingPlayerChild(child) - addToInventory(child) - - -- now store info in case of death - --saveGearPositions() - end) -end - -function playerCharacterChildAdded(child) - addingPlayerChild(child,true) - addToInventory(child) - - -- now store info in case of death - --saveGearPositions() -end --- End Functions - - - - - - --- Begin Script -wait() -- let stuff initialize incase this is first heartbeat... - -waitForChild(player,"Backpack") -waitForProperty(player,"Character") -local backpackChildren = player.Backpack:GetChildren() -local size = math.min(10,#backpackChildren) -for i = 1, size do - addingPlayerChild(backpackChildren[i],false) - - -- now store info in case of death - --saveGearPositions() -end -setupBackpackListener() - -waitForProperty(player,"Character") -for i,v in ipairs(player.Character:GetChildren()) do - playerCharacterChildAdded(v) -end -characterChildAddedCon = player.Character.ChildAdded:connect(function(child) playerCharacterChildAdded(child) end) - -waitForChild(player.Character,"Humanoid") -humanoidDiedCon = player.Character.Humanoid.Died:connect(function() - if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end - deactivateLoadout() - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end -end) - -player.CharacterRemoving:connect(function() - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" then - gearSlots[i].Parent = nil - gearSlots[i] = "empty" - end +screen.Changed:connect(function(prop) + if prop == "AbsoluteSize" then + resizeEvent:Fire(screen.AbsoluteSize) end end) -player.CharacterAdded:connect(function() - --canSaveLoadout = false -- we need to save loadout table until we check it out - - waitForProperty(game.Players,"LocalPlayer") - player = game.Players.LocalPlayer -- make sure we are still looking at the correct character - waitForChild(player,"Backpack") - - --[[local loadoutCount = 0 - - local backpackChildren = player.Backpack:GetChildren() - -- Make sure we put gear back in where we last had them - for i = 1, #backpackChildren do - for pos,v in pairs(lastLoadout) do - if v["Name"] and v.Name == backpackChildren[i].Name then - addingPlayerChild(backpackChildren[i],false,pos) - lastLoadout[pos] = nil - loadoutCount = loadoutCount + 1 - break - end - end - if loadoutCount >= 10 then -- we've accounted for all slots, no need to go thru rest of gear - break - end - end]] - --canSaveLoadout = true -- used loadout table, allow script to edit this again - - local backpackChildren = player.Backpack:GetChildren() - local size = math.min(10,#backpackChildren) - for i = 1, size do - addingPlayerChild(backpackChildren[i],false) - end - - setupBackpackListener() - - if characterChildAddedCon then - characterChildAddedCon:disconnect() - characterChildAddedCon = nil - end - - characterChildAddedCon = - player.Character.ChildAdded:connect(function(child) - addingPlayerChild(child,true) - - -- now store info in case of death - -- saveGearPositions() - end) - - waitForChild(player.Character,"Humanoid") - humanoidDiedCon = - player.Character.Humanoid.Died:connect(function() - deactivateLoadout() - - if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end - end) - activateLoadout() -end) - -waitForChild(guiBackpack,"SwapSlot") -guiBackpack.SwapSlot.Changed:connect(function() - if guiBackpack.SwapSlot.Value then - local swapSlot = guiBackpack.SwapSlot - local pos = swapSlot.Slot.Value - if pos == 0 then pos = 10 end - if gearSlots[pos] then - reorganizeLoadout(gearSlots[pos],false) - end - if swapSlot.GearButton.Value then - addingPlayerChild(swapSlot.GearButton.Value.GearReference.Value,false,pos) - - -- now store info in case of death - --saveGearPositions() - end - guiBackpack.SwapSlot.Value = false +-- GuiService key setup +game:GetService("GuiService"):AddKey(tilde) +game:GetService("GuiService"):AddKey(backquote) +game:GetService("GuiService").KeyPressed:connect(function(key) + if not active then return end + if key == tilde or key == backquote then + toggleBackpack() end end) +backpackButton.MouseButton1Click:connect(function() + if not active then return end + toggleBackpack() +end) -game:GetService("GuiService").KeyPressed:connect(function(key) activateGear(key) end) +if game.Players.LocalPlayer["Character"] then + activateBackpack() +end +game.Players.LocalPlayer.CharacterAdded:connect(activateBackpack) + +-- search functions +searchBox.FocusLost:connect(function(enterPressed) + if enterPressed or searchBox.Text ~= "" then + doSearch() + elseif searchBox.Text == "" then + resetSearch() + end +end) +searchButton.MouseButton1Click:connect(doSearch) +resetButton.MouseButton1Click:connect(resetSearch) + +backpackButton.Visible = true diff --git a/public/asset/14 b/public/asset/14 index 91731d8..2fca69e 100644 --- a/public/asset/14 +++ b/public/asset/14 @@ -1,726 +1,402 @@ -%14% -if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client - +%14& -- A couple of necessary functions local function waitForChild(instance, name) + assert(instance) + assert(name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end return instance:FindFirstChild(name) end local function waitForProperty(instance, property) + assert(instance) + assert(property) while not instance[property] do instance.Changed:wait() end end -local currentLoadout = script.Parent -local StaticTabName = "gear" - -local robloxGui = game:GetService("CoreGui"):FindFirstChild("RobloxGui") -assert(robloxGui) -waitForChild(robloxGui,"CurrentLoadout") -waitForChild(robloxGui.CurrentLoadout,"TempSlot") -waitForChild(robloxGui.CurrentLoadout.TempSlot,"SlotNumber") - - ---- Begin Locals waitForChild(game,"Players") waitForProperty(game.Players,"LocalPlayer") local player = game.Players.LocalPlayer -waitForChild(game, "LocalBackpack") -game.LocalBackpack:SetOldSchoolBackpack(false) +local RbxGui, msg = LoadLibrary("RbxGui") +if not RbxGui then print("could not find RbxGui!") return end -waitForChild(currentLoadout.Parent,"Backpack") -local guiBackpack = currentLoadout.Parent.Backpack +--- Begin Locals +local StaticTabName = "gear" -local backpackManager = waitForChild(guiBackpack,"CoreScripts/BackpackScripts/BackpackManager") +local backpack = script.Parent +local screen = script.Parent.Parent + +local backpackItems = {} +local buttons = {} + +local debounce = false +local browsingMenu = false + +local mouseEnterCons = {} +local mouseClickCons = {} + +local characterChildAddedCon = nil +local characterChildRemovedCon = nil +local backpackAddCon = nil + +local playerBackpack = waitForChild(player,"Backpack") + +waitForChild(backpack,"Tabs") + +waitForChild(backpack,"Gear") +local gearPreview = waitForChild(backpack.Gear,"GearPreview") + +local scroller = waitForChild(backpack.Gear,"GearGridScrollingArea") + +local currentLoadout = waitForChild(backpack.Parent,"CurrentLoadout") + +local grid = waitForChild(backpack.Gear,"GearGrid") +local gearButton = waitForChild(grid,"GearButton") + +local swapSlot = waitForChild(script.Parent,"SwapSlot") + +local backpackManager = waitForChild(script.Parent,"CoreScripts/BackpackScripts/BackpackManager") local backpackOpenEvent = waitForChild(backpackManager,"BackpackOpenEvent") local backpackCloseEvent = waitForChild(backpackManager,"BackpackCloseEvent") local tabClickedEvent = waitForChild(backpackManager,"TabClickedEvent") local resizeEvent = waitForChild(backpackManager,"ResizeEvent") +local searchRequestedEvent = waitForChild(backpackManager,"SearchRequestedEvent") +local tellBackpackReadyFunc = waitForChild(backpackManager,"BackpackReady") -local inGearTab = true +-- creating scroll bar early as to make sure items get placed correctly +local scrollFrame, scrollUp, scrollDown, recalculateScroll = RbxGui.CreateScrollingFrame(nil,"grid") -local maxNumLoadoutItems = 10 +scrollFrame.Position = UDim2.new(0,0,0,30) +scrollFrame.Size = UDim2.new(1,0,1,-30) +scrollFrame.Parent = backpack.Gear.GearGrid -local characterChildAddedCon = nil -local backpackChildCon = nil +local scrollBar = Instance.new("Frame") +scrollBar.Name = "ScrollBar" +scrollBar.BackgroundTransparency = 0.9 +scrollBar.BackgroundColor3 = Color3.new(1,1,1) +scrollBar.BorderSizePixel = 0 +scrollBar.Size = UDim2.new(0, 17, 1, -36) +scrollBar.Position = UDim2.new(0,0,0,18) +scrollBar.Parent = scroller -local debounce = false +scrollDown.Position = UDim2.new(0,0,1,-17) -local enlargeFactor = 1.18 -local buttonSizeEnlarge = UDim2.new(1 * enlargeFactor,0,1 * enlargeFactor,0) -local buttonSizeNormal = UDim2.new(1,0,1,0) -local enlargeOverride = true -local guiTweenSpeed = 0.5 +scrollUp.Parent = scroller +scrollDown.Parent = scroller -local inventory = {} +local scrollFrameLoadout, scrollUpLoadout, scrollDownLoadout, recalculateScrollLoadout = RbxGui.CreateScrollingFrame() -for i = 0, 9 do - game:GetService("GuiService"):AddKey(tostring(i)) -- register our keys -end +scrollFrameLoadout.Position = UDim2.new(0,0,0,0) +scrollFrameLoadout.Size = UDim2.new(1,0,1,0) +scrollFrameLoadout.Parent = backpack.Gear.GearLoadouts.LoadoutsList -local gearSlots = {} -for i = 1, maxNumLoadoutItems do - gearSlots[i] = "empty" -end ---- End Locals +local LoadoutButton = Instance.new("TextButton") +LoadoutButton.RobloxLocked = true +LoadoutButton.Name = "LoadoutButton" +LoadoutButton.Font = Enum.Font.ArialBold +LoadoutButton.FontSize = Enum.FontSize.Size14 +LoadoutButton.Position = UDim2.new(0,0,0,0) +LoadoutButton.Size = UDim2.new(1,0,0,32) +LoadoutButton.Style = Enum.ButtonStyle.RobloxButton +LoadoutButton.Text = "Loadout #1" +LoadoutButton.TextColor3 = Color3.new(1,1,1) +LoadoutButton.Parent = scrollFrameLoadout +local LoadoutButtonTwo = LoadoutButton:clone() +LoadoutButtonTwo.Text = "Loadout #2" +LoadoutButtonTwo.Parent = scrollFrameLoadout +local LoadoutButtonThree = LoadoutButton:clone() +LoadoutButtonThree.Text = "Loadout #3" +LoadoutButtonThree.Parent = scrollFrameLoadout +local LoadoutButtonFour = LoadoutButton:clone() +LoadoutButtonFour.Text = "Loadout #4" +LoadoutButtonFour.Parent = scrollFrameLoadout +local scrollBarLoadout = Instance.new("Frame") +scrollBarLoadout.Name = "ScrollBarLoadout" +scrollBarLoadout.BackgroundTransparency = 0.9 +scrollBarLoadout.BackgroundColor3 = Color3.new(1,1,1) +scrollBarLoadout.BorderSizePixel = 0 +scrollBarLoadout.Size = UDim2.new(0, 17, 1, -36) +scrollBarLoadout.Position = UDim2.new(0,0,0,18) +scrollBarLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea + +scrollDownLoadout.Position = UDim2.new(0,0,1,-17) + +scrollUpLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea +scrollDownLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea -- Begin Functions -local function kill(prop,con,gear) - if con then con:disconnect() end - if prop == true and gear then - reorganizeLoadout(gear,false) - end -end - -function characterInWorkspace() - if game.Players["LocalPlayer"] then - if game.Players.LocalPlayer["Character"] then - if game.Players.LocalPlayer.Character ~= nil then - if game.Players.LocalPlayer.Character.Parent ~= nil then - return true - end - end - end - end - - return false -end - -function removeGear(gear) - local emptySlot = nil - for i = 1, #gearSlots do - if gearSlots[i] == gear and gear.Parent ~= nil then - emptySlot = i +function removeFromMap(map,object) + for i = 1, #map do + if map[i] == object then + table.remove(map,i) break end end - if emptySlot then - if gearSlots[emptySlot].GearReference.Value then - if gearSlots[emptySlot].GearReference.Value.Parent == game.Players.LocalPlayer.Character then -- if we currently have this equipped, unequip it - gearSlots[emptySlot].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack - end - - if gearSlots[emptySlot].GearReference.Value:IsA("HopperBin") and gearSlots[emptySlot].GearReference.Value.Active then -- this is an active hopperbin - gearSlots[emptySlot].GearReference.Value:Disable() - gearSlots[emptySlot].GearReference.Value.Active = false - end - end - - gearSlots[emptySlot] = "empty" - - local centerizeX = gear.Size.X.Scale/2 - local centerizeY = gear.Size.Y.Scale/2 - gear:TweenSizeAndPosition(UDim2.new(0,0,0,0), - UDim2.new(gear.Position.X.Scale + centerizeX,gear.Position.X.Offset,gear.Position.Y.Scale + centerizeY,gear.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/4,true) - delay(guiTweenSpeed/2, - function() - gear:remove() - end) - end end -function insertGear(gear, addToSlot) - local pos = nil - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - pos = i - break - end - end +function robloxLock(instance) + instance.RobloxLocked = true + children = instance:GetChildren() + if children then + for i, child in ipairs(children) do + robloxLock(child) + end + end +end - if pos == 1 and gearSlots[1] ~= "empty" then gear:remove() return end -- we are currently full, can't add in +function resize() + local size = 0 + if gearPreview.AbsoluteSize.Y > gearPreview.AbsoluteSize.X then + size = gearPreview.AbsoluteSize.X * 0.75 else - pos = addToSlot - -- push all gear down one slot - local start = 1 - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - start = i - break - end - end - for i = start, pos + 1, -1 do - gearSlots[i] = gearSlots[i - 1] - if i == 10 then - gearSlots[i].SlotNumber.Text = "0" - gearSlots[i].SlotNumberDownShadow.Text = "0" - gearSlots[i].SlotNumberUpShadow.Text = "0" - else - gearSlots[i].SlotNumber.Text = i - gearSlots[i].SlotNumberDownShadow.Text = i - gearSlots[i].SlotNumberUpShadow.Text = i - end - end + size = gearPreview.AbsoluteSize.Y * 0.75 end - gearSlots[pos] = gear - if pos ~= maxNumLoadoutItems then - if(type(tostring(pos)) == "string") then - local posString = tostring(pos) - gear.SlotNumber.Text = posString - gear.SlotNumberDownShadow.Text = posString - gear.SlotNumberUpShadow.Text = posString - end - else -- tenth gear doesn't follow mathematical pattern :( - gear.SlotNumber.Text = "0" - gear.SlotNumberDownShadow.Text = "0" - gear.SlotNumberUpShadow.Text = "0" - end - gear.Visible = true - - local con = nil - con = gear.Kill.Changed:connect(function(prop) kill(prop,con,gear) end) + waitForChild(gearPreview,"GearImage") + gearPreview.GearImage.Size = UDim2.new(0,size,0,size) + gearPreview.GearImage.Position = UDim2.new(0,gearPreview.AbsoluteSize.X/2 - size/2,0.75,-size) + + resizeGrid() end - -function reorganizeLoadout(gear, inserting, equipped, addToSlot) - if inserting then -- add in gear - insertGear(gear, addToSlot) - else - removeGear(gear) +function addToGrid(child) + if not child:IsA("Tool") then + if not child:IsA("HopperBin") then + return + end + end + if child:FindFirstChild("RobloxBuildTool") then return end + + for i,v in pairs(backpackItems) do -- check to see if we already have this gear registered + if v == child then return end end - if gear ~= "empty" then gear.ZIndex = 1 end -end -function checkToolAncestry(child,parent) - if child:FindFirstChild("RobloxBuildTool") then return end -- don't show roblox build tools - if child:IsA("Tool") or child:IsA("HopperBin") then - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then - if parent == nil then - gearSlots[i].Kill.Value = true - return false - elseif child.Parent == player.Character then - gearSlots[i].Selected = true - return true - elseif child.Parent == player.Backpack then - if child:IsA("Tool") or child:IsA("HopperBin") then gearSlots[i].Selected = false end - return true - else - gearSlots[i].Kill.Value = true - return false + table.insert(backpackItems,child) + + local changeCon = child.Changed:connect(function(prop) + if prop == "Name" then + if buttons[child] then + if buttons[child].Image == "" then + buttons[child].GearText.Text = child.Name end - return true end end - end -end - -function removeAllEquippedGear(physGear) - local stuff = player.Character:GetChildren() - for i = 1, #stuff do - if ( stuff[i]:IsA("Tool") or stuff[i]:IsA("HopperBin") ) and stuff[i] ~= physGear then - if stuff[i]:IsA("Tool") then stuff[i].Parent = player.Backpack end - if stuff[i]:IsA("HopperBin") then - stuff[i]:Disable() + end) + local ancestryCon = nil + ancestryCon = child.AncestryChanged:connect(function(theChild,theParent) + local thisObject = nil + for k,v in pairs(backpackItems) do + if v == child then + thisObject = v + break end end - end -end - -function hopperBinSwitcher(numKey, physGear) - if not physGear then return end - - physGear:ToggleSelect() - - if gearSlots[numKey] == "empty" then return end - - if not physGear.Active then - gearSlots[numKey].Selected = false - normalizeButton(gearSlots[numKey]) - else - gearSlots[numKey].Selected = true - enlargeButton(gearSlots[numKey]) - end -end - -function toolSwitcher(numKey) - - if not gearSlots[numKey] then return end - local physGear = gearSlots[numKey].GearReference.Value - if physGear == nil then return end - - removeAllEquippedGear(physGear) -- we don't remove this gear, as then we get a double switcheroo - - local key = numKey - if numKey == 0 then key = 10 end - - for i = 1, #gearSlots do - if gearSlots[i] and gearSlots[i] ~= "empty" and i ~= key then - normalizeButton(gearSlots[i]) - gearSlots[i].Selected = false - if gearSlots[i].GearReference and gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value:IsA("HopperBin") and gearSlots[i].GearReference.Value.Active then - gearSlots[i].GearReference.Value:ToggleSelect() - end - end - end - - if physGear:IsA("HopperBin") then - hopperBinSwitcher(numKey,physGear) - else - if physGear.Parent == player.Character then - physGear.Parent = player.Backpack - - if gearSlots[numKey] ~= "empty" then - gearSlots[numKey].Selected = false - normalizeButton(gearSlots[numKey]) - end - else - --player.Character.Humanoid:EquipTool(physGear) + + waitForProperty(player,"Character") + waitForChild(player,"Backpack") + if (child.Parent ~= player.Backpack and child.Parent ~= player.Character) then + if ancestryCon then ancestryCon:disconnect() end + if changeCon then changeCon:disconnect() end - physGear.Parent = player.Character - gearSlots[numKey].Selected = true + for k,v in pairs(backpackItems) do + if v == thisObject then + if mouseEnterCons[buttons[v]] then mouseEnterCons[buttons[v]]:disconnect() end + if mouseClickCons[buttons[v]] then mouseClickCons[buttons[v]]:disconnect() end + buttons[v].Parent = nil + buttons[v] = nil + break + end + end - enlargeButton(gearSlots[numKey]) + removeFromMap(backpackItems,thisObject) + + resizeGrid() + else + resizeGrid() + end + updateGridActive() + end) + resizeGrid() +end + +function buttonClick(button) + if button:FindFirstChild("UnequipContextMenu") and not button.Active then + button.UnequipContextMenu.Visible = true + browsingMenu = true + end +end + +function previewGear(button) + if not browsingMenu then + gearPreview.GearImage.Image = button.Image + gearPreview.GearStats.GearName.Text = button.GearReference.Value.Name + end +end + +function findEmptySlot() + local smallestNum = nil + local loadout = currentLoadout:GetChildren() + for i = 1, #loadout do + if loadout[i]:IsA("Frame") and #loadout[i]:GetChildren() <= 0 then + local frameNum = tonumber(string.sub(loadout[i].Name,5)) + if frameNum == 0 then frameNum = 10 end + if not smallestNum or (smallestNum > frameNum) then + smallestNum = frameNum + end end end + if smallestNum == 10 then smallestNum = 0 end + return smallestNum end - -function activateGear(num) - local numKey = nil - if num == "0" then - numKey = 10 -- why do lua indexes have to start at 1? :( - else - numKey = tonumber(num) - end - - if(numKey == nil) then return end - - if gearSlots[numKey] ~= "empty" then - toolSwitcher(numKey) - end -end - - -enlargeButton = function(button) - if button.Size.Y.Scale > 1 then return end - if not button.Parent then return end - if not button.Selected then return end - - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i] ~= button then - normalizeButton(gearSlots[i]) - end - end - - if not enlargeOverride then - return - end - - if button:IsA("ImageButton") or button:IsA("TextButton") then - button.ZIndex = 2 - local centerizeX = -(buttonSizeEnlarge.X.Scale - button.Size.X.Scale)/2 - local centerizeY = -(buttonSizeEnlarge.Y.Scale - button.Size.Y.Scale)/2 - button:TweenSizeAndPosition(buttonSizeEnlarge, - UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/5,enlargeOverride) - end -end - -normalizeAllButtons = function() - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i] ~= button then - normalizeButton(gearSlots[i],0.1) - end - end -end - - -normalizeButton = function(button, speed) - if not button then return end - if button.Size.Y.Scale <= 1 then return end - if button.Selected then return end - if not button.Parent then return end - - local moveSpeed = speed - if moveSpeed == nil or type(moveSpeed) ~= "number" then moveSpeed = guiTweenSpeed/5 end - - if button:IsA("ImageButton") or button:IsA("TextButton") then - button.ZIndex = 1 - local inverseEnlarge = 1/enlargeFactor - local centerizeX = -(buttonSizeNormal.X.Scale - button.Size.X.Scale)/2 - local centerizeY = -(buttonSizeNormal.Y.Scale - button.Size.Y.Scale)/2 - button:TweenSizeAndPosition(buttonSizeNormal, - UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), - Enum.EasingDirection.Out, Enum.EasingStyle.Quad,moveSpeed,enlargeOverride) - end -end - -local waitForDebounce = function() - while debounce do - wait() - end -end - -function pointInRectangle(point,rectTopLeft,rectSize) - if point.x > rectTopLeft.x and point.x < (rectTopLeft.x + rectSize.x) then - if point.y > rectTopLeft.y and point.y < (rectTopLeft.y + rectSize.y) then - return true +function checkForSwap(button,x,y) + local loadoutChildren = currentLoadout:GetChildren() + for i = 1, #loadoutChildren do + if loadoutChildren[i]:IsA("Frame") and string.find(loadoutChildren[i].Name,"Slot") then + if x >= loadoutChildren[i].AbsolutePosition.x and x <= (loadoutChildren[i].AbsolutePosition.x + loadoutChildren[i].AbsoluteSize.x) then + if y >= loadoutChildren[i].AbsolutePosition.y and y <= (loadoutChildren[i].AbsolutePosition.y + loadoutChildren[i].AbsoluteSize.y) then + local slot = tonumber(string.sub(loadoutChildren[i].Name,5)) + swapGearSlot(slot,button) + return true + end + end end end return false end -function swapGear(gearClone,toFrame) - local toFrameChildren = toFrame:GetChildren() - if #toFrameChildren == 1 then - if toFrameChildren[1]:FindFirstChild("SlotNumber") then - - local toSlot = tonumber(toFrameChildren[1].SlotNumber.Text) - local gearCloneSlot = tonumber(gearClone.SlotNumber.Text) - if toSlot == 0 then toSlot = 10 end - if gearCloneSlot == 0 then gearCloneSlot = 10 end - - gearSlots[toSlot] = gearClone - gearSlots[gearCloneSlot] = toFrameChildren[1] - - toFrameChildren[1].SlotNumber.Text = gearClone.SlotNumber.Text - toFrameChildren[1].SlotNumberDownShadow.Text = gearClone.SlotNumber.Text - toFrameChildren[1].SlotNumberUpShadow.Text = gearClone.SlotNumber.Text - - local subString = string.sub(toFrame.Name,5) - gearClone.SlotNumber.Text = subString - gearClone.SlotNumberDownShadow.Text = subString - gearClone.SlotNumberUpShadow.Text = subString - - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) - toFrameChildren[1].Position = UDim2.new(toFrameChildren[1].Position.X.Scale,0,toFrameChildren[1].Position.Y.Scale,0) - - toFrameChildren[1].Parent = gearClone.Parent - gearClone.Parent = toFrame - end - else - local slotNum = tonumber(gearClone.SlotNumber.Text) - if slotNum == 0 then slotNum = 10 end - gearSlots[slotNum] = "empty" -- reset this gear slot - - local subString = string.sub(toFrame.Name,5) - gearClone.SlotNumber.Text = subString - gearClone.SlotNumberDownShadow.Text = subString - gearClone.SlotNumberUpShadow.Text = subString - - local toSlotNum = tonumber(gearClone.SlotNumber.Text) - if toSlotNum == 0 then toSlotNum = 10 end - gearSlots[toSlotNum] = gearClone - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) - gearClone.Parent = toFrame - end -end - -function resolveDrag(gearClone,x,y) - local mousePoint = Vector2.new(x,y) - - local frame = gearClone.Parent - local frames = frame.Parent:GetChildren() - - for i = 1, #frames do - if frames[i]:IsA("Frame") then - if pointInRectangle(mousePoint, frames[i].AbsolutePosition,frames[i].AbsoluteSize) then - swapGear(gearClone,frames[i]) - return true - end - end - end - - if x < frame.AbsolutePosition.x or x > ( frame.AbsolutePosition.x + frame.AbsoluteSize.x ) then - reorganizeLoadout(gearClone,false) - return false - elseif y < frame.AbsolutePosition.y or y > ( frame.AbsolutePosition.y + frame.AbsoluteSize.y ) then - reorganizeLoadout(gearClone,false) - return false - else - if dragBeginPos then gearClone.Position = dragBeginPos end - return -1 - end -end - -function unequipAllItems(dontEquipThis) - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then break end - if gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value ~= dontEquipThis then - if gearSlots[i].GearReference.Value:IsA("HopperBin") then - gearSlots[i].GearReference.Value:Disable() - elseif gearSlots[i].GearReference.Value:IsA("Tool") then - gearSlots[i].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack - end - gearSlots[i].Selected = false - end - end -end - -function showToolTip(button, tip) - if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then - button.ToolTipLabel.Text = tostring(tip) - local xSize = button.ToolTipLabel.TextBounds.X + 6 - button.ToolTipLabel.Size = UDim2.new(0,xSize,0,20) - button.ToolTipLabel.Position = UDim2.new(0.5,-xSize/2,0,-30) - button.ToolTipLabel.Visible = true - end -end - -function hideToolTip(button, tip) - if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then - button.ToolTipLabel.Visible = false - end -end - -local addingPlayerChild = function(child, equipped, addToSlot, inventoryGearButton) - waitForDebounce() - debounce = true - - if child:FindFirstChild("RobloxBuildTool") then debounce = false return end -- don't show roblox build tools - if not child:IsA("Tool") then - if not child:IsA("HopperBin") then - debounce = false - return -- we don't care about anything besides tools (sigh...) - end - end - - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then -- we already have gear, do nothing - debounce = false - return - end - end - end - - - local gearClone = currentLoadout.TempSlot:clone() - gearClone.Name = child.Name - gearClone.GearImage.Image = child.TextureId - if gearClone.GearImage.Image == "" then - gearClone.GearText.Text = child.Name - end - gearClone.GearReference.Value = child - - gearClone.MouseEnter:connect(function() - if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then - showToolTip(gearClone, gearClone.GearReference.Value.ToolTip) - end - end) - - gearClone.MouseLeave:connect(function() - if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then - hideToolTip(gearClone, gearClone.GearReference.Value.ToolTip) - end - end) - - gearClone.RobloxLocked = true - - local slotToMod = -1 - - if not addToSlot then - for i = 1, #gearSlots do - if gearSlots[i] == "empty" then - slotToMod = i - break - end - end - else - slotToMod = addToSlot - end - - if slotToMod == - 1 then -- No available slot to add in! - debounce = false - return - end - - local slotNum = slotToMod % 10 - local parent = currentLoadout:FindFirstChild("Slot"..tostring(slotNum)) - gearClone.Parent = parent - - if inventoryGearButton then - local absolutePositionFinal = inventoryGearButton.AbsolutePosition - local currentAbsolutePosition = gearClone.AbsolutePosition - local diff = absolutePositionFinal - currentAbsolutePosition - gearClone.Position = UDim2.new(gearClone.Position.X.Scale,diff.x,gearClone.Position.Y.Scale,diff.y) - gearClone.ZIndex = 4 - end - - if addToSlot then - reorganizeLoadout(gearClone, true, equipped, addToSlot) - else - reorganizeLoadout(gearClone, true) - end - - if gearClone.Parent == nil then debounce = false return end -- couldn't fit in (hopper is full!) - - if equipped then - gearClone.Selected = true - unequipAllItems(child) - delay(guiTweenSpeed + 0.01,function() -- if our gear is equipped, we will want to enlarge it when done moving - if gearClone:FindFirstChild("GearReference") and ( (gearClone.GearReference.Value:IsA("Tool") and gearClone.GearReference.Value.Parent == player.Character) or - (gearClone.GearReference.Value:IsA("HopperBin") and gearClone.GearReference.Value.Active == true) ) then - enlargeButton(gearClone) - end - end) - end - - local dragBeginPos = nil - local clickCon, buttonDeleteCon, mouseEnterCon, mouseLeaveCon, dragStop, dragBegin = nil - clickCon = gearClone.MouseButton1Click:connect(function() - if characterInWorkspace() then - if not gearClone.Draggable then - activateGear(gearClone.SlotNumber.Text) - end - end - end) - mouseEnterCon = gearClone.MouseEnter:connect(function() - if guiBackpack.Visible then - gearClone.Draggable = true - end - end) - dragBegin = gearClone.DragBegin:connect(function(pos) - dragBeginPos = pos - gearClone.ZIndex = 7 - local children = gearClone:GetChildren() - for i = 1, #children do - if children[i]:IsA("TextLabel") then - if string.find(children[i].Name,"Shadow") then - children[i].ZIndex = 8 - else - children[i].ZIndex = 9 +function resizeGrid() + for k,v in pairs(backpackItems) do + if not v:FindFirstChild("RobloxBuildTool") then + if not buttons[v] then + local buttonClone = gearButton:clone() + buttonClone.Parent = grid.ScrollingFrame + buttonClone.Visible = true + buttonClone.Image = v.TextureId + if buttonClone.Image == "" then + buttonClone.GearText.Text = v.Name end - elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then - children[i].ZIndex = 7 - end - end - end) - dragStop = gearClone.DragStopped:connect(function(x,y) - if gearClone.Selected then - gearClone.ZIndex = 2 - else - gearClone.ZIndex = 1 - end - local children = gearClone:GetChildren() - for i = 1, #children do - if children[i]:IsA("TextLabel") then - if string.find(children[i].Name,"Shadow") then - children[i].ZIndex = 3 - else - children[i].ZIndex = 4 - end - elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then - children[i].ZIndex = 2 - end - end - resolveDrag(gearClone,x,y) - end) - mouseLeaveCon = gearClone.MouseLeave:connect(function() - gearClone.Draggable = false - end) - buttonDeleteCon = gearClone.AncestryChanged:connect(function() - if gearClone.Parent and gearClone.Parent.Parent == currentLoadout then return end - if clickCon then clickCon:disconnect() end - if buttonDeleteCon then buttonDeleteCon:disconnect() end - if mouseEnterCon then mouseEnterCon:disconnect() end - if mouseLeaveCon then mouseLeaveCon:disconnect() end - if dragStop then dragStop:disconnect() end - if dragBegin then dragBegin:disconnect() end - end) -- this probably isn't necessary since objects are being deleted (probably), but this might still leak just in case - local childCon = nil - local childChangeCon = nil - childCon = child.AncestryChanged:connect(function(newChild,parent) - if not checkToolAncestry(newChild,parent) then - if childCon then childCon:disconnect() end - if childChangeCon then childChangeCon:disconnect() end - removeFromInventory(child) - elseif parent == game.Players.LocalPlayer.Backpack then - normalizeButton(gearClone) - end - end) - - childChangeCon = child.Changed:connect(function(prop) - if prop == "Name" then - if gearClone and gearClone.GearImage.Image == "" then - gearClone.GearText.Text = child.Name + buttonClone.GearReference.Value = v + buttonClone.Draggable = true + buttons[v] = buttonClone + + local unequipMenu = getGearContextMenu() + + unequipMenu.Visible = false + unequipMenu.Parent = buttonClone + + local beginPos = nil + buttonClone.DragBegin:connect(function(value) + buttonClone.ZIndex = 9 + beginPos = value + end) + buttonClone.DragStopped:connect(function(x,y) + buttonClone.ZIndex = 1 + if beginPos ~= buttonClone.Position then + if not checkForSwap(buttonClone,x,y) then + buttonClone:TweenPosition(beginPos,Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.5, true) + buttonClone.Draggable = false + delay(0.5,function() + buttonClone.Draggable = true + end) + else + buttonClone.Position = beginPos + end + end + end) + local clickTime = tick() + mouseEnterCons[buttonClone] = buttonClone.MouseEnter:connect(function() previewGear(buttonClone) end) + mouseClickCons[buttonClone] = buttonClone.MouseButton1Click:connect(function() + local newClickTime = tick() + if buttonClone.Active and (newClickTime - clickTime) < 0.5 then + local slot = findEmptySlot() + if slot then + buttonClone.ZIndex = 1 + swapGearSlot(slot,buttonClone) + end + else + buttonClick(buttonClone) + end + clickTime = newClickTime + end) end - elseif prop == "Active" then - if child and child:IsA("HopperBin") then - if not child.Active then - gearClone.Selected = false - normalizeButton(gearClone) + end + end + recalculateScroll() +end + +function showPartialGrid(subset) + for k,v in pairs(buttons) do + v.Parent = nil + end + if subset then + for k,v in pairs(subset) do + v.Parent = grid.ScrollingFrame + end + end + recalculateScroll() +end + +function showEntireGrid() + for k,v in pairs(buttons) do + v.Parent = grid.ScrollingFrame + end + recalculateScroll() +end + +function inLoadout(gear) + local children = currentLoadout:GetChildren() + for i = 1, #children do + if children[i]:IsA("Frame") then + local button = children[i]:GetChildren() + if #button > 0 then + if button[1].GearReference.Value and button[1].GearReference.Value == gear then + return true end end - elseif prop == "TextureId" then - gearClone.GearImage.Image = child.TextureId end - end) - - debounce = false - -end - -function addToInventory(child) - if not child:IsA("Tool") or not child:IsA("HopperBin") then return end - - local slot = nil - for i = 1, #inventory do - if inventory[i] and inventory[i] == child then return end - if not inventory[i] then slot = i end end - if slot then - inventory[slot] = child - elseif #inventory < 1 then - inventory[1] = child - else - inventory[#inventory + 1] = child - end -end + return false +end -function removeFromInventory(child) - for i = 1, #inventory do - if inventory[i] == child then - table.remove(inventory,i) - inventory[i] = nil +function updateGridActive() + for k,v in pairs(backpackItems) do + if buttons[v] then + local gear = nil + local gearRef = buttons[v]:FindFirstChild("GearReference") + + if gearRef then gear = gearRef.Value end + + if not gear then + buttons[v].Active = false + elseif inLoadout(gear) then + buttons[v].Active = false + else + buttons[v].Active = true + end end end end -local spreadOutGear = function() - loadoutChildren = currentLoadout:GetChildren() - - for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") then - loadoutChildren[i].BackgroundTransparency = 0.5 - local slot = tonumber(string.sub(loadoutChildren[i].Name,5)) - if slot == 0 then slot = 10 end - loadoutChildren[i]:TweenPosition(UDim2.new((slot - 1)/10,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, true) - end - end -end - -local centerGear = function() - loadoutChildren = currentLoadout:GetChildren() +function centerGear(loadoutChildren) local gearButtons = {} - local lastSlotAdd = nlii - + local lastSlotAdd = nil for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") then - if #loadoutChildren[i]:GetChildren() > 0 then - if loadoutChildren[i].Name == "Slot0" then - lastSlotAdd = loadoutChildren[i] - else - table.insert(gearButtons, loadoutChildren[i]) - end + if loadoutChildren[i]:IsA("Frame") and #loadoutChildren[i]:GetChildren() > 0 then + if loadoutChildren[i].Name == "Slot0" then + lastSlotAdd = loadoutChildren[i] + else + table.insert(gearButtons, loadoutChildren[i]) end - loadoutChildren[i].BackgroundTransparency = 1 end end if lastSlotAdd then table.insert(gearButtons,lastSlotAdd) end @@ -731,150 +407,437 @@ local centerGear = function() end end -function editLoadout() - if inGearTab then - spreadOutGear() - end -end - -function readonlyLoadout() - if not inGearTab then - centerGear() - end -end - -function setupBackpackListener() - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end - backpackChildCon = player.Backpack.ChildAdded:connect(function(child) - addingPlayerChild(child) - addToInventory(child) - end) -end - -function playerCharacterChildAdded(child) - addingPlayerChild(child,true) - addToInventory(child) -end - -function activateLoadout() - currentLoadout.Visible = true -end - -function deactivateLoadout() - currentLoadout.Visible = false -end - -function tabHandler(inFocus) - inGearTab = inFocus - if inFocus then - editLoadout() +function tabClickHandler(tabName) + if tabName == StaticTabName then + backpackOpenHandler(tabName) else - readonlyLoadout() + backpackCloseHandler(tabName) + end +end + +function backpackOpenHandler(currentTab) + if currentTab and currentTab ~= StaticTabName then + backpack.Gear.Visible = false + return + end + + backpack.Gear.Visible = true + updateGridActive() + + resizeGrid() + resize() + tellBackpackReadyFunc:Invoke() +end + +function backpackCloseHandler(currentTab) + if currentTab and currentTab ~= StaticTabName then + backpack.Gear.Visible = false + return + end + + backpack.Gear.Visible = false + + resizeGrid() + resize() + tellBackpackReadyFunc:Invoke() +end + +function loadoutCheck(child, selectState) + if not child:IsA("ImageButton") then return end + for k,v in pairs(backpackItems) do + if buttons[v] then + if child:FindFirstChild("GearReference") and buttons[v]:FindFirstChild("GearReference") then + if buttons[v].GearReference.Value == child.GearReference.Value then + buttons[v].Active = selectState + break + end + end + end + end +end + +function clearPreview() + gearPreview.GearImage.Image = "" + gearPreview.GearStats.GearName.Text = "" +end + +function removeAllEquippedGear(physGear) + local stuff = player.Character:GetChildren() + for i = 1, #stuff do + if ( stuff[i]:IsA("Tool") or stuff[i]:IsA("HopperBin") ) and stuff[i] ~= physGear then + stuff[i].Parent = playerBackpack + end + end +end + +function equipGear(physGear) + removeAllEquippedGear(physGear) + physGear.Parent = player.Character + updateGridActive() +end + +function unequipGear(physGear) + physGear.Parent = playerBackpack + updateGridActive() +end + +function highlight(button) + button.TextColor3 = Color3.new(0,0,0) + button.BackgroundColor3 = Color3.new(0.8,0.8,0.8) +end +function clearHighlight(button) + button.TextColor3 = Color3.new(1,1,1) + button.BackgroundColor3 = Color3.new(0,0,0) +end + +function swapGearSlot(slot,gearButton) + if not swapSlot.Value then -- signal loadout to swap a gear out + swapSlot.Slot.Value = slot + swapSlot.GearButton.Value = gearButton + swapSlot.Value = true + updateGridActive() end end --- End Functions +local UnequipGearMenuClick = function(element, menu) + if type(element.Action) ~= "number" then return end + local num = element.Action + if num == 1 then -- remove from loadout + unequipGear(menu.Parent.GearReference.Value) + local inventoryButton = menu.Parent + local gearToUnequip = inventoryButton.GearReference.Value + local loadoutChildren = currentLoadout:GetChildren() + local slot = -1 + for i = 1, #loadoutChildren do + if loadoutChildren[i]:IsA("Frame") then + local button = loadoutChildren[i]:GetChildren() + if button[1] and button[1].GearReference.Value == gearToUnequip then + slot = button[1].SlotNumber.Text + break + end + end + end + swapGearSlot(slot,nil) + end +end +function setupCharacterConnections() + if backpackAddCon then backpackAddCon:disconnect() end + backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) + + -- make sure we get all the children + local backpackChildren = game.Players.LocalPlayer.Backpack:GetChildren() + for i = 1, #backpackChildren do + addToGrid(backpackChildren[i]) + end + if characterChildAddedCon then characterChildAddedCon:disconnect() end + characterChildAddedCon = + game.Players.LocalPlayer.Character.ChildAdded:connect(function(child) + addToGrid(child) + updateGridActive() + end) + + if characterChildRemovedCon then characterChildRemovedCon:disconnect() end + characterChildRemovedCon = + game.Players.LocalPlayer.Character.ChildRemoved:connect(function(child) + updateGridActive() + end) --- Begin Script -wait() -- let stuff initialize incase this is first heartbeat... + wait() + centerGear(currentLoadout:GetChildren()) +end + +function removeCharacterConnections() + if characterChildAddedCon then characterChildAddedCon:disconnect() end + if characterChildRemovedCon then characterChildRemovedCon:disconnect() end + if backpackAddCon then backpackAddCon:disconnect() end +end + +function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end + +function filterGear(terms) + local filteredGear = {} + for k,v in pairs(backpackItems) do + if buttons[v] then + local gearString = string.lower(buttons[v].GearReference.Value.Name) + gearString = trim(gearString) + for i = 1, #terms do + if string.match(gearString,terms[i]) then + table.insert(filteredGear,buttons[v]) + break + end + end + end + end + + return filteredGear +end +function splitByWhitespace(text) + if type(text) ~= "string" then return nil end + + local terms = {} + for token in string.gmatch(text, "[^%s]+") do + if string.len(token) > 0 then + table.insert(terms,token) + end + end + return terms +end +function showSearchGear(searchTerms) + if not backpack.Gear.Visible then return end -- currently not active tab + + local searchTermTable = splitByWhitespace(searchTerms) + if searchTermTable and (#searchTermTable > 0) then + currSearchTerms = searchTermTable + else + currSearchTerms = nil + end + + if searchTermTable == nil then + showEntireGrid() + return + end + + local filteredButtons = filterGear(currSearchTerms) + showPartialGrid(filteredButtons) +end + +function nukeBackpack() + while #buttons > 0 do + table.remove(buttons) + end + buttons = {} + while #backpackItems > 0 do + table.remove(backpackItems) + end + backpackItems = {} + local scrollingFrameChildren = grid.ScrollingFrame:GetChildren() + for i = 1, #scrollingFrameChildren do + scrollingFrameChildren[i]:remove() + end +end + +function getGearContextMenu() + local gearContextMenu = Instance.new("Frame") + gearContextMenu.Active = true + gearContextMenu.Name = "UnequipContextMenu" + gearContextMenu.Size = UDim2.new(0,115,0,70) + gearContextMenu.Position = UDim2.new(0,-16,0,-16) + gearContextMenu.BackgroundTransparency = 1 + gearContextMenu.Visible = false + + local gearContextMenuButton = Instance.new("TextButton") + gearContextMenuButton.Name = "UnequipContextMenuButton" + gearContextMenuButton.Text = "" + gearContextMenuButton.Style = Enum.ButtonStyle.RobloxButtonDefault + gearContextMenuButton.ZIndex = 8 + gearContextMenuButton.Size = UDim2.new(1, 0, 1, -20) + gearContextMenuButton.Visible = true + gearContextMenuButton.Parent = gearContextMenu + + local elementHeight = 12 + + local contextMenuElements = {} + local contextMenuElementsName = {"Remove Hotkey"} + + for i = 1, #contextMenuElementsName do + local element = {} + element.Type = "Button" + element.Text = contextMenuElementsName[i] + element.Action = i + element.DoIt = UnequipGearMenuClick + table.insert(contextMenuElements,element) + end + + for i, contextElement in ipairs(contextMenuElements) do + local element = contextElement + if element.Type == "Button" then + local button = Instance.new("TextButton") + button.Name = "UnequipContextButton" .. i + button.BackgroundColor3 = Color3.new(0,0,0) + button.BorderSizePixel = 0 + button.TextXAlignment = Enum.TextXAlignment.Left + button.Text = " " .. contextElement.Text + button.Font = Enum.Font.Arial + button.FontSize = Enum.FontSize.Size14 + button.Size = UDim2.new(1, 8, 0, elementHeight) + button.Position = UDim2.new(0,0,0,elementHeight * i) + button.TextColor3 = Color3.new(1,1,1) + button.ZIndex = 9 + button.Parent = gearContextMenuButton + + button.MouseButton1Click:connect(function() + if button.Active and not gearContextMenu.Parent.Active then + local success, result = pcall(function() element.DoIt(element, gearContextMenu) end) + browsingMenu = false + gearContextMenu.Visible = false + clearHighlight(button) + clearPreview() + end + end) + + button.MouseEnter:connect(function() + if button.Active and gearContextMenu.Parent.Active then + highlight(button) + end + end) + button.MouseLeave:connect(function() + if button.Active and gearContextMenu.Parent.Active then + clearHighlight(button) + end + end) + + contextElement.Button = button + contextElement.Element = button + elseif element.Type == "Label" then + local frame = Instance.new("Frame") + frame.Name = "ContextLabel" .. i + frame.BackgroundTransparency = 1 + frame.Size = UDim2.new(1, 8, 0, elementHeight) + + local label = Instance.new("TextLabel") + label.Name = "Text1" + label.BackgroundTransparency = 1 + label.BackgroundColor3 = Color3.new(1,1,1) + label.BorderSizePixel = 0 + label.TextXAlignment = Enum.TextXAlignment.Left + label.Font = Enum.Font.ArialBold + label.FontSize = Enum.FontSize.Size14 + label.Position = UDim2.new(0.0, 0, 0, 0) + label.Size = UDim2.new(0.5, 0, 1, 0) + label.TextColor3 = Color3.new(1,1,1) + label.ZIndex = 9 + label.Parent = frame + element.Label1 = label + + if element.GetText2 then + label = Instance.new("TextLabel") + label.Name = "Text2" + label.BackgroundTransparency = 1 + label.BackgroundColor3 = Color3.new(1,1,1) + label.BorderSizePixel = 0 + label.TextXAlignment = Enum.TextXAlignment.Right + label.Font = Enum.Font.Arial + label.FontSize = Enum.FontSize.Size14 + label.Position = UDim2.new(0.5, 0, 0, 0) + label.Size = UDim2.new(0.5, 0, 1, 0) + label.TextColor3 = Color3.new(1,1,1) + label.ZIndex = 9 + label.Parent = frame + element.Label2 = label + end + frame.Parent = gearContextMenuButton + element.Label = frame + element.Element = frame + end + end + + gearContextMenu.ZIndex = 4 + gearContextMenu.MouseLeave:connect(function() + browsingMenu = false + gearContextMenu.Visible = false + clearPreview() + end) + robloxLock(gearContextMenu) + + return gearContextMenu +end -waitForChild(player,"Backpack") -waitForProperty(player,"Character") local backpackChildren = player.Backpack:GetChildren() -local size = math.min(10,#backpackChildren) -for i = 1, size do - addingPlayerChild(backpackChildren[i],false) +for i = 1, #backpackChildren do + addToGrid(backpackChildren[i]) end -setupBackpackListener() -waitForProperty(player,"Character") -for i,v in ipairs(player.Character:GetChildren()) do - playerCharacterChildAdded(v) -end -characterChildAddedCon = player.Character.ChildAdded:connect(function(child) playerCharacterChildAdded(child) end) +------------------------- Start Lifelong Connections ----------------------- -waitForChild(player.Character,"Humanoid") -humanoidDiedCon = player.Character.Humanoid.Died:connect(function() - if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end - deactivateLoadout() - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end + +resizeEvent.Event:connect(function(absSize) + if debounce then return end + + debounce = true + wait() + resize() + resizeGrid() + debounce = false end) +currentLoadout.ChildAdded:connect(function(child) loadoutCheck(child, false) end) +currentLoadout.ChildRemoved:connect(function(child) loadoutCheck(child, true) end) + +currentLoadout.DescendantAdded:connect(function(descendant) + if not backpack.Visible and ( descendant:IsA("ImageButton") or descendant:IsA("TextButton") ) then + centerGear(currentLoadout:GetChildren()) + end +end) +currentLoadout.DescendantRemoving:connect(function(descendant) + if not backpack.Visible and ( descendant:IsA("ImageButton") or descendant:IsA("TextButton") ) then + wait() + centerGear(currentLoadout:GetChildren()) + end +end) + +grid.MouseEnter:connect(function() clearPreview() end) +grid.MouseLeave:connect(function() clearPreview() end) + player.CharacterRemoving:connect(function() - for i = 1, #gearSlots do - if gearSlots[i] ~= "empty" then - gearSlots[i].Parent = nil - gearSlots[i] = "empty" - end + removeCharacterConnections() + nukeBackpack() +end) +player.CharacterAdded:connect(function() setupCharacterConnections() end) + +player.ChildAdded:connect(function(child) + if child:IsA("Backpack") then + playerBackpack = child + if backpackAddCon then backpackAddCon:disconnect() end + backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) end end) -player.CharacterAdded:connect(function() - waitForProperty(game.Players,"LocalPlayer") - player = game.Players.LocalPlayer -- make sure we are still looking at the correct character - waitForChild(player,"Backpack") - - - delay(1,function() - local backpackChildren = player.Backpack:GetChildren() - local size = math.min(10,#backpackChildren) - for i = 1, size do - addingPlayerChild(backpackChildren[i],false) - end - setupBackpackListener() - end) - - activateLoadout() - - if characterChildAddedCon then - characterChildAddedCon:disconnect() - characterChildAddedCon = nil +swapSlot.Changed:connect(function() + if not swapSlot.Value then + updateGridActive() end +end) - characterChildAddedCon = - player.Character.ChildAdded:connect(function(child) - addingPlayerChild(child,true) +local loadoutChildren = currentLoadout:GetChildren() +for i = 1, #loadoutChildren do + if loadoutChildren[i]:IsA("Frame") and string.find(loadoutChildren[i].Name,"Slot") then + loadoutChildren[i].ChildRemoved:connect(function() + updateGridActive() end) - - waitForChild(player.Character,"Humanoid") - humanoidDiedCon = - player.Character.Humanoid.Died:connect(function() - deactivateLoadout() - - if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end - if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end + loadoutChildren[i].ChildAdded:connect(function() + updateGridActive() end) - -end) - -waitForChild(guiBackpack,"SwapSlot") -guiBackpack.SwapSlot.Changed:connect(function() - if guiBackpack.SwapSlot.Value then - local swapSlot = guiBackpack.SwapSlot - local pos = swapSlot.Slot.Value - if pos == 0 then pos = 10 end - if gearSlots[pos] then - reorganizeLoadout(gearSlots[pos],false) - end - if swapSlot.GearButton.Value then - addingPlayerChild(swapSlot.GearButton.Value.GearReference.Value,false,pos) - end - guiBackpack.SwapSlot.Value = false end -end) +end +------------------------- End Lifelong Connections ----------------------- -game:GetService("GuiService").KeyPressed:connect(function(key) - if characterInWorkspace() then - activateGear(key) - end -end) +resize() +resizeGrid() -backpackOpenEvent.Event:connect(editLoadout) -backpackCloseEvent.Event:connect(centerGear) -tabClickedEvent.Event:connect(function ( tabName ) - tabHandler(tabName == StaticTabName) -end) \ No newline at end of file +-- make sure any items in the loadout are accounted for in inventory +local loadoutChildren = currentLoadout:GetChildren() +for i = 1, #loadoutChildren do + loadoutCheck(loadoutChildren[i], false) +end +if not backpack.Visible then centerGear(currentLoadout:GetChildren()) end + +-- make sure that inventory is listening to gear reparenting +if characterChildAddedCon == nil and game.Players.LocalPlayer["Character"] then + setupCharacterConnections() +end +if not backpackAddCon then + backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) +end + +backpackOpenEvent.Event:connect(backpackOpenHandler) +backpackCloseEvent.Event:connect(backpackCloseHandler) +tabClickedEvent.Event:connect(tabClickHandler) +searchRequestedEvent.Event:connect(showSearchGear) + +recalculateScrollLoadout() \ No newline at end of file diff --git a/public/asset/15 b/public/asset/15 index e21dcce..fdff51b 100644 --- a/public/asset/15 +++ b/public/asset/15 @@ -1,247 +1,884 @@ %15% --- A couple of necessary functions -print("BackpackWardrobe.lua loaded - edit 14") +if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client +-- A couple of necessary functions local function waitForChild(instance, name) - assert(instance) - assert(name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end return instance:FindFirstChild(name) end local function waitForProperty(instance, property) - assert(instance) - assert(property) while not instance[property] do instance.Changed:wait() end end +local currentLoadout = script.Parent +local StaticTabName = "gear" + +local robloxGui = game:GetService("CoreGui"):FindFirstChild("RobloxGui") +assert(robloxGui) +waitForChild(robloxGui,"CurrentLoadout") +waitForChild(robloxGui.CurrentLoadout,"TempSlot") +waitForChild(robloxGui.CurrentLoadout.TempSlot,"SlotNumber") + + +--- Begin Locals waitForChild(game,"Players") waitForProperty(game.Players,"LocalPlayer") local player = game.Players.LocalPlayer -local RbxGui, msg = LoadLibrary("RbxGui") -if not RbxGui then print("could not find RbxGui!") return end +waitForChild(game, "LocalBackpack") +game.LocalBackpack:SetOldSchoolBackpack(false) ---- Begin Locals -local StaticTabName = "wardrobe" +waitForChild(currentLoadout.Parent,"Backpack") +local guiBackpack = currentLoadout.Parent.Backpack -local backpack = script.Parent -local screen = script.Parent.Parent - -local backpackItems = {} -local buttons = {} - -local debounce = false -local browsingMenu = false - -local mouseEnterCons = {} -local mouseClickCons = {} - -local characterChildAddedCon = nil -local characterChildRemovedCon = nil -local backpackAddCon = nil - -local Camera = game.Workspace.CurrentCamera - -local playerBackpack = waitForChild(player,"Backpack") - -waitForChild(backpack,"Tabs") - -waitForChild(backpack,"Wardrobe") - -local currentLoadout = waitForChild(backpack.Parent,"CurrentLoadout") - -local walkSpeed = 16 -local screenSize = game:GetService("CoreGui"):FindFirstChild("RobloxGui").AbsoluteSize -local rotateCharacter = false -local rotateCharacterButton = waitForChild(backpack.Wardrobe,"PreviewButton") - -local swapSlot = waitForChild(script.Parent,"SwapSlot") - -local backpackManager = waitForChild(script.Parent,"CoreScripts/BackpackScripts/BackpackManager") +local backpackManager = waitForChild(guiBackpack,"CoreScripts/BackpackScripts/BackpackManager") local backpackOpenEvent = waitForChild(backpackManager,"BackpackOpenEvent") local backpackCloseEvent = waitForChild(backpackManager,"BackpackCloseEvent") local tabClickedEvent = waitForChild(backpackManager,"TabClickedEvent") local resizeEvent = waitForChild(backpackManager,"ResizeEvent") -local searchRequestedEvent = waitForChild(backpackManager,"SearchRequestedEvent") -local tellBackpackReadyFunc = waitForChild(backpackManager,"BackpackReady") --- creating scroll bar early as to make sure items get placed correctly +local inGearTab = true + +local maxNumLoadoutItems = 10 + +local characterChildAddedCon = nil +local backpackChildCon = nil + +local debounce = false + +local enlargeFactor = 1.18 +local buttonSizeEnlarge = UDim2.new(1 * enlargeFactor,0,1 * enlargeFactor,0) +local buttonSizeNormal = UDim2.new(1,0,1,0) +local enlargeOverride = true +local guiTweenSpeed = 0.5 + +local inventory = {} + +for i = 0, 9 do + game:GetService("GuiService"):AddKey(tostring(i)) -- register our keys +end + +local gearSlots = {} +for i = 1, maxNumLoadoutItems do + gearSlots[i] = "empty" +end +--- End Locals + + + + -- Begin Functions -function lerpTest(from, to) - local ax, ay, az, a11, a12, a13, a21, a22, a23, a31, a32, a33 = from:components() - local bx, by, bz, b11, b12, b13, b21, b22, b23, b31, b32, b33 = to:components() - - local diffx = bx - ax; - local diffy = by - ay; - local diffz = bz - az; - - local diff11 = b11 - a11; - local diff12 = b12 - a12; - local diff13 = b13 - a13; - - local diff21 = b21 - a21; - local diff22 = b22 - a22; - local diff23 = b23 - a23; - - local diff31 = b31 - a31; - local diff32 = b32 - a32; - local diff33 = b33 - a33; - - while wait(0.1) do - break +local function kill(prop,con,gear) + if con then con:disconnect() end + if prop == true and gear then + reorganizeLoadout(gear,false) end end -function removeFromMap(map,object) - for i = 1, #map do - if map[i] == object then - table.remove(map,i) +function characterInWorkspace() + if game.Players["LocalPlayer"] then + if game.Players.LocalPlayer["Character"] then + if game.Players.LocalPlayer.Character ~= nil then + if game.Players.LocalPlayer.Character.Parent ~= nil then + return true + end + end + end + end + + return false +end + +function removeGear(gear) + local emptySlot = nil + for i = 1, #gearSlots do + if gearSlots[i] == gear and gear.Parent ~= nil then + emptySlot = i break end end + if emptySlot then + if gearSlots[emptySlot].GearReference.Value then + if gearSlots[emptySlot].GearReference.Value.Parent == game.Players.LocalPlayer.Character then -- if we currently have this equipped, unequip it + gearSlots[emptySlot].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack + end + + if gearSlots[emptySlot].GearReference.Value:IsA("HopperBin") and gearSlots[emptySlot].GearReference.Value.Active then -- this is an active hopperbin + gearSlots[emptySlot].GearReference.Value:Disable() + gearSlots[emptySlot].GearReference.Value.Active = false + end + end + + gearSlots[emptySlot] = "empty" + + local centerizeX = gear.Size.X.Scale/2 + local centerizeY = gear.Size.Y.Scale/2 + gear:TweenSizeAndPosition(UDim2.new(0,0,0,0), + UDim2.new(gear.Position.X.Scale + centerizeX,gear.Position.X.Offset,gear.Position.Y.Scale + centerizeY,gear.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/4,true) + delay(guiTweenSpeed/2, + function() + gear:remove() + end) + end +end + +function insertGear(gear, addToSlot) + local pos = nil + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + pos = i + break + end + end + + if pos == 1 and gearSlots[1] ~= "empty" then gear:remove() return end -- we are currently full, can't add in + else + pos = addToSlot + -- push all gear down one slot + local start = 1 + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + start = i + break + end + end + for i = start, pos + 1, -1 do + gearSlots[i] = gearSlots[i - 1] + if i == 10 then + gearSlots[i].SlotNumber.Text = "0" + gearSlots[i].SlotNumberDownShadow.Text = "0" + gearSlots[i].SlotNumberUpShadow.Text = "0" + else + gearSlots[i].SlotNumber.Text = i + gearSlots[i].SlotNumberDownShadow.Text = i + gearSlots[i].SlotNumberUpShadow.Text = i + end + end + end + + gearSlots[pos] = gear + if pos ~= maxNumLoadoutItems then + if(type(tostring(pos)) == "string") then + local posString = tostring(pos) + gear.SlotNumber.Text = posString + gear.SlotNumberDownShadow.Text = posString + gear.SlotNumberUpShadow.Text = posString + end + else -- tenth gear doesn't follow mathematical pattern :( + gear.SlotNumber.Text = "0" + gear.SlotNumberDownShadow.Text = "0" + gear.SlotNumberUpShadow.Text = "0" + end + gear.Visible = true + + local con = nil + con = gear.Kill.Changed:connect(function(prop) kill(prop,con,gear) end) +end + + +function reorganizeLoadout(gear, inserting, equipped, addToSlot) + if inserting then -- add in gear + insertGear(gear, addToSlot) + else + removeGear(gear) + end + if gear ~= "empty" then gear.ZIndex = 1 end +end + +function checkToolAncestry(child,parent) + if child:FindFirstChild("RobloxBuildTool") then return end -- don't show roblox build tools + if child:IsA("Tool") or child:IsA("HopperBin") then + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then + if parent == nil then + gearSlots[i].Kill.Value = true + return false + elseif child.Parent == player.Character then + gearSlots[i].Selected = true + return true + elseif child.Parent == player.Backpack then + if child:IsA("Tool") or child:IsA("HopperBin") then gearSlots[i].Selected = false end + return true + else + gearSlots[i].Kill.Value = true + return false + end + return true + end + end + end end -function robloxLock(instance) - instance.RobloxLocked = true - children = instance:GetChildren() - if children then - for i, child in ipairs(children) do - robloxLock(child) - end - end -end - -function buttonClick(button) - if button:FindFirstChild("UnequipContextMenu") and not button.Active then - button.UnequipContextMenu.Visible = true - browsingMenu = true +function removeAllEquippedGear(physGear) + local stuff = player.Character:GetChildren() + for i = 1, #stuff do + if ( stuff[i]:IsA("Tool") or stuff[i]:IsA("HopperBin") ) and stuff[i] ~= physGear then + if stuff[i]:IsA("Tool") then stuff[i].Parent = player.Backpack end + if stuff[i]:IsA("HopperBin") then + stuff[i]:Disable() + end + end end end -function tabClickHandler(tabName) - if tabName == StaticTabName then - backpackOpenHandler(tabName) +function hopperBinSwitcher(numKey, physGear) + if not physGear then return end + + physGear:ToggleSelect() + + if gearSlots[numKey] == "empty" then return end + + if not physGear.Active then + gearSlots[numKey].Selected = false + normalizeButton(gearSlots[numKey]) else - backpackCloseHandler(tabName) + gearSlots[numKey].Selected = true + enlargeButton(gearSlots[numKey]) end end -function backpackOpenHandler(currentTab) - if currentTab and currentTab ~= StaticTabName then - backpack.Wardrobe.Visible = false +function toolSwitcher(numKey) + + if not gearSlots[numKey] then return end + local physGear = gearSlots[numKey].GearReference.Value + if physGear == nil then return end + + removeAllEquippedGear(physGear) -- we don't remove this gear, as then we get a double switcheroo + + local key = numKey + if numKey == 0 then key = 10 end + + for i = 1, #gearSlots do + if gearSlots[i] and gearSlots[i] ~= "empty" and i ~= key then + normalizeButton(gearSlots[i]) + gearSlots[i].Selected = false + if gearSlots[i].GearReference and gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value:IsA("HopperBin") and gearSlots[i].GearReference.Value.Active then + gearSlots[i].GearReference.Value:ToggleSelect() + end + end + end + + if physGear:IsA("HopperBin") then + hopperBinSwitcher(numKey,physGear) + else + if physGear.Parent == player.Character then + physGear.Parent = player.Backpack + + if gearSlots[numKey] ~= "empty" then + gearSlots[numKey].Selected = false + normalizeButton(gearSlots[numKey]) + end + else + --player.Character.Humanoid:EquipTool(physGear) + + physGear.Parent = player.Character + gearSlots[numKey].Selected = true + + enlargeButton(gearSlots[numKey]) + end + end +end + + +function activateGear(num) + local numKey = nil + if num == "0" then + numKey = 10 -- why do lua indexes have to start at 1? :( + else + numKey = tonumber(num) + end + + if(numKey == nil) then return end + + if gearSlots[numKey] ~= "empty" then + toolSwitcher(numKey) + end +end + + +enlargeButton = function(button) + if button.Size.Y.Scale > 1 then return end + if not button.Parent then return end + if not button.Selected then return end + + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i] ~= button then + normalizeButton(gearSlots[i]) + end + end + + if not enlargeOverride then return end - - backpack.Wardrobe.Visible = true - createView() - tellBackpackReadyFunc:Invoke() -end -function backpackCloseHandler(currentTab) - if currentTab and currentTab ~= StaticTabName then - backpack.Wardrobe.Visible = false - revertView() - return + if button:IsA("ImageButton") or button:IsA("TextButton") then + button.ZIndex = 2 + local centerizeX = -(buttonSizeEnlarge.X.Scale - button.Size.X.Scale)/2 + local centerizeY = -(buttonSizeEnlarge.Y.Scale - button.Size.Y.Scale)/2 + button:TweenSizeAndPosition(buttonSizeEnlarge, + UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/5,enlargeOverride) end - - backpack.Wardrobe.Visible = false - revertView() - tellBackpackReadyFunc:Invoke() end -function highlight(button) - button.TextColor3 = Color3.new(0,0,0) - button.BackgroundColor3 = Color3.new(0.8,0.8,0.8) -end -function clearHighlight(button) - button.TextColor3 = Color3.new(1,1,1) - button.BackgroundColor3 = Color3.new(0,0,0) -end - -function trim(s) - return (s:gsub("^%s*(.-)%s*$", "%1")) -end - -function splitByWhitespace(text) - if type(text) ~= "string" then return nil end - - local terms = {} - for token in string.gmatch(text, "[^%s]+") do - if string.len(token) > 0 then - table.insert(terms,token) - end +normalizeAllButtons = function() + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i] ~= button then + normalizeButton(gearSlots[i],0.1) + end end - return terms end -function createView() - -- stop player from moving and store initial speed (they can still jump though) - if player.Character.Humanoid.WalkSpeed ~= 0 then walkSpeed = player.Character.Humanoid.WalkSpeed end - player.Character.Humanoid.WalkSpeed = 0 - -- initialize camera - Camera.CameraType = Enum.CameraType.Scriptable - focusCamera() +normalizeButton = function(button, speed) + if not button then return end + if button.Size.Y.Scale <= 1 then return end + if button.Selected then return end + if not button.Parent then return end + + local moveSpeed = speed + if moveSpeed == nil or type(moveSpeed) ~= "number" then moveSpeed = guiTweenSpeed/5 end + + if button:IsA("ImageButton") or button:IsA("TextButton") then + button.ZIndex = 1 + local inverseEnlarge = 1/enlargeFactor + local centerizeX = -(buttonSizeNormal.X.Scale - button.Size.X.Scale)/2 + local centerizeY = -(buttonSizeNormal.Y.Scale - button.Size.Y.Scale)/2 + button:TweenSizeAndPosition(buttonSizeNormal, + UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,moveSpeed,enlargeOverride) + end end -function revertView() - -- restore initial walk speed - player.Character.Humanoid.WalkSpeed = walkSpeed - - -- restore player camera - Camera.CameraType = Enum.CameraType.Custom - - -- if character spin is enabled then disable it - if rotateCharacter then toggleCharacterSpin() end +local waitForDebounce = function() + while debounce do + wait() + end end -function focusCamera() - if not backpack.Wardrobe.Visible then return end - - local cameraAngle = CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0) - local cameraPosition = CFrame.new(screenSize.X*0.00983455882, 0, screenSize.Y*-0.01527777777) - - Camera.CoordinateFrame = game.Players.LocalPlayer.Character.Torso.CFrame * cameraPosition * cameraAngle +function pointInRectangle(point,rectTopLeft,rectSize) + if point.x > rectTopLeft.x and point.x < (rectTopLeft.x + rectSize.x) then + if point.y > rectTopLeft.y and point.y < (rectTopLeft.y + rectSize.y) then + return true + end + end + return false end -function toggleCharacterSpin() - rotateCharacter = not rotateCharacter +function swapGear(gearClone,toFrame) + local toFrameChildren = toFrame:GetChildren() + if #toFrameChildren == 1 then + if toFrameChildren[1]:FindFirstChild("SlotNumber") then - if rotateCharacter then - rotateCharacterButton.Text = "Pause" + local toSlot = tonumber(toFrameChildren[1].SlotNumber.Text) + local gearCloneSlot = tonumber(gearClone.SlotNumber.Text) + if toSlot == 0 then toSlot = 10 end + if gearCloneSlot == 0 then gearCloneSlot = 10 end + + gearSlots[toSlot] = gearClone + gearSlots[gearCloneSlot] = toFrameChildren[1] + + toFrameChildren[1].SlotNumber.Text = gearClone.SlotNumber.Text + toFrameChildren[1].SlotNumberDownShadow.Text = gearClone.SlotNumber.Text + toFrameChildren[1].SlotNumberUpShadow.Text = gearClone.SlotNumber.Text + + local subString = string.sub(toFrame.Name,5) + gearClone.SlotNumber.Text = subString + gearClone.SlotNumberDownShadow.Text = subString + gearClone.SlotNumberUpShadow.Text = subString + + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) + toFrameChildren[1].Position = UDim2.new(toFrameChildren[1].Position.X.Scale,0,toFrameChildren[1].Position.Y.Scale,0) + + toFrameChildren[1].Parent = gearClone.Parent + gearClone.Parent = toFrame + end else - rotateCharacterButton.Text = "Rotate" - end + local slotNum = tonumber(gearClone.SlotNumber.Text) + if slotNum == 0 then slotNum = 10 end + gearSlots[slotNum] = "empty" -- reset this gear slot - while rotateCharacter do - wait(0.05) - player.Character.Torso.CFrame = player.Character.Torso.CFrame * CFrame.Angles(0,0.035,0) + local subString = string.sub(toFrame.Name,5) + gearClone.SlotNumber.Text = subString + gearClone.SlotNumberDownShadow.Text = subString + gearClone.SlotNumberUpShadow.Text = subString + + local toSlotNum = tonumber(gearClone.SlotNumber.Text) + if toSlotNum == 0 then toSlotNum = 10 end + gearSlots[toSlotNum] = gearClone + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) + gearClone.Parent = toFrame end end -------------------------- Start Lifelong Connections ----------------------- +function resolveDrag(gearClone,x,y) + local mousePoint = Vector2.new(x,y) + local frame = gearClone.Parent + local frames = frame.Parent:GetChildren() -resizeEvent.Event:connect(function(absSize) - if debounce then return end - + for i = 1, #frames do + if frames[i]:IsA("Frame") then + if pointInRectangle(mousePoint, frames[i].AbsolutePosition,frames[i].AbsoluteSize) then + swapGear(gearClone,frames[i]) + return true + end + end + end + + if x < frame.AbsolutePosition.x or x > ( frame.AbsolutePosition.x + frame.AbsoluteSize.x ) then + reorganizeLoadout(gearClone,false) + return false + elseif y < frame.AbsolutePosition.y or y > ( frame.AbsolutePosition.y + frame.AbsoluteSize.y ) then + reorganizeLoadout(gearClone,false) + return false + else + if dragBeginPos then gearClone.Position = dragBeginPos end + return -1 + end +end + +function unequipAllItems(dontEquipThis) + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value ~= dontEquipThis then + if gearSlots[i].GearReference.Value:IsA("HopperBin") then + gearSlots[i].GearReference.Value:Disable() + elseif gearSlots[i].GearReference.Value:IsA("Tool") then + gearSlots[i].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack + end + gearSlots[i].Selected = false + end + end +end + +function showToolTip(button, tip) + if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then + button.ToolTipLabel.Text = tostring(tip) + local xSize = button.ToolTipLabel.TextBounds.X + 6 + button.ToolTipLabel.Size = UDim2.new(0,xSize,0,20) + button.ToolTipLabel.Position = UDim2.new(0.5,-xSize/2,0,-30) + button.ToolTipLabel.Visible = true + end +end + +function hideToolTip(button, tip) + if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then + button.ToolTipLabel.Visible = false + end +end + +local addingPlayerChild = function(child, equipped, addToSlot, inventoryGearButton) + waitForDebounce() debounce = true - wait() - screenSize = absSize - focusCamera() + + if child:FindFirstChild("RobloxBuildTool") then debounce = false return end -- don't show roblox build tools + if not child:IsA("Tool") then + if not child:IsA("HopperBin") then + debounce = false + return -- we don't care about anything besides tools (sigh...) + end + end + + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then -- we already have gear, do nothing + debounce = false + return + end + end + end + + + local gearClone = currentLoadout.TempSlot:clone() + gearClone.Name = child.Name + gearClone.GearImage.Image = child.TextureId + if gearClone.GearImage.Image == "" then + gearClone.GearText.Text = child.Name + end + gearClone.GearReference.Value = child + + gearClone.MouseEnter:connect(function() + if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then + showToolTip(gearClone, gearClone.GearReference.Value.ToolTip) + end + end) + + gearClone.MouseLeave:connect(function() + if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then + hideToolTip(gearClone, gearClone.GearReference.Value.ToolTip) + end + end) + + gearClone.RobloxLocked = true + + local slotToMod = -1 + + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + slotToMod = i + break + end + end + else + slotToMod = addToSlot + end + + if slotToMod == - 1 then -- No available slot to add in! + debounce = false + return + end + + local slotNum = slotToMod % 10 + local parent = currentLoadout:FindFirstChild("Slot"..tostring(slotNum)) + gearClone.Parent = parent + + if inventoryGearButton then + local absolutePositionFinal = inventoryGearButton.AbsolutePosition + local currentAbsolutePosition = gearClone.AbsolutePosition + local diff = absolutePositionFinal - currentAbsolutePosition + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,diff.x,gearClone.Position.Y.Scale,diff.y) + gearClone.ZIndex = 4 + end + + if addToSlot then + reorganizeLoadout(gearClone, true, equipped, addToSlot) + else + reorganizeLoadout(gearClone, true) + end + + if gearClone.Parent == nil then debounce = false return end -- couldn't fit in (hopper is full!) + + if equipped then + gearClone.Selected = true + unequipAllItems(child) + delay(guiTweenSpeed + 0.01,function() -- if our gear is equipped, we will want to enlarge it when done moving + if gearClone:FindFirstChild("GearReference") and ( (gearClone.GearReference.Value:IsA("Tool") and gearClone.GearReference.Value.Parent == player.Character) or + (gearClone.GearReference.Value:IsA("HopperBin") and gearClone.GearReference.Value.Active == true) ) then + enlargeButton(gearClone) + end + end) + end + + local dragBeginPos = nil + local clickCon, buttonDeleteCon, mouseEnterCon, mouseLeaveCon, dragStop, dragBegin = nil + clickCon = gearClone.MouseButton1Click:connect(function() + if characterInWorkspace() then + if not gearClone.Draggable then + activateGear(gearClone.SlotNumber.Text) + end + end + end) + mouseEnterCon = gearClone.MouseEnter:connect(function() + if guiBackpack.Visible then + gearClone.Draggable = true + end + end) + dragBegin = gearClone.DragBegin:connect(function(pos) + dragBeginPos = pos + gearClone.ZIndex = 7 + local children = gearClone:GetChildren() + for i = 1, #children do + if children[i]:IsA("TextLabel") then + if string.find(children[i].Name,"Shadow") then + children[i].ZIndex = 8 + else + children[i].ZIndex = 9 + end + elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then + children[i].ZIndex = 7 + end + end + end) + dragStop = gearClone.DragStopped:connect(function(x,y) + if gearClone.Selected then + gearClone.ZIndex = 2 + else + gearClone.ZIndex = 1 + end + local children = gearClone:GetChildren() + for i = 1, #children do + if children[i]:IsA("TextLabel") then + if string.find(children[i].Name,"Shadow") then + children[i].ZIndex = 3 + else + children[i].ZIndex = 4 + end + elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then + children[i].ZIndex = 2 + end + end + resolveDrag(gearClone,x,y) + end) + mouseLeaveCon = gearClone.MouseLeave:connect(function() + gearClone.Draggable = false + end) + buttonDeleteCon = gearClone.AncestryChanged:connect(function() + if gearClone.Parent and gearClone.Parent.Parent == currentLoadout then return end + if clickCon then clickCon:disconnect() end + if buttonDeleteCon then buttonDeleteCon:disconnect() end + if mouseEnterCon then mouseEnterCon:disconnect() end + if mouseLeaveCon then mouseLeaveCon:disconnect() end + if dragStop then dragStop:disconnect() end + if dragBegin then dragBegin:disconnect() end + end) -- this probably isn't necessary since objects are being deleted (probably), but this might still leak just in case + + local childCon = nil + local childChangeCon = nil + childCon = child.AncestryChanged:connect(function(newChild,parent) + if not checkToolAncestry(newChild,parent) then + if childCon then childCon:disconnect() end + if childChangeCon then childChangeCon:disconnect() end + removeFromInventory(child) + elseif parent == game.Players.LocalPlayer.Backpack then + normalizeButton(gearClone) + end + end) + + childChangeCon = child.Changed:connect(function(prop) + if prop == "Name" then + if gearClone and gearClone.GearImage.Image == "" then + gearClone.GearText.Text = child.Name + end + elseif prop == "Active" then + if child and child:IsA("HopperBin") then + if not child.Active then + gearClone.Selected = false + normalizeButton(gearClone) + end + end + elseif prop == "TextureId" then + gearClone.GearImage.Image = child.TextureId + end + end) + debounce = false + +end + +function addToInventory(child) + if not child:IsA("Tool") or not child:IsA("HopperBin") then return end + + local slot = nil + for i = 1, #inventory do + if inventory[i] and inventory[i] == child then return end + if not inventory[i] then slot = i end + end + if slot then + inventory[slot] = child + elseif #inventory < 1 then + inventory[1] = child + else + inventory[#inventory + 1] = child + end +end + +function removeFromInventory(child) + for i = 1, #inventory do + if inventory[i] == child then + table.remove(inventory,i) + inventory[i] = nil + end + end +end + +local spreadOutGear = function() + loadoutChildren = currentLoadout:GetChildren() + + for i = 1, #loadoutChildren do + if loadoutChildren[i]:IsA("Frame") then + loadoutChildren[i].BackgroundTransparency = 0.5 + local slot = tonumber(string.sub(loadoutChildren[i].Name,5)) + if slot == 0 then slot = 10 end + loadoutChildren[i]:TweenPosition(UDim2.new((slot - 1)/10,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, true) + end + end +end + +local centerGear = function() + loadoutChildren = currentLoadout:GetChildren() + local gearButtons = {} + local lastSlotAdd = nlii + + for i = 1, #loadoutChildren do + if loadoutChildren[i]:IsA("Frame") then + if #loadoutChildren[i]:GetChildren() > 0 then + if loadoutChildren[i].Name == "Slot0" then + lastSlotAdd = loadoutChildren[i] + else + table.insert(gearButtons, loadoutChildren[i]) + end + end + loadoutChildren[i].BackgroundTransparency = 1 + end + end + if lastSlotAdd then table.insert(gearButtons,lastSlotAdd) end + + local startPos = ( 1 - (#gearButtons * 0.1) ) / 2 + for i = 1, #gearButtons do + gearButtons[i]:TweenPosition(UDim2.new(startPos + ((i - 1) * 0.1),0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, true) + end +end + +function editLoadout() + if inGearTab then + spreadOutGear() + end +end + +function readonlyLoadout() + if not inGearTab then + centerGear() + end +end + +function setupBackpackListener() + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end + backpackChildCon = player.Backpack.ChildAdded:connect(function(child) + addingPlayerChild(child) + addToInventory(child) + end) +end + +function playerCharacterChildAdded(child) + addingPlayerChild(child,true) + addToInventory(child) +end + +function activateLoadout() + currentLoadout.Visible = true +end + +function deactivateLoadout() + currentLoadout.Visible = false +end + +function tabHandler(inFocus) + inGearTab = inFocus + if inFocus then + editLoadout() + else + readonlyLoadout() + end +end +-- End Functions + + + + + + +-- Begin Script +wait() -- let stuff initialize incase this is first heartbeat... + +waitForChild(player,"Backpack") +waitForProperty(player,"Character") + +-- not sure why this had no delay but the player.CharacterAdded one had one... this type of error would be easier to avoid with function reusage +delay(1,function() + local backpackChildren = player.Backpack:GetChildren() + local size = math.min(10,#backpackChildren) + for i = 1, size do + addingPlayerChild(backpackChildren[i],false) + end + setupBackpackListener() end) +waitForProperty(player,"Character") +for i,v in ipairs(player.Character:GetChildren()) do + playerCharacterChildAdded(v) +end +characterChildAddedCon = player.Character.ChildAdded:connect(function(child) playerCharacterChildAdded(child) end) -------------------------- End Lifelong Connections ----------------------- +waitForChild(player.Character,"Humanoid") +humanoidDiedCon = player.Character.Humanoid.Died:connect(function() + if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end + deactivateLoadout() + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end +end) -backpackOpenEvent.Event:connect(backpackOpenHandler) -backpackCloseEvent.Event:connect(backpackCloseHandler) -tabClickedEvent.Event:connect(tabClickHandler) -rotateCharacterButton.MouseButton1Click:connect(toggleCharacterSpin) \ No newline at end of file +player.CharacterRemoving:connect(function() + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" then + gearSlots[i].Parent = nil + gearSlots[i] = "empty" + end + end +end) + +player.CharacterAdded:connect(function() + waitForProperty(game.Players,"LocalPlayer") + player = game.Players.LocalPlayer -- make sure we are still looking at the correct character + waitForChild(player,"Backpack") + + + delay(1,function() + local backpackChildren = player.Backpack:GetChildren() + local size = math.min(10,#backpackChildren) + for i = 1, size do + addingPlayerChild(backpackChildren[i],false) + end + setupBackpackListener() + end) + + activateLoadout() + + if characterChildAddedCon then + characterChildAddedCon:disconnect() + characterChildAddedCon = nil + end + + characterChildAddedCon = + player.Character.ChildAdded:connect(function(child) + addingPlayerChild(child,true) + end) + + waitForChild(player.Character,"Humanoid") + humanoidDiedCon = + player.Character.Humanoid.Died:connect(function() + deactivateLoadout() + + if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end + end) + +end) + +waitForChild(guiBackpack,"SwapSlot") +guiBackpack.SwapSlot.Changed:connect(function() + if guiBackpack.SwapSlot.Value then + local swapSlot = guiBackpack.SwapSlot + local pos = swapSlot.Slot.Value + if pos == 0 then pos = 10 end + if gearSlots[pos] then + reorganizeLoadout(gearSlots[pos],false) + end + if swapSlot.GearButton.Value then + addingPlayerChild(swapSlot.GearButton.Value.GearReference.Value,false,pos) + end + guiBackpack.SwapSlot.Value = false + end +end) + +game:GetService("GuiService").KeyPressed:connect(function(key) + if characterInWorkspace() then + activateGear(key) + end +end) + +backpackOpenEvent.Event:connect(editLoadout) +backpackCloseEvent.Event:connect(centerGear) +tabClickedEvent.Event:connect(function ( tabName ) + tabHandler(tabName == StaticTabName) +end) \ No newline at end of file diff --git a/public/asset/16 b/public/asset/16 index 85406f6..2dbe1a9 100644 --- a/public/asset/16 +++ b/public/asset/16 @@ -1,147 +1,247 @@ %16% --- Responsible for giving out tools in personal servers +-- A couple of necessary functions +print("BackpackWardrobe.lua loaded - edit 14") --- first, lets see if buildTools have already been created --- create the object in lighting (TODO: move to some sort of "container" object when we have one) -local toolsArray = game.Lighting:FindFirstChild("BuildToolsModel") -local ownerArray = game.Lighting:FindFirstChild("OwnerToolsModel") -local hasBuildTools = false - -function getIds(idTable, assetTable) - for i = 1, #idTable do - local model = game:GetService("InsertService"):LoadAsset(idTable[i]) - if model then - local children = model:GetChildren() - for i = 1, #children do - if children[i]:IsA("Tool") then - table.insert(assetTable,children[i]) - end - end - end +local function waitForChild(instance, name) + assert(instance) + assert(name) + while not instance:FindFirstChild(name) do + instance.ChildAdded:wait() + end + return instance:FindFirstChild(name) +end +local function waitForProperty(instance, property) + assert(instance) + assert(property) + while not instance[property] do + instance.Changed:wait() end end -function storeInLighting(modelName, assetTable) - local model = Instance.new("Model") - model.Archivable = false - model.Name = modelName - - for i = 1, #assetTable do - assetTable[i].Parent = model - end - - if not game.Lighting:FindFirstChild(modelName) then -- no one beat us to it, we get to insert - model.Parent = game.Lighting - end -end +waitForChild(game,"Players") +waitForProperty(game.Players,"LocalPlayer") +local player = game.Players.LocalPlayer -if not toolsArray then -- no one has made build tools yet, we get to! - local buildToolIds = {} - local ownerToolIds = {} +local RbxGui, msg = LoadLibrary("RbxGui") +if not RbxGui then print("could not find RbxGui!") return end - table.insert(buildToolIds,73089166) -- PartSelectionTool - table.insert(buildToolIds,73089190) -- DeleteTool - table.insert(buildToolIds,73089204) -- CloneTool - table.insert(buildToolIds,73089214) -- RotateTool - table.insert(buildToolIds,73089239) -- ConfigTool - table.insert(buildToolIds,73089259) -- WiringTool - table.insert(buildToolIds,58921588) -- ClassicTool - - table.insert(ownerToolIds, 65347268) +--- Begin Locals +local StaticTabName = "wardrobe" - -- next, create array of our tools - local buildTools = {} - local ownerTools = {} - - getIds(buildToolIds, buildTools) - getIds(ownerToolIds, ownerTools) - - storeInLighting("BuildToolsModel",buildTools) - storeInLighting("OwnerToolsModel",ownerTools) - - toolsArray = game.Lighting:FindFirstChild("BuildToolsModel") - ownerArray = game.Lighting:FindFirstChild("OwnerToolsModel") -end +local backpack = script.Parent +local screen = script.Parent.Parent -local localBuildTools = {} - -function giveBuildTools() - if not hasBuildTools then - hasBuildTools = true - local theTools = toolsArray:GetChildren() - for i = 1, #theTools do - local toolClone = theTools[i]:clone() - if toolClone then - toolClone.Parent = game.Players.LocalPlayer.Backpack - table.insert(localBuildTools,toolClone) - end - end - end -end - -function giveOwnerTools() - local theOwnerTools = ownerArray:GetChildren() - for i = 1, #theOwnerTools do - local ownerToolClone = theOwnerTools[i]:clone() - if ownerToolClone then - ownerToolClone.Parent = game.Players.LocalPlayer.Backpack - table.insert(localBuildTools,ownerToolClone) - end - end -end - -function removeBuildTools() - if hasBuildTools then - hasBuildTools = false - for i = 1, #localBuildTools do - localBuildTools[i].Parent = nil - end - localBuildTools = {} - end -end - -if game.Players.LocalPlayer.HasBuildTools then - giveBuildTools() -end -if game.Players.LocalPlayer.PersonalServerRank >= 255 then - giveOwnerTools() -end +local backpackItems = {} +local buttons = {} local debounce = false -game.Players.LocalPlayer.Changed:connect(function(prop) - if prop == "HasBuildTools" then - while debounce do - wait(0.5) - end - - debounce = true - - if game.Players.LocalPlayer.HasBuildTools then - giveBuildTools() - else - removeBuildTools() - end - - if game.Players.LocalPlayer.PersonalServerRank >= 255 then - giveOwnerTools() - end - - debounce = false - elseif prop == "PersonalServerRank" then - if game.Players.LocalPlayer.PersonalServerRank >= 255 then - giveOwnerTools() - elseif game.Players.LocalPlayer.PersonalServerRank <= 0 then - game.Players.LocalPlayer:Remove() -- you're banned, goodbye! +local browsingMenu = false + +local mouseEnterCons = {} +local mouseClickCons = {} + +local characterChildAddedCon = nil +local characterChildRemovedCon = nil +local backpackAddCon = nil + +local Camera = game.Workspace.CurrentCamera + +local playerBackpack = waitForChild(player,"Backpack") + +waitForChild(backpack,"Tabs") + +waitForChild(backpack,"Wardrobe") + +local currentLoadout = waitForChild(backpack.Parent,"CurrentLoadout") + +local walkSpeed = 16 +local screenSize = game:GetService("CoreGui"):FindFirstChild("RobloxGui").AbsoluteSize +local rotateCharacter = false +local rotateCharacterButton = waitForChild(backpack.Wardrobe,"PreviewButton") + +local swapSlot = waitForChild(script.Parent,"SwapSlot") + +local backpackManager = waitForChild(script.Parent,"CoreScripts/BackpackScripts/BackpackManager") +local backpackOpenEvent = waitForChild(backpackManager,"BackpackOpenEvent") +local backpackCloseEvent = waitForChild(backpackManager,"BackpackCloseEvent") +local tabClickedEvent = waitForChild(backpackManager,"TabClickedEvent") +local resizeEvent = waitForChild(backpackManager,"ResizeEvent") +local searchRequestedEvent = waitForChild(backpackManager,"SearchRequestedEvent") +local tellBackpackReadyFunc = waitForChild(backpackManager,"BackpackReady") + +-- creating scroll bar early as to make sure items get placed correctly + + +-- Begin Functions +function lerpTest(from, to) + local ax, ay, az, a11, a12, a13, a21, a22, a23, a31, a32, a33 = from:components() + local bx, by, bz, b11, b12, b13, b21, b22, b23, b31, b32, b33 = to:components() + + local diffx = bx - ax; + local diffy = by - ay; + local diffz = bz - az; + + local diff11 = b11 - a11; + local diff12 = b12 - a12; + local diff13 = b13 - a13; + + local diff21 = b21 - a21; + local diff22 = b22 - a22; + local diff23 = b23 - a23; + + local diff31 = b31 - a31; + local diff32 = b32 - a32; + local diff33 = b33 - a33; + + while wait(0.1) do + break + end +end + +function removeFromMap(map,object) + for i = 1, #map do + if map[i] == object then + table.remove(map,i) + break end end +end + +function robloxLock(instance) + instance.RobloxLocked = true + children = instance:GetChildren() + if children then + for i, child in ipairs(children) do + robloxLock(child) + end + end +end + +function buttonClick(button) + if button:FindFirstChild("UnequipContextMenu") and not button.Active then + button.UnequipContextMenu.Visible = true + browsingMenu = true + end +end + +function tabClickHandler(tabName) + if tabName == StaticTabName then + backpackOpenHandler(tabName) + else + backpackCloseHandler(tabName) + end +end + +function backpackOpenHandler(currentTab) + if currentTab and currentTab ~= StaticTabName then + backpack.Wardrobe.Visible = false + return + end + + backpack.Wardrobe.Visible = true + createView() + tellBackpackReadyFunc:Invoke() +end + +function backpackCloseHandler(currentTab) + if currentTab and currentTab ~= StaticTabName then + backpack.Wardrobe.Visible = false + revertView() + return + end + + backpack.Wardrobe.Visible = false + revertView() + tellBackpackReadyFunc:Invoke() +end + +function highlight(button) + button.TextColor3 = Color3.new(0,0,0) + button.BackgroundColor3 = Color3.new(0.8,0.8,0.8) +end +function clearHighlight(button) + button.TextColor3 = Color3.new(1,1,1) + button.BackgroundColor3 = Color3.new(0,0,0) +end + +function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end + +function splitByWhitespace(text) + if type(text) ~= "string" then return nil end + + local terms = {} + for token in string.gmatch(text, "[^%s]+") do + if string.len(token) > 0 then + table.insert(terms,token) + end + end + return terms +end + +function createView() + -- stop player from moving and store initial speed (they can still jump though) + if player.Character.Humanoid.WalkSpeed ~= 0 then walkSpeed = player.Character.Humanoid.WalkSpeed end + player.Character.Humanoid.WalkSpeed = 0 + + -- initialize camera + Camera.CameraType = Enum.CameraType.Scriptable + focusCamera() +end + +function revertView() + -- restore initial walk speed + player.Character.Humanoid.WalkSpeed = walkSpeed + + -- restore player camera + Camera.CameraType = Enum.CameraType.Custom + + -- if character spin is enabled then disable it + if rotateCharacter then toggleCharacterSpin() end +end + +function focusCamera() + if not backpack.Wardrobe.Visible then return end + + local cameraAngle = CFrame.fromEulerAnglesXYZ(0, math.pi, 0) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0) + local cameraPosition = CFrame.new(screenSize.X*0.00983455882, 0, screenSize.Y*-0.01527777777) + + Camera.CoordinateFrame = game.Players.LocalPlayer.Character.Torso.CFrame * cameraPosition * cameraAngle +end + +function toggleCharacterSpin() + rotateCharacter = not rotateCharacter + + if rotateCharacter then + rotateCharacterButton.Text = "Pause" + else + rotateCharacterButton.Text = "Rotate" + end + + while rotateCharacter do + wait(0.05) + player.Character.Torso.CFrame = player.Character.Torso.CFrame * CFrame.Angles(0,0.035,0) + end +end + +------------------------- Start Lifelong Connections ----------------------- + + +resizeEvent.Event:connect(function(absSize) + if debounce then return end + + debounce = true + wait() + screenSize = absSize + focusCamera() + debounce = false end) -game.Players.LocalPlayer.CharacterAdded:connect(function() - hasBuildTools = false - if game.Players.LocalPlayer.HasBuildTools then - giveBuildTools() - end - if game.Players.LocalPlayer.PersonalServerRank >= 255 then - giveOwnerTools() - end -end) + +------------------------- End Lifelong Connections ----------------------- + +backpackOpenEvent.Event:connect(backpackOpenHandler) +backpackCloseEvent.Event:connect(backpackCloseHandler) +tabClickedEvent.Event:connect(tabClickHandler) +rotateCharacterButton.MouseButton1Click:connect(toggleCharacterSpin) \ No newline at end of file