Skip to content

Commit

Permalink
Merge pull request #61 from RyanLua/topbar-plus
Browse files Browse the repository at this point in the history
Move from UIShelf to TopbarPlus v3
  • Loading branch information
RyanLua committed Jun 18, 2024
2 parents 29b32d3 + 05b63f6 commit ee27a3c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 92 deletions.
19 changes: 0 additions & 19 deletions develop.project.json

This file was deleted.

62 changes: 29 additions & 33 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local TOOLTIP_OFFSET: number = -5 -- From to
-- Topbar icons
local ARROW_IMAGE_OPEN: string = "rbxasset://textures/ui/TopBar/inventoryOn.png"
local ARROW_IMAGE_CLOSE: string = "rbxasset://textures/ui/TopBar/inventoryOff.png"
local ARROW_HOTKEY: { Enum.KeyCode } = { Enum.KeyCode.Backquote, Enum.KeyCode.DPadUp } --TODO: Hookup '~' too?
-- local ARROW_HOTKEY: { Enum.KeyCode } = { Enum.KeyCode.Backquote, Enum.KeyCode.DPadUp } --TODO: Hookup '~' too?

-- Hotbar slots
local HOTBAR_SLOTS_FULL: number = 10 -- 10 is the max
Expand Down Expand Up @@ -154,7 +154,23 @@ local GAMEPAD_INPUT_TYPES: { [Enum.UserInputType]: boolean } =
-- Topbar logic
local BackpackEnabled: boolean = true

local UIShelf: any = require(script.Packages.UIShelf)
local Icon: any = require(script.Packages:WaitForChild("topbarplus"))

local inventoryIcon: any = Icon.new()
:setName("Inventory")
:setImage(ARROW_IMAGE_OPEN, "Selected")
:setImage(ARROW_IMAGE_CLOSE, "Deselected")
:setImageScale(1)
:setCaption("Inventory")
:bindToggleKey(Enum.KeyCode.Backquote)
:autoDeselect(false)
:setOrder(-1)

inventoryIcon.toggled:Connect(function(): ()
if not GuiService.MenuIsOpen then
BackpackScript.OpenClose()
end
end)

local BackpackGui: ScreenGui = Instance.new("ScreenGui")
BackpackGui.DisplayOrder = 120
Expand Down Expand Up @@ -191,17 +207,6 @@ local Character: Model = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: any = Character:WaitForChild("Humanoid")
local Backpack: Instance = Player:WaitForChild("Backpack")

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: any = nil
local SlotsByTool = {} -- Map of Tools to their assigned Slots
Expand All @@ -225,7 +230,7 @@ local BackpackPanel = nil
local lastEquippedSlot: any = nil

local function EvaluateBackpackPanelVisibility(enabled: boolean): boolean
return enabled and InventoryIcon.enabled and BackpackEnabled and VRService.VREnabled
return enabled and inventoryIcon.enabled and BackpackEnabled and VRService.VREnabled
end

local function ShowVRBackpackPopup(): ()
Expand Down Expand Up @@ -792,7 +797,7 @@ local function MakeSlot(parent: Instance, initIndex: number?): GuiObject
startPoint = dragPoint

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

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

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

-- Restore height
SlotFrame.ZIndex = 1
Expand Down Expand Up @@ -1100,7 +1105,7 @@ local function OnInputBegan(input: InputObject, isProcessed: boolean): ()
if not isProcessed then
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 @@ -1401,10 +1406,10 @@ function vrMoveSlotToInventory(): ()
end

function enableGamepadInventoryControl(): ()
local goBackOneLevel = function(inputState: Enum.UserInputState): ()
if inputState ~= Enum.UserInputState.Begin then
return
end
local goBackOneLevel = function(): ()
-- if inputState ~= Enum.UserInputState.Begin then
-- return
-- end

local selectedSlot: any = getGamepadSwapSlot()
if selectedSlot then
Expand All @@ -1415,7 +1420,7 @@ function enableGamepadInventoryControl(): ()
return
end
elseif InventoryFrame.Visible then
BackpackScript.OpenClose()
inventoryIcon:deselect()
end
end

Expand Down Expand Up @@ -1489,11 +1494,6 @@ end
local function OnIconChanged(enabled: boolean): ()
-- Check for enabling/disabling the whole thing
enabled = enabled and StarterGui:GetCore("TopbarEnabled")
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 @@ -1566,12 +1566,6 @@ for index: number = 1, NumberOfHotbarSlots do
end
end

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

local LeftBumperButton: ImageLabel = Instance.new("ImageLabel")
LeftBumperButton.BackgroundTransparency = 1
LeftBumperButton.Name = "LeftBumper"
Expand Down Expand Up @@ -2007,11 +2001,13 @@ end
-- When menu is opend, disable backpack
GuiService.MenuOpened:Connect(function(): ()
BackpackGui.Enabled = false
inventoryIcon:setEnabled(false)
end)

-- When menu is closed, enable backpack
GuiService.MenuClosed:Connect(function(): ()
BackpackGui.Enabled = true
inventoryIcon:setEnabled(true)
end)

do -- Make the Inventory expand/collapse arrow (unless TopBar)
Expand Down
12 changes: 6 additions & 6 deletions test.project.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "Satchel",
"name": "Test Satchel",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"$path": "Packages"
},

"StarterPlayer": {
"$className": "StarterPlayer",

"StarterPlayerScripts": {
"$className": "StarterPlayerScripts",

"Test": {
"$path": "tests/Test.client.luau",
"$path": "tests/Test.client.lua",

"Satchel": {
"$path": "src"
}
Expand Down
13 changes: 0 additions & 13 deletions tests/Develop.client.luau

This file was deleted.

3 changes: 1 addition & 2 deletions tests/Test.client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
]]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TestEZ = require(ReplicatedStorage:WaitForChild("testez"))

local Satchel = script:WaitForChild("Satchel")
local TestEZ = require(Satchel.Packages:WaitForChild("testez"))

require(Satchel) -- Initialize Satchel
TestEZ.TestBootstrap:run({ Satchel }) -- Run Tests
21 changes: 3 additions & 18 deletions wally.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@
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"
name = "1foreverhd/topbarplus"
version = "3.0.2"
dependencies = []

[[package]]
Expand All @@ -30,4 +15,4 @@ dependencies = []
[[package]]
name = "ryanlua/satchel"
version = "1.2.0"
dependencies = [["UIShelf", "canary-development/uishelf@1.1.5"], ["testez", "roblox/testez@0.4.1"]]
dependencies = [["testez", "roblox/testez@0.4.1"], ["topbarplus", "1foreverhd/topbarplus@3.0.2"]]
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ exclude = ["**"]
include = ["src", "src/*", "default.project.json", "wally.lock", "wally.toml"]

[dependencies]
UIShelf = "canary-development/uishelf@1.1.5"
topbarplus = "1foreverhd/topbarplus@3.0.2"
testez = "roblox/testez@0.4.1"

0 comments on commit ee27a3c

Please sign in to comment.