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);
            }
        }
示例#2
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            base.HandleType(componentType, parserParams);
            ClickableImage clickableImage = componentType.component as ClickableImage;

            if (componentType.data.TryGetValue("onClick", out string onClick))
            {
                clickableImage.OnClickEvent += delegate
                {
                    if (!parserParams.actions.TryGetValue(onClick, out BSMLAction onClickAction))
                    {
                        throw new Exception("on-click action '" + onClick + "' not found");
                    }

                    onClickAction.Invoke();
                };
            }

            if (componentType.data.TryGetValue("clickEvent", out string clickEvent))
            {
                clickableImage.OnClickEvent += delegate
                {
                    parserParams.EmitEvent(clickEvent);
                };
            }
        }
示例#3
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            SliderSetting sliderSetting = componentType.component as SliderSetting;

            if (componentType.data.TryGetValue("isInt", out string isInt))
            {
                sliderSetting.isInt = Parse.Bool(isInt);
            }

            if (componentType.data.TryGetValue("increment", out string increment))
            {
                sliderSetting.increments = Parse.Float(increment);
            }

            if (componentType.data.TryGetValue("minValue", out string minValue))
            {
                sliderSetting.slider.minValue = Parse.Float(minValue);
            }

            if (componentType.data.TryGetValue("maxValue", out string maxValue))
            {
                sliderSetting.slider.maxValue = Parse.Float(maxValue);
            }

            if (componentType.data.TryGetValue("showButtons", out string showButtons))
            {
                sliderSetting.showButtons = Parse.Bool(showButtons);
            }
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            base.HandleType(componentType, parserParams);
            TabSelector tabSelector = (componentType.component as TabSelector);

            tabSelector.parserParams = parserParams;
            if (!componentType.data.TryGetValue("tabTag", out string tabTag))
            {
                throw new Exception("Tab Selector must have a tab-tag");
            }
            tabSelector.tabTag = tabTag;
            parserParams.AddEvent("post-parse", tabSelector.Setup);
        }
示例#5
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            try
            {
                ModalColorPicker colorPicker = componentType.component as ModalColorPicker;
                if (componentType.data.TryGetValue("value", out string value))
                {
                    if (!parserParams.values.TryGetValue(value, out BSMLValue associatedValue))
                    {
                        throw new Exception("value '" + value + "' not found");
                    }

                    colorPicker.associatedValue = associatedValue;
                }

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

                    colorPicker.onCancel = action;
                }

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

                    colorPicker.onDone = action;
                }

                if (componentType.data.TryGetValue("onChange", out string onChange))
                {
                    if (!parserParams.actions.TryGetValue(onChange, out BSMLAction action))
                    {
                        throw new Exception("color-change action '" + onChange + "' not found");
                    }

                    colorPicker.onChange = action;
                }
            }
            catch (Exception ex)
            {
                Logger.log?.Error(ex);
            }
        }
示例#6
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            LayoutGroup layoutGroup = (componentType.component as LayoutGroup);

            if (componentType.data.TryGetValue("pad", out string pad))
            {
                int padding = Parse.Int(pad);
                layoutGroup.padding = new RectOffset(padding, padding, padding, padding);
            }

            layoutGroup.padding = new RectOffset(componentType.data.TryGetValue("padLeft", out string padLeft) ? Parse.Int(padLeft) : layoutGroup.padding.left, componentType.data.TryGetValue("padRight", out string padRight) ? Parse.Int(padRight) : layoutGroup.padding.right, componentType.data.TryGetValue("padTop", out string padTop) ? Parse.Int(padTop) : layoutGroup.padding.top, componentType.data.TryGetValue("padBottom", out string padBottom) ? Parse.Int(padBottom) : layoutGroup.padding.bottom);
            if (componentType.data.TryGetValue("childAlign", out string childAlign))
            {
                layoutGroup.childAlignment = (TextAnchor)Enum.Parse(typeof(TextAnchor), childAlign);
            }
        }
