Пример #1
0
 public void Add(DrawElement aDrawable)
 {
     if (null != mList && null != aDrawable)
     {
         if (!mList.Contains(aDrawable))
         {
             mList.Add(aDrawable);
         }
     }
 }
Пример #2
0
 //
 private void UpdatePropertyList(DrawElement obj)
 {
     // Depends on Object....
     //if (ElementTracker.Instance.TrackObj != obj)
     {
         obj.Factory.PopulatePropertyList(obj.Property);
         obj.Factory.UpdateProperty(obj);
         FactoryManager.getInstance().SetSelectedFactory(obj.Factory);
     }
 }
Пример #3
0
        public DrawElement FindTrackObj(Point point, DrawElement hitItem)
        {
            // If diff track obj than must change it
            // If in Hotspot
            // If nothing
            // IF in item
            if (FindHotSpot(point) != null)
            {
                return(TrackObj);
            }

            return(hitItem);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="listProperty">The array property to be drawn.</param>
        /// <param name="headerTitle">The title to display in the list header.</param>
        /// <param name="singleClickDelete">
        /// If true, the list will support single click deleting of elements.  Otherwise the
        /// default Unity behavior will be used.
        /// </param>
        /// <param name="elementHeight">The draw height of each element.</param>
        /// <param name="onDrawElement">The method to use for drawing an element. (Required)</param>
        /// <param name="onAddElement">
        /// The method to use for adding new elements, or null for default Unity behavior.
        /// </param>
        public ReorderableListControl(SerializedProperty listProperty,
                                      string headerTitle, bool singleClickDelete, float elementHeight,
                                      DrawElement onDrawElement, UpdateListElement onAddElement = null)
        {
            if (onDrawElement == null)
            {
                throw new System.ArgumentNullException("onDrawElement");
            }

            m_ElementHeight = elementHeight;
            m_OnAddElement  = onAddElement;
            m_OnDrawElement = onDrawElement;

            m_List = CreateList(listProperty, headerTitle, singleClickDelete);
        }
Пример #5
0
        public DrawElement GetHitItem(Point point)
        {
            DrawElement hitItem = null;
            int         count   = mList.Count - 1;

            for (int i = count; i >= 0; i--)
            {
                hitItem = (DrawElement)mList[i];
                if (hitItem.hitTest(point))
                {
                    return(hitItem);
                }
            }

            return(null);
        }
Пример #6
0
        //
        private void WriteProperty(DrawElement item, XmlElement node)
        {
            PropertyObject propObj = null;
            int index = 0;
            List<PropertyObject> listProp = new List<PropertyObject>(item.Property.List.Values);

            foreach (String prop in item.Property.List.Keys)
            {
                propObj = listProp[index];
                //if (propObj.IsModified())
                {
                    node.SetAttribute(propObj.Name, propObj.Text);
                }
                index++;
            }
        }
Пример #7
0
 /// <summary>sets attributes of a control based on what properties were set</summary>
 ///
 private void SetItemAttribs(DrawElement item, XmlElement node)
 {
     XmlElement properties = m_XmlDom.CreateElement("", "Properties", "");
     node.AppendChild(properties);
     foreach (String strKey in item.Property.List.Keys)
     {
         if (strKey.Equals("Id"))
         {
             node.SetAttribute(strKey, item.Property.GetValue(strKey));
         }
         else if (!string.IsNullOrEmpty(item.Property.GetValue(strKey)))
         {
             XmlElement nodeChild = m_XmlDom.CreateElement("", strKey, "");
             nodeChild.InnerText = item.Property.GetValue(strKey);
             properties.AppendChild(nodeChild);
         }
     }
 }
Пример #8
0
        public static ElementProperty CreateParam(DrawElement obj)
        {
            ElementProperty prop = null;

            if (obj is ElementWindow)
            {
                prop = new ElementPropertyWindow();
            }
            else if (obj is ElementButton)
            {
                prop = new ElementPropertyButton();
            }
            if (prop != null)
            {
                prop.InitDefaultProperty();
            }
            return(prop);
        }
Пример #9
0
        public void onMouseDown(MouseEventArgs e)
        {
            DrawElement hitItem = null;

            mptLastPos     = e.Location;
            hitItem        = FindTrackObj(e.Location, HitObj);
            TrackObj       = hitItem;
            m_AddToHistory = false;
            if (TrackObj != null)
            {
                if (TrackObj.Moveable)
                {
                    TrackObj.Drag = true;
                    HandleMouseDown(e);
                }
                // Need to move in the manager class
                TrackObj.onMouseDown(e);
            }
        }
Пример #10
0
        //
        public void CreateChildlement(XmlNode node)
        {
            FactoryShape factoryShape = FactoryManager.getInstance().GetFactory(node.Name);
            DrawElement  model        = factoryShape.CreateControl();

            ElementProperty prop = FactoryActionParam.CreateParam(model);

            model.Property = prop;

            foreach (XmlAttribute attr in node.Attributes)
            {
                prop.SetValue(attr.Name, attr.Value);
            }


            try
            {
                XmlNodeList propertiesNodes = node.FirstChild.ChildNodes;
                foreach (XmlNode nodeProp in propertiesNodes)
                {
                    prop.SetValue(nodeProp.Name, nodeProp.InnerText);
                }
            }
            catch (Exception e)
            {
            }



            factoryShape.PopulatePropertyList(prop);
            m_GridView.Tag = prop;
            Action action = factoryShape.CreateAddAction(model, m_Window);

            action.SetParam(prop);
            //
            mHostory.ExcuteAction(action);
        }
Пример #11
0
 public Action(IController controller)
 {
     mController = controller;
     m_Model     = null;
     m_Tracker   = ElementTracker.Instance;
 }
Пример #12
0
 public void Remove(DrawElement obj)
 {
     mList.Remove(obj);
 }
        public ReorderableCollection(SerializedProperty property, SerializedProperty collection)
        {
            bool   allowDrag     = true;
            object pathReference = SerializationReflection.GetPathReference(property);

            if (pathReference != null)
            {
                Type sortedType = SerializationReflection.GetPathReference(property).GetType();

                while (sortedType != null)
                {
                    if (sortedType.GetInterface("SortedCollection`1") != null)
                    {
                        allowDrag = false;
                        break;
                    }
                    sortedType = sortedType.BaseType;
                }
            }

            string collectionPath = CollectionDisplay.GetFullPath(collection);

            DisplayState listState;

            if (ListStates.ContainsKey(collectionPath))
            {
                ListStates.Remove(collectionPath);
            }

            listState = new DisplayState();
            ListStates.Add(collectionPath, listState);
            listState.Collection = collection;
            listState.List       = this;

            DrawerState drawerState = CollectionDisplay.GetDrawerState(property);
            var         newList     = new ReorderableList(collection.serializedObject, collection)
            {
                draggable = allowDrag,
            };

            newList.showDefaultBackground = false;

            newList.onReorderCallbackWithDetails = (ReorderableList list, int oldIndex, int newIndex) =>
            {
                Reorder?.Invoke(drawerState.Property, listState.Collection, oldIndex, newIndex);
            };

            newList.drawHeaderCallback = (Rect position) =>
            {
                SerializedProperty hasLostValue = drawerState.Property.FindPropertyRelative("hasLostValue");
                if (hasLostValue != null && hasLostValue.boolValue == true)
                {
                    EditorUtility.DisplayDialog("Collection Error", "You've attempted to change an element in a way that prevents it from being added to the collection. The element will be moved to the Add Element area of the list so you can change the element and add it back in.", "Okay");
                    ListStates[CollectionDisplay.GetFullPath(listState.Collection)].AddingElement = true;
                    hasLostValue.boolValue = false;
                }

                Rect startPosition = position;

                DrawHeaderBackground(position, drawerState.Property, listState.Collection);
                DrawSettingsButton(position, drawerState.Property, listState.Collection);
                position.y += DrawSettings(position, drawerState.Property, listState.Collection);

                for (var i = 0; i < DrawHeaderAreaHandlers.Count; i++)
                {
                    position.y += DrawHeaderAreaHandlers[i].Invoke(position, drawerState.Property, listState.Collection);
                }

                listState.LastHeaderHeight = position.y - startPosition.y;
                newList.headerHeight       = listState.LastHeaderHeight;
            };

            newList.drawElementCallback += (Rect position, int index, bool isActive, bool isFocused) =>
            {
                position.y += 2;

                var pageRange = GetPageDisplayRange(listState.Collection);
                if (index >= pageRange.x && index < pageRange.y)
                {
                    EditorGUI.BeginDisabledGroup(listState.AddingElement);
                    DrawElement?.Invoke(position, index, drawerState.Property, listState.Collection);
                    EditorGUI.EndDisabledGroup();
                }
            };

            newList.drawElementBackgroundCallback = (Rect position, int index, bool isActive, bool isFocused) =>
            {
                if (Mathf.Approximately(position.height, 0))
                {
                    return;
                }

                Rect backgroundPos = position;
                backgroundPos.yMin       -= 2;
                backgroundPos.yMax       += 2;
                boxBackground.fixedHeight = backgroundPos.height;
                boxBackground.fixedWidth  = backgroundPos.width;
                Color guiColor = UnityEngine.GUI.color;

                if (isActive)
                {
                    UnityEngine.GUI.color = UnityEngine.GUI.skin.settings.selectionColor;
                }

                if (index % 2 == 0)
                {
                    UnityEngine.GUI.color = Color.Lerp(UnityEngine.GUI.color, Color.black, .1f);
                }

                if (Event.current.type == EventType.Repaint)
                {
                    boxBackground.Draw(position, false, isActive, true, false);
                }

                UnityEngine.GUI.color = guiColor;

                position.xMin += 2;
                position.xMax -= 3;
            };

            newList.elementHeightCallback += (int index) =>
            {
                int pageSize       = GetItemsPerPage(listState.Collection);
                int pageStartIndex = (listState.CurrentPageSet * listState.PageSetSize * pageSize) + (listState.CurrentPage * pageSize);
                int pageEndIndex   = pageStartIndex + pageSize;

                if (index >= pageStartIndex && index < pageEndIndex && (GetElementHeight != null))
                {
                    return(GetElementHeight(index, drawerState.Property, listState.Collection) + 2);
                }

                return(0);
            };

            newList.drawFooterCallback = (Rect position) =>
            {
                DrawFooterBackground(position, drawerState.Property, listState.Collection);
                DrawAddRemoveButtons(position, drawerState.Property, listState.Collection);

                Rect startPosition = position;
                for (var i = 0; i < DrawFooterAreaHandlers.Count; i++)
                {
                    position.y += DrawFooterAreaHandlers[i].Invoke(position, drawerState.Property, listState.Collection);
                }

                position.y += DrawPageSelection(position, drawerState.Property, listState.Collection);
                if (listState.List.DrawCustomAdd)
                {
                    position.y += DrawAddArea(position, property, collection);
                }

                listState.LastFooterHeight  = position.y - startPosition.y;
                listState.LastFooterHeight += 4;
                List.footerHeight           = listState.LastFooterHeight;
            };

            newList.onRemoveCallback += (ReorderableList targetList) =>
            {
                if (targetList.index > -1)
                {
                    int pageSize       = GetItemsPerPage(listState.Collection);
                    int pageStartIndex = GetPageDisplayRange(listState.Collection).x;
                    listState.Collection.DeleteArrayElementAtIndex(pageStartIndex + targetList.index);
                }
            };

            newList.onAddCallback += (ReorderableList targetList) =>
            {
                if (DrawCustomAdd)
                {
                    ListStates[collectionPath].AddingElement = !ListStates[collectionPath].AddingElement;
                    if (ListStates[collectionPath].AddingElement)
                    {
                        SerializationReflection.CallPrivateMethod(property, "ClearTemp");
                    }
                }
                else
                {
                    listState.Collection.InsertArrayElementAtIndex(listState.Collection.arraySize);
                }
            };

            List = newList;
        }
Пример #14
0
 protected void DrawInvoke(IEnumerable <LayoutDrawElement> drawElements)
 {
     DrawElement?.Invoke(this, new DrawEventArgs(drawElements.ToArray()));
 }