public override void OnDirectionMove(UIState.Direction direction) { if (selectedViewIndex == -1) { OnClickView(0); } int currentRow = selectedViewIndex / viewGroup.Column; int currentColumn = selectedViewIndex % viewGroup.Column; int upRow = (currentRow - 1 + viewGroup.Row) % viewGroup.Row; int downRow = (currentRow + 1) % viewGroup.Row; int leftColumn = (currentColumn - 1 + viewGroup.Column) % viewGroup.Column; int rightColumn = (currentColumn + 1) % viewGroup.Column; int upIndex = upRow * viewGroup.Column + currentColumn; int downIndex = downRow * viewGroup.Column + currentColumn; int leftIndex = currentRow * viewGroup.Column + leftColumn; int rightIndex = currentRow * viewGroup.Column + rightColumn; int totalItems = CountTotalItemsOfTab(currentTab); int currentSelectionPos = currentViewPage * viewGroup.views.Count + selectedViewIndex; switch (direction) { case UIState.Direction.UP: // if needed, refresh page if (currentViewPage > 0 && currentRow == 0) { currentViewPage--; OnClickTab((int)currentTab); } OnClickView(upIndex); break; case UIState.Direction.LEFT: OnClickView(leftIndex); break; case UIState.Direction.DOWN: if (currentRow == viewGroup.Row - 1) { if (CountTotalItemsOfTab(currentTab) > (currentViewPage + 1) * viewGroup.views.Count) { currentViewPage++; OnClickTab((int)currentTab); } } OnClickView(downIndex); break; case UIState.Direction.RIGHT: OnClickView(rightIndex); break; default: break; } }
public override void OnDirectionMove(UIState.Direction direction) { int currentRow = currentSelection / selectionViews.Column; int currentColumn = currentSelection % selectionViews.Column; int upRow = (currentRow - 1 + selectionViews.Row) % selectionViews.Row; int downRow = (currentRow + 1) % selectionViews.Row; int leftColumn = (currentColumn - 1 + selectionViews.Column) % selectionViews.Column; int rightColumn = (currentColumn + 1) % selectionViews.Column; int upIndex = upRow * selectionViews.Column + currentColumn; int downIndex = downRow * selectionViews.Column + currentColumn; int leftIndex = currentRow * selectionViews.Column + leftColumn; int rightIndex = currentRow * selectionViews.Column + rightColumn; int totalItems = 0; if (currentSlot == 0) { totalItems = playerStock.weaponStock.Count; } else if (currentSlot == 1 || currentSlot == 2) { totalItems = playerStock.wearableStock.Count; } int currentSelectionPos = currentPage * itemsPerPage + currentSelection; switch (direction) { case UIState.Direction.UP: // if needed, refresh page if (currentPage > 0 && currentRow == 0) { currentPage--; DisplaySelectionView(currentSlot); } OnClickSelectionItem(upIndex); //Debug.Log("move up"); break; case UIState.Direction.LEFT: OnClickSelectionItem(leftIndex); //Debug.Log("move left"); break; case UIState.Direction.DOWN: if (currentRow == selectionViews.Row - 1) { if (totalItems > (currentPage + 1) * selectionViews.views.Count) { currentPage++; DisplaySelectionView(currentSlot); } } OnClickSelectionItem(downIndex); //Debug.Log("move down"); break; case UIState.Direction.RIGHT: OnClickSelectionItem(rightIndex); //Debug.Log("move right index: " + rightIndex); break; default: break; } }