public ScreenBase(string name) { string _dataString = File.ReadAllText($@"Screens\Data\{name}.json"); try { Data = new ScreenData(JObject.Parse(_dataString)); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error parsing JSON:\r\n\r\n" + ex.Message); throw ex; } try { BackgroundTex = GContent.Load <Texture2D>(Data.Background); } catch { // Load color instead? } Menus = new List <MenuBase>(); if (Data.Menus != null) { foreach (var _mData in Data.Menus) { Menus.Add(GMenus.Create(_mData, null)); } } }
public MenuBase(MenuData data, MenuBase parent) { Parent = parent; Data = data; Name = Data.Name; Type = Data.Type; Text = Data.Text; if (!string.IsNullOrWhiteSpace(Data.Position)) { Position = Vec2FromString(Data.Position); } if (!string.IsNullOrWhiteSpace(Data.Size)) { Size = Vec2FromString(Data.Size); } if (!string.IsNullOrWhiteSpace(Data.Depth)) { Depth = float.Parse(Data.Depth); } else { Depth = 0.99f; } if (!string.IsNullOrWhiteSpace(Data.Align)) { string[] _alignSplit = Data.Align.Split(','); foreach (var _ha in Enum.GetValues(typeof(MenuHAlign))) { if (_alignSplit[0].Trim().ToLower() == _ha.ToString().ToLower()) { HAlign = (MenuHAlign)_ha; } } foreach (var _va in Enum.GetValues(typeof(MenuVAlign))) { if (_alignSplit[1].Trim().ToLower() == _va.ToString().ToLower()) { VAlign = (MenuVAlign)_va; } } } else { HAlign = MenuHAlign.Left; VAlign = MenuVAlign.Top; } if (!string.IsNullOrWhiteSpace(Data.TextAlign)) { string[] _alignSplit = Data.TextAlign.Split(','); foreach (var _ha in Enum.GetValues(typeof(MenuHAlign))) { if (_alignSplit[0].Trim().ToLower() == _ha.ToString().ToLower()) { TextHAlign = (MenuHAlign)_ha; } } foreach (var _va in Enum.GetValues(typeof(MenuVAlign))) { if (_alignSplit[1].Trim().ToLower() == _va.ToString().ToLower()) { TextVAlign = (MenuVAlign)_va; } } } else { TextHAlign = MenuHAlign.Center; TextVAlign = MenuVAlign.Middle; } if ((Data.ShowText ?? "").ToLower() == "yes") { ShowText = true; } if (!string.IsNullOrWhiteSpace(Data.Bgc)) { Bgc = ColorFromString(Data.Bgc); } else { Bgc = null; } if (!string.IsNullOrWhiteSpace(Data.HoverBgc)) { HoverBgc = ColorFromString(Data.HoverBgc); } else { HoverBgc = null; } if (!string.IsNullOrWhiteSpace(Data.FocusBgc)) { FocusBgc = ColorFromString(Data.FocusBgc); } else { FocusBgc = null; } if (!string.IsNullOrWhiteSpace(Data.FocusHoverBgc)) { FocusHoverBgc = ColorFromString(Data.FocusHoverBgc); } else { FocusHoverBgc = null; } if (!string.IsNullOrWhiteSpace(Data.BorderColor)) { BorderColor = ColorFromString(Data.BorderColor); } else { BorderColor = null; } BorderThickness = 1; int.TryParse(Data.BorderThickness, out BorderThickness); if ((Data.ShowType ?? "").ToLower() == "yes") { ShowType = true; } Items = new List <MenuBase>(); if (Data.Items != null && Data.Items.Count > 0) { foreach (var _itemData in Data.Items) { var _sItem = GMenus.Create(_itemData, this); Items.Add(_sItem); } } }