private void ClearActionButtons() { SpritedStringUI buttonText = null; ButtonAnimator buttonAnimator = null; GameObject buttonObject = null; if (actionTexts != null) { for (int i = 0; i < actionTexts.Length; i++) { buttonText = actionTexts[i]; if (buttonText != null) { buttonText.Clear(); actionTexts[i] = null; } } actionTexts = null; } if (actionTextObjects != null) { for (int i = 0; i < actionTextObjects.Length; i++) { buttonObject = actionTextObjects[i]; if (buttonObject != null) { Destroy(buttonObject); actionTextObjects[i] = null; } } actionTextObjects = null; } if (actionButtons != null) { for (int i = 0; i < actionButtons.Length; i++) { buttonAnimator = actionButtons[i]; if (buttonAnimator != null) { buttonAnimator.Clear(); actionButtons[i] = null; } } actionButtons = null; } actionButtonTransforms = null; if (actionButtonObjects != null) { for (int i = 0; i < actionButtonObjects.Length; i++) { buttonObject = actionButtonObjects[i]; if (buttonObject != null) { Destroy(buttonObject); actionButtonObjects[i] = null; } } actionButtonObjects = null; } }
private void ClearHypotheticalStatsDisplay() { SpritedStringUI hypotheticText = null; if (hypotheticTexts != null) { for (int i = 0; i < hypotheticTexts.Length; i++) { hypotheticText = hypotheticTexts[i]; if (hypotheticText != null) { hypotheticText.Clear(); hypotheticTexts[i] = null; } } } GameObject hypotheticObject = null; if (hypotheticObjects != null) { for (int i = 0; i < hypotheticObjects.Length; i++) { hypotheticObject = hypotheticObjects[i]; if (hypotheticObject != null) { Destroy(hypotheticObject); hypotheticObjects[i] = null; } } } }
protected void CreateButtonText(RectTransform buttonTransform, string textContent, ref GameObject textObject, ref RectTransform textTransform, ref SpritedStringUI textComponent, bool replicateScale) { RectTransform areaParentTrans = null; if ((buttonTransform != null) && (textContent != null)) { areaParentTrans = (RectTransform)buttonTransform.parent; if (areaParentTrans != null) { textObject = new GameObject("ButtonText", typeof(RectTransform)); textTransform = textObject.GetComponent <RectTransform>(); textTransform.SetParent(areaParentTrans, false); textComponent = textObject.AddComponent <SpritedStringUI>(); textComponent.SetSymbolSource(font); textComponent.SetValue(textContent); textComponent.ToggleRaycastTargeting(false); textTransform.anchoredPosition = buttonTransform.anchoredPosition; if (replicateScale) { textTransform.localScale = buttonTransform.localScale; } } } }
private void CreateHypotheticalStatsDisplay() { if ((validItems != null) && statsDisplayValid && (player != null)) { if ((checkingItemIndex > -1) && (checkingItemIndex < validItems.Count)) { PlayerAgent.EquipAttribute[] attributes = statsDisplay.attributes; if (attributes != null) { int totalAttributes = attributes.Length; float[] attributeValues = new float[totalAttributes]; player.GetHypotheticalEquipResults(validItems[checkingItemIndex], attributes, ref attributeValues); hypotheticObjects = new GameObject[totalAttributes]; hypotheticTexts = new SpritedStringUI[totalAttributes]; TextAlignment textAnchor = statsDisplay.attributeAnchorAlignment; Vector2 textScale = statsDisplay.attributeScales; int textPercentage = 0; int textPercentageLimited = 0; Vector2[] allPositionRates = statsDisplay.attributeEquipPosRates; Vector2 textPositionRates = Vector2.zero; GameObject newTextObject = null; RectTransform newTextTransform = null; SpritedStringUI newText = null; int[] oneAttributeValues = null; for (int i = 0; i < totalAttributes; i++) { textPercentage = UsefulFunctions.GetPercentage(attributeValues[i]); textPercentageLimited = (textPercentage > percentageLimit) ? percentageLimit : textPercentage; textPositionRates = allPositionRates[i] + hypotheticTextOffset; CreateTextDisplayObject("HypotheticStat", textPercentageLimited.ToString(), textScale, textPositionRates, textAnchor, ref newTextObject, ref newTextTransform, ref newText); hypotheticObjects[i] = newTextObject; hypotheticTexts[i] = newText; if ((statValues != null) && (aspects != null) && (newText != null)) { oneAttributeValues = statValues[i]; for (int j = 0; j < aspects.Length; j++) { if (aspects[j] == AttributeAspect.Equip) { if (textPercentage > oneAttributeValues[j]) { newText.SetColor(hypotheticColorIncrease, Vector4.zero); } else if (textPercentage < oneAttributeValues[j]) { newText.SetColor(hypotheticColorDecrease, Vector4.zero); } break; } } } } attributes = null; attributeValues = null; } } } }
protected override void Awake() { base.Awake(); itemDatabase = null; currencyImageObject = null; currencyImageTrans = null; currencyImage = null; currencyTextObject = null; currencyTextTrans = null; currencyText = null; }
protected void UpdateTextDisplayObject(string objectContent, Vector2 scaleChange, Vector2 positionRates, TextAlignment anchorAlign, RectTransform readyTransform, SpritedStringUI readyText) { Vector2 originalUIDimensions = Vector2.zero; if (readyText != null) { readyText.SetValue(objectContent); originalUIDimensions = readyText.GetUIDimensions(); PlaceTransformProperly(readyTransform, originalUIDimensions, scaleChange, positionRates, anchorAlign); } }
private void ChangeButtonState(bool pressedState, ButtonAnimator buttonAnimator, SpritedStringUI buttonName, SpritedStringUI buttonAmount) { if (buttonAnimator != null) { buttonAnimator.SetPressed(pressedState); } Color textColor = pressedState ? equippedTextColor : Color.white; if (buttonName != null) { buttonName.SetColor(textColor, Vector4.zero); } if (buttonAmount != null) { buttonAmount.SetColor(textColor, Vector4.zero); } }
private void AdvancePage() { if (pictureObject != null) { if (textLines != null) { pictureImage = null; pictureTrans = null; Destroy(pictureObject); pictureObject = null; PlacePageLines(); written = false; } else { open = false; closing = true; } } else if (textLines != null) { RemovePageLines(); pageFirstLineIndex = pageLastLineIndex + 1; if (pageFirstLineIndex < textLines.Length) { pageLastLineIndex = pageFirstLineIndex + maxLinesPerPage - 1; if (pageLastLineIndex >= textLines.Length) { pageLastLineIndex = textLines.Length - 1; } PlacePageLines(); written = false; currentLineIndex = -1; currentLine = null; currentSymbolIndex = -1; } else { open = false; closing = true; } } }
private void RemovePageLines() { RectTransform textLineTrans = null; SpritedStringUI textLineComponent = null; if ((pageFirstLineIndex > -1) && (pageLastLineIndex > -1) && (textLineTransforms != null) && (textLineComponents != null)) { for (int i = pageFirstLineIndex; i < pageLastLineIndex + 1; i++) { /*halmeida - relying on the coherence of all the "textLine" arrays.*/ textLineTrans = textLineTransforms[i]; textLineComponent = textLineComponents[i]; if ((textLineTrans != null) && (textLineComponent != null)) { textLineTrans.SetParent(null); textLineComponent.ToggleAllSymbolVisuals(false); } } } }
protected override void ClearStatsDisplay() { if (currencyText != null) { currencyText.Clear(); currencyText = null; } currencyTextTrans = null; if (currencyTextObject != null) { Destroy(currencyTextObject); currencyTextObject = null; } currencyImage = null; currencyImageTrans = null; if (currencyImageObject != null) { Destroy(currencyImageObject); currencyImageObject = null; } base.ClearStatsDisplay(); }
protected override void Awake() { base.Awake(); player = null; levelObject = null; levelTransform = null; levelText = null; statsDisplayValid = false; stats = null; statObjects = null; statTransforms = null; statTexts = null; statValues = null; percentageLimit = 1; aspects = null; if (statsDisplay != null) { for (int i = statsDisplay.attributeMaxDigits; i > 0; i--) { percentageLimit *= 10; } percentageLimit--; statsDisplayValid = EvaluateDisplaySchemeCompatibility(); if (statsDisplayValid) { if (displayAllAspects) { aspects = (AttributeAspect[])Enum.GetValues(typeof(AttributeAspect)); } else { aspects = displayAspects; } } } }
protected void CreateTextDisplayObject(string objectName, string objectContent, Vector2 scaleChange, Vector2 positionRates, TextAlignment anchorAlign, ref GameObject newObject, ref RectTransform newTransform, ref SpritedStringUI newText) { Vector2 originalUIDimensions = Vector2.zero; if (font != null) { newObject = new GameObject(objectName, typeof(RectTransform)); newTransform = newObject.GetComponent <RectTransform>(); newText = newObject.AddComponent <SpritedStringUI>(); newText.SetSymbolSource(font); newText.SetValue(objectContent); newText.ToggleRaycastTargeting(false); originalUIDimensions = newText.GetUIDimensions(); PlaceTransformProperly(newTransform, originalUIDimensions, scaleChange, positionRates, anchorAlign); } }
private void CreateItemButtons() { chosenItemIndex = -1; checkingItemIndex = -1; if ((validItems != null) && (itemButtonModel != null) && (itemButtons == null)) { if (validItems.Count > 0) { itemButtonObjects = new GameObject[validItems.Count]; itemButtonTransforms = new RectTransform[validItems.Count]; itemButtons = new ButtonAnimator[validItems.Count]; itemTextObjects = new GameObject[validItems.Count]; itemTextTransforms = new RectTransform[validItems.Count]; itemTexts = new SpritedStringUI[validItems.Count]; itemAmountObjects = new GameObject[validItems.Count]; itemAmountTransforms = new RectTransform[validItems.Count]; itemAmountComponents = new SpritedStringUI[validItems.Count]; Vector2 buttonScale = itemDisplayScheme.buttonElementScale; Vector2[] allPositionRates = itemDisplayScheme.elementPositionRates; Vector2 buttonPositionRates = Vector2.zero; Vector2 textPositionRates = Vector2.zero; GameTextDatabase gameTextDatabase = GameTextDatabase.Instance; ItemData itemData = null; string itemName = null; bool itemHidden = false; GameObject itemButtonObject = null; RectTransform itemButtonTrans = null; ButtonAnimator itemButton = null; GameObject itemTextObject = null; RectTransform itemTextTrans = null; SpritedStringUI itemText = null; GameObject itemAmountObject = null; RectTransform itemAmountTransform = null; SpritedStringUI itemAmountComponent = null; bool needsScroll = false; for (int i = 0; i < validItems.Count; i++) { itemData = validItems[i]; itemHidden = true; buttonPositionRates = new Vector2(0.5f, 0.5f); gameTextDatabase.GetItemDescription(itemData.itemID, ref itemName); if (allPositionRates != null) { if (i < allPositionRates.Length) { itemHidden = false; buttonPositionRates = allPositionRates[i]; } else { needsScroll = true; } } CreateButtonObject(itemButtonModel, buttonScale, buttonPositionRates, TextAlignment.Center, ref itemButtonObject, ref itemButtonTrans, ref itemButton); textPositionRates = buttonPositionRates + itemTextOffsetRates; CreateTextDisplayObject("ItemName", itemName, Vector2.one, textPositionRates, TextAlignment.Left, ref itemTextObject, ref itemTextTrans, ref itemText); textPositionRates = buttonPositionRates + itemAmountOffsetRates; CreateTextDisplayObject("ItemUnits", validItemUnits[i].ToString(), Vector2.one, textPositionRates, TextAlignment.Right, ref itemAmountObject, ref itemAmountTransform, ref itemAmountComponent); if (itemHidden) { lastItemIndex = i - 1; itemButtonObject.SetActive(false); itemTextObject.SetActive(false); itemAmountObject.SetActive(false); } else { if (firstItemIndex == -1) { firstItemIndex = i; lastItemIndex = i; } } itemButtonObjects[i] = itemButtonObject; itemButtonTransforms[i] = itemButtonTrans; itemButtons[i] = itemButton; itemTextObjects[i] = itemTextObject; itemTextTransforms[i] = itemTextTrans; itemTexts[i] = itemText; itemAmountObjects[i] = itemAmountObject; itemAmountTransforms[i] = itemAmountTransform; itemAmountComponents[i] = itemAmountComponent; if ((chosenItemIndex == -1) && (itemButton != null)) { if (player.IsEquippedWith(itemData.itemID)) { chosenItemIndex = i; ChangeButtonState(true, itemButton, itemText, itemAmountComponent); } } } if (needsScroll) { buttonScale = itemDisplayScheme.buttonReturnScale; buttonPositionRates = itemDisplayScheme.returnPositionRates; CreateButtonObject(itemReturnButtonModel, buttonScale, buttonPositionRates, TextAlignment.Center, ref itemReturnButtonObject, ref itemReturnButtonTransform, ref itemReturnButton); buttonScale = itemDisplayScheme.buttonAdvanceScale; buttonPositionRates = itemDisplayScheme.advancePositionRates; CreateButtonObject(itemAdvanceButtonModel, buttonScale, buttonPositionRates, TextAlignment.Center, ref itemAdvanceButtonObject, ref itemAdvanceButtonTransform, ref itemAdvanceButton); if (itemReturnButton != null) { itemReturnButton.SetPressed(true); } } } else { Debug.Log("Debug : MenuInventory : no items to show in section " + chosenSectionIndex + "."); } } }
private void CreateActionButtons() { if ((validItems != null) && (actionButtonModel != null) && (interfaceCanvasTrans != null) && (actionButtons == null)) { GameTextDatabase gameTextDatabase = GameTextDatabase.Instance; int totalActions = 0; if (itemActions != null) { totalActions = itemActions.Length; } if ((totalActions > 0) && (checkingItemIndex > -1) && (checkingItemIndex < validItems.Count)) { ItemData itemData = validItems[checkingItemIndex]; bool isEquippable = (itemData.equipment != null); bool isEquipped = player.IsEquippedWith(itemData.itemID); bool isExpendable = itemData.expendable; actionButtonObjects = new GameObject[totalActions]; actionButtonTransforms = new RectTransform[totalActions]; actionButtons = new ButtonAnimator[totalActions]; /*halmeida - the button objects and the text objects have to be separate objects so that they * can have different scaling.*/ actionTextObjects = new GameObject[totalActions]; actionTexts = new SpritedStringUI[totalActions]; Vector2 buttonScale = actionDisplayScheme.buttonElementScale; Vector2 buttonPositionRates = Vector2.zero; string actionName = null; Vector2[] allPositionRates = actionDisplayScheme.elementPositionRates; GameObject buttonObject = null; RectTransform buttonTransform = null; ButtonAnimator buttonAnimator = null; GameObject buttonTextObject = null; RectTransform buttonTextTrans = null; SpritedStringUI buttonText = null; for (int i = 0; i < totalActions; i++) { if (gameTextDatabase != null) { actionName = gameTextDatabase.GetMenuOptionText(itemActions[i]); } if (allPositionRates != null) { buttonPositionRates = (allPositionRates.Length > i) ? allPositionRates[i] : new Vector2(0.5f, 0.5f); } CreateButtonObject(actionButtonModel, buttonScale, buttonPositionRates, TextAlignment.Center, ref buttonObject, ref buttonTransform, ref buttonAnimator); actionButtonObjects[i] = buttonObject; actionButtonTransforms[i] = buttonTransform; actionButtons[i] = buttonAnimator; CreateTextDisplayObject("ActionName", actionName, Vector2.one, buttonPositionRates, TextAlignment.Center, ref buttonTextObject, ref buttonTextTrans, ref buttonText); actionTextObjects[i] = buttonTextObject; actionTexts[i] = buttonText; switch (itemActions[i]) { case ChoiceEffect.Equip: if (!isEquippable || isEquipped) { ChangeButtonState(true, buttonAnimator, buttonText, null); } break; case ChoiceEffect.Unequip: if (!isEquipped) { ChangeButtonState(true, buttonAnimator, buttonText, null); } break; case ChoiceEffect.Use: if (!isExpendable) { ChangeButtonState(true, buttonAnimator, buttonText, null); } break; } } } } }
protected virtual bool CreateStatsDisplay() { GameTextDatabase textDatabase = null; int totalStats = 0; string statName = null; string textName = null; string textValue = null; float statValueOriginal = 0f; float statValueBase = 0f; float statEquippedSum = 0f; bool toDiscard = false; GameObject textObject = null; RectTransform textTransform = null; SpritedStringUI textComponent = null; Vector2 textDimensions = Vector2.zero; Vector2 textScales = Vector2.zero; Vector2 textPositionRates = Vector2.zero; TextAlignment textAnchor = TextAlignment.Center; textDatabase = GameTextDatabase.Instance; if (statsDisplayValid && (interfaceCanvasTrans != null) && (player != null) && (textDatabase != null)) { if (statsDisplay.displayLevel && (levelObject == null)) { statName = textDatabase.GetSystemText(GameTextDatabase.TEXT_ID_PLAYER_LEVEL, ref toDiscard); statName += " " + player.GetCurrentLevel(); textScales = statsDisplay.levelScales; textPositionRates = statsDisplay.levelPositionRates; textAnchor = statsDisplay.levelAnchorAlignment; CreateTextDisplayObject("LevelDisplay", statName, textScales, textPositionRates, textAnchor, ref levelObject, ref levelTransform, ref levelText); } if (statObjects == null) { stats = statsDisplay.attributes; if (stats != null) { totalStats = stats.Length; if (totalStats > 0) { statObjects = new GameObject[totalStats][]; statTransforms = new RectTransform[totalStats][]; statTexts = new SpritedStringUI[totalStats][]; statValues = new int[totalStats][]; GameObject[] newStatObjects = null; RectTransform[] newStatTransforms = null; SpritedStringUI[] newStatTexts = null; int[] newStatValues = null; int statValue = -1; int percentageBase = 0; int percentageBaseLimited = 0; int percentageEquip = 0; int percentageEquipLimited = 0; int percentageTotal = 0; int percentageTotalLimited = 0; bool percentageBaseReady = false; bool percentageEquipReady = false; textAnchor = statsDisplay.attributeAnchorAlignment; textScales = statsDisplay.attributeScales; for (int i = 0; i < stats.Length; i++) { newStatObjects = new GameObject[aspects.Length]; newStatTransforms = new RectTransform[aspects.Length]; newStatTexts = new SpritedStringUI[aspects.Length]; newStatValues = new int[aspects.Length]; statName = textDatabase.GetEquipAttributeName(stats[i]); player.GetStatValueSegments(stats[i], ref statValueOriginal, ref statValueBase, ref statEquippedSum); percentageBaseReady = false; percentageEquipReady = false; for (int j = 0; j < aspects.Length; j++) { switch (aspects[j]) { case AttributeAspect.Name: textName = "StatName" + statName; textValue = statName; textPositionRates = statsDisplay.attributeNamePosRates[i]; statValue = -1; break; case AttributeAspect.Base: textName = "StatBase" + statName; if (!percentageBaseReady) { percentageBase = UsefulFunctions.GetPercentage(statValueBase, statValueOriginal); statValue = percentageBase; percentageBaseLimited = (percentageBase > percentageLimit) ? percentageLimit : percentageBase; percentageBaseReady = true; } textValue = percentageBaseLimited.ToString(); textPositionRates = statsDisplay.attributeBasePosRates[i]; break; case AttributeAspect.Equip: textName = "StatEquip" + statName; if (!percentageEquipReady) { percentageEquip = UsefulFunctions.GetPercentage(statEquippedSum); statValue = percentageEquip; percentageEquipLimited = (percentageEquip > percentageLimit) ? percentageLimit : percentageEquip; percentageEquipReady = true; } textValue = percentageEquipLimited.ToString(); textPositionRates = statsDisplay.attributeEquipPosRates[i]; break; case AttributeAspect.Total: textName = "StatTotal" + statName; if (!percentageBaseReady) { percentageBase = UsefulFunctions.GetPercentage(statValueBase, statValueOriginal); percentageBaseLimited = (percentageBase > percentageLimit) ? percentageLimit : percentageBase; percentageBaseReady = true; } if (!percentageEquipReady) { percentageEquip = UsefulFunctions.GetPercentage(statEquippedSum); percentageEquipLimited = (percentageEquip > percentageLimit) ? percentageLimit : percentageEquip; percentageEquipReady = true; } percentageTotal = percentageBase + percentageEquip; statValue = percentageTotal; percentageTotalLimited = (percentageTotal > percentageLimit) ? percentageLimit : percentageTotal; textValue = percentageTotalLimited.ToString(); textPositionRates = statsDisplay.attributeTotalPosRates[i]; break; } CreateTextDisplayObject(textName, textValue, textScales, textPositionRates, textAnchor, ref textObject, ref textTransform, ref textComponent); newStatObjects[j] = textObject; newStatTransforms[j] = textTransform; newStatTexts[j] = textComponent; newStatValues[j] = statValue; } statObjects[i] = newStatObjects; statTransforms[i] = newStatTransforms; statTexts[i] = newStatTexts; statValues[i] = newStatValues; } } } } return(true); } return(false); }
protected virtual void ClearOptions() { ButtonAnimator optionComponent = null; GameObject optionObject = null; SpritedStringUI optionText = null; selectedOptionComponent = null; optionEffects = null; if (optionComponents != null) { for (int i = 0; i < optionComponents.Length; i++) { optionComponent = optionComponents[i]; if (optionComponent != null) { optionComponent.Clear(); optionComponents[i] = null; } } optionComponents = null; } if (optionTransforms != null) { for (int i = 0; i < optionTransforms.Length; i++) { optionTransforms[i] = null; } optionTransforms = null; } if (optionObjects != null) { for (int i = 0; i < optionObjects.Length; i++) { optionObject = optionObjects[i]; if (optionObject != null) { Destroy(optionObject); optionObjects[i] = null; } } optionObjects = null; } if (optionTexts != null) { for (int i = 0; i < optionTexts.Length; i++) { optionText = optionTexts[i]; if (optionText != null) { optionText.Clear(); optionTexts[i] = null; } } optionTexts = null; } if (optionTextObjects != null) { for (int i = 0; i < optionTextObjects.Length; i++) { optionObject = optionTextObjects[i]; if (optionObject != null) { Destroy(optionObject); optionTextObjects[i] = null; } } optionTextObjects = null; } currentValidModels = 0; currentValidOptionModels = null; currentValidOptionScales = null; currentValidOptionChoiceEffects = null; currentValidOptionEventIDs = null; }
public void ClearVisualRepresentation(bool immediately) { if (!graphicsCleared) { if (overlayDark || immediately) { if (titleText != null) { titleText.Clear(); titleText = null; } if (titleTextObject != null) { Destroy(titleTextObject); titleTextObject = null; } if (titleComponent != null) { titleComponent.Clear(); titleComponent = null; } titleTransform = null; if (titleObject != null) { Destroy(titleObject); titleObject = null; } selectedQuitComponent = null; if (quitText != null) { quitText.Clear(); quitText = null; } if (quitTextObject != null) { Destroy(quitTextObject); quitTextObject = null; } if (quitComponent != null) { quitComponent.Clear(); quitComponent = null; } quitTransform = null; if (quitObject != null) { Destroy(quitObject); quitObject = null; } ClearOptions(); if (optionsParent != null) { optionsParentTransform = null; Destroy(optionsParent); optionsParent = null; } if (!immediately && (imageOverlayComponent != null)) { overlayFadeSpeed = -overlayFadeSpeedRef; } else { overlayDark = false; overlayClear = true; } } if (overlayClear) { if (imageOverlayObject != null) { imageOverlayComponent = null; Destroy(imageOverlayObject); imageOverlayObject = null; } graphicsCleared = true; if (immediately) { requiringProgress = false; selectedChoiceEffect = ChoiceEffect.None; } } } }
private void PlacePageLines() { Vector2 insertionPosition = Vector2.zero; Vector2 linePosition = Vector2.zero; GameObject textLineObject = null; RectTransform textLineTrans = null; SpritedStringUI textLineComponent = null; float textLineWidth = 0f; int linesOnPage = 0; float insertionX = 0f; if ((pageFirstLineIndex > -1) && (pageLastLineIndex > -1) && (textLineObjects != null) && (pictureObject == null)) { switch (textAlignment) { case TextAlignment.AlignLeft: insertionX = textArea.x; break; case TextAlignment.AlignMiddle: insertionX = textArea.x + textArea.width / 2f; break; case TextAlignment.AlignRight: insertionX = textArea.x + textArea.width; break; } insertionPosition = new Vector2(insertionX, textArea.y - lineHeight / 2f); for (int i = pageFirstLineIndex; i < pageLastLineIndex + 1; i++) { /*halmeida - relying on the coherence of all the "textLine" arrays.*/ textLineObject = textLineObjects[i]; textLineTrans = textLineTransforms[i]; textLineComponent = textLineComponents[i]; if ((textLineObject != null) && (textLineTrans != null) && (textLineComponent != null) && (ownTransform != null)) { textLineWidth = textLineComponent.GetUIDimensions().x; linePosition = insertionPosition; switch (textAlignment) { case TextAlignment.AlignLeft: linePosition.x += textLineWidth / 2f; break; case TextAlignment.AlignRight: linePosition.x -= textLineWidth / 2f; break; } textLineTrans.SetParent(ownTransform, false); textLineTrans.anchoredPosition = linePosition; insertionPosition.y -= (DISTANCE_BETWEEN_LINES_FACTOR + 1.0f) * lineHeight; } } if (autoClose) { linesOnPage = pageLastLineIndex - pageFirstLineIndex + 1; autoCloseDuration = linesOnPage * AUTO_CLOSE_LINE_TIME; autoCloseElapsed = 0f; } } }
protected virtual void ProgressWriting(bool immediately, float timeStep) { SpritedStringUI textLineComponent = null; int lineLength = 0; int totalToReveal = 0; if (pictureObject != null) { written = true; writeImmediately = false; if (autoCloseDuration > 0f) { autoCloseElapsed = 0f; } } else if (textLineComponents != null) { if (currentLineIndex < 0) { currentLineIndex = pageFirstLineIndex; } if (immediately) { writeImmediately = true; } if ((textSpeed == 0f) || writeImmediately) { if (currentLineIndex > -1) { for (int i = currentLineIndex; i < pageLastLineIndex + 1; i++) { if (textLineComponents.Length > i) { textLineComponent = textLineComponents[i]; if (textLineComponent != null) { textLineComponent.ToggleAllSymbolVisuals(true); } } } } written = true; writeImmediately = false; } else { if (currentLine == null) { if ((currentLineIndex > -1) && (currentLineIndex <= pageLastLineIndex) && (textLineComponents.Length > currentLineIndex)) { textLineComponent = textLineComponents[currentLineIndex]; if (textLineComponent != null) { lineLength = textLineComponent.GetTotalSymbols(); if (lineLength > 0) { currentLine = textLineComponent; currentSymbolIndex = 0; currentLineLength = lineLength; textLineComponent.ToggleSymbolVisual(currentSymbolIndex, true); symbolElapsed = 0f; } } } if (currentLine == null) { written = true; } } else { if (ShouldShowImmediately(currentLineIndex)) { totalToReveal = currentLineLength; } else { symbolElapsed += textSpeed * timeStep; totalToReveal = (int)(symbolElapsed / symbolDuration); } if (totalToReveal > 0) { for (int i = totalToReveal; i > 0; i--) { currentSymbolIndex++; if (currentSymbolIndex < currentLineLength) { currentLine.ToggleSymbolVisual(currentSymbolIndex, true); } else { currentLineIndex++; currentLine = null; break; } } symbolElapsed = 0f; } } } if (written) { if (autoCloseDuration > 0f) { autoCloseElapsed = 0f; } } } }
private bool AddCanvasText(string textString, SymbolDatabase textFont, Color textColor, Vector4 textColorGradient, int textEvolution, Transform originTransform, Vector2 originWorldPosition, bool workDuringPause) { GameObject textObject = null; RectTransform textTrans = null; SpritedStringUI text = null; int textIndex = -1; Vector3 completeWorldPos = Vector3.zero; Vector2 currentWorldPos = Vector2.zero; Vector2 canvasPosition = Vector2.zero; Vector2 textSpeed = Vector2.zero; Vector2 textIncreasedScale = Vector2.zero; Color textGeneralColor = Color.white; float textDurationShow = 0f; float textDurationPlain = 0f; float textDurationHide = 0f; int textStage = INVALID_TEXT_STAGE; if (originTransform != null) { completeWorldPos = originTransform.position; currentWorldPos = new Vector2(completeWorldPos.x, completeWorldPos.y); /*halmeida - in case there is an origin transform, the originWorldPosition vector is interpreted as an offset * from the transform's position.*/ currentWorldPos += originWorldPosition; } else { currentWorldPos = originWorldPosition; } if (TransformWorldToCanvasPosition(currentWorldPos, ref canvasPosition)) { textIndex = (textObjects == null) ? 0 : textObjects.Length; textObject = new GameObject("UIText" + textIndex, typeof(RectTransform)); if (textObject != null) { textTrans = textObject.GetComponent <RectTransform>(); text = textObject.AddComponent <SpritedStringUI>(); if (text != null) { text.SetSymbolSource(textFont); text.ToggleRaycastTargeting(false); text.SetValue(textString); textTrans.SetParent(interfaceCanvasTrans, false); textTrans.anchoredPosition = canvasPosition; switch (textEvolution) { case TEXT_EVOLUTION_ASCENT: textSpeed.y = TEXT_ASCENT_SPEED; textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_ASCENT_START_SCALE_X, TEXT_ASCENT_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_ASCENT_DURATION_SHOW; textDurationPlain = TEXT_ASCENT_DURATION_PLAIN; textDurationHide = TEXT_ASCENT_DURATION_HIDE; break; case TEXT_EVOLUTION_STAY: textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_STAY_START_SCALE_X, TEXT_STAY_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_STAY_DURATION_SHOW; textDurationPlain = TEXT_STAY_DURATION_PLAIN; textDurationHide = TEXT_STAY_DURATION_HIDE; break; case TEXT_EVOLUTION_NONE_WAIT: case TEXT_EVOLUTION_NONE_GO: textGeneralColor = text.GetGeneralColor(); textGeneralColor.a = 0f; text.SetGeneralColor(textGeneralColor); textStage = TEXT_STAGE_SHOW; textIncreasedScale = new Vector2(TEXT_NONE_START_SCALE_X, TEXT_NONE_START_SCALE_Y); textTrans.localScale = new Vector3(textIncreasedScale.x, textIncreasedScale.y, 1f); textDurationShow = TEXT_NONE_DURATION_SHOW; textDurationPlain = TEXT_NONE_DURATION_PLAIN; textDurationHide = TEXT_NONE_DURATION_HIDE; break; } text.SetColor(textColor, textColorGradient); UsefulFunctions.IncreaseArray <GameObject>(ref textObjects, textObject); UsefulFunctions.IncreaseArray <RectTransform>(ref textTransforms, textTrans); UsefulFunctions.IncreaseArray <SpritedStringUI>(ref texts, text); UsefulFunctions.IncreaseArray <int>(ref textEvolutions, textEvolution); UsefulFunctions.IncreaseArray <Transform>(ref textOriginTransforms, originTransform); UsefulFunctions.IncreaseArray <Vector2>(ref textOriginPositions, originWorldPosition); UsefulFunctions.IncreaseArray <Vector2>(ref textSpeeds, textSpeed); UsefulFunctions.IncreaseArray <Vector2>(ref textIncreasedScales, textIncreasedScale); UsefulFunctions.IncreaseArray <float>(ref textDurationsShow, textDurationShow); UsefulFunctions.IncreaseArray <float>(ref textDurationsPlain, textDurationPlain); UsefulFunctions.IncreaseArray <float>(ref textDurationsHide, textDurationHide); UsefulFunctions.IncreaseArray <int>(ref textStages, textStage); UsefulFunctions.IncreaseArray <float>(ref textStageElapseds, 0f); UsefulFunctions.IncreaseArray <float>(ref textElapseds, 0f); UsefulFunctions.IncreaseArray <bool>(ref textPauseds, workDuringPause); return(true); } } textTrans = null; if (textObject != null) { Destroy(textObject); } } return(false); }
/*halmeida - carefull when using this method. If any memory is currently allocated, it will not be freed.*/ protected virtual void ResetAllClassFields() { if (cleared) { canvasTransform = null; symbolDatabase = null; maxBoxWidth = 0f; maxBoxHeight = 0f; boxSizeLimitsSet = false; maxTextWidth = 0f; maxTextHeight = 0f; boxSprite = null; boxObject = null; boxTransform = null; boxImage = null; boxArea = new Rect(0f, 0f, 0f, 0f); textArea = new Rect(0f, 0f, 0f, 0f); margin = 0f; marginDouble = 0f; lineHeight = 0f; maxLineWidth = 0f; maxLinesPerPage = 0; pageFirstLineIndex = -1; pageLastLineIndex = -1; built = false; open = false; openAlpha = 1f; openScale = Vector2.one; opening = false; written = false; closing = false; closed = false; closedAlpha = 0f; closedScale = new Vector2(0.1f, 0.1f); cleared = false; instantCreation = false; reactionType = ReactionType.ReactAnywhere; textAlignment = TextAlignment.AlignLeft; text = null; textLines = null; textLineObjects = null; textLineTransforms = null; textLineComponents = null; textSpeed = 0f; currentLine = null; currentLineIndex = -1; currentSymbolIndex = -1; currentLineLength = 0; symbolDuration = 0f; symbolElapsed = 0f; writeImmediately = false; autoClose = false; autoCloseDuration = 0f; autoCloseElapsed = 0f; openingSpeed = 1f; picture = null; pictureObject = null; pictureTrans = null; pictureImage = null; } }
private void CreateSectionButtons() { bool toDiscard = false; GameObject buttonObject = null; RectTransform buttonTransform = null; ButtonAnimator buttonAnimator = null; GameObject buttonTextObject = null; RectTransform buttonTextTrans = null; SpritedStringUI buttonText = null; Vector2 buttonScale = Vector2.one; Vector2 buttonPositionRates = Vector2.zero; if ((sectionButtonModel != null) && (interfaceCanvasTrans != null) && (sectionButtons == null)) { GameTextDatabase gameTextDatabase = GameTextDatabase.Instance; int totalSections = 1; if (firstSections != null) { if (firstSections.Length > 0) { totalSections += firstSections.Length; } } sectionButtonObjects = new GameObject[totalSections]; sectionButtonTransforms = new RectTransform[totalSections]; sectionButtons = new ButtonAnimator[totalSections]; /*halmeida - the button objects and the text objects have to be separate objects so that they * can have different scaling.*/ sectionTextObjects = new GameObject[totalSections]; sectionTexts = new SpritedStringUI[totalSections]; buttonScale = sectionDisplayScheme.buttonElementScale; string sectionTitle = null; Vector2[] allPositionRates = sectionDisplayScheme.elementPositionRates; for (int i = 0; i < totalSections; i++) { if (gameTextDatabase != null) { if (i == (totalSections - 1)) { sectionTitle = gameTextDatabase.GetSystemText(GameTextDatabase.TEXT_ID_NON_EQUIPPABLE_ITEMS, ref toDiscard); } else { sectionTitle = gameTextDatabase.GetEquipBodyPartName(firstSections[i]); } } if (allPositionRates != null) { buttonPositionRates = (allPositionRates.Length > i) ? allPositionRates[i] : new Vector2(0.5f, 0.5f); } CreateButtonObject(sectionButtonModel, buttonScale, buttonPositionRates, TextAlignment.Center, ref buttonObject, ref buttonTransform, ref buttonAnimator); sectionButtonObjects[i] = buttonObject; sectionButtonTransforms[i] = buttonTransform; sectionButtons[i] = buttonAnimator; CreateTextDisplayObject("SectionName", sectionTitle, Vector2.one, buttonPositionRates, TextAlignment.Center, ref buttonTextObject, ref buttonTextTrans, ref buttonText); sectionTextObjects[i] = buttonTextObject; sectionTexts[i] = buttonText; } } }
protected virtual void Awake() { GameObject optionModel = null; RectTransform optionTrans = null; ButtonAnimator optionComponent = null; ChoiceEffect optionChoiceEffect = ChoiceEffect.None; GameObject optionEventObject = null; EventBase optionEventComponent = null; int optionEventID = EventBase.INVALID_EVENT_ID; Vector2 optionScale = Vector2.one; gameController = null; font = null; interfaceCanvasObject = null; interfaceCanvasTrans = null; interfaceCanvasComponent = null; interfaceCanvasRect = new Rect(0f, 0f, 0f, 0f); interfaceCanvasScreenRect = new Rect(0f, 0f, 0f, 0f); imageOverlayModel = null; imageOverlayObject = null; imageOverlayComponent = null; titleObject = null; titleTransform = null; titleComponent = null; titleTextObject = null; titleText = null; quitObject = null; quitTransform = null; quitComponent = null; quitTextObject = null; quitText = null; allowQuitOption = true; optionsParent = null; optionsParentTransform = null; totalValidModels = 0; totalValidOptionModels = null; totalValidOptionScales = null; totalValidOptionChoiceEffects = null; totalValidOptionEventIDs = null; currentValidModels = 0; currentValidOptionModels = null; currentValidOptionScales = null; currentValidOptionChoiceEffects = null; currentValidOptionEventIDs = null; optionObjects = null; optionTransforms = null; optionComponents = null; optionEffects = null; optionTextObjects = null; optionTexts = null; selectedChoiceEffect = ChoiceEffect.None; selectedQuitComponent = null; selectedOptionComponent = null; overlayFadeSpeed = 0f; overlayFadeSpeedRef = (backgroundAlphaSpeed > 0f) ? backgroundAlphaSpeed : 1f; overlayMaxAlpha = backgroundMaxAlpha; overlayDark = false; overlayClear = false; graphicsReady = false; graphicsCleared = false; touchingOverlay = false; draggingMenu = false; lastDragCanvasX = 0f; lastDragCanvasY = 0f; highestOptionTopY = 0f; hiddenOptionHeight = 0f; maxScreenOffsetLeft = 0f; maxScreenOffsetRight = 0f; maxScreenOffsetUp = 0f; maxScreenOffsetDown = 0f; requiringProgress = false; clearBeforeEffect = true; eventManager = null; previousMenu = null; if (optionModels != null) { for (int i = 0; i < optionModels.Length; i++) { optionModel = optionModels[i]; if (optionModel != null) { optionTrans = optionModel.GetComponent <RectTransform>(); optionComponent = optionModel.GetComponent <ButtonAnimator>(); if ((optionTrans != null) && (optionComponent != null)) { optionScale = Vector2.one; optionChoiceEffect = ChoiceEffect.None; optionEventID = EventBase.INVALID_EVENT_ID; if (optionButtonScales != null) { if (optionButtonScales.Length > i) { optionScale = optionButtonScales[i]; } } if (optionChoiceEffects != null) { if (optionChoiceEffects.Length > i) { optionChoiceEffect = optionChoiceEffects[i]; } } if (optionEventRequirements != null) { if (optionEventRequirements.Length > i) { optionEventObject = optionEventRequirements[i]; if (optionEventObject != null) { optionEventComponent = optionEventObject.GetComponent <EventBase>(); if (optionEventComponent != null) { optionEventID = optionEventComponent.eventID; } } } } totalValidModels++; UsefulFunctions.IncreaseArray <GameObject>(ref totalValidOptionModels, optionModel); UsefulFunctions.IncreaseArray <Vector2>(ref totalValidOptionScales, optionScale); UsefulFunctions.IncreaseArray <ChoiceEffect>(ref totalValidOptionChoiceEffects, optionChoiceEffect); UsefulFunctions.IncreaseArray <int>(ref totalValidOptionEventIDs, optionEventID); } } } } }
public virtual void Clear() { SpritedStringUI textLineComponent = null; GameObject textLineObject = null; if (textLineComponents != null) { for (int i = 0; i < textLineComponents.Length; i++) { textLineComponent = textLineComponents[i]; if (textLineComponent != null) { textLineComponent.Clear(); textLineComponents[i] = null; } } textLineComponents = null; } if (textLineTransforms != null) { for (int i = 0; i < textLineTransforms.Length; i++) { textLineTransforms[i] = null; } textLineTransforms = null; } if (textLineObjects != null) { for (int i = 0; i < textLineObjects.Length; i++) { textLineObject = textLineObjects[i]; if (textLineObject != null) { Destroy(textLineObject); textLineObjects[i] = null; } } textLineObjects = null; } if (textLines != null) { for (int i = 0; i < textLines.Length; i++) { textLines[i] = null; } textLines = null; } text = null; if (pictureObject != null) { pictureImage = null; pictureTrans = null; Destroy(pictureObject); pictureObject = null; } picture = null; boxSprite = null; boxImage = null; boxTransform = null; if (boxObject != null) { Destroy(boxObject); boxObject = null; } symbolDatabase = null; built = false; cleared = true; }
protected virtual void ClearStatsDisplay() { SpritedStringUI textComponent = null; SpritedStringUI[] textComponents = null; RectTransform[] textTransforms = null; GameObject textObject = null; GameObject[] textObjects = null; if (levelObject != null) { levelText.Clear(); levelText = null; Destroy(levelObject); levelObject = null; } if (stats != null) { for (int i = 0; i < stats.Length; i++) { statValues[i] = null; textComponents = statTexts[i]; if (textComponents != null) { for (int j = 0; j < textComponents.Length; j++) { textComponent = textComponents[j]; if (textComponent != null) { textComponent.Clear(); textComponents[j] = null; } } statTexts[i] = null; } textTransforms = statTransforms[i]; if (textTransforms != null) { for (int j = 0; j < textTransforms.Length; j++) { textTransforms[j] = null; } statTransforms[i] = null; } textObjects = statObjects[i]; if (textObjects != null) { for (int j = 0; j < textObjects.Length; j++) { textObject = textObjects[j]; if (textObject != null) { Destroy(textObject); textObjects[j] = null; } } statObjects[i] = null; } } statValues = null; statTexts = null; statTransforms = null; statObjects = null; stats = null; } }
protected virtual void BuildOptions() { if ((interfaceCanvasComponent == null) || (optionsParentTransform == null)) { return; } SeparateCurrentlyValidOptions(); if ((currentValidOptionModels == null) || (currentValidOptionChoiceEffects == null)) { return; } optionObjects = new GameObject[currentValidModels]; optionTransforms = new RectTransform[currentValidModels]; optionComponents = new ButtonAnimator[currentValidModels]; optionEffects = new ChoiceEffect[currentValidModels]; optionTextObjects = new GameObject[currentValidModels]; optionTexts = new SpritedStringUI[currentValidModels]; GameObject optionModel = null; GameObject newOptionObject = null; RectTransform newOptionTrans = null; ButtonAnimator newOptionComponent = null; Vector2 newOptionScale = Vector2.one; ChoiceEffect newOptionEffect = ChoiceEffect.None; GameObject newOptionTextObject = null; RectTransform toDiscard = null; SpritedStringUI newOptionText = null; /*halmeida - discover the canvas X coordinate where all options should be placed.*/ float newAnchoredX = (optionCenterXRate - 0.5f) * interfaceCanvasRect.width; /*halmeida - discover the canvas Y coordinate where the top of the first option should be placed.*/ highestOptionTopY = (highestOptionTopRate - 0.5f) * interfaceCanvasRect.height; float newAnchoredY = highestOptionTopY; /*halmeida - discover the vertical distance from one option to the next.*/ float optionDistance = optionDistanceRate * interfaceCanvasRect.height; float halfOptionHeight = 0f; GameTextDatabase gameTextDatabase = GameTextDatabase.Instance; string buttonCaption = null; for (int i = 0; i < currentValidModels; i++) { optionModel = currentValidOptionModels[i]; newOptionObject = Instantiate(optionModel) as GameObject; newOptionTrans = newOptionObject.GetComponent <RectTransform>(); newOptionComponent = newOptionObject.GetComponent <ButtonAnimator>(); newOptionScale = currentValidOptionScales[i]; newOptionEffect = currentValidOptionChoiceEffects[i]; newOptionTrans.SetParent(optionsParentTransform, false); newOptionTrans.localScale = new Vector3(newOptionScale.x, newOptionScale.y, 1f); halfOptionHeight = (newOptionTrans.rect.height / 2f) * newOptionScale.y; newAnchoredY -= halfOptionHeight; newOptionTrans.anchoredPosition = new Vector2(newAnchoredX, newAnchoredY); newAnchoredY -= halfOptionHeight + optionDistance; newOptionTextObject = null; newOptionText = null; if (useOptionEffectAsText && (gameTextDatabase != null)) { buttonCaption = gameTextDatabase.GetMenuOptionText(newOptionEffect); CreateButtonText(newOptionTrans, buttonCaption, ref newOptionTextObject, ref toDiscard, ref newOptionText, false); } optionObjects[i] = newOptionObject; optionTransforms[i] = newOptionTrans; optionComponents[i] = newOptionComponent; optionEffects[i] = newOptionEffect; optionTextObjects[i] = newOptionTextObject; optionTexts[i] = newOptionText; } hiddenOptionHeight = 0f; if (newAnchoredY < -interfaceCanvasRect.height / 2f) { hiddenOptionHeight = -newAnchoredY - interfaceCanvasRect.height / 2f; } }
public void Progress(float timeStep) { RectTransform textTrans = null; bool textPaused = false; bool progressText = false; int textStage = INVALID_TEXT_STAGE; float stageDuration = 0f; float stageElapsed = 0f; float stageRate = 0f; bool keepStage = false; SpritedStringUI text = null; Color textColor = Color.white; Vector3 textScale = Vector3.one; Vector2 textIncreasedScale = Vector2.zero; bool textRemoved = false; int textEvolution = INVALID_TEXT_EVOLUTION; float textElapsed = 0f; Transform textOriginTrans = null; Vector2 textOriginWorld = Vector2.zero; Vector2 textOriginCanvas = Vector2.zero; Vector3 completeWorldPos = Vector3.zero; Vector2 currentOriginWorldPos = Vector2.zero; Vector2 textSpeed = Vector2.zero; if (textTransforms != null) { for (int i = 0; i < textTransforms.Length; i++) { textPaused = textPauseds[i]; /*halmeida - if a text was added during a game pause, I will progress it during the pause and I will continue * progressing it after the game is unpaused, because I don't want it to get stuck in the screen until the next pause. * However, if a text was added when the game was unpaused, I will only progress it while the game is unpaused.*/ progressText = (textPaused || (!textPaused && !paused)); if (progressText) { textTrans = textTransforms[i]; text = texts[i]; textStage = textStages[i]; stageRate = 0f; textRemoved = false; switch (textStage) { case TEXT_STAGE_SHOW: stageDuration = textDurationsShow[i]; if (stageDuration <= 0f) { stageRate = 1f; } else { stageElapsed = textStageElapseds[i]; stageElapsed += timeStep; stageRate = stageElapsed / stageDuration; stageRate = (stageRate > 1f) ? 1f : stageRate; textColor = text.GetGeneralColor(); textColor.a = Mathf.Lerp(0f, 1f, stageRate); text.SetGeneralColor(textColor); textIncreasedScale = textIncreasedScales[i]; textScale = textTrans.localScale; textScale.x = Mathf.Lerp(textIncreasedScale.x, 1f, stageRate); textScale.y = Mathf.Lerp(textIncreasedScale.y, 1f, stageRate); textTrans.localScale = textScale; } break; case TEXT_STAGE_PLAIN: stageDuration = textDurationsPlain[i]; if (stageDuration <= 0f) { stageRate = 1f; } else { stageElapsed = textStageElapseds[i]; stageElapsed += timeStep; stageRate = stageElapsed / stageDuration; stageRate = (stageRate > 1f) ? 1f : stageRate; } break; case TEXT_STAGE_HIDE: stageDuration = textDurationsHide[i]; if (stageDuration <= 0f) { stageRate = 1f; } else { stageElapsed = textStageElapseds[i]; stageElapsed += timeStep; stageRate = stageElapsed / stageDuration; stageRate = (stageRate > 1f) ? 1f : stageRate; textColor = text.GetGeneralColor(); textColor.a = Mathf.Lerp(1f, 0f, stageRate); text.SetGeneralColor(textColor); textIncreasedScale = textIncreasedScales[i]; textScale = textTrans.localScale; textScale.x = Mathf.Lerp(1f, textIncreasedScale.x, stageRate); textScale.y = Mathf.Lerp(1f, textIncreasedScale.y, stageRate); textTrans.localScale = textScale; } break; case TEXT_STAGE_OVER: RemoveCanvasText(i); textRemoved = true; break; } if (textRemoved) { if (textTransforms != null) { i--; } else { break; } } else { textEvolution = textEvolutions[i]; if ((textEvolution == TEXT_EVOLUTION_NONE_WAIT) && endWaitingTexts) { textEvolutions[i] = TEXT_EVOLUTION_NONE_GO; textEvolution = TEXT_EVOLUTION_NONE_GO; } if (stageRate == 1f) { keepStage = ((textEvolution == TEXT_EVOLUTION_NONE_WAIT) && (textStage == TEXT_STAGE_PLAIN)); if (!keepStage) { textStage++; textStages[i] = textStage; textStageElapseds[i] = 0f; } else { textStageElapseds[i] = stageElapsed; } } else { textStageElapseds[i] = stageElapsed; } textElapsed = textElapseds[i]; textElapsed += timeStep; textElapseds[i] = textElapsed; textOriginTrans = textOriginTransforms[i]; textOriginWorld = textOriginPositions[i]; if (textOriginTrans != null) { completeWorldPos = textOriginTrans.position; currentOriginWorldPos = new Vector2(completeWorldPos.x, completeWorldPos.y); currentOriginWorldPos += textOriginWorld; } else { currentOriginWorldPos = textOriginWorld; } if (TransformWorldToCanvasPosition(currentOriginWorldPos, ref textOriginCanvas)) { textSpeed = textSpeeds[i]; textTrans.anchoredPosition = textOriginCanvas + (textElapsed * textSpeed); } text.FeedPositionToMaterial(); } } } } endWaitingTexts = false; }
private void ClearSectionButtons() { SpritedStringUI buttonText = null; ButtonAnimator buttonAnimator = null; GameObject buttonObject = null; if (sectionTexts != null) { for (int i = 0; i < sectionTexts.Length; i++) { buttonText = sectionTexts[i]; if (buttonText != null) { buttonText.Clear(); sectionTexts[i] = null; } } sectionTexts = null; } if (sectionTextObjects != null) { for (int i = 0; i < sectionTextObjects.Length; i++) { buttonObject = sectionTextObjects[i]; if (buttonObject != null) { Destroy(buttonObject); sectionTextObjects[i] = null; } } sectionTextObjects = null; } if (sectionButtons != null) { for (int i = 0; i < sectionButtons.Length; i++) { buttonAnimator = sectionButtons[i]; if (buttonAnimator != null) { buttonAnimator.Clear(); sectionButtons[i] = null; } } sectionButtons = null; } sectionButtonTransforms = null; if (sectionButtonObjects != null) { for (int i = 0; i < sectionButtonObjects.Length; i++) { buttonObject = sectionButtonObjects[i]; if (buttonObject != null) { Destroy(buttonObject); sectionButtonObjects[i] = null; } } sectionButtonObjects = null; } chosenSectionIndex = -1; }
private void ClearItemButtons() { SpritedStringUI buttonText = null; ButtonAnimator buttonAnimator = null; GameObject buttonObject = null; if (itemReturnButton != null) { itemReturnButton.Clear(); itemReturnButton = null; } itemReturnButtonTransform = null; if (itemReturnButtonObject != null) { Destroy(itemReturnButtonObject); itemReturnButtonObject = null; } if (itemAdvanceButton != null) { itemAdvanceButton.Clear(); itemAdvanceButton = null; } itemAdvanceButtonTransform = null; if (itemAdvanceButtonObject != null) { Destroy(itemAdvanceButtonObject); itemAdvanceButtonObject = null; } if (itemAmountComponents != null) { for (int i = 0; i < itemAmountComponents.Length; i++) { buttonText = itemAmountComponents[i]; if (buttonText != null) { buttonText.Clear(); itemAmountComponents[i] = null; } } itemAmountComponents = null; } itemAmountTransforms = null; if (itemAmountObjects != null) { for (int i = 0; i < itemAmountObjects.Length; i++) { buttonObject = itemAmountObjects[i]; if (buttonObject != null) { Destroy(buttonObject); itemAmountObjects[i] = null; } } itemAmountObjects = null; } if (itemTexts != null) { for (int i = 0; i < itemTexts.Length; i++) { buttonText = itemTexts[i]; if (buttonText != null) { buttonText.Clear(); itemTexts[i] = null; } } itemTexts = null; } itemTextTransforms = null; if (itemTextObjects != null) { for (int i = 0; i < itemTextObjects.Length; i++) { buttonObject = itemTextObjects[i]; if (buttonObject != null) { Destroy(buttonObject); itemTextObjects[i] = null; } } itemTextObjects = null; } if (itemButtons != null) { for (int i = 0; i < itemButtons.Length; i++) { buttonAnimator = itemButtons[i]; if (buttonAnimator != null) { buttonAnimator.Clear(); itemButtons[i] = null; } } itemButtons = null; } itemButtonTransforms = null; if (itemButtonObjects != null) { for (int i = 0; i < itemButtonObjects.Length; i++) { buttonObject = itemButtonObjects[i]; if (buttonObject != null) { Destroy(buttonObject); itemButtonObjects[i] = null; } } itemButtonObjects = null; } chosenItemIndex = -1; checkingItemIndex = -1; firstItemIndex = -1; lastItemIndex = -1; }
private void SplitTextIntoLines() { GameObject textLineObject = null; RectTransform textLineTrans = null; SpritedStringUI textLineComponent = null; string textLine = null; int textLineLength = 0; int textLineIndex = -1; float textLineWidth = 0f; float interval = 0f; float position = 0f; int lineFirstIndex = -1; int lineLastIndex = -1; int lineLastIndexValid = -1; int lineLastIndexNext = -1; int lineLastIndexPrevious = -1; bool lineReady = false; bool allLinesReady = false; bool spaceFound = false; /*halmeida - to get one line I gotta create a long enough SpritedStringUI that fits * exactly into the maxTextWidth. If I don't have enough characters to fill the width, * I will just make a shorter line. The problem is that I'm able to see the width of a * sprited string only after I set its value with all the characters it is supposed to * have. Adding character by character to the SpritedString would be too slow, so I use * a sort of bynary search, looking for the maximum valid size for each line.*/ if ((text != null) && (textLines == null) && (ownTransform != null)) { textLineIndex = 0; lineFirstIndex = 0; lineLastIndex = text.Length - 1; while (!allLinesReady) { lineLastIndexValid = -1; interval = lineLastIndex - lineFirstIndex + 1; position = lineFirstIndex + interval; while (!lineReady) { if (textLineObject == null) { textLineObject = new GameObject("TextBoxUILine" + textLineIndex, typeof(RectTransform)); textLineTrans = textLineObject.GetComponent <RectTransform>(); /*halmeida - we should not add the lines as children of the object yet because the box * image itself has not yet been added as a child of the object. The lines would get behind * it if they were added now.*/ textLineComponent = textLineObject.AddComponent <SpritedStringUI>(); textLineComponent.SetSymbolSource(symbolDatabase); } textLineLength = lineLastIndex - lineFirstIndex + 1; textLine = text.Substring(lineFirstIndex, textLineLength); textLineWidth = symbolDatabase.GetStringWidthUI(textLine); //Debug.Log("Debug : TextBoxUI : attempting text line width "+textLineWidth+"."); interval = interval / 2f; if (textLineWidth > maxTextWidth) { position -= interval; } else { lineLastIndexValid = lineLastIndex; position += interval; } lineLastIndexNext = (int)position; /*halmeida - the position value itself should never be the same, but since it is rounded * to an integer index, we may end up falling back to a previously checked index. When that * happens, it means the interval has become small enough to stop the search.*/ if ((lineLastIndexNext == lineLastIndexPrevious) || (lineLastIndexNext == lineLastIndex) || (lineLastIndexNext > text.Length - 1)) { if (lineLastIndexValid == -1) { /*halmeida - after all the searching, no valid size was found. This probably means * the maxTextWidth is just too small to fit even one character. Even so we will * forcibly accept a one character wide line.*/ lineLastIndexValid = lineFirstIndex; } if (lineLastIndexValid > lineFirstIndex) { /*halmeida - if there is more than one character in the line, we can check for * word integrity. We cannot break a word into two lines. This means that the last * character in a line that is not the last line has to be an empty space or the * space has to be the first character in the next line.*/ if ((lineLastIndexValid + 1) < text.Length) { spaceFound = false; for (int i = (lineLastIndexValid + 1); i > lineFirstIndex; i--) { if (text[i] == ' ') { lineLastIndexValid = i - 1; spaceFound = true; } else { if (spaceFound) { break; } } } } } lineReady = true; /*halmeida - we didn't necessarily end the search at a valid size, but the last valid * size found is the biggest possible one. So we use that value to build the line.*/ textLineLength = lineLastIndexValid - lineFirstIndex + 1; textLine = text.Substring(lineFirstIndex, textLineLength); textLineComponent.SetValue(textLine); textLineComponent.ToggleAllSymbolVisuals(false); //Debug.Log("Debug : TextBoxUI : line "+textLineIndex+" is \""+textLine+"\"."); textLineWidth = textLineComponent.GetUIDimensions().x; //Debug.Log("Debug : TextBoxUI : final text line width "+textLineWidth+"."); if (textLineWidth > maxLineWidth) { maxLineWidth = textLineWidth; } } else { lineLastIndexPrevious = lineLastIndex; lineLastIndex = lineLastIndexNext; } } UsefulFunctions.IncreaseArray <string>(ref textLines, textLine); UsefulFunctions.IncreaseArray <GameObject>(ref textLineObjects, textLineObject); UsefulFunctions.IncreaseArray <RectTransform>(ref textLineTransforms, textLineTrans); UsefulFunctions.IncreaseArray <SpritedStringUI>(ref textLineComponents, textLineComponent); textLine = null; textLineObject = null; textLineTrans = null; textLineComponent = null; if (lineLastIndexValid == (text.Length - 1)) { allLinesReady = true; } else { textLineIndex++; lineFirstIndex = lineLastIndexValid + 1; for (int i = lineFirstIndex; i < text.Length; i++) { if (text[i] == ' ') { lineFirstIndex++; if (lineFirstIndex == text.Length) { allLinesReady = true; } } else { break; } } lineLastIndex = text.Length - 1; lineReady = false; } } } }