add toggle for acrylic, fix roact fragments
This commit is contained in:
parent
3b327ea260
commit
3d641b34ce
8 changed files with 167 additions and 6 deletions
119
src/StarterPlayer/StarterPlayerScripts/ui/config/config.tsx
Normal file
119
src/StarterPlayer/StarterPlayerScripts/ui/config/config.tsx
Normal file
|
@ -0,0 +1,119 @@
|
|||
import Roact from "@rbxts/roact"
|
||||
import Padding from "ReplicatedStorage/ui/components/padding"
|
||||
import Acrylic from "ReplicatedStorage/ui/components/acrylic"
|
||||
import { ContextActionService, HttpService } from "@rbxts/services"
|
||||
import { Spring } from "@rbxts/flipper"
|
||||
import { useGroupMotor } from "@rbxts/roact-hooked-plus"
|
||||
import { useEffect } from "@rbxts/roact-hooked"
|
||||
import { useRootProducer } from "ReplicatedStorage/ui/store/hooks/useUiProducer"
|
||||
|
||||
interface ConfigProps extends Roact.JsxInstanceProperties<Frame> {
|
||||
shown: boolean
|
||||
|
||||
Event?: Roact.JsxInstanceEvents<Frame>
|
||||
Change?: Roact.JsxInstanceChangeEvents<Frame>
|
||||
}
|
||||
|
||||
const CONFIG_DEFAULT = [new Spring(1.5, { frequency: 6 })]
|
||||
const CONFIG_ACTIVE = [new Spring(.5, { frequency: 6 })]
|
||||
|
||||
function config(props: ConfigProps): Roact.Element {
|
||||
const { toggleAcrylic } = useRootProducer()
|
||||
|
||||
let { shown } = props
|
||||
|
||||
const spreadableProps = { ...props } as Partial<ConfigProps>
|
||||
delete spreadableProps.shown
|
||||
|
||||
const [slotPosYMap, setPosYGoal] = useGroupMotor([1.5, 6])
|
||||
const slotPosY = slotPosYMap.map((t) => t[0])
|
||||
|
||||
useEffect(() => {
|
||||
const guid = HttpService.GenerateGUID(false)
|
||||
ContextActionService.BindAction(
|
||||
guid,
|
||||
(_, userInputState) => {
|
||||
if (Enum.UserInputState.Begin === userInputState) {
|
||||
shown = !shown
|
||||
if (shown) {
|
||||
setPosYGoal(CONFIG_ACTIVE)
|
||||
} else {
|
||||
setPosYGoal(CONFIG_DEFAULT)
|
||||
}
|
||||
}
|
||||
},
|
||||
false,
|
||||
Enum.KeyCode.P
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<frame
|
||||
{...spreadableProps}
|
||||
AnchorPoint={new Vector2(.5, .5)}
|
||||
Position={
|
||||
slotPosY.map((posY) => {
|
||||
return new UDim2(.5, 0, posY, 0)
|
||||
})
|
||||
}
|
||||
BackgroundTransparency={1}
|
||||
Size={new UDim2(.4, 0, .7, 0)}
|
||||
Key={"Config"}
|
||||
>
|
||||
{/* u can move cursor in first person */}
|
||||
<textbutton
|
||||
Size={new UDim2(1, 0, 1 ,0)}
|
||||
Modal={true}
|
||||
Visible={false}
|
||||
/>
|
||||
<Acrylic
|
||||
radius={2}
|
||||
distance={0.001}
|
||||
/>
|
||||
<frame
|
||||
AnchorPoint={new Vector2(0, 0)}
|
||||
Position={new UDim2(0, 0, 0, 0)}
|
||||
Size={new UDim2(1, 0, 1, 0)}
|
||||
BackgroundTransparency={.7}
|
||||
BackgroundColor3={Color3.fromHex("#1e1e2e")}
|
||||
>
|
||||
<uilistlayout
|
||||
Padding={new UDim(0, 5)}
|
||||
VerticalAlignment={Enum.VerticalAlignment.Top}
|
||||
HorizontalAlignment={Enum.HorizontalAlignment.Left}
|
||||
FillDirection={Enum.FillDirection.Vertical}
|
||||
/>
|
||||
<uicorner
|
||||
CornerRadius={new UDim(0, 2)}
|
||||
/>
|
||||
<Padding
|
||||
padding={new UDim(0, 5)}
|
||||
/>
|
||||
<textbutton
|
||||
Size={new UDim2(1, 0, .1, 0)}
|
||||
Font={Enum.Font.Gotham}
|
||||
TextXAlignment={Enum.TextXAlignment.Left}
|
||||
BackgroundTransparency={.5}
|
||||
BackgroundColor3={Color3.fromHex("#11111b")}
|
||||
AutoButtonColor={false}
|
||||
TextColor3={Color3.fromHex("#cdd6f4")}
|
||||
TextScaled
|
||||
Text={"Toggle acrylic UI"}
|
||||
Event={{
|
||||
Activated: (): void => {toggleAcrylic()}
|
||||
}}
|
||||
>
|
||||
<Padding
|
||||
paddingY={new UDim(.3, 0)}
|
||||
paddingX={new UDim(0, 5)}
|
||||
/>
|
||||
<uicorner
|
||||
CornerRadius={new UDim(0, 2)}
|
||||
/>
|
||||
</textbutton>
|
||||
</frame>
|
||||
</frame>
|
||||
)
|
||||
}
|
||||
|
||||
export default config
|
Loading…
Add table
Add a link
Reference in a new issue