Skip to content

Commit 612de09

Browse files
authored
Merge pull request #41 from CyberAgentGameEntertainment/feature/sorting
Sorting for LayoutViewer
2 parents addd3e3 + 30fd2fe commit 612de09

7 files changed

Lines changed: 110 additions & 20 deletions

File tree

Assets/SmartAddresser/Editor/Core/Models/Layouts/Entry.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using SmartAddresser.Editor.Core.Models.Shared;
45
using UnityEngine;
56

@@ -20,13 +21,14 @@ public sealed class Entry
2021
[NonSerialized] private bool _isErrorTypeDirty = true;
2122
[NonSerialized] private bool _isMessagesDirty = true;
2223

23-
public Entry(string address, string assetPath, string[] labels, string[] versions)
24+
public Entry(string address, string assetPath, IReadOnlyList<string> labels, IReadOnlyList<string> versions)
2425
{
2526
_id = IdentifierFactory.Create();
2627
_address = address;
2728
_assetPath = assetPath;
28-
_labels = labels ?? Array.Empty<string>();
29-
_versions = versions ?? Array.Empty<string>();
29+
// Sort labels and versions for sorting of LayoutViewer.
30+
_labels = labels == null ? Array.Empty<string>() : labels.OrderBy(x => x).ToArray();
31+
_versions = versions == null ? Array.Empty<string>() : versions.OrderBy(x => x).ToArray();
3032
}
3133

3234
public string Id => _id;

Assets/SmartAddresser/Editor/Core/Models/Services/BuildLayoutService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static Task<Group> BuildGroupAsync(AddressRule addressRule, LayoutRule l
9595
versions.Add(version);
9696
}
9797

98-
var entry = new Entry(address, assetPath, labels, versions.ToArray());
98+
var entry = new Entry(address, assetPath, labels, versions);
9999
group.Entries.Add(entry);
100100
}
101101

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/AddressRuleEditor/AddressRuleListTreeView.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ public enum Columns
2121
AssetGroups,
2222
AddressRule
2323
}
24+
25+
private GUIStyle _cellLabelStyle;
26+
27+
private GUIStyle CellLabelStyle
28+
{
29+
get
30+
{
31+
if (_cellLabelStyle == null)
32+
{
33+
_cellLabelStyle = new GUIStyle(EditorStyles.label)
34+
{
35+
wordWrap = false
36+
};
37+
}
38+
39+
return _cellLabelStyle;
40+
}
41+
}
2442

2543
[NonSerialized] private int _currentId;
2644

@@ -52,7 +70,7 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
5270
{
5371
case Columns.Groups:
5472
GUI.enabled = addressableGroup != null && !addressableGroup.ReadOnly && item.Rule.Control.Value;
55-
GUI.Label(cellRect, GetText(item, columnIndex));
73+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
5674
break;
5775
case Columns.Control:
5876
GUI.enabled = addressableGroup != null && !addressableGroup.ReadOnly;
@@ -62,11 +80,11 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
6280
break;
6381
case Columns.AssetGroups:
6482
GUI.enabled = addressableGroup != null && !addressableGroup.ReadOnly && item.Rule.Control.Value;
65-
GUI.Label(cellRect, GetText(item, columnIndex));
83+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
6684
break;
6785
case Columns.AddressRule:
6886
GUI.enabled = addressableGroup != null && !addressableGroup.ReadOnly && item.Rule.Control.Value;
69-
GUI.Label(cellRect, GetText(item, columnIndex));
87+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
7088
break;
7189
default:
7290
throw new NotImplementedException();

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/LabelRuleEditor/LabelRuleListTreeView.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ public enum Columns
2323
AssetGroups,
2424
LabelRule
2525
}
26+
27+
private GUIStyle _cellLabelStyle;
28+
29+
private GUIStyle CellLabelStyle
30+
{
31+
get
32+
{
33+
if (_cellLabelStyle == null)
34+
{
35+
_cellLabelStyle = new GUIStyle(EditorStyles.label)
36+
{
37+
wordWrap = false
38+
};
39+
}
40+
41+
return _cellLabelStyle;
42+
}
43+
}
2644

