From 613eeeb3d86a001047d07a4c3960863588dc99b3 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 8 Dec 2024 17:14:42 +0900 Subject: [PATCH 1/2] feat: add remove button for prefab safe set --- .../Editor/Set/PrefabSafeSetEditor.cs | 35 +++++++++++++++---- Localization/en-us.po | 3 ++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Internal/PrefabSafeSet/Editor/Set/PrefabSafeSetEditor.cs b/Internal/PrefabSafeSet/Editor/Set/PrefabSafeSetEditor.cs index 26a94b1c6..9832bca2f 100644 --- a/Internal/PrefabSafeSet/Editor/Set/PrefabSafeSetEditor.cs +++ b/Internal/PrefabSafeSet/Editor/Set/PrefabSafeSetEditor.cs @@ -12,7 +12,7 @@ internal static class EditorStatics { private static GUIContent WithLocalization(GUIContent content, string key, string? tooltip = null) { - content.text = AAOL10N.Tr(key); + content.text = key.StartsWith('\0') ? key.Substring(1) : AAOL10N.Tr(key); if (tooltip != null) content.tooltip = AAOL10N.Tr(tooltip); return content; @@ -37,7 +37,11 @@ private static GUIContent WithLocalization(GUIContent content, string key, strin private static readonly GUIContent ForceAddButtonBacked = new GUIContent(); public static GUIContent ForceAddButton => WithLocalization(ForceAddButtonBacked, - "+", "PrefabSafeSet:tooltip:Force Add Button"); + "\0+", "PrefabSafeSet:tooltip:Force Add Button"); + + private static readonly GUIContent RemoveButtonBacked = new GUIContent(); + public static GUIContent RemoveButton => WithLocalization(RemoveButtonBacked, + "\0-", "PrefabSafeSet:tooltip:Remove Button"); } [CustomPropertyDrawer(typeof(PrefabSafeSet<>), true)] @@ -294,12 +298,24 @@ private ModificationKind OnePrefabElement(Rect position, GUIContent label, IElem ModificationKind kind) { // layout - var fieldPosition = position; + var buttonWidth = EditorGUIUtility.singleLineHeight; + var spacing = EditorGUIUtility.standardVerticalSpacing; + + var fieldPosition = position with + { + width = position.width - (buttonWidth + spacing) * 2, + }; // two buttons - fieldPosition.width -= EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - var addButtonPosition = new Rect( - fieldPosition.xMax + EditorGUIUtility.standardVerticalSpacing, position.y, - EditorGUIUtility.singleLineHeight, position.height); + var addButtonPosition = position with + { + x = fieldPosition.xMax + spacing, + width = buttonWidth, + }; + var removeButtonPosition = position with + { + x = addButtonPosition.xMax + spacing, + width = buttonWidth, + }; var result = ModificationKind.Natural; @@ -315,6 +331,11 @@ private ModificationKind OnePrefabElement(Rect position, GUIContent label, IElem if (GUI.Button(addButtonPosition, EditorStatics.ForceAddButton)) result = ModificationKind.Add; EditorGUI.EndDisabledGroup(); + + EditorGUI.BeginDisabledGroup(kind == ModificationKind.Remove); + if (GUI.Button(removeButtonPosition, EditorStatics.RemoveButton)) + result = ModificationKind.Remove; + EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); } diff --git a/Localization/en-us.po b/Localization/en-us.po index a2aa9b115..a9c695e7d 100644 --- a/Localization/en-us.po +++ b/Localization/en-us.po @@ -37,6 +37,9 @@ msgstr "Drag & Drop value to here to add element to this set." msgid "PrefabSafeSet:tooltip:Force Add Button" msgstr "Add this element in current prefab modifications." +msgid "PrefabSafeSet:tooltip:Remove Button" +msgstr "Remove Element" + # , csharp-format msgid "PrefabSafeSet:label:Element {0}" msgstr "Element {0}" From 363f0ddc00564720e2b643a2e9f809edc89685e2 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 8 Dec 2024 17:21:35 +0900 Subject: [PATCH 2/2] docs(changelog): `-` button for prefab safe seet --- CHANGELOG-PRERELEASE.md | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 48ec60efb..717a02bda 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added +- `-` button for prefab safe set `#1368` ### Changed diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db6943b5..b0e5a29b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added +- `-` button for prefab safe set `#1368` ### Changed