removed a ton of xml comments and such
This commit is contained in:
@@ -3,50 +3,39 @@ using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Jovian.EncounterSystem.Editor {
|
||||
/// <summary>
|
||||
/// Drawer for <see cref="DialogLineRef"/>. Shows the library + id picker on one row, the inline
|
||||
/// fallback text area underneath, and a resolved preview below that. Preserves WYSIWYG — the
|
||||
/// final text is always visible.
|
||||
/// </summary>
|
||||
/// <summary>Id dropdown (library inherited from the owning asset's <c>library</c> field) + inline fallback + resolved preview.</summary>
|
||||
[CustomPropertyDrawer(typeof(DialogLineRef))]
|
||||
public class DialogLineRefDrawer : PropertyDrawer {
|
||||
private const string NonePlaceholder = "<none>";
|
||||
private const string EmptyLibraryPlaceholder = "<assign a library first>";
|
||||
private const string EmptyLibraryPlaceholder = "<set library on the parent asset>";
|
||||
private const float PreviewHeight = 32f;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||
var libraryProp = property.FindPropertyRelative("library");
|
||||
var idProp = property.FindPropertyRelative("id");
|
||||
var inlineProp = property.FindPropertyRelative("inlineText");
|
||||
var library = ResolveLibrary(property);
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
var lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
var spacing = EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
var libraryRect = new Rect(position.x, position.y, position.width, lineHeight);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.PropertyField(libraryRect, libraryProp, label);
|
||||
var libraryChanged = EditorGUI.EndChangeCheck();
|
||||
var idRect = new Rect(position.x, position.y, position.width, lineHeight);
|
||||
DrawIdPicker(idRect, library, idProp, label);
|
||||
|
||||
using(new EditorGUI.IndentLevelScope()) {
|
||||
var idRect = new Rect(position.x, position.y + lineHeight + spacing, position.width, lineHeight);
|
||||
DrawIdPicker(idRect, libraryProp, idProp, libraryChanged);
|
||||
var inlineRect = new Rect(
|
||||
position.x,
|
||||
position.y + lineHeight + spacing,
|
||||
position.width,
|
||||
lineHeight * 2);
|
||||
EditorGUI.PropertyField(inlineRect, inlineProp, new GUIContent("Inline"));
|
||||
|
||||
var inlineRect = new Rect(
|
||||
position.x,
|
||||
position.y + (lineHeight + spacing) * 2,
|
||||
position.width,
|
||||
lineHeight * 2);
|
||||
EditorGUI.PropertyField(inlineRect, inlineProp, new GUIContent("Inline"));
|
||||
|
||||
var previewRect = new Rect(
|
||||
position.x,
|
||||
position.y + (lineHeight + spacing) * 2 + lineHeight * 2 + spacing,
|
||||
position.width,
|
||||
PreviewHeight);
|
||||
DrawPreview(previewRect, libraryProp, idProp, inlineProp);
|
||||
}
|
||||
var previewRect = new Rect(
|
||||
position.x,
|
||||
position.y + lineHeight + spacing + lineHeight * 2 + spacing,
|
||||
position.width,
|
||||
PreviewHeight);
|
||||
DrawPreview(previewRect, library, idProp, inlineProp);
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
@@ -54,18 +43,19 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||
var lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
var spacing = EditorGUIUtility.standardVerticalSpacing;
|
||||
// library + id + (inline 2 lines) + preview
|
||||
return (lineHeight + spacing) * 2 + lineHeight * 2 + spacing + PreviewHeight;
|
||||
// id + (inline 2 lines) + preview
|
||||
return lineHeight + spacing + lineHeight * 2 + spacing + PreviewHeight;
|
||||
}
|
||||
|
||||
private static void DrawIdPicker(Rect rect, SerializedProperty libraryProp, SerializedProperty idProp, bool libraryChanged) {
|
||||
var library = libraryProp.objectReferenceValue as DialogLineLibrary;
|
||||
private static DialogLineLibrary ResolveLibrary(SerializedProperty property) {
|
||||
var libraryProp = property.serializedObject.FindProperty("library");
|
||||
return libraryProp?.objectReferenceValue as DialogLineLibrary;
|
||||
}
|
||||
|
||||
private static void DrawIdPicker(Rect rect, DialogLineLibrary library, SerializedProperty idProp, GUIContent label) {
|
||||
if(library == null || library.lines == null || library.lines.Count == 0) {
|
||||
using(new EditorGUI.DisabledScope(true)) {
|
||||
EditorGUI.Popup(rect, "Id", 0, new[] { EmptyLibraryPlaceholder });
|
||||
}
|
||||
if(libraryChanged) {
|
||||
idProp.stringValue = string.Empty;
|
||||
EditorGUI.Popup(rect, label.text, 0, new[] { EmptyLibraryPlaceholder });
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -82,24 +72,18 @@ namespace Jovian.EncounterSystem.Editor {
|
||||
var id = line?.id ?? string.Empty;
|
||||
ids[i + 1] = id;
|
||||
names[i + 1] = string.IsNullOrEmpty(id) ? $"<unnamed {i}>" : id;
|
||||
if(!libraryChanged && id == idProp.stringValue && !string.IsNullOrEmpty(id)) {
|
||||
if(id == idProp.stringValue && !string.IsNullOrEmpty(id)) {
|
||||
currentIndex = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(libraryChanged) {
|
||||
idProp.stringValue = string.Empty;
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
var newIndex = EditorGUI.Popup(rect, "Id", currentIndex, names);
|
||||
var newIndex = EditorGUI.Popup(rect, label.text, currentIndex, names);
|
||||
if(newIndex != currentIndex) {
|
||||
idProp.stringValue = ids[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawPreview(Rect rect, SerializedProperty libraryProp, SerializedProperty idProp, SerializedProperty inlineProp) {
|
||||
var library = libraryProp.objectReferenceValue as DialogLineLibrary;
|
||||
private static void DrawPreview(Rect rect, DialogLineLibrary library, SerializedProperty idProp, SerializedProperty inlineProp) {
|
||||
var id = idProp.stringValue;
|
||||
var inline = inlineProp.stringValue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user