local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local StarterGui = game:GetService("StarterGui") local BotData = require(ReplicatedStorage.Data.BotData) local InventoryClient = require(script.Parent.InventoryClient) local DataTypes = require(ReplicatedStorage.Data.DataTypes) local Signal = require(ReplicatedStorage.Shared.SharedUtils.Signal) local sharedBotUtils = require(ReplicatedStorage.Shared.SharedUtils.sharedBotUtils) local GarageUIHandler = {} local localPlayer = Players.LocalPlayer local PlayerGui = localPlayer.PlayerGui local GarageGui = PlayerGui:WaitForChild("GarageGui") local WorldOverlay = GarageGui:WaitForChild("WorldOverlay") local nav_Left = GarageGui.Navigation.Left local nav_Right = GarageGui.Navigation.Right local StatusHUD = GarageGui:WaitForChild("StatusHUD") local TopCenter = GarageGui:WaitForChild("TopCenter") local BotName = TopCenter:WaitForChild("BotName") local SkinName = TopCenter:WaitForChild("SkinName") local Drawer = GarageGui:WaitForChild("Drawer") local SelectedTab = Drawer:WaitForChild("SelectedTab") local Selector = SelectedTab:WaitForChild("Selector") local Handle = Drawer:WaitForChild("Handle") local Tabs = Drawer:WaitForChild("Tabs") local t_Accessories = Tabs:WaitForChild("Accessories") local t_Skins = Tabs:WaitForChild("Skins") local t_Tanks = Tabs:WaitForChild("Tanks") local SafetyDrawer = Drawer:WaitForChild("SafetyDrawer") local ScrollingFrame = SafetyDrawer:WaitForChild("ScollingFrame") local InteractionContainer = SafetyDrawer:WaitForChild("InteractionContainer") local BuyContainer = InteractionContainer:WaitForChild("BuyContainer") local BuyButton = BuyContainer:WaitForChild("LowerButton") local EquipIndicator = BuyContainer:WaitForChild("Indicator") local EquipContainer = InteractionContainer:WaitForChild("EquipContainer") local EquipButton = EquipContainer:WaitForChild("LowerButton") local EquipIndicator = EquipContainer:WaitForChild("Indicator") type Inventory = DataTypes.Inventory local Models = ReplicatedStorage.Assets.Models local ITEM_TEMPLATE = ReplicatedStorage.Assets.UI:WaitForChild("ITEM_TEMPLATE") --t is a tab button :) local HANDLE_UP_POSITION = UDim2.new(-0.005, 0, 0.773, 0) local HANDLE_DOWN_POSITION = UDim2.new(-0.005, 0, 0.97, 0) local _cachedItemTable = {} function _moveTabSelector(t: TextButton) print(t.AbsoluteSize) Selector.Size = UDim2.fromOffset(t.AbsoluteSize.X, t.AbsoluteSize.Y) Selector.Position = UDim2.fromOffset(t.AbsolutePosition.X, t.AbsolutePosition.Y) end function _cleanUpItems() for _, v in pairs(ScrollingFrame:GetChildren()) do if v:IsA("ImageButton") then v:Destroy() end end table.clear(_cachedItemTable) end function _newTemplate(model: Model) local new = ITEM_TEMPLATE:Clone() model.Parent = new.Viewport new.Viewport.CurrentCamera = Instance.new("Camera", new.Viewport) new.Viewport.CurrentCamera.CFrame = CFrame.new(Vector3.new(0, 2, 12), model:GetPivot().Position) new.Parent = ScrollingFrame table.insert(_cachedItemTable, new) new.Name = #_cachedItemTable new:SetAttribute("ItemName", model.Name) return new end function GarageUIHandler.SetItems(items, currentTab) _cleanUpItems() for _, itemModel in items do local ui = _newTemplate(itemModel) ui.Activated:Connect(function() GarageUIHandler.Events.OnItemClicked:Fire(itemModel) end) end GarageUIHandler.UpdateItemsState(currentTab) end function _GetAllItems() return _cachedItemTable end function _BrightenItem(item: typeof(ITEM_TEMPLATE)) item.BackgroundTransparency = 0 end function _ShadowItem(item: typeof(ITEM_TEMPLATE)) item.BackgroundTransparency = 0.5 end function _PullHandleUp(anim: boolean?) if anim then Drawer:TweenPosition(HANDLE_UP_POSITION, Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.3) else Drawer.Position = HANDLE_UP_POSITION end end function _PullHandleDown(anim: boolean?) if anim then Drawer:TweenPosition(HANDLE_DOWN_POSITION, Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.3) else Drawer.Position = HANDLE_DOWN_POSITION end end function _TransitionBlack(hide: boolean?) if hide then for i = 0, 100, 5 do local v = i / 100 WorldOverlay.BackgroundTransparency = v task.wait(0.03) end else for i = 100, 0, -5 do local v = i / 100 WorldOverlay.BackgroundTransparency = v task.wait(0.03) end end end function _ToggleVisibility(value: boolean?) value = value or false StatusHUD.Visible = value Drawer.Controls.Visible = value GarageGui.AbilityHUD.Visible = value StatusHUD.Visible = value TopCenter.Visible = value end function GarageUIHandler.Hide(anim: boolean?) _PullHandleDown(anim) if anim then _TransitionBlack(false) end _ToggleVisibility(false) if anim then _TransitionBlack(true) end end function GarageUIHandler.Show(anim: boolean?) _PullHandleUp(anim) if anim then _TransitionBlack(false) end _ToggleVisibility(true) if anim then _TransitionBlack(true) end end function GarageUIHandler.SetActiveTab(t: TextButton) _moveTabSelector(t) end function GarageUIHandler.UpdateItemsState(tabName) for _, item in pairs(_GetAllItems()) do local itemName = item:GetAttribute("ItemName") local can = true if tabName == "Tanks" then can = InventoryClient.HasTank(itemName) elseif tabName == "Skins" then can = InventoryClient.HasSkin(itemName) end if can then _BrightenItem(item) else _ShadowItem(item) end end end GarageUIHandler.Messages = { CANT_AFFORD = "Not Enough Money", CAN_AFFORD = "BUY", CAN_EQUIP = "EQUIP", ALREADY_EQUIPPED = "EQUIPPED", ERROR = "Something went wrong", } GarageUIHandler.Events = { OnTabClicked = Signal.new(), OnItemClicked = Signal.new(), OnBuyClicked = Signal.new(), OnEquipClicked = Signal.new(), OnNavigClicked = Signal.new(), OnHandleClicked = Signal.new(), } function GarageUIHandler:Init() for _, v in pairs(Tabs:GetChildren()) do if not v:IsA("TextButton") then continue end v.Activated:Connect(function() _moveTabSelector(v) GarageUIHandler.Events.OnTabClicked:Fire(v) end) end nav_Left.Activated:Connect(function() GarageUIHandler.Events.OnNavigClicked:Fire(-1) end) nav_Right.Activated:Connect(function() GarageUIHandler.Events.OnNavigClicked:Fire(1) end) EquipButton.Activated:Connect(function() GarageUIHandler.Events.OnEquipClicked:Fire(EquipButton) end) Handle.Activated:Connect(function() GarageUIHandler.Events.OnHandleClicked:Fire() end) end return GarageUIHandler