removed a ton of xml comments and such
This commit is contained in:
@@ -8,11 +8,7 @@ using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Jovian.EncounterSystem.Editor {
|
||||
/// <summary>
|
||||
/// Designer-facing browser for every <see cref="IEncounter"/> authored across all
|
||||
/// <see cref="EncounterTable"/> assets in the project. Virtualised ListView on the left,
|
||||
/// property-field detail pane on the right. Search by id/name/description; filter by kind.
|
||||
/// </summary>
|
||||
/// <summary>Browser for every encounter across all tables. Search + kind filter + detail pane. Quest chains render as a tree rooted at the first step.</summary>
|
||||
public class EncounterBrowserWindow : EditorWindow {
|
||||
private const string AllKinds = "All";
|
||||
|
||||
@@ -23,13 +19,12 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
}
|
||||
|
||||
private readonly List<Record> allRecords = new();
|
||||
private List<Record> filteredRecords = new();
|
||||
private string searchText = string.Empty;
|
||||
private string kindFilter = AllKinds;
|
||||
|
||||
private readonly Dictionary<IEncounter, List<ValidationIssue>> issuesByEncounter = new();
|
||||
|
||||
private ListView listView;
|
||||
private TreeView treeView;
|
||||
private VisualElement detailPane;
|
||||
private ToolbarMenu kindDropdown;
|
||||
|
||||
@@ -78,15 +73,15 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
split.style.flexGrow = 1f;
|
||||
rootVisualElement.Add(split);
|
||||
|
||||
listView = new ListView {
|
||||
treeView = new TreeView {
|
||||
makeItem = MakeRow,
|
||||
bindItem = BindRow,
|
||||
fixedItemHeight = 22,
|
||||
selectionType = SelectionType.Single
|
||||
};
|
||||
listView.selectionChanged += OnSelectionChanged;
|
||||
listView.style.flexGrow = 1f;
|
||||
split.Add(listView);
|
||||
treeView.selectionChanged += OnSelectionChanged;
|
||||
treeView.style.flexGrow = 1f;
|
||||
split.Add(treeView);
|
||||
|
||||
detailPane = new ScrollView(ScrollViewMode.Vertical) {
|
||||
style = { paddingLeft = 8, paddingTop = 8, paddingRight = 8, flexGrow = 1f }
|
||||
@@ -134,7 +129,7 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
}
|
||||
|
||||
private void BindRow(VisualElement element, int index) {
|
||||
var record = filteredRecords[index];
|
||||
var record = treeView.GetItemDataForIndex<Record>(index);
|
||||
var label = element.Q<Label>("row-label");
|
||||
var badge = element.Q<VisualElement>("issue-badge");
|
||||
|
||||
@@ -222,15 +217,73 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
}
|
||||
|
||||
private void ApplyFilter() {
|
||||
filteredRecords = allRecords.Where(Matches).ToList();
|
||||
if(listView != null) {
|
||||
listView.itemsSource = filteredRecords;
|
||||
listView.Rebuild();
|
||||
listView.ClearSelection();
|
||||
var filtered = allRecords.Where(Matches).ToList();
|
||||
var items = BuildTreeItems(filtered);
|
||||
if(treeView != null) {
|
||||
treeView.SetRootItems(items);
|
||||
treeView.Rebuild();
|
||||
treeView.ClearSelection();
|
||||
treeView.ExpandAll();
|
||||
}
|
||||
ShowEmptyDetail();
|
||||
}
|
||||
|
||||
private static List<TreeViewItemData<Record>> BuildTreeItems(List<Record> records) {
|
||||
var byEncounter = new Dictionary<IEncounter, Record>();
|
||||
foreach(var r in records) {
|
||||
if(r.encounter != null) {
|
||||
byEncounter[r.encounter] = r;
|
||||
}
|
||||
}
|
||||
|
||||
// Any encounter that is a `nextEncounter` target of another record in the filtered set
|
||||
// becomes a non-root (rendered as a child), not a top-level item.
|
||||
var nonRoot = new HashSet<IEncounter>();
|
||||
foreach(var r in records) {
|
||||
if(r.encounter?.Kind is not QuestKind quest) {
|
||||
continue;
|
||||
}
|
||||
var next = quest.nextEncounter.Resolve();
|
||||
if(next != null && byEncounter.ContainsKey(next)) {
|
||||
nonRoot.Add(next);
|
||||
}
|
||||
}
|
||||
|
||||
var result = new List<TreeViewItemData<Record>>();
|
||||
var uid = 0;
|
||||
foreach(var r in records) {
|
||||
if(r.encounter != null && nonRoot.Contains(r.encounter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var children = BuildChainChildren(r, byEncounter, ref uid);
|
||||
result.Add(new TreeViewItemData<Record>(uid++, r, children));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<TreeViewItemData<Record>> BuildChainChildren(Record root, Dictionary<IEncounter, Record> byEncounter, ref int uid) {
|
||||
var children = new List<TreeViewItemData<Record>>();
|
||||
if(root.encounter?.Kind is not QuestKind) {
|
||||
return children;
|
||||
}
|
||||
|
||||
var current = root.encounter;
|
||||
var visited = new HashSet<IEncounter> { current };
|
||||
while(current?.Kind is QuestKind quest) {
|
||||
var next = quest.nextEncounter.Resolve();
|
||||
if(next == null || !visited.Add(next)) {
|
||||
break;
|
||||
}
|
||||
if(!byEncounter.TryGetValue(next, out var nextRecord)) {
|
||||
break;
|
||||
}
|
||||
children.Add(new TreeViewItemData<Record>(uid++, nextRecord));
|
||||
current = next;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
private bool Matches(Record record) {
|
||||
var kindName = record.encounter?.Kind?.GetType().Name ?? string.Empty;
|
||||
if(kindFilter != AllKinds && kindName != kindFilter) {
|
||||
|
||||
Reference in New Issue
Block a user