Game.UI.Editor.ExternalLinkField
Assembly: Game (inferred)
Namespace: Game.UI.Editor
Type: class
Base: Widget
Summary:
ExternalLinkField is a UI Widget used by the mod upload/editor UI to collect, validate and serialize a list of external links associated with an asset/mod. It exposes a list of IModsUploadSupport.ExternalLinkData entries, accepted link types derived from IModsUploadSupport.ExternalLinkInfo, and a maximum number of allowed links. The widget serializes its state via WriteProperties for the UI JSON writer and integrates with AssetUploadUtils for validation and type-locking behavior. It also contains an inner Bindings class that provides binding triggers to add, remove or set links from UI bindings.
Fields
-
private static readonly IModsUploadSupport.ExternalLinkData kDefaultLink
Default link template used when adding a new link. It is initialized with the first accepted type from IModsUploadSupport.ExternalLinkInfo.kAcceptedTypes and an empty URL. -
private static readonly string[] kAcceptedTypes
Array of accepted external link type strings derived from IModsUploadSupport.ExternalLinkInfo.kAcceptedTypes (project-defined list of accepted types). -
public List<IModsUploadSupport.ExternalLinkData> links { get; set; }
Public auto-property storing the current list of external links. Defaults to an empty list. Each entry is an IModsUploadSupport.ExternalLinkData with m_Type and m_URL. -
public int maxLinks { get; set; }
Public auto-property for the maximum allowed links. Default value: 5. -
public class Bindings : IWidgetBindingFactory
(nested)
Factory for widget bindings that exposes trigger bindings that can be used from UI binding scripts to manipulate the widget: - "setExternalLink" — parameters: (int index, string type, string url) — sets link at index.
- "removeExternalLink" — parameter: (int index) — removes link at index.
- "addExternalLink" — no parameters — adds a new default link.
Properties
-
public List<IModsUploadSupport.ExternalLinkData> links { get; set; }
List of current external links. Mutations call SetPropertiesChanged() so the UI will be updated/serialized. -
public int maxLinks { get; set; }
Maximum number of links allowed. The widget exposes this to the UI; note the Add() method does not enforce this limit in-code (UI should use maxLinks to prevent user from adding beyond it).
Constructors
public ExternalLinkField()
No explicit constructor is defined in source; default constructor is used and auto-properties are initialized inline (links = new List<...>(), maxLinks = 5). The widget relies on overridden WriteProperties to emit its state.
Methods
protected override void WriteProperties(IJsonWriter writer)
Serializes the widget state for the UI writer. It writes:- "links": an array of ExternalLinkData entries serialized by WriteExternalLink.
- "acceptedTypes": the kAcceptedTypes array.
-
"maxLinks": the maxLinks integer.
-
private void WriteExternalLink(IJsonWriter writer, IModsUploadSupport.ExternalLinkData link)
Writes a single ExternalLinkData object using the writer. The serialized object includes: - "type": link.m_Type
- "url": link.m_URL
- "error": boolean indicating validation failure — based on !AssetUploadUtils.ValidateExternalLink(link)
-
"lockType": result of AssetUploadUtils.LockLinkType(link.m_URL, out _) — indicates whether link type should be locked to a specific type based on URL
-
private void SetValue(int index, string type, string url)
Sets/overwrites the link at the given index with the provided type and url. Before assignment, it checks AssetUploadUtils.LockLinkType(url, out var lockedType) and, if locked, overrides the provided type with the lockedType. After updating links[index], it calls SetPropertiesChanged() to mark the widget as changed. -
Note: No explicit bounds checking for index is present in the source — callers should ensure index is valid.
-
private void Remove(int index)
Removes the link at the specified index via links.RemoveAt(index) and calls SetPropertiesChanged(). -
Note: No bounds checking is performed here — callers must ensure index validity.
-
private void Add()
Adds a new link using the kDefaultLink template and calls SetPropertiesChanged(). -
Note: The method does not enforce maxLinks; the UI should respect maxLinks to prevent adding too many entries.
-
public IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
(in Bindings)
Creates three TriggerBinding entries for the widget: - setExternalLink: triggers SetValue(index, type, url) and calls onValueChanged(widget)
- removeExternalLink: triggers Remove(index) and calls onValueChanged(widget)
- addExternalLink: triggers Add() and calls onValueChanged(widget)
Usage Example
// Create and manipulate the widget instance in code:
var extField = new ExternalLinkField();
// Add a new default link
extField.Add();
// Directly modify a link (ensure index is valid)
extField.SetValue(0, "website", "https://example.com");
// Remove a link (ensure index is valid)
extField.Remove(0);
// The widget will call SetPropertiesChanged() on modifications so the UI system can refresh/serialize it.
// Example of how the widget exposes accepted types and maxLinks in its JSON output:
// "acceptedTypes": [ "website", "github", ... ]
// "maxLinks": 5
// Using bindings (from UI binding scripts), the available triggers are:
// - setExternalLink(groupWidget, index, type, url)
// - removeExternalLink(groupWidget, index)
// - addExternalLink(groupWidget)
Additional notes: - The widget relies on AssetUploadUtils for validation and for determining if a URL enforces (locks) its link type. Validation status is exposed as the "error" boolean in the serialized link objects. - The code does not perform index bounds checking or enforce maxLinks in the Add method; ensure the UI or caller code prevents invalid operations.