0

I have a problem with my Custom-"Item Tip". When I am with my mouse at the "start of the Tip, it's showing only text and not the whole UI.

When I am only in the Inventory Item but not at the Tool Tip: enter image description here

When I am between being in it and not(I changed the color of the text to read so you can see it better): enter image description here

MyCode:

public class InventorySlot : VisualElement
{

    public Image Icon;
    public string ItemGuid = "";
    public string itemName = "";
    public Seltenheit itemSeltenheit = 0;
    public List<WerteType> stats = new List<WerteType>();

    //Visual Element Dinge
    private UIDocument tip;
    private VisualElement ve;
    private Label name, seltenheit, schaden, schaden1, schaden2;
    private float top, left;
    public InventorySlot(Sprite sprite, UIDocument tooltip, float top, float left)
    {
        tip = tooltip;
        this.top = top;
        this.left = left;
        var rootElement = tip.rootVisualElement;
        ve = rootElement.Q<VisualElement>("tooltip");
        name = rootElement.Q<Label>("name");
        seltenheit = rootElement.Q<Label>("seltenheit");
        schaden = rootElement.Q<Label>("schaden");
        ve.style.display = DisplayStyle.None;

        Icon = new Image();
        Add(Icon);
        Icon.style.paddingBottom = 15;
        Icon.style.paddingTop = 15;
        Icon.style.paddingLeft = 15;
        Icon.style.paddingRight = 15;
        Icon.style.flexGrow = 1;
        style.width = 64;
        style.height = 64;
        style.marginBottom = 5;
        style.marginTop = 5;
        style.marginLeft = 5;
        style.marginRight = 5;
        style.backgroundImage = new StyleBackground(sprite);
        RegisterCallback<PointerDownEvent>(OnPointerDown);
        RegisterCallback<PointerLeaveEvent>(OnPointerLeave);
        RegisterCallback<PointerEnterEvent>(OnPointerEnter);

    }
    private void OnPointerLeave(PointerLeaveEvent evt)
    {
        ve.style.display = DisplayStyle.None;
        ToolTipDatenLeeren();

    }

    private void OnPointerEnter(PointerEnterEvent evt)
    {
        ToolTipDaten();
        ToolTipAufrufen();
    }

    private void ToolTipAufrufen()
    {
        var coordinaten = worldBound.center;
        ve.transform.position = new Vector2(coordinaten.x - left, (coordinaten.y - top));
        ve.style.backgroundColor = new StyleColor(Color.red);
        ve.style.display = DisplayStyle.Flex;

    }
    private void ToolTipDaten()
    {
        name.text = itemName;
        seltenheit.text = itemSeltenheit.ToString();

        if (stats == null)
            stats = new List<WerteType>();
        if (stats.Count > 0)
            schaden.text = stats.ToString();
    }

    private void ToolTipDatenLeeren()
    {
        name.text = "";
        seltenheit.text = "";
        schaden.text = "";
        stats = null;
    }


    #region HoldItem
    private void OnPointerDown(PointerDownEvent evt)
    {
        //Not the left mouse button
        if (evt.button != 0 || ItemGuid.Equals(""))
        {
            return;
        }
        //Clear the image
        Icon.image = null;
        //Start the drag
        Inventar.StartDrag(evt.position, this);
    }
    public void HoldItem(Item item)
    {
        Icon.sprite = item.Icon;
        ItemGuid = item.GUID;
        itemName = item.Name;
        itemSeltenheit = item.seltenheit;

        AusruestungsItems aItem = (AusruestungsItems)item;
        if (aItem != null)
            stats = aItem.stats;
    }
    public void DropItem()
    {
        ItemGuid = "";
        Icon.sprite = null;
    }
    #endregion
}
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41

0 Answers0