整合SLSUtilities
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudiosEditor.ScriptableSheets.Popups
|
||||
{
|
||||
public abstract class AnchoredPopupWindowContent : PopupWindowContent
|
||||
{
|
||||
protected readonly Rect m_AnchoredRect;
|
||||
|
||||
public AnchoredPopupWindowContent(Rect anchoredRect)
|
||||
{
|
||||
m_AnchoredRect = anchoredRect;
|
||||
}
|
||||
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
return m_AnchoredRect.size;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect rect)
|
||||
{
|
||||
editorWindow.position = m_AnchoredRect;
|
||||
OnGUI();
|
||||
}
|
||||
|
||||
public abstract void OnGUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 098cdf9445a889a408cb3841891ff96a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Editor/Popups/AnchoredPopupWindowContent.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,173 @@
|
||||
using LunaWolfStudiosEditor.ScriptableSheets.Layout;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudiosEditor.ScriptableSheets.Popups
|
||||
{
|
||||
public class ColumnVisibilityPopupWindowContent : AnchoredPopupWindowContent
|
||||
{
|
||||
private readonly MultiColumnHeaderState m_MultiColumnHeaderState;
|
||||
private readonly int m_VisibleColumnLimit;
|
||||
private readonly Action<int[]> m_VisibilityChanged;
|
||||
|
||||
private readonly bool[] m_ColumnVisibility;
|
||||
private readonly string[] m_ColumnNames;
|
||||
private readonly HashSet<int> m_VisibleColumns = new HashSet<int>();
|
||||
private readonly Paginator m_Paginator = new Paginator();
|
||||
private readonly List<int> m_Indices = new List<int>();
|
||||
private readonly List<int> m_PagedIndices = new List<int>();
|
||||
|
||||
private Vector2 m_SizeOfBestFit = Vector2.zero;
|
||||
private Vector2 m_ScrollPos;
|
||||
private int m_TotalPages;
|
||||
private int m_PreviousSelectedPage = 1;
|
||||
|
||||
public ColumnVisibilityPopupWindowContent(Rect anchoredRect, MultiColumnHeaderState multiColumnHeaderState, int visibleColumnLimit, Action<int[]> visibilityChanged) : base(anchoredRect)
|
||||
{
|
||||
m_MultiColumnHeaderState = multiColumnHeaderState;
|
||||
m_VisibleColumnLimit = visibleColumnLimit;
|
||||
m_VisibilityChanged = visibilityChanged;
|
||||
|
||||
m_ColumnVisibility = new bool[m_MultiColumnHeaderState.columns.Length];
|
||||
m_ColumnNames = new string[m_MultiColumnHeaderState.columns.Length];
|
||||
|
||||
var columnCount = m_MultiColumnHeaderState.columns.Length;
|
||||
for (var i = 0; i < columnCount; i++)
|
||||
{
|
||||
m_ColumnVisibility[i] = m_MultiColumnHeaderState.visibleColumns.Contains(i);
|
||||
m_ColumnNames[i] = string.IsNullOrEmpty(m_MultiColumnHeaderState.columns[i].headerContent?.text) ? i.ToString() : m_MultiColumnHeaderState.columns[i].headerContent.text;
|
||||
if (m_ColumnVisibility[i])
|
||||
{
|
||||
m_VisibleColumns.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
m_Paginator.SetObjectsPerPage(PopupContent.Window.ColumnVisibilityRowsPerPage);
|
||||
m_Paginator.SetTotalObjects(columnCount);
|
||||
m_TotalPages = m_Paginator.GetTotalPages();
|
||||
m_Indices = Enumerable.Range(0, m_ColumnVisibility.Length).ToList();
|
||||
m_PagedIndices = m_Paginator.GetPageObjects(m_Indices);
|
||||
}
|
||||
|
||||
public override Vector2 GetWindowSize()
|
||||
{
|
||||
// Can't call GUI.skin if opening via context menu.
|
||||
if (Event.current == null || m_ColumnNames.Length <= 0)
|
||||
{
|
||||
return m_AnchoredRect.size;
|
||||
}
|
||||
// We need to calculate the best fit from inside OnGUI in case the user opens the popup from the context window.
|
||||
if (m_SizeOfBestFit == Vector2.zero)
|
||||
{
|
||||
var widestLabel = m_ColumnNames.Max(n => GUI.skin.toggle.CalcSize(new GUIContent(n)).x);
|
||||
// Add extra padding when we display the pagination buttons.
|
||||
if (m_TotalPages > 1)
|
||||
{
|
||||
widestLabel = Mathf.Max(PopupContent.Window.ColumnVisibilityMinWidth, widestLabel);
|
||||
}
|
||||
m_SizeOfBestFit.x = Mathf.Min(widestLabel + PopupContent.Window.ColumnVisibilityPadding, m_AnchoredRect.size.x);
|
||||
var contentHeight = (m_PagedIndices.Count + 1) * EditorGUIUtility.singleLineHeight;
|
||||
m_SizeOfBestFit.y = Mathf.Min(contentHeight + PopupContent.Window.ColumnVisibilityPadding, m_AnchoredRect.size.y);
|
||||
}
|
||||
return m_SizeOfBestFit;
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if (m_ColumnVisibility.Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
var columnVisibilityHeaderContent = SheetsContent.Label.GetColumnContent(m_ColumnVisibility.Count(c => c == true), m_VisibleColumnLimit, m_ColumnVisibility.Count());
|
||||
columnVisibilityHeaderContent.text = $"{PopupContent.Label.ColumnVisibility} {columnVisibilityHeaderContent.text}";
|
||||
var headerLabelWidth = GUI.skin.label.CalcSize(columnVisibilityHeaderContent).x;
|
||||
EditorGUILayout.LabelField(columnVisibilityHeaderContent, GUILayout.Width(headerLabelWidth));
|
||||
|
||||
if (m_TotalPages > 1)
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
var showFirstAndLastPageButtons = m_TotalPages > SheetLayout.FirstAndLastPageThreshold;
|
||||
if (showFirstAndLastPageButtons)
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(m_Paginator.IsOnFirstPage());
|
||||
if (GUILayout.Button(SheetsContent.Button.FirstPage, SheetLayout.InlineButton))
|
||||
{
|
||||
m_Paginator.GoToFirstPage();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(SheetsContent.Button.PreviousPage, SheetLayout.InlineButton))
|
||||
{
|
||||
m_Paginator.PreviousPage();
|
||||
}
|
||||
|
||||
var pageLabelContent = SheetsContent.Label.GetColumnVisibilityPageContent(m_Paginator.CurrentPage, m_TotalPages, m_Paginator.TotalObjects);
|
||||
var pageLabelWidth = GUI.skin.label.CalcSize(pageLabelContent).x;
|
||||
EditorGUILayout.LabelField(pageLabelContent, SheetLayout.CenterLabelStyle, GUILayout.Width(pageLabelWidth));
|
||||
|
||||
if (GUILayout.Button(SheetsContent.Button.NextPage, SheetLayout.InlineButton))
|
||||
{
|
||||
m_Paginator.NextPage();
|
||||
}
|
||||
|
||||
if (showFirstAndLastPageButtons)
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(m_Paginator.IsOnLastPage());
|
||||
if (GUILayout.Button(SheetsContent.Button.LastPage, SheetLayout.InlineButton))
|
||||
{
|
||||
m_Paginator.GoToLastPage();
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
if (m_PreviousSelectedPage != m_Paginator.CurrentPage)
|
||||
{
|
||||
m_PagedIndices.Clear();
|
||||
m_PagedIndices.AddRange(m_Paginator.GetPageObjects(m_Indices));
|
||||
m_PreviousSelectedPage = m_Paginator.CurrentPage;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
foreach (var i in m_PagedIndices)
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup((m_MultiColumnHeaderState.visibleColumns.Length >= m_VisibleColumnLimit && !m_ColumnVisibility[i]) || i == 0);
|
||||
var newValue = EditorGUILayout.ToggleLeft(m_ColumnNames[i], m_ColumnVisibility[i]);
|
||||
if (newValue != m_ColumnVisibility[i])
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
m_VisibleColumns.Add(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VisibleColumns.Remove(i);
|
||||
}
|
||||
m_ColumnVisibility[i] = newValue;
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_VisibilityChanged?.Invoke(m_VisibleColumns.OrderBy(i => i).ToArray());
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f202a7e98b4e04340906c68158561575
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Editor/Popups/ColumnVisibilityPopupWindowContent.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,85 @@
|
||||
using LunaWolfStudiosEditor.ScriptableSheets.Layout;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LunaWolfStudiosEditor.ScriptableSheets.Popups
|
||||
{
|
||||
public class InputPopupWindowContent : AnchoredPopupWindowContent
|
||||
{
|
||||
private static readonly string InputPopupControlName = $"{nameof(InputPopupWindowContent)}";
|
||||
|
||||
private readonly Action<string> m_Confirmed;
|
||||
private readonly GUIContent m_LabelContent;
|
||||
|
||||
private string m_Input;
|
||||
|
||||
public InputPopupWindowContent(Rect anchoredRect, GUIContent labelContent, string defaultInput, Action<string> confirmed) : base(anchoredRect)
|
||||
{
|
||||
m_LabelContent = labelContent;
|
||||
m_Input = defaultInput;
|
||||
m_Confirmed = confirmed;
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField(m_LabelContent);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUI.SetNextControlName(InputPopupControlName);
|
||||
m_Input = EditorGUILayout.TextField(m_Input);
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
EditorGUI.FocusTextInControl(InputPopupControlName);
|
||||
}
|
||||
GUI.SetNextControlName(string.Empty);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(PopupContent.Button.Confirm))
|
||||
{
|
||||
ConfirmInput();
|
||||
}
|
||||
|
||||
SheetLayout.DrawVerticalLine();
|
||||
|
||||
if (GUILayout.Button(PopupContent.Button.Cancel))
|
||||
{
|
||||
CancelInput();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
var e = Event.current;
|
||||
if (e.type == EventType.KeyUp && e.modifiers == EventModifiers.None)
|
||||
{
|
||||
switch (e.keyCode)
|
||||
{
|
||||
case KeyCode.KeypadEnter:
|
||||
case KeyCode.Return:
|
||||
ConfirmInput();
|
||||
e.Use();
|
||||
break;
|
||||
case KeyCode.Escape:
|
||||
CancelInput();
|
||||
e.Use();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfirmInput()
|
||||
{
|
||||
m_Confirmed?.Invoke(m_Input);
|
||||
editorWindow.Close();
|
||||
}
|
||||
|
||||
private void CancelInput()
|
||||
{
|
||||
editorWindow.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0819559f90d9a7341b4793dfa60600ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Editor/Popups/InputPopupWindowContent.cs
|
||||
uploadId: 823456
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "LunaWolfStudiosEditor.ScriptableSheets.Popups",
|
||||
"rootNamespace": "LunaWolfStudiosEditor.ScriptableSheets.Popups",
|
||||
"references": [
|
||||
"GUID:b37e9192bd2da3f4cbecf27120ea8f63"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74ba5ed9332e02843a6b48c610ad545e
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284559
|
||||
packageName: Scriptable Sheets
|
||||
packageVersion: 1.8.0
|
||||
assetPath: Packages/com.lunawolfstudios.scriptablesheets/Editor/Popups/LunaWolfStudiosEditor.ScriptableSheets.Popups.asmdef
|
||||
uploadId: 823456
|
||||
Reference in New Issue
Block a user