Esempio n. 1
0
 /// <summary>
 /// Selects the panel's continue button (i.e., navigates to it).
 /// </summary>
 /// <param name="allowStealFocus">Select continue button even if another element is already selected.</param>
 public virtual void Select(bool allowStealFocus = true)
 {
     UITools.Select(continueButton, allowStealFocus);
 }
Esempio n. 2
0
        private IEnumerator WaitForAnimationTrigger(State stateWhenBegin, State stateWhenEnd, string triggerName, bool pauseAfterAnimation, bool panelActive, bool wait, System.Action callback)
        {
            if (state != stateWhenEnd)
            {
                state = stateWhenBegin;
                if (panelActive)
                {
                    if (panel != null && !panel.gameObject.activeSelf)
                    {
                        panel.gameObject.SetActive(true);
                        yield return(null);
                    }
                }
                if (CanTriggerAnimation(triggerName) && m_animator.gameObject.activeSelf)
                {
                    if (debug)
                    {
                        Debug.Log("<color=green>" + panel.name + ".Animator.SetTrigger(" + triggerName + ") time=" + Time.time + "</color>");
                    }
                    CheckAnimatorModeAndTimescale(triggerName);
                    float timeout       = Time.realtimeSinceStartup + maxWaitDuration;
                    var   goalHashID    = Animator.StringToHash(triggerName);
                    var   oldHashId     = UITools.GetAnimatorNameHash(m_animator.GetCurrentAnimatorStateInfo(0));
                    var   currentHashID = oldHashId;
                    m_animator.SetTrigger(triggerName);
                    if (wait)
                    {
                        // Wait while we're not at the goal state and we're in the original state and we haven't timed out:
                        while ((currentHashID != goalHashID) && (currentHashID == oldHashId) && (Time.realtimeSinceStartup < timeout))
                        {
                            yield return(null);

                            var isAnimatorValid = m_animator != null && m_animator.isActiveAndEnabled && m_animator.runtimeAnimatorController != null && m_animator.layerCount > 0;
                            currentHashID = isAnimatorValid ? UITools.GetAnimatorNameHash(m_animator.GetCurrentAnimatorStateInfo(0)) : currentHashID;
                        }
                        // If we're in the goal state and we haven't timed out, wait for the duration of the goal state:
                        if (currentHashID == goalHashID && Time.realtimeSinceStartup < timeout)
                        {
                            var clipLength = m_animator.GetCurrentAnimatorStateInfo(0).length;
                            if (Mathf.Approximately(0, Time.timeScale))
                            {
                                timeout = Time.realtimeSinceStartup + clipLength;
                                while (Time.realtimeSinceStartup < timeout)
                                {
                                    yield return(null);
                                }
                            }
                            else
                            {
                                yield return(new WaitForSeconds(clipLength));
                            }
                        }
                        if (debug)
                        {
                            Debug.Log("<color=red>... finished " + panel.name + ".Animator.SetTrigger(" + triggerName + ") time=" + Time.time + "</color>");
                        }
                    }
                }
            }
            if (!panelActive)
            {
                Tools.SetGameObjectActive(panel, false);
            }
            if (pauseAfterAnimation)
            {
                Time.timeScale = 0;
            }
            m_animCoroutine = null;
            state           = stateWhenEnd;
            if (callback != null)
            {
                callback.Invoke();
            }
        }
Esempio n. 3
0
 public virtual void OpenOnStartConversation(Texture2D portraitTexture, string portraitName, DialogueActor dialogueActor)
 {
     OpenOnStartConversation(UITools.CreateSprite(portraitTexture), portraitName, dialogueActor);
 }
Esempio n. 4
0
 public void OnLevelWasLoaded(int level)
 {
     UITools.RequireEventSystem();
 }
Esempio n. 5
0
 public void OnSceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
 {
     UITools.RequireEventSystem();
 }
Esempio n. 6
0
        public void AutoFocus()
        {
            GameObject go = completedQuestsButton.gameObject.activeSelf ? completedQuestsButton.gameObject : activeQuestsButton.gameObject;

            UITools.Select(go.GetComponent <UnityEngine.UI.Selectable>());
        }
 public virtual void SetPCPortrait(Texture2D portraitTexture, string portraitName)
 {
     SetPCPortrait(UITools.CreateSprite(portraitTexture), portraitName);
 }