示例#7
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            GenericSetting genericSetting = componentType.component as GenericSetting;

            if (componentType.data.TryGetValue("formatter", out string formatterId))
            {
                if (!parserParams.actions.TryGetValue(formatterId, out BSMLAction formatter))
                {
                    throw new Exception("formatter action '" + formatter + "' not found");
                }

                genericSetting.formatter = formatter;
            }

            if (componentType.data.TryGetValue("applyOnChange", out string applyOnChange))
            {
                genericSetting.updateOnChange = Parse.Bool(applyOnChange);
            }

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

                genericSetting.onChange = onChangeAction;
            }

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

                genericSetting.associatedValue = associatedValue;
                if (componentType.data.TryGetValue("bindValue", out string bindValue) && Parse.Bool(bindValue))
                {
                    BindValue(componentType, parserParams, associatedValue, _ => genericSetting.ReceiveValue());
                }
            }

            parserParams.AddEvent(componentType.data.TryGetValue("setEvent", out string setEvent) ? setEvent : "apply", genericSetting.ApplyValue);
            parserParams.AddEvent(componentType.data.TryGetValue("getEvent", out string getEvent) ? getEvent : "cancel", genericSetting.ReceiveValue);
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            DropDownListSetting listSetting = componentType.component as DropDownListSetting;

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

                listSetting.values = values.GetValue() as List <object>;
            }
            else
            {
                throw new Exception("list must have associated options");
            }
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            try
            {
                Button button = componentType.component as Button;

                if (componentType.data.TryGetValue("onClick", out string onClick))
                {
                    button.onClick.AddListener(delegate
                    {
                        if (!parserParams.actions.TryGetValue(onClick, out BSMLAction onClickAction))
                        {
                            throw new Exception("on-click action '" + onClick + "' not found");
                        }

                        onClickAction.Invoke();
                    });
                }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            try
            {
                ModalView modalView      = componentType.component as ModalView;
                Transform originalParent = modalView.transform.parent;
                bool      moveToCenter   = true;
                if (componentType.data.TryGetValue("moveToCenter", out string moveToCenterString))
                {
                    moveToCenter = bool.Parse(moveToCenterString);
                }

                if (componentType.data.TryGetValue("showEvent", out string showEvent))
                {
                    parserParams.AddEvent(showEvent, delegate
                    {
                        modalView.Show(true, moveToCenter);
                    });
                }

                if (componentType.data.TryGetValue("hideEvent", out string hideEvent))
                {
                    parserParams.AddEvent(hideEvent, delegate
                    {
                        modalView.Hide(true, () => modalView.transform.SetParent(originalParent, true));
                    });
                }

                if (componentType.data.TryGetValue("clickOffCloses", out string clickOffCloses) && Parse.Bool(clickOffCloses))
                {
                    modalView._blockerClickedEvent += delegate
                    {
                        modalView.Hide(true, () => modalView.transform.SetParent(originalParent, true));
                    };
                }
            }
            catch (Exception ex)
            {
                Logger.log?.Error(ex);
            }
        }
