|
3 | 3 | local GuiService = game:GetService("GuiService") |
4 | 4 | local Players = game:GetService("Players") |
5 | 5 | local StarterGui = game:GetService("StarterGui") |
| 6 | +local UserInputService = game:GetService("UserInputService") |
6 | 7 |
|
7 | 8 | local React = require(script.Parent.Parent.react) |
8 | 9 | local ReactRoblox = require(script.Parent.Parent["react-roblox"]) |
| 10 | +local closeInventory = require(script.Parent.Api.closeInventory) |
9 | 11 |
|
10 | 12 | local App = require(script.Parent.Components.App) |
11 | 13 |
|
@@ -36,34 +38,56 @@ local function Satchel() |
36 | 38 | local inventoryClosedSignal = bindableEvents.InventoryClosed.Event:Connect(function() |
37 | 39 | setOpened(false) |
38 | 40 | end) |
| 41 | + local menuOpenedSignal = GuiService.MenuOpened:Connect(function() |
| 42 | + closeInventory() |
| 43 | + end) |
39 | 44 |
|
40 | 45 | return function() |
41 | 46 | inventoryOpenedSignal:Disconnect() |
42 | 47 | inventoryClosedSignal:Disconnect() |
| 48 | + menuOpenedSignal:Disconnect() |
43 | 49 | end |
44 | 50 | end, {}) |
45 | 51 |
|
| 52 | + -- Close backpack when clicking outside of it |
| 53 | + UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean) |
| 54 | + local inputType = input.UserInputType |
| 55 | + if not gameProcessedEvent then |
| 56 | + if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then |
| 57 | + closeInventory() |
| 58 | + end |
| 59 | + end |
| 60 | + end) |
| 61 | + |
46 | 62 | -- Change slots based on viewport display size |
47 | 63 | local slots, setSlots = React.useState(10) |
48 | 64 | local rows, setRows = React.useState(4) |
49 | 65 |
|
50 | 66 | React.useEffect(function() |
51 | | - local function viewportDisplaySizeChanged() |
| 67 | + local function updateBackpackSize() |
| 68 | + local screenOrientation = playerGui.CurrentScreenOrientation |
52 | 69 | local viewportSize = GuiService.ViewportDisplaySize |
53 | | - if viewportSize == Enum.DisplaySize.Small then |
54 | | - setSlots(5) |
| 70 | + |
| 71 | + if screenOrientation == Enum.ScreenOrientation.Portrait then |
| 72 | + setSlots(3) |
55 | 73 | setRows(3) |
| 74 | + elseif viewportSize == Enum.DisplaySize.Small then |
| 75 | + setSlots(5) |
| 76 | + setRows(2) |
56 | 77 | else |
57 | 78 | setSlots(10) |
58 | 79 | setRows(4) |
59 | 80 | end |
60 | 81 | end |
61 | 82 |
|
62 | | - viewportDisplaySizeChanged() |
63 | | - local signal = GuiService:GetPropertyChangedSignal("ViewportDisplaySize"):Connect(viewportDisplaySizeChanged) |
| 83 | + updateBackpackSize() |
| 84 | + local viewportSignal = GuiService:GetPropertyChangedSignal("ViewportDisplaySize"):Connect(updateBackpackSize) |
| 85 | + local orientationSignal = |
| 86 | + playerGui:GetPropertyChangedSignal("CurrentScreenOrientation"):Connect(updateBackpackSize) |
64 | 87 |
|
65 | 88 | return function() |
66 | | - signal:Disconnect() |
| 89 | + viewportSignal:Disconnect() |
| 90 | + orientationSignal:Disconnect() |
67 | 91 | end |
68 | 92 | end, {}) |
69 | 93 |
|
|
0 commit comments