private void ShiftElements() { List <RearrangementElement> newElementList = new List <RearrangementElement>(); List <List <GameObject> > rounds = UIManager.instance.rounds; int currentRound = CombatManager.instance.currentRound - 1; bool isNewRound = UIManager.instance.newRound; for (int i = currentRound; i < rounds.Count; ++i) { for (int j = 0; j < rounds[i].Count; ++j) { if (i == currentRound && j == 0) { if (isNewRound) { UIManager.instance.newRound = false; } else { continue; } } RectTransform elementRect = rounds[i][j].GetComponent <RectTransform>(); Vector2 startPos = elementRect.anchoredPosition; Vector2 endPos = new Vector2(startPos.x, startPos.y + UIManager.instance.GetShiftAmount(isNewRound)); RearrangementElement shiftingElement = new RearrangementElement(startPos, endPos, elementRect); newElementList.Add(shiftingElement); } } StartCoroutine(RearrangeElements("SHIFT", newElementList)); }
public void HideElement() { int currentRound = CombatManager.instance.currentRound; List <RearrangementElement> elementList = new List <RearrangementElement>(); GameObject element = rounds[currentRound - 1][1]; RectTransform elementRect = element.GetComponent <RectTransform>(); Vector2 startPos = elementRect.anchoredPosition; Vector2 endPos = new Vector2(startPos.x + 200f, startPos.y); RearrangementElement rElement = new RearrangementElement(startPos, endPos, elementRect); elementList.Add(rElement); rounds[currentRound - 1].RemoveAt(1); StartCoroutine(UIAnimations.instance.RearrangeElements("HIDE", elementList)); }
public void NextRound() { ResetCombatPointsBar(); int currentRound = CombatManager.instance.currentRound; List <RearrangementElement> elementList = new List <RearrangementElement>(); for (int i = 0; i < rounds[currentRound - 1].Count; ++i) { RectTransform elementRect = rounds[currentRound - 1][i].GetComponent <RectTransform>(); Vector2 startPos = elementRect.anchoredPosition; Vector2 endPos = new Vector2(startPos.x + 200f, startPos.y); RearrangementElement rElement = new RearrangementElement(startPos, endPos, elementRect); elementList.Add(rElement); } ++CombatManager.instance.currentRound; ConvertElements(); newRound = true; StartCoroutine(UIAnimations.instance.RearrangeElements("HIDE", elementList)); }
public void WaitOnClick() { DeselectButton(); waitButton.interactable = false; skipButton.interactable = false; if (!GameStateManager.instance.CheckState("COMBAT")) { return; } List <RearrangementElement> elementList = new List <RearrangementElement>(); string whoseTurn = CombatManager.instance.whoseTurn; int currentRound = CombatManager.instance.currentRound; for (int i = 1; i < rounds[currentRound - 1].Count; ++i) { var elementScript = rounds[currentRound - 1][i].GetComponent <QueueElement>(); var rect = rounds[currentRound - 1][i].GetComponent <RectTransform>(); if (elementScript.attachedGameObject.name == whoseTurn) { Vector2 newPos = new Vector2(rect.anchoredPosition.x, rect.anchoredPosition.y - (rounds[currentRound - 1].Count - 2) * queueElementSize.y); RearrangementElement newElement = new RearrangementElement(rect.anchoredPosition, newPos, rect); elementList.Insert(0, newElement); } else { Vector2 newPos = new Vector2(rect.anchoredPosition.x, rect.anchoredPosition.y + queueElementSize.y); RearrangementElement newElement = new RearrangementElement(rect.anchoredPosition, newPos, rect); elementList.Add(newElement); } } CombatManager.instance.movementTilemap.ClearAllTiles(); StartCoroutine(UIAnimations.instance.RearrangeElements("WAIT", elementList)); }
public void RefillQueue(int lastRoundElements, string whichStage) { List <RearrangementElement> elementList = new List <RearrangementElement>(); int totalQueueElements = 0; int currentRound = CombatManager.instance.currentRound; for (int i = currentRound - 1; i < rounds.Count; ++i) { for (int j = 1; j < rounds[i].Count; ++j) { ++totalQueueElements; } } int refillCount = maxCombatQueueElements - totalQueueElements; List <GameObject> combatOrder = CombatManager.instance.combatOrder; int combatQueueCount = combatOrder.Count; int counter = lastRoundElements; for (int i = totalQueueElements; i < maxCombatQueueElements; ++i) { if (i < combatQueueCount) { GameObject combatUnit = combatOrder[i]; GameObject elementInstance = CreatePrimaryCombatQueueElement(combatUnit, currentRound); // Since the position are not driven by a layout group, we have to do it manually. RectTransform elementRTransform = elementInstance.GetComponent <RectTransform>(); Vector2 newPos = new Vector2(200f, i * queueElementSize.y * -1 - spaceAfterRound); elementRTransform.anchoredPosition = newPos; RearrangementElement newElement = new RearrangementElement(newPos, new Vector2(0f, newPos.y), elementRTransform); elementList.Add(newElement); } else { if (counter == combatQueueCount) { counter = 0; rounds.Add(new List <GameObject>()); Vector2 anchoredPos = new Vector2(200f, i * queueElementSize.y * -1 - spaceAfterRound * GetTotalRoundTexts()); RectTransform roundTextRect = CreateRoundTextInstance(lastRoundVisible + 1, anchoredPos); RearrangementElement roundTextElement = new RearrangementElement(anchoredPos, new Vector2(0f, anchoredPos.y), roundTextRect); elementList.Add(roundTextElement); } int roundTexts = GetTotalRoundTexts(); float space = spaceAfterRound * roundTexts; GameObject combatUnit = combatOrder[counter]; GameObject elementInstance = CreateSecondaryCombatQueueElement(combatUnit, lastRoundVisible); RectTransform elementRTransform = elementInstance.GetComponent <RectTransform>(); Vector2 newPos = new Vector2(200f, i * queueElementSize.y * -1 - space); elementRTransform.anchoredPosition = newPos; RearrangementElement newElement = new RearrangementElement(newPos, new Vector2(0f, newPos.y), elementRTransform); elementList.Add(newElement); ++counter; } } combatVisRect.sizeDelta = new Vector2(combatVisRect.sizeDelta.x, combatVisualisationBaseHeight + queuePanelRTransform.sizeDelta.y); if (whichStage == "REARRANGING") { StartCoroutine(UIAnimations.instance.RearrangeElements("NEW", elementList)); } else if (whichStage == "SHIFT") { StartCoroutine(UIAnimations.instance.RearrangeElements("LAST", elementList)); } }
public void DeathChange(GameObject dyingUnit) { List <RearrangementElement> elementList = new List <RearrangementElement>(); List <RectTransform> deathElements = new List <RectTransform>(); // Cycle through each round and each round element, gather up dying elements as well as other moving elements. int currentRound = CombatManager.instance.currentRound; for (int i = currentRound - 1; i < rounds.Count; ++i) { List <int> indices = new List <int>(); for (int j = 0; j < rounds[i].Count; ++j) { GameObject element = rounds[i][j]; var elementScript = element.GetComponent <QueueElement>(); if (elementScript.attachedGameObject == dyingUnit) { // Getting the dying unit index in the combat queue. Everything below should be moved above. indices.Add(j); // Creating the skull on the dying unit's element. GameObject skull = Instantiate(deathPanel, Vector2.zero, Quaternion.identity, element.transform); RectTransform skullRect = skull.GetComponent <RectTransform>(); skullRect.anchoredPosition = Vector2.zero; // Setting up values to move the element away RectTransform elementRect = element.GetComponent <RectTransform>(); deathElements.Add(elementRect); Vector2 newPos = new Vector2(elementRect.rect.width * 4, elementRect.anchoredPosition.y); RearrangementElement movingElement = new RearrangementElement(elementRect.anchoredPosition, newPos, elementRect); rounds[i].RemoveAt(j); elementList.Add(movingElement); } } } // Triple layered loop to gather amount to move for each element in the rounds. foreach (RectTransform deathElement in deathElements) { for (int i = currentRound - 1; i < rounds.Count; ++i) { for (int j = 0; j < rounds[i].Count; ++j) { RectTransform element = rounds[i][j].GetComponent <RectTransform>(); var elementScript = element.GetComponent <QueueElement>(); if (element.anchoredPosition.y < deathElement.anchoredPosition.y) { elementScript.amountToMove += queueElementSize.y; } } } } // Go through each element for (int i = currentRound - 1; i < rounds.Count; ++i) { for (int j = 0; j < rounds[i].Count; ++j) { RectTransform element = rounds[i][j].GetComponent <RectTransform>(); var elementScript = element.GetComponent <QueueElement>(); if (elementScript.attachedGameObject == dyingUnit) { continue; } Vector2 startPos = element.anchoredPosition; Vector2 endPos = new Vector2(element.anchoredPosition.x, element.anchoredPosition.y + elementScript.amountToMove); elementScript.amountToMove = 0f; RearrangementElement rElement = new RearrangementElement(startPos, endPos, element); UIAnimations.instance.secondElementList.Add(rElement); } } // Moving the elements. StartCoroutine(UIAnimations.instance.RearrangeElements("DYING", elementList)); }