public void Add(PTFlatGroupElement element) { if (element && !Contains(element)) { content.Add(element); } }
public void Remove(PTFlatGroupElement element) { if (element && Contains(element)) { content.Remove(element); } }
public void CreateElements(int num) { //Only for testing use for (int i = 0; i < num; ++i) { PTFlatGroupElement element = Instantiate(elementPrefab).GetComponent <PTFlatGroupElement>(); ptZone.Add(element.transform, timerAnimation); } UpdateContent(); }
public void AddCollection(PTFlatGroupElement element) { if (Contains(element)) { return; } else { PTFlatGroupCollection newCollection = new PTFlatGroupCollection(false); newCollection.Add(element); Collections.Add(newCollection); } }
public KeyValuePair <int, PTFlatGroupCollection> FindCollectionWithIndexBy(PTFlatGroupElement element) { if (Collections != null && element != null) { for (int i = 0; i < Collections.Count; i++) { if (Collections[i].Contains(element)) { return(new KeyValuePair <int, PTFlatGroupCollection>(i, Collections[i])); } } } return(new KeyValuePair <int, PTFlatGroupCollection>(-1, null)); }
public void Calibrate(bool rearrange) { //put all elements on children to a list List <PTFlatGroupElement> listChildrenElements = new List <PTFlatGroupElement>(); foreach (Transform child in ptZone.content) { PTFlatGroupElement currElement = child.GetComponent <PTFlatGroupElement>(); if (currElement) { listChildrenElements.Add(currElement); } } HashSet <PTFlatGroupElement> elementsToRemoveFromCollections = new HashSet <PTFlatGroupElement>(); foreach (PTFlatGroupCollection collection in Collections) { foreach (PTFlatGroupElement element in collection.content) { //Remove the element from collection if current element doesn't exist in the transform children if (!listChildrenElements.Contains(element)) { //Take a note of which elements are going to delete try { elementsToRemoveFromCollections.Add(element); } catch { } } //Remove the element from list if current element exist in both list and collection else { listChildrenElements.Remove(element); } } } foreach (PTFlatGroupElement element in elementsToRemoveFromCollections) { Remove(element); } //Add the rest children to collection foreach (PTFlatGroupElement element in listChildrenElements) { AddCollection(element); } if (rearrange) { UpdateContent(); } }
public bool Contains(PTFlatGroupElement element) { if (!element) { return(false); } foreach (PTFlatGroupCollection collection in Collections) { if (collection.Contains(element)) { return(true); } } return(false); }
public int GetSiblingIndex(PTFlatGroupElement element) { int ret = 0; for (int i = 0; i < Collections.Count; ++i) { for (int j = 0; j < Collections[i].Count; ++j) { if (Collections[i].content[j] == element) { return(ret); } ++ret; } } return(-1); }
public void UnGroup(PTFlatGroupElement element) { KeyValuePair <int, PTFlatGroupCollection> collection = FindCollectionWithIndexBy(element); if (collection.Value != null) { collection.Value.Remove(element); PTFlatGroupCollection newCollection = new PTFlatGroupCollection(false); newCollection.Add(element); Collections.Insert(collection.Key + 1, newCollection); collection.Value.UpdateBackground(this); if (collection.Value.Count == 0) { Collections.Remove(collection.Value); } } UpdateContent(); }
public int GetSiblingIndexExpected(PTFlatGroupElement element) { int siblingIndexHover = GetSiblingIndexHover(element.transform.position); KeyValuePair <int, PTFlatGroupCollection> collectionHover = FindCollectionWithIndexBy(siblingIndexHover); int siblingIndexCurr = GetSiblingIndex(element); int elementDistance = Mathf.Abs(siblingIndexHover - siblingIndexCurr); int offset = siblingIndexHover > siblingIndexCurr ? 1 : -1; KeyValuePair <int, PTFlatGroupCollection> collectionInTheWay = FindCollectionWithIndexBy(siblingIndexHover - offset); if (collectionHover.Value == null || collectionHover.Value.Contains(element) || collectionInTheWay.Value == null) { return(siblingIndexHover); } else { //Debug.Log(siblingIndexIntent + " " + siblingIndexCurr + " " + elementDistance + " " + collectionHover.Count); if (collectionHover.Value.isGroup) { if (elementDistance > collectionInTheWay.Value.Count) { return(siblingIndexHover - offset); } } else { if (elementDistance == collectionInTheWay.Value.Count) { return(siblingIndexHover); } else { return(siblingIndexHover - offset); } } return(siblingIndexCurr); } }
public void Remove(PTFlatGroupElement element) { //Remove from collection PTFlatGroupCollection collection = FindCollectionBy(element); if (collection != null) { if (collection.Contains(element)) { collection.Remove(element); } if (collection.Count == 0) { Collections.Remove(collection); } } //unparent if (element != null && this == element.GetComponentInParent <PTFlatGroups>()) { element.transform.SetParent(null); } }
public void SwapElements(int siblingIndexA, int siblingIndexB) { if (siblingIndexA >= 0 && siblingIndexA < ptZone.Count && siblingIndexB >= 0 && siblingIndexB < ptZone.Count && Mathf.Abs(siblingIndexA - siblingIndexB) == 1) { //locate KeyValuePair <int, PTFlatGroupCollection> collectionA = FindCollectionWithIndexBy(siblingIndexA); KeyValuePair <int, PTFlatGroupCollection> collectionB = FindCollectionWithIndexBy(siblingIndexB); PTFlatGroupElement elementA = ptZone.Get(siblingIndexA).GetComponent <PTFlatGroupElement>(); PTFlatGroupElement elementB = ptZone.Get(siblingIndexB).GetComponent <PTFlatGroupElement>(); //swap int indexElementA = collectionA.Value.IndexOf(elementA); int indexElementB = collectionB.Value.IndexOf(elementB); collectionA.Value.Remove(elementA); int targetInsertIndex = indexElementA < collectionA.Value.Count ? indexElementA : collectionA.Value.Count; collectionA.Value.Insert(targetInsertIndex, elementB); collectionB.Value.Remove(elementB); collectionB.Value.Insert(indexElementB, elementA); //update content UpdateContent(); } }
public bool Contains(PTFlatGroupElement element) { return(content.Find(x => x == element) != null); }
public void Insert(int index, PTFlatGroupElement element) { content.Insert(index, element); }
public int IndexOf(PTFlatGroupElement element) { return(content.IndexOf(element)); }
public PTFlatGroupCollection FindCollectionBy(PTFlatGroupElement element) { return(FindCollectionWithIndexBy(element).Value); }