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; } }
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; } } } } }
private bool CreateHeader() { string buttonCaption = null; RectTransform toDiscard = null; Vector2 anchoredPosition = Vector2.zero; if (interfaceCanvasObject != null) { GameTextDatabase gameTextDatabase = GameTextDatabase.Instance; if ((titleModel != null) && (titleObject == null)) { titleObject = Instantiate(titleModel) as GameObject; titleTransform = titleObject.GetComponent <RectTransform>(); titleComponent = titleObject.GetComponent <ButtonAnimator>(); if ((titleTransform != null) && (titleComponent != null)) { titleTransform.SetParent(interfaceCanvasTrans, false); anchoredPosition.x = (titlePositionRates.x - 0.5f) * interfaceCanvasRect.width; anchoredPosition.y = (titlePositionRates.y - 0.5f) * interfaceCanvasRect.height; titleTransform.anchoredPosition = anchoredPosition; titleTransform.localScale = new Vector3(titleScale.x, titleScale.y, 1f); if (gameTextDatabase != null) { buttonCaption = gameTextDatabase.GetMenuOptionText(titleTextEffect); CreateButtonText(titleTransform, buttonCaption, ref titleTextObject, ref toDiscard, ref titleText, true); } titleComponent.SetPressed(true); } else { titleTransform = null; if (titleComponent != null) { titleComponent.Clear(); titleComponent = null; } Destroy(titleObject); titleObject = null; } } if (allowQuitOption && (quitModel != null) && (quitObject == null)) { quitObject = Instantiate(quitModel) as GameObject; quitTransform = quitObject.GetComponent <RectTransform>(); quitComponent = quitObject.GetComponent <ButtonAnimator>(); if ((quitTransform != null) && (quitComponent != null)) { quitTransform.SetParent(interfaceCanvasTrans, false); anchoredPosition.x = (quitPositionRates.x - 0.5f) * interfaceCanvasRect.width; anchoredPosition.y = (quitPositionRates.y - 0.5f) * interfaceCanvasRect.height; quitTransform.anchoredPosition = anchoredPosition; quitTransform.localScale = new Vector3(quitScale.x, quitScale.y, 1f); if (gameTextDatabase != null) { buttonCaption = gameTextDatabase.GetMenuOptionText(quitTextEffect); CreateButtonText(quitTransform, buttonCaption, ref quitTextObject, ref toDiscard, ref quitText, true); } } else { quitTransform = null; if (quitComponent != null) { quitComponent.Clear(); quitComponent = null; } Destroy(quitObject); quitObject = null; } } return((quitObject != null) || (titleObject != null)); } return(false); }