Пример #1
0
        public TagElement(AssetResult result, string value, SerializableHashSet <string> values)
        {
            _assetResult = result;
            _value       = value;
            _values      = values;

            var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/TagElement.uxml");
            var ui         = visualTree.CloneTree();
            var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/TagElement.uss");

            ui.styleSheets.Add(styleSheet);
            Add(ui);

            _displayElement  = ui.Q <VisualElement>("display");
            _editElement     = ui.Q <VisualElement>("edit");
            _nameElement     = ui.Q <Label>("attribute-name");
            _nameEditElement = ui.Q <SearchSuggest>("attribute-name-edit");

            ui.Q <Button>("okButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(true, _nameEditElement.Value));
            ui.Q <Button>("cancelButton").RegisterCallback <MouseUpEvent>(_ => ToggleEdit());

            _displayElement.RegisterCallback <MouseDownEvent>(OnNameClicked);

            if (!_assetResult.Library.IsLocked)
            {
                _nameEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _nameEditElement));

                // right-click menu
                _displayElement.AddManipulator(new ContextualMenuManipulator(AddContextMenu));
            }

            Update();
            RegisterCallback <AttachToPanelEvent>(OnAttached);
        }
Пример #2
0
        private void OnKeyDown(KeyDownEvent evt, SearchSuggest ss)
        {
            if (ss.PopupVisible)
            {
                return;
            }
            switch (evt.keyCode)
            {
            case KeyCode.Return or KeyCode.KeypadEnter:
                CompleteEdit(true, _nameEditElement.Value, _valuesEditElement.Value);
                break;

            case KeyCode.Escape:
                CompleteEdit(false);
                evt.StopImmediatePropagation();
                break;
            }
        }
Пример #3
0
        public KeyValueElement(AssetResult result, LibraryKeyValue keyValue, bool isLink)
        {
            _assetResult = result;
            _keyValue    = keyValue;

            var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/KeyValueElement.uxml");
            var ui         = visualTree.CloneTree();
            var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Packages/org.visualpinball.engine.unity/VisualPinball.Unity/VisualPinball.Unity.Editor/AssetBrowser/KeyValueElement.uss");

            ui.styleSheets.Add(styleSheet);
            Add(ui);

            _displayElement     = ui.Q <VisualElement>("display");
            _displayLinkElement = ui.Q <VisualElement>("display-link");
            _editElement        = ui.Q <VisualElement>("edit");
            _nameElement        = ui.Q <Label>("attribute-name");
            _linkElement        = ui.Q <Label>("attribute-link");
            _valuesElement      = ui.Q <VisualElement>("attribute-values");
            _nameEditElement    = ui.Q <SearchSuggest>("attribute-name-edit");
            _valuesEditElement  = ui.Q <SearchSuggest>("attribute-value-edit");

            ui.Q <Button>("okButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(true, _nameEditElement.Value, _valuesEditElement.Value));
            ui.Q <Button>("cancelButton").RegisterCallback <MouseUpEvent>(_ => CompleteEdit(false));

            _isLink = isLink;
            DisplayContainer.RemoveFromClassList("hidden");
            DisplayContainer.RegisterCallback <MouseDownEvent>(OnNameClicked);

            if (!_assetResult.Library.IsLocked)
            {
                _nameEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _nameEditElement));
                _valuesEditElement.RegisterKeyDownCallback(evt => OnKeyDown(evt, _valuesEditElement));
                if (!_isLink)
                {
                    _valuesEditElement.IsMultiValue = true;
                }

                // right-click menu
                DisplayContainer.AddManipulator(new ContextualMenuManipulator(AddContextMenu));
            }

            RegisterCallback <AttachToPanelEvent>(OnAttached);
        }