Пример #1
0
 public override void HandleTypeAfterChildren(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
 {
     foreach (GameObject go in parserParams.GetObjectsWithTag("ScrollFocus"))
     {
         go.AddComponent <ItemForFocussedScrolling>();
     }
 }
        public override void HandleTypeAfterParse(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            BSMLScrollableContainer scrollView = componentType.component as BSMLScrollableContainer;

            if (componentType.data.TryGetValue("id", out string id))
            {
                scrollView.PageUpButton = parserParams.GetObjectsWithTag("PageUpFor:" + id)
                                          .Select(o => o.GetComponent <Button>())
                                          .Where(b => b != null)
                                          .FirstOrDefault();

                scrollView.PageDownButton = parserParams.GetObjectsWithTag("PageDownFor:" + id)
                                            .Select(o => o.GetComponent <Button>())
                                            .Where(b => b != null)
                                            .FirstOrDefault();

                scrollView.ScrollIndicator = parserParams.GetObjectsWithTag("IndicatorFor:" + id)
                                             .Select(o => o.GetComponent <VerticalScrollIndicator>() ?? o.GetComponent <BSMLScrollIndicator>())
                                             .Where(i => i != null)
                                             .FirstOrDefault();
            }

            scrollView.RefreshContent();
            scrollView.RefreshButtons();
            //scrollView.ScrollAt(0, false);
        }
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            base.HandleType(componentType, parserParams);

            var markdownText = (MarkdownText)componentType.component;

            // run this manually once to ensure it overwrites the children
            if (componentType.data.TryGetValue("text", out var text))
            {
                markdownText.Text = text;
            }

            if (componentType.data.TryGetValue("linkPressed", out var selectCell))
            {
                markdownText.OnLinkPressed += (url, title) =>
                {
                    if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action))
                    {
                        throw new Exception("link-pressed action '" + componentType.data["onClick"] + "' not found");
                    }

                    _ = action.Invoke(url, title);
                };
            }
        }
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            base.HandleType(componentType, parserParams);
            FormattableText formattableText = componentType.component as FormattableText;
            NotifyUpdater   updater         = null;

            if (componentType.data.TryGetValue("data", out string dataStr))
            {
                if (parserParams.values.TryGetValue(dataStr, out BSMLValue dataValue))
                {
                    formattableText.Data = dataValue.GetValue();
                    BindValue(componentType, parserParams, dataValue, val => formattableText.Data = val, updater);
                }
                else
                {
                    throw new Exception($"data value '{dataStr}' not found");
                }
            }
            if (componentType.data.TryGetValue("dataFormatter", out string formatterStr))
            {
                if (parserParams.values.TryGetValue(formatterStr, out BSMLValue formatterValue))
                {
                    formattableText.SetFormatter(formatterValue.GetValue());
                    updater = BindValue(componentType, parserParams, formatterValue, val => formattableText.SetFormatter(val), updater);
                }
                else
                {
                    throw new Exception($"data-formatter value '{formatterStr}' not found");
                }
            }
        }
            public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
            {
                base.HandleType(componentType, parserParams);
                var buttonCollection = componentType.component as ButtonCollection;

                buttonCollection.SetTexts(new[] { "t1", "t2", "t3" });
                buttonCollection.parserParams = parserParams;
                parserParams.AddEvent("post-parse", buttonCollection.Setup);
            }
