Example #1
0
        public void Update()
        {
            foreach (AssemblerIconElement element in SubElements.OfType <AssemblerIconElement>().ToList())
            {
                if (!AssemblerList.Keys.Contains(element.DisplayedMachine))
                {
                    SubElements.Remove(element);
                }
            }

            foreach (var kvp in AssemblerList)
            {
                if (!SubElements.OfType <AssemblerIconElement>().Any(aie => aie.DisplayedMachine == kvp.Key))
                {
                    SubElements.Add(new AssemblerIconElement(kvp.Key, kvp.Value, Parent));
                }
            }

            int y          = (int)(Height / Math.Ceiling(AssemblerList.Count / 2d));
            int widthOver2 = this.Width / 2;

            int i = 0;

            foreach (AssemblerIconElement element in SubElements.OfType <AssemblerIconElement>())
            {
                element.DisplayedNumber = AssemblerList[element.DisplayedMachine];

                if (i % 2 == 0)
                {
                    element.X = widthOver2 - element.Width;
                }
                else
                {
                    element.X = widthOver2;
                }
                element.Y = (int)Math.Floor(i / 2d) * y;

                if (AssemblerList.Count == 1)
                {
                    element.X = (Width - element.Width) / 2;
                }
                else if (i == AssemblerList.Count - 1 && AssemblerList.Count % 2 != 0)
                {
                    element.X = widthOver2 - (element.Width / 2);
                }

                i++;
            }
        }
 public void RemoveSubElement(DungeonNode newSub) => SubElements.Remove(newSub);