Exemplo n.º 1
0
        static MList ToDoubleList            // Maybe<IEnumerable<double>>;
            (this IEnumerable <string> src)
        {
            var output = new RowDatas();

            foreach (var strdata in src)
            {
                double res;
                if (!double.TryParse(strdata, out res))
                {
                    return(None);
                }
                output.Add(res);
            }
            return(output);
        }
Exemplo n.º 2
0
        private bool CellDatas_InsertEvent(int index, CellData value)
        {
            value.MergeDataEvent -= Value_MergeDataEvent;
            value.MergeDataEvent += Value_MergeDataEvent;

            #region 处理行
            var row = RowDatas.FirstOrDefault(p => p.RowIndex == value.RowIndex);
            if (row == null)
            {
                var rowButton = TableController.RowController.Create <TableRowButton>();
                row = new RowData(TableController, rowButton, value.RowIndex)
                {
                    RowIndex = value.RowIndex
                };
                value.RowData = row;
                row.Heigth    = value.RowHeigth;
                RowDatas.Add(row);
            }
            row.CellDatas.Add(value);
            value.RowData = row;
            #endregion
            #region 处理列
            var column = ColumnDatas.FirstOrDefault(p => p.ColumnIndex == value.ColumnIndex);
            if (column == null)
            {
                var columnButton = TableController.ColumnController.Create <TableColumnButton>();
                column = new ColumnData(TableController, columnButton, value.ColumnIndex)
                {
                    ColumnIndex = value.ColumnIndex
                };
                value.ColumnData = column;
                column.Width     = value.ColumnWidth;
                ColumnDatas.Add(column);
            }
            column.CellDatas.Add(value);
            value.ColumnData = column;
            #endregion
            RefreshSize();
            value.Refresh();
            return(true);
        }
