예제 #1
0
 /// <summary>
 /// Applies default locked state to profile data if this is not yet applied.
 /// This function is useful when you don't want to use level select screens or you want to get
 /// level locked state before running level select screen.
 /// </summary>
 public void ApplyProfile()
 {
     for (int i = 0; i < levels.Count; ++i)
     {
         var level = levels[i];
         if (!MadLevelProfile.IsLockedSet(level.name))
         {
             MadLevelProfile.SetLocked(level.name, level.lockedByDefault);
         }
     }
 }
예제 #2
0
파일: MadLevel.cs 프로젝트: kewls74/game1
    /// <summary>
    /// Finds the last unlocked level (in the order). Be aware that locked flag in the new
    /// game is set when the player visits level select screen for the first time.
    /// </summary>
    /// <returns>The first locked level name or <code>null</code> if there's no level
    /// that is marked as locked.</returns>
    public static string FindLastUnlockedLevelName(string groupName) {
        LayoutUninitializedCheck();

        return FindLastLevelName(groupName, (level) => {
            if (MadLevelProfile.IsLockedSet(level.name)) {
                return !MadLevelProfile.IsLocked(level.name);
            } else {
                return !level.lockedByDefault;
            }
        });
    }
예제 #3
0
    /// <summary>
    /// Gets last unlocked icon or null if cannot be found.
    /// </summary>
    /// <returns></returns>
    public MadLevelIcon GetLastUnlockedIcon()
    {
        var lastUnlocked =
            from l in MadLevel.activeConfiguration.levels
            where l.groupId == configurationGroup &&
            l.type == MadLevel.Type.Level &&
            MadLevelProfile.IsLockedSet(l.name) &&
            MadLevelProfile.IsLocked(l.name) == false
            orderby l.order descending
            select l;
        var lastUnlockedLevel = lastUnlocked.FirstOrDefault();

        if (lastUnlockedLevel != null)
        {
            var lastUnlockedIcon = MadLevelLayout.current.GetIcon(lastUnlockedLevel.name);
            return(lastUnlockedIcon);
        }
        else
        {
            return(null);
        }
    }
예제 #4
0
    bool IsLevelBooleanSet()
    {
        string levelName = icon.level.name;

        switch (specialType)
        {
        case SpecialType.Regular:
            return(MadLevelProfile.IsLevelPropertySet(levelName, name));

        case SpecialType.LevelNumber:
            return(MadLevelProfile.IsLevelPropertySet(levelName, name));

        case SpecialType.Locked:
            return(MadLevelProfile.IsLockedSet(levelName));

        case SpecialType.Completed:
            return(MadLevelProfile.IsCompletedSet(levelName));

        default:
            MadDebug.Assert(false, "Unknown special type: " + specialType);
            return(false);
        }
    }
    public int CountLocked() {
        var levelNames = GetLevelNames();
        int result = 0;

        var layout = MadLevelLayout.TryGet();

        for (int i = 0; i < levelNames.Count; ++i) {
            var levelName = levelNames[i];

            // first look for a layout, because icons locked state are more trustworthy
            if (layout != null) {
                var icon = layout.GetIcon(levelName);
                if (icon != null) {
                    if (icon.locked) {
                        result++;
                    }

                    continue;
                }
            }

            // no layout or no icon
            if (MadLevelProfile.IsLockedSet(levelName)) {
                if (MadLevelProfile.IsLocked(levelName)) {
                    result++;
                }
            } else {
                var lockedByDefault = MadLevel.activeConfiguration.FindLevelByName(levelName).lockedByDefault;
                if (lockedByDefault) {
                    result++;
                }
            }
        }

        return result;
    }
