Ejemplo n.º 1
0
    void RemoveGroup(MadLevelConfiguration.Group group)
    {
        if (group == configuration.defaultGroup)
        {
            Debug.LogError("Cannot remove default group");
            return;
        }

        bool removeLevels = false;

        if (group.GetLevels().Count > 0)
        {
            if (EditorUtility.DisplayDialog("Remove Levels As Well?",
                                            "Do you want to remove all levels in this group as well? "
                                            + "If no, all levels will be moved to default group.", "Yes", "No"))
            {
                removeLevels = true;
            }
        }

        MadUndo.RecordObject2(configuration, "Remove Group");

        if (currentGroup == group)
        {
            currentGroup = configuration.defaultGroup;
        }

        if (removeLevels)
        {
            var levels = group.GetLevels();
            configuration.levels.RemoveAll((level) => levels.Contains(level));
        }

        configuration.RemoveGroup(group);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Finds the last name of the level, that predicate returns <code>true</code> value.
    /// </summary>
    /// <returns>The last found level or <code>null<code> if not found.</returns>
    /// <param name="predicate">The predicate.</param>
    public static string FindLastLevelName(string groupName, LevelPredicate predicate) {
        CheckHasConfiguration();

        MadLevelConfiguration.Group group = null;
        if (groupName != null) {
            group = activeConfiguration.FindGroupByName(groupName);
            if (group == null) {
                Debug.LogError("Cannot find group named " + groupName);
                return null;
            }
        }

        var levels = activeConfiguration.GetLevelsInOrder();
        for (int i = levels.Length - 1; i >= 0; i--) {
            var level = levels[i];

            if (group != null && level.groupId != group.id) {
                continue;
            }

            if (predicate(level)) {
                return level.name;
            }
        }

        return null;
    }
    private void TryRename(MadLevelConfiguration.Group @group, string newName)
    {
        if (conf.FindGroupByName(newName) == null)
        {
            @group.name = newName;
            EditorUtility.SetDirty(conf);
        }
        else
        {
            EditorUtility.DisplayDialog("Group Exists", "Group '" + newName + "' already exists.", "OK");
        }

        Repaint();
    }
    private void RenameGroup(MadLevelConfiguration.Group currentGroup)
    {
        var builder = new MadInputDialog.Builder("Enter Group Name", "Enter a new name for group \"" + currentGroup.name + "\".", (name) => {
            if (!string.IsNullOrEmpty(name))
            {
                currentGroup.name = name;
                EditorUtility.SetDirty(configuration);
            }
        });

        builder.defaultValue = currentGroup.name;
        builder.allowEmpty   = false;
        builder.BuildAndShow();
    }
 protected int GroupToIndex(MadLevelConfiguration configuration, MadLevelConfiguration.Group group)
 {
     if (group == configuration.defaultGroup)
     {
         return(0);
     }
     else
     {
         if (configuration.groups.Contains(group))
         {
             return(configuration.groups.IndexOf(group) + 1);
         }
         else
         {
             Debug.LogError("Group not found: " + group);
             return(0);
         }
     }
 }