示例#11
0
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            IncrementSetting incrementSetting = componentType.component as IncrementSetting;

            if (componentType.data.TryGetValue("isInt", out string isInt))
            {
                incrementSetting.isInt = Parse.Bool(isInt);
            }

            if (componentType.data.TryGetValue("increment", out string increment))
            {
                incrementSetting.increments = Parse.Float(increment);
            }

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

            if (componentType.data.TryGetValue("maxValue", out string maxValue))
            {
                incrementSetting.maxValue = Parse.Float(maxValue);
            }
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            TextSegmentedControl textControl = componentType.component as TextSegmentedControl;

            if (componentType.data.TryGetValue("data", out string value))
            {
                if (!parserParams.values.TryGetValue(value, out BSMLValue contents))
                {
                    throw new Exception("value '" + value + "' not found");
                }
                textControl.SetTexts((contents.GetValue() as IEnumerable).Cast <object>().Select(x => x.ToString()).ToArray());
            }

            if (componentType.data.TryGetValue("selectCell", out string selectCell))
            {
                textControl.didSelectCellEvent += (SegmentedControl control, int index) => {
                    if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action))
                    {
                        throw new Exception("select-cell action '" + componentType.data["selectCell"] + "' not found");
                    }
                    action.Invoke(control, index);
                };
            }
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            IconSegmentedControl iconControl = componentType.component as IconSegmentedControl;

            if (componentType.data.TryGetValue("data", out string value))
            {
                if (!parserParams.values.TryGetValue(value, out BSMLValue contents))
                {
                    throw new Exception("value '" + value + "' not found");
                }
                iconControl.SetData((contents.GetValue() as List <IconSegmentedControl.DataItem>).ToArray());
            }

            if (componentType.data.TryGetValue("selectCell", out string selectCell))
            {
                iconControl.didSelectCellEvent += (SegmentedControl control, int index) => {
                    if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action))
                    {
                        throw new Exception("select-cell action '" + componentType.data["selectCell"] + "' not found");
                    }
                    action.Invoke(control, index);
                };
            }
        }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            CustomCellListTableData tableData = componentType.component as CustomCellListTableData;

            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["selectCell"] + "' not found");
                    }

                    action.Invoke(table, (table.dataSource as CustomCellListTableData).data[index]);
                };
            }

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

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

            if (componentType.data.TryGetValue("cellTemplate", out string cellTemplate))
            {
                tableData.cellTemplate = "<bg>" + cellTemplate + "</bg>";
            }

            if (componentType.data.TryGetValue("cellClickable", out string cellClickable))
            {
                tableData.clickableCells = Parse.Bool(cellClickable);
            }

            if (componentType.data.TryGetValue("alignCenter", out string alignCenter))
            {
                tableData.tableView.SetField <TableView, bool>("_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 <object>;
                tableData.tableView.ReloadData();
            }

            switch (tableData.tableView.tableType)
            {
            case 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 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))
            {
                ScrollView scroller = tableData.tableView.GetField <ScrollView, TableView>("_scrollView");
                parserParams.AddEvent(id + "#PageUp", scroller.PageUpButtonPressed);
                parserParams.AddEvent(id + "#PageDown", scroller.PageDownButtonPressed);
            }
        }
示例#15
0
        private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams parserParams)
        {
            if (!tags.TryGetValue(node.Name, out BSMLTag currentTag))
            {
                throw new Exception("Tag type '" + node.Name + "' not found");
            }

            //TEMPORARY
            if (node.Name == "image")
            {
                for (int i = 0; i < 100; i++)
                {
                    Logger.log.Critical("do not use image tag for raw images please switch to raw-image");
                }
            }
            //

            GameObject currentNode = currentTag.CreateObject(parent.transform);

            List <ComponentTypeWithData> componentTypes = new List <ComponentTypeWithData>();

            foreach (TypeHandler typeHandler in typeHandlers)
            {
                Type      type      = (typeHandler.GetType().GetCustomAttributes(typeof(ComponentHandler), true).FirstOrDefault() as ComponentHandler).type;
                Component component = GetExternalComponent(currentNode, type);
                if (component != null)
                {
                    ComponentTypeWithData componentType = new ComponentTypeWithData();
                    componentType.data        = GetParameters(node, typeHandler.CachedProps, parserParams, out Dictionary <string, BSMLPropertyValue> propertyMap);
                    componentType.propertyMap = propertyMap;
                    componentType.typeHandler = typeHandler;
                    componentType.component   = component;
                    componentTypes.Add(componentType);
                }
            }
            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleType(componentType, parserParams);
            }

            object host = parserParams.host;

            if (host != null && node.Attributes["id"] != null)
            {
                foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    UIComponent uicomponent = fieldInfo.GetCustomAttributes(typeof(UIComponent), true).FirstOrDefault() as UIComponent;
                    if (uicomponent != null && uicomponent.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.FieldType));
                    }

                    UIObject uiobject = fieldInfo.GetCustomAttributes(typeof(UIObject), true).FirstOrDefault() as UIObject;
                    if (uiobject != null && uiobject.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, currentNode);
                    }
                }
            }
            if (node.Attributes["tags"] != null)
            {
                parserParams.AddObjectTags(currentNode, node.Attributes["tags"].Value.Split(','));
            }

            if (currentTag.AddChildren)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    HandleNode(childNode, currentNode, parserParams);
                }
            }

            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleTypeAfterChildren(componentType, parserParams);
            }
        }
