public void OnGUI(UnityModManager.ModEntry modEntry)
        {
            if (Mod == null || !Mod.Enabled)
            {
                return;
            }

            if (_buttonStyle == null)
            {
                _buttonStyle = new GUIStyle(GUI.skin.button)
                {
                    alignment = TextAnchor.MiddleLeft
                }
            }
            ;

            try {
                // blueprint type
                {
                    // refresh blueprint types
                    if (_bpTypeNames == null)
                    {
                        if (GetBlueprints() == null)
                        {
                            GUILayout.Label("Blueprints".Orange().Bold() + " loading: " + BlueprintLoader.progress.ToString("P2").Cyan().Bold());
                            return;
                        }
                        RefreshTypeNames();
                    }
                    bool isDirty = false;
                    // slelection - button
                    using (new GUILayout.HorizontalScope()) {
                        GUIHelper.ToggleButton(ref _bpsExpanded, $"Current: {_bpTypeNames[_bpTypeIndex]}", _buttonStyle, GUILayout.ExpandWidth(false));

                        if (_bpsExpanded.IsOn())
                        {
                            GUILayout.Space(10f);

                            GUILayout.Label("Height:", GUILayout.ExpandWidth(false));
                            _bpsHeight = GUILayout.HorizontalSlider(_bpsHeight, 0f, Screen.height / 2, GUILayout.Width(100f), GUILayout.ExpandWidth(false));
                            // _searchText input
                            GUILayout.Space(10);
                            GUIHelper.TextField(ref _selectionSearchText, () => isDirty = true, null, GUILayout.Width(200));
                            if (isDirty)
                            {
                                RefreshTypeNames();
                            }
                        }
                    }
                    // slelection - list
                    if (_bpsExpanded.IsOn())
                    {
                        using (new GUILayout.HorizontalScope(GUI.skin.box, GUILayout.Width(_bpsWidth), GUILayout.Height(_bpsHeight))) {
                            GUILayout.Space(30f);

                            using (var scrollView = new GUILayout.ScrollViewScope(_bpsScrollPosition)) {
                                _bpsScrollPosition = scrollView.scrollPosition;

                                GUIHelper.SelectionGrid(ref _bpTypeIndex, _bpTypeNames, 1, () => {
                                    _searchText = null;
                                    if (_bpTypeIndex == 0)
                                    {
                                        _bpFields     = null;
                                        _bpProperties = null;
                                        _bpChildNames = null;
                                        _searchIndex  = 0;

                                        _filteredBPs = null;
                                        _treeView.Clear();
                                    }
                                    else
                                    {
                                        _bpFields     = Node.GetFields(_bpTypes[_bpTypeIndex]).OrderBy(info => info.Name).ToDictionary(info => info.Name);
                                        _bpProperties = Node.GetProperties(_bpTypes[_bpTypeIndex]).OrderBy(info => info.Name).ToDictionary(info => info.Name);
                                        _bpChildNames = _bpFields.Keys.Concat(_bpProperties.Keys).OrderBy(key => key).ToArray();
                                        _searchIndex  = Array.IndexOf(_bpChildNames, "name");

                                        _filteredBPs = GetBlueprints().Where(item => item.GetType() == _bpTypes[_bpTypeIndex]).ToList();
                                        _treeView.SetRoot(_filteredBPs);
                                    }
                                }, _buttonStyle, GUILayout.ExpandWidth(false));

                                // cache width
                                if (Event.current.type == EventType.Repaint)
                                {
                                    _bpsWidth = GUILayoutUtility.GetLastRect().width + 65f;
                                }
                            }
                        }
                    }
                }
                if (_bpTypeIndex != 0)
                {
                    // search bar
                    if (_bpChildNames.Length > 0)
                    {
                        GUILayout.Space(10f);

                        bool isDirty = false;

                        // slelection - button
                        using (new GUILayout.HorizontalScope()) {
                            GUIHelper.ToggleButton(ref _searchExpanded, $"Search: {_bpChildNames[_searchIndex]}", _buttonStyle, GUILayout.ExpandWidth(false));

                            GUILayout.Space(10f);

                            GUIHelper.ToggleButton(ref _searchReversed, "By Excluding", () => isDirty = true, () => isDirty = true, _buttonStyle, GUILayout.ExpandWidth(false));

                            // _searchText input
                            GUILayout.Space(10);
                            GUIHelper.TextField(ref _searchText, () => isDirty = true, null, GUILayout.Width(200));

                            if (_searchExpanded.IsOn())
                            {
                                GUILayout.Space(10f);

                                GUILayout.Label("Height:", GUILayout.ExpandWidth(false));
                                _searchHeight = GUILayout.HorizontalSlider(_searchHeight, 0f, Screen.height / 2, GUILayout.Width(100f), GUILayout.ExpandWidth(false));
                            }
                        }
                        // slelection - list
                        if (_searchExpanded.IsOn())
                        {
                            using (new GUILayout.HorizontalScope(GUI.skin.box, GUILayout.Width(_searchWidth), GUILayout.Height(_searchHeight))) {
                                GUILayout.Space(30f);

                                using (var scrollView = new GUILayout.ScrollViewScope(_searchScrollPosition)) {
                                    _searchScrollPosition = scrollView.scrollPosition;

                                    // selection
                                    GUIHelper.SelectionGrid(ref _searchIndex, _bpChildNames, 1, () => isDirty = true, _buttonStyle, GUILayout.ExpandWidth(false));

                                    // cache width
                                    if (Event.current.type == EventType.Repaint)
                                    {
                                        _searchWidth = GUILayoutUtility.GetLastRect().width + 65f;
                                    }
                                }
                            }
                        }
                        // do search
                        if (isDirty)
                        {
                            if (string.IsNullOrEmpty(_searchText))
                            {
                                _treeView.SetRoot(_filteredBPs);
                            }
                            else
                            {
                                var searchText = _searchText.ToLower();
                                if (_bpFields.TryGetValue(_bpChildNames[_searchIndex], out FieldInfo f))
                                {
                                    _treeView.SetRoot(_filteredBPs.Where(bp => {
                                        try { return((f.GetValue(bp)?.ToString()?.ToLower().Contains(searchText) ?? false) != _searchReversed.IsOn()); }
                                        catch { return(_searchReversed.IsOn()); }
                                    }).ToList());
                                }
                                else if (_bpProperties.TryGetValue(_bpChildNames[_searchIndex], out PropertyInfo p))
                                {
                                    _treeView.SetRoot(_filteredBPs.Where(bp => {
                                        try { return((p.GetValue(bp)?.ToString()?.ToLower().Contains(searchText) ?? false) != _searchReversed.IsOn()); }
                                        catch { return(_searchReversed.IsOn()); }
                                    }).ToList());
                                }
                            }
                        }
                    }

                    GUILayout.Space(10f);
                    // tree view
                    _treeView.OnGUI(true, false);
                }
            }
            catch (Exception e) {
                _bpTypeIndex = 0;
                _treeView.Clear();
                modEntry.Logger.Error(e.StackTrace);
                throw e;
            }
        }
    }
