{"TotalCount":24,"Files":[{"Ident":"dicta.panelrendertarget","Path":"TargetScreen.cs","FileName":"TargetScreen.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using PanelRenderTarget;\nusing Sandbox;\nusing Sandbox.UI;\nusing System;\nusing System.Linq;\n\npublic class TargetScreen : Component, Component.DontExecuteOnServer, ITargetScreen\n{\n\t[Property, Feature( \u0022interaction\u0022 ), Description( \u0022Enable verbose logs for screen mouse detection\u0022 )]\n\tpublic bool DebugMouseTrace { get; set; } = false;\n\n\t[Property] public string ScreenMaterialName { get; set; } = \u0022screen-01\u0022;\n\t[Property] public Material ScreenMaterial { get; set; } = Material.Load( \u0022materials/screen.vmat\u0022 );\n\t[Property] public Vector2Int ScreenTextureSize { get; set; } = new( 1280, 720 );\n\t[Property] public float TraceDistance { get; set; } = 200f;\n\t[Property] public bool ForceUpdate { get; set; } = false;\n\t[Property] public PanelTypeReference PanelType { get; set; } = new();\n\t[Property, Feature( \u0022interaction\u0022 ), Description( \u0022Small UV offset applied after triangle interpolation to correct slight drift\u0022 )]\n\tpublic Vector2 ScreenUvOffset { get; set; } = Vector2.Zero;\n\n\t[Property, Feature(\u0022interaction\u0022), Description(\u0022interact with 2d mouse cursor\u0022)]\n\tpublic bool ScreenCursorInteraction { get; set; } = false;\n\n\t[Property,Feature(\u0022interaction\u0022), Description(\u0022whether to show the virtual cursor\u0022) ]\n\tpublic bool ShowVirtualCursor { get; set; } = true;\n\n\t[Property, Feature( \u0022Optimisation\u0022 ), Description(\u0022fps when the panel is focused\u0022) ]\n\tpublic int UpdateRateFocus { get; set; } = 60;\n\n\t[Property, Feature(\u0022Optimisation\u0022)]\n\tpublic bool UpdateWhenNotFocused { get; set; } = false;\n\n\t[Property, Feature( \u0022Optimisation\u0022 ), Description( \u0022fps update rate when the panel is visible in camera\u0022 ) ]\n\tpublic int UpdateRateNotFocused { get; set; } = 30;\n\n\t[Property, Feature( \u0022Optimisation\u0022 ), Description(\u0022the distance of the update rate visible but not focus\u0022) ]\n\tpublic int UpdateDistanceMax { get; set; } = 500;\n\n\n\tprivate bool _firstUpdate = false;\n\n\n\n\tprivate readonly TargetPanelInput _input = new();\n\n\tpublic ModelRenderer Renderer { get; private set; }\n\tprivate Material _screenMaterialCopy;\n\tprivate Texture _screenTexture;\n\tprivate TargetRootPanel _rootPanel;\n\tprivate PanelSceneObject _panelObject;\n\tprivate Vertex[] _cachedVertices;\n\tprivate uint[] _cachedIndices;\n\tprivate Model _cachedMeshModel;\n\tprivate TriangleMaterialRange[] _cachedTriangleMaterialRanges = Array.Empty\u003CTriangleMaterialRange\u003E();\n\tprivate double _tracePerfAccumMs;\n\tprivate double _tracePerfMaxMs;\n\tprivate double _tracePerfCacheAccumMs;\n\tprivate double _tracePerfTrianglesAccumMs;\n\tprivate int _tracePerfSamples;\n\tprivate TimeSince _tracePerfLogTimer;\n\n\tprivate readonly struct TriangleMaterialRange\n\t{\n\t\tpublic int StartTriangle { get; init; }\n\t\tpublic int EndTriangleExclusive { get; init; }\n\t\tpublic Material Material { get; init; }\n\t}\n\n\tprotected Panel Panel { get; private set; }\n\tpublic TargetRootPanel RootPanel =\u003E _rootPanel;\n\tpublic PanelSceneObject PanelObject =\u003E _panelObject;\n\tprotected Texture ScreenTexture =\u003E _screenTexture;\n\n\tprotected override void OnPreRender()\n\t{\n\t\t//ensure sceneobject have transform and correct bound for engine culling\n\t\t_panelObject.Transform = Renderer.Transform.World;\n\t\t_panelObject.Bounds = Renderer.Bounds;\n\t}\n\n\tprotected override void OnEnabled()\n\t{\n\t\tbase.OnEnabled();\n\n\t\tRenderer = Components.Get\u003CModelRenderer\u003E();\n\n\t\tif ( !Renderer.IsValid() )\n\t\t{\n\t\t\tLog.Warning( \u0022No ModelRenderer found.\u0022 );\n\t\t\tEnabled = false;\n\t\t\treturn;\n\t\t}\n\n\t\tRefreshMeshCache();\n\t\tCreateTexture();\n\t\tCreatePanel();\n\t\tSetupMaterial();\n\t\tCreatePanelObject();\n\n\t\tOnPanelCreated( Panel );\n\n\t\tvar panelComponent = Components.Get\u003CPanelComponent\u003E();\n\t\tTargetPanelSystem.Current.RegisterScreen( this );\n\t}\n\n\tpublic Panel GetPanel()\n\t{\n\t\treturn Panel;\n\t}\n\n\tprotected virtual void OnPanelCreated( Panel panel )\n\t{\n\t}\n\n\tprivate void CreateTexture()\n\t{\n\t\t_screenTexture = Texture.CreateRenderTarget()\n\t\t\t.WithSize( ScreenTextureSize.x, ScreenTextureSize.y )\n\t\t\t.WithInitialColor( Color.Black )\n\t\t\t.WithMips()\n\t\t\t.Create();\n\t}\n\n\tprivate void CreatePanel()\n\t{\n\t\tvar bounds = new Rect( 0, 0, ScreenTextureSize.x, ScreenTextureSize.y );\n\t\t\n\t\t_rootPanel = new TargetRootPanel\n\t\t{\n\t\t\tRenderedManually = true,\n\t\t\tIsWorldPanel = true,\n\t\t\tFixedBounds = bounds,\n\t\t\tFixedScale = 1f,\n\t\t\tPanelBounds = bounds,\n\t\t\tMouseVisibility = ScreenCursorInteraction ? MouseVisibility.Visible : MouseVisibility.Hidden\n\t\t};\n\n\t\t_rootPanel.Style.Width = Length.Pixels( ScreenTextureSize.x );\n\t\t_rootPanel.Style.Height = Length.Pixels( ScreenTextureSize.y );\n\n\t\tvar type = PanelType?.Resolve();\n\n\t\tif ( type?.TargetType is null || !typeof( Panel ).IsAssignableFrom( type.TargetType ) )\n\t\t{\n\t\t\tLog.Warning( $\u0022Invalid panel type: {PanelType?.TypeName}\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\tPanel = type.Create\u003CPanel\u003E();\n\t\t_rootPanel.AddChild( Panel );\n\n\t\tPanel.Style.Width = Length.Percent( 100 );\n\t\tPanel.Style.Height = Length.Percent( 100 );\n\t}\n\n\tprivate void CreatePanelObject()\n\t{\n\t\t_panelObject = new PanelSceneObject(\n\t\t\tGameObject.GetBounds(),\n\t\t\tScene.SceneWorld,\n\t\t\t_rootPanel,\n\t\t\t_screenTexture,\n\t\t\tthis\n\t\t);\n\t}\n\n\tpublic void Tick()\n\t{\n\t\tif ( !Renderer.IsValid() || Renderer.Model is null || !Panel.IsValid() )\n\t\t\treturn;\n\n\t\tvar camera = Scene.Camera;\n\n\t\tif ( camera is null )\n\t\t\treturn;\n\n\t\tif ( !TryGetPanelPosition( camera, out var panelPos ) )\n\t\t{\n\t\t\tClearInput();\n\t\t\treturn;\n\t\t}\n\n\t\t_panelObject.CursorPosition = panelPos;\n\t\t\n\t\t_input.Tick(\n\t\t\t_rootPanel,\n\t\t\tpanelPos,\n\t\t\tInput.Down( \u0022attack1\u0022 ),\n\t\t\tInput.MouseWheel\n\t\t);\n\n\t}\n\n\n\tprivate bool TryGetPanelPosition( CameraComponent camera, out Vector2 panelPos )\n\t{\n\t\tpanelPos = default;\n\t\t\n\t\tvar screenCenter = new Vector2(\n\t\t\tcamera.ScreenRect.Size.x * 0.5f,\n\t\t\tcamera.ScreenRect.Size.y * 0.5f\n\t\t);\n\n\t\tvar ray = camera.ScreenPixelToRay( screenCenter );\n\n\t\tif( ScreenCursorInteraction )\n\t\t{\n\t\t\tray = camera.ScreenPixelToRay( Mouse.Position );\n\t\t}\n\n\t\treturn TryGetPanelPositionFromMeshRaycast( ray, out panelPos );\n\t}\n\n\tprivate bool TryGetPanelPositionFromMeshRaycast( Ray ray, out Vector2 panelPos )\n\t{\n\t\tusing var scope = Sandbox.Diagnostics.Performance.Scope( \u0022TargetScreen.MouseTrace\u0022 );\n\t\tvar totalTimer = Sandbox.Diagnostics.FastTimer.StartNew();\n\t\tpanelPos = default;\n\n\t\tvar cacheTimer = Sandbox.Diagnostics.FastTimer.StartNew();\n\t\tRefreshMeshCache();\n\t\tvar cacheMs = cacheTimer.ElapsedMilliSeconds;\n\n\t\tif ( _cachedVertices is null || _cachedIndices is null || _cachedIndices.Length \u003C 3 )\n\t\t{\n\t\t\tif ( DebugMouseTrace )\n\t\t\t\tLog.Info( $\u0022[TargetScreen] Reject mesh cache: vertices={_cachedVertices?.Length ?? 0} indices={_cachedIndices?.Length ?? 0}\u0022 );\n\t\t\tUpdateDebugTracePerf( totalTimer.ElapsedMilliSeconds, cacheMs, 0f );\n\t\t\treturn false;\n\t\t}\n\n\t\tvar localOrigin = Renderer.Transform.World.PointToLocal( ray.Position );\n\t\tvar localEnd = Renderer.Transform.World.PointToLocal( ray.Position \u002B ray.Forward * TraceDistance );\n\t\tvar localDirection = (localEnd - localOrigin).Normal;\n\n\t\tvar bestDistance = float.MaxValue;\n\t\tvar bestUv = Vector2.Zero;\n\t\tvar bestTriangle = -1;\n\t\tvar triangleTimer = Sandbox.Diagnostics.FastTimer.StartNew();\n\n\t\tfor ( int triStart = 0; triStart \u002B 2 \u003C _cachedIndices.Length; triStart \u002B= 3 )\n\t\t{\n\t\t\tvar triangleIndex = triStart / 3;\n\t\t\tif ( !IsTriangleMaterialMatch( triangleIndex ) )\n\t\t\t\tcontinue;\n\n\t\t\tvar i0 = _cachedIndices[triStart \u002B 0];\n\t\t\tvar i1 = _cachedIndices[triStart \u002B 1];\n\t\t\tvar i2 = _cachedIndices[triStart \u002B 2];\n\t\t\tif ( i0 \u003E= _cachedVertices.Length || i1 \u003E= _cachedVertices.Length || i2 \u003E= _cachedVertices.Length )\n\t\t\t\tcontinue;\n\n\t\t\tvar v0 = _cachedVertices[i0];\n\t\t\tvar v1 = _cachedVertices[i1];\n\t\t\tvar v2 = _cachedVertices[i2];\n\n\t\t\tif ( !TryRayTriangleIntersection( localOrigin, localDirection, v0.Position, v1.Position, v2.Position, out var distance, out var barycentric ) )\n\t\t\t\tcontinue;\n\n\t\t\tif ( distance \u003E TraceDistance || distance \u003E= bestDistance )\n\t\t\t\tcontinue;\n\n\t\t\tvar triangleUv =\n\t\t\t\tv0.TexCoord0 * barycentric.x \u002B\n\t\t\t\tv1.TexCoord0 * barycentric.y \u002B\n\t\t\t\tv2.TexCoord0 * barycentric.z;\n\n\t\t\tbestDistance = distance;\n\t\t\tbestUv = triangleUv;\n\t\t\tbestTriangle = triangleIndex;\n\t\t}\n\n\t\tvar triangleMs = triangleTimer.ElapsedMilliSeconds;\n\n\t\tif ( bestTriangle \u003C 0 )\n\t\t{\n\t\t\tif ( DebugMouseTrace )\n\t\t\t\tLog.Info( $\u0022[TargetScreen] No triangle hit. vertices={_cachedVertices.Length} indices={_cachedIndices.Length}\u0022 );\n\t\t\tUpdateDebugTracePerf( totalTimer.ElapsedMilliSeconds, cacheMs, triangleMs );\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( DebugMouseTrace )\n\t\t\tLog.Info( $\u0022[TargetScreen] Mesh hit triangle={bestTriangle} distance={bestDistance} rawUv={bestUv}\u0022 );\n\n\t\tvar uv = new Vector2(\n\t\t\tbestUv.x - MathF.Floor( bestUv.x ),\n\t\t\tbestUv.y - MathF.Floor( bestUv.y )\n\t\t);\n\n\t\tuv \u002B= ScreenUvOffset;\n\n\t\tpanelPos = new Vector2(\n\t\t\tMath.Clamp( uv.x, 0f, 1f ) * ScreenTextureSize.x,\n\t\t\tMath.Clamp( uv.y, 0f, 1f ) * ScreenTextureSize.y\n\t\t);\n\n\t\tif ( DebugMouseTrace )\n\t\t\tLog.Info( $\u0022[TargetScreen] Final UV={uv} panelPos={panelPos}\u0022 );\n\n\t\tUpdateDebugTracePerf( totalTimer.ElapsedMilliSeconds, cacheMs, triangleMs );\n\t\treturn true;\n\t}\n\n\tprivate void UpdateDebugTracePerf( double totalMs, double cacheMs, double triangleMs )\n\t{\n\t\t_tracePerfAccumMs \u002B= totalMs;\n\t\t_tracePerfCacheAccumMs \u002B= cacheMs;\n\t\t_tracePerfTrianglesAccumMs \u002B= triangleMs;\n\t\t_tracePerfMaxMs = Math.Max( _tracePerfMaxMs, totalMs );\n\t\t_tracePerfSamples\u002B\u002B;\n\n\t\tif ( _tracePerfLogTimer \u003C 5f )\n\t\t\treturn;\n\n\t\tvar avgTotalMs = _tracePerfSamples \u003E 0 ? _tracePerfAccumMs / _tracePerfSamples : 0d;\n\t\tvar avgCacheMs = _tracePerfSamples \u003E 0 ? _tracePerfCacheAccumMs / _tracePerfSamples : 0d;\n\t\tvar avgTrianglesMs = _tracePerfSamples \u003E 0 ? _tracePerfTrianglesAccumMs / _tracePerfSamples : 0d;\n\t\tvar callsPerSecond = _tracePerfLogTimer \u003E 0f ? _tracePerfSamples / _tracePerfLogTimer : 0f;\n\t\tvar triangleCount = _cachedIndices?.Length / 3 ?? 0;\n\n\t\tLog.Info( $\u0022[TargetScreen] Trace perf avg={avgTotalMs:F3}ms max={_tracePerfMaxMs:F3}ms cache={avgCacheMs:F3}ms triangles={avgTrianglesMs:F3}ms calls={callsPerSecond:F1}/s tris={triangleCount}\u0022 );\n\n\t\t_tracePerfAccumMs = 0d;\n\t\t_tracePerfCacheAccumMs = 0d;\n\t\t_tracePerfTrianglesAccumMs = 0d;\n\t\t_tracePerfMaxMs = 0d;\n\t\t_tracePerfSamples = 0;\n\t\t_tracePerfLogTimer = 0f;\n\t}\n\n\tprivate void RefreshMeshCache()\n\t{\n\t\tvar model = Renderer?.Model;\n\t\tif ( model is null || model == _cachedMeshModel )\n\t\t\treturn;\n\n\t\t_cachedMeshModel = model;\n\t\t_cachedVertices = model.GetVertices();\n\t\t_cachedIndices = model.GetIndices();\n\t\t_cachedTriangleMaterialRanges = BuildTriangleMaterialRanges( model );\n\n\t\tif ( DebugMouseTrace )\n\t\t\tLog.Info( $\u0022[TargetScreen] Refreshed mesh cache for {model.Name}: vertices={_cachedVertices?.Length ?? 0} indices={_cachedIndices?.Length ?? 0} materialRanges={_cachedTriangleMaterialRanges.Length}\u0022 );\n\t}\n\n\tprivate TriangleMaterialRange[] BuildTriangleMaterialRanges( Model model )\n\t{\n\t\tvar meshInfo = model.MeshInfo;\n\t\tif ( meshInfo?.Meshes is null )\n\t\t\treturn Array.Empty\u003CTriangleMaterialRange\u003E();\n\n\t\tvar ranges = new System.Collections.Generic.List\u003CTriangleMaterialRange\u003E();\n\t\tvar triangleCursor = 0;\n\n\t\tforeach ( var mesh in meshInfo.Meshes )\n\t\t{\n\t\t\tif ( mesh?.DrawCalls is null )\n\t\t\t\tcontinue;\n\n\t\t\tforeach ( var drawCall in mesh.DrawCalls )\n\t\t\t{\n\t\t\t\tvar triangleCount = Math.Max( 0, drawCall.Indices / 3 );\n\t\t\t\tif ( triangleCount == 0 )\n\t\t\t\t\tcontinue;\n\n\t\t\t\tranges.Add( new TriangleMaterialRange\n\t\t\t\t{\n\t\t\t\t\tStartTriangle = triangleCursor,\n\t\t\t\t\tEndTriangleExclusive = triangleCursor \u002B triangleCount,\n\t\t\t\t\tMaterial = drawCall.Material\n\t\t\t\t} );\n\n\t\t\t\tif ( DebugMouseTrace )\n\t\t\t\t\tLog.Info( $\u0022[TargetScreen] Material range {triangleCursor}-\u003E{triangleCursor \u002B triangleCount} material={drawCall.Material?.Name}\u0022 );\n\n\t\t\t\ttriangleCursor \u002B= triangleCount;\n\t\t\t}\n\t\t}\n\n\t\treturn ranges.ToArray();\n\t}\n\n\tprivate bool IsTriangleMaterialMatch( int triangleIndex )\n\t{\n\t\tif ( string.IsNullOrWhiteSpace( ScreenMaterialName ) || _cachedTriangleMaterialRanges.Length == 0 )\n\t\t\treturn true;\n\n\t\tforeach ( var range in _cachedTriangleMaterialRanges )\n\t\t{\n\t\t\tif ( triangleIndex \u003C range.StartTriangle || triangleIndex \u003E= range.EndTriangleExclusive )\n\t\t\t\tcontinue;\n\n\t\t\tvar match = range.Material?.Name?.Contains( ScreenMaterialName, StringComparison.OrdinalIgnoreCase ) == true;\n\t\t\tif ( DebugMouseTrace \u0026\u0026 triangleIndex == range.StartTriangle )\n\t\t\t\tLog.Info( $\u0022[TargetScreen] Triangle {triangleIndex} material={range.Material?.Name} match={match}\u0022 );\n\t\t\treturn match;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate static bool TryRayTriangleIntersection( Vector3 origin, Vector3 direction, Vector3 a, Vector3 b, Vector3 c, out float distance, out Vector3 barycentric )\n\t{\n\t\tdistance = 0f;\n\t\tbarycentric = default;\n\n\t\tconst float epsilon = 0.0001f;\n\t\tvar edge1 = b - a;\n\t\tvar edge2 = c - a;\n\t\tvar pvec = Vector3.Cross( direction, edge2 );\n\t\tvar det = Vector3.Dot( edge1, pvec );\n\t\tif ( MathF.Abs( det ) \u003C epsilon )\n\t\t\treturn false;\n\n\t\tvar invDet = 1f / det;\n\t\tvar tvec = origin - a;\n\t\tvar v = Vector3.Dot( tvec, pvec ) * invDet;\n\t\tif ( v \u003C 0f || v \u003E 1f )\n\t\t\treturn false;\n\n\t\tvar qvec = Vector3.Cross( tvec, edge1 );\n\t\tvar w = Vector3.Dot( direction, qvec ) * invDet;\n\t\tif ( w \u003C 0f || v \u002B w \u003E 1f )\n\t\t\treturn false;\n\n\t\tdistance = Vector3.Dot( edge2, qvec ) * invDet;\n\t\tif ( distance \u003C 0f )\n\t\t\treturn false;\n\n\t\tbarycentric = new Vector3( 1f - v - w, v, w );\n\t\treturn true;\n\t}\n\n\tprivate void SetupMaterial()\n\t{\n\t\tvar oldMaterial = Renderer.Model.Materials\n\t\t\t.FirstOrDefault( x =\u003E x.Name.Contains( ScreenMaterialName ) );\n\n\t\tvar index = Renderer.Model.Materials.IndexOf( oldMaterial );\n\n\t\tif ( index \u003C 0 )\n\t\t{\n\t\t\tLog.Warning( $\u0022Screen material not found: {ScreenMaterialName}\u0022 );\n\t\t\treturn;\n\t\t}\n\n\t\t_screenMaterialCopy = ScreenMaterial.CreateCopy();\n\t\t_screenMaterialCopy.Set( \u0022g_tColor\u0022, _screenTexture );\n\n\t\tRenderer.Materials.SetOverride( index, _screenMaterialCopy );\n\t}\n\n\tprivate void ClearInput()\n\t{\n\t\t_input.Clear();\n\t}\n\n\tprotected override void OnDisabled()\n\t{\n\t\tbase.OnDisabled();\n\n\t\tClearInput();\n\n\t\t_panelObject?.Delete();\n\t\t_panelObject = null;\n\n\t\t_rootPanel?.Delete( true );\n\t\t_rootPanel = null;\n\n\t\t_screenTexture?.Dispose();\n\t\t_screenTexture = null;\n\n\t\t_screenMaterialCopy = null;\n\t\tPanel = null;\n\t\tRenderer = null;\n\n\t\tTargetPanelSystem.Current.UnregisterScreen( this );\n\t}\n}\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/TargetPanelInput.cs","FileName":"TargetPanelInput.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Sandbox.UI;\r\nusing System.Linq;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\npublic class TargetPanelInput\r\n{\r\n\tprivate Panel _hovered;\r\n\tprivate Panel _active;\r\n\tprivate bool _lastMouseDown;\r\n\tprivate bool _suppressClick;\r\n\r\n\tprivate Panel _potentialDrag;\r\n\r\n\tprivate MousePanelEvent CreateMouseEvent( string type, Panel panel, Vector2 mousePos, string button )\r\n\t{\r\n\t\tvar panelEvent = new MousePanelEvent( type, panel, button );\r\n\t\tpanelEvent.LocalPosition = mousePos - panel.Box.Rect.Position \u002B panel.ScrollOffset;\r\n\t\treturn panelEvent;\r\n\t}\r\n\r\n\tprivate Panel FindFocusableParent( Panel panel )\r\n\t{\r\n\t\twhile ( panel != null )\r\n\t\t{\r\n\t\t\tif ( panel.AcceptsFocus )\r\n\t\t\t\treturn panel;\r\n\r\n\t\t\tpanel = panel.Parent;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic void Tick( RootPanel root, Vector2 mousePos, bool mouseDown, Vector2 mouseWheel )\r\n\t{\r\n\t\tif ( !root.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tvar target = FindPanelAt( root, mousePos );\r\n\t\tvar screenRoot = root as TargetRootPanel;\r\n\r\n\t\tif ( screenRoot != null )\r\n\t\t\tscreenRoot.MousePosition = mousePos;\r\n\r\n\t\tSetHovered( target );\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tCreateMouseEvent( \u0022onmousemove\u0022, _hovered, mousePos, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif ( _hovered != null \u0026\u0026 mouseWheel.Length \u003E 0 )\r\n\t\t{\r\n\t\t\t_hovered.OnMouseWheel( mouseWheel.y * Vector2.Up );\r\n\t\t}\r\n\r\n\t\tif ( mouseDown \u0026\u0026 !_lastMouseDown )\r\n\t\t{\r\n\t\t\t// A second click on an open popup button closes it without reopening on release.\r\n\t\t\t_suppressClick = screenRoot?.CloseLocalPopups( target ) == true;\r\n\t\t\t_active = _hovered;\r\n\r\n\t\t\tif ( _active != null )\r\n\t\t\t{\r\n\t\t\t\t_potentialDrag = FindDragTarget( _active );\r\n\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Active, true, _active );\r\n\r\n\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\tCreateMouseEvent( \u0022onmousedown\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t);\r\n\r\n\t\t\t\tvar focusTarget = FindFocusableParent( _active );\r\n\r\n\t\t\t\tif ( focusTarget != null )\r\n\t\t\t\t{\r\n\t\t\t\t\tInputFocus.Set( focusTarget );\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tInputFocus.Clear();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tInputFocus.Clear();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( !mouseDown \u0026\u0026 _lastMouseDown )\r\n\t\t{\r\n\t\t\tif ( _active != null )\r\n\t\t\t{\r\n\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\tCreateMouseEvent( \u0022onmouseup\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t);\r\n\r\n\t\t\t\tif ( _active == _hovered \u0026\u0026 !_suppressClick )\r\n\t\t\t\t{\r\n\t\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\t\tCreateMouseEvent( \u0022onclick\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Active, false, _active );\r\n\t\t\t}\r\n\r\n\t\t\t_active = null;\r\n\t\t}\r\n\r\n\t\t_lastMouseDown = mouseDown;\r\n\t}\r\n\r\n\tprivate Panel FindDragTarget( Panel panel )\r\n\t{\r\n\t\twhile ( panel != null )\r\n\t\t{\r\n\t\t\tif ( panel.WantsDrag )\r\n\t\t\t\treturn panel;\r\n\r\n\t\t\tpanel = panel.Parent;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic void Clear()\r\n\t{\r\n\t\tSetHovered( null );\r\n\r\n\t\tif ( _active != null )\r\n\t\t{\r\n\t\t\tSwitchPseudoClass( PseudoClass.Active, false, _active );\r\n\t\t\t_active = null;\r\n\t\t}\r\n\r\n\t\t_lastMouseDown = false;\r\n\t\t_suppressClick = false;\r\n\t}\r\n\r\n\tprivate void SetHovered( Panel current )\r\n\t{\r\n\t\tif ( current == _hovered )\r\n\t\t\treturn;\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\tSwitchPseudoClass( PseudoClass.Hover, false, _hovered, current );\r\n\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tnew MousePanelEvent( \u0022onmouseout\u0022, _hovered, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\t_hovered = current;\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\tif ( _active == null || _active == _hovered )\r\n\t\t\t{\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Hover, true, _hovered );\r\n\t\t\t}\r\n\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tnew MousePanelEvent( \u0022onmouseover\u0022, _hovered, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static void SwitchPseudoClass(\r\n\t\tPseudoClass pseudoClass,\r\n\t\tbool state,\r\n\t\tPanel panel,\r\n\t\tPanel unlessAncestorOf = null\r\n\t)\r\n\t{\r\n\t\tif ( panel == null )\r\n\t\t\treturn;\r\n\r\n\t\tforeach ( var item in panel.AncestorsAndSelf )\r\n\t\t{\r\n\t\t\tif ( unlessAncestorOf == null || !unlessAncestorOf.IsAncestor( item ) )\r\n\t\t\t{\r\n\t\t\t\titem.Switch( pseudoClass, state );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate Panel FindPanelAt( Panel root, Vector2 pos )\r\n\t{\r\n\t\tif ( root == null || !root.IsValid() || !root.IsVisible )\r\n\t\t\treturn null;\r\n\r\n\t\tif ( !root.Box.Rect.IsInside( pos ) )\r\n\t\t\treturn null;\r\n\r\n\t\t// Trier les enfants par z-index d\u00E9croissant pour tester le plus haut en premier\r\n\t\tvar children = root.Children?\r\n\t\t\t.Where( x =\u003E x != null \u0026\u0026 x.IsValid() \u0026\u0026 x.IsVisible )\r\n\t\t\t.OrderByDescending( x =\u003E x.ComputedStyle?.ZIndex ?? 0 )\r\n\t\t\t.ThenByDescending( x =\u003E x.SiblingIndex );\r\n\r\n\t\tif ( children != null )\r\n\t\t{\r\n\t\t\tforeach ( var child in children )\r\n\t\t\t{\r\n\t\t\t\tvar hit = FindPanelAt( child, pos );\r\n\t\t\t\tif ( hit != null )\r\n\t\t\t\t\treturn hit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn root;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/TargetPanelSystem.cs","FileName":"TargetPanelSystem.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Sandbox.Internal;\r\nusing Sandbox.UI;\r\nusing System.Collections.Generic;\r\nnamespace PanelRenderTarget;\r\n\r\npublic class TargetPanelSystem : GameObjectSystem\u003CTargetPanelSystem\u003E\r\n{\r\n\r\n\tpublic TargetPanelSystem(Scene scene) : base(scene)\r\n\t{\r\n\t\tListen(Stage.FinishUpdate,1,UpdateAll, \u0022TargetPanelSystemUpdateAll\u0022 );\r\n\t}\r\n\r\n\tprotected HashSet\u003CTargetScreen\u003E Screens = new();\r\n\r\n\tpublic void RegisterScreen( TargetScreen screen )\r\n\t{\r\n\t\tScreens.Add(screen);\r\n\t}\r\n\r\n\tpublic void UnregisterScreen( TargetScreen screen )\r\n\t{\r\n\t\tScreens.Remove(screen);\r\n\t}\r\n\r\n\tvoid UpdateAll()\r\n\t{\r\n\t\tif ( Application.IsDedicatedServer ) return;\r\n\r\n\t\tvar position = Scene.Camera.WorldPosition;\r\n\t\tvar frustrum = Scene.Camera.GetFrustum();\r\n\t\tvar camera = Scene.Camera;\r\n\r\n\t\tforeach ( var screen in Screens )\r\n\t\t{\r\n\t\t\tbool visible = frustrum.IsInside( screen.Renderer.Bounds, partially: true );\r\n\t\t\tvar panel = screen.RootPanel;\r\n\t\t\tvar initPassed = screen.PanelObject.InitPassed;\r\n\t\t\tscreen.PanelObject.IsFocus = false;\r\n\t\t\t\r\n\t\t\tif (!visible || (screen.WorldPosition.Distance( position ) \u003E screen.UpdateDistanceMax \u0026\u0026 initPassed ))\r\n\t\t\t{\r\n\t\t\t\tscreen.PanelObject.RenderingEnabled = false;\r\n\t\t\t\tif ( panel.Style.Display != DisplayMode.None )\r\n\t\t\t\t\tpanel.Style.Display = DisplayMode.None;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\r\n\t\t\tvar worldBounds = screen.Renderer.Bounds;\r\n\t\t\tvar screenCenter = new Vector2(\r\n\t\t\t\tcamera.ScreenRect.Size.x * 0.5f,\r\n\t\t\t\tcamera.ScreenRect.Size.y * 0.5f\r\n\t\t\t);\r\n\t\t\tvar pointerPosition = screen.ScreenCursorInteraction ? Mouse.Position : screenCenter;\r\n\t\t\tvar ray = camera.ScreenPixelToRay( pointerPosition );\r\n\t\t\tvar touch = worldBounds.Trace( ray, screen.TraceDistance, out _ );\r\n\r\n\t\t\tif ( screen.UpdateWhenNotFocused == false \u0026\u0026 !touch \u0026\u0026 initPassed )\r\n\t\t\t{\r\n\t\t\t\tscreen.PanelObject.RenderingEnabled = false;\r\n\t\t\t\tif ( panel.Style.Display != DisplayMode.None )\r\n\t\t\t\t\tpanel.Style.Display = DisplayMode.None;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tscreen.PanelObject.RenderingEnabled = true;\r\n\t\t\tif( panel.Style.Display != DisplayMode.Contents )\r\n\t\t\t\tpanel.Style.Display = DisplayMode.Contents;\r\n\r\n\t\t\t//only execute the tick when aim the model because tick is for input only\r\n\t\t\tif ( touch )\r\n\t\t\t{\r\n\t\t\t\tscreen.PanelObject.IsFocus = true;\r\n\t\t\t\tscreen.Tick();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tpublic void CreatePanelScreen\u003CT\u003E( GameObject go, string screenMaterialName, Material material, Vector2Int size )\r\n\t\twhere T : PanelRenderTarget.ScreenPanel\r\n\t{\r\n\t\tvar comp = go.AddComponent\u003CTargetScreen\u003E( false );\r\n\t\tcomp.ScreenMaterialName = screenMaterialName;\r\n\t\tcomp.ScreenMaterial = material;\r\n\t\tcomp.ScreenTextureSize = size;\r\n\t\tcomp.PanelType.TypeName = typeof( T ).FullName;\r\n\t\tcomp.Enabled = true;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/TargetRootPanel.cs","FileName":"TargetRootPanel.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Sandbox.UI;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\npublic class TargetRootPanel : RootPanel\r\n{\r\n\r\n\tpublic Rect FixedBounds { get; set; } = new Rect( 0, 0, 1280, 720 );\r\n\tpublic float FixedScale { get; set; } = 1f;\r\n\r\n\tpublic new Vector2 MousePosition { get; set; }\r\n\r\n\tpublic MouseVisibility MouseVisibility { get; set; } = MouseVisibility.Hidden;\r\n\r\n\tpublic override void Tick()\r\n\t{\r\n\t\tbase.Tick();\r\n\t\tif ( MouseVisibility == MouseVisibility.Visible \u0026\u0026 Mouse.Visibility != MouseVisibility.Visible )\r\n\t\t{\r\n\t\t\tMouse.Visibility = MouseVisibility.Visible;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override void OnDeleted()\r\n\t{\r\n\t\tbase.OnDeleted();\r\n\t\tif ( MouseVisibility == MouseVisibility.Visible )\r\n\t\t{\r\n\t\t\tMouse.Visibility = MouseVisibility.Auto;\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void UpdateBounds( Rect rect )\r\n\t{\r\n\t\tPanelBounds = FixedBounds;\r\n\t}\r\n\r\n\tprotected override void UpdateScale( Rect screenSize )\r\n\t{\r\n\t\tScale = FixedScale;\r\n\t}\r\n\r\n\tprotected override void OnChildAdded( Panel child )\r\n\t{\r\n\t\tbase.OnChildAdded( child );\r\n\r\n\t\t// Native popups normally attach directly to FindPopupPanel(), this root.\r\n\t\tif ( child is not BasePopup popup )\r\n\t\t\treturn;\r\n\r\n\t\tpopup.StayOpen = true;\r\n\r\n\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource is DropDown )\r\n\t\t{\r\n\t\t\tmenu.AddEventListener( \u0022onclick\u0022, e =\u003E\r\n\t\t\t{\r\n\t\t\t\tif ( !menu.IsValid() || menu.IsDeleting || !e.Target.IsValid() )\r\n\t\t\t\t\treturn;\r\n\r\n\t\t\t\t// The option\u0027s own click handler runs before the event reaches its menu.\r\n\t\t\t\t// This also closes the menu when the selected value did not change.\r\n\t\t\t\tif ( e.Target.AncestorsAndSelf.OfType\u003CButton\u003E().Any( button =\u003E button.Parent == menu ) )\r\n\t\t\t\t\tmenu.Delete();\r\n\t\t\t} );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EClose local popups. Returns true when the click closed its own popup button\u0027s menu.\u003C/summary\u003E\r\n\tpublic bool CloseLocalPopups( Panel clickedPanel )\r\n\t{\r\n\t\tif ( !clickedPanel.IsValid() || clickedPanel.FindRootPanel() != this )\r\n\t\t\treturn false;\r\n\r\n\t\tbool closedSourcePopup = false;\r\n\t\tvar keep = new HashSet\u003CBasePopup\u003E();\r\n\t\tvar pending = new Stack\u003CPanel\u003E();\r\n\t\tif ( clickedPanel.IsValid() \u0026\u0026 clickedPanel.FindRootPanel() == this )\r\n\t\t\tpending.Push( clickedPanel );\r\n\r\n\t\twhile ( pending.Count \u003E 0 )\r\n\t\t{\r\n\t\t\tforeach ( var popup in pending.Pop().AncestorsAndSelf.OfType\u003CBasePopup\u003E() )\r\n\t\t\t{\r\n\t\t\t\tif ( popup.FindRootPanel() != this || !keep.Add( popup ) )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource.IsValid()\r\n\t\t\t\t\t\u0026\u0026 menu.PopupSource.FindRootPanel() == this )\r\n\t\t\t\t\tpending.Push( menu.PopupSource );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach ( var popup in Descendants.OfType\u003CBasePopup\u003E().ToArray() )\r\n\t\t{\r\n\t\t\tif ( popup.IsValid() \u0026\u0026 !popup.IsDeleting \u0026\u0026 popup.FindRootPanel() == this \u0026\u0026 !keep.Contains( popup ) )\r\n\t\t\t{\r\n\t\t\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource is PopupButton source\r\n\t\t\t\t\t\u0026\u0026 clickedPanel.IsValid() \u0026\u0026 clickedPanel.AncestorsAndSelf.Contains( source ) )\r\n\t\t\t\t\tclosedSourcePopup = true;\r\n\r\n\t\t\t\tpopup.Delete();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn closedSourcePopup;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"TargetPanelInput.cs","FileName":"TargetPanelInput.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Sandbox.UI;\r\nusing System.Linq;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\npublic class TargetPanelInput\r\n{\r\n\tprivate Panel _hovered;\r\n\tprivate Panel _active;\r\n\tprivate bool _lastMouseDown;\r\n\tprivate bool _suppressClick;\r\n\r\n\tprivate Panel _potentialDrag;\r\n\r\n\tprivate MousePanelEvent CreateMouseEvent( string type, Panel panel, Vector2 mousePos, string button )\r\n\t{\r\n\t\tvar panelEvent = new MousePanelEvent( type, panel, button );\r\n\t\tpanelEvent.LocalPosition = mousePos - panel.Box.Rect.Position \u002B panel.ScrollOffset;\r\n\t\treturn panelEvent;\r\n\t}\r\n\r\n\tprivate Panel FindFocusableParent( Panel panel )\r\n\t{\r\n\t\twhile ( panel != null )\r\n\t\t{\r\n\t\t\tif ( panel.AcceptsFocus )\r\n\t\t\t\treturn panel;\r\n\r\n\t\t\tpanel = panel.Parent;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic void Tick( RootPanel root, Vector2 mousePos, bool mouseDown, Vector2 mouseWheel )\r\n\t{\r\n\t\tif ( !root.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\tvar target = FindPanelAt( root, mousePos );\r\n\t\tvar screenRoot = root as TargetRootPanel;\r\n\r\n\t\tif ( screenRoot != null )\r\n\t\t\tscreenRoot.MousePosition = mousePos;\r\n\r\n\t\tSetHovered( target );\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tCreateMouseEvent( \u0022onmousemove\u0022, _hovered, mousePos, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tif ( _hovered != null \u0026\u0026 mouseWheel.Length \u003E 0 )\r\n\t\t{\r\n\t\t\t_hovered.OnMouseWheel( mouseWheel.y * Vector2.Up );\r\n\t\t}\r\n\r\n\t\tif ( mouseDown \u0026\u0026 !_lastMouseDown )\r\n\t\t{\r\n\t\t\t// A second click on an open popup button closes it without reopening on release.\r\n\t\t\t_suppressClick = screenRoot?.CloseLocalPopups( target ) == true;\r\n\t\t\t_active = _hovered;\r\n\r\n\t\t\tif ( _active != null )\r\n\t\t\t{\r\n\t\t\t\t_potentialDrag = FindDragTarget( _active );\r\n\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Active, true, _active );\r\n\r\n\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\tCreateMouseEvent( \u0022onmousedown\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t);\r\n\r\n\t\t\t\tvar focusTarget = FindFocusableParent( _active );\r\n\r\n\t\t\t\tif ( focusTarget != null )\r\n\t\t\t\t{\r\n\t\t\t\t\tInputFocus.Set( focusTarget );\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tInputFocus.Clear();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tInputFocus.Clear();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( !mouseDown \u0026\u0026 _lastMouseDown )\r\n\t\t{\r\n\t\t\tif ( _active != null )\r\n\t\t\t{\r\n\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\tCreateMouseEvent( \u0022onmouseup\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t);\r\n\r\n\t\t\t\tif ( _active == _hovered \u0026\u0026 !_suppressClick )\r\n\t\t\t\t{\r\n\t\t\t\t\t_active.CreateEvent(\r\n\t\t\t\t\t\tCreateMouseEvent( \u0022onclick\u0022, _active, mousePos, \u0022mouseleft\u0022 )\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Active, false, _active );\r\n\t\t\t}\r\n\r\n\t\t\t_active = null;\r\n\t\t}\r\n\r\n\t\t_lastMouseDown = mouseDown;\r\n\t}\r\n\r\n\tprivate Panel FindDragTarget( Panel panel )\r\n\t{\r\n\t\twhile ( panel != null )\r\n\t\t{\r\n\t\t\tif ( panel.WantsDrag )\r\n\t\t\t\treturn panel;\r\n\r\n\t\t\tpanel = panel.Parent;\r\n\t\t}\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic void Clear()\r\n\t{\r\n\t\tSetHovered( null );\r\n\r\n\t\tif ( _active != null )\r\n\t\t{\r\n\t\t\tSwitchPseudoClass( PseudoClass.Active, false, _active );\r\n\t\t\t_active = null;\r\n\t\t}\r\n\r\n\t\t_lastMouseDown = false;\r\n\t\t_suppressClick = false;\r\n\t}\r\n\r\n\tprivate void SetHovered( Panel current )\r\n\t{\r\n\t\tif ( current == _hovered )\r\n\t\t\treturn;\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\tSwitchPseudoClass( PseudoClass.Hover, false, _hovered, current );\r\n\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tnew MousePanelEvent( \u0022onmouseout\u0022, _hovered, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\t_hovered = current;\r\n\r\n\t\tif ( _hovered != null )\r\n\t\t{\r\n\t\t\tif ( _active == null || _active == _hovered )\r\n\t\t\t{\r\n\t\t\t\tSwitchPseudoClass( PseudoClass.Hover, true, _hovered );\r\n\t\t\t}\r\n\r\n\t\t\t_hovered.CreateEvent(\r\n\t\t\t\tnew MousePanelEvent( \u0022onmouseover\u0022, _hovered, \u0022none\u0022 )\r\n\t\t\t);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static void SwitchPseudoClass(\r\n\t\tPseudoClass pseudoClass,\r\n\t\tbool state,\r\n\t\tPanel panel,\r\n\t\tPanel unlessAncestorOf = null\r\n\t)\r\n\t{\r\n\t\tif ( panel == null )\r\n\t\t\treturn;\r\n\r\n\t\tforeach ( var item in panel.AncestorsAndSelf )\r\n\t\t{\r\n\t\t\tif ( unlessAncestorOf == null || !unlessAncestorOf.IsAncestor( item ) )\r\n\t\t\t{\r\n\t\t\t\titem.Switch( pseudoClass, state );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate Panel FindPanelAt( Panel root, Vector2 pos )\r\n\t{\r\n\t\tif ( root == null || !root.IsValid() || !root.IsVisible )\r\n\t\t\treturn null;\r\n\r\n\t\tif ( !root.Box.Rect.IsInside( pos ) )\r\n\t\t\treturn null;\r\n\r\n\t\t// Trier les enfants par z-index d\u00E9croissant pour tester le plus haut en premier\r\n\t\tvar children = root.Children?\r\n\t\t\t.Where( x =\u003E x != null \u0026\u0026 x.IsValid() \u0026\u0026 x.IsVisible )\r\n\t\t\t.OrderByDescending( x =\u003E x.ComputedStyle?.ZIndex ?? 0 )\r\n\t\t\t.ThenByDescending( x =\u003E x.SiblingIndex );\r\n\r\n\t\tif ( children != null )\r\n\t\t{\r\n\t\t\tforeach ( var child in children )\r\n\t\t\t{\r\n\t\t\t\tvar hit = FindPanelAt( child, pos );\r\n\t\t\t\tif ( hit != null )\r\n\t\t\t\t\treturn hit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn root;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"UnitTests/UnitTest.cs","FileName":"UnitTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":427873,"IsPrivate":false,"Code":"global using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\n[TestClass]\r\npublic class TestInit\r\n{\r\n\tpublic static Sandbox.TestAppSystem AppSystem;\r\n\r\n\t[AssemblyInitialize]\r\n\tpublic static void AssemblyInitialize( TestContext context )\r\n\t{\r\n\t\tAppSystem = new Sandbox.TestAppSystem();\r\n\t\tAppSystem.Init();\r\n\t}\r\n\r\n\t[AssemblyCleanup]\r\n\tpublic static void AssemblyCleanup()\r\n\t{\r\n\t\tAppSystem.Shutdown();\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/PanelTypeReference.cs","FileName":"PanelTypeReference.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\n\nnamespace PanelRenderTarget;\n\n// Stores a panel type by name so scene serialization remains stable.\npublic sealed class PanelTypeReference\n{\n\tpublic string TypeName { get; set; }\n\n\tpublic TypeDescription Resolve()\n\t{\n\t\tif ( string.IsNullOrWhiteSpace( TypeName ) )\n\t\t\treturn null;\n\n\t\tvar typeLibrary = Game.TypeLibrary;\n\t\tif ( typeLibrary is null )\n\t\t\treturn null;\n\n\t\treturn typeLibrary.GetType( typeof( PanelRenderTarget.ScreenPanel ), TypeName, true, true );\n\t}\n}\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/ui/Example.razor","FileName":"Example.razor","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"@using Sandbox\r\n@using Sandbox.UI\r\n@using System\r\n@using System.Collections.Generic\r\n\r\n@namespace PanelRenderTarget\r\n@inherits ScreenPanel\r\n\r\n\u003Cdiv class=\u0022screen\u0022\u003E\r\n\t\u003Cdiv class=\u0022title\u0022\u003EExample\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022debug\u0022 @onclick=@Click @onmouseover=@OnDebugMouseOver @onmouseout=@OnDebugMouseOut\u003E\r\n\t\t\u003Cdiv class=\u0022test-hover\u0022\u003EHover: @IsHovering\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EPressed: @IsPressed\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EClicks: @ClickCount\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EMouse: @MousePosition\u003C/div\u003E\r\n\r\n\t\t\u003CTextEntry @onclick=@TestClick Value:Bind=@test placeholder=\u0022Quantit\u00E9e\u0022 /\u003E\r\n\t\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022select-debug\u0022\u003E\r\n\t\t\u003Cdiv\u003ETest DropDown\u003C/div\u003E\r\n\t\t\u003CDropDown @ref=\u0022SelectControl\u0022\r\n\t\t\tOptions=\u0022@SelectOptions\u0022\r\n\t\t\tValue=\u0022@SelectedValue\u0022\r\n\t\t\tValueChanged=\u0022@OnSelectChanged\u0022 /\u003E\r\n\t\t\u003Cdiv\u003EValeur du controle : @SelectControl?.Value\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EValeur recue : @SelectedValue\u003C/div\u003E\r\n\t\t\u003Cdiv\u003ECallbacks ValueChanged : @SelectChangeCount\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EDernier changement : @LastSelectChange\u003C/div\u003E\r\n\t\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022cursor\u0022 style=\u0022left:@CursorLeft; top:@CursorTop;\u0022\u003E\u003C/div\u003E\r\n\t\r\n\u003C/div\u003E\r\n\r\n@code\r\n{\r\n\tpublic Vector2 MousePosition { get; private set; }\r\n\tpublic bool IsHovering { get; private set; }\r\n\tpublic bool IsPressed { get; private set; }\r\n\tpublic int ClickCount { get; private set; }\r\n\tprivate DropDown SelectControl { get; set; }\r\n\tprivate readonly List\u003COption\u003E SelectOptions = new()\r\n\t{\r\n\t\tnew Option( \u0022Choisir une option\u0022, \u0022\u0022 ),\r\n\t\tnew Option( \u0022Option A\u0022, \u0022a\u0022 ),\r\n\t\tnew Option( \u0022Option B\u0022, \u0022b\u0022 ),\r\n\t\tnew Option( \u0022Option C\u0022, \u0022c\u0022 )\r\n\t};\r\n\tprivate string SelectedValue { get; set; } = \u0022\u0022;\r\n\tprivate int SelectChangeCount { get; set; }\r\n\tprivate string LastSelectChange { get; set; } = \u0022Aucun\u0022;\r\n\r\n\tprivate void OnSelectChanged( string value )\r\n\t{\r\n\t\tSelectedValue = value;\r\n\t\tSelectChangeCount\u002B\u002B;\r\n\t\tLastSelectChange = $\u0022{DateTime.Now:HH:mm:ss.fff} : {value}\u0022;\r\n\t\tStateHasChanged();\r\n\t}\r\n\r\n\tprivate string CursorLeft =\u003E $\u0022{MousePosition.x}px\u0022;\r\n\tprivate string CursorTop =\u003E $\u0022{MousePosition.y}px\u0022;\r\n\r\n\tpublic string test { get; set; } = \u0022teste\u0022;\r\n\r\n\tprotected override void OnMouseMove(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseMove(e);\r\n\t\tvar root = FindRootPanel() as TargetRootPanel;\r\n\t\t//MousePosition = root.MousePosition;\r\n\t}\r\n\r\n\tpublic void OnDebugMouseOver(PanelEvent e)\r\n\t{\r\n\t\tIsHovering = true;\r\n\t}\r\n\r\n\tpublic void OnDebugMouseOut(PanelEvent e)\r\n\t{\r\n\t\tIsHovering = false;\r\n\t}\r\n\r\n\tpublic void TestClick(PanelEvent e)\r\n\t{\r\n\t\tLog.Info(\u0022Clicked on text entry\u0022);\r\n\t}\r\n\r\n\tprotected override void OnMouseDown(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseDown(e);\r\n\t\tIsPressed = true;\r\n\t}\r\n\r\n\tprotected override void OnMouseUp(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseUp(e);\r\n\t\tIsPressed = false;\r\n\t}\r\n\r\n\tpublic void Click(PanelEvent e)\r\n\t{\r\n\t\tClickCount\u002B\u002B;\r\n\t}\r\n\r\n\tprotected override int BuildHash()\r\n\t{\r\n\t\tStateHasChanged();\r\n\t\tvar hash = 17;\r\n\t\thash = hash * 31 \u002B MousePosition.x.GetHashCode();\r\n\t\thash = hash * 31 \u002B MousePosition.y.GetHashCode();\r\n\t\thash = hash * 31 \u002B IsHovering.GetHashCode();\r\n\t\thash = hash * 31 \u002B IsPressed.GetHashCode();\r\n\t\thash = hash * 31 \u002B ClickCount.GetHashCode();\r\n\t\treturn hash;\r\n\t}\r\n}\r\n\r\n\u003Cstyle\u003E\r\n\t.screen {\r\n\t\tcursor: crosshair;\r\n\t\tpointer-events: auto;\r\n\t\tposition: absolute;\r\n\t\tleft: 0;\r\n\t\ttop: 0;\r\n\t\twidth: 100%;\r\n\t\theight: 100%;\r\n\t\tbackground-color: #06111f;\r\n\t\tcolor: white;\r\n\t\tfont-size: 32px;\r\n\t\tfont-weight: bold;\r\n\t}\r\n\r\n\t.title {\r\n\t\tposition: absolute;\r\n\t\tleft: 40px;\r\n\t\ttop: 40px;\r\n\t\tcolor: white;\r\n\t\tfont-size: 64px;\r\n\t}\r\n\r\n\t.debug {\r\n\t\tposition: absolute;\r\n\t\tleft: 40px;\r\n\t\ttop: 140px;\r\n\t\tfont-size: 28px;\r\n\t\tcolor: #9fd4ff;\r\n\t\tflex-direction: column;\r\n\t\twidth:400px;\r\n\t}\r\n\r\n\t\t.debug:hover {\r\n\t\t\tbackground-color: aqua;\r\n\t\t}\r\n\r\n\t\t.debug:active {\r\n\t\t\tbackground-color: red;\r\n\t\t}\r\n\r\n\t.cursor {\r\n\t\tposition: absolute;\r\n\t\twidth: 24px;\r\n\t\theight: 24px;\r\n\t\tbackground-color: red;\r\n\t\tborder-radius: 50%;\r\n\t\ttransform: translate(-50% -50%);\r\n\t}\r\n\r\n\t.select-debug {\r\n\t\tposition: absolute;\r\n\t\tleft: 500px;\r\n\t\ttop: 140px;\r\n\t\twidth: 650px;\r\n\t\tflex-direction: column;\r\n\t\tgap: 12px;\r\n\t\tfont-size: 24px;\r\n\t\tcolor: #9fd4ff;\r\n\t}\r\n\r\n\tTextEntry {\r\n\t\tbackground-color:green;\r\n\t}\r\n\r\n\tTextEntry:focus {\r\n\t\tborder-color: red;\r\n\t}\r\n\u003C/style\u003E\r\n"},{"Ident":"dicta.panelrendertarget","Path":"ScreenPanel.cs","FileName":"ScreenPanel.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"namespace PanelRenderTarget;\r\n\r\n//placeholder for get better list in type editor we can list all Screen Panels and not just Panel\r\npublic abstract class ScreenPanel : Sandbox.UI.Panel\r\n{\r\n\t\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"ui/Example.razor","FileName":"Example.razor","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"@using Sandbox\r\n@using Sandbox.UI\r\n@using System\r\n@using System.Collections.Generic\r\n\r\n@namespace PanelRenderTarget\r\n@inherits ScreenPanel\r\n\r\n\u003Cdiv class=\u0022screen\u0022\u003E\r\n\t\u003Cdiv class=\u0022title\u0022\u003EExample\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022debug\u0022 @onclick=@Click @onmouseover=@OnDebugMouseOver @onmouseout=@OnDebugMouseOut\u003E\r\n\t\t\u003Cdiv class=\u0022test-hover\u0022\u003EHover: @IsHovering\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EPressed: @IsPressed\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EClicks: @ClickCount\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EMouse: @MousePosition\u003C/div\u003E\r\n\r\n\t\t\u003CTextEntry @onclick=@TestClick Value:Bind=@test placeholder=\u0022Quantit\u00E9e\u0022 /\u003E\r\n\t\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022select-debug\u0022\u003E\r\n\t\t\u003Cdiv\u003ETest DropDown\u003C/div\u003E\r\n\t\t\u003CDropDown @ref=\u0022SelectControl\u0022\r\n\t\t\tOptions=\u0022@SelectOptions\u0022\r\n\t\t\tValue=\u0022@SelectedValue\u0022\r\n\t\t\tValueChanged=\u0022@OnSelectChanged\u0022 /\u003E\r\n\t\t\u003Cdiv\u003EValeur du controle : @SelectControl?.Value\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EValeur recue : @SelectedValue\u003C/div\u003E\r\n\t\t\u003Cdiv\u003ECallbacks ValueChanged : @SelectChangeCount\u003C/div\u003E\r\n\t\t\u003Cdiv\u003EDernier changement : @LastSelectChange\u003C/div\u003E\r\n\t\u003C/div\u003E\r\n\r\n\t\u003Cdiv class=\u0022cursor\u0022 style=\u0022left:@CursorLeft; top:@CursorTop;\u0022\u003E\u003C/div\u003E\r\n\t\r\n\u003C/div\u003E\r\n\r\n@code\r\n{\r\n\tpublic Vector2 MousePosition { get; private set; }\r\n\tpublic bool IsHovering { get; private set; }\r\n\tpublic bool IsPressed { get; private set; }\r\n\tpublic int ClickCount { get; private set; }\r\n\tprivate DropDown SelectControl { get; set; }\r\n\tprivate readonly List\u003COption\u003E SelectOptions = new()\r\n\t{\r\n\t\tnew Option( \u0022Choisir une option\u0022, \u0022\u0022 ),\r\n\t\tnew Option( \u0022Option A\u0022, \u0022a\u0022 ),\r\n\t\tnew Option( \u0022Option B\u0022, \u0022b\u0022 ),\r\n\t\tnew Option( \u0022Option C\u0022, \u0022c\u0022 )\r\n\t};\r\n\tprivate string SelectedValue { get; set; } = \u0022\u0022;\r\n\tprivate int SelectChangeCount { get; set; }\r\n\tprivate string LastSelectChange { get; set; } = \u0022Aucun\u0022;\r\n\r\n\tprivate void OnSelectChanged( string value )\r\n\t{\r\n\t\tSelectedValue = value;\r\n\t\tSelectChangeCount\u002B\u002B;\r\n\t\tLastSelectChange = $\u0022{DateTime.Now:HH:mm:ss.fff} : {value}\u0022;\r\n\t\tStateHasChanged();\r\n\t}\r\n\r\n\tprivate string CursorLeft =\u003E $\u0022{MousePosition.x}px\u0022;\r\n\tprivate string CursorTop =\u003E $\u0022{MousePosition.y}px\u0022;\r\n\r\n\tpublic string test { get; set; } = \u0022teste\u0022;\r\n\r\n\tprotected override void OnMouseMove(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseMove(e);\r\n\t\tvar root = FindRootPanel() as TargetRootPanel;\r\n\t\t//MousePosition = root.MousePosition;\r\n\t}\r\n\r\n\tpublic void OnDebugMouseOver(PanelEvent e)\r\n\t{\r\n\t\tIsHovering = true;\r\n\t}\r\n\r\n\tpublic void OnDebugMouseOut(PanelEvent e)\r\n\t{\r\n\t\tIsHovering = false;\r\n\t}\r\n\r\n\tpublic void TestClick(PanelEvent e)\r\n\t{\r\n\t\tLog.Info(\u0022Clicked on text entry\u0022);\r\n\t}\r\n\r\n\tprotected override void OnMouseDown(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseDown(e);\r\n\t\tIsPressed = true;\r\n\t}\r\n\r\n\tprotected override void OnMouseUp(MousePanelEvent e)\r\n\t{\r\n\t\tbase.OnMouseUp(e);\r\n\t\tIsPressed = false;\r\n\t}\r\n\r\n\tpublic void Click(PanelEvent e)\r\n\t{\r\n\t\tClickCount\u002B\u002B;\r\n\t}\r\n\r\n\tprotected override int BuildHash()\r\n\t{\r\n\t\tStateHasChanged();\r\n\t\tvar hash = 17;\r\n\t\thash = hash * 31 \u002B MousePosition.x.GetHashCode();\r\n\t\thash = hash * 31 \u002B MousePosition.y.GetHashCode();\r\n\t\thash = hash * 31 \u002B IsHovering.GetHashCode();\r\n\t\thash = hash * 31 \u002B IsPressed.GetHashCode();\r\n\t\thash = hash * 31 \u002B ClickCount.GetHashCode();\r\n\t\treturn hash;\r\n\t}\r\n}\r\n\r\n\u003Cstyle\u003E\r\n\t.screen {\r\n\t\tcursor: crosshair;\r\n\t\tpointer-events: auto;\r\n\t\tposition: absolute;\r\n\t\tleft: 0;\r\n\t\ttop: 0;\r\n\t\twidth: 100%;\r\n\t\theight: 100%;\r\n\t\tbackground-color: #06111f;\r\n\t\tcolor: white;\r\n\t\tfont-size: 32px;\r\n\t\tfont-weight: bold;\r\n\t}\r\n\r\n\t.title {\r\n\t\tposition: absolute;\r\n\t\tleft: 40px;\r\n\t\ttop: 40px;\r\n\t\tcolor: white;\r\n\t\tfont-size: 64px;\r\n\t}\r\n\r\n\t.debug {\r\n\t\tposition: absolute;\r\n\t\tleft: 40px;\r\n\t\ttop: 140px;\r\n\t\tfont-size: 28px;\r\n\t\tcolor: #9fd4ff;\r\n\t\tflex-direction: column;\r\n\t\twidth:400px;\r\n\t}\r\n\r\n\t\t.debug:hover {\r\n\t\t\tbackground-color: aqua;\r\n\t\t}\r\n\r\n\t\t.debug:active {\r\n\t\t\tbackground-color: red;\r\n\t\t}\r\n\r\n\t.cursor {\r\n\t\tposition: absolute;\r\n\t\twidth: 24px;\r\n\t\theight: 24px;\r\n\t\tbackground-color: red;\r\n\t\tborder-radius: 50%;\r\n\t\ttransform: translate(-50% -50%);\r\n\t}\r\n\r\n\t.select-debug {\r\n\t\tposition: absolute;\r\n\t\tleft: 500px;\r\n\t\ttop: 140px;\r\n\t\twidth: 650px;\r\n\t\tflex-direction: column;\r\n\t\tgap: 12px;\r\n\t\tfont-size: 24px;\r\n\t\tcolor: #9fd4ff;\r\n\t}\r\n\r\n\tTextEntry {\r\n\t\tbackground-color:green;\r\n\t}\r\n\r\n\tTextEntry:focus {\r\n\t\tborder-color: red;\r\n\t}\r\n\u003C/style\u003E\r\n"},{"Ident":"dicta.panelrendertarget","Path":"Debug/CreateFromCodeComponent.cs","FileName":"CreateFromCodeComponent.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\nusing Sandbox;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\npublic class CreateFromCodeRtPanelComponent : Component, Component.DontExecuteOnServer\r\n{\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tbase.OnEnabled();\r\n\t\t\r\n\t\tTargetPanelSystem.Current.CreatePanelScreen\u003CExample\u003E(GameObject, \u0022flatscreen_tv_display\u0022, Material.Load(\u0022materials/screen.vmat\u0022), new Vector2Int(1280, 720));\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":".obj/__compiler_extra.cs","FileName":"__compiler_extra.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"global using static Sandbox.Internal.GlobalGameNamespace;\r\nglobal using Microsoft.AspNetCore.Components;\r\nglobal using Microsoft.AspNetCore.Components.Rendering;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonTitle\u0022, \u0022PanelRenderTarget\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonIdent\u0022, \u0022panelrendertarget\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022OrgIdent\u0022, \u0022dicta\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022Ident\u0022, \u0022dicta.panelrendertarget\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineVersion\u0022, \u002230\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineMinorVersion\u0022, \u00221\u0022 )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \u0022.NETCoreApp,Version=v9.0\u0022, FrameworkDisplayName = \u0022.NET 9.0\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022CompileTime\u0022, \u00222026-10-22T03:54:27.1305106Z\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\u00220.0.115.0\u0022)]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\u00220.0.115.0\u0022)]"},{"Ident":"dicta.panelrendertarget","Path":"Code/ITargetScreen.cs","FileName":"ITargetScreen.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"public interface ITargetScreen\r\n{\r\n    void Tick();\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"ITargetScreen.cs","FileName":"ITargetScreen.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"public interface ITargetScreen\r\n{\r\n    void Tick();\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"PanelTypeReference.cs","FileName":"PanelTypeReference.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\n\nnamespace PanelRenderTarget;\n\n// Stores a panel type by name so scene serialization remains stable.\npublic sealed class PanelTypeReference\n{\n\tpublic string TypeName { get; set; }\n\n\tpublic TypeDescription Resolve()\n\t{\n\t\tif ( string.IsNullOrWhiteSpace( TypeName ) )\n\t\t\treturn null;\n\n\t\tvar typeLibrary = Game.TypeLibrary;\n\t\tif ( typeLibrary is null )\n\t\t\treturn null;\n\n\t\treturn typeLibrary.GetType( typeof( PanelRenderTarget.ScreenPanel ), TypeName, true, true );\n\t}\n}\n"},{"Ident":"dicta.panelrendertarget","Path":"Editor/PanelTypeReferenceEditor.cs","FileName":"PanelTypeReferenceEditor.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox.UI;\nusing Sandbox;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Editor;\n\nnamespace PanelRenderTarget;\n\n[CustomEditor( typeof( PanelTypeReference ) )]\npublic class PanelTypeReferenceEditor : ControlObjectWidget\n{\n\tpublic override bool SupportsMultiEdit =\u003E false;\n\n\tprivate readonly ComboBox _typeSelector;\n\tprivate readonly List\u003CTypeDescription\u003E _panelTypes;\n\n\tpublic PanelTypeReferenceEditor( SerializedProperty property ) : base( property, false )\n\t{\n\t\tLayout = Layout.Column();\n\t\tLayout.Spacing = 4;\n\n\t\t_panelTypes = EditorTypeLibrary.GetTypes\u003CScreenPanel\u003E()\n\t\t\t.Where( x =\u003E !x.IsAbstract \u0026\u0026 x.TargetType != null )\n\t\t\t.OrderBy( x =\u003E x.Title ?? x.Name )\n\t\t\t.ToList();\n\n\t\tvar row = Layout.AddRow();\n\t\trow.Add( new Editor.Label( \u0022Panel Type\u0022 ) { MinimumWidth = 120 } );\n\t\t_typeSelector = row.Add( new ComboBox( this ), 1 );\n\n\t\t_typeSelector.AddItem( \u0022(Aucun)\u0022 );\n\n\t\tfor ( int i = 0; i \u003C _panelTypes.Count; i\u002B\u002B )\n\t\t{\n\t\t\t_typeSelector.AddItem( _panelTypes[i].Title ?? _panelTypes[i].Name );\n\t\t}\n\n\t\tvar current = SerializedProperty.GetValue\u003CPanelTypeReference\u003E();\n\t\tvar currentTypeName = current?.TypeName;\n\n\t\tif ( string.IsNullOrWhiteSpace( currentTypeName ) )\n\t\t{\n\t\t\t_typeSelector.CurrentIndex = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvar idx = _panelTypes.FindIndex( x =\u003E\n\t\t\t\tx.TargetType?.FullName == currentTypeName ||\n\t\t\t\tx.ClassName == currentTypeName ||\n\t\t\t\tx.Name == currentTypeName );\n\n\t\t\t_typeSelector.CurrentIndex = idx \u003E= 0 ? idx \u002B 1 : 0;\n\t\t}\n\n\t\t_typeSelector.ItemChanged \u002B= OnTypeChanged;\n\t}\n\n\tprivate void OnTypeChanged()\n\t{\n\t\tif ( _typeSelector.CurrentIndex \u003C= 0 )\n\t\t{\n\t\t\tSerializedProperty.SetValue( new PanelTypeReference() );\n\t\t\treturn;\n\t\t}\n\n\t\tvar selected = _panelTypes[_typeSelector.CurrentIndex - 1];\n\n\t\tSerializedProperty.SetValue( new PanelTypeReference\n\t\t{\n\t\t\tTypeName = selected.TargetType.FullName\n\t\t} );\n\t}\n}\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/PanelSceneObject.cs","FileName":"PanelSceneObject.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\n//try to make panel is not visible when doesnt need update maybe that optimise the Ui rendering\r\npublic class PanelSceneObject : SceneCustomObject\r\n{\r\n\tprivate readonly TargetRootPanel _panel;\r\n\tprivate readonly Texture _texture;\r\n\tprivate RenderTarget _renderTarget;\r\n\r\n\tprivate float _timeSinceLastRender = 0f;\r\n\r\n\tpublic Vector2 CursorPosition { get; set; }\r\n\tpublic bool IsFocus { get; set; } = false;\r\n\tpublic string CursorIcon { get; set; } = \u0022arrow_selector_tool\u0022;\r\n\r\n\tpublic readonly TargetScreen Screen;\r\n\r\n\tprivate int _renderCount = 0;\r\n\r\n\tpublic bool InitPassed { get; set; } = false;\r\n\r\n\tpublic PanelSceneObject(\r\n\t\tBBox bound,\r\n\t\tSceneWorld sceneWorld,\r\n\t\tTargetRootPanel panel,\r\n\t\tTexture texture,\r\n\t\tTargetScreen screen\r\n\t) : base( sceneWorld )\r\n\t{\r\n\t\t_panel = panel;\r\n\t\t_texture = texture;\r\n\t\t_renderTarget = RenderTarget.From( _texture );\r\n\t\tBounds = bound;\r\n\t\tScreen = screen;\r\n\t\tFlags.IsOpaque = true;\r\n\t\tFlags.IsTranslucent = false;\r\n\t\tFlags.WantsPrePass = false;\r\n\t\t//this.GetGameObject\r\n\t}\r\n\r\n\tpublic override void RenderSceneObject()\r\n\t{\r\n\t\tbase.RenderSceneObject();\r\n\t\tif ( !_texture.IsLoaded || !_panel.IsValid() )\r\n\t\t\treturn;\r\n\r\n\t\t_timeSinceLastRender \u002B= Time.Delta;\r\n\r\n\t\tvar updateRate = IsFocus\r\n\t\t\t? 1f / Screen.UpdateRateFocus\r\n\t\t\t: 1f / Screen.UpdateRateNotFocused;\r\n\r\n\t\tif ( InitPassed \u0026\u0026 _timeSinceLastRender \u003C updateRate )\r\n\t\t\treturn;\r\n\r\n\t\t//we make 5 render init because with alot of panel some doesnt update the texture full\r\n\t\tif ((!IsFocus \u0026\u0026 Screen.UpdateWhenNotFocused == false) \u0026\u0026 _renderCount \u003E 5 )\r\n\t\t{\r\n\t\t\tInitPassed = true;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\r\n\t\t_timeSinceLastRender = 0f;\r\n\r\n\t\t\r\n\t\t_renderCount\u002B\u002B;\r\n\r\n\t\tvar bounds = new Rect( 0, 0, _texture.Width, _texture.Height );\r\n\r\n\t\t_panel.FixedBounds = bounds;\r\n\t\t_panel.PanelBounds = bounds;\r\n\t\t_panel.FixedScale = 1f;\r\n\t\t//_panel.Scale = 1f;\r\n\t\tvar oldTarget = Graphics.RenderTarget;\r\n\t\tvar oldViewport = Graphics.Viewport;\r\n\r\n\t\tGraphics.RenderTarget = _renderTarget;\r\n\t\tGraphics.Viewport = bounds;\r\n\r\n\t\tGraphics.Attributes.SetCombo( \u0022D_WORLDPANEL\u0022, 0 );\r\n\t\t//_panel.MarkRenderDirty();\r\n\r\n\t\t_panel.RenderManual();\r\n\t\t\r\n\t\tif ( IsFocus \u0026\u0026 Screen.ShowVirtualCursor )\r\n\t\t{\r\n\t\t\tvar cursorRect = new Rect(\r\n\t\t\t\tCursorPosition.x,\r\n\t\t\t\tCursorPosition.y - 8,\r\n\t\t\t\t0,\r\n\t\t\t\t0\r\n\t\t\t);\r\n\t\t\tGraphics.DrawText( cursorRect, \u0022.\u0022, Color.Red, \u0022Roboto\u0022, 32f );\r\n\t\t}\r\n\r\n\t\tGraphics.GenerateMipMaps( _texture );\r\n\r\n\t\tGraphics.Viewport = oldViewport;\r\n\t\tGraphics.RenderTarget = oldTarget;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"Code/ScreenPanel.cs","FileName":"ScreenPanel.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"namespace PanelRenderTarget;\r\n\r\n//placeholder for get better list in type editor we can list all Screen Panels and not just Panel\r\npublic abstract class ScreenPanel : Sandbox.UI.Panel\r\n{\r\n\t\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"TargetRootPanel.cs","FileName":"TargetRootPanel.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Sandbox.UI;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace PanelRenderTarget;\r\n\r\npublic class TargetRootPanel : RootPanel\r\n{\r\n\r\n\tpublic Rect FixedBounds { get; set; } = new Rect( 0, 0, 1280, 720 );\r\n\tpublic float FixedScale { get; set; } = 1f;\r\n\r\n\tpublic new Vector2 MousePosition { get; set; }\r\n\r\n\tpublic MouseVisibility MouseVisibility { get; set; } = MouseVisibility.Hidden;\r\n\r\n\tpublic override void Tick()\r\n\t{\r\n\t\tbase.Tick();\r\n\t\tif ( MouseVisibility == MouseVisibility.Visible \u0026\u0026 Mouse.Visibility != MouseVisibility.Visible )\r\n\t\t{\r\n\t\t\tMouse.Visibility = MouseVisibility.Visible;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override void OnDeleted()\r\n\t{\r\n\t\tbase.OnDeleted();\r\n\t\tif ( MouseVisibility == MouseVisibility.Visible )\r\n\t\t{\r\n\t\t\tMouse.Visibility = MouseVisibility.Auto;\r\n\t\t}\r\n\t}\r\n\r\n\tprotected override void UpdateBounds( Rect rect )\r\n\t{\r\n\t\tPanelBounds = FixedBounds;\r\n\t}\r\n\r\n\tprotected override void UpdateScale( Rect screenSize )\r\n\t{\r\n\t\tScale = FixedScale;\r\n\t}\r\n\r\n\tprotected override void OnChildAdded( Panel child )\r\n\t{\r\n\t\tbase.OnChildAdded( child );\r\n\r\n\t\t// Native popups normally attach directly to FindPopupPanel(), this root.\r\n\t\tif ( child is not BasePopup popup )\r\n\t\t\treturn;\r\n\r\n\t\tpopup.StayOpen = true;\r\n\r\n\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource is DropDown )\r\n\t\t{\r\n\t\t\tmenu.AddEventListener( \u0022onclick\u0022, e =\u003E\r\n\t\t\t{\r\n\t\t\t\tif ( !menu.IsValid() || menu.IsDeleting || !e.Target.IsValid() )\r\n\t\t\t\t\treturn;\r\n\r\n\t\t\t\t// The option\u0027s own click handler runs before the event reaches its menu.\r\n\t\t\t\t// This also closes the menu when the selected value did not change.\r\n\t\t\t\tif ( e.Target.AncestorsAndSelf.OfType\u003CButton\u003E().Any( button =\u003E button.Parent == menu ) )\r\n\t\t\t\t\tmenu.Delete();\r\n\t\t\t} );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EClose local popups. Returns true when the click closed its own popup button\u0027s menu.\u003C/summary\u003E\r\n\tpublic bool CloseLocalPopups( Panel clickedPanel )\r\n\t{\r\n\t\tif ( !clickedPanel.IsValid() || clickedPanel.FindRootPanel() != this )\r\n\t\t\treturn false;\r\n\r\n\t\tbool closedSourcePopup = false;\r\n\t\tvar keep = new HashSet\u003CBasePopup\u003E();\r\n\t\tvar pending = new Stack\u003CPanel\u003E();\r\n\t\tif ( clickedPanel.IsValid() \u0026\u0026 clickedPanel.FindRootPanel() == this )\r\n\t\t\tpending.Push( clickedPanel );\r\n\r\n\t\twhile ( pending.Count \u003E 0 )\r\n\t\t{\r\n\t\t\tforeach ( var popup in pending.Pop().AncestorsAndSelf.OfType\u003CBasePopup\u003E() )\r\n\t\t\t{\r\n\t\t\t\tif ( popup.FindRootPanel() != this || !keep.Add( popup ) )\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource.IsValid()\r\n\t\t\t\t\t\u0026\u0026 menu.PopupSource.FindRootPanel() == this )\r\n\t\t\t\t\tpending.Push( menu.PopupSource );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach ( var popup in Descendants.OfType\u003CBasePopup\u003E().ToArray() )\r\n\t\t{\r\n\t\t\tif ( popup.IsValid() \u0026\u0026 !popup.IsDeleting \u0026\u0026 popup.FindRootPanel() == this \u0026\u0026 !keep.Contains( popup ) )\r\n\t\t\t{\r\n\t\t\t\tif ( popup is Popup menu \u0026\u0026 menu.PopupSource is PopupButton source\r\n\t\t\t\t\t\u0026\u0026 clickedPanel.IsValid() \u0026\u0026 clickedPanel.AncestorsAndSelf.Contains( source ) )\r\n\t\t\t\t\tclosedSourcePopup = true;\r\n\r\n\t\t\t\tpopup.Delete();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn closedSourcePopup;\r\n\t}\r\n}\r\n"},{"Ident":"dicta.panelrendertarget","Path":"UnitTests/LibraryTest.cs","FileName":"LibraryTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":427873,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n[TestClass]\r\npublic partial class LibraryTests\r\n{\r\n\t[TestMethod]\r\n\tpublic void SceneTest()\r\n\t{\r\n\t\tvar scene = new Scene();\r\n\t\tusing ( scene.Push() )\r\n\t\t{\r\n\t\t\tvar go = new GameObject();\r\n\r\n\t\t\tAssert.AreEqual( 1, scene.Directory.GameObjectCount );\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"}]}