2745
[NonSerialized] private int _currentId;
2846

@@ -62,10 +80,10 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
6280
base.CellGUI(columnIndex, cellRect, args);
6381
break;
6482
case Columns.AssetGroups:
65-
GUI.Label(cellRect, GetText(item, columnIndex));
83+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
6684
break;
6785
case Columns.LabelRule:
68-
GUI.Label(cellRect, GetText(item, columnIndex));
86+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
6987
break;
7088
default:
7189
throw new NotImplementedException();

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutRuleEditor/VersionRuleEditor/VersionRuleListTreeView.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ public enum Columns
2323
AssetGroups,
2424
VersionRule
2525
}
26+
27+
private GUIStyle _cellLabelStyle;
28+
29+
private GUIStyle CellLabelStyle
30+
{
31+
get
32+
{
33+
if (_cellLabelStyle == null)
34+
{
35+
_cellLabelStyle = new GUIStyle(EditorStyles.label)
36+
{
37+
wordWrap = false
38+
};
39+
}
40+
41+
return _cellLabelStyle;
42+
}
43+
}
2644

2745
[NonSerialized] private int _currentId;
2846

@@ -63,10 +81,10 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
6381
base.CellGUI(columnIndex, cellRect, args);
6482
break;
6583
case Columns.AssetGroups:
66-
GUI.Label(cellRect, GetText(item, columnIndex));
84+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
6785
break;
6886
case Columns.VersionRule:
69-
GUI.Label(cellRect, GetText(item, columnIndex));
87+
GUI.Label(cellRect, GetText(item, columnIndex), CellLabelStyle);
7088
break;
7189
default:
7290
throw new NotImplementedException();

Assets/SmartAddresser/Editor/Core/Tools/Addresser/LayoutViewer/LayoutViewerTreeView.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,30 @@ public enum Columns
2121
Labels,
2222
Versions
2323
}
24-
24+
25+
private static readonly int[] DefaultSkipSortingDepths = { 0 };
26+
2527
private readonly Texture2D _badgeBackgroundTexture;
2628
private readonly Texture2D _failedTexture;
2729
private readonly Texture2D _successTexture;
2830
private readonly Texture2D _warningTexture;
31+
private GUIStyle _cellLabelStyle;
32+
33+
private GUIStyle CellLabelStyle
34+
{
35+
get
36+
{
37+
if (_cellLabelStyle == null)
38+
{
39+
_cellLabelStyle = new GUIStyle(EditorStyles.label)
40+
{
41+
wordWrap = false
42+
};
43+
}
44+
45+
return _cellLabelStyle;
46+
}
47+
}
2948

3049
[NonSerialized] private int _currentId;
3150

