Example #1
0
        /// <summary>
        /// Renders list of config views on custom editor.
        /// </summary>
        public static void Render(MVCEditor editor, MvcConfig config)
        {
            ConfigViewEditorFlags.Setup(config);

            DrawControls(editor, config);
            DrawViews(editor, config);
        }
Example #2
0
        private static void DrawViews(MVCEditor editor, MvcConfig config)
        {
            if (!IsShowingView)
            {
                return;
            }

            GUILayout.BeginVertical("GroupBox");

            for (int i = 0; i < config.Views.Count; i++)
            {
                if (ConfigViewEditorFlags.IsOpen[i])
                {
                    DrawOpenedView(editor, config, config.Views[i], i);
                }
                else
                {
                    DrawClosedView(editor, config, config.Views[i], i);
                }
            }

            EditorColors.SetBackgroundColor(Color.green);
            {
                if (GUILayout.Button("Create View"))
                {
                    config.Views.Add(new MvcConfig.View(config)
                    {
                        Name = "View" + config.Views.Count
                    });

                    ConfigViewEditorFlags.Setup(config);
                    ConfigViewEditorFlags.SetOpen(config.Views.Count - 1);
                    SetEdit(config.Views.GetLast());
                }
            }
            EditorColors.ResetBackgroundColor();

            GUILayout.EndVertical();
        }
Example #3
0
        private static void DrawClosedView(MVCEditor editor, MvcConfig config, MvcConfig.View view, int index)
        {
            GUILayout.BeginHorizontal("GroupBox");

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label(view.Name + " : " + view.GetBaseClass());
            GUILayout.Label(view.LifeType.ToString() + " on dispose.");
            if (view.IsInitial)
            {
                GUILayout.Label("Initial view");
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            if (GUILayout.Button("Edit"))
            {
                ConfigViewEditorFlags.SetOpen(index);
                SetEdit(view);
            }

            GUILayout.EndHorizontal();
        }
Example #4
0
        private static void DrawOpenedView(MVCEditor editor, MvcConfig config, MvcConfig.View view, int index)
        {
            GUILayout.BeginVertical("LightmapEditorSelectedHighlight");

            editingName = ViewNameTrim(
                EditorGUILayout.TextField("View name", editingName)
                );
            editingBaseClassName = EditorGUILayout.TextField("Custom base class", editingBaseClassName);
            editingLifeType      = (MvcLifeType)EditorGUILayout.EnumPopup("Custom lifecycle", editingLifeType);
            editingRescaleMode   = (MvcRescaleType)EditorGUILayout.EnumPopup("View rescale mode", editingRescaleMode);
            editingInitial       = EditorGUILayout.Toggle("Is initial view?", editingInitial);

            if (GUILayout.Button("Save & Close"))
            {
                if (ApplyEdit(config, view))
                {
                    ConfigViewEditorFlags.ResetFlags();
                }
            }

            EditorColors.SetBackgroundColor(Color.red);
            {
                if (GUILayout.Button("Danger Zone!"))
                {
                    ConfigViewEditorFlags.IsDeleteOpen ^= true;
                }
            }
            EditorColors.ResetBackgroundColor();

            if (ConfigViewEditorFlags.IsDeleteOpen)
            {
                GUILayout.BeginVertical("GroupBox");

                EditorGUILayout.HelpBox(
                    "It is highly recommended to apply configurations first before performing any actions here.",
                    MessageType.Warning
                    );

                // Red background for danger zone buttons
                EditorColors.SetBackgroundColor(Color.red);
                {
                    if (GUILayout.Button("Delete config"))
                    {
                        if (EditorDialog.OpenAlert(
                                "Delete view configuration.",
                                "Are you sure you want to delete this view's configuration? " + DeleteWarning,
                                "Yes", "No"))
                        {
                            // Remove view from views list.
                            MvcViewRemover.RemoveFromConfig(config.Views, index);
                            ConfigViewEditorFlags.Setup(config);
                            ConfigViewEditorFlags.ResetFlags();
                        }
                    }

                    // If loaded from resources, the user must've already created a prefab or at least scripts.
                    if (view.IsFromResources)
                    {
                        EditorGUILayout.Space();

                        if (GUILayout.Button("Delete prefab"))
                        {
                            // Confirm prefab deletion
                            if (EditorDialog.OpenAlert(
                                    "Delete view prefab",
                                    "Are you sure you want to delete this view's prefab? " + DeleteWarning,
                                    "Yes", "No"))
                            {
                                MvcViewRemover.RemovePrefab(view);
                            }
                        }

                        EditorGUILayout.Space();

                        if (GUILayout.Button("Delete all"))
                        {
                            // Confirm deletion of all view-related things
                            if (EditorDialog.OpenAlert(
                                    "Delete view config, scripts, prefab",
                                    "Are you sure you want to delete this view's config, scripts, and prefab?" + DeleteWarning,
                                    "Yes", "No"))
                            {
                                MvcViewRemover.RemoveFromConfig(config.Views, index);
                                MvcViewRemover.RemoveScripts(view);
                                MvcViewRemover.RemovePrefab(view);
                                MvcViewRemover.Finalize(config);

                                ConfigViewEditorFlags.Setup(config);
                                ConfigViewEditorFlags.ResetFlags();
                            }
                        }
                    }
                }
                EditorColors.ResetBackgroundColor();

                GUILayout.EndVertical();
            }

            GUILayout.EndVertical();
        }