//Called in chain when you delete an element private void ReplaceWithNextItem(int currentRow, int currentColumn) { if (!IsLastColumn(currentRow) || !IsLastRow(currentColumn)) { HorizontalGridItem next = GetNextElement(currentRow, currentColumn); if (next != null) { if (!IsLastColumn(currentColumn)) { elements[currentRow, currentColumn] = next; elements[currentRow, currentColumn + 1] = null; elements[currentRow, currentColumn].OnActionCompleted = OnFinishOperation; elements[currentRow, currentColumn].MoveBack(positions[new Vector2(currentRow, currentColumn)], currentRow, (currentColumn + 1), ReplaceWithNextItem); } // end if else { next.OnActionCompleted -= OnFinishOperation; next.MoveAndHide(helperPos[new Vector2(currentRow + 1, -1)]); HorizontalGridItem reemplaze = availableItems.Pop(); reemplaze.SetData(next.Id, next.ItemName); reemplaze.Show(helperPos[new Vector2(currentRow, 1)], true); elements[currentRow + 1, 0] = null; elements[currentRow, currentColumn] = reemplaze; elements[currentRow, currentColumn].MoveBack(positions[new Vector2(currentRow, currentColumn)], (currentRow + 1), 0, ReplaceWithNextItem); } } else { OnFinishOperation(); } } // end if }
public void InsertItem(string itemId, string itemName) { if (!inAction) { if (!IsGridFull()) { if (!Contains(itemId)) { Vector2 index = ObtainPlacementIndex(itemName); // sorting by name HorizontalGridItem item = availableItems.Pop(); item.SetData(itemId, itemName); InsertItem(item, (int)index.x, (int)index.y); } // end check else { OnFinishOperation(); } } // end else { OnFinishOperation(); } } else { //Debug.LogError("agregando a queue insert item " + itemName); actionsQueue.EnqueueInsertAction(new GridAction(itemId, itemName, InsertItem)); } }
private void InsertItem(HorizontalGridItem item, int row, int col) { HorizontalGridItem last = AssignElement(item.GetComponent <HorizontalGridItem>(), row, col); if (last != null) // there is elements to move { int NERow = row; int NECol = col + 1; if (IsLastColumn(col)) // we check if we need to go a change row { NERow++; NECol = 0; } if (NERow < elements.GetLength(0)) // if not the last element { for (int i = NERow; i < elements.GetLength(0) && last != null; i++) { for (int j = NECol; j < elements.GetLength(1) && last != null; j++) { if (!IsFirstColumn(j)) { HorizontalGridItem temp = elements[i, j]; elements[i, j] = last; MoveElement(elements[i, j], positions[new Vector2(i, j)]); //Debug.LogError(elements[i, j].gameObject.name + "movido a " + i + "," + j); last = temp; } else { HorizontalGridItem temp = elements[i, j]; HorizontalGridItem hideReplacement = last; hideReplacement.MoveAndHide(helperPos[new Vector2(i - 1, 1)]); HorizontalGridItem reeplazement = availableItems.Pop(); reeplazement.SetData(last.Id, last.ItemName); reeplazement.Show(helperPos[new Vector2(i, -1)], true); elements[i, j] = reeplazement; MoveElement(elements[i, j], positions[new Vector2(i, j)]); //Debug.LogError(elements[i, j].gameObject.name + "movido a " + i + "," + j); last = temp; } } NECol = 0; } // end for } // end if there is next row else { OnFinishOperation(); } } // end if there is next element else { OnFinishOperation(); } }
/// <summary> /// Asgin an item to the grid, if there was an item before it returns it, if not returns null /// </summary> /// <param name="item"></param> /// <param name="row"></param> /// <param name="column"></param> /// <returns></returns> private HorizontalGridItem AssignElement(HorizontalGridItem item, int row, int col) { HorizontalGridItem last = elements[row, col]; elements[row, col] = item; elements[row, col].OnActionCompleted = OnFinishOperation; elements[row, col].Show(positions[new Vector2(row, col)]); return(last); }
private HorizontalGridItem RemoveElement(int row, int col) { HorizontalGridItem last = elements[row, col]; last.OnActionCompleted = OnFinishOperation; //last.gameObject.SetActive(false); last.Hide(row, col, ReplaceWithNextItem); elements[row, col] = null; return(last); }
private void LoadPosterValues(HorizontalGridItem item) { MovieSearchOutputData data = cacheData.Find(cache => cache.Id == item.Id); if (data != null) { MoviePosterView posterButton = item.GetComponent <MoviePosterView>(); posterButton.SetData(data.Id, data.Title, data.Poster); } }
private HorizontalGridItem GetNextElement(int row, int col) { HorizontalGridItem item = null; int nextRow = row; int nextCol = col; if (IsLastColumn(col)) { nextRow = row + 1; nextCol = 0; } else { nextCol = col + 1; } if (nextRow < elements.GetLength(0)) { item = elements[nextRow, nextCol]; } return(item); }
private void ReturnItemToStack(HorizontalGridItem item) { availableItems.Push(item); }
private void MoveElement(HorizontalGridItem item, Vector2 position) { item.OnActionCompleted = OnFinishOperation; item.Move(position); }