public void RemoveInterface(UIContainer uiObject)
 {
     if (uiObject == null)
     {
         throw new ArgumentNullException("uiObject");
     }
     _interfaces.RemoveAll(wr => wr.Target == null || wr.Target == uiObject);
 }
 public bool AddInterface(UIContainer uiObject)
 {
     ClearNull();
     if (uiObject == null)
     {
         throw new ArgumentNullException("uiObject");
     }
     if (_interfaces.Any(wr => wr.Target == uiObject))
     {
         return(false);
     }
     _interfaces.Add(new WeakReference(uiObject));
     return(true);
 }
        private void OnRender(UIContainer container, IUIWindow window)
        {
            if (container.UIObjects == null)
            {
                return;
            }
            for (int j = 0; j < container.UIObjects.Length; j++)
            {
                var uiObject = container.UIObjects[j];
                if (uiObject.Callback != null)
                {
                    var newValue = window.Draw(
                        j,
                        true,
                        uiObject.Value,
                        uiObject.Text
                        );

                    if (uiObject.Value == null)
                    {
                        try
                        {
                            uiObject.Callback(newValue);
                        }
                        catch (Exception e)
                        {
                            ErrorOnce(
                                j + ": " + container.Key,
                                "Callback for {0}-{1} (null) failed:\n{2}",
                                container.Title,
                                j,
                                e
                                );
                        }
                    }
                    ///Hahaha, this is ugly and can easily break, but whatever
                    else if (newValue.GetHashCode() != uiObject.Value.GetHashCode())
                    {
                        try
                        {
                            uiObject.Callback(newValue);
                        }
                        catch (Exception e)
                        {
                            ErrorOnce(
                                j + ": " + container.Key,
                                "Callback for {0}-{1} ({2}=>{3}) failed:\n{3}",
                                container.Title,
                                j,
                                uiObject.Value.GetType(),
                                newValue.GetType(),
                                e
                                );
                        }
                        uiObject.Value = newValue;
                    }
                }
                else
                {
                    window.Draw(
                        j,
                        false,
                        uiObject.Value,
                        uiObject.Text
                        );
                }
                if (uiObject.NewLine)
                {
                    window.NewLine();
                }
                container.UIObjects[j] = uiObject;
            }
        }