using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using GOLDEngine; namespace FSO.Client.UI.Framework.Parser { public class UIGroup : UINode { public UINode SharedProperties { get; set; } public List Children { get; set; } public static UIGroup FromReduction(GOLDEngine.Reduction r, Dictionary dataMap) { UIGroup result = new UIGroup(); // ::= BeginLiteral EndLiteral var content = (List)dataMap[r[1]]; var sharedProps = content.FirstOrDefault(x => x.Name == "SetSharedProperties"); result.SharedProperties = sharedProps; result.Children = content.Where(x => x != sharedProps).ToList(); return result; } } public class UISharedProperties { public static UISharedProperties FromReduction(GOLDEngine.Reduction r) { UISharedProperties result = new UISharedProperties(); return result; } } public class UINode { public string Name { get; set; } public string ID { get; set; } public Dictionary Attributes { get; internal set; } public UINode() { Attributes = new Dictionary(); } public Vector2 GetVector2(string name) { var att = Attributes[name]; if (att != null) { /** Remove ( ) **/ att = att.Substring(1, att.Length - 2); var parts = att.Split(new char[] { ',' }); return new Vector2(float.Parse(parts[0]), float.Parse(parts[1])); } return Vector2.Zero; } public Color GetColor(string name) { var att = Attributes[name]; if (att != null) { return UIScript.ParseRGB(att); } return default(Color); } public Point GetPoint(string name) { var att = Attributes[name]; if (att != null) { /** Remove ( ) **/ att = att.Substring(1, att.Length - 2); var parts = att.Split(new char[] { ',' }); return new Point(int.Parse(parts[0]), int.Parse(parts[1])); } return Point.Zero; } public void AddAtts(Dictionary attributes) { foreach (var att in attributes) { if (!Attributes.ContainsKey(att.Key)) { this[att.Key] = att.Value; } } } public string this[string name] { get { string result = null; Attributes.TryGetValue(name, out result); return result; } set { Attributes[name] = value; } } } }