using EventInput;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
public class GUIDropDown : GUIComponent, IKeyboardSubscriber
{
/// The component that was selected from the dropdown.
/// of the component selected from the dropdown.
public delegate bool OnSelectedHandler(GUIComponent selected, object obj = null);
///
/// Triggers when some item is cliecked from the dropdown.
/// Note that is not set yet when this callback triggers, and returning false from the callback disallows selecting it.
/// If you want to access the new value, use the obj argument.
///
public OnSelectedHandler OnSelected;
///
/// Triggers after an item has been selected from the dropdown, all validation has been done and the new value has been set.
///
public OnSelectedHandler AfterSelected;
public OnSelectedHandler OnDropped;
private readonly GUIButton button;
public GUIButton Button => button;
private readonly GUIImage icon;
private readonly GUIListBox listBox;
private RectTransform currentHighestParent;
private List parentHierarchy = new List();
private readonly bool selectMultiple;
public bool Dropped { get; set; }
public bool AllowNonText { get; set; }
public object SelectedItemData
{
get
{
if (listBox.SelectedComponent == null) return null;
return listBox.SelectedComponent.UserData;
}
}
public override bool Enabled
{
get { return listBox.Enabled; }
set { listBox.Enabled = value; }
}
public bool ButtonEnabled
{
get { return button.Enabled; }
set
{
button.Enabled = value;
if (icon != null) { icon.Enabled = value; }
}
}
public GUIComponent SelectedComponent
{
get { return listBox.SelectedComponent; }
}
public override bool Selected
{
get
{
return Dropped;
}
set
{
Dropped = value;
}
}
public GUIListBox ListBox
{
get { return listBox; }
}
public object SelectedData
{
get
{
return listBox.SelectedComponent?.UserData;
}
}
public int SelectedIndex
{
get
{
if (listBox.SelectedComponent == null) return -1;
return listBox.Content.GetChildIndex(listBox.SelectedComponent);
}
}
public Color ButtonTextColor
{
get { return button.TextColor; }
set { button.TextColor = value; }
}
public override GUIFont Font
{
get { return button?.Font ?? base.Font; }
set
{
if (button != null) { button.Font = value; }
}
}
public void ReceiveTextInput(char inputChar)
{
GUI.KeyboardDispatcher.Subscriber = null;
}
public void ReceiveTextInput(string text) { }
public void ReceiveCommandInput(char command) { }
public void ReceiveEditingInput(string text, int start, int length) { }
public void ReceiveSpecialInput(Keys key)
{
switch (key)
{
case Keys.Up:
case Keys.Down:
listBox.ReceiveSpecialInput(key);
GUI.KeyboardDispatcher.Subscriber = this;
break;
default:
GUI.KeyboardDispatcher.Subscriber = null;
break;
}
}
private readonly List