Ejemplo n.º 1
0
        private void DrawNode(Node node, int depth, bool collapse)
        {
            ToggleState expanded = node.Expanded;

            if (depth >= _skipLevels && !(collapse && depth > 0))
            {
                if (!node.hasChildren)
                {
                    expanded = ToggleState.None;
                }
                else if (node.Expanded == ToggleState.None)
                {
                    expanded = ToggleState.Off;
                }
                DrawNodePrivate(node, depth, ref expanded);
                node.Expanded = expanded;
            }
            if (collapse)
            {
                node.Expanded = ToggleState.Off;
            }

            // children
            if (expanded.IsOn())
            {
                DrawChildren(node, depth + 1, collapse);
            }
        }
Ejemplo n.º 2
0
        public static void ToggleButton(ref ToggleState toggle, string text, ref float minWidth, Action on, Action off, GUIStyle style = null, params GUILayoutOption[] options)
        {
            ToggleState old = toggle;

            ToggleButton(ref toggle, text, ref minWidth, style, options);
            if (toggle != old)
            {
                if (toggle.IsOn())
                {
                    on?.Invoke();
                }
                else
                {
                    off?.Invoke();
                }
            }
        }
Ejemplo n.º 3
0
        public static ToggleState ToggleTypeList(ToggleState toggle, string text, HashSet <string> selectedTypes, HashSet <Type> allTypes, GUIStyle style = null, params GUILayoutOption[] options)
        {
            GUILayout.BeginHorizontal();

            ToggleButton(ref toggle, text, style, options);

            if (toggle.IsOn())
            {
                using (new GUILayout.VerticalScope())
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        if (GUILayout.Button("Select All"))
                        {
                            foreach (Type type in allTypes)
                            {
                                selectedTypes.Add(type.FullName);
                            }
                        }
                        if (GUILayout.Button("Deselect All"))
                        {
                            selectedTypes.Clear();
                        }
                    }

                    foreach (Type type in allTypes)
                    {
                        ToggleButton(selectedTypes.Contains(type.FullName) ? ToggleState.On : ToggleState.Off, type.Name.ToSentence(),
                                     () => selectedTypes.Add(type.FullName),
                                     () => selectedTypes.Remove(type.FullName),
                                     style, options);
                    }
                }
            }

            GUILayout.EndHorizontal();

            return(toggle);
        }
Ejemplo n.º 4
0
        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.Shared.progress.ToString("P2").Cyan().Bold());
                            return;
                        }
                        RefreshTypeNames();
                        RefreshBPSearchData();
                    }
                    using (new GUILayout.HorizontalScope()) {
                        bool isDirty = false;
                        // Blueprint Picker
                        using (new GUILayout.VerticalScope()) {
                            // Header and Search Field
                            bool blueprintListIsDirty = false;
                            GUIHelper.Div();
                            using (new GUILayout.HorizontalScope(GUILayout.Width(450))) {
                                // Header and Search Field
                                GUILayout.Label($"{_bpTypeNames[_bpTypeIndex]}".Cyan(), GUILayout.Width(300));

                                GUILayout.Space(10);
                                GUIHelper.TextField(ref _selectionSearchText, () => blueprintListIsDirty = true, null, GUILayout.MinWidth(150));
                            }
                            if (blueprintListIsDirty)
                            {
                                RefreshTypeNames();
                            }
                            GUIHelper.Div();
                            // Blueprint Picker List
                            if (_bpsExpanded.IsOn())
                            {
                                using (var scrollView = new GUILayout.ScrollViewScope(_bpsScrollPosition, GUILayout.Width(450))) {
                                    _bpsScrollPosition = scrollView.scrollPosition;
                                    GUIHelper.SelectionGrid(ref _bpTypeIndex, _bpTypeNames, 1, () => {
                                        _searchText = null;
                                        RefreshBPSearchData();
                                        _filteredBPs = _bpTypeIndex == 0 ? GetBlueprints() : GetBlueprints().Where(item => item.GetType() == _bpTypes[_bpTypeIndex]).ToList();
                                        ;
                                        _treeView.SetRoot(_filteredBPs);
                                    }, _buttonStyle, GUILayout.Width(450));

                                    // cache width
                                    if (Event.current.type == EventType.Repaint)
                                    {
                                        _bpsWidth = GUILayoutUtility.GetLastRect().width + 65f;
                                    }
                                }
                                //}
                            }
                        }

                        using (new GUILayout.VerticalScope(GUI.skin.box)) {
                            // Data Search Bar
                            GUIHelper.Div();
                            if (_bpChildNames.Length > 0)
                            {
                                using (new GUILayout.HorizontalScope()) {
                                    // search bar
                                    GUILayout.Space(10f);

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

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

                                        if (GUIHelper.Checkbox(ref _searchReversed, "By Excluding", _buttonStyle, GUILayout.ExpandWidth(false)))
                                        {
                                            isDirty = true;
                                        }


                                        if (_searchExpanded.IsOn())
                                        {
                                            GUILayout.Space(10f);
                                        }
                                    }
                                }
                            }
                            // Data Search Field Picker
                            if (_searchExpanded.IsOn())
                            {
                                // selection
                                GUIHelper.Div();
                                var availableWidth = Main.ummWidth - 550;
                                int xCols          = (int)Math.Ceiling(availableWidth / 300);
                                GUIHelper.SelectionGrid(ref _searchIndex, _bpChildNames, xCols, () => isDirty = true, _buttonStyle, GUILayout.Width(availableWidth));

                                // cache width
                                if (Event.current.type == EventType.Repaint)
                                {
                                    _searchWidth = GUILayoutUtility.GetLastRect().width + 65f;
                                }
                            }
                            // Do the search
                            if (isDirty)
                            {
                                UpdateSearchResults();
                            }
                            GUIHelper.Div();
                            // tree view
                            using (new GUILayout.VerticalScope()) {
                                _treeView.OnGUI(true, false);
                            }
                        }
                    }
                }
            }
            catch (Exception e) {
                _bpTypeIndex = 0;
//                _treeView.Clear();
                modEntry.Logger.Error(e.StackTrace);
                throw e;
            }
        }
    }