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); } }
private void SetSeparator(TabSelector tabSelector, string hasSeparator) { //temp FieldInfo fieldInfo = typeof(SegmentedControl).GetField("_separatorPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); fieldInfo.SetValue(tabSelector.textSegmentedControl, Parse.Bool(hasSeparator) ? fieldInfo.GetValue(Resources.FindObjectsOfTypeAll <TextSegmentedControl>().First(x => fieldInfo.GetValue(x) != null)) : null); // }
/// <summary> /// Helper method which sets all the properties in the class to their respected FlashObject field. /// Use InternalNameAttribute to specify a property which has a FlashObject counter-part. /// SetFields does not travel the hierarchy. So Derived types must make their own separate call to SetFields. /// </summary> /// <param name="obj">Object to change properties</param> /// <param name="flash">Flash object to get fields from</param> public static void SetFields <T>(T obj, FlashObject flash) { if (flash == null) { return; } foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var intern = prop.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault() as InternalNameAttribute; if (intern == null) { continue; } object value; var type = prop.PropertyType; try { if (type == typeof(string)) { value = flash[intern.Name].Value; } else if (type == typeof(int)) { value = Parse.Int(flash[intern.Name].Value); } else if (type == typeof(long)) { value = Parse.Long(flash[intern.Name].Value); } else if (type == typeof(bool)) { value = Parse.Bool(flash[intern.Name].Value); } else { try { value = Activator.CreateInstance(type, flash[intern.Name]); } catch (Exception e) { throw new NotSupportedException(string.Format("Type {0} not supported by flash serializer", type.FullName), e); } } prop.SetValue(obj, value, null); } catch (Exception e) { StaticLogger.Error(string.Format("Error parsing {0}#{1}", typeof(T).FullName, prop.Name)); StaticLogger.Error(e); } } }
private static FontStyles SetStyle(FontStyles existing, FontStyles modifyStyle, string flag) { if (Parse.Bool(flag)) { return(existing |= modifyStyle); } else { return(existing &= ~modifyStyle); } }
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 async Task <List <Application> > GetApplications() { var result = new List <Application>(); Logger.Trace("BEGIN | Matrix.Server.Registry.Database.ApplicationRepository.GetApplications"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = await connection.QueryAsync <dynamic>("SELECT [Id], [Enabled], [Name], [Description], [Created], [Updated], [Deleted] FROM [Applications] WHERE [Deleted] = @deleted", new { @deleted = false }); foreach (var i in entity) { var o = new Application(); o.Id = Parse.Guid(i.Id); o.Enabled = Parse.Bool(i.Enabled); o.Name = i.Name; o.Description = i.Description; o.Created = Parse.DateTime(i.Created); o.Updated = Parse.DateTime(i.Updated); o.Deleted = Parse.Bool(i.Deleted); result.Add(o); } connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Registry.Database.ApplicationRepository.GetApplications"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Registry.Database.ApplicationRepository.GetApplications"); return(result); }
public async Task <List <Model.KeyValuePair> > GetSettings(Guid application) { var result = new List <Model.KeyValuePair>(); Logger.Trace("BEGIN | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = await connection.QueryAsync <dynamic>("SELECT [Id], [Application], [Enabled], [Key], [Value], [Created], [Updated] FROM [Configuration] WHERE [Application] = @application AND [Deleted] = @deleted", new { @application = application, @deleted = false }); foreach (var i in entity) { var o = new Model.KeyValuePair(); o.Id = Parse.Guid(i.Id); o.Application = Parse.Guid(i.Id); o.Enabled = Parse.Bool(i.Enabled); o.Key = i.Key; o.Value = i.Value; o.Created = Parse.DateTime(i.Created); o.Updated = Parse.DateTime(i.Updated); result.Add(o); } connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); return(result); }
public async Task <Model.KeyValuePair> GetSettings(Guid application, string key) { var result = new Model.KeyValuePair(); Logger.Trace("BEGIN | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = (await connection.QueryAsync <dynamic>("SELECT [Id], [Application], [Enabled], [Key], [Value], [Created], [Updated] FROM [Configuration] WHERE [Application] = @application AND [Key] = @key AND [Deleted] = @deleted", new { @application = application, @key = key, @deleted = false }))?.FirstOrDefault(); if (entity != null) { result.Id = Parse.Guid(entity.Id); result.Application = Parse.Guid(entity.Id); result.Enabled = Parse.Bool(entity.Enabled); result.Key = entity.Key; result.Value = entity.Value; result.Created = Parse.DateTime(entity.Created); result.Updated = Parse.DateTime(entity.Updated); } connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Configurator.Database.ConfigurationRepository.GetSettings"); return(result); }
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 override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams) { ListSliderSetting listSetting = componentType.component as ListSliderSetting; 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"); } if (componentType.data.TryGetValue("showButtons", out string showButtons)) { listSetting.showButtons = Parse.Bool(showButtons); } }
public async Task <Application> GetApplicationById(Guid id) { var result = new Application(); Logger.Trace("BEGIN | Matrix.Server.Registry.Database.ApplicationRepository.GetApplicationById"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = await connection.QueryFirstOrDefaultAsync <dynamic>("SELECT [Id], [Enabled], [Name], [Description], [Created], [Updated], [Deleted] FROM [Applications] WHERE [Id] = @id AND [Deleted] = @deleted", new { @id = id, @deleted = false }); result.Id = Parse.Guid(entity.Id); result.Enabled = Parse.Bool(entity.Enabled); result.Name = entity.Name; result.Description = entity.Description; result.Created = Parse.DateTime(entity.Created); result.Updated = Parse.DateTime(entity.Updated); result.Deleted = Parse.Bool(entity.Deleted); connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Registry.Database.ApplicationRepository.GetApplicationById"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Registry.Database.ApplicationRepository.GetApplicationById"); return(result); }
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(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 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); } }
public async Task <List <Email> > GetEmailByStatus(Guid application, int status) { var result = new List <Email>(); Logger.Trace("BEGIN | Matrix.Server.Postman.Database.EmailRepository.GetEmailByStatus"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = await connection.QueryAsync <dynamic>("SELECT [Id], [Application], [From], [Subject], [Body], [HTML], [Status] FROM [Emails] WHERE [Application] = @Application AND [Status] = @status AND [Deleted] = @deleted", new { application, status, @deleted = false }); if (entity != null) { foreach (var i in entity) { var o = new Email() { Id = Parse.Guid(i.Id), Application = Parse.Guid(i.Application), From = i.From, Subject = i.Subject, Body = i.Body, HTML = Parse.Bool(i.HTML), Status = Parse.Integer(i.Status) }; dynamic list = await connection.QueryAsync <dynamic>("SELECT [Address], [Blind], [Copy] FROM [EmailAddress] WHERE [EmailId] = @id AND [Deleted] = @deleted", new { o.Id, @deleted = false }); if (list != null) { foreach (var x in list) { var address = x.Address; var copy = Parse.Bool(x.Copy); var blind = Parse.Bool(x.Blind); if (!copy && !blind) { i.To.Add(address); } else { if (copy) { i.Cc.Add(address); } if (blind) { i.Bcc.Add(address); } } } } result.Add(o); } } connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Postman.Database.EmailRepository.GetEmailByStatus"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Postman.Database.EmailRepository.GetEmailByStatus"); return(result); }
public async Task <Email> GetEmailById(Guid id) { Email result = null; Logger.Trace("BEGIN | Matrix.Server.Postman.Database.EmailRepository.GetEmailById"); DbConnection connection = null; try { using (connection = GetDbConnection()) { await connection.OpenAsync(); dynamic entity = await connection.QueryFirstOrDefaultAsync <dynamic>("SELECT [Id], [Application], [From], [Subject], [Body], [HTML], [Status] FROM [Emails] WHERE [Id] = @id AND [Deleted] = @deleted", new { id, @deleted = false }); if (entity != null) { result = new Email() { Id = Parse.Guid(entity.Id), Application = Parse.Guid(entity.Application), From = entity.From, Subject = entity.Subject, Body = entity.Body, HTML = Parse.Bool(entity.HTML), Status = Parse.Integer(entity.Status) }; dynamic list = await connection.QueryAsync <dynamic>("SELECT [Address], [Blind], [Copy] FROM [EmailAddress] WHERE [EmailId] = @id AND [Deleted] = @deleted", new { id, @deleted = false }); if (list != null) { foreach (var i in list) { var address = i.Address; var copy = Parse.Bool(i.Copy); var blind = Parse.Bool(i.Blind); if (!copy && !blind) { result.To.Add(address); } else { if (copy) { result.Cc.Add(address); } if (blind) { result.Bcc.Add(address); } } } } } connection.Close(); } } catch (Exception e) { Logger.Trace("ERROR | Matrix.Server.Postman.Database.EmailRepository.GetEmailById"); Logger.Error(e); } Logger.Trace("END | Matrix.Server.Postman.Database.EmailRepository.GetEmailById"); return(result); }
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); } }
public static void SetInteractable(GenericInteractableSetting interactable, string flag) { interactable.interactable = Parse.Bool(flag); }
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 static void SetInteractable(Selectable selectable, string flag) { selectable.interactable = Parse.Bool(flag); }
private void SetSeparator(TabSelector tabSelector, string hasSeparator) { tabSelector.textSegmentedControl.SetField <SegmentedControl, Transform>("_separatorPrefab", Parse.Bool(hasSeparator) ? (Resources.FindObjectsOfTypeAll <TextSegmentedControl>().First(x => x.GetField <Transform, SegmentedControl> ("_separatorPrefab") != null).GetField <Transform, SegmentedControl>("_separatorPrefab")) : null); }
public static bool ToBool(string data) { return(Parse.Bool(data)); }
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); } }
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); } }
public void TestParseBool(string sval, bool defaultVal, bool result) { Assert.AreEqual(result, Parse.Bool(sval, defaultVal)); }