Пример #6
0
            public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
            {
                Debug.LogError("Handler handling stuff");
                base.HandleType(componentType, parserParams);
                ButtonCollection buttonCollection = (componentType.component as ButtonCollection);

                buttonCollection.SetTexts(new [] { "t1", "t2", "t3" });
                buttonCollection.parserParams = parserParams;
                parserParams.AddEvent("post-parse", buttonCollection.Setup);
            }
            public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
            {
                try
                {
                    var button = componentType.component as IconToggleButton;

                    if (componentType.data.TryGetValue("onToggle", out var onToggle))
                    {
                        if (parserParams.actions.TryGetValue(onToggle, out var onToggleAction))
                        {
                            button.OnStateChanged += val => { onToggleAction.Invoke(val); };
                        }
                    }

                    base.HandleType(componentType, parserParams);
                }
                catch (Exception)
                { }
            }
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            base.HandleType(componentType, parserParams);
            var backgroundable = (Backgroundable)componentType.component;

            if (componentType.data.TryGetValue("customBg", out var customBg))
            {
                InitSprite();
                var imageview = GetOrAddImageView(backgroundable);
                if (imageview != null)
                {
                    imageview.overrideSprite  = _bgSprite;
                    backgroundable.background = imageview;
                }
            }

            if (componentType.data.TryGetValue("customColor", out var customColor))
            {
                TrySetBackgroundColor(backgroundable, customColor);
            }

            if (componentType.data.TryGetValue("border", out var borderAttr))
            {
                AddBorder(backgroundable.gameObject, borderAttr == "square");
            }

            if (componentType.data.TryGetValue("raycast", out var raycastAttr))
            {
                if (backgroundable.background != null)
                {
                    backgroundable.background.raycastTarget = bool.Parse(raycastAttr);
                }
            }

            if (componentType.data.TryGetValue("skew", out var skew))
            {
                if (backgroundable.background is ImageView imageView)
                {
                    imageView.SetSkew(float.Parse(skew));
                }
            }
        }
Пример #9
0
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            BSMLScrollableContainer scrollView = componentType.component as BSMLScrollableContainer;

            if (componentType.data.TryGetValue("id", out string id))
            {
                parserParams.AddEvent(id + "#PageUp", scrollView.PageUpButtonPressed);
                parserParams.AddEvent(id + "#PageDown", scrollView.PageDownButtonPressed);
            }

            if (componentType.data.TryGetValue("maskOverflow", out string value))
            {
                scrollView.MaskOverflow = bool.TryParse(value, out bool bval) ? bval : true;
            }

            if (componentType.data.TryGetValue("alignBottom", out value))
            {
                scrollView.AlignBottom = bool.TryParse(value, out bool bval) ? bval : false;
            }
        }
Пример #10
0
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            var tableData = componentType.component as CustomListTableData;

            if (componentType.data.TryGetValue("selectCell", out var selectCell))
            {
                tableData.TableView.didSelectCellWithIdxEvent += delegate(TableView table, int index)
                {
                    if (!parserParams.actions.TryGetValue(selectCell, out var action))
                    {
                        throw new Exception("select-cell action '" + componentType.data["onClick"] + "' not found");
                    }

                    action.Invoke(table, index);
                };
            }

            if (componentType.data.TryGetValue("listDirection", out var listDirection))
            {
                tableData.TableView.SetField("_tableType", (TableView.TableType)Enum.Parse(typeof(TableView.TableType), listDirection));
            }

            if (componentType.data.TryGetValue("listStyle", out var listStyle))
            {
                tableData.Style = (CustomListTableData.ListStyle)Enum.Parse(typeof(CustomListTableData.ListStyle), listStyle);
            }

            if (componentType.data.TryGetValue("cellSize", out var cellSize))
            {
                tableData.cellSize = Parse.Float(cellSize);
            }

            if (componentType.data.TryGetValue("expandCell", out var expandCell))
            {
                tableData.ExpandCell = Parse.Bool(expandCell);
            }

            if (componentType.data.TryGetValue("alignCenter", out var alignCenter))
            {
                tableData.TableView.SetField("_alignToCenter", Parse.Bool(alignCenter));
            }


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

                tableData.Data = contents.GetValue() as List <CustomListTableData.CustomCellInfo>;
                tableData.TableView.ReloadData();
            }

            switch (tableData.TableView.tableType)
            {
            case TableView.TableType.Vertical:
                (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(
                    componentType.data.TryGetValue("listWidth", out var vListWidth) ? Parse.Float(vListWidth) : 60,
                    tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out var vVisibleCells)
                            ? Parse.Float(vVisibleCells)
                            : 7));
                break;

            case TableView.TableType.Horizontal:
                (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(
                    tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out var hVisibleCells) ? Parse.Float(hVisibleCells) : 4),
                    componentType.data.TryGetValue("listHeight", out var hListHeight) ? Parse.Float(hListHeight) : 40);
                break;
            }

            componentType.component.gameObject.GetComponent <LayoutElement>().preferredHeight =
                (componentType.component.gameObject.transform as RectTransform).sizeDelta.y;
            componentType.component.gameObject.GetComponent <LayoutElement>().preferredWidth =
                (componentType.component.gameObject.transform as RectTransform).sizeDelta.x;

            tableData.TableView.gameObject.SetActive(true);
            tableData.TableView.LazyInit();

            if (componentType.data.TryGetValue("id", out var id))
            {
                var scroller = tableData.TableView.GetField <ScrollView, TableView>("_scrollView");
                parserParams.AddEvent(id + "#PageUp", scroller.PageUpButtonPressed);
                parserParams.AddEvent(id + "#PageDown", scroller.PageDownButtonPressed);
            }
        }
