Skip to content

Commit 0f06183

Browse files
committed
fix edit multiple notes bugs
1 parent 74ca136 commit 0f06183

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

Editor/LazyNoteEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace DCFApixels.Notes.Editors
55
{
6+
using static NotesConsts;
67
[CustomEditor(typeof(LazyNote))]
78
internal class LazyNoteEditor : Editor
89
{
@@ -61,7 +62,7 @@ public override void OnInspectorGUI()
6162

6263
GUIStyle gUIStylex = new GUIStyle(EditorStyles.helpBox);
6364
heightProp.floatValue = EditorGUILayout.FloatField("↕", heightProp.floatValue, gUIStylex, GUILayout.MaxWidth(58));
64-
heightProp.floatValue = Mathf.Max(20f, heightProp.floatValue);
65+
heightProp.floatValue = Mathf.Max(MIN_NOTE_HEIGHT, heightProp.floatValue);
6566
GUI.color = defaultColor;
6667
EditorGUIUtility.labelWidth = originalValue;
6768

Editor/NoteEditor.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace DCFApixels.Notes.Editors
55
{
6+
using static NotesConsts;
67
[CustomEditor(typeof(Note))]
78
[CanEditMultipleObjects]
89
internal class NoteEditor : Editor
@@ -85,12 +86,11 @@ public override void OnInspectorGUI()
8586
Color defaultColor = GUI.color;
8687
Color defaultBackgroundColor = GUI.backgroundColor;
8788

88-
AuthorInfo author = Settings.GetAuthorInfoOrDummy(authorProp.intValue);
89-
NoteTypeInfo noteType = Settings.GetNoteTypeInfoOrDummy(typeProp.intValue);
89+
AuthorInfo author = Settings.GetAuthorInfoOrDummy(authorProp.hasMultipleDifferentValues ? 0 : authorProp.intValue);
90+
NoteTypeInfo noteType = Settings.GetNoteTypeInfoOrDummy(typeProp.hasMultipleDifferentValues ? 0 : typeProp.intValue);
9091
Color headerColor = author.color;
9192
Color bodyColor = noteType.color;
9293

93-
EditorGUI.BeginChangeCheck();
9494

9595
Color headerBackColor = NormalizeBackgroundColor(headerColor);
9696

@@ -145,8 +145,12 @@ public override void OnInspectorGUI()
145145
GUI.color = new Color(0.2f, 0.2f, 0.2f);
146146

147147
GUIStyle gUIStylex = new GUIStyle(EditorStyles.helpBox);
148-
heightProp.floatValue = EditorGUILayout.FloatField("↕", heightProp.floatValue, gUIStylex, GUILayout.MaxWidth(58));
149-
heightProp.floatValue = Mathf.Max(20f, heightProp.floatValue);
148+
EditorGUI.BeginChangeCheck();
149+
float newHeight = EditorGUILayout.FloatField("↕", heightProp.hasMultipleDifferentValues ? DEFAULT_NOTE_HEIGHT : heightProp.floatValue, gUIStylex, GUILayout.MaxWidth(58));
150+
if (EditorGUI.EndChangeCheck())
151+
{
152+
heightProp.floatValue = Mathf.Max(newHeight, MIN_NOTE_HEIGHT);
153+
}
150154
EditorGUIUtility.labelWidth = originalValue;
151155

152156

@@ -160,11 +164,16 @@ public override void OnInspectorGUI()
160164

161165
GUILayout.Box(_lineTex, GUILayout.Height(1), GUILayout.ExpandWidth(true));
162166

163-
textProp.stringValue = EditorGUILayout.TextArea(textProp.stringValue, areastyle, GUILayout.Height(heightProp.floatValue));
167+
EditorGUI.BeginChangeCheck();
168+
string newValue = EditorGUILayout.TextArea(textProp.hasMultipleDifferentValues? "-" : textProp.stringValue, areastyle, GUILayout.Height(heightProp.floatValue));
169+
if (EditorGUI.EndChangeCheck())
170+
{
171+
textProp.stringValue = newValue;
172+
}
173+
164174
GUI.backgroundColor = defaultBackgroundColor;
165175

166176
serializedObject.ApplyModifiedProperties();
167-
EditorGUI.EndChangeCheck();
168177
}
169178

170179
private void DrawNote(Note target, SerializedObject serializedObject)

Runtime/Consts.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ internal class NotesConsts
88
public const string AUTHOR = "DCFApixels";
99
public const string NOTE_SEPARATOR = ">-<";
1010

11+
public const float DEFAULT_NOTE_HEIGHT = 100f;
12+
public const float MIN_NOTE_HEIGHT = 20f;
13+
1114
public const string STICKER_NAME = "Sticker";
1215
public const string ANONYMOUS_NAME = "Anonymous";
1316
public static readonly Color STICKER_COLOR = new Color(1f, 0.8f, 0.3f, 1f);

Runtime/LazyNote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class LazyNote : MonoBehaviour
1111
[SerializeField]
1212
private string _text = "Enter text...";
1313
[SerializeField]
14-
private float _height = 100f;
14+
private float _height = DEFAULT_NOTE_HEIGHT;
1515
[SerializeField]
1616
private Color _color = STICKER_COLOR;
1717
[SerializeField]

Runtime/Note.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace DCFApixels.Notes
66
{
7+
using static NotesConsts;
78
[AddComponentMenu("Notes/" + nameof(Note), 30)]
89
internal class Note : MonoBehaviour
910
{
1011
#if UNITY_EDITOR
1112
[SerializeField]
1213
private string _text = "Enter text...";
1314
[SerializeField]
14-
private float _height = 100f;
15+
private float _height = DEFAULT_NOTE_HEIGHT;
1516
[SerializeField]
1617
private bool _drawIcon = true;
1718

0 commit comments

Comments
 (0)