예제 #6
0
    void Build()
    {
        List <MadLevelIcon> allIcons = new List <MadLevelIcon>();

        allIcons.AddRange(MadTransform.FindChildren <MadLevelIcon>(transform));

        int     levelCount    = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        Vector2 currentOffset = Vector2.zero;

        MadLevelIcon previousIcon = null;

        // find out min and max depth
        int min, max;

        iconTemplate.MinMaxDepthRecursively(out min, out max);
        const string name = "level {0:D3}";

        HashSet <MadLevelIcon> activeIcons = new HashSet <MadLevelIcon>();

        for (int levelIndex = 0; levelIndex < levelCount; ++levelIndex)
        {
            MadLevelIcon levelIcon = MadTransform.FindChild <MadLevelIcon>(
                draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
            bool newInstance = levelIcon == null;

            // create new icon instance if it's not exists
            if (newInstance)
            {
                levelIcon = CreateIcon(draggable.transform, string.Format(name, levelIndex + 1), iconTemplate);

                // position & scale
                levelIcon.pivotPoint           = MadSprite.PivotPoint.Center;
                levelIcon.transform.localScale = Vector3.one;

                do
                {
                    levelIcon.transform.localPosition = currentOffset;
                    currentOffset += offset;
                } while (Collides(levelIcon, allIcons));

                allIcons.Add(levelIcon);
            }

            // make it active if deactivated
            if (!MadGameObject.IsActive(levelIcon.gameObject))
            {
                MadGameObject.SetActive(levelIcon.gameObject, true);
            }

            // setup level properties
            levelIcon.levelGroup            = configurationGroup;
            levelIcon.levelIndex            = levelIndex;
            levelIcon.configuration         = currentConfiguration;
            levelIcon.hasLevelConfiguration = true;

            // set level number if exists
            if (levelIcon.levelNumber != null)
            {
                levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
            }

            // level unlock if set
            if (previousIcon != null)
            {
                if (newInstance)
                {
                    previousIcon.unlockOnComplete.Add(levelIcon);
                }
            }
            else
            {
                levelIcon.locked = false;
            }

            if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(levelIcon.level.name))
            {
                levelIcon.locked = levelIcon.level.lockedByDefault;
            }

            previousIcon = levelIcon;

            activeIcons.Add(levelIcon);
        }

        BuildBackgroundTexture();

        DeactivateAllOther(activeIcons);
    }
