Fixed exceptions in GUIListBox.Select if any of the children have null userdata, option to add tooltips to GUIDropDown items

This commit is contained in:
Joonas Rikkonen
2017-12-19 22:22:42 +02:00
parent 9599137e83
commit 0a8c79c1cb
2 changed files with 8 additions and 7 deletions
@@ -115,10 +115,11 @@ namespace Barotrauma
listBox.AddChild(child); listBox.AddChild(child);
} }
public void AddItem(string text, object userData = null) public void AddItem(string text, object userData = null, string toolTip = "")
{ {
GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "ListBoxElement", Alignment.TopLeft, Alignment.CenterLeft, listBox); GUITextBlock textBlock = new GUITextBlock(new Rectangle(0,0,0,20), text, "ListBoxElement", Alignment.TopLeft, Alignment.CenterLeft, listBox);
textBlock.UserData = userData; textBlock.UserData = userData;
textBlock.ToolTip = toolTip;
} }
public override void ClearChildren() public override void ClearChildren()
@@ -171,12 +171,12 @@ namespace Barotrauma
{ {
for (int i = 0; i < children.Count; i++) for (int i = 0; i < children.Count; i++)
{ {
if (!children[i].UserData.Equals(userData)) continue; if ((children[i].UserData != null && children[i].UserData.Equals(userData)) ||
(children[i].UserData == null && userData == null))
Select(i, force); {
Select(i, force);
//if (OnSelected != null) OnSelected(Selected, Selected.UserData); if (!SelectMultiple) return;
if (!SelectMultiple) return; }
} }
} }