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

View File

@@ -499,6 +499,28 @@ namespace Barotrauma
cursor.Draw(spriteBatch, PlayerInput.MousePosition);
}
public static void AddToGUIUpdateList()
{
if (pauseMenuOpen)
{
pauseMenu.AddToGUIUpdateList();
}
if (settingsMenuOpen)
{
GameMain.Config.SettingsFrame.AddToGUIUpdateList();
}
if (GUIMessageBox.MessageBoxes.Count > 0)
{
var messageBox = GUIMessageBox.MessageBoxes.Peek();
if (messageBox != null)
{
messageBox.AddToGUIUpdateList();
}
}
}
public static void Update(float deltaTime)
{
if (pauseMenuOpen)
@@ -516,7 +538,6 @@ namespace Barotrauma
var messageBox = GUIMessageBox.MessageBoxes.Peek();
if (messageBox != null)
{
GUIComponent.MouseOn = messageBox;
messageBox.Update(deltaTime);
}
}

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

View File

@@ -166,6 +166,13 @@ namespace Barotrauma
return true;
}
public override void AddToGUIUpdateList()
{
base.AddToGUIUpdateList();
button.AddToGUIUpdateList();
if (Dropped) listBox.AddToGUIUpdateList();
}
public override void Update(float deltaTime)
{
if (!Visible) return;

View File

@@ -36,7 +36,7 @@ namespace Barotrauma
//if (style != null) ApplyStyle(style);
}
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
{
if (!Visible) return;

View File

@@ -264,6 +264,20 @@ namespace Barotrauma
}
}
public override void AddToGUIUpdateList()
{
base.AddToGUIUpdateList();
if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList();
}
public override Rectangle MouseRect
{
get
{
return Rectangle.Empty;
}
}
public override void Update(float deltaTime)
{
if (!Visible) return;

View File

@@ -55,6 +55,11 @@ namespace Barotrauma
}
}
public override Rectangle MouseRect
{
get { return box.Rect; }
}
public GUITickBox(Rectangle rect, string label, Alignment alignment, GUIComponent parent)
: this(rect, label, alignment, GUI.Font, parent)
{
@@ -69,6 +74,7 @@ namespace Barotrauma
box = new GUIFrame(rect, Color.DarkGray, null, this);
box.HoverColor = Color.Gray;
box.SelectedColor = Color.DarkGray;
box.CanBeFocused = false;
text = new GUITextBlock(new Rectangle(rect.Right + 10, rect.Y+2, 20, rect.Height), label, GUI.Style, this, font);
@@ -76,19 +82,19 @@ namespace Barotrauma
Enabled = true;
}
public override void Update(float deltaTime)
{
if (!Visible || !Enabled) return;
if (MouseOn != null && MouseOn != this && !MouseOn.IsParentOf(this)) return;
//if (MouseOn != null && MouseOn != this && !MouseOn.IsParentOf(this)) return;
if (text.Rect.Contains(PlayerInput.MousePosition)) MouseOn = this;
//if (text.Rect.Contains(PlayerInput.MousePosition)) MouseOn = this;
if (box.Rect.Contains(PlayerInput.MousePosition))
if (MouseOn==this)//box.Rect.Contains(PlayerInput.MousePosition))
{
//ToolTip = this.ToolTip;
MouseOn = this;
//MouseOn = this;
box.State = ComponentState.Hover;