public bool DrawGUIList(EditorGUILayoutEx in_layout)
        {
            if (!_Initialized)
            {
                _Initialized        = true;
                UseTypeRow          = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow);
                WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType);
            }

            var old = GUI.enabled;

            if (WorksheetQueryStatus != QueryStatus.Idle && RowsDisplay.Length == 0)
            {
                GUI.enabled = false;
            }


            var newExportType = WorksheetExportType;

            if (IsDataValid)
            {
                newExportType = (ExportType)EditorGUILayout.EnumPopup(WorksheetName, WorksheetExportType);
            }
            else if (WorksheetQueryStatus != QueryStatus.Idle)
            {
                EditorGUILayout.LabelField(WorksheetName,
                                           Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) +
                                           Google2u.Ellipses);
            }
            else
            {
                var oldColor = GUI.color;
                if (GUI.GetNameOfFocusedControl() != WorksheetName + "Invalid")
                {
                    GUI.color = Color.red;
                }
                GUI.SetNextControlName(WorksheetName + "Invalid");
                newExportType = (ExportType)EditorGUILayout.EnumPopup(WorksheetName, WorksheetExportType);
                GUI.color     = oldColor;
            }

            if (newExportType != WorksheetExportType)
            {
                WorksheetExportType = Google2uGUIUtil.SetEnum(Prefix + "ExportType", newExportType);
            }

            GUI.enabled = old;

            return(WorksheetExportType != ExportType.DoNotExport);
        }