Пример #11
0
        public override void HandleType(BSMLParser.ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            var tableData = (PropListTableData)componentType.component;

            if (componentType.data.TryGetValue("selectCell", out string selectCell))
            {
                tableData.tableView.didSelectCellWithIdxEvent += delegate(TableView table, int index)
                {
                    if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action))
                    {
                        throw new Exception("select-cell action '" + componentType.data["onClick"] + "' not found");
                    }

                    action.Invoke(table, index);
                };
            }

            if (componentType.data.TryGetValue("listDirection", out string listDirection))
            {
                tableData.tableView.SetField("_tableType", (TableView.TableType)Enum.Parse(typeof(TableView.TableType), listDirection));
            }

            if (componentType.data.TryGetValue("cellSize", out string cellSize))
            {
                tableData.cellSize = Parse.Float(cellSize);
            }

            if (componentType.data.TryGetValue("alignCenter", out string alignCenter))
            {
                tableData.tableView.SetField("_alignToCenter", Parse.Bool(alignCenter));
            }


            if (componentType.data.TryGetValue("data", out string value))
            {
                if (!parserParams.values.TryGetValue(value, out BSMLValue contents))
                {
                    throw new Exception("value '" + value + "' not found");
                }
                tableData.data = contents.GetValue() as List <PropListTableData.PropertyDescriptor>;
                tableData.tableView.ReloadData();
            }

            switch (tableData.tableView.tableType)
            {
            case TableView.TableType.Vertical:
                (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(componentType.data.TryGetValue("listWidth", out string vListWidth) ? Parse.Float(vListWidth) : 60, tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string vVisibleCells) ? Parse.Float(vVisibleCells) : 7));
                break;

            case TableView.TableType.Horizontal:
                (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string hVisibleCells) ? Parse.Float(hVisibleCells) : 4), componentType.data.TryGetValue("listHeight", out string hListHeight) ? Parse.Float(hListHeight) : 40);
                break;
            }

            componentType.component.gameObject.GetComponent <LayoutElement>().preferredHeight = (componentType.component.gameObject.transform as RectTransform).sizeDelta.y;
            componentType.component.gameObject.GetComponent <LayoutElement>().preferredWidth  = (componentType.component.gameObject.transform as RectTransform).sizeDelta.x;

            tableData.tableView.gameObject.SetActive(true);
            tableData.tableView.LazyInit();

            if (componentType.data.TryGetValue("id", out string id))
            {
                TableViewScroller scroller = tableData.tableView.GetField <TableViewScroller, TableView>("scroller");
                parserParams.AddEvent(id + "#PageUp", scroller.PageScrollUp);
                parserParams.AddEvent(id + "#PageDown", scroller.PageScrollDown);
            }
        }