From bbf70cf8690911b917437cc2209b7d09be441382 Mon Sep 17 00:00:00 2001 From: reidlab Date: Tue, 15 Aug 2023 22:20:02 -0700 Subject: [PATCH] finish hotbar (i think) --- package.json | 2 ++ .../StarterPlayerScripts/ui/hotbar/slot.tsx | 27 ++++++++++++++----- yarn.lock | 15 ++++++++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4fef381..f637509 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@rbxts/character-promise": "^1.0.2", + "@rbxts/flipper": "^2.0.1", "@rbxts/log": "^0.6.3", "@rbxts/make": "^1.0.6", "@rbxts/matter": "^0.6.2-ts.6", @@ -41,6 +42,7 @@ "@rbxts/rewire": "^0.3.0", "@rbxts/roact": "^1.4.4-ts.0", "@rbxts/roact-hooked": "^2.6.0", + "@rbxts/roact-hooked-plus": "^1.8.1", "@rbxts/roact-reflex": "^2.1.0", "@rbxts/services": "^1.5.1", "@rbxts/testez": "^0.4.2-ts.0", diff --git a/src/StarterPlayer/StarterPlayerScripts/ui/hotbar/slot.tsx b/src/StarterPlayer/StarterPlayerScripts/ui/hotbar/slot.tsx index 1fe0ad8..27f718b 100644 --- a/src/StarterPlayer/StarterPlayerScripts/ui/hotbar/slot.tsx +++ b/src/StarterPlayer/StarterPlayerScripts/ui/hotbar/slot.tsx @@ -4,6 +4,8 @@ import { useWorldContext } from "../contexts/worldContext" import { ContextActionService, HttpService } from "@rbxts/services" import Padding from "ReplicatedStorage/ui/components/padding" import Acrylic from "ReplicatedStorage/ui/components/acrylic" +import { Spring } from "@rbxts/flipper" +import { useGroupMotor } from "@rbxts/roact-hooked-plus" interface SlotProps extends Roact.JsxInstanceProperties { index: number @@ -14,6 +16,9 @@ interface SlotProps extends Roact.JsxInstanceProperties { Change?: Roact.JsxInstanceChangeEvents } +const SLOT_DEFAULT = [new Spring(.7, { frequency: 6 }), new Spring(6, { frequency: 6 })] +const SLOT_ACTIVE = [new Spring(.5, { frequency: 6 }), new Spring(5, { frequency: 6 })] + function slot(props: SlotProps): Roact.Element { const { index, keycode, tool } = props @@ -22,13 +27,19 @@ function slot(props: SlotProps): Roact.Element { delete spreadableProps.keycode delete spreadableProps.tool + const [slotBgTransparencyAndSlotRatio, setSlotGoal] = useGroupMotor([.7, 6]) + const slotBgTransparency = slotBgTransparencyAndSlotRatio.map((t) => t[0]) + const slotRatio = slotBgTransparencyAndSlotRatio.map((t) => t[1]) + const { clientState } = useWorldContext() const handleActivated = (): void => { if (tool.Parent !== clientState.character) { clientState.character.Humanoid.EquipTool(tool) + setSlotGoal(SLOT_ACTIVE) } else { clientState.character.Humanoid.UnequipTools() + setSlotGoal(SLOT_DEFAULT) } } @@ -43,25 +54,27 @@ function slot(props: SlotProps): Roact.Element { false, keycode ) + + tool.Unequipped.Connect(() => { + setSlotGoal(SLOT_DEFAULT) + }) }) return (