public static void LoadLayout(Stream stream, IHUD hud, int screenWidth, int screenHeight) { HUDLayout layout = (HUDLayout)Serializers.XmlDeserialize(stream, typeof(HUDLayout)); foreach (HUDComponent clayout in layout.Components) { Dictionary <string, string> data = new Dictionary <string, string>(clayout.Data.Count); foreach (string dataItem in clayout.Data.FindAll(di => !string.IsNullOrEmpty(di))) { string[] tokens = dataItem.Split('='); if (!data.ContainsKey(tokens[0])) { data.Add(tokens[0], tokens[1]); } } // parse the element // if the element doesn't exist quit right here if (!_mapping.ContainsKey(clayout.Id)) { // error, id not found System.Diagnostics.Trace.TraceWarning("No IHUDComponent found with id {0}! Ignoring this entry.", clayout.Id); continue; } // create this hud component and add it IHUDComponent component = (IHUDComponent)Activator.CreateInstance(_mapping[clayout.Id], false); component.X = GetAbsX(screenWidth, clayout.X); component.Y = GetAbsY(screenHeight, clayout.Y); component.Enabled = true; component.Visible = clayout.Visible; component.OnLoadLayout(data); hud.AddComponent(component); } }
public void AddComponent(IHUDComponent comp) { if (!HUDComponents.Contains(comp)) { HUDComponents.Add(comp); } }
public void OnResize(int width, int height) { bool dimensionsChanged = false; if (width != this.Width) { dimensionsChanged = true; Width = width; } if (height != this.Height) { dimensionsChanged = true; Height = height; } if (dimensionsChanged) { // update from lowest order to highest for (int i = 0; i < _components.Count; i++) { IHUDComponent c = _components[i]; c.OnResize(width, height); } } }
public void RemoveComponent(IHUDComponent component) { if (_components.Contains(component)) { _components.Remove(component); component.OnDetach(); } }
public void OnKeyUp(KeyboardKeyEventArgs e) { // update from lowest order to highest for (int i = 0; i < _components.Count; i++) { IHUDComponent c = _components[i]; c.OnKeyUp(e); } }
public void AddComponent(IHUDComponent component) { if (!_components.Contains(component)) { _components.Add(component); // sort the components via their Orders _components.Sort(CompareComponentOrder); // then attach it component.OnAttach(this); } }
private int CompareComponentOrder(IHUDComponent left, IHUDComponent right) { if (left.Order < right.Order) { return(left.Order - right.Order); } if (left.Order == right.Order) { return(0); } if (left.Order > right.Order) { return(left.Order - right.Order); } return(0); }
public void Render() { if (!Enabled || !Visible || !_isInitialized) { return; } // render from lowest order to highest for (int i = 0; i < _components.Count; i++) { IHUDComponent c = _components[i]; if (c.Visible) { c.Render(); } } }
public void Update(double delta) { if (!_isInitialized) { this.Initialize(); _isInitialized = true; } if (!Enabled) { return; } // update from lowest order to highest for (int i = 0; i < _components.Count; i++) { IHUDComponent c = _components[i]; if (c.Enabled) { c.Update(delta); } } }
public void RemoveComponent(IHUDComponent comp) { HUDComponents.Remove(comp); }
public void AddComponent(String name, IHUDComponent component) { components.Add(name, component); }
private int CompareComponentOrder(IHUDComponent left, IHUDComponent right) { if (left.Order < right.Order) { return left.Order - right.Order; } if (left.Order == right.Order) { return 0; } if (left.Order > right.Order) { return left.Order - right.Order; } return 0; }