@@ -19,8 +19,11 @@ internal class StatsOptionsControl<T> : TableLayoutPanel where T : StatOptionsBa
19
19
protected Button BtRemove ;
20
20
protected TextBox TbOptionsName ;
21
21
protected Label LbParent ;
22
+ protected Label LbParentParent ;
23
+ protected Label LbAffectedSpecies ;
22
24
protected StatsOptions < T > SelectedStatsOptions ;
23
25
protected StatsOptionsSettings < T > StatsOptionsSettings ;
26
+ protected TextBox TbAffectedSpecies ;
24
27
protected FlowLayoutPanel StatsContainer ;
25
28
protected ToolTip Tt ;
26
29
private bool _ignoreIndexChange ;
@@ -74,6 +77,22 @@ protected void InitializeControls(StatsOptionsSettings<T> settings, ToolTip tt)
74
77
CbbParent . SelectedIndexChanged += CbbParent_SelectedIndexChanged ;
75
78
flpHeaderControls . Controls . Add ( CbbParent ) ;
76
79
80
+ var marginLabelDefault = new Padding ( 5 , 7 , 5 , 0 ) ;
81
+
82
+ LbParentParent = new Label { Margin = marginLabelDefault , AutoSize = true } ;
83
+ tt . SetToolTip ( LbParentParent , "If the parent setting has no value for a stat, the parent's parent's values are used etc." ) ;
84
+ flpHeaderControls . Controls . Add ( LbParentParent ) ;
85
+ flpHeaderControls . SetFlowBreak ( LbParentParent , true ) ;
86
+
87
+ LbAffectedSpecies = new Label { Text = "Affected species: " , Margin = marginLabelDefault , AutoSize = true } ;
88
+ tt . SetToolTip ( LbAffectedSpecies , @"Comma separated list of species affected by this setting.
89
+ More specific identifier will be used first. Specificity order is
90
+ BlueprintPath > DescriptiveNameAndMod > DescriptiveName > Name" ) ;
91
+ flpHeaderControls . Controls . Add ( LbAffectedSpecies ) ;
92
+ TbAffectedSpecies = new TextBox { AutoSize = true , MinimumSize = new Size ( 50 , 0 ) } ;
93
+ flpHeaderControls . Controls . Add ( TbAffectedSpecies ) ;
94
+ TbAffectedSpecies . Leave += TbAffectedSpeciesLeave ;
95
+
77
96
InitializeStatControls ( ) ;
78
97
InitializeOptions ( ) ;
79
98
}
@@ -150,13 +169,47 @@ private void CbbOptions_SelectedIndexChanged(object sender, EventArgs e)
150
169
LbParent . Visible = isNotRoot ;
151
170
CbbParent . Visible = isNotRoot ;
152
171
BtRemove . Visible = isNotRoot ;
172
+ LbParentParent . Text = ParentsParentText ( SelectedStatsOptions . ParentOptions ) ;
173
+ LbAffectedSpecies . Visible = isNotRoot ;
174
+ TbAffectedSpecies . Visible = isNotRoot ;
175
+ TbAffectedSpecies . Text = SelectedStatsOptions . AffectedSpecies == null ? string . Empty : string . Join ( ", " , SelectedStatsOptions . AffectedSpecies ) ;
153
176
154
177
UpdateStatsControls ( isNotRoot ) ;
155
178
156
179
CbbParent . SelectedItem = SelectedStatsOptions . ParentOptions ;
157
180
this . ResumeDrawing ( ) ;
158
181
}
159
182
183
+ private void TbAffectedSpeciesLeave ( object sender , EventArgs e )
184
+ {
185
+ if ( SelectedStatsOptions == null ) return ;
186
+ var sp = TbAffectedSpecies . Text
187
+ . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries )
188
+ . Select ( s => s . Trim ( ) ) . Where ( s => ! string . IsNullOrEmpty ( s ) )
189
+ . Distinct ( )
190
+ . ToArray ( ) ;
191
+ SelectedStatsOptions . AffectedSpecies = sp . Any ( ) ? sp : null ;
192
+ }
193
+
194
+ private string ParentsParentText ( StatsOptions < T > selectedStatsOptions )
195
+ {
196
+ var maxGenerationsShown = 5 ;
197
+ var currentParent = selectedStatsOptions ? . ParentOptions ;
198
+ var parentText = string . Empty ;
199
+ while ( currentParent != null )
200
+ {
201
+ if ( maxGenerationsShown -- <= 0 )
202
+ {
203
+ parentText += " \u2794 …" ;
204
+ break ;
205
+ }
206
+ parentText += " \u2794 " + ( string . IsNullOrEmpty ( currentParent . Name ) ? currentParent . ToString ( ) : currentParent . Name ) ;
207
+ currentParent = currentParent . ParentOptions ;
208
+ }
209
+
210
+ return parentText ;
211
+ }
212
+
160
213
/// <summary>
161
214
/// Override this method to update the UI of the stat controls.
162
215
/// </summary>
@@ -167,7 +220,9 @@ private void CbbParent_SelectedIndexChanged(object sender, EventArgs e)
167
220
if ( _ignoreIndexChange ) return ;
168
221
SelectedStatsOptions = CbbOptions . SelectedItem as StatsOptions < T > ;
169
222
if ( SelectedStatsOptions == null ) return ;
170
- SelectedStatsOptions . ParentOptions = CbbParent . SelectedItem as StatsOptions < T > ;
223
+ var selectedParent = CbbParent . SelectedItem as StatsOptions < T > ;
224
+ if ( SelectedStatsOptions == selectedParent ) return ; // ignore if node itself is selected as parent
225
+ SelectedStatsOptions . ParentOptions = selectedParent ;
171
226
InitializeOptions ( true ) ;
172
227
StatsOptionsSettings . ClearSpeciesCache ( ) ;
173
228
}
@@ -187,6 +242,9 @@ private void TbOptionsName_Leave(object sender, EventArgs e)
187
242
StatsOptionsSettings . StatsOptionsDict . Add ( newName , SelectedStatsOptions ) ;
188
243
// update text in combobox
189
244
CbbOptions . Items [ CbbOptions . SelectedIndex ] = SelectedStatsOptions ;
245
+ var cbbParentIndex = CbbParent . Items . IndexOf ( SelectedStatsOptions ) ;
246
+ if ( cbbParentIndex >= 0 )
247
+ CbbParent . Items [ cbbParentIndex ] = SelectedStatsOptions ;
190
248
StatsOptionsSettings . ClearSpeciesCache ( ) ;
191
249
}
192
250
0 commit comments