public virtual void DeselectOptionComponent() { if (selectedOptionComponent != null) { selectedOptionComponent.SetPressed(false); selectedOptionComponent = null; } }
protected virtual bool CheckOptionsHit(Vector2 canvasPoint) { RectTransform optionTransform = null; ButtonAnimator optionComponent = null; float realWidth = 0f; float realHeight = 0f; float xMin = 0f; float yMax = 0f; if (optionTransforms != null) { for (int i = 0; i < optionTransforms.Length; i++) { optionTransform = optionTransforms[i]; realWidth = optionTransform.rect.width * optionTransform.localScale.x; realHeight = optionTransform.rect.height * optionTransform.localScale.y; xMin = optionTransform.anchoredPosition.x - realWidth / 2f; yMax = optionTransform.anchoredPosition.y + realHeight / 2f; if (optionsParentTransform != null) { xMin += optionsParentTransform.anchoredPosition.x; yMax += optionsParentTransform.anchoredPosition.y; } if (UsefulFunctions.AreaContainsPoint(xMin, yMax, realWidth, realHeight, canvasPoint.x, canvasPoint.y)) { selectedOptionComponent = null; if (optionComponents != null) { if (optionComponents.Length > i) { optionComponent = optionComponents[i]; if (optionComponent != null) { selectedOptionComponent = optionComponent; selectedOptionComponent.SetPressed(true); } } } selectedChoiceEffect = ChoiceEffect.None; if (optionEffects != null) { if (optionEffects.Length > i) { selectedChoiceEffect = optionEffects[i]; } } return(true); } } } return(false); }
public virtual bool ReactToQuitRequest(bool ignoreQuitAvailability) { if (!ignoreQuitAvailability) { if (quitComponent != null) { selectedQuitComponent = quitComponent; selectedQuitComponent.SetPressed(true); } else { return(false); } } selectedChoiceEffect = ChoiceEffect.CloseMenu; return(true); }
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 bool CheckQuitHit(Vector2 canvasPoint) { if (quitTransform != null) { float realWidth = quitTransform.rect.width * quitTransform.localScale.x; float realHeight = quitTransform.rect.height * quitTransform.localScale.y; float xMin = quitTransform.anchoredPosition.x - realWidth / 2f; float yMax = quitTransform.anchoredPosition.y + realHeight / 2f; if (UsefulFunctions.AreaContainsPoint(xMin, yMax, realWidth, realHeight, canvasPoint.x, canvasPoint.y)) { selectedQuitComponent = quitComponent; selectedQuitComponent.SetPressed(true); ReactToQuitRequest(true); return(true); } } return(false); }
protected override bool CheckOptionsHit(Vector2 canvasPoint) { if (!base.CheckOptionsHit(canvasPoint)) { if ((sectionButtonTransforms != null) && (actionButtonTransforms == null)) { for (int i = 0; i < sectionButtonTransforms.Length; i++) { if (CheckTransformPointCollision(sectionButtonTransforms[i], canvasPoint)) { if ((chosenSectionIndex > -1) && (chosenSectionIndex != i)) { sectionButtons[chosenSectionIndex].SetPressed(false); ClearItemButtons(); ClearValidItems(); chosenSectionIndex = i; sectionButtons[i].SetPressed(true); SeparateValidItems(); CreateItemButtons(); } return(true); } } } if ((itemButtonTransforms != null) && (actionButtonTransforms == null)) { for (int i = firstItemIndex; i <= lastItemIndex; i++) { if (CheckTransformPointCollision(itemButtonTransforms[i], canvasPoint)) { if (i != chosenItemIndex) { ChangeButtonState(true, itemButtons[i], itemTexts[i], itemAmountComponents[i]); } checkingItemIndex = i; CreateAdditionalOverlays(); CreateHypotheticalStatsDisplay(); CreateActionButtons(); if (itemDatabase.DisplayItemInfo(ItemDatabase.ItemDisplayContext.Inventory, validItems[i])) { textBoxUIManager = TextBoxUIManager.Instance; } return(true); } } if (CheckTransformPointCollision(itemAdvanceButtonTransform, canvasPoint)) { if ((itemButtons.Length - 1) > lastItemIndex) { firstItemIndex += itemDisplayScheme.elementsScrolled; lastItemIndex += itemDisplayScheme.elementsScrolled; if (lastItemIndex >= itemButtons.Length) { lastItemIndex = itemButtons.Length - 1; } RepositionItemButtons(); itemAdvanceButton.SetPressed(!((itemButtons.Length - 1) > lastItemIndex)); itemReturnButton.SetPressed(!(firstItemIndex > 0)); } return(true); } if (CheckTransformPointCollision(itemReturnButtonTransform, canvasPoint)) { if (firstItemIndex > 0) { firstItemIndex -= itemDisplayScheme.elementsScrolled; Vector2[] allElementPositions = itemDisplayScheme.elementPositionRates; lastItemIndex = allElementPositions.Length - 1; RepositionItemButtons(); itemReturnButton.SetPressed(!(firstItemIndex > 0)); itemAdvanceButton.SetPressed(!((itemButtons.Length - 1) > lastItemIndex)); } return(true); } } if (actionButtonTransforms != null) { for (int i = 0; i < actionButtonTransforms.Length; i++) { if (CheckTransformPointCollision(actionButtonTransforms[i], canvasPoint)) { if (!actionButtons[i].IsPressed()) { switch (itemActions[i]) { case ChoiceEffect.Equip: player.EquipItem(validItems[checkingItemIndex]); UpdateStatsDisplay(); if (chosenItemIndex > -1) { ChangeButtonState(false, itemButtons[chosenItemIndex], itemTexts[chosenItemIndex], itemAmountComponents[chosenItemIndex]); } chosenItemIndex = checkingItemIndex; break; case ChoiceEffect.Unequip: player.UnequipItem(validItems[checkingItemIndex].itemID); UpdateStatsDisplay(); ChangeButtonState(false, itemButtons[checkingItemIndex], itemTexts[checkingItemIndex], itemAmountComponents[checkingItemIndex]); checkingItemIndex = -1; chosenItemIndex = -1; break; case ChoiceEffect.Use: break; case ChoiceEffect.CloseMenu: if (checkingItemIndex != chosenItemIndex) { ChangeButtonState(false, itemButtons[checkingItemIndex], itemTexts[checkingItemIndex], itemAmountComponents[checkingItemIndex]); } break; } ClearActionButtons(); ClearHypotheticalStatsDisplay(); ClearAdditionalOverlays(); if (textBoxUIManager != null) { textBoxUIManager.InterceptActionPress(); textBoxUIManager = null; } } return(true); } } } } return(false); }
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 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); }