public void RefreshBPSearchData() { _filteredBPs = GetBlueprints(); if (_filteredBPs != null) { _treeView.SetRoot(_filteredBPs); } else { _treeView.Clear(); } _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"); }
void ResetTree() { if (_treeView == null) { _treeView = new ReflectionTreeView(); } Func <object> getTarget = TARGET_LIST[_targetNames[Main.settings.selectedRawDataType]]; if (getTarget == null) { _treeView.Clear(); } else { _treeView.SetRoot(getTarget()); } }
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; } } }