public void PutChipsIntoPot() { bool areThereChipsNotInPot = false; for (int playerIndex = 0; playerIndex < _currentGame.Players.Count; playerIndex++) { Player player = _currentGame.Players[playerIndex]; Transform playerTransform = PlayersParent.transform.Find("Player" + playerIndex); Transform blindsTransform = playerTransform.Find("Blinds"); for (int chipIndex = blindsTransform.childCount - 1; chipIndex >= 0; chipIndex--) { if (!areThereChipsNotInPot) { areThereChipsNotInPot = true; } Transform childTransform = blindsTransform.GetChild(chipIndex); GameObject.Destroy(childTransform.gameObject); } blindsTransform.DetachChildren(); } if (!areThereChipsNotInPot) { return; } int potIndex = 0; // TODO: reset chipPosition.y between pots foreach (Pot pot in _currentGame.CurrentHand.Pots) { Transform potTransform = PotsParent.transform.Find("Pot" + potIndex); if (potTransform == null) { Debug.LogError("PutChipsIntoPot: could not find pot transform, pot index = " + potIndex); break; } int potSize = pot.Size; for (int chipDenominationIndex = _chipDenominations.Length - 1; chipDenominationIndex >= 0; chipDenominationIndex--) { int denomination = (int)_chipDenominations[chipDenominationIndex]; if (denomination > potSize) { continue; } while (potSize >= denomination) { GameObject chipObject = GameObject.Instantiate(ChipPrefab); ChipWidget chipWidget = chipObject.GetComponent <ChipWidget>(); chipWidget.Denomination = _chipDenominations[chipDenominationIndex]; Vector3 chipPosition = potTransform.position; // one child is pot size text int chipsCount = potTransform.childCount - 1; if (chipsCount > 0) { int chipsInStack = chipsCount; int stackIndex = 0; if (chipsCount >= Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS) { stackIndex = chipsCount / Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS; chipsInStack = chipsCount % Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS; } // TODO: correct this magic if (stackIndex > 0) { chipPosition.x += (chipWidget.ImageWidth * stackIndex); } chipPosition.y += (chipWidget.ImageHeight * chipsInStack) / 6; } chipObject.transform.parent = potTransform; chipObject.transform.localPosition = chipPosition; chipObject.transform.localScale = Vector3.one; potSize -= denomination; } } if (potSize > 0) { Debug.LogError("PutChipsIntoPot: wrong bet amount (could not be presented with current chip denominations)."); } potIndex++; } // old variant with all the players chips in pot unchanged //if (player.CurrentBet > 0) { // Transform playerTransform = PlayersParent.transform.Find("Player" + playerIndex); // Transform blindsTransform = playerTransform.Find("Blinds"); // for (int chipIndex = blindsTransform.childCount - 1; chipIndex >= 0; chipIndex--) { // Transform childTransform = blindsTransform.GetChild(chipIndex); // GameObject chipObject = childTransform.gameObject; // ChipWidget chipWidget = chipObject.GetComponent<ChipWidget>(); // Vector3 chipPosition = Pot.transform.position; // int chipsCountInPot = Pot.transform.childCount; // if (chipsCountInPot > 0) { // int chipsInStack = chipsCountInPot; // int stackColumn = 0, stackRow = 0; // if (chipsCountInPot >= Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS) { // stackColumn = (chipsCountInPot / Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS) % Defines.MAX_STACKS_IN_ONE_ROW_IN_BETS; // stackRow = (chipsCountInPot / Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS) / Defines.MAX_STACKS_IN_ONE_ROW_IN_BETS; // chipsInStack = chipsCountInPot % Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS; // } // // TODO: correct this magic // if (stackColumn > 0) { // chipPosition.x += (chipWidget.ImageWidth * stackColumn); // } // if (stackRow > 0) { // chipPosition.y -= (chipWidget.ImageHeight * stackRow); // } // chipPosition.y += (chipWidget.ImageHeight * chipsInStack) / 6; // } // childTransform.parent = Pot.transform; // childTransform.localPosition = chipPosition; // } // blindsTransform.DetachChildren(); //} //} _currentAmountToBet = 0; }
private void PutChipsInfrontPlayer(Transform place, int betAmount, ChipAlignment chipAlignment = ChipAlignment.Right) { if (chipAlignment == ChipAlignment.Invalid) { Debug.LogWarning("PutChipsInfrontPlayer: chipAlignment is invalid, applying right alignment."); chipAlignment = ChipAlignment.Right; } for (int chipDenominationIndex = _chipDenominations.Length - 1; chipDenominationIndex >= 0; chipDenominationIndex--) { int denomination = (int)_chipDenominations[chipDenominationIndex]; if (denomination > betAmount) { continue; } while (betAmount >= denomination) { GameObject chipObject = GameObject.Instantiate(ChipPrefab); ChipWidget chipWidget = chipObject.GetComponent <ChipWidget>(); chipWidget.Denomination = _chipDenominations[chipDenominationIndex]; Vector3 chipPosition = place.position; int chipsCount = place.childCount; if (chipsCount > 0) { int chipsInStack = chipsCount; int stackIndex = 0; if (chipsCount >= Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS) { stackIndex = chipsCount / Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS; chipsInStack = chipsCount % Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS; } // TODO: correct this magic if (stackIndex > 0) { if (chipAlignment == ChipAlignment.Right) { chipPosition.x += (chipWidget.ImageWidth * stackIndex); } else if (chipAlignment == ChipAlignment.Left) { chipPosition.x -= (chipWidget.ImageWidth * stackIndex); } } chipPosition.y += (chipWidget.ImageHeight * chipsInStack) / 6; } chipObject.transform.parent = place; chipObject.transform.localPosition = chipPosition; chipObject.transform.localScale = Vector3.one; betAmount -= denomination; } } if (betAmount > 0) { Debug.LogError("PutChipsInfrontPlayer: wrong bet amount (could not be presented with current chip denominations)."); } }