Skip to content

Commit

Permalink
Merge pull request #1368 from anatawa12/add-remove-button
Browse files Browse the repository at this point in the history
feat: add remove button for prefab safe set
  • Loading branch information
anatawa12 authored Dec 8, 2024
2 parents e1ecba5 + 363f0dd commit a681655
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- `-` button for prefab safe set `#1368`

### Changed

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- `-` button for prefab safe set `#1368`

### Changed

Expand Down
35 changes: 28 additions & 7 deletions Internal/PrefabSafeSet/Editor/Set/PrefabSafeSetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions Localization/en-us.po
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit a681655

Please sign in to comment.