Skip to content

Commit

Permalink
Fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ichenpipi committed Aug 18, 2023
1 parent 7d2478b commit 2ecf5f1
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 99 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.4] - 2023-08-18

- Fix bugs.

## [1.0.3] - 2023-08-10

- Fix bugs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ private void InitDropArea()
text = "Drop to Pin",
style =
{
paddingLeft = 0,
paddingRight = 0,
paddingLeft = 10,
paddingRight = 10,
fontSize = 40,
color = dropTipTextColor,
unityFontStyleAndWeight = FontStyle.Bold,
unityTextAlign = TextAnchor.MiddleCenter,
whiteSpace = WhiteSpace.Normal,
#if UNITY_2021_1_OR_NEWER
unityTextOutlineColor = new Color(0f, 0f, 0f, 1f),
unityTextOutlineWidth = 1,
Expand Down
24 changes: 13 additions & 11 deletions Editor/Scripts/Window/ProjectPinBoardWindowContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ private void InitContent()
}
});
}
// 监听元素尺寸变化
m_Content.RegisterCallback<GeometryChangedEvent>(OnContentGeometryChangedEventChanged);

// 内容分栏
m_ContentSplitView = new TwoPaneSplitView()
Expand All @@ -87,17 +89,6 @@ private void InitContent()
};
m_Content.Add(m_ContentSplitView);

// 元素就绪后恢复预览区域状态
{
void Callback(GeometryChangedEvent evt)
{
TogglePreview(ProjectPinBoardSettings.enablePreview);
m_ContentSplitView.UnregisterCallback<GeometryChangedEvent>(Callback);
}

m_ContentSplitView.RegisterCallback<GeometryChangedEvent>(Callback);
}

// 拖拽线
{
m_ContentDragLine = m_ContentSplitView.Q<VisualElement>("unity-dragline-anchor");
Expand Down Expand Up @@ -128,6 +119,17 @@ void Callback(GeometryChangedEvent evt)
InitContentPreview();
}

/// <summary>
/// 元素尺寸变化回调
/// </summary>
/// <param name="evt"></param>
private void OnContentGeometryChangedEventChanged(GeometryChangedEvent evt)
{
// 窄视图时隐藏预览区域
bool isNarrow = (m_Toolbar.localBound.width <= 250);
TogglePreview(!isNarrow && ProjectPinBoardSettings.enablePreview);
}

/// <summary>
/// 内容是否初始化
/// </summary>
Expand Down
19 changes: 18 additions & 1 deletion Editor/Scripts/Window/ProjectPinBoardWindowHotkeys.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

Expand Down Expand Up @@ -41,7 +43,22 @@ private void RegisterHotkeys()
// F5
else if (evt.keyCode == KeyCode.F5)
{
RefreshData();
Menu_Reload();
}
// Delete / Backspace
else if (evt.keyCode == KeyCode.Delete || evt.keyCode == KeyCode.Backspace)
{
string[] names = GetSelectedItemInfos().Select(v => $"- {v.Name}").ToArray();
bool isOk = EditorUtility.DisplayDialog(
"[Project Pin Board] Unpin assets",
$"Are you sure to unpin the following assets?\n{string.Join("\n", names)}",
"Confirm!",
"Cancel"
);
if (isOk)
{
ProjectPinBoardManager.Unpin(GetSelectedItemGuids());
}
}
// 不响应
else
Expand Down
13 changes: 13 additions & 0 deletions Editor/Scripts/Window/ProjectPinBoardWindowToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private void InitToolbar()
m_Toolbar.style.flexShrink = 0;
m_Toolbar.style.flexDirection = FlexDirection.Row;
}
// 监听元素尺寸变化
m_Toolbar.RegisterCallback<GeometryChangedEvent>(OnToolbarGeometryChangedEventChanged);

// 分割线
VisualElement separator = rootVisualElement.Q<VisualElement>("Separator");
Expand Down Expand Up @@ -59,6 +61,17 @@ private void InitToolbar()
}
}

