mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 18:30:14 +00:00
3.0 - serie clone and covert
This commit is contained in:
@@ -252,10 +252,8 @@ namespace XCharts
|
||||
foreach (var kvp in typeMap)
|
||||
{
|
||||
var type = kvp;
|
||||
if (RuntimeUtil.HasSubclass(type))
|
||||
continue;
|
||||
|
||||
list.Add(type);
|
||||
if (type.IsDefined(typeof(SerieHandlerAttribute), false))
|
||||
list.Add(type);
|
||||
}
|
||||
list.Sort((a, b) => { return a.Name.CompareTo(b.Name); });
|
||||
return list;
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace XCharts
|
||||
//Editor m_Inspector;
|
||||
internal SerializedProperty baseProperty;
|
||||
internal SerializedProperty showProperty;
|
||||
internal List<HeaderMenuInfo> menus = new List<HeaderMenuInfo>();
|
||||
protected Dictionary<string, Type> m_CoordOptionsDic;
|
||||
protected List<string> m_CoordOptionsNames;
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ namespace XCharts
|
||||
if (m_DataDimension.intValue < 1) m_DataDimension.intValue = 1;
|
||||
int dimension = m_DataDimension.intValue;
|
||||
bool showName = m_ShowDataName.boolValue;
|
||||
bool showSelected = serie is Pie;
|
||||
if (listSize != m_Datas.arraySize)
|
||||
{
|
||||
while (listSize > m_Datas.arraySize) m_Datas.arraySize++;
|
||||
@@ -73,25 +72,25 @@ namespace XCharts
|
||||
int num = listSize > 10 ? 10 : listSize;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
DrawSerieData(dimension, m_Datas, i, showName, showSelected);
|
||||
DrawSerieData(dimension, m_Datas, i, showName);
|
||||
}
|
||||
if (num >= 10)
|
||||
{
|
||||
ChartEditorHelper.DrawHeader("... ", false, false, null, null);
|
||||
DrawSerieData(dimension, m_Datas, listSize - 1, showName, showSelected);
|
||||
DrawSerieData(dimension, m_Datas, listSize - 1, showName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_Datas.arraySize; i++)
|
||||
{
|
||||
DrawSerieData(dimension, m_Datas, i, showName, showSelected);
|
||||
DrawSerieData(dimension, m_Datas, i, showName);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void DrawSerieData(int dimension, SerializedProperty m_Datas, int index, bool showName, bool showSelected)
|
||||
private void DrawSerieData(int dimension, SerializedProperty m_Datas, int index, bool showName)
|
||||
{
|
||||
bool flag;
|
||||
if (!m_DataElementFoldout.TryGetValue(index, out flag))
|
||||
@@ -112,8 +111,6 @@ namespace XCharts
|
||||
var lastLabelWid = EditorGUIUtility.labelWidth;
|
||||
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||
var sereName = serieData.FindPropertyRelative("m_Name");
|
||||
var selected = serieData.FindPropertyRelative("m_Selected");
|
||||
|
||||
var data = serieData.FindPropertyRelative("m_Data");
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
var gap = 2;
|
||||
@@ -132,21 +129,9 @@ namespace XCharts
|
||||
}
|
||||
SerializedProperty element = data.GetArrayElementAtIndex(1);
|
||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
|
||||
if (showSelected)
|
||||
{
|
||||
drawRect.width = drawRect.width - 18;
|
||||
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
|
||||
drawRect.x = currentWidth - 40;
|
||||
EditorGUI.PropertyField(drawRect, selected, GUIContent.none);
|
||||
drawRect.x = lastX;
|
||||
drawRect.width = lastWid;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawRect.x = startX;
|
||||
drawRect.xMax = maxX;
|
||||
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
|
||||
}
|
||||
drawRect.x = startX;
|
||||
drawRect.xMax = maxX;
|
||||
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -84,46 +84,20 @@ namespace XCharts
|
||||
{
|
||||
var editor = m_Editors[i];
|
||||
string title = editor.GetDisplayTitle();
|
||||
int id = i;
|
||||
var menus = new List<HeaderMenuInfo>();
|
||||
menus.Add(new HeaderMenuInfo("Remove", () => { RemoveSerieEditor(id); }));
|
||||
if (i < m_Editors.Count - 1)
|
||||
menus.Add(new HeaderMenuInfo("Move Down", () =>
|
||||
{
|
||||
if (chart.MoveDownSerie(id))
|
||||
{
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
}));
|
||||
if (i > 0)
|
||||
menus.Add(new HeaderMenuInfo("Move Up", () =>
|
||||
{
|
||||
if (chart.MoveUpSerie(id))
|
||||
{
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
}));
|
||||
bool displayContent = ChartEditorHelper.DrawHeader(
|
||||
title,
|
||||
editor.baseProperty,
|
||||
editor.showProperty,
|
||||
menus.ToArray());
|
||||
editor.menus.ToArray());
|
||||
if (displayContent)
|
||||
{
|
||||
editor.OnInternalInspectorGUI();
|
||||
}
|
||||
}
|
||||
if (m_Editors.Count > 0)
|
||||
{
|
||||
//EditorGUILayout.Space();
|
||||
}
|
||||
else
|
||||
if (m_Editors.Count <= 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No serie.", MessageType.Info);
|
||||
}
|
||||
//EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
void RefreshEditors()
|
||||
@@ -142,7 +116,7 @@ namespace XCharts
|
||||
|
||||
void CreateEditor(Serie serie, SerializedProperty property, int index = -1)
|
||||
{
|
||||
|
||||
var id = index >= 0 ? index : m_Editors.Count;
|
||||
var settingsType = serie.GetType();
|
||||
Type editorType;
|
||||
|
||||
@@ -150,6 +124,39 @@ namespace XCharts
|
||||
editorType = typeof(SerieBaseEditor);
|
||||
var editor = (SerieBaseEditor)Activator.CreateInstance(editorType);
|
||||
editor.Init(chart, serie, property, m_BaseEditor);
|
||||
editor.menus.Clear();
|
||||
editor.menus.Add(new HeaderMenuInfo("Clone", () =>
|
||||
{
|
||||
CloneSerie(editor.serie);
|
||||
}));
|
||||
editor.menus.Add(new HeaderMenuInfo("Remove", () =>
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("", "Sure remove serie?", "Yes", "Cancel"))
|
||||
RemoveSerieEditor(id);
|
||||
}));
|
||||
editor.menus.Add(new HeaderMenuInfo("Move Down", () =>
|
||||
{
|
||||
if (chart.MoveDownSerie(id))
|
||||
{
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
}));
|
||||
editor.menus.Add(new HeaderMenuInfo("Move Up", () =>
|
||||
{
|
||||
if (chart.MoveUpSerie(id))
|
||||
{
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
}));
|
||||
foreach (var type in GetCovertToSerie(editor.serie.GetType()))
|
||||
{
|
||||
editor.menus.Add(new HeaderMenuInfo("Covert to " + type.Name, () =>
|
||||
{
|
||||
CovertSerie(editor.serie, type);
|
||||
}));
|
||||
}
|
||||
|
||||
if (index < 0)
|
||||
m_Editors.Add(editor);
|
||||
@@ -173,6 +180,21 @@ namespace XCharts
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public void CovertSerie(Serie serie, Type type)
|
||||
{
|
||||
chart.CovertSerie(serie, type);
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
|
||||
public void CloneSerie(Serie serie){
|
||||
var newSerie = serie.Clone();
|
||||
newSerie.serieName = chart.GenerateDefaultSerieName();
|
||||
chart.InsertSerie(newSerie);
|
||||
m_SeriesProperty = m_BaseEditor.RefreshSeries();
|
||||
RefreshEditors();
|
||||
}
|
||||
|
||||
private void RemoveSerieEditor(int id)
|
||||
{
|
||||
m_Editors[id].OnDisable();
|
||||
@@ -186,5 +208,23 @@ namespace XCharts
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
private List<Type> GetCovertToSerie(Type serie)
|
||||
{
|
||||
var list = new List<Type>();
|
||||
var typeMap = RuntimeUtil.GetAllTypesDerivedFrom<Serie>();
|
||||
foreach (var kvp in typeMap)
|
||||
{
|
||||
var type = kvp;
|
||||
if (type.IsDefined(typeof(SerieConvertAttribute), false))
|
||||
{
|
||||
var attribute = type.GetAttribute<SerieConvertAttribute>();
|
||||
if (attribute != null && attribute.Contains(serie))
|
||||
list.Add(type);
|
||||
}
|
||||
}
|
||||
list.Sort((a, b) => { return a.Name.CompareTo(b.Name); });
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user