Exemplo n.º 3
0
        private void OnGUI()
        {
            m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);

            if (RowDatas == null || RowDatas.Count == 0)
            {
                Close();
                return;
            }

            CheckColumnCount();

            if (LightMode == 0)
            {
                Theme = "ScriptText";
            }
            else if (LightMode == 1)
            {
                Theme = "PreferencesSectionBox";
            }

            if (reorderableList == null)
            {
                reorderableList =
                    new ReorderableList(RowDatas, typeof(List <DataTableRowData>), true, false, true, true);

                reorderableList.drawElementCallback = (Rect rect, int index, bool selected, bool focused) =>
                {
                    for (int i = 0; i < RowDatas[index].Data.Count; i++)
                    {
                        rect.width =
                            (Instance.position.width - 20) /
                            RowDatas[index].Data.Count;

                        rect.x = rect.width * i + 20;

                        RowDatas[index].Data[i] =
                            EditorGUI.TextField(rect, "", RowDatas[index].Data[i],
                                                Instance.Theme);
                    }
                };

                reorderableList.onAddCallback = (ReorderableList list) =>
                {
                    bool result =
                        EditorUtility.DisplayDialog("提示", "添加 行 或 列", "行", "列");

                    if (result)
                    {
                        if (RowDatas.Count == 0)
                        {
                            RowDatas.Add(new DataTableRowData()
                            {
                                Data = new List <string>()
                                {
                                    "", "", "", ""
                                }
                            });
                        }
                        else
                        {
                            DataTableRowData data = new DataTableRowData();

                            for (int i = 0; i < RowDatas[0].Data.Count - 1; i++)
                            {
                                data.Data.Add("");
                            }

                            RowDatas.Add(data);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < RowDatas.Count; i++)
                        {
                            RowDatas[i].Data.Add("");
                        }
                    }
                };

                reorderableList.onRemoveCallback = (ReorderableList list) =>
                {
                    bool result =
                        EditorUtility.DisplayDialog("提示", "移除 行 或 列", "行", "列");

                    if (result)
                    {
                        RowDatas.RemoveAt(list.index);
                    }
                    else
                    {
                        for (int i = 0; i < RowDatas.Count; i++)
                        {
                            RowDatas[i].Data.RemoveAt(RowDatas[i].Data.Count - 1);
                        }
                    }
                };

                reorderableList.drawHeaderCallback = (Rect rect) =>
                {
                    EditorGUI.LabelField(rect, FilePath);
                    rect.x = rect.width - 70;
                    EditorGUI.LabelField(rect, "高亮模式");
                    rect.x = rect.width - 20;

                    LightMode =
                        EditorGUI.Toggle(rect, LightMode == 0 ? true : false)
                            ? 0
                            : 1;

                    EditorPrefs
                    .SetInt("DataTableEditor_" + Application.productName + "_LightMode",
                            LightMode);
                };
            }

            reorderableList.DoLayoutList();

            GUILayout.EndScrollView();
        }
        private void OnGUI()
        {
            m_scrollViewPos = GUILayout.BeginScrollView(m_scrollViewPos);
            if (RowDatas == null || RowDatas.Count == 0)
            {
                Close();
                GUILayout.EndScrollView();
                return;
            }

            CheckColumnCount();

            if (LightMode == 0)
            {
                Theme = "ScriptText";
            }
            else if (LightMode == 1)
            {
                Theme = "PreferencesSectionBox";
            }

            if (reorderableList == null)
            {
#if UNITY_2019_1_OR_NEWER
                reorderableList =
                    new UnityInternalBridge.ReorderableList(RowDatas, typeof(List <DataTableRowData>), true, false, true,
                                                            true);
#else
                reorderableList =
                    new ReorderableList(RowDatas, typeof(List <DataTableRowData>), true, false, true, true);
#endif

                reorderableList.drawElementCallback = (Rect rect, int index, bool selected, bool focused) =>
                {
                    for (int i = 0; i < RowDatas[index].Data.Count; i++)
                    {
                        if (RowDatas[index].Data.Count > 10)
                        {
                            rect.width =
                                (this.position.width - 20) /
                                10;
                        }
                        else
                        {
                            rect.width =
                                (this.position.width - 20) /
                                RowDatas[index].Data.Count;
                        }

                        rect.x = rect.width * i + 20;
                        RowDatas[index].Data[i] =
                            EditorGUI.TextField(rect, "", RowDatas[index].Data[i],
                                                this.Theme);
                    }
                };

                reorderableList.onAddCallback = list =>
                {
                    bool result =
                        EditorUtility.DisplayDialog("提示", "添加 行 或 列", "行", "列");

                    if (result)
                    {
                        if (RowDatas.Count == 0)
                        {
                            RowDatas.Add(new DataTableRowData()
                            {
                                Data = new List <string>()
                                {
                                    "", "", "", ""
                                }
                            });
                        }
                        else
                        {
                            DataTableRowData data = new DataTableRowData();

                            for (int i = 0; i < RowDatas[0].Data.Count - 1; i++)
                            {
                                data.Data.Add("");
                            }

                            RowDatas.Add(data);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < RowDatas.Count; i++)
                        {
                            RowDatas[i].Data.Add("");
                        }
                    }
                    Focus();
                };

                reorderableList.onRemoveCallback = list =>
                {
                    bool result =
                        EditorUtility.DisplayDialog("提示", "移除 行 或 列", "行", "列");

                    if (result)
                    {
                        RowDatas.RemoveAt(list.index);
                    }
                    else
                    {
                        for (int i = 0; i < RowDatas.Count; i++)
                        {
                            RowDatas[i].Data.RemoveAt(RowDatas[i].Data.Count - 1);
                        }
                    }
                    Focus();
                };

                reorderableList.drawHeaderCallback = (Rect rect) =>
                {
                    EditorGUI.LabelField(rect, FilePath);
                    rect.x = rect.width - 70;
                    EditorGUI.LabelField(rect, "高亮模式");
                    rect.x = rect.width - 20;

                    LightMode =
                        EditorGUI.Toggle(rect, LightMode == 0 ? true : false)
                            ? 0
                            : 1;

                    EditorPrefs
                    .SetInt("DataTableEditor_" + Application.productName + "_LightMode",
                            LightMode);
                };
            }

            reorderableList.DoLayoutList();

            if (RowDatas != null && RowDatas.Count > 0)
            {
                if (RowDatas[0].Data.Count > 10)
                {
                    float listItemWidth = 0f;
                    float listX         = 0f;
                    listItemWidth = (position.width - 20) / 10;
                    listX         = listItemWidth * (RowDatas[0].Data.Count - 1) + 20;
                    GUILayout.Label("", new GUIStyle()
                    {
                        fixedWidth = listX
                    });
                }
            }

            GUILayout.EndScrollView();
            if (IsCombinationKey(EventModifiers.Control, KeyCode.S, EventType.KeyDown))
            {
                SaveDataTable();
            }
        }