public void RefreshTypeNames() { _bpTypes = new Type[] { null }.Concat(GetBlueprints() .Select(bp => bp.GetType()).Distinct().OrderBy(type => type.FullName)).ToArray(); if (_selectionSearchText != null && _selectionSearchText.Length > 0) { _bpTypes = _bpTypes.Where(type => type?.FullName.ToLower().Contains(_selectionSearchText) ?? false).ToArray(); } _bpTypeNames = _bpTypes.Select(type => type?.FullName).ToArray(); _bpTypeNames[0] = "None"; _bpTypeIndex = 0; _filteredBPs = null; _treeView.Clear(); }
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 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"); }
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 (ResourcesLibrary.LibraryObject != null) { _bpTypes = new Type[] { null }.Concat(ResourcesLibrary.LibraryObject.BlueprintsByAssetId.Values .Select(bp => bp.GetType()).Distinct().OrderBy(type => type.FullName)).ToArray(); _bpTypeNames = _bpTypes.Select(type => type?.FullName).ToArray(); _bpTypeNames[0] = "None"; _bpTypeIndex = 0; _blueprints = null; _treeView.Clear(); } else { return; } } // slelection - button using (new GUILayout.HorizontalScope()) { GUIHelper.ToggleButton(ref _bpsExpanded, $"Current: {_bpTypeNames[_bpTypeIndex]}", _buttonStyle, GUILayout.ExpandWidth(false)); if (_bpsExpanded) { GUILayout.Space(10f); GUILayout.Label("Height:", GUILayout.ExpandWidth(false)); _bpsHeight = GUILayout.HorizontalSlider(_bpsHeight, 0f, Screen.height / 2, GUILayout.Width(100f), GUILayout.ExpandWidth(false)); } } // slelection - list if (_bpsExpanded) { 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; _blueprints = 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).ToArray(); _searchIndex = Array.IndexOf(_bpChildNames, "name"); _blueprints = ResourcesLibrary.LibraryObject.BlueprintsByAssetId.Values.Where(item => item.GetType() == _bpTypes[_bpTypeIndex]).ToList(); _treeView.SetRoot(_blueprints); } }, _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)); if (_searchExpanded) { 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) { 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; } } } } // input GUIHelper.TextField(ref _searchText, () => isDirty = true); // do search if (isDirty) { if (string.IsNullOrEmpty(_searchText)) { _treeView.SetRoot(_blueprints); } else { if (_bpFields.TryGetValue(_bpChildNames[_searchIndex], out FieldInfo f)) { _treeView.SetRoot(_blueprints.Where(bp => { try { return((f.GetValue(bp)?.ToString().Contains(_searchText) ?? false) != _searchReversed); } catch { return(_searchReversed); } }).ToList()); } else if (_bpProperties.TryGetValue(_bpChildNames[_searchIndex], out PropertyInfo p)) { _treeView.SetRoot(_blueprints.Where(bp => { try { return((p.GetValue(bp)?.ToString().Contains(_searchText) ?? false) != _searchReversed); } catch { return(_searchReversed); } }).ToList()); } } } } GUILayout.Space(10f); // tree view _treeView.OnGUI(true, false); } } catch (Exception e) { _bpTypeIndex = 0; _treeView.Clear(); modEntry.Logger.Error(e.StackTrace); throw e; } } }