public override GameObject CreateObject(Transform parent)
        {
            GameObject         gameObject         = base.CreateObject(parent);
            ExternalComponents externalComponents = gameObject.GetComponent <ExternalComponents>();

            RectTransform windowTransform = externalComponents.Get <RectTransform>();

            windowTransform.name      = "BSMLModalKeyboard";
            windowTransform.sizeDelta = new Vector2(135, 75);

            RectTransform parentTransform = new GameObject("KeyboardParent").AddComponent <RectTransform>();

            parentTransform.SetParent(gameObject.transform, false);

            KEYBOARD keyboard = new KEYBOARD(parentTransform, KEYBOARD.QWERTY, true, 4, -12);

            parentTransform.localScale *= 1.4f;

            ModalKeyboard modalKeyboard = gameObject.AddComponent <ModalKeyboard>();

            modalKeyboard.keyboard  = keyboard;
            modalKeyboard.modalView = externalComponents.Get <ModalView>();
            keyboard.EnterPressed  += delegate(string value) { modalKeyboard.OnEnter(value); };

            return(gameObject);
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            try
            {
                ModalKeyboard modalKeyboard = componentType.component as ModalKeyboard;
                if (componentType.data.TryGetValue("clearOnOpen", out string clearOnOpen))
                {
                    modalKeyboard.clearOnOpen = bool.Parse(clearOnOpen);
                }

                if (componentType.data.TryGetValue("value", out string value))
                {
                    if (!parserParams.values.TryGetValue(value, out BSMLValue associatedValue))
                    {
                        throw new Exception("value '" + value + "' not found");
                    }

                    modalKeyboard.associatedValue = associatedValue;
                }

                if (componentType.data.TryGetValue("onEnter", out string onEnter))
                {
                    if (!parserParams.actions.TryGetValue(onEnter, out BSMLAction onEnterAction))
                    {
                        throw new Exception("on-enter action '" + onEnter + "' not found");
                    }

                    modalKeyboard.onEnter = onEnterAction;
                }
            }
            catch (Exception ex)
            {
                Logger.log?.Error(ex);
            }
        }
Пример #3
0
        private void Awake()
        {
            // Create ModalKeyboard (BSML)
            var modalKeyboardTag = new ModalKeyboardTag();
            var modalKeyboardObj = modalKeyboardTag.CreateObject(transform);

            _modalKeyboard                        = modalKeyboardObj.GetComponent <ModalKeyboard>();
            _modalKeyboard.clearOnOpen            = false;
            _modalKeyboard.keyboard.EnterPressed += OnModalKeyboardSubmit;

            // Create server button
            var createServerButtonTransform = transform.Find("CreateServerButton");

            createServerButtonTransform.localPosition = new Vector3(-76.50f, 40.0f, 0.0f);

            _createServerButton = transform.Find("CreateServerButton").GetComponent <Button>();
            _createServerButton.onClick.AddListener(delegate
            {
                MpModeSelection.OpenCreateServerMenu();
            });

            // Move the top-right loading control up, so the refresh button aligns properly
            (transform.Find("Filters/SmallLoadingControl") as RectTransform).localPosition = new Vector3(62.0f, 3.5f, 0.0f);

            // Resize the filters bar so it doesn't overlap the refresh button
            var filterButtonTransform = (transform.Find("Filters/FilterButton") as RectTransform);

            filterButtonTransform.sizeDelta = new Vector2(-11.0f, 10.0f);
            filterButtonTransform.offsetMax = new Vector2(-11.0f, 5.0f);

            _filterButton = filterButtonTransform.GetComponent <Button>();
            _filterButton.onClick.AddListener(delegate
            {
                _modalKeyboard.keyboard.KeyboardText.text = !String.IsNullOrEmpty(_searchQuery) ? _searchQuery : "";
                //_modalKeyboard.keyboard.KeyboardText.fontSize = 4;

                _modalKeyboard.modalView.Show(true, true, null);
            });

            // Filters lable
            _filterButtonLabel      = transform.Find("Filters/FilterButton/Content/Text").GetComponent <CurvedTextMeshPro>();
            _filterButtonLabel.text = "Hello world!";

            // Hide top-right loading spinners
            Destroy(transform.Find("Filters/SmallLoadingControl/LoadingContainer").gameObject);
            Destroy(transform.Find("Filters/SmallLoadingControl/DownloadingContainer").gameObject);

            // Refresh button (add listener, make visible)
            var smallLoadingControl = transform.Find("Filters/SmallLoadingControl").GetComponent <LoadingControl>();

            smallLoadingControl.didPressRefreshButtonEvent += OnRefreshPressed;

            var refreshContainer = smallLoadingControl.transform.Find("RefreshContainer");

            refreshContainer.gameObject.SetActive(true);

            _refreshButton = refreshContainer.Find("RefreshButton").GetComponent <Button>();

            // Change "Music Packs" table header to "Type"
            transform.Find("GameServersListTableView/GameServerListTableHeader/LabelsContainer/MusicPack").GetComponent <CurvedTextMeshPro>()
            .SetText("Type");

            // Main loading control
            _mainLoadingControl = transform.Find("GameServersListTableView/TableView/Viewport/MainLoadingControl").GetComponent <LoadingControl>();
            _mainLoadingControl.didPressRefreshButtonEvent += OnRefreshPressed;

            _mainLoadingControl.ShowLoading("Initializing");

            // Table view
            _tableView = transform.Find("GameServersListTableView").GetComponent <GameServersListTableView>();

            // Modify content cell prefab (add a background)
            var contentCellPrefab = _tableView.GetField <GameServerListTableCell, GameServersListTableView>("_gameServerListCellPrefab");

            var backgroundBase = Resources.FindObjectsOfTypeAll <ImageView>().First(x => x.gameObject?.name == "Background" &&
                                                                                    x.sprite != null && x.sprite.name.StartsWith("RoundRect10"));

            var backgroundClone = UnityEngine.Object.Instantiate(backgroundBase);

            backgroundClone.transform.SetParent(contentCellPrefab.transform, false);
            backgroundClone.transform.SetAsFirstSibling();
            backgroundClone.name = "Background";

            var backgroundTransform = backgroundClone.transform as RectTransform;

            backgroundTransform.anchorMin = new Vector2(0.0f, 0.0f);
            backgroundTransform.anchorMax = new Vector2(0.95f, 1.0f);
            backgroundTransform.offsetMin = new Vector2(0.5f, 0.0f);
            backgroundTransform.offsetMax = new Vector2(5.0f, 0.0f);
            backgroundTransform.sizeDelta = new Vector2(4.50f, 0.0f);

            var cellBackgroundHelper = contentCellPrefab.gameObject.AddComponent <CellBackgroundHelper>();

            cellBackgroundHelper.Cell       = contentCellPrefab;
            cellBackgroundHelper.Background = backgroundClone;
        }