예제 #7
0
    // builds level icons that are absent now
    private void Build(bool forceDelete)
    {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild <MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = OnDragStopCallback;

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        MadLevelIcon previousIcon = null;

        int levelCount = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount)
        {
            Transform page = MadTransform.FindChild <Transform>(draggable.transform,
                                                                (t) => t.name == "Page " + (pageIndex + 1));
            bool createPageInstance = page == null;

            if (createPageInstance)
            {
                page           = MadTransform.CreateChild <Transform>(draggable.transform, "Page " + (pageIndex + 1));
                page.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;
            }

            Transform pageAnchor = MadTransform.FindChild <Transform>(draggable.transform,
                                                                      (t) => t.name == "Anchor " + (pageIndex + 1));
            if (pageAnchor == null)
            {
                pageAnchor = MadTransform.CreateChild <Transform>(draggable.transform, "Anchor " + (pageIndex + 1));
                pageAnchor.gameObject.AddComponent <MadFollow>();
            }

            var followPage = pageAnchor.GetComponent <MadFollow>();
            followPage.followTransform = page;

            if (createPageInstance || generate)
            {
                switch (pagingMethod)
                {
                case PagingMethod.HorizontalSimple:
                    page.localPosition = ComputePageOffsetHoriz(pageIndex);
                    break;

                case PagingMethod.VerticalSimple:
                    page.localPosition = ComputePageOffsetVert(pageIndex);
                    break;

                case PagingMethod.HorizontalZoom:
                    page.localPosition = ComputePageOffsetHoriz(pageIndex);
                    break;

                case PagingMethod.VerticalZoom:
                    page.localPosition = ComputePageOffsetVert(pageIndex);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            int  levelPageIndex = 0;
            bool stop           = false;
            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y)
            {
                if (stop)
                {
                    break;
                }

                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++, levelPageIndex++)
                {
                    if (limitLevelsPerPage && generate && levelPageIndex == levelsPerPage)
                    {
                        stop = true;
                        break;
                    }

                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon = null;

                    if (!forceDelete)
                    {
                        // look directly under Draggable
                        levelIcon = MadTransform.FindChild <MadLevelIcon>(
                            draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        if (levelIcon != null)
                        {
                            // move to page
                            levelIcon.transform.parent = page;
                        }
                        else
                        {
                            // find under the page
                            levelIcon = MadTransform.FindChild <MadLevelIcon>(
                                page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        }
                    }

                    var  level             = currentConfiguration.GetLevel(MadLevel.Type.Level, configurationGroup, levelIndex);
                    bool createNewInstance = levelIcon == null;

                    if (createNewInstance)
                    {
                        levelIcon = CreateIcon(
                            page.transform, level.name, iconTemplate);
                    }
                    else
                    {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;

                    levelIcon.levelGroup            = configurationGroup;
                    levelIcon.levelIndex            = levelIndex;
                    levelIcon.configuration         = currentConfiguration;
                    levelIcon.hasLevelConfiguration = true;

                    if (!MadGameObject.IsActive(levelIcon.gameObject))
                    {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }
                    else
                    {
                        // re-enable icon to reload its properties
                        MadGameObject.SetActive(levelIcon.gameObject, false);
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    if (generate || createNewInstance)
                    {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        if (!generate)
                        {
                            levelIcon.transform.localPosition =
                                new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);
                        }
                        else
                        {
                            levelIcon.transform.localPosition = IconGeneratedPosition(levelIndex, levelCount, x - 1,
                                                                                      y - 1);
                        }

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null)
                        {
                            levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
                        }
                    }

                    if (previousIcon != null)
                    {
                        if (createNewInstance)
                        {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }

                    if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(level.name))
                    {
                        levelIcon.locked = levelIcon.level.lockedByDefault;
                    }

                    previousIcon = levelIcon;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging();

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren <MadSprite>();

        foreach (var sprite in sprites)
        {
            sprite.editorSelectable = !generate;
        }

#if UNITY_EDITOR
        EditorApplication.delayCall += () => EditorUtility.SetDirty(this);
#endif
    }
예제 #8
0
    // builds level icons that are absent now
    private void Build(bool forceDelete)
    {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild <MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = (index) => {
            pageCurrentIndex = index;
        };

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        MadLevelIcon previousIcon = null;

        int levelCount = configuration.LevelCount(MadLevel.Type.Level, configurationGroup);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount)
        {
            Transform page = MadTransform.FindChild <Transform>(draggable.transform,
                                                                (t) => t.name == "Page " + (pageIndex + 1));
            bool createPageInstance = page == null;

            if (createPageInstance)
            {
                page           = MadTransform.CreateChild <Transform>(draggable.transform, "Page " + (pageIndex + 1));
                page.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;
            }

            if (createPageInstance || generate)
            {
                page.localPosition = new Vector3(pagesXOffset * pageIndex, 0, 0);
            }


            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y)
            {
                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++)
                {
                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon = null;

                    if (!forceDelete)
                    {
                        // look directly under Draggable
                        levelIcon = MadTransform.FindChild <MadLevelIcon>(
                            draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        if (levelIcon != null)
                        {
                            // move to page
                            levelIcon.transform.parent = page;
                        }
                        else
                        {
                            // find under the page
                            levelIcon = MadTransform.FindChild <MadLevelIcon>(
                                page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        }
                    }

                    var  level             = configuration.GetLevel(MadLevel.Type.Level, configurationGroup, levelIndex);
                    bool createNewInstance = levelIcon == null;

                    if (createNewInstance)
                    {
                        levelIcon = CreateIcon(
                            page.transform, level.name, iconTemplate);
                    }
                    else
                    {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;

                    levelIcon.levelGroup            = configurationGroup;
                    levelIcon.levelIndex            = levelIndex;
                    levelIcon.configuration         = configuration;
                    levelIcon.hasLevelConfiguration = true;

                    if (!MadGameObject.IsActive(levelIcon.gameObject))
                    {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }
                    else
                    {
                        // re-enable icon to reload its properties
                        MadGameObject.SetActive(levelIcon.gameObject, false);
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    if (generate || createNewInstance)
                    {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        if (!generate)
                        {
                            levelIcon.transform.localPosition =
                                new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);
                        }
                        else
                        {
                            levelIcon.transform.localPosition = IconGeneratedPosition(levelIndex, levelCount, x - 1,
                                                                                      y - 1);
                        }

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null)
                        {
                            levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
                        }
                    }

                    if (previousIcon != null)
                    {
                        if (createNewInstance)
                        {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }

                    if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(level.name))
                    {
                        levelIcon.locked = levelIcon.level.lockedByDefault;
                    }

                    previousIcon = levelIcon;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging(draggable, (int)Mathf.Ceil((float)levelCount / (gridWidth * gridHeight)));

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren <MadSprite>();

        foreach (var sprite in sprites)
        {
            sprite.editorSelectable = !generate;
        }
    }