GUI elements now respect render order + some minor distance comparison optimization

This commit is contained in:
juanjp600
2016-11-15 22:26:36 -03:00
parent 3c57b9d945
commit d2c17274fe
39 changed files with 441 additions and 47 deletions
+47 -4
View File
@@ -10,9 +10,47 @@ namespace Barotrauma
public abstract class GUIComponent
{
const float FlashDuration = 1.5f;
public static GUIComponent MouseOn;
public static GUIComponent MouseOn
{
get;
private set;
}
public static void ForceMouseOn(GUIComponent c)
{
MouseOn = c;
}
protected static List<GUIComponent> ComponentsToUpdate = new List<GUIComponent>();
public virtual void AddToGUIUpdateList()
{
if (!Visible) return;
if (ComponentsToUpdate.Contains(this)) return;
ComponentsToUpdate.Add(this);
children.ForEach(c => c.AddToGUIUpdateList());
}
public static void ClearUpdateList()
{
ComponentsToUpdate.Clear();
}
public static GUIComponent UpdateMouseOn()
{
MouseOn = null;
for (int i=ComponentsToUpdate.Count-1;i>=0;i--)
{
GUIComponent c = ComponentsToUpdate[i];
if (c.MouseRect.Contains(PlayerInput.MousePosition))
{
MouseOn = c;
break;
}
}
return MouseOn;
}
protected static KeyboardDispatcher keyboardDispatcher;
public enum ComponentState { None, Hover, Selected};
@@ -97,6 +135,11 @@ namespace Barotrauma
}
}
}
public virtual Rectangle MouseRect
{
get { return CanBeFocused ? rect : Rectangle.Empty; }
}
public List<UISprite> sprites;
//public Alignment SpriteAlignment { get; set; }
@@ -304,7 +347,7 @@ namespace Barotrauma
if (flashTimer>0.0f) flashTimer -= deltaTime;
if (CanBeFocused)
/*if (CanBeFocused)
{
if (rect.Contains(PlayerInput.MousePosition))
{
@@ -315,7 +358,7 @@ namespace Barotrauma
if (MouseOn == this) MouseOn = null;
}
}
}*/
//use a fixed list since children can change their order in the main children list
//TODO: maybe find a more efficient way of handling changes in list order