Esempio n. 8
0
 /// <summary>
 /// Given a Texture2D and/or Sprite, returns whichever one is not null.
 /// Gives preference to the Texture2D.
 public static Sprite GetSprite(Texture2D texture, Sprite sprite)
 {
     return((texture != null) ? UITools.CreateSprite(texture) : sprite);
 }
 /// <summary>
 /// Auto-focuses the continue button. Useful for gamepads.
 /// </summary>
 public void AutoFocus(bool allowStealFocus = true)
 {
     UITools.Select(continueButton, allowStealFocus);
 }
        protected IEnumerator SelectElement(UnityEngine.UI.Selectable elementToSelect)
        {
            yield return(null);

            UITools.Select(elementToSelect);
        }
        public override void OnQuestListUpdated()
        {
            if (!m_isAwake)
            {
                return;
            }
            UnityEngine.UI.Selectable elementToSelect = null;
            showingActiveQuestsHeading.SetActive(isShowingActiveQuests);
            showingCompletedQuestHeading.SetActive(!isShowingActiveQuests);
            selectionPanelContentManager.Clear();
            var questTitleTemplate = isShowingActiveQuests ? activeQuestHeadingTemplate : completedQuestHeadingTemplate;

            // Get group names, and draw selected quest in its panel while we're at it:
            var groupNames            = new List <string>();
            int numGroupless          = 0;
            var repaintedQuestDetails = false;

            if (quests.Length > 0)
            {
                foreach (var quest in quests)
                {
                    if (IsSelectedQuest(quest))
                    {
                        RepaintSelectedQuest(quest);
                        repaintedQuestDetails = true;
                    }
                    var groupName = quest.Group;
                    if (string.IsNullOrEmpty(groupName))
                    {
                        numGroupless++;
                    }
                    if (string.IsNullOrEmpty(groupName) || groupNames.Contains(groupName))
                    {
                        continue;
                    }
                    groupNames.Add(groupName);
                }
            }
            if (!repaintedQuestDetails)
            {
                RepaintSelectedQuest(null);
            }

            // Add quests by group:
            foreach (var groupName in groupNames)
            {
                var groupFoldout = selectionPanelContentManager.Instantiate <StandardUIFoldoutTemplate>(questGroupTemplate);
                selectionPanelContentManager.Add(groupFoldout, questSelectionContentContainer);
                groupFoldout.Assign(groupName, IsGroupExpanded(groupName));
                var targetGroupName    = groupName;
                var targetGroupFoldout = groupFoldout;
                if (!keepGroupsExpanded)
                {
                    groupFoldout.foldoutButton.onClick.AddListener(() => { OnClickGroup(targetGroupName, targetGroupFoldout); });
                }
                if (string.Equals(foldoutToSelect, groupName))
                {
                    elementToSelect = groupFoldout.foldoutButton;
                    foldoutToSelect = null;
                }
                foreach (var quest in quests)
                {
                    if (string.Equals(quest.Group, groupName))
                    {
                        var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(questTitleTemplate);
                        questTitle.Assign(quest.Heading.text, OnToggleTracking);
                        selectionPanelContentManager.Add(questTitle, groupFoldout.interiorPanel);
                        var target = quest.Title;
                        questTitle.button.onClick.AddListener(() => { OnClickQuest(target); });
                        if (showDetailsOnSelect)
                        {
                            AddShowDetailsOnSelect(questTitle.button, target);
                        }
                        if (string.Equals(quest.Title, questTitleToSelect))
                        {
                            elementToSelect    = questTitle.button;
                            questTitleToSelect = null;
                        }
                    }
                }
            }

            // Add groupless quests:
            foreach (var quest in quests)
            {
                if (!string.IsNullOrEmpty(quest.Group))
                {
                    continue;
                }
                var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(questTitleTemplate);
                questTitle.Assign(quest.Heading.text, OnToggleTracking);
                selectionPanelContentManager.Add(questTitle, questSelectionContentContainer);
                var target = quest.Title;
                questTitle.button.onClick.AddListener(() => { OnClickQuest(target); });
                if (showDetailsOnSelect)
                {
                    AddShowDetailsOnSelect(questTitle.button, target);
                }
                if (string.Equals(quest.Title, questTitleToSelect))
                {
                    elementToSelect    = questTitle.button;
                    questTitleToSelect = null;
                }
            }

            // If no quests, add no quests text:
            if (quests.Length == 0 && showNoQuestsText)
            {
                var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(completedQuestHeadingTemplate);
                questTitle.Assign(IsShowingActiveQuests ? noActiveQuestsText : noCompletedQuestsText, null);
                selectionPanelContentManager.Add(questTitle, questSelectionContentContainer);
            }

            SetStateToggleButtons();
            mainPanel.RefreshSelectablesList();
            if (mainPanel != null)
            {
                UnityEngine.UI.LayoutRebuilder.MarkLayoutForRebuild(mainPanel.GetComponent <RectTransform>());
            }
            if (elementToSelect != null)
            {
                StartCoroutine(SelectElement(elementToSelect));
            }
            else if (UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject == null && mainPanel != null && mainPanel.firstSelected != null && InputDeviceManager.autoFocus)
            {
                UITools.Select(mainPanel.firstSelected.GetComponent <UnityEngine.UI.Selectable>());
            }
        }
        /// <summary>
        /// Sets the controls active/inactive, except this method never activates the timer. If the
        /// UI's display settings specify a timeout, then the UI will call StartTimer() to manually
        /// activate the timer.
        /// </summary>
        /// <param name='value'>
        /// Value (<c>true</c> for active; otherwise inactive).
        /// </param>
        public override void SetActive(bool value)
        {
            SubtitleReminder.SetActive(value && SubtitleReminder.HasText);
            Tools.SetGameObjectActive(buttonTemplate, false);
            foreach (var button in buttons)
            {
                if (button != null)
                {
                    Tools.SetGameObjectActive(button, value && button.visible);
                }
            }
            Tools.SetGameObjectActive(timer, false);
            Tools.SetGameObjectActive(pcName, value);
            Tools.SetGameObjectActive(pcImage, value);
            if (value == true)
            {
                if ((pcImage != null) && (pcPortraitTexture != null))
                {
                    pcImage.sprite = UITools.CreateSprite(pcPortraitTexture);
                }
                if ((pcName != null) && (pcPortraitName != null))
                {
                    pcName.text = pcPortraitName;
                }
                Tools.SetGameObjectActive(panel, true);

                animationTransitions.ClearTriggers(showHideController);
                showHideController.Show(animationTransitions.showTrigger, false, null);

                //--- Replaced by code above:
                //if (!isVisible && CanTriggerAnimation(animationTransitions.showTrigger))
                //{
                //    switch (animationTransitions.transitionMode)
                //    {
                //        case UIShowHideController.TransitionMode.State:
                //            animator.Play(animationTransitions.showTrigger);
                //            break;
                //        case UIShowHideController.TransitionMode.Trigger:
                //            animator.SetTrigger(animationTransitions.showTrigger);
                //            break;
                //    }
                //}

                if (explicitNavigationForTemplateButtons)
                {
                    SetupTemplateButtonNavigation();
                }
            }
            else
            {
                if (isVisible && CanTriggerAnimation(animationTransitions.hideTrigger))
                {
                    animationTransitions.ClearTriggers(showHideController);
                    showHideController.Hide(animationTransitions.hideTrigger, DeactivateUIElements);

                    //--- Replaced by code above:
                    //switch (animationTransitions.transitionMode)
                    //{
                    //    case UIShowHideController.TransitionMode.State:
                    //        animator.Play(animationTransitions.hideTrigger);
                    //        break;
                    //    case UIShowHideController.TransitionMode.Trigger:
                    //        animator.SetTrigger(animationTransitions.hideTrigger);
                    //        break;
                    //}
                    //DialogueManager.Instance.StartCoroutine(DisableAfterAnimation(panel));
                }
                else if (!isHiding)
                {
                    if (panel != null)
                    {
                        Tools.SetGameObjectActive(panel, false);
                    }
                }
            }
        }
Esempio n. 13
0
 public static string StripRPGMakerCodes(string s) // Moved to UITools, but kept for compatibility with third party code.
 {
     return(UITools.StripRPGMakerCodes(s));
 }
 public virtual void SetPCPortrait(Texture2D portraitTexture, string portraitName)
 {
     dialogueControls.responseMenuControls.SetPCPortrait(UITools.CreateSprite(portraitTexture), portraitName);
 }