Skip to content

Commit

Permalink
Merge pull request #30 from RyanLua/chrome-topbar
Browse files Browse the repository at this point in the history
Add support for chrome topbar using UIShelf
  • Loading branch information
RyanLua authored Dec 14, 2023
2 parents 6067dde + d39da0c commit 78f1b9e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ luac.out
*.x86_64
*.hex

# Wally

Packages
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion modules/TopbarPlus
Submodule TopbarPlus deleted from 8ae9b4
6 changes: 6 additions & 0 deletions src/Satchel/Packages.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Packages",
"tree": {
"$path": "../../Packages"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

local ContextActionService = game:GetService("ContextActionService")
local TextChatService = game:GetService("TextChatService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local StarterGui = game:GetService("StarterGui")
local GuiService = game:GetService("GuiService")
Expand Down Expand Up @@ -144,19 +143,7 @@ local GAMEPAD_INPUT_TYPES: table = { -- These are the input types that will be u
-- Topbar logic
local BackpackEnabled: boolean = true

local function GetIconModule(): ModuleScript
local ReplicatedIconModule: ModuleScript = ReplicatedStorage:FindFirstChild("Icon")
local LocalIconModule: ModuleScript = script.Icon

if ReplicatedIconModule and ReplicatedIconModule:IsA("ModuleScript") then
LocalIconModule:Destroy()
return ReplicatedIconModule
else
return LocalIconModule
end
end

local Icon: table = require(GetIconModule())
local UIShelf: any = require(script.Parent.Packages.UIShelf)

local BackpackGui = Instance.new("ScreenGui")
BackpackGui.DisplayOrder = 120
Expand Down Expand Up @@ -192,15 +179,16 @@ local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Backpack = Player:WaitForChild("Backpack")

local InventoryIcon = Icon.new()
InventoryIcon:setImage(ARROW_IMAGE_CLOSE, "deselected")
InventoryIcon:setImage(ARROW_IMAGE_OPEN, "selected")
-- InventoryIcon:setTheme(Themes.BlueGradient)
InventoryIcon:bindToggleKey(ARROW_HOTKEY[1], ARROW_HOTKEY[2])
InventoryIcon:setName("InventoryIcon")
InventoryIcon:setImageYScale(1.12)
InventoryIcon:setOrder(-5)
InventoryIcon.deselectWhenOtherIconSelected = false
local InventoryIcon: any = UIShelf.CreateIcon({
Name = "Backpack",
Image = ARROW_IMAGE_CLOSE,
Order = 1,
Area = UIShelf.HorizontalAlignment.Left,
})
InventoryIcon:BindKeyCode(ARROW_HOTKEY[1], ARROW_HOTKEY[2])
InventoryIcon:SetTooltip("Backpack")
InventoryIcon:SetImageSize(Vector2.new(40, 40))
InventoryIcon:SetImage(ARROW_IMAGE_CLOSE)

local Slots = {} -- List of all Slots by index
local LowestEmptySlot = nil
Expand Down Expand Up @@ -779,7 +767,7 @@ local function MakeSlot(parent: Instance, index: number): GuiObject
startPoint = dragPoint

SlotFrame.BorderSizePixel = 2
InventoryIcon:lock()
-- InventoryIcon:lock()

-- Raise above other slots
SlotFrame.ZIndex = 2
Expand Down Expand Up @@ -826,7 +814,7 @@ local function MakeSlot(parent: Instance, index: number): GuiObject
SlotFrame.Parent = startParent

SlotFrame.BorderSizePixel = 0
InventoryIcon:unlock()
-- InventoryIcon:unlock()

-- Restore height
SlotFrame.ZIndex = 1
Expand Down Expand Up @@ -1063,7 +1051,6 @@ local function OnInputBegan(input: InputObject, isProcessed: boolean): ()
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
if InventoryFrame.Visible then
BackpackScript.OpenClose()
InventoryIcon:deselect()
end
end
end
Expand Down Expand Up @@ -1378,8 +1365,6 @@ function enableGamepadInventoryControl()
selectedSlot.Frame.BorderSizePixel = 0
return
end
elseif InventoryFrame.Visible then
InventoryIcon:deselect()
end
end

Expand Down Expand Up @@ -1453,7 +1438,11 @@ end
local function OnIconChanged(enabled: boolean): ()
-- Check for enabling/disabling the whole thing
enabled = enabled and StarterGui:GetCore("TopbarEnabled")
InventoryIcon:setEnabled(enabled and not GuiService.MenuIsOpen)
if InventoryFrame.Visible then
InventoryIcon:SetImage(ARROW_IMAGE_OPEN)
else
InventoryIcon:SetImage(ARROW_IMAGE_CLOSE)
end
WholeThingEnabled = enabled
MainFrame.Visible = enabled

Expand Down Expand Up @@ -1514,16 +1503,11 @@ for i = 1, NumberOfHotbarSlots do
end
end

InventoryIcon.selected:Connect(function(): ()
InventoryIcon.Activated:Connect(function()
if not GuiService.MenuIsOpen then
BackpackScript.OpenClose()
end
end)
InventoryIcon.deselected:Connect(function(): ()
if InventoryFrame.Visible then
BackpackScript.OpenClose()
end
end)

local LeftBumperButton = NewGui("ImageLabel", "LeftBumper")
LeftBumperButton.Size = UDim2.new(0, 40, 0, 40)
Expand Down Expand Up @@ -1912,7 +1896,7 @@ do -- Search stuff
searchBox.FocusLost:Connect(focusLost)

BackpackScript.StateChanged.Event:Connect(function(isNowOpen: boolean): ()
InventoryIcon:getInstance("iconButton").Modal = isNowOpen -- Allows free mouse movement even in first person
-- InventoryIcon:getInstance("iconButton").Modal = isNowOpen -- Allows free mouse movement even in first person

if not isNowOpen then
reset()
Expand All @@ -1922,11 +1906,8 @@ do -- Search stuff
HotkeyFns[Enum.KeyCode.Escape.Value] = function(isProcessed: any): ()
if isProcessed then -- Pressed from within a TextBox
reset()
elseif InventoryFrame.Visible then
InventoryIcon:deselect()
end
end

local function detectGamepad(lastInputType: Enum.UserInputType): ()
if lastInputType == Enum.UserInputType.Gamepad1 and not UserInputService.VREnabled then
searchFrame.Visible = false
Expand All @@ -1942,15 +1923,13 @@ local menuClosed = false
GuiService.MenuOpened:Connect(function(): ()
BackpackGui.Enabled = false
if InventoryFrame.Visible then
InventoryIcon:deselect()
menuClosed = true
end
end)

GuiService.MenuClosed:Connect(function(): ()
BackpackGui.Enabled = true
if menuClosed then
InventoryIcon:select()
menuClosed = false
end
end)
Expand Down
6 changes: 0 additions & 6 deletions src/Satchel/SatchelScript/Icon.project.json

This file was deleted.

22 changes: 21 additions & 1 deletion wally.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@
# It is not intended for manual editing.
registry = "test"

[[package]]
name = "canary-development/uishelf"
version = "1.1.5"
dependencies = [["Signal", "red-blox/signal@1.0.0"]]

[[package]]
name = "red-blox/promise"
version = "1.1.1"
dependencies = [["Spawn", "red-blox/spawn@1.0.0"]]

[[package]]
name = "red-blox/signal"
version = "1.0.0"
dependencies = [["Promise", "red-blox/promise@1.1.1"], ["Spawn", "red-blox/spawn@1.0.0"]]

[[package]]
name = "red-blox/spawn"
version = "1.0.0"
dependencies = []

[[package]]
name = "ryanlua/satchel"
version = "1.2.0"
dependencies = []
dependencies = [["UIShelf", "canary-development/uishelf@1.1.5"]]
3 changes: 3 additions & 0 deletions wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ authors = ["Ryan Luu <ryan.luu@ryanluu.dev>"]
realm = "shared"
registry = "https://github.com/UpliftGames/wally-index"
exclude = ["assets"]

[dependencies]
UIShelf = "canary-development/uishelf@1.1.5"

0 comments on commit 78f1b9e

Please sign in to comment.