示例#16
0
 public virtual void HandleTypeAfterParse(ComponentTypeWithData componentType, BSMLParserParams parserParams)
 {
 }
示例#17
0
 public abstract void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams);
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            CustomListTableData tableData  = componentType.component as CustomListTableData;
            ScrollView          scrollView = tableData.tableView.GetField <ScrollView, TableView>("_scrollView");

            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);
                };
            }

            bool verticalList = true;

            if (componentType.data.TryGetValue("listDirection", out string listDirection))
            {
                tableData.tableView.SetField <TableView, TableType>("_tableType", (TableType)Enum.Parse(typeof(TableType), listDirection));
                scrollViewDirectionField.SetValue(scrollView, Enum.Parse(scrollViewDirectionField.FieldType, listDirection));
                verticalList = listDirection.ToLower() != "horizontal";
            }

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

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

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

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

            if (componentType.data.TryGetValue("stickScrolling", out string stickScrolling))
            {
                if (Parse.Bool(stickScrolling))
                {
                    scrollView.SetField("_platformHelper", BeatSaberUI.PlatformHelper);
                }
            }

            // We can only show the scroll bar for vertical lists
            if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar))
            {
                if (Parse.Bool(showScrollbar))
                {
                    TextPageScrollView textScrollView = UnityEngine.Object.Instantiate(ScrollViewTag.ScrollViewTemplate, componentType.component.transform);

                    Button pageUpButton   = textScrollView.GetField <Button, ScrollView>("_pageUpButton");
                    Button pageDownButton = textScrollView.GetField <Button, ScrollView>("_pageDownButton");
                    VerticalScrollIndicator verticalScrollIndicator = textScrollView.GetField <VerticalScrollIndicator, ScrollView>("_verticalScrollIndicator");
                    RectTransform           scrollBar = verticalScrollIndicator.transform.parent as RectTransform;

                    scrollView.SetField("_pageUpButton", pageUpButton);
                    scrollView.SetField("_pageDownButton", pageDownButton);
                    scrollView.SetField("_verticalScrollIndicator", verticalScrollIndicator);
                    scrollBar.SetParent(componentType.component.transform);
                    GameObject.Destroy(textScrollView.gameObject);

                    // Need to adjust scroll bar positioning
                    scrollBar.anchorMin = new Vector2(1, 0);
                    scrollBar.anchorMax = Vector2.one;
                    scrollBar.offsetMin = Vector2.zero;
                    scrollBar.offsetMax = new Vector2(8, 0);
                }
            }

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


                var tableDataValue = contents.GetValue();
                if (!(tableDataValue is List <CustomCellInfo> tableDataList))
                {
                    throw new Exception($"Value '{value}' is not a List<CustomCellInfo>, which is required for custom-list");
                }

                tableData.data = tableDataList;
                tableData.tableView.ReloadData();
            }

            switch (tableData.tableView.tableType)
            {
            case 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 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))
            {
                parserParams.AddEvent(id + "#PageUp", scrollView.PageUpButtonPressed);
                parserParams.AddEvent(id + "#PageDown", scrollView.PageDownButtonPressed);
            }
        }