/// <summary>
/// 元素尺寸变化回调
/// </summary>
/// <param name="evt"></param>
private void OnToolbarGeometryChangedEventChanged(GeometryChangedEvent evt)
{
// 窄视图时隐藏部分按钮
m_ToolbarPreviewToggle.style.display = ((m_Toolbar.localBound.width <= 250) ? DisplayStyle.None : DisplayStyle.Flex);
m_ToolbarSyncSelectionToggle.style.display = ((m_Toolbar.localBound.width <= 200) ? DisplayStyle.None : DisplayStyle.Flex);
}

}

}
24 changes: 12 additions & 12 deletions Editor/Scripts/Window/Toolbar/ProjectPinBoardWindowToolbarFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public partial class ProjectPinBoardWindow
/// <summary>
/// 类型过滤按钮
/// </summary>
private ToolbarButton m_TypeFilterButton = null;
private ToolbarButton m_ToolbarTypeFilterButton = null;

/// <summary>
/// 标签过滤按钮
/// </summary>
private ToolbarButton m_TagFilterButton = null;
private ToolbarButton m_ToolbarTagFilterButton = null;

/// <summary>
/// 初始化
/// </summary>
private void InitToolbarFilterButton()
{
// 类型过滤
m_TypeFilterButton = new ToolbarButton()
m_ToolbarTypeFilterButton = new ToolbarButton()
{
name = "TypeFilterButton",
tooltip = "Filter by Type",
Expand All @@ -50,9 +50,9 @@ private void InitToolbarFilterButton()
justifyContent = Justify.Center,
}
};
m_Toolbar.Add(m_TypeFilterButton);
m_Toolbar.Add(m_ToolbarTypeFilterButton);
// 图标
m_TypeFilterButton.Add(new Image()
m_ToolbarTypeFilterButton.Add(new Image()
{
image = PipiUtility.GetIcon("FilterByType"),
scaleMode = ScaleMode.ScaleToFit,
Expand All @@ -62,10 +62,10 @@ private void InitToolbarFilterButton()
}
});
// 回调
m_TypeFilterButton.clicked += OnTypeFilterButtonClicked;
m_ToolbarTypeFilterButton.clicked += OnTypeFilterButtonClicked;

// 标签过滤
m_TagFilterButton = new ToolbarButton()
m_ToolbarTagFilterButton = new ToolbarButton()
{
name = "TagFilterButton",
tooltip = "Filter by Tag",
Expand All @@ -85,9 +85,9 @@ private void InitToolbarFilterButton()
justifyContent = Justify.Center,
}
};
m_Toolbar.Add(m_TagFilterButton);
m_Toolbar.Add(m_ToolbarTagFilterButton);
// 图标
m_TagFilterButton.Add(new Image()
m_ToolbarTagFilterButton.Add(new Image()
{
image = PipiUtility.GetIcon("FilterByLabel"),
scaleMode = ScaleMode.ScaleToFit,
Expand All @@ -97,20 +97,20 @@ private void InitToolbarFilterButton()
}
});
// 回调
m_TagFilterButton.clicked += OnTagFilterButtonClicked;
m_ToolbarTagFilterButton.clicked += OnTagFilterButtonClicked;
}

private void OnTypeFilterButtonClicked()
{
const string popupTitle = "Filter by Type";
Vector2 popupPos = new Vector2(m_TypeFilterButton.worldBound.x, m_TypeFilterButton.worldBound.y + 4);
Vector2 popupPos = new Vector2(m_ToolbarTypeFilterButton.worldBound.x, m_ToolbarTypeFilterButton.worldBound.y + 4);
ShowTogglePopup(popupTitle, popupPos, m_ItemTypeList, m_FilteringType, (v) => { SetTypeFilter(m_FilteringType.Equals(v, StringComparison.OrdinalIgnoreCase) ? string.Empty : v); });
}

