mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
* Remove unnecessary static singletons in MainMenu code * Empty SceneWorld delete queues during shutdown * Dresser cancel async load operation on destroy * Use reflection to null references to static native resources on shutdown This way we don't have to remember doing this manually. * Fix SoundOcclusionSystem using static lists to reference resources * Sound System: Use weak references to refer to scenes * Cleanup static logging listeners that kept strong refs to panels * UISystem Cleanup, make sure all panel/stylesheet refs are released * RenderTarget and RenderAttributes shutdown cleanup * Rework AvatarLoader, ThumbLoader & HTTPImageLoader Cache First try to go through ResourceLibrary.WeakIndex which might already hold the texture. If there is no hit, go through a second cache that caches HTTP & Steam API response bytes instead of textures. We want to cache the response bytes rather than the actual Texture, so stuff cached sits in RAM not VRAM. Before avatars and thumbs would reside in VRAM. * Fix rendertarget leak in CommandList.Attr.SetValue GetDepthTarget() / GetColorTarget() return a new strong handle (ref count +1). We need to DestroyStrongHandle() that ref. So handles don't leak. * Call EngineLoop.DrainFrameEndDisposables before shutdown * NativeResourceCache now report leaks on shutdown * Override Resource.Destroy for native resources, kill stronghandles * Deregister SceneWorld from SceneWorld.All during destruction * Ensure async texture loading cancels on shutdown * SkinnedModelRender bonemergetarget deregister from target OnDisabled * Clear shaderMaterials cache during shutdown * Refactor Shutdown code Mostly renaming methods from Clear() -> Shutdown() Adding separate GlobalContext.Shutdown function (more aggressive than GlobalContext.Reset). Clear some static input state. * Deregister surfaces from Surface.All in OnDestroy * RunAllStaticConstructors when loading a mount * Advanced managed resource leak tracker enabled via `resource_leak_tracking 1` Works by never pruning the WeakTable in NativeResourceCache. So we can check for all resources if they are still being held on to and log a callstack.
97 lines
1.5 KiB
C#
97 lines
1.5 KiB
C#
using Sandbox.Engine;
|
|
using Sandbox.Internal;
|
|
|
|
namespace Sandbox.UI;
|
|
|
|
internal static class TooltipSystem
|
|
{
|
|
static IPanel lastHovered;
|
|
static IPanel lastTooltip;
|
|
|
|
internal static void Clear()
|
|
{
|
|
lastTooltip?.Delete( true );
|
|
lastTooltip = null;
|
|
lastHovered = null;
|
|
}
|
|
|
|
internal static void SetHovered( IPanel current )
|
|
{
|
|
if ( lastHovered == current )
|
|
return;
|
|
|
|
if ( current == null )
|
|
{
|
|
lastHovered = null;
|
|
lastTooltip?.Delete( false );
|
|
lastTooltip = null;
|
|
return;
|
|
}
|
|
|
|
if ( !current.HasTooltip )
|
|
{
|
|
SetHovered( current.Parent );
|
|
return;
|
|
}
|
|
|
|
lastHovered = current;
|
|
|
|
if ( current != null )
|
|
{
|
|
lastTooltip?.Delete( false );
|
|
lastTooltip = current.CreateTooltip();
|
|
Frame();
|
|
}
|
|
}
|
|
|
|
internal static void Frame()
|
|
{
|
|
if ( !lastTooltip.IsValid() )
|
|
return;
|
|
|
|
if ( !InputRouter.MouseCursorVisible )
|
|
{
|
|
lastTooltip?.Delete( false );
|
|
lastTooltip = null;
|
|
lastHovered = null;
|
|
return;
|
|
}
|
|
|
|
if ( lastHovered.IsValid() )
|
|
{
|
|
lastHovered.UpdateTooltip( lastTooltip );
|
|
}
|
|
|
|
//
|
|
// Given the mouse position, try to position the tooltip
|
|
// so it's not hanging off the screen. Not actually doing any
|
|
// kind of restrict to screen or anything.
|
|
//
|
|
|
|
var pos = InputRouter.MouseCursorPosition;
|
|
|
|
TextFlag align = 0;
|
|
|
|
if ( pos.x < Screen.Size.x * 0.70f )
|
|
{
|
|
align |= TextFlag.Right;
|
|
}
|
|
else
|
|
{
|
|
align |= TextFlag.Left;
|
|
}
|
|
|
|
if ( pos.y > Screen.Size.y * 0.1f )
|
|
{
|
|
align |= TextFlag.Top;
|
|
}
|
|
else
|
|
{
|
|
align |= TextFlag.Bottom;
|
|
}
|
|
|
|
lastTooltip.SetAbsolutePosition( align, pos, 20 );
|
|
|
|
}
|
|
}
|