// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. using System; using System.IO; using System.Text; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Content { /// /// Asset item object. /// /// [HideInEditor] public abstract class AssetItem : ContentItem { /// /// Gets the asset unique identifier. /// public Guid ID { get; protected set; } /// /// Gets the asset type identifier. /// public string TypeName { get; } /// /// Initializes a new instance of the class. /// /// The asset path. /// The asset type name. /// The asset identifier. protected AssetItem(string path, string typeName, ref Guid id) : base(path) { TypeName = typeName; ID = id; } /// protected override void UpdateTooltipText() { var sb = new StringBuilder(); OnBuildTooltipText(sb); TooltipText = sb.ToString(); } private sealed class TooltipDoubleClickHook : Control { public AssetItem Item; public TooltipDoubleClickHook() { AnchorPreset = AnchorPresets.StretchAll; Offsets = Margin.Zero; } public override bool OnMouseDoubleClick(Vector2 location, MouseButton button) { return Item.OnMouseDoubleClick(Item.ScreenToClient(ClientToScreen(location)), button); } } /// public override void OnTooltipShown(Tooltip tooltip) { base.OnTooltipShown(tooltip); // Inject the hook control for the double-click event (if user double-clicks on tooltip over the asset item it will open that item - helps on small screens) var hook = tooltip.GetChild(); if (hook == null) hook = tooltip.AddChild(); hook.Item = this; } /// /// Called when building tooltip text. /// /// The String Builder. protected virtual void OnBuildTooltipText(StringBuilder sb) { sb.Append("Type: ").Append(TypeName).AppendLine(); sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine(); sb.Append("Path: ").Append(Path).AppendLine(); } /// public override ContentItemType ItemType => ContentItemType.Asset; /// /// Determines whether asset is of the specified type (included inheritance checks). /// /// The type to check. /// true if asset is of the specified type (including inherited types); otherwise, false. public bool IsOfType() { return IsOfType(typeof(T)); } /// /// Determines whether asset is of the specified type (included inheritance checks). /// /// The type to check. /// true if asset is of the specified type (including inherited types); otherwise, false. public virtual bool IsOfType(Type type) { return false; } /// protected override bool DrawShadow => true; /// public override ContentItem Find(Guid id) { return id == ID ? this : null; } /// public override string ToString() { return Path + ":" + ID; } } }