Class UITKPanelPositions
Stores where the player has dragged each panel, and the grid those drags snap to.
public static class UITKPanelPositions
- Inheritance
-
UITKPanelPositions
- Inherited Members
Remarks
Panel positions have to survive two very different lifetimes, and the shorter one is the
reason this exists at all. Hiding a panel disables its UnityEngine.UIElements.UIDocument,
and re-enabling it clones the UXML afresh — so the inline left/top a drag
wrote are discarded the first time the panel is closed. Without somewhere outside the
visual tree to keep them, "move the inventory window" only lasted until the player pressed
the key that closed it.
The longer lifetime is the session. Values live in GlobalSettings
under UI.Panel.<name>.X / .Y, beside every other client setting, so a
player's arrangement is still there next launch.
Reads happen here; writes go through ClientSettings. This class used to own a debounce timer of its own, which meant two independent timers rewriting the same whole file on their own schedules — see ClientSettings for what that cost. There is one pending write in the client and one place that flushes it.
Coordinates are panel points, not screen pixels. PanelSettings is authored ScaleWithScreenSize against a 1200x800 reference matching on width, so a stored X means the same thing on any monitor; the visible height in points changes with aspect ratio, which is why UITKControl re-clamps a restored position rather than trusting it.
Fields
DefaultSnapGridSize
Grid used when the player has never chosen one.
public const float DefaultSnapGridSize = 8
Field Value
Remarks
Small enough to feel like free movement and large enough that two panels dragged roughly level actually end up level. Zero disables snapping entirely.
KeyPrefix
Prefix for the per-panel configuration keys.
public const string KeyPrefix = "UI.Panel."
Field Value
Remarks
Public because UIProfile copies these keys wholesale into and out of a shareable profile and has to agree with this class about which keys those are. A second copy of the literal is one rename away from a profile that saves nothing and a load that wipes every window position.
MaxSnapGridSize
Largest grid the options slider offers, in panel points.
public const float MaxSnapGridSize = 32
Field Value
SnapGridKey
Configuration key holding the drag snap grid, in panel points.
public const string SnapGridKey = "UI.SnapGridSize"
Field Value
Properties
SnapGridSize
The drag snap grid in panel points. Zero disables snapping.
public static float SnapGridSize { get; set; }
Property Value
Methods
Clear(string)
Forgets a panel's stored position, returning it to wherever its stylesheet puts it.
public static void Clear(string panelName)
Parameters
panelNamestringThe panel's GameObject name.
InvalidateSnapGrid()
Drops the cached snap grid so the next read comes from the configuration again.
public static void InvalidateSnapGrid()
Remarks
Needed because the configuration can be replaced wholesale after this has been read —
UITKOptions.EnsureConfigurationLoaded creates and loads it lazily, and a panel
dragged before the options screen was ever opened would otherwise keep snapping to the
compiled-in default for the rest of the session.
Snap(Vector2)
Rounds a position onto the snap grid.
public static Vector2 Snap(Vector2 position)
Parameters
positionVector2Desired top-left, in panel points.
Returns
- Vector2
The position rounded to the nearest grid intersection, or unchanged when snapping is off.
Store(string, Vector2)
Records where the player left a panel.
public static void Store(string panelName, Vector2 position)
Parameters
panelNamestringThe panel's GameObject name.
positionVector2Top-left, in panel points.
TryLoad(string, out Vector2)
Reads the stored position for a panel.
public static bool TryLoad(string panelName, out Vector2 position)
Parameters
panelNamestringThe panel's GameObject name, as registered with UIManager.
positionVector2The stored top-left, in panel points.
Returns
- bool
True when the player has moved this panel before.