Ejemplo n.º 1
0
 protected void InvokeFilterButtonPressed() => FilterButtonPressed?.Invoke();
Ejemplo n.º 2
0
 private void OnFilterButtonClicked()
 {
     Logger.log.Debug("Filter button pressed");
     FilterButtonPressed?.Invoke();
 }
        public void Setup(bool forceReinit = false)
        {
            if (Initialized)
            {
                if (!forceReinit)
                {
                    return;
                }

                if (_container != null)
                {
                    DestroyImmediate(_container);
                    _container         = null;
                    _mainModule        = null;
                    _sortModeModule    = null;
                    _quickFilterModule = null;
                    _miscModule        = null;
                }
            }

            var topScreen = Resources.FindObjectsOfTypeAll <GameObject>().First(x => x.name == "TopScreen");

            _container      = Instantiate(topScreen, topScreen.transform.parent, true);
            _container.name = "EnhancedSearchAndFiltersButtonPanel";
            _container.AddComponent <RectMask2D>();

            // always render this screen in front of the title view controller's screen
            var canvas = _container.GetComponent <Canvas>();

            canvas.sortingOrder += 1;

            // expand screen to reveal sort mode buttons
            _hoverEventHandler = _container.AddComponent <EnterExitEventHandler>();
            _hoverEventHandler.PointerEntered += delegate()
            {
                if (_inRevealAnimation)
                {
                    return;
                }
                else if (_contractAnimation != null)
                {
                    StopCoroutine(_contractAnimation);
                    _contractAnimation = null;
                }

                _expandAnimation = ExpandAnimationCoroutine();
                StartCoroutine(_expandAnimation);
            };
            _hoverEventHandler.PointerExited += delegate()
            {
                if (_inRevealAnimation)
                {
                    return;
                }

                bool immediate = false;
                if (_expandAnimation != null)
                {
                    StopCoroutine(_expandAnimation);
                    _expandAnimation = null;
                    immediate        = true;
                }
                else if (_contractAnimation != null)
                {
                    StopCoroutine(_contractAnimation);
                    _contractAnimation = null;
                }

                _contractAnimation = ContractAnimationCoroutine(immediate);
                StartCoroutine(_contractAnimation);
            };

            Destroy(_container.transform.Find("TitleViewController").gameObject);
            Destroy(_container.GetComponentInChildren <Screen>(true));
            Destroy(_container.GetComponentInChildren <HorizontalLayoutGroup>(true));

            // yoinked from:
            // https://github.com/monkeymanboy/BeatSaberMarkupLanguage/blob/master/BeatSaberMarkupLanguage/FloatingScreen/FloatingScreen.cs
            // prevents lots of exceptions being thrown by the VRGraphicRaycaster in some situations
            SetMainCameraToCanvas setCamera = _container.GetComponent <SetMainCameraToCanvas>();

            setCamera.SetField("_canvas", canvas);
            setCamera.SetField("_mainCamera", Resources.FindObjectsOfTypeAll <MainCamera>().FirstOrDefault(camera => camera.camera?.stereoTargetEye != StereoTargetEyeMask.None) ?? Resources.FindObjectsOfTypeAll <MainCamera>().FirstOrDefault());

            // position the screen
            var rt = _container.transform as RectTransform;

            rt.sizeDelta        = new Vector2(DefaultXSize, 30f);
            rt.pivot            = new Vector2(1f, 0f);
            rt.anchorMin        = new Vector2(1f, 0f);
            rt.anchorMax        = new Vector2(1f, 0f);
            rt.anchoredPosition = new Vector2(1.6f, 2.44f);
            rt.localRotation    = Quaternion.Euler(345f, 0f, 0f);
            rt.localPosition   += new Vector3(0f, 0f, -0.001f);

            // initialize modules
            // - unexpanded container is of size 28w x 30h
            // - usable area minus default padding (3) for each module is 22w x 24h
            Vector2 anchorMin   = new Vector2(1f, 0f);
            Vector2 anchorMax   = Vector2.one;
            Vector2 sizeDelta   = new Vector2(28f, 0f);
            Vector2 anchoredPos = new Vector2(-14f, 0f);

            _expandedXSize = 0f;

            if (!PluginConfig.DisableSearch || !PluginConfig.DisableFilters)
            {
                _mainModule = new GameObject("MainModule").AddComponent <MainModule>();
                _mainModule.SearchButtonPressed      += () => SearchButtonPressed?.Invoke();
                _mainModule.FilterButtonPressed      += () => FilterButtonPressed?.Invoke();
                _mainModule.ClearFilterButtonPressed += () => ClearFilterButtonPressed?.Invoke();

                _mainModule.RectTransform.SetParent(_container.transform, false);
                _mainModule.RectTransform.anchorMin        = anchorMin;
                _mainModule.RectTransform.anchorMax        = anchorMax;
                _mainModule.RectTransform.sizeDelta        = sizeDelta;
                _mainModule.RectTransform.anchoredPosition = anchoredPos;
                anchoredPos    -= sizeDelta;
                _expandedXSize += sizeDelta.x;
            }

            _sortModeModule = new GameObject("SortModeModule").AddComponent <SortModeModule>();
            _sortModeModule.SortButtonPressed += () => SortButtonPressed?.Invoke();

            _sortModeModule.RectTransform.SetParent(_container.transform, false);
            _sortModeModule.RectTransform.anchorMin        = anchorMin;
            _sortModeModule.RectTransform.anchorMax        = anchorMax;
            _sortModeModule.RectTransform.sizeDelta        = sizeDelta;
            _sortModeModule.RectTransform.anchoredPosition = anchoredPos;
            anchoredPos    -= sizeDelta;
            _expandedXSize += sizeDelta.x;

            if (!PluginConfig.DisableFilters)
            {
                _quickFilterModule = new GameObject("QuickFilterModule").AddComponent <QuickFilterModule>();
                _quickFilterModule.ApplyQuickFilterPressed += (quickFilter) => ApplyQuickFilterPressed?.Invoke(quickFilter);

                _quickFilterModule.RectTransform.SetParent(_container.transform, false);
                _quickFilterModule.RectTransform.anchorMin        = anchorMin;
                _quickFilterModule.RectTransform.anchorMax        = anchorMax;
                _quickFilterModule.RectTransform.sizeDelta        = sizeDelta;
                _quickFilterModule.RectTransform.anchoredPosition = anchoredPos;
                anchoredPos    -= sizeDelta;
                _expandedXSize += sizeDelta.x;
            }

            _miscModule = new GameObject("MiscModule").AddComponent <MiscModule>();
            _miscModule.ReportButtonPressed += () => ReportButtonPressed?.Invoke();

            _miscModule.RectTransform.SetParent(_container.transform, false);
            _miscModule.RectTransform.anchorMin        = anchorMin;
            _miscModule.RectTransform.anchorMax        = anchorMax;
            _miscModule.RectTransform.sizeDelta        = sizeDelta;
            _miscModule.RectTransform.anchoredPosition = anchoredPos;
            anchoredPos    -= sizeDelta;
            _expandedXSize += sizeDelta.x;

            Initialized = true;

            HidePanel(true);
        }