|
1 | | -// Visual Pinball Engine |
2 | | -// Copyright (C) 2022 freezy and VPE Team |
| 1 | +// // Visual Pinball Engine |
| 2 | +// // Copyright (C) 2022 freezy and VPE Team |
| 3 | +// // |
| 4 | +// // This program is free software: you can redistribute it and/or modify |
| 5 | +// // it under the terms of the GNU General Public License as published by |
| 6 | +// // the Free Software Foundation, either version 3 of the License, or |
| 7 | +// // (at your option) any later version. |
| 8 | +// // |
| 9 | +// // This program is distributed in the hope that it will be useful, |
| 10 | +// // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// // GNU General Public License for more details. |
| 13 | +// // |
| 14 | +// // You should have received a copy of the GNU General Public License |
| 15 | +// // along with this program. If not, see <https://www.gnu.org/licenses/>. |
3 | 16 | // |
4 | | -// This program is free software: you can redistribute it and/or modify |
5 | | -// it under the terms of the GNU General Public License as published by |
6 | | -// the Free Software Foundation, either version 3 of the License, or |
7 | | -// (at your option) any later version. |
| 17 | +// using UnityEditor; |
| 18 | +// using UnityEngine; |
8 | 19 | // |
9 | | -// This program is distributed in the hope that it will be useful, |
10 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | -// GNU General Public License for more details. |
| 20 | +// namespace VisualPinball.Unity.VisualScripting.Editor |
| 21 | +// { |
| 22 | +// [CustomPropertyDrawer(typeof(DisplayDefinition))] |
| 23 | +// public class DisplayDefinitionPropertyDrawer : PropertyDrawer |
| 24 | +// { |
| 25 | +// private const float Padding = 2f; |
| 26 | +// |
| 27 | +// public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
| 28 | +// { |
| 29 | +// return base.GetPropertyHeight(property, label); |
| 30 | +// // var f = property.FindPropertyRelative(nameof(DisplayDefinition.SupportedFormats)); |
| 31 | +// // |
| 32 | +// // return 5 * (EditorGUIUtility.singleLineHeight + Padding); |
| 33 | +// } |
| 34 | +// |
| 35 | +// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
| 36 | +// { |
| 37 | +// var idProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Id)); |
| 38 | +// var widthProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Width)); |
| 39 | +// var heightProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Height)); |
| 40 | +// |
| 41 | +// var contentPosition = position; |
| 42 | +// contentPosition.height = EditorGUIUtility.singleLineHeight; |
| 43 | +// |
| 44 | +// //EditorGUI.BeginProperty(position, label, property); |
| 45 | +// EditorGUI.PropertyField(contentPosition, idProperty, new GUIContent("ID:")); |
| 46 | +// //EditorGUI.EndProperty(); |
| 47 | +// position.y += EditorGUIUtility.singleLineHeight + Padding; |
| 48 | +// |
| 49 | +// contentPosition = EditorGUI.PrefixLabel(position, new GUIContent("Size:")); |
| 50 | +// contentPosition.height = EditorGUIUtility.singleLineHeight; |
| 51 | +// |
| 52 | +// var half = contentPosition.width / 2; |
| 53 | +// GUI.skin.label.padding = new RectOffset(3, 3, 6, 6); |
| 54 | +// |
| 55 | +// //show the X and Y from the point |
| 56 | +// var oldLabelWidth = EditorGUIUtility.labelWidth; |
| 57 | +// EditorGUIUtility.labelWidth = 14f; |
| 58 | +// contentPosition.width *= 0.5f; |
| 59 | +// EditorGUI.indentLevel = 0; |
| 60 | +// |
| 61 | +// // Begin/end property & change check make each field |
| 62 | +// // behave correctly when multi-object editing. |
| 63 | +// EditorGUI.BeginProperty(contentPosition, label, widthProperty); |
| 64 | +// { |
| 65 | +// EditorGUI.BeginChangeCheck(); |
| 66 | +// var newVal = EditorGUI.IntField(contentPosition, new GUIContent("W"), widthProperty.intValue); |
| 67 | +// if (EditorGUI.EndChangeCheck()) |
| 68 | +// widthProperty.intValue = newVal; |
| 69 | +// } |
| 70 | +// EditorGUI.EndProperty(); |
| 71 | +// |
| 72 | +// contentPosition.x += half; |
| 73 | +// EditorGUI.BeginProperty(contentPosition, label, heightProperty); |
| 74 | +// { |
| 75 | +// EditorGUI.BeginChangeCheck(); |
| 76 | +// var newVal = EditorGUI.IntField(contentPosition, new GUIContent("H"), heightProperty.intValue); |
| 77 | +// if (EditorGUI.EndChangeCheck()) |
| 78 | +// heightProperty.intValue = newVal; |
| 79 | +// } |
| 80 | +// EditorGUI.EndProperty(); |
| 81 | +// |
| 82 | +// EditorGUIUtility.labelWidth = oldLabelWidth; |
| 83 | +// |
| 84 | +// var supportedFormatsProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportedFormats)); |
| 85 | +// |
| 86 | +// position.y += EditorGUIUtility.singleLineHeight + Padding; |
| 87 | +// contentPosition = position; |
| 88 | +// contentPosition.height = EditorGUIUtility.singleLineHeight; |
| 89 | +// EditorGUI.PropertyField(contentPosition, supportedFormatsProperty, new GUIContent("Supported Formats:")); |
| 90 | +// } |
| 91 | +// } |
| 92 | +// } |
13 | 93 | // |
14 | | -// You should have received a copy of the GNU General Public License |
15 | | -// along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | | - |
17 | | -using System; |
18 | | -using UnityEditor; |
19 | | -using UnityEngine; |
20 | | - |
21 | | -namespace VisualPinball.Unity.VisualScripting.Editor |
22 | | -{ |
23 | | - [CustomPropertyDrawer(typeof(DisplayDefinition))] |
24 | | - public class DisplayDefinitionPropertyDrawer : PropertyDrawer |
25 | | - { |
26 | | - private const float Padding = 2f; |
27 | | - |
28 | | - public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
29 | | - { |
30 | | - return 5 * (EditorGUIUtility.singleLineHeight + Padding); |
31 | | - } |
32 | | - |
33 | | - public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
34 | | - { |
35 | | - var idProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Id)); |
36 | | - var widthProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Width)); |
37 | | - var heightProperty = property.FindPropertyRelative(nameof(DisplayDefinition.Height)); |
38 | | - |
39 | | - var contentPosition = position; |
40 | | - contentPosition.height = EditorGUIUtility.singleLineHeight; |
41 | | - |
42 | | - //EditorGUI.BeginProperty(position, label, property); |
43 | | - EditorGUI.PropertyField(contentPosition, idProperty, new GUIContent("ID:")); |
44 | | - //EditorGUI.EndProperty(); |
45 | | - position.y += EditorGUIUtility.singleLineHeight + Padding; |
46 | | - |
47 | | - contentPosition = EditorGUI.PrefixLabel(position, new GUIContent("Size:")); |
48 | | - contentPosition.height = EditorGUIUtility.singleLineHeight; |
49 | | - |
50 | | - var half = contentPosition.width / 2; |
51 | | - GUI.skin.label.padding = new RectOffset(3, 3, 6, 6); |
52 | | - |
53 | | - //show the X and Y from the point |
54 | | - var oldLabelWidth = EditorGUIUtility.labelWidth; |
55 | | - EditorGUIUtility.labelWidth = 14f; |
56 | | - contentPosition.width *= 0.5f; |
57 | | - EditorGUI.indentLevel = 0; |
58 | | - |
59 | | - // Begin/end property & change check make each field |
60 | | - // behave correctly when multi-object editing. |
61 | | - EditorGUI.BeginProperty(contentPosition, label, widthProperty); |
62 | | - { |
63 | | - EditorGUI.BeginChangeCheck(); |
64 | | - var newVal = EditorGUI.IntField(contentPosition, new GUIContent("W"), widthProperty.intValue); |
65 | | - if (EditorGUI.EndChangeCheck()) |
66 | | - widthProperty.intValue = newVal; |
67 | | - } |
68 | | - EditorGUI.EndProperty(); |
69 | | - |
70 | | - contentPosition.x += half; |
71 | | - EditorGUI.BeginProperty(contentPosition, label, heightProperty); |
72 | | - { |
73 | | - EditorGUI.BeginChangeCheck(); |
74 | | - var newVal = EditorGUI.IntField(contentPosition, new GUIContent("H"), heightProperty.intValue); |
75 | | - if (EditorGUI.EndChangeCheck()) |
76 | | - heightProperty.intValue = newVal; |
77 | | - } |
78 | | - EditorGUI.EndProperty(); |
79 | | - |
80 | | - EditorGUIUtility.labelWidth = oldLabelWidth; |
81 | | - |
82 | | - var supportsNumericInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsNumericInput)); |
83 | | - var supportsTextInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsTextInput)); |
84 | | - var supportsImageInputProperty = property.FindPropertyRelative(nameof(DisplayDefinition.SupportsImageInput)); |
85 | | - |
86 | | - |
87 | | - position.y += EditorGUIUtility.singleLineHeight + Padding; |
88 | | - contentPosition = position; |
89 | | - contentPosition.height = EditorGUIUtility.singleLineHeight; |
90 | | - EditorGUI.PropertyField(contentPosition, supportsNumericInputProperty, new GUIContent("Numeric:")); |
91 | | - contentPosition.y += EditorGUIUtility.singleLineHeight + Padding; |
92 | | - EditorGUI.PropertyField(contentPosition, supportsTextInputProperty, new GUIContent("Text:")); |
93 | | - contentPosition.y += EditorGUIUtility.singleLineHeight + Padding; |
94 | | - EditorGUI.PropertyField(contentPosition, supportsImageInputProperty, new GUIContent("Data:")); |
95 | | - } |
96 | | - } |
97 | | -} |
98 | | - |
0 commit comments