Example #1
0
        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);
            }
        }
Example #2
0
 public void AddComponent(IHUDComponent comp)
 {
     if (!HUDComponents.Contains(comp))
     {
         HUDComponents.Add(comp);
     }
 }
Example #3
0
        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);
                }
            }
        }
Example #4
0
 public void RemoveComponent(IHUDComponent component)
 {
     if (_components.Contains(component))
     {
         _components.Remove(component);
         component.OnDetach();
     }
 }
Example #5
0
 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);
     }
 }
Example #6
0
 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);
     }
 }
Example #7
0
 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);
 }
Example #8
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();
                }
            }
        }
Example #9
0
        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);
                }
            }
        }
Example #10
0
 public void RemoveComponent(IHUDComponent comp)
 {
     HUDComponents.Remove(comp);
 }
Example #11
0
 public void AddComponent(String name, IHUDComponent component)
 {
     components.Add(name, component);
 }
Example #12
0
 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;
 }
Example #13
0
 public void RemoveComponent(IHUDComponent component)
 {
     if (_components.Contains(component))
     {
         _components.Remove(component);
         component.OnDetach();
     }
 }
Example #14
0
 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);
     }
 }