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

            try
            {
                if (_treeView == null)
                {
                    ResetTree();
                }

                // target selection
                GUIHelper.SelectionGrid(ref Main.settings.selectedRawDataType, _targetNames, 5, () => {
                    ResetTree();
                });

                // tree view
                if (Main.settings.selectedRawDataType != 0)
                {
                    GUILayout.Space(10f);

                    _treeView.OnGUI();
                }
            }
            catch (Exception e)
            {
                Main.settings.selectedRawDataType = 0;
                _treeView.Clear();
                modEntry.Logger.Error(e.StackTrace);
                throw e;
            }
        }
예제 #2
0
        public void OnGUI(UnityModManager.ModEntry modEntry)
        {
            if (Mod == null || !Mod.Enabled)
            {
                return;
            }

            try
            {
                // target selection
                GUIHelper.SelectionGrid(ref _targetIndex, _targetNames, 5, () =>
                {
                    Func <object> getTarget = TARGET_LIST[_targetNames[_targetIndex]];
                    if (getTarget == null)
                    {
                        _treeView.Clear();
                    }
                    else
                    {
                        _treeView.SetRoot(getTarget());
                    }
                });

                // tree view
                if (_targetIndex != 0)
                {
                    GUILayout.Space(10f);

                    _treeView.OnGUI();
                }
            }
            catch (Exception e)
            {
                _targetIndex = 0;
                _treeView.Clear();
                modEntry.Logger.Error(e.StackTrace);
                throw e;
            }
        }
        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;
            }
        }
    }
예제 #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;
            }
        }
    }