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) { 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); } }
public void Setup() { if (BSMLParser.IsSingletonAvailable) { try { viewController = BeatSaberUI.CreateViewController <ViewController>(); SetupViewControllerTransform(viewController); parserParams = BSMLParser.instance.Parse(Utilities.GetResourceContent(assembly, resource), viewController.gameObject, host); didSetup = true; } catch (Exception ex) { if (ex is BSMLResourceException resEx) { Logger.log.Error($"Cannot find bsml resource '{resEx.ResourcePath}' in '{resEx.Assembly?.GetName().Name ?? "<NULL>"}' for settings menu."); } else { Logger.log.Error($"Error adding settings menu for {assembly?.GetName().Name ?? "<NULL>"} ({text}): {ex.Message}"); } Logger.log.Debug(ex); parserParams = BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), SETTINGS_ERROR_PATH), viewController.gameObject); } } }
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); }; } }
private async void Construct(SiraLog logger) { _logger = logger; ParserParams = await UIHelpers.ParseFromResourceAsync(_resourceName, gameObject, this); Init(); }
public virtual void Init(GameObject viewContainer) { if (_viewGameObject != null) { return; } _parserParams = UIUtilities.ParseBSML(ViewResource, viewContainer, this); _viewGameObject.name = ContainerGameObjectName; }
public BSMLParserParams Parse(XmlNode parentNode, GameObject parent, object host = null) { BSMLParserParams parserParams = new BSMLParserParams(); parserParams.host = host; if (host != null) { foreach (MethodInfo methodInfo in host.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { UIAction uiaction = methodInfo.GetCustomAttributes(typeof(UIAction), true).FirstOrDefault() as UIAction; if (uiaction != null) { parserParams.actions.Add(uiaction.id, new BSMLAction(host, methodInfo)); } } foreach (FieldInfo fieldInfo in host.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { UIValue uivalue = fieldInfo.GetCustomAttributes(typeof(UIValue), true).FirstOrDefault() as UIValue; if (uivalue != null) { parserParams.values.Add(uivalue.id, new BSMLFieldValue(host, fieldInfo)); } UIParams uiParams = fieldInfo.GetCustomAttributes(typeof(UIParams), true).FirstOrDefault() as UIParams; if (uiParams != null) { fieldInfo.SetValue(host, parserParams); } } foreach (PropertyInfo propertyInfo in host.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { UIValue uivalue = propertyInfo.GetCustomAttributes(typeof(UIValue), true).FirstOrDefault() as UIValue; if (uivalue != null) { parserParams.values.Add(uivalue.id, new BSMLPropertyValue(host, propertyInfo)); } } } foreach (XmlNode node in parentNode.ChildNodes) { HandleNode(node, parent, parserParams); } foreach (KeyValuePair <string, BSMLAction> action in parserParams.actions.Where(x => x.Key.StartsWith(SUBSCRIVE_EVENT_ACTION_PREFIX))) { parserParams.AddEvent(action.Key.Substring(1), delegate { action.Value.Invoke(); }); } parserParams.EmitEvent("post-parse"); return(parserParams); }
public void HandleNode(XmlNode node, GameObject parent, BSMLParserParams parserParams, out IEnumerable <ComponentTypeWithData> componentInfo) { if (node.Name.StartsWith(MACRO_PREFIX)) { HandleMacroNode(node, parent, parserParams, out componentInfo); } else { HandleTagNode(node, parent, parserParams, out componentInfo); } }
public void HandleNode(XmlNode node, GameObject parent, BSMLParserParams parserParams) { if (node.Name.StartsWith(MACRO_PREFIX)) { HandleMacroNode(node, parent, parserParams); } else { HandleTagNode(node, parent, parserParams); } }
private void HandleMacroNode(XmlNode node, GameObject parent, BSMLParserParams parserParams) { if (!macros.TryGetValue(node.Name, out BSMLMacro currentMacro)) { throw new Exception("Macro type '" + node.Name + "' not found"); } Dictionary <string, string> properties = GetParameters(node, currentMacro.CachedProps, parserParams, out _); currentMacro.Execute(node, parent, properties, parserParams); }
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); }
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); } }
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); } }
public virtual void Init(GameObject viewContainer) { if (_viewGameObject != null) { return; } if (!string.IsNullOrEmpty(ViewResource) && !string.IsNullOrEmpty(ContainerGameObjectName)) { _parserParams = UIUtilities.ParseBSML(ViewResource, viewContainer, this); _viewGameObject.name = ContainerGameObjectName; } else { Logger.log.Warn("FilterBase could not initialize filter view (ViewResource or ContainerGameObjectName are null or empty). Is this intentional?"); } }
public async Task Open(bool notify = true) { if (_firstActivation) { ParserParams = await UIHelpers.ParseFromResourceAsync(_resourceName, gameObject, this); gameObject.SetActive(false); _firstActivation = false; Init(); } gameObject.SetActive(true); if (notify) { DidOpen(); } }
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); } }
public override void Execute(XmlNode node, GameObject parent, Dictionary <string, string> data, BSMLParserParams parserParams) { if (data.TryGetValue("hosts", out string hosts)) { if (!parserParams.values.TryGetValue(hosts, out BSMLValue values)) { throw new Exception("host list '" + hosts + "' not found"); } bool passTags = false; if (data.TryGetValue("passTags", out string passTagsString)) { passTags = Parse.Bool(passTagsString); } foreach (object host in values.GetValue() as List <object> ) { BSMLParserParams nodeParams = BSMLParser.instance.Parse(node, parent, host); if (passTags) { nodeParams.PassTaggedObjects(parserParams); } } } }
public async Task Open(bool notify = true) { if (_firstActivation) { ParserParams = await _bsmlDecorator.ParseFromResourceAsync(_resourceName, gameObject, this); gameObject.SetActive(false); _firstActivation = false; foreach (var obj in ParserParams.GetObjectsWithTag("canvas")) { var newParent = obj.transform.parent.CreateGameObject("CanvasContainer"); newParent.AddComponent <RectTransform>(); newParent.AddComponent <VerticalLayoutGroup>(); newParent.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize; newParent.AddComponent <LayoutElement>(); newParent.AddComponent <Canvas>(); var canvasScaler = newParent.AddComponent <CanvasScaler>(); canvasScaler.referencePixelsPerUnit = 10; canvasScaler.scaleFactor = 3.44f; newParent.AddComponent <CurvedCanvasSettings>(); UIHelpers.AddVrRaycaster(newParent, _raycasterWithCache); obj.transform.SetParent(newParent.transform, false); } await Init(); } gameObject.SetActive(true); if (notify) { DidOpen(); } }
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) { 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) { 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); } }
private Dictionary <string, string> GetParameters(XmlNode node, Dictionary <string, string[]> properties, BSMLParserParams parserParams, out Dictionary <string, BSMLPropertyValue> propertyMap) { Dictionary <string, string> parameters = new Dictionary <string, string>(); bool isNotifyHost = typeof(INotifiableHost).IsAssignableFrom(parserParams.host.GetType()); propertyMap = null; if (isNotifyHost) { propertyMap = new Dictionary <string, BSMLPropertyValue>(); } foreach (KeyValuePair <string, string[]> propertyAliases in properties) { List <string> aliasList = new List <string>(propertyAliases.Value); if (!aliasList.Contains(propertyAliases.Key)) { aliasList.Add(propertyAliases.Key); } foreach (string alias in aliasList) { if (node.Attributes[alias] != null) { string value = node.Attributes[alias].Value; if (value.StartsWith(RETRIEVE_VALUE_PREFIX)) { string valueID = value.Substring(1); if (!parserParams.values.TryGetValue(valueID, out BSMLValue uiValue)) { throw new Exception("No UIValue exists with the id '" + valueID + "'"); } parameters.Add(propertyAliases.Key, uiValue.GetValue()?.ToString()); if (isNotifyHost && uiValue is BSMLPropertyValue propVal) { if (propVal != null) { propertyMap.Add(propertyAliases.Key, propVal); } else { Logger.log?.Warn($"PropertyValue is null for {propertyAliases.Key}"); } } } else { parameters.Add(propertyAliases.Key, value); } break; } if (alias == "_children") { parameters.Add(propertyAliases.Key, node.InnerXml); } } } return(parameters); }
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); } }
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); } }
public virtual void HandleTypeAfterParse(ComponentTypeWithData componentType, BSMLParserParams parserParams) { }
public abstract void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams);