Exemple #1
0
    public int FindLevelIndex(MadLevel.Type type, int groupId, string levelName)
    {
        List <Level> list;

        if (groupId == -1)
        {
            var query = from l in levels where l.type == type orderby l.order ascending select l;
            list = query.ToList();
        }
        else
        {
            var query = from l in levels where l.type == type && l.groupId == groupId orderby l.order ascending select l;
            list = query.ToList();
        }

        int index = 0;

        foreach (var level in list)
        {
            if (level.name == levelName)
            {
                return(index);
            }

            index++;
        }

        return(-1);
    }
Exemple #2
0
 /// <summary>
 /// Gets the name of a level (with given type) that exists after given level.
 /// </summary>
 /// <returns>The name of next level or <code>null</code> if not found.</returns>
 /// <param name="levelName">Level name.</param>
 /// <param name="type">Type of previous level.</param>
 public static string GetNextLevelNameTo(string levelName, MadLevel.Type type) {
     CheckHasConfiguration();
     CheckLevelExists(levelName);
     
     var level = activeConfiguration.FindNextLevel(levelName, type);
     return level != null ? level.name : null;
 }
Exemple #3
0
    public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type, bool sameGroup)
    {
        var currentLevel = FindLevelByName(currentLevelName);

        MadDebug.Assert(currentLevel != null, "Cannot find level " + currentLevelName);

        if (sameGroup)
        {
            var prevLevelQuery =
                from l in levels
                where l.groupId == currentLevel.groupId && l.order < currentLevel.order && l.type == type
                orderby l.order descending
                select l;

            var prevLevel = prevLevelQuery.FirstOrDefault();
            return(prevLevel);
        }
        else
        {
            var prevLevelQuery =
                from l in levels
                where l.order < currentLevel.order && l.type == type
                orderby l.order descending
                select l;

            var prevLevel = prevLevelQuery.FirstOrDefault();
            return(prevLevel);
        }
    }
Exemple #4
0
 /// <summary>
 /// Gets the all defined level names of given type.
 /// </summary>
 /// <returns>The all defined level names of given type.</returns>
 public static string[] GetAllLevelNames(MadLevel.Type type) {
     CheckHasConfiguration();
     var output = new List<string>();
     for (int i = 0; i < activeConfiguration.levels.Count; ++i) {
         var level = activeConfiguration.levels[i];
         if (level.type == type) {
             output.Add(level.name);
         }
     }
     
     return output.ToArray();
 }
Exemple #5
0
 public int LevelCount(MadLevel.Type type, int groupId)
 {
     if (groupId == -1)
     {
         var query = from level in levels where level.type == type select level;
         return(query.Count());
     }
     else
     {
         var query = from level in levels where level.type == type && level.groupId == groupId select level;
         return(query.Count());
     }
 }
Exemple #6
0
    public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type)
    {
        var currentLevel = FindLevelByName(currentLevelName);

        MadDebug.Assert(currentLevel != null, "Cannot find level " + currentLevelName);

        var nextLevelQuery =
            from l in levels
            where l.order < currentLevel.order && l.type == type
            orderby l.order descending
            select l;

        var nextLevel = nextLevelQuery.FirstOrDefault();

        return(nextLevel);
    }
Exemple #7
0
    public int FindLevelIndex(MadLevel.Type type, string levelName)
    {
        var query = from l in levels where l.type == type orderby l.order ascending select l;

        int index = 0;

        foreach (var level in query)
        {
            if (level.name == levelName)
            {
                return(index);
            }

            index++;
        }

        return(-1);
    }
Exemple #8
0
    public Level GetLevel(MadLevel.Type type, int index)
    {
        var query = from l in levels where l.type == type orderby l.order ascending select l;

        int skipped = 0;

        foreach (var level in query)
        {
            if (skipped == index)
            {
                return(level);
            }
            else
            {
                skipped++;
            }
        }

        Debug.LogError(string.Format("Out of bounds: {0} (size: {1})", index, skipped));
        return(null);
    }
Exemple #9
0
    public Level GetLevel(MadLevel.Type type, int groupId, int index)
    {
        int i2 = 0;

        for (int i = 0; i < levels.Count; ++i)
        {
            var level = levels[i];
            if (level.type == type && (groupId == -1 || level.groupId == groupId))
            {
                if (i2 == index)
                {
                    return(level);
                }
                else
                {
                    i2++;
                }
            }
        }

        return(null);
    }
 public MadLevelQuery OfLevelType(MadLevel.Type levelType) {
     hasLevelType = true;
     this.levelType = levelType;
     return this;
 }
Exemple #11
0
 public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type)
 {
     return(FindPreviousLevel(currentLevelName, type, false));
 }
Exemple #12
0
 /// <summary>
 /// Finds the first name of the level of given <code>type</code>.
 /// </summary>
 /// <returns>The first found level or <code>null<code> if not found.</returns>
 /// <param name="levelType">The level type.</param>
 public static string FindFirstLevelName(MadLevel.Type levelType) {
     return FindFirstLevelName(null, (level) => level.type == levelType);
 }
Exemple #13
0
 public int FindLevelIndex(MadLevel.Type type, string levelName)
 {
     return(FindLevelIndex(type, -1, levelName));
 }
Exemple #14
0
 public Level GetLevel(MadLevel.Type type, int index)
 {
     return(GetLevel(type, -1, index));
 }
Exemple #15
0
 public int LevelCount(MadLevel.Type type)
 {
     return(LevelCount(type, -1));
 }
 public MadLevelQuery OfLevelType(MadLevel.Type levelType) {
     hasLevelType = true;
     this.levelType = levelType;
     return this;
 }
Exemple #17
0
 /// <summary>
 /// Finds the last name of the level of given <code>type</code>.
 /// </summary>
 /// <returns>The last found level or <code>null<code> if not found.</returns>
 /// <param name="levelType">The level type.</param>
 public static string FindLastLevelName(MadLevel.Type levelType) {
     return FindLastLevelName((level) => level.type == levelType);
 }
Exemple #18
0
 /// <summary>
 /// Gets the name of the next level of given type.
 /// </summary>
 /// <returns>The next level name or <code>null</code> if not found.</returns>
 /// <param name="type">Level type.</param>
 public static string GetNextLevelName(MadLevel.Type type) {
     CheckHasConfiguration();
     
     var level = activeConfiguration.FindNextLevel(currentLevelName, type);
     return level != null ? level.name : null;
 }
Exemple #19
0
 /// <summary>
 /// Finds the first name of the level of given <code>type</code>.
 /// </summary>
 /// <returns>The first found level or <code>null<code> if not found.</returns>
 /// <param name="levelType">The level type.</param>
 public static string FindFirstLevelName(MadLevel.Type levelType, string groupName) {
     return FindFirstLevelName(groupName, (level) => level.type == levelType);
 }
Exemple #20
0
    public int LevelCount(MadLevel.Type type)
    {
        var query = from level in levels where level.type == type select level;

        return(query.Count());
    }
    public override void OnInspectorGUI()
    {
        if (MadTrialEditor.isTrialVersion && MadTrialEditor.expired)
        {
            MadTrialEditor.OnEditorGUIExpired("Mad Level Manager");
            return;
        }

        LoadTextures(); // loading textures with delay to prevent editor errors
        CheckAssetLocation();
        ActiveInfo();

        GUIGroupPopup();

        LoadItems();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(GUILayout.Width(1));
        GUILayout.Space(200);
        EditorGUILayout.EndVertical();
        list.Draw();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("Add"))
        {
            AddLevel();
        }
        GUI.backgroundColor = Color.white;

        GUI.enabled         = list.selectedItem != null;
        GUI.backgroundColor = Color.red;
        if (GUILayout.Button("Remove") || GUI.enabled && Event.current.keyCode == KeyCode.Delete)
        {
            RemoveLevel();
        }
        GUI.backgroundColor = Color.white;

        GUILayout.FlexibleSpace();

        GUILayout.Label("Move");

        if (GUILayout.Button("Down"))
        {
            MoveDown();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Up"))
        {
            MoveUp();
            configuration.SetDirty();
        }

        GUILayout.Space(10);

        if (GUILayout.Button("Bottom"))
        {
            MoveToBottom();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Top"))
        {
            MoveToTop();
            configuration.SetDirty();
        }

        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();

        MadGUI.IndentBox("Level Properties", () => {
            var item  = list.selectedItem;
            var items = list.selectedItems;

            if (item == null)
            {
                item        = new LevelItem(configuration);
                GUI.enabled = false;
            }

            MadUndo.RecordObject(configuration, "Edit '" + item.level.name + "'");
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            UnityEngine.Object sceneValue = null;
            if (!multiSelection)
            {
                MadGUI.Validate(() => item.level.sceneObject != null, () => {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                });
            }
            else
            {
                bool unified = (from i in items select i.level.sceneObject).Distinct().Count() == 1;
                if (unified)
                {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                }
                else
                {
                    sceneValue = EditorGUILayout.ObjectField("Scene", null, typeof(UnityEngine.Object), false);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Scene");
                foreach (var levelItem in items)
                {
                    levelItem.level.sceneObject = sceneValue;
                }
            }


            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Set Current", GUILayout.Width(85)))
            {
                MadUndo.RecordObject2(target, "Change Scene");
#if UNITY_5 && !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
                Scene activeScene = SceneManager.GetActiveScene();
                var obj           = AssetDatabase.LoadAssetAtPath(activeScene.name, typeof(UnityEngine.Object));
#else
                var obj = AssetDatabase.LoadAssetAtPath(EditorApplication.currentScene, typeof(UnityEngine.Object));
#endif

                if (obj != null)
                {
                    foreach (var levelItem in items)
                    {
                        levelItem.level.sceneObject = obj;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Scene not saved", "Current scene is not saved. Please save it first (CTRL+S).", "OK");
                }
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndHorizontal();
            if (!CheckAssetIsScene(item.level.sceneObject))
            {
                item.level.sceneObject = null;
            }

            MadGUI.Validate(() => !string.IsNullOrEmpty(item.level.name), () => {
                GUI.SetNextControlName("level name"); // needs names to unfocus
                using (MadGUI.EnabledIf(!multiSelection)) {
                    if (!multiSelection)
                    {
                        EditorGUI.BeginChangeCheck();
                        var value = EditorGUILayout.TextField("Level Name", item.level.name);
                        if (EditorGUI.EndChangeCheck())
                        {
                            MadUndo.RecordObject2(target, "Changed Level Name");
                            item.level.name = value;
                        }
                    }
                    else
                    {
                        EditorGUILayout.TextField("Level Name", "-");
                    }
                }
            });


            // level type
            MadLevel.Type typeValue = default(MadLevel.Type);
            EditorGUI.BeginChangeCheck();
            if (!multiSelection)
            {
                typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
            }
            else
            {
                bool unified = (from i in items select i.level.type).Distinct().Count() == 1;
                if (unified)
                {
                    typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
                }
                else
                {
                    int val = EditorGUILayout.Popup("Type", -1, Enum.GetNames(typeof(MadLevel.Type)));
                    if (val != -1)
                    {
                        typeValue = (MadLevel.Type)val;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Type");
                foreach (var levelItem in items)
                {
                    levelItem.level.type = typeValue;
                }
            }


            GUI.SetNextControlName("arguments"); // needs names to unfocus
            if (!multiSelection)
            {
                EditorGUI.BeginChangeCheck();
                var value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    item.level.arguments = value;
                }
            }
            else
            {
                bool unified = (from i in items select i.level.arguments).Distinct().Count() == 1;
                EditorGUI.BeginChangeCheck();
                string value = "";
                if (unified)
                {
                    value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                }
                else
                {
                    value = EditorGUILayout.TextField("Arguments", "-");
                }
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    foreach (var levelItem in items)
                    {
                        levelItem.level.arguments = value;
                    }
                }
            }

            if (MadGUI.Foldout("Locking", false))
            {
                using (MadGUI.Indent()) {
                    bool lockedByDefultState = false;
                    if (multiSelection)
                    {
                        bool unified = (from i in items select i.level.lockedByDefault).Distinct().Count() == 1;
                        if (unified && (item.level.lockedByDefault))
                        {
                            lockedByDefultState = true;
                        }
                    }
                    else
                    {
                        lockedByDefultState = item.level.lockedByDefault;
                    }

                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("locked by default"); // needs names to unfocus
                    bool lockedByDefaultValue = EditorGUILayout.Toggle("Locked By Default", lockedByDefultState);
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Locked By Default");
                        foreach (var levelItem in items)
                        {
                            levelItem.level.lockedByDefault = lockedByDefaultValue;
                        }
                    }
                }
                EditorGUILayout.Space();
            }

            if (MadGUI.Foldout("Extensions", false))
            {
                using (MadGUI.Indent()) {
                    EditorGUI.BeginChangeCheck();
                    int extensionIndex = -1;

                    if (!multiSelection)
                    {
                        extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                    }
                    else
                    {
                        bool unified = (from i in items select i.level.extension).Distinct().Count() == 1;
                        if (unified)
                        {
                            extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                        }
                    }

                    extensionIndex = MadGUI.DynamicPopup(extensionIndex, "Extension", configuration.extensions.Count + 1,
                                                         (index) => {
                        if (index == 0)
                        {
                            return("(none)");
                        }
                        else
                        {
                            return(configuration.extensions[index - 1].name);
                        }
                    });
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Extension For Level");

                        foreach (var levelItem in items)
                        {
                            if (extensionIndex == 0)
                            {
                                levelItem.level.extension = null;
                            }
                            else
                            {
                                levelItem.level.extension = configuration.extensions[extensionIndex - 1];
                            }
                        }

                        configuration.SetDirty();
                    }

                    bool enabledState = GUI.enabled;
                    GUI.enabled       = true;
                    if (MadGUI.Button("Open Extension Editor", Color.magenta))
                    {
                        MadLevelExtensionEditor.Show(configuration);
                    }
                    GUI.enabled = enabledState;

                    EditorGUILayout.Space();
                }
            }

            EditorGUI.BeginChangeCheck();
            int groupIndex = GroupToIndex(item.level.group);
            groupIndex     = EditorGUILayout.Popup("Move To Group:", groupIndex, GroupNames());
            if (EditorGUI.EndChangeCheck())
            {
                var @group = IndexToGroup(groupIndex);
                MadUndo.RecordObject2(target, "Move Levels To Group " + @group.name);
                foreach (var levelItem in items)
                {
                    levelItem.level.group = @group;
                }
            }


            if (EditorGUI.EndChangeCheck())
            {
                configuration.SetDirty();
            }

            if (inspectorAddons.Count > 0)
            {
                EditorGUILayout.Space();
            }

            foreach (var addon in inspectorAddons)
            {
                addon.OnInspectorGUI(item.level);
            }

            GUI.enabled = true;
        });

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Help"))
        {
            Help.BrowseURL(MadLevelHelp.LevelConfigurationHelp);
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!configuration.IsValid())
        {
            MadGUI.Error("Configuration is invalid. Please make sure that:\n"
                         + "- There's no levels with \"!!!\" icon. These levels may have duplicated name or missing scene.\n"
                         + "- All your extensions have no missing scenes (in Extension Editor)"
                         );
        }

        if (configuration.active && !MadLevelConfigurationEditor.CheckBuildSynchronized(configuration))
        {
            if (MadGUI.ErrorFix(
                    "Build configuration is not in synch with level configuration.",
                    "Synchronize Now"))
            {
                MadLevelConfigurationEditor.SynchronizeBuild(configuration);
            }
        }

        ExecuteDelayed();
    }