コード例 #1
0
        public void TestAddRemoveItem()
        {
            var uiManager = IoCManager.Resolve <IUserInterfaceManagerInternal>();

            uiManager.InitializeTesting();
            var optionButton = new MultiselectOptionButton <string>();

            optionButton.AddItem("Label1", "Key1");
            optionButton.AddItem("Label2", "Key2");
            optionButton.AddItem("Label3", "Key3");

            Assert.That(optionButton.GetIdx("Key1"), Is.EqualTo(0));
            Assert.That(optionButton.GetIdx("Key2"), Is.EqualTo(1));
            Assert.That(optionButton.GetIdx("Key3"), Is.EqualTo(2));
            Assert.That(optionButton.GetItemKey(0), Is.EqualTo("Key1"));
            Assert.That(optionButton.GetItemKey(1), Is.EqualTo("Key2"));
            Assert.That(optionButton.GetItemKey(2), Is.EqualTo("Key3"));

            optionButton.RemoveItem(1);

            Assert.That(optionButton.GetIdx("Key1"), Is.EqualTo(0));
            Assert.That(optionButton.GetIdx("Key3"), Is.EqualTo(1));
            Assert.That(optionButton.GetItemKey(0), Is.EqualTo("Key1"));
            Assert.That(optionButton.GetItemKey(1), Is.EqualTo("Key3"));

            optionButton.RemoveItem(0);

            Assert.That(optionButton.GetIdx("Key3"), Is.EqualTo(0));
            Assert.That(optionButton.GetItemKey(0), Is.EqualTo("Key3"));
        }
コード例 #2
0
 public ItemPressedEventArgs(TKey key, bool selected, MultiselectOptionButton <TKey> button)
 {
     Key      = key;
     Selected = selected;
     Button   = button;
 }
コード例 #3
0
 private void OnFilterItemSelected(MultiselectOptionButton <string> .ItemPressedEventArgs args)
 {
     UpdateFilterLabel();
     SearchAndDisplay();
 }
コード例 #4
0
        public ActionMenu(ClientActionsComponent actionsComponent, ActionsUI actionsUI)
        {
            _actionsComponent = actionsComponent;
            _actionsUI        = actionsUI;
            _actionManager    = IoCManager.Resolve <ActionManager>();
            _gameHud          = IoCManager.Resolve <IGameHud>();

            Title             = Loc.GetString("Actions");
            CustomMinimumSize = (300, 300);

            Contents.AddChild(new VBoxContainer
            {
                Children =
                {
                    new HBoxContainer
                    {
                        Children =
                        {
                            (_searchBar             = new LineEdit
                            {
                                StyleClasses        ={ StyleNano.StyleClassActionSearchBox                    },
                                SizeFlagsHorizontal = SizeFlags.FillExpand,
                                PlaceHolder         = Loc.GetString("Search")
                            }),
                            (_filterButton          = new MultiselectOptionButton <string>()
                            {
                                Label               = Loc.GetString("Filter")
                            }),
                        }
                    },
                    (_clearButton = new Button
                    {
                        Text = Loc.GetString("Clear"),
                    }),
                    (_filterLabel = new Label()),
                    new ScrollContainer
                    {
                        //TODO: needed? CustomMinimumSize = new Vector2(200.0f, 0.0f),
                        SizeFlagsVertical   = SizeFlags.FillExpand,
                        SizeFlagsHorizontal = SizeFlags.FillExpand,
                        Children            =
                        {
                            (_resultsGrid = new GridContainer
                            {
                                MaxWidth  = 300
                            })
                        }
                    }
                }
            });

            // populate filters from search tags
            var filterTags = new List <string>();

            foreach (var action in _actionManager.EnumerateActions())
            {
                filterTags.AddRange(action.Filters);
            }

            // special one to filter to only include item actions
            filterTags.Add(ItemTag);
            filterTags.Add(NotItemTag);
            filterTags.Add(InstantActionTag);
            filterTags.Add(ToggleActionTag);
            filterTags.Add(TargetActionTag);
            filterTags.Add(AllActionsTag);
            filterTags.Add(GrantedActionsTag);

            foreach (var tag in filterTags.Distinct().OrderBy(tag => tag))
            {
                _filterButton.AddItem(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tag), tag);
            }

            UpdateFilterLabel();

            _dragShadow = new TextureRect
            {
                CustomMinimumSize = (64, 64),
                Stretch           = TextureRect.StretchMode.Scale,
                Visible           = false
            };
            UserInterfaceManager.PopupRoot.AddChild(_dragShadow);
            LayoutContainer.SetSize(_dragShadow, (64, 64));

            _dragDropHelper = new DragDropHelper <ActionMenuItem>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag);
        }
コード例 #5
0
        public ActionMenu(ActionsUI actionsUI)
        {
            _actionsUI = actionsUI;
            _gameHud   = IoCManager.Resolve <IGameHud>();
            _entMan    = IoCManager.Resolve <IEntityManager>();

            Title   = Loc.GetString("ui-actionmenu-title");
            MinSize = (320, 300);

            Contents.AddChild(new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical,
                Children    =
                {
                    new BoxContainer
                    {
                        Orientation = LayoutOrientation.Horizontal,
                        Children    =
                        {
                            (_searchBar          = new LineEdit
                            {
                                StyleClasses     ={ StyleNano.StyleClassActionSearchBox                    },
                                HorizontalExpand = true,
                                PlaceHolder      = Loc.GetString("ui-actionmenu-search-bar-placeholder-text")
                            }),
                            (_filterButton       = new MultiselectOptionButton <string>()
                            {
                                Label            = Loc.GetString("ui-actionmenu-filter-button")
                            })
                        }
                    },
                    (_clearButton = new Button
                    {
                        Text = Loc.GetString("ui-actionmenu-clear-button"),
                    }),
                    (_filterLabel = new Label()),
                    new ScrollContainer
                    {
                        //TODO: needed? MinSize = new Vector2(200.0f, 0.0f),
                        VerticalExpand   = true,
                        HorizontalExpand = true,
                        Children         =
                        {
                            (_resultsGrid    = new GridContainer
                            {
                                MaxGridWidth = 300
                            })
                        }
                    }
                }
            });

            foreach (var tag in _filters)
            {
                _filterButton.AddItem(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tag), tag);
            }

            // default to showing all actions.
            _filterButton.SelectKey(AllFilter);

            UpdateFilterLabel();

            _dragShadow = new TextureRect
            {
                MinSize = (64, 64),
                Stretch = TextureRect.StretchMode.Scale,
                Visible = false,
                SetSize = (64, 64)
            };
            UserInterfaceManager.PopupRoot.AddChild(_dragShadow);

            _dragDropHelper = new DragDropHelper <ActionMenuItem>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag);
        }