コード例 #1
0
        public void AddItem(string text, object userData = null, string toolTip = "")
        {
            if (selectMultiple)
            {
                var frame = new GUIFrame(new RectTransform(new Point(button.Rect.Width, button.Rect.Height), listBox.Content.RectTransform)
                {
                    IsFixedSize = false
                }, style: "ListBoxElement")
                {
                    UserData = userData,
                    ToolTip  = toolTip
                };

                new GUITickBox(new RectTransform(new Vector2(1.0f, 0.8f), frame.RectTransform, anchor: Anchor.CenterLeft)
                {
                    MaxSize = new Point(int.MaxValue, (int)(button.Rect.Height * 0.8f))
                }, text)
                {
                    UserData   = userData,
                    ToolTip    = toolTip,
                    OnSelected = (GUITickBox tb) =>
                    {
                        List <string> texts = new List <string>();
                        selectedDataMultiple.Clear();
                        selectedIndexMultiple.Clear();
                        int i = 0;
                        foreach (GUIComponent child in ListBox.Content.Children)
                        {
                            var tickBox = child.GetChild <GUITickBox>();
                            if (tickBox.Selected)
                            {
                                selectedDataMultiple.Add(child.UserData);
                                selectedIndexMultiple.Add(i);
                                texts.Add(tickBox.Text);
                            }
                            i++;
                        }
                        button.Text = string.Join(", ", texts);
                        // TODO: The callback is called at least twice, remove this?
                        OnSelected?.Invoke(tb.Parent, tb.Parent.UserData);
                        return(true);
                    }
                };
            }
            else
            {
                new GUITextBlock(new RectTransform(new Point(button.Rect.Width, button.Rect.Height), listBox.Content.RectTransform)
                {
                    IsFixedSize = false
                }, text, style: "ListBoxElement")
                {
                    UserData = userData,
                    ToolTip  = toolTip
                };
            }
        }
コード例 #2
0
        private bool OnClicked(GUIComponent component, object obj)
        {
            if (wasOpened)
            {
                return(false);
            }

            wasOpened = true;
            Dropped   = !Dropped;

            if (Dropped)
            {
                if (Enabled)
                {
                    OnDropped?.Invoke(this, userData);
                }
                if (parent.children[parent.children.Count - 1] != this)
                {
                    parent.children.Remove(this);
                    parent.children.Add(this);
                }
            }

            return(true);
        }
コード例 #3
0
ファイル: GUIDropDown.cs プロジェクト: yaelatletl/Barotrauma
        private bool OnClicked(GUIComponent component, object obj)
        {
            if (wasOpened)
            {
                return(false);
            }

            wasOpened = true;
            Dropped   = !Dropped;
            if (Dropped && Enabled)
            {
                OnDropped?.Invoke(this, userData);
                listBox.UpdateScrollBarSize();
            }
            return(true);
        }
コード例 #4
0
        private bool OnClicked(GUIComponent component, object obj)
        {
            if (wasOpened)
            {
                return(false);
            }

            wasOpened = true;
            Dropped   = !Dropped;
            if (Dropped && Enabled)
            {
                OnDropped?.Invoke(this, userData);
                listBox.UpdateScrollBarSize();

                GUI.KeyboardDispatcher.Subscriber = this;
            }
            else if (GUI.KeyboardDispatcher.Subscriber == this)
            {
                GUI.KeyboardDispatcher.Subscriber = null;
            }
            return(true);
        }