private static void SortControlsByInfo() { if (_needSort) { for (var el = Gumps.First; el != null; el = el.Next) { var c = el.Value; if (c.ControlInfo.Layer == UILayer.Default) { continue; } if (c.ControlInfo.Layer == UILayer.Under) { for (var first = Gumps.First; first != null; first = first.Next) { if (first.Value == c) { if (Gumps.Last != null) { Gumps.Remove(first); Gumps.AddAfter(Gumps.Last, c); } } } } else if (c.ControlInfo.Layer == UILayer.Over) { for (var first = Gumps.First; first != null; first = first.Next) { if (first.Value == c) { Gumps.Remove(first); Gumps.AddFirst(c); } } } } _needSort = false; } }