11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Threading ;
45using System . Windows ;
@@ -30,9 +31,9 @@ public partial class ChunkViewModel
3031 /// Helper method to expand and select a child node.
3132 /// </summary>
3233 /// <param name="cvm">The node to expand</param>
33- /// <param name="selectChild ">If parameter is set to false or cvm has no children, will select cvm. Otherwise, will select first child.</param>
34+ /// <param name="selectFirstChild ">If parameter is set to false or cvm has no children, will select cvm. Otherwise, will select first child.</param>
3435 /// <param name="expandOnlyChild">If cvm has only one child, it will be expanded as well.</param>
35- private void ExpandAndSelect ( ChunkViewModel ? cvm , bool selectChild = false , bool expandOnlyChild = false )
36+ private void ExpandAndSelect ( ChunkViewModel ? cvm , bool selectFirstChild = false , bool expandOnlyChild = false )
3637 {
3738 if ( cvm is null )
3839 {
@@ -51,16 +52,45 @@ private void ExpandAndSelect(ChunkViewModel? cvm, bool selectChild = false, bool
5152 return ;
5253 }
5354
54- if ( ! selectChild || cvm . TVProperties . Count == 0 )
55+ if ( ! selectFirstChild || cvm . TVProperties . Count == 0 )
5556 {
5657 Tab . SetSelection ( cvm ) ;
5758 return ;
5859 }
5960
6061 Tab . SetSelection ( cvm . TVProperties [ 0 ] ) ;
6162 }
63+
64+
65+ /// <summary>
66+ /// Map of data types with selection paths
67+ /// </summary>
68+ private static readonly Dictionary < Type , List < string > > s_typesAndChildren = new ( )
69+ {
70+ { typeof ( CMaterialInstance ) , [ "values" ] } , // mi file
71+ { typeof ( CMaterialTemplate ) , [ "parameters" , "2" ] } , // .mt / .remt
72+ { typeof ( Multilayer_Setup ) , [ "layers" ] } , // .mt / .remt
73+ { typeof ( appearanceAppearanceResource ) , [ "appearances" ] } , // .app
74+ { typeof ( C2dArray ) , [ "compiledData" ] } , // .csv
75+ { typeof ( JsonResource ) , [ "root" ] } , // .json
76+ { typeof ( gameuiSwitcherInfo ) , [ "options" ] } , // .inkcharcustomization
77+ { typeof ( gameuiOptionsGroup ) , [ "options" ] } , // .inkcharcustomization
78+ { typeof ( questQuestPhaseResource ) , [ "graph" ] } , // .questphase
79+ } ;
80+
81+ private void ExpandNodeAndParents ( )
82+ {
83+ if ( Parent ? . IsExpanded == false )
84+ {
85+ Parent . ExpandNodeAndParents ( ) ;
86+ }
87+
88+ IsExpanded = true ;
89+ }
90+
6291 /// <summary>
6392 /// Called from ChunkViewmodelFactory after initializing the chunk.
93+ /// For quest node expansion, see RedTypeToChunkViewModelCollectionConverter.AutoExpandProperties
6494 /// </summary>
6595 public ChunkViewModel SetInitialExpansionState ( )
6696 {
@@ -69,20 +99,19 @@ public ChunkViewModel SetInitialExpansionState()
6999 return this ;
70100 }
71101
102+ if ( s_typesAndChildren . TryGetValue ( PropertyType , out var paths ) )
103+ {
104+ CalculatePropertiesRecursive ( ) ;
105+ var node = GetPropertyChild ( [ ..paths ] ) ;
106+ if ( node is not null )
107+ {
108+ ExpandAndSelect ( node , true ) ;
109+ return this ;
110+ }
111+ }
112+
72113 switch ( ResolvedData )
73114 {
74- // .mi file
75- case CMaterialInstance when GetPropertyChild ( "values" ) is ChunkViewModel child :
76- ExpandAndSelect ( child , true ) ;
77- break ;
78- // .mt file
79- case CMaterialTemplate when GetPropertyChild ( "parameters" , "2" ) is ChunkViewModel child :
80- ExpandAndSelect ( child , true ) ;
81- break ;
82- // .mlsetup file
83- case Multilayer_Setup when GetPropertyChild ( "layers" ) is ChunkViewModel child :
84- ExpandAndSelect ( child , true ) ;
85- break ;
86115 // .inkatlas
87116 case inkTextureAtlas when GetPropertyChild ( "slots" ) is ChunkViewModel child :
88117 ExpandAndSelect ( child , true ) ;
@@ -95,10 +124,6 @@ public ChunkViewModel SetInitialExpansionState()
95124 }
96125 }
97126 break ;
98- // .app file
99- case appearanceAppearanceResource when GetPropertyChild ( "appearances" ) is ChunkViewModel child :
100- ExpandAndSelect ( child , false , true ) ;
101- break ;
102127 // .ent file
103128 case entEntityTemplate template :
104129
@@ -107,6 +132,8 @@ public ChunkViewModel SetInitialExpansionState()
107132 var nodeToExpand = template . Appearances . Count == 0 ? components : appearances ;
108133 ExpandAndSelect ( nodeToExpand , true , true ) ;
109134 break ;
135+
136+ #region mesh
110137 // .mesh file
111138 case CMesh :
112139 if ( GetPropertyChild ( "appearances" ) is { TVProperties . Count : > 0 } meshAppearances )
@@ -131,14 +158,9 @@ public ChunkViewModel SetInitialExpansionState()
131158 }
132159
133160 break ;
134- // .csv
135- case C2dArray when GetPropertyChild ( "compiledData" ) is ChunkViewModel child :
136- ExpandAndSelect ( child , true ) ;
137- break ;
138- // .json
139- case JsonResource when GetPropertyChild ( "root" ) is ChunkViewModel child :
140- ExpandAndSelect ( child , true ) ;
141- break ;
161+
162+ #endregion
163+
142164 // streamingsector
143165 case worldStreamingSector :
144166 // will run into stack overflow due to race conditions if we do this straight away. Let's wait a bit!
0 commit comments