private void OnTagFilterButtonClicked()
{
const string popupTitle = "Filter by Tag";
Vector2 popupPos = new Vector2(m_TagFilterButton.worldBound.x, m_TagFilterButton.worldBound.y + 4);
Vector2 popupPos = new Vector2(m_ToolbarTagFilterButton.worldBound.x, m_ToolbarTagFilterButton.worldBound.y + 4);
ShowTogglePopup(popupTitle, popupPos, m_ItemTagList, m_FilteringTag, (v) => { SetTagFilter(m_FilteringTag.Equals(v, StringComparison.OrdinalIgnoreCase) ? string.Empty : v); });
}

Expand Down
32 changes: 19 additions & 13 deletions Editor/Scripts/Window/Toolbar/ProjectPinBoardWindowToolbarSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class ProjectPinBoardWindow
{

/// <summary>
/// 工具栏搜索栏
/// 搜索栏
/// </summary>
private ToolbarSearchField m_ToolbarSearchField = null;

Expand All @@ -24,8 +24,9 @@ private void InitToolbarSearchField()
{
m_ToolbarSearchField = new ToolbarSearchField()
{
name = "SearchField",
name = "Search",
value = m_SearchText,
tooltip = "Search [Ctrl+F]",
style =
{
width = StyleKeyword.Auto,
Expand Down Expand Up @@ -55,10 +56,9 @@ private void InitToolbarSearchField()
private void OnSearchFieldValueChanged(ChangeEvent<string> evt)
{
SetSearchText(evt.newValue);
UpdateContent();
}

#region Searching
#region SearchField

/// <summary>
/// 搜索文本
Expand All @@ -71,9 +71,23 @@ private void OnSearchFieldValueChanged(ChangeEvent<string> evt)
/// <param name="value"></param>
private void SetSearchText(string value)
{
m_ToolbarSearchField.value = (m_SearchText = value);
m_SearchText = value;
m_ToolbarSearchField.SetValueWithoutNotify(value);
UpdateContent();
}

/// <summary>
/// 聚焦到搜索框
/// </summary>
private void FocusToSearchField()
{
m_ToolbarSearchField.Focus();
}

#endregion

#region Searching

/// <summary>
/// 获取不包含过滤器的实际搜索内容
/// </summary>
Expand All @@ -93,14 +107,6 @@ private string GetSearchContent()
return text;
}

/// <summary>
/// 聚焦到搜索框
/// </summary>
private void FocusToSearchField()
{
m_ToolbarSearchField.Focus();
}

#endregion

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public partial class ProjectPinBoardWindow
/// <summary>
/// 排序菜单
/// </summary>
private ToolbarMenu m_SortingMenu = null;
private ToolbarMenu m_ToolbarSortingMenu = null;

/// <summary>
/// 初始化
/// </summary>
private void InitToolbarSortingMenu()
{
m_SortingMenu = new ToolbarMenu()
m_ToolbarSortingMenu = new ToolbarMenu()
{
name = "SortingMenu",
tooltip = "Asset list sorting",
Expand All @@ -44,16 +44,16 @@ private void InitToolbarSortingMenu()
justifyContent = Justify.SpaceBetween,
}
};
m_Toolbar.Add(m_SortingMenu);
m_Toolbar.Add(m_ToolbarSortingMenu);
// 图标
m_SortingMenu.Insert(0, new Image()
m_ToolbarSortingMenu.Insert(0, new Image()
{
image = PipiUtility.GetIcon("AlphabeticalSorting"),
scaleMode = ScaleMode.ScaleToFit,
});
// 隐藏文本元素
{
TextElement text = m_SortingMenu.Q<TextElement>("", "unity-text-element");
TextElement text = m_ToolbarSortingMenu.Q<TextElement>("", "unity-text-element");
text.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ private void InitToolbarSortingMenu()
/// </summary>
private void BuildSortingMenuItems()
{
DropdownMenu menu = m_SortingMenu.menu;
DropdownMenu menu = m_ToolbarSortingMenu.menu;
foreach (var item in s_SortingMenuMap)
{
menu.AppendAction(item.Key, OnSortingMenuAction, GetSortingMenuActionStatus);
Expand Down
Loading

0 comments on commit 2ecf5f1

Please sign in to comment.