@@ -38,6 +38,9 @@ local DEBOUNCE_TIME = 0.25
3838local defeatableTopbarSuccess , defeatableTopbarFlagValue = pcall (function () return settings ():GetFFlag (" EnableSetCoreTopbarEnabled" ) end )
3939local defeatableTopbar = (defeatableTopbarSuccess and defeatableTopbarFlagValue == true )
4040
41+ local vr3dGuisSuccess , vr3dGuisFlagValue = pcall (function () return settings ():GetFFlag (" RenderUserGuiIn3DSpace" ) end )
42+ local vr3dGuis = (vr3dGuisSuccess and vr3dGuisFlagValue == true )
43+
4144--[[ END OF FFLAG VALUES ]]
4245
4346
@@ -50,6 +53,7 @@ local InputService = game:GetService('UserInputService')
5053local StarterGui = game :GetService (' StarterGui' )
5154local ContextActionService = game :GetService (" ContextActionService" )
5255local RunService = game :GetService (' RunService' )
56+ local TextService = game :GetService (' TextService' )
5357
5458--[[ END OF SERVICES ]]
5559
@@ -511,7 +515,12 @@ local function Create3DMenuItem()
511515
512516 function menuItem :SetHoverText (text )
513517 hoverTextLabel .Text = text
514- local frameWidth = hoverTextLabel .TextBounds .X + 20
518+ local textSize = TextService :GetTextSize (
519+ hoverTextLabel .Text ,
520+ 24 ,
521+ hoverTextLabel .Font ,
522+ Vector2 .new (1000 , 10000 ))
523+ local frameWidth = textSize .x + 20
515524 hoverTextFrame .Position = UDim2 .new (0.5 , - frameWidth / 2 , 0 , 55 )
516525 hoverTextFrame .Size = UDim2 .new (0 , frameWidth , 0 , 60 )
517526 end
@@ -1253,6 +1262,70 @@ local function Create3DChatIcon(topBarInstance, panel, menubar)
12531262 return menuItem
12541263end
12551264
1265+ local function Create3DUserGuiToggleIcon (topBarInstance , panel , menubar )
1266+ local menuItem = Create3DMenuItem ()
1267+ menuItem :SetHoverText (" 2D UI" )
1268+
1269+ local icon = Util .Create " ImageLabel" {
1270+ Parent = menuItem :GetInstance (),
1271+
1272+ Position = UDim2 .new (0.5 , - 14 , 0.5 , - 14 ),
1273+ Size = UDim2 .new (0 , 28 , 0 , 28 ),
1274+
1275+ BackgroundTransparency = 1 ,
1276+
1277+ Image = " rbxasset://textures/ui/VR/toggle2D.png"
1278+ }
1279+
1280+ local userGuiPanel = Panel3D .Get (" UserGui" )
1281+ userGuiPanel :SetType (Panel3D .Type .Fixed )
1282+ userGuiPanel :ResizePixels (300 , 125 )
1283+ userGuiPanel :SetVisible (false , false )
1284+
1285+ menuItem .MouseButton1Click :connect (function ()
1286+ if InputService .VREnabled then
1287+ userGuiPanel :SetVisible (not userGuiPanel .isVisible , false )
1288+ end
1289+ end )
1290+
1291+ function userGuiPanel :OnVisibilityChanged (visible )
1292+ if visible then
1293+ local headLook = Panel3D .GetHeadLookXZ (true )
1294+ userGuiPanel .localCF = headLook * CFrame .Angles (math.rad (5 ), 0 , 0 ) * CFrame .new (0 , 0 , 5 )
1295+ end
1296+ menuItem :SetActive (visible )
1297+ local success , msg = pcall (function ()
1298+ CoreGuiService :SetUserGuiRendering (true , visible and userGuiPanel :GetPart () or nil , Enum .NormalId .Front )
1299+ end )
1300+ if not success then
1301+ print (" Topbar - userGuiPanel:OnVisibilityChanged:" , msg )
1302+ end
1303+ end
1304+
1305+ local function OnVREnabled (prop )
1306+ if prop == ' VREnabled' then
1307+ local guiPart = nil
1308+ if InputService .VREnabled then
1309+ if userGuiPanel .isVisible then
1310+ guiPart = userGuiPanel :GetPart ()
1311+ end
1312+ else
1313+ userGuiPanel :SetVisible (false , false )
1314+ end
1315+ local success , msg = pcall (function ()
1316+ CoreGuiService :SetUserGuiRendering (InputService .VREnabled , guiPart , Enum .NormalId .Front )
1317+ end )
1318+ if not success then
1319+ print (" Topbar - OnVREnabled:" , msg )
1320+ end
1321+ end
1322+ end
1323+ InputService .Changed :connect (OnVREnabled )
1324+ spawn (function () OnVREnabled (" VREnabled" ) end )
1325+
1326+ return menuItem
1327+ end
1328+
12561329---- -------
12571330
12581331--- Backpack ---
@@ -1346,6 +1419,7 @@ local nameAndHealthMenuItem = CreateUsernameHealthMenuItem()
13461419
13471420local settingsIcon3D = Create3DSettingsIcon (TopBar , Topbar3DPanel , ThreeDMenubar )
13481421local chatIcon3D = Create3DChatIcon (TopBar , Topbar3DPanel , ThreeDMenubar )
1422+ local userGuiIcon3D = Create3DUserGuiToggleIcon (TopBar , Topbar3DPanel , ThreeDMenubar )
13491423
13501424local LEFT_ITEM_ORDER = {}
13511425local RIGHT_ITEM_ORDER = {}
@@ -1382,6 +1456,9 @@ end
13821456if chatIcon3D then
13831457 THREE_D_ITEM_ORDER [chatIcon3D ] = 2
13841458end
1459+ if userGuiIcon3D then
1460+ THREE_D_ITEM_ORDER [userGuiIcon3D ] = 3
1461+ end
13851462
13861463---- ---------------------
13871464
@@ -1476,6 +1553,39 @@ if nameAndHealthMenuItem and topbarEnabled and not isTenFootInterface then
14761553 AddItemInOrder (RightMenubar , nameAndHealthMenuItem , RIGHT_ITEM_ORDER )
14771554end
14781555
1556+ if userGuiIcon3D and vr3dGuis then
1557+ local function FindScreenGuiChild (object )
1558+ for _ , child in pairs (object :GetChildren ()) do
1559+ if child :IsA (' ScreenGui' ) then
1560+ return child
1561+ end
1562+ end
1563+ end
1564+
1565+ local function onPlayerGuiAdded (playerGui )
1566+ playerGui .ChildAdded :connect (function (child )
1567+ if FindScreenGuiChild (playerGui ) then
1568+ AddItemInOrder (ThreeDMenubar , userGuiIcon3D , THREE_D_ITEM_ORDER )
1569+ end
1570+ end )
1571+ playerGui .ChildRemoved :connect (function (child )
1572+ if child :IsA (' ScreenGui' ) and not FindScreenGuiChild (playerGui ) then
1573+ ThreeDMenubar :RemoveItem (userGuiIcon3D )
1574+ end
1575+ end )
1576+ if FindScreenGuiChild (playerGui ) then
1577+ AddItemInOrder (ThreeDMenubar , userGuiIcon3D , THREE_D_ITEM_ORDER )
1578+ end
1579+ end
1580+ Player .ChildAdded :connect (function (child )
1581+ if child :IsA (' PlayerGui' ) then
1582+ onPlayerGuiAdded (child )
1583+ end
1584+ end )
1585+ if Player :FindFirstChild (' PlayerGui' ) then
1586+ onPlayerGuiAdded (Player :FindFirstChild (' PlayerGui' ))
1587+ end
1588+ end
14791589
14801590
14811591local function MoveHamburgerTo3D ()
0 commit comments