示例#2
0
        private void DrawNode(Node node, int depth, bool collapse)
        {
            ToggleState expanded = (ToggleState)node.CustomFlags;

            if (depth >= _skipLevels && !(collapse && depth > 0))
            {
                _nodesCount++;

                if (_nodesCount > _startIndex && _nodesCount <= _startIndex + MaxRows)
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        if (!node.hasChildren)
                        {
                            expanded = ToggleState.None;
                        }
                        else if (node.CustomFlags == (int)ToggleState.None)
                        {
                            expanded = ToggleState.Off;
                        }
                        node.CustomFlags = (int)expanded;

                        // title
                        GUILayout.Space(DepthDelta * (depth - _skipLevels));
                        GUIHelper.ToggleButton(ref expanded,
                                               GetPrefix(node.NodeType).Color(RGBA.grey) +
                                               node.Name + " : " + node.Type.Name.Color(
                                                   node.IsBaseType ? RGBA.grey :
                                                   node.IsGameObject ? RGBA.magenta :
                                                   node.IsEnumerable ? RGBA.cyan : RGBA.orange),
                                               () => node.CustomFlags = (int)ToggleState.On,
                                               () => node.CustomFlags = (int)ToggleState.Off,
                                               _buttonStyle, GUILayout.ExpandWidth(false), GUILayout.MinWidth(TitleMinWidth));
                        ;

                        // value
                        Color originalColor = GUI.contentColor;
                        GUI.contentColor = node.IsException ? Color.red : node.IsNull ? Color.grey : originalColor;
                        GUILayout.TextArea(node.ValueText);
                        GUI.contentColor = originalColor;

                        // instance type
                        if (node.InstType != null && node.InstType != node.Type)
                        {
                            GUILayout.Label(node.InstType.Name.Color(RGBA.yellow), _buttonStyle, GUILayout.ExpandWidth(false));
                        }
                    }
                }
            }

            if (collapse)
            {
                node.CustomFlags = (int)ToggleState.Off;
            }

            // children
            if (expanded.IsOn())
            {
                DrawChildren(node, depth + 1, collapse);
            }

            string GetPrefix(NodeType nodeType)
            {
                switch (nodeType)
                {
                case NodeType.Component:
                    return("[c] ");

                case NodeType.Item:
                    return("[i] ");

                case NodeType.Field:
                    return("[f] ");

                case NodeType.Property:
                    return("[p] ");

                default:
                    return(string.Empty);
                }
            }
        }