Ejemplo n.º 1
0
 public void SetCurrentBound(SerializedRule temp, Object o)
 {
     folderAsset = o;
     TempRule    = temp;
     this.Bind(new SerializedObject(TempRule));
 }
        public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            // This function is called when the user clicks on the MyCustom element in the Settings window.
            _settings    = PvCustomizerSettings.GetOrCreateSettings();
            _srlSettings = new SerializedObject(_settings);
            keywords     = GetSearchKeywordsFromSerializedObject(_srlSettings);

            var tree = Resource.Load <VisualTreeAsset>("UXML/PvCustomizerSettingsProvider_UXML.uxml");

            tree.CloneTree(rootElement);

            #region images

            rootElement.Q(className: "logo").style.backgroundImage =
                new StyleBackground(Resource.Load <Texture2D>("Icons/logo.png"));

            #endregion

            #region list-view

            _rulesListQ = rootElement.Query <ListView>().Name("rulesList");
            ListView rulesList = _rulesListQ.First();
            rulesList.bindItem = (vi, i) =>
            {
                FolderRuleOptionsPanel optionsPanel = vi.Q <FolderRuleOptionsPanel>();
                if (i >= 0 && _settings.Rules.Count > i)
                {
                    optionsPanel.SetEnabled(true);
                    SerializedRule serializedRule = ScriptableObject.CreateInstance <SerializedRule>();
                    serializedRule.rule = _settings.Rules[i];
                    optionsPanel.SetCurrentBound(serializedRule, null);
                }
                else
                {
                    optionsPanel.SetEnabled(false);
                }
            };

            rulesList.makeItem = () =>
            {
                var child = Resource.Load <VisualTreeAsset>("UXML/FolderRuleOptionsPanel_UXML.uxml").CloneTree();
                child.style.paddingTop        = 5;
                child.style.paddingBottom     = 5;
                child.style.borderBottomWidth = 3;
                child.style.borderBottomColor = Color.black;

                var optionsPanel = child.Q <FolderRuleOptionsPanel>();

                optionsPanel.Q <Button>("btn_Reset")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Cancel")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Apply")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Settings")?.RemoveFromHierarchy();
                optionsPanel.Q("tag-holder").RemoveFromHierarchy();

                optionsPanel.OnDelete = () => DeleteRule(child);

                return(child);
            };
            rulesList.style.flexGrow = 1;
            rulesList.Refresh();

            #endregion

            #region tint example + imgui

            _tintExampleContainer = rootElement.Q <IMGUIContainer>("tintExample");
            _tintExampleContainer.onGUIHandler += DrawTintExample;

            #endregion

            rootElement.Bind(_srlSettings);
        }