@@ -98,10 +117,10 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
98117
statusIconRect.width = statusIconRect.height;
99118
labelRect.xMin += statusIconRect.width + 2.0f;
100119
GUI.DrawTexture(statusIconRect, errorTypeIcon);
101-
GUI.Label(labelRect, GetTextForDisplay(item, columnIndex));
120+
GUI.Label(labelRect, GetTextForDisplay(item, columnIndex), CellLabelStyle);
102121
break;
103122
case Columns.AssetPath:
104-
GUI.Label(cellRect, GetTextForDisplay(item, columnIndex));
123+
GUI.Label(cellRect, GetTextForDisplay(item, columnIndex), CellLabelStyle);
105124
break;
106125
case Columns.Labels:
107126
DrawBadges(entryItem.Entry.Labels, new Vector2(cellRect.x, cellRect.y + 1),
@@ -142,7 +161,7 @@ private void DrawBadges(IEnumerable<string> texts, Vector2 startPos, float heigh
142161
GUI.DrawTexture(textureRect, _badgeBackgroundTexture, ScaleMode.StretchToFill, true, 0, Color.white,
143162
Vector4.zero, cornerRadius);
144163
var labelRect = new Rect(pos.x + 6, pos.y, labelWidth, height);
145-
GUI.Label(labelRect, text);
164+
GUI.Label(labelRect, text, CellLabelStyle);
146165

147166
pos.x += textureRect.width;
148167
pos.x += 3; // space between badges
@@ -183,6 +202,12 @@ protected override string GetTextForSearch(TreeViewItem item, int columnIndex)
183202

184203
}
185204

205+
protected override IEnumerable<int> GetSkipSortingDepths()
206+
{
207+
// Exclude GroupItem from sorting targets.
208+
return DefaultSkipSortingDepths;
209+
}
210+
186211
protected override bool CanMultiSelect(TreeViewItem item)
187212
{
188213
return false;
@@ -287,7 +312,7 @@ public MultiColumnHeaderState.Column[] GetColumnStates()
287312
sortedAscending = oldGroupNameAddressColumn?.sortedAscending ?? true,
288313
headerContent = new GUIContent("Group Name / Address"),
289314
headerTextAlignment = TextAlignment.Center,
290-
canSort = false,
315+
canSort = true,
291316
minWidth = 50,
292317
autoResize = false,
293318
allowToggleVisibility = false
@@ -298,7 +323,7 @@ public MultiColumnHeaderState.Column[] GetColumnStates()
298323
sortedAscending = oldAssetPathColumn?.sortedAscending ?? true,
299324
headerContent = new GUIContent("Asset Path"),
300325
headerTextAlignment = TextAlignment.Center,
301-
canSort = false,
326+
canSort = true,
302327
minWidth = 50,
303328
autoResize = false,
304329
allowToggleVisibility = false
@@ -309,7 +334,7 @@ public MultiColumnHeaderState.Column[] GetColumnStates()
309334
sortedAscending = oldLabelsColumn?.sortedAscending ?? true,
310335
headerContent = new GUIContent("Labels"),
311336
headerTextAlignment = TextAlignment.Center,
312-
canSort = false,
337+
canSort = true,
313338
minWidth = 20,
314339
autoResize = false,
315340
allowToggleVisibility = false
@@ -320,7 +345,7 @@ public MultiColumnHeaderState.Column[] GetColumnStates()
320345
sortedAscending = oldVersionsColumn?.sortedAscending ?? true,
321346
headerContent = new GUIContent("Versions"),
322347
headerTextAlignment = TextAlignment.Center,
323-
canSort = false,
348+
canSort = true,
324349
minWidth = 20,
325350
autoResize = false,
326351
allowToggleVisibility = false

Assets/SmartAddresser/Editor/Foundation/EasyTreeView/TreeViewBase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ private void SortHierarchical(IList<TreeViewItem> children, int keyColumnIndex,
310310
{
311311
if (children == null) return;
312312

313-
var orderedChildren = OrderItems(children, keyColumnIndex, ascending).ToList();
313+
var depth = children[0].depth;
314+
var isSkipSortingTarget = GetSkipSortingDepths().Contains(depth);
315+
var orderedChildren = isSkipSortingTarget
316+
? new List<TreeViewItem>(children)
317+
: OrderItems(children, keyColumnIndex, ascending).ToList();
314318

315319
children.Clear();
316320
foreach (var orderedChild in orderedChildren) children.Add(orderedChild);
@@ -319,5 +323,10 @@ private void SortHierarchical(IList<TreeViewItem> children, int keyColumnIndex,
319323
if (child != null)
320324
SortHierarchical(child.children, keyColumnIndex, ascending);
321325
}
326+
327+
protected virtual IEnumerable<int> GetSkipSortingDepths()
328+
{
329+
return Array.Empty<int>();
330+
}
322331
}
323332
}

0 commit comments

Comments
 (0)