<commit_before>﻿using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UtyMap.Unity.Infrastructure.Config;

namespace Assets.Scripts.Menu
{
    public class PanelManager : MonoBehaviour
    {
        private const string OpenTransitionName = "Open";
        private const string ClosedStateName = "Closed";

        public Animator initiallyOpen;

        private int _openParameterId;
        private Animator _open;
        private GameObject _previouslySelected;

        public void OnEnable()
        {
            _openParameterId = Animator.StringToHash(OpenTransitionName);

            if (initiallyOpen == null)
                return;

            OpenPanel(initiallyOpen);
        }

        public void OpenPanel (Animator anim)
        {
            if (_open == anim)
                return;

            anim.gameObject.SetActive(true);
            var newPreviouslySelected = EventSystem.current.currentSelectedGameObject;

            anim.transform.SetAsLastSibling();

            CloseCurrent();

            _previouslySelected = newPreviouslySelected;

            _open = anim;
            _open.SetBool(_openParameterId, true);

            GameObject go = FindFirstEnabledSelectable(anim.gameObject);

            SetSelected(go);
        }

        static GameObject FindFirstEnabledSelectable (GameObject gameObject)
        {
            GameObject go = null;
            var selectables = gameObject.GetComponentsInChildren<Selectable> (true);
            foreach (var selectable in selectables) {
                if (selectable.IsActive () && selectable.IsInteractable ()) {
                    go = selectable.gameObject;
                    break;
                }
            }
            return go;
        }

        public void CloseCurrent()
        {
            if (_open == null)
                return;

            _open.SetBool(_openParameterId, false);
            SetSelected(_previouslySelected);
            StartCoroutine(DisablePanelDeleyed(_open));
            _open = null;
        }

        IEnumerator DisablePanelDeleyed(Animator anim)
        {
            bool closedStateReached = false;
            bool wantToClose = true;
            while (!closedStateReached && wantToClose)
            {
                if (!anim.IsInTransition(0))
                    closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(ClosedStateName);

                wantToClose = !anim.GetBool(_openParameterId);

                yield return new WaitForEndOfFrame();<commit_msg>demo: do not select first selectable on menu<commit_after>﻿using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UtyMap.Unity.Infrastructure.Config;

namespace Assets.Scripts.Menu
{
    public class PanelManager : MonoBehaviour
    {
        private const string OpenTransitionName = "Open";
        private const string ClosedStateName = "Closed";

        public Animator initiallyOpen;

        private int _openParameterId;
        private Animator _open;
        private GameObject _previouslySelected;

        public void OnEnable()
        {
            _openParameterId = Animator.StringToHash(OpenTransitionName);

            if (initiallyOpen == null)
                return;

            OpenPanel(initiallyOpen);
        }

        public void OpenPanel (Animator anim)
        {
            if (_open == anim)
                return;

            anim.gameObject.SetActive(true);
            var newPreviouslySelected = EventSystem.current.currentSelectedGameObject;

            anim.transform.SetAsLastSibling();

            CloseCurrent();

            _previouslySelected = newPreviouslySelected;

            _open = anim;
            _open.SetBool(_openParameterId, true);

            //GameObject go = FindFirstEnabledSelectable(anim.gameObject);
            //SetSelected(go);
        }

        //static GameObject FindFirstEnabledSelectable (GameObject gameObject)
        //{
        //    GameObject go = null;
        //    var selectables = gameObject.GetComponentsInChildren<Selectable> (true);
        //    foreach (var selectable in selectables) {
        //        if (selectable.IsActive () && selectable.IsInteractable ()) {
        //            go = selectable.gameObject;
        //            break;
        //        }
        //    }
        //    return go;
        //}

        public void CloseCurrent()
        {
            if (_open == null)
                return;

            _open.SetBool(_openParameterId, false);
            SetSelected(_previouslySelected);
            StartCoroutine(DisablePanelDeleyed(_open));
            _open = null;
        }

        IEnumerator DisablePanelDeleyed(Animator anim)
        {
            bool closedStateReached = false;
            bool wantToClose = true;
            while (!closedStateReached && wantToClose)
            {
                if (!anim.IsInTransition(0))
                    closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(ClosedStateName);

                wantToClose = !anim.GetBool(_openParameterId);

                yield return new WaitForEndOfFrame();
{'fraction_non_alphanumeric': 0.0767905017234776, 'fraction_numerical': 0.0007659900421294523, 'mean_word_length': 1.8556588299617278, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6880400', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1270, 'n_words': 272}