示例#19
0
 public override void HandleTypeAfterChildren(ComponentTypeWithData componentType, BSMLParserParams parserParams)
 {
     (componentType.component as GenericSetting).Setup();
 }
        public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams)
        {
            CustomCellListTableData tableData = componentType.component as CustomCellListTableData;

            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["selectCell"] + "' not found");
                    }

                    action.Invoke(table, (table.dataSource as CustomCellListTableData).data[index]);
                };
            }

            if (componentType.data.TryGetValue("listDirection", out string listDirection))
            {
                //temp
                FieldInfo fieldInfo = typeof(TableView).GetField("_tableType", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                fieldInfo.SetValue(tableData.tableView, (TableType)Enum.Parse(typeof(TableType), listDirection));
                //

                /*
                 * tableData.tableView.SetPrivateField("_tableType", (TableType)Enum.Parse(typeof(TableType), listDirection));
                 */
            }

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

            if (componentType.data.TryGetValue("cellTemplate", out string cellTemplate))
            {
                tableData.cellTemplate = "<bg>" + cellTemplate + "</bg>";
            }

            if (componentType.data.TryGetValue("cellClickable", out string cellClickable))
            {
                tableData.clickableCells = Parse.Bool(cellClickable);
            }

            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 <object>;
                tableData.tableView.ReloadData();
            }

            switch (tableData.tableView.tableType)
            {
            case 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));
                tableData.tableView.contentTransform.anchorMin = new Vector2(0, 1);
                break;

            case 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);

            if (componentType.data.TryGetValue("id", out string id))
            {
                //temp
                FieldInfo         fieldInfo = typeof(TableView).GetField("_scroller", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                TableViewScroller scroller  = fieldInfo.GetValue(tableData.tableView) as TableViewScroller;
                //

                /*
                 * TableViewScroller scroller = tableData.tableView.GetPrivateField<TableViewScroller>("_scroller");
                 */
                parserParams.AddEvent(id + "#PageUp", scroller.PageScrollUp);
                parserParams.AddEvent(id + "#PageDown", scroller.PageScrollDown);
            }
        }
示例#21
0
        private void HandleTagNode(XmlNode node, GameObject parent, BSMLParserParams parserParams, out IEnumerable <ComponentTypeWithData> componentInfo)
        {
            if (!tags.TryGetValue(node.Name, out BSMLTag currentTag))
            {
                throw new Exception("Tag type '" + node.Name + "' not found");
            }

            GameObject currentNode = currentTag.CreateObject(parent.transform);

            List <ComponentTypeWithData> componentTypes = new List <ComponentTypeWithData>();

            foreach (TypeHandler typeHandler in typeHandlers)
            {
                Type type = (typeHandler.GetType().GetCustomAttributes(typeof(ComponentHandler), true).FirstOrDefault() as ComponentHandler)?.type;
                if (type == null)
                {
                    continue;
                }
                Component component = GetExternalComponent(currentNode, type);
                if (component != null)
                {
                    ComponentTypeWithData componentType = new ComponentTypeWithData();
                    componentType.data        = GetParameters(node, typeHandler.CachedProps, parserParams, out Dictionary <string, BSMLValue> valueMap);
                    componentType.valueMap    = valueMap;
                    componentType.typeHandler = typeHandler;
                    componentType.component   = component;
                    componentTypes.Add(componentType);
                }
            }
            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleType(componentType, parserParams);
            }

            object host = parserParams.host;

            if (host != null && node.Attributes["id"] != null)
            {
                foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    UIComponent uicomponent = fieldInfo.GetCustomAttributes(typeof(UIComponent), true).FirstOrDefault() as UIComponent;
                    if (uicomponent != null && uicomponent.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, GetExternalComponent(currentNode, fieldInfo.FieldType));
                    }

                    UIObject uiobject = fieldInfo.GetCustomAttributes(typeof(UIObject), true).FirstOrDefault() as UIObject;
                    if (uiobject != null && uiobject.id == node.Attributes["id"].Value)
                    {
                        fieldInfo.SetValue(host, currentNode);
                    }
                }
            }
            if (node.Attributes["tags"] != null)
            {
                parserParams.AddObjectTags(currentNode, node.Attributes["tags"].Value.Split(','));
            }

            IEnumerable <ComponentTypeWithData> childrenComponents = Enumerable.Empty <ComponentTypeWithData>();

            if (currentTag.AddChildren)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    HandleNode(childNode, currentNode, parserParams, out IEnumerable <ComponentTypeWithData> children);
                    childrenComponents = childrenComponents.Concat(children);
                }
            }

            foreach (ComponentTypeWithData componentType in componentTypes)
            {
                componentType.typeHandler.HandleTypeAfterChildren(componentType, parserParams);
            }

            componentInfo = componentTypes.Concat(childrenComponents);
        }