|
7 | 7 |
|
8 | 8 | namespace Toolbox.Editor |
9 | 9 | { |
| 10 | + using Toolbox.Attributes; |
10 | 11 | using Toolbox.Editor.Drawers; |
11 | 12 |
|
12 | 13 | /// <summary> |
@@ -83,6 +84,12 @@ internal class ToolboxPropertyHandler |
83 | 84 | /// </summary> |
84 | 85 | private bool hasToolboxConditionDrawer; |
85 | 86 |
|
| 87 | + /// <summary> |
| 88 | + /// Temporary solution to cache all attributes responsible for overriding label. |
| 89 | + /// This will be replaced with validation attributes. |
| 90 | + /// </summary> |
| 91 | + private ILabelProcessorAttribute labelProcessorAttribute; |
| 92 | + |
86 | 93 |
|
87 | 94 | /// <summary> |
88 | 95 | /// Constructor prepares all property-related data for custom drawing. |
@@ -166,26 +173,27 @@ private void CheckIfPropertyHasPropertyDrawer(Type type) |
166 | 173 |
|
167 | 174 | private void HandleNewAttribute(PropertyAttribute attribute) |
168 | 175 | { |
169 | | - if (!isChild) |
| 176 | + //NOTE: setting tooltip and labels is valid only for parent or single properties |
| 177 | + //it's a bit ugly but, it's the only semi-acceptable way to support built-in TooltipAttribute |
| 178 | + //TODO: move these attributes to validation drawers |
| 179 | + switch (attribute) |
170 | 180 | { |
171 | | - //NOTE: setting tooltip and labels is valid only for parent or single properties |
172 | | - //it's a bit ugly but, it's the only semi-acceptable way to support built-in TooltipAttribute |
173 | | - switch (attribute) |
174 | | - { |
175 | | - case TooltipAttribute a: |
176 | | - label.tooltip = a.tooltip; |
177 | | - return; |
178 | | - case NewLabelAttribute a: |
179 | | - label.text = a.NewLabel; |
180 | | - return; |
181 | | - case LabelByChildAttribute a: |
182 | | - if (!isArray) |
183 | | - { |
184 | | - PropertyUtility.OverrideLabelByChild(label, property, a.ChildName); |
185 | | - } |
186 | | - |
187 | | - return; |
188 | | - } |
| 181 | + case TooltipAttribute a: |
| 182 | + label.tooltip = a.tooltip; |
| 183 | + return; |
| 184 | + case NewLabelAttribute a: |
| 185 | + if (!isChild) |
| 186 | + { |
| 187 | + labelProcessorAttribute = a; |
| 188 | + } |
| 189 | + return; |
| 190 | + case LabelByChildAttribute a: |
| 191 | + if (!isArray) |
| 192 | + { |
| 193 | + labelProcessorAttribute = a; |
| 194 | + } |
| 195 | + |
| 196 | + return; |
189 | 197 | } |
190 | 198 |
|
191 | 199 | var attributeType = attribute.GetType(); |
@@ -276,6 +284,8 @@ private bool TryAssignConditionAttribute(ToolboxConditionAttribute attribute) |
276 | 284 |
|
277 | 285 | private void DrawProperty(SerializedProperty property, GUIContent label) |
278 | 286 | { |
| 287 | + ProcessLabel(property, label); |
| 288 | + |
279 | 289 | //get toolbox drawer for the property or draw it in the default way |
280 | 290 | if (hasToolboxPropertyDrawer && (!hasBuiltInPropertyDrawer || isArray)) |
281 | 291 | { |
@@ -326,6 +336,25 @@ private void CloseDecoratorDrawers(PropertyCondition conditionState = PropertyCo |
326 | 336 | } |
327 | 337 | } |
328 | 338 |
|
| 339 | + //TODO: replace this method with validation attributes |
| 340 | + private void ProcessLabel(SerializedProperty property, GUIContent label) |
| 341 | + { |
| 342 | + if (labelProcessorAttribute == null) |
| 343 | + { |
| 344 | + return; |
| 345 | + } |
| 346 | + |
| 347 | + switch (labelProcessorAttribute) |
| 348 | + { |
| 349 | + case NewLabelAttribute a: |
| 350 | + label.text = a.NewLabel; |
| 351 | + return; |
| 352 | + case LabelByChildAttribute a: |
| 353 | + PropertyUtility.OverrideLabelByChild(label, property, a.ChildName); |
| 354 | + return; |
| 355 | + } |
| 356 | + } |
| 357 | + |
329 | 358 | private void HandleDecorator(ToolboxDecoratorAttribute attribute, bool onBegin, PropertyCondition conditionState = PropertyCondition.Valid) |
330 | 359 | { |
331 | 360 | var drawer = ToolboxDrawerModule.GetDecoratorDrawer(attribute); |
|
0 commit comments