Exemple #2
0
        public Google2uExportOptions(string in_prefix)
        {
            _Prefix = in_prefix;

            LowercaseHeader = Google2uGUIUtil.GetBool(in_prefix + "LowercaseHeader", LowercaseHeader);

            TrimStrings      = Google2uGUIUtil.GetBool(in_prefix + "TrimStrings", TrimStrings);
            TrimStringArrays = Google2uGUIUtil.GetBool(in_prefix + "TrimStringArrays", TrimStringArrays);

            ArrayDelimiters        = Google2uGUIUtil.GetInt(in_prefix + "ArrayDelimiters", ArrayDelimiters);
            StringArrayDelimiters  = Google2uGUIUtil.GetInt(in_prefix + "StringArrayDelimiters", StringArrayDelimiters);
            ComplexTypeDelimiters  = Google2uGUIUtil.GetInt(in_prefix + "ComplexTypeDelimiters", ComplexTypeDelimiters);
            ComplexArrayDelimiters = Google2uGUIUtil.GetInt(in_prefix + "ComplexArrayDelimiters", ComplexArrayDelimiters);

            #region ObjectDatabase Options

            var dbObjName = Google2uGUIUtil.GetString(_Prefix + "GameObjectDatabaseName", string.Empty);
            if (string.IsNullOrEmpty(dbObjName) == false)
            {
                var go = GameObject.Find(dbObjName);
                if (go)
                {
                    ExportDatabaseGameObjectName = dbObjName;
                    _ExportDatabaseGameObject    = go;
                }
            }


            _OverrideObjectDatabaseNames = new Dictionary <string, string>();


            var tmpOverrides = Google2uGUIUtil.GetString(_Prefix + "OverrideObjectDatabaseNames",
                                                         string.Empty);
            var tmpOverrideSplit = tmpOverrides.Split(',');
            foreach (var s in tmpOverrideSplit)
            {
                var sSplit = s.Split('|');
                if (sSplit.Length == 2)
                {
                    _OverrideObjectDatabaseNames.Add(sSplit[0], sSplit[1]);
                }
            }

            GeneratePlaymakerActions = Google2uGUIUtil.GetBool(in_prefix + "GeneratePlaymakerActions",
                                                               GeneratePlaymakerActions);
            UseDoNotDestroy     = Google2uGUIUtil.GetBool(in_prefix + "UseDoNotDestroy", UseDoNotDestroy);
            ObjectDBCullColumns = Google2uGUIUtil.GetBool(in_prefix + "ObjectDBCullColumns", ObjectDBCullColumns);
            ObjectDBCullRows    = Google2uGUIUtil.GetBool(in_prefix + "ObjectDBCullRows", ObjectDBCullRows);

            #endregion

            #region Static DB Options

            StaticDBCullColumns = Google2uGUIUtil.GetBool(in_prefix + "StaticDBCullColumns", StaticDBCullColumns);
            StaticDBCullRows    = Google2uGUIUtil.GetBool(in_prefix + "StaticDBCullRows", StaticDBCullRows);

            #endregion

            #region JSON Options

            EscapeUnicode         = Google2uGUIUtil.GetBool(in_prefix + "EscapeUnicode", EscapeUnicode);
            JSONCellArrayToString = Google2uGUIUtil.GetBool(in_prefix + "JSONCellArrayToString", JSONCellArrayToString);
            JSONExportClass       = Google2uGUIUtil.GetBool(in_prefix + "JSONExportClass", JSONExportClass);
            JSONExportType        = Google2uGUIUtil.GetEnum(in_prefix + "JSONExportType", JSONExportType);
            JSONCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "JSONCullColumns", JSONCullColumns);
            JSONCullRows          = Google2uGUIUtil.GetBool(in_prefix + "JSONCullRows", JSONCullRows);
            JSONIgnoreIDColumn    = Google2uGUIUtil.GetBool(in_prefix + "JSONIgnoreIDColumn", JSONIgnoreIDColumn);
            JSONExportPretty      = Google2uGUIUtil.GetBool(in_prefix + "JSONExportPretty", JSONExportPretty);
            #endregion

            #region XML Options

            XMLCellArrayToString = Google2uGUIUtil.GetBool(in_prefix + "XMLCellArrayToString", XMLCellArrayToString);
            XMLCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "XMLCullColumns", XMLCullColumns);
            XMLCullRows          = Google2uGUIUtil.GetBool(in_prefix + "XMLCullRows", XMLCullRows);

            #endregion

            #region CSV Options

            EscapeCSVStrings     = Google2uGUIUtil.GetBool(in_prefix + "EscapeCSVStrings", EscapeCSVStrings);
            CSVCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "CSVCullColumns", CSVCullColumns);
            CSVCullRows          = Google2uGUIUtil.GetBool(in_prefix + "CSVCullRows", CSVCullRows);
            CSVConvertLineBreaks = Google2uGUIUtil.GetBool(in_prefix + "CSVConvertLineBreaks", CSVConvertLineBreaks);

            #endregion

            #region NGUI Options

            EscapeNGUIStrings     = Google2uGUIUtil.GetBool(in_prefix + "EscapeNGUIStrings", EscapeNGUIStrings);
            NGUICullColumns       = Google2uGUIUtil.GetBool(in_prefix + "NGUICullColumns", NGUICullColumns);
            NGUICullRows          = Google2uGUIUtil.GetBool(in_prefix + "NGUICullRows", NGUICullRows);
            NGUIConvertLineBreaks = Google2uGUIUtil.GetBool(in_prefix + "NGUIConvertLineBreaks", NGUIConvertLineBreaks);
            NGUILegacyExport      = Google2uGUIUtil.GetBool(in_prefix + "NGUILegacyExport", NGUILegacyExport);

            #endregion
        }
        public void DrawGUIFull(EditorGUILayoutEx in_layout)
        {
            if (!_Initialized)
            {
                _Initialized        = true;
                UseTypeRow          = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow);
                WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType);
            }

            if (WorksheetQueryStatus != QueryStatus.QueryComplete && WorksheetQueryStatus != QueryStatus.Idle &&
                RowsDisplay.Length == 0)
            {
                EditorGUILayout.LabelField(
                    Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) +
                    Google2u.Ellipses);
            }
            else if (RowsDisplay.Length == 0)
            {
                if (WorksheetQueryStatus == QueryStatus.QueryComplete || WorksheetQueryStatus == QueryStatus.Idle)
                {
                    EditorGUILayout.LabelField(
                        Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_EMPTY_WORKSHEET));
                }
            }
            else
            {
                if (DoInitialSizeCheck)
                {
                    DoInitialSizeCheck = false;
                    for (var i = 0; i < ColOptions.Count; ++i)
                    {
                        CalculateColumnWidth(i, this);
                    }
                }

                if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15)
                {
                    DoUpdateQuery = true;
                }

                if (ActiveCell != null)
                {
                    if (!ActiveCell.SkipValidation && !string.IsNullOrEmpty(ActiveCell.Tooltip))
                    {
                        EditorGUILayoutEx.SetColor(Color.red);
                        GUILayout.Label(ActiveCell.Tooltip);
                        EditorGUILayoutEx.ResetColor();
                    }
                    if (ActiveCell.DrawCellValue(in_layout))
                    {
                        WorksheetQueryStatus = QueryStatus.Idle;
                        LastUpdateTime       = DateTime.MinValue;
                        DoUpdateQuery        = true;
                        UpdateValidation     = true;
                    }
                }
                else
                {
                    var old = GUI.enabled;
                    GUI.enabled = false;
                    EditorGUILayout.TextField(string.Empty);
                    GUI.enabled = old;
                }

                // Calculate the total width and height of the scroll area
                var totalHeight = Math.Max(120, 22 + (24 * RowsDisplay.Length));
                var totalWidth  = 40 + ColOptions.Sum(in_colOption => in_colOption.Width);

                EditorGUILayout.Separator();
                if (Event.current.type == EventType.Repaint)
                {
                    _LastRect = GUILayoutUtility.GetLastRect();
                }
                var scrollHeight = Screen.height - _LastRect.y - 30;
                var screenRect   = new Rect(0f, _LastRect.y, Screen.width, scrollHeight);
                var viewRect     = new Rect(0f, 0f, totalWidth, totalHeight);

                _MyScrollPos = GUI.BeginScrollView(screenRect, _MyScrollPos, viewRect);

                var curRect = new Rect(0.0f, 0.0f, 40.0f, 22.0f);

                // Blank
                GUI.Label(curRect, string.Empty, in_layout.CellHeader);

                // Column Letters (Resizable Columns)
                for (var i = 0; i < RowsDisplay[0].Count; i++)
                {
                    var label = GetColumnName(i + 1);
                    curRect.x    += curRect.width;
                    curRect.width = ColOptions[i].Width;
                    GUI.Label(curRect, label, in_layout.CellHeader);

                    ColOptions[i].ColumnRect       = curRect;
                    ColOptions[i].ColumnRect.width = ColOptions[i].Width;

                    if (ColOptions[i].ColumnRect.Contains(Event.current.mousePosition))
                    {
                        ColOptions[i].HasMouse = true;
                    }

                    if (!ColOptions[i].HasMouse)
                    {
                        continue;
                    }

                    if ((Event.current.type == EventType.MouseDown) && (Event.current.clickCount >= 2))
                    {
                        // Doubleclick
                        CalculateColumnWidth(i, this);
                    }
                    if (Event.current.type == EventType.MouseDrag)
                    {
                        ColOptions[i].CurPos = Event.current.mousePosition;

                        if (!ColOptions[i].Dragging)
                        {
                            ColOptions[i].Dragging = true;
                            ColOptions[i].StartPos = ColOptions[i].CurPos;
                        }
                    }

                    if (Event.current.type == EventType.MouseUp)
                    {
                        ColOptions[i].Dragging = false;
                        ColOptions[i].HasMouse = false;
                    }

                    if (!ColOptions[i].Dragging)
                    {
                        continue;
                    }

                    if (Event.current.isMouse)
                    {
                        Event.current.Use();
                    }

                    ColOptions[i].Width +=
                        Convert.ToInt32((ColOptions[i].CurPos.x - ColOptions[i].StartPos.x));
                    ColOptions[i].StartPos = ColOptions[i].CurPos;
                    ColOptions[i].Width    = Math.Max(26, ColOptions[i].Width);
                }


                curRect = new Rect(0.0f, 22.0f, 40.0f, 24.0f);

                // The rest of the rows
                for (var i = 0; i < RowsDisplay.Length; i++)
                {
                    if (i == 1)
                    {
                        // Could be type row
                        if (GUI.Button(curRect, UseTypeRow ? "Type" : "2", in_layout.CellTypeButton))
                        {
                            if (UseTypeRow == false)
                            {
                                if (EditorUtility.DisplayDialog(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_HEADER),
                                                                Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_MESSAGE), "OK", "Cancel"))
                                {
                                    UseTypeRow      = !UseTypeRow;
                                    UpdateCellTypes = true;
                                }
                            }
                            else
                            {
                                UseTypeRow      = !UseTypeRow;
                                UpdateCellTypes = true;
                            }
                        }
                    }
                    else
                    {
                        // Row Number
                        GUI.Label(curRect, Convert.ToString(i + 1), in_layout.CellHeader);
                    }

                    // Cell Values

                    if (i == 1 && UseTypeRow)
                    {
                        for (var j = 0; j < RowsDisplay[i].Count; j++)
                        {
                            curRect.x    += curRect.width;
                            curRect.width = ColOptions[j].Width;

                            var myCell = RowsDisplay[i][j];

                            if (myCell.MyType == SupportedType.Unrecognized)
                            {
                                myCell.SetTypeFromValue();
                            }

                            var cellType    = myCell.MyType;
                            var curSelected = 0;
                            foreach (var guiContent in _ComboBoxList)
                            {
                                if (guiContent.text.Equals(Convert.ToString(cellType)))
                                {
                                    break;
                                }
                                curSelected++;
                            }
                            if (curSelected >= _ComboBoxList.Length)
                            {
                                curSelected = 0;
                            }

                            Google2uGUIUtil.ComboBox comboBoxControl;
                            if (!_ComboBoxes.ContainsKey(j))
                            {
                                comboBoxControl = new Google2uGUIUtil.ComboBox(curRect, _ComboBoxList[curSelected],
                                                                               _ComboBoxList, in_layout.CellTypeButton, in_layout.OuterBox, in_layout.CellHeader);
                                _ComboBoxes.Add(j, comboBoxControl);
                            }
                            else
                            {
                                comboBoxControl = _ComboBoxes[j];
                            }
                            comboBoxControl.width  = curRect.width;
                            comboBoxControl.height = curRect.height;
                            comboBoxControl.x      = curRect.x;
                            comboBoxControl.y      = curRect.y;
                            var newSelected = comboBoxControl.Show();
                            if (newSelected != curSelected)
                            {
                                var newType =
                                    (SupportedType)
                                    Enum.Parse(typeof(SupportedType), _ComboBoxList[newSelected].text, true);
                                myCell.MyType = newType;
                                myCell.SetValueFromType();
                                UpdateCellTypes  = true;
                                UpdateValidation = true;
                            }
                        }
                    }
                    else
                    {
                        for (var j = 0; j < RowsDisplay[i].Count; j++)
                        {
                            curRect.x    += curRect.width;
                            curRect.width = ColOptions[j].Width;

                            if (curRect.x + curRect.width > _MyScrollPos.x && curRect.x < _MyScrollPos.x + Screen.width &&
                                curRect.y + curRect.height > _MyScrollPos.y && curRect.y < _MyScrollPos.y + scrollHeight)
                            {
                                if (i < 2 || i > 5 || !_ComboBoxes.ContainsKey(j) || _ComboBoxes[j].IsShown == false)
                                {
                                    var newCell = RowsDisplay[i][j].DrawGUI(in_layout, curRect, ActiveCell);
                                    if (newCell != null)
                                    {
                                        GUI.FocusControl("Blank");
                                        ActiveCell = newCell;
                                    }
                                }
                            }
                        }
                    }


                    curRect.x     = 0.0f;
                    curRect.width = 40.0f;
                    curRect.y    += curRect.height;
                }

                GUI.EndScrollView();
            }
        }