void GetOldestProximalBubblePosition(out int newBubbleXCoordinate, out int newBubbleYCoordinate, int[] firstPosition, int[] secondPosition, int[] thirdPosition, int[] fourthPosition, int bubbleParentX, int bubbleParentY) { newBubbleXCoordinate = -1; newBubbleYCoordinate = -1; // IF not parent AND position valid, returns age index, ELSE returns int.MaxValue. int firstPositionDesirability = GetPositionDesirability(firstPosition, bubbleParentX, bubbleParentY); int secondPositionDesirability = GetPositionDesirability(secondPosition, bubbleParentX, bubbleParentY); int thirdPositionDesirability = GetPositionDesirability(thirdPosition, bubbleParentX, bubbleParentY); int fourthPositionDesirability = GetPositionDesirability(fourthPosition, bubbleParentX, bubbleParentY); int[] bubbleAgeIndices = new int[4] { firstPositionDesirability, secondPositionDesirability, thirdPositionDesirability, fourthPositionDesirability }; int oldestBubbleIndex = Mathf.Min(bubbleAgeIndices); DialogueBubbleController oldestBubble = oldestToYoungestBubbles[oldestBubbleIndex]; for (int y = 0; y < dialogueBubbleMatrixWidth; y++) { for (int x = 0; x < dialogueBubbleMatrixWidth; x++) { if (dialogueBubbleMatrix[x, y] == oldestBubble) { newBubbleXCoordinate = x; newBubbleYCoordinate = y; break; } } } }
public void RegisterTermClick(DialogueBubbleController dialogueBubble, string clickedTerm) { if (IsTermSpecial(clickedTerm)) { DeferToSpecialCase(clickedTerm); return; } int bubbleXCoordinate = -1, bubbleYCoordinate = -1; int newBubbleXCoordinate = -1, newBubbleYCoordinate = -1; BubbleExpandDirection bubbleExpandDirection; string bubbleName = dialogueBubble.name; int bubbleParentX = dialogueBubble.bubbleParentX; int bubbleParentY = dialogueBubble.bubbleParentY; ParseBubbleID(bubbleName, out bubbleXCoordinate, out bubbleYCoordinate); GetNewBubblePosition(bubbleXCoordinate, bubbleYCoordinate, out newBubbleXCoordinate, out newBubbleYCoordinate, out bubbleExpandDirection, bubbleParentX, bubbleParentY); if (newBubbleXCoordinate == -1 || newBubbleYCoordinate == -1) { Debug.LogError("Error finding a space for new dialogue bubble."); } DialogueBubbleController activatingBubble = dialogueBubbleMatrix[newBubbleXCoordinate, newBubbleYCoordinate]; activatingBubble.gameObject.SetActive(true); string textContents = currentDialogueObject[clickedTerm][TEXT_NAME].str; JSONObject clickableTermsObject = currentDialogueObject[clickedTerm][CLICKABLE_TERMS_NAME]; List <string> clickableTerms = new List <string>(); foreach (JSONObject j in clickableTermsObject.list) { clickableTerms.Add(j.str); } activatingBubble.ActivateBubble(textContents, clickableTerms, bubbleExpandDirection, bubbleXCoordinate, bubbleYCoordinate); if (oldestToYoungestBubbles.IndexOf(activatingBubble) > -1) { oldestToYoungestBubbles.Remove(activatingBubble); } oldestToYoungestBubbles.Add(activatingBubble); }
private void OnEnable() { oldestToYoungestBubbles = new List <DialogueBubbleController>(); // Turn first bubble on and all others off. for (int y = 0; y < dialogueBubbleMatrixWidth; y++) { for (int x = 0; x < dialogueBubbleMatrixWidth; x++) { if (x == 0 && y == 0) { DialogueBubbleController dialogueBubble = dialogueBubbleMatrix[x, y]; dialogueBubble.gameObject.SetActive(true); oldestToYoungestBubbles.Add(dialogueBubble); } else { dialogueBubbleMatrix[x, y].gameObject.SetActive(false); } } } }