Exemple #1
0
    void CleanUp(bool forceDelete)
    {
        int levelCount = configuration.LevelCount(MadLevel.Type.Level);
        var children   = MadTransform.FindChildren <MadLevelIcon>(transform, (icon) => icon.hasLevelConfiguration);

        if (forceDelete)
        {
            foreach (var child in children)
            {
                MadGameObject.SafeDestroy(child.gameObject);
            }
        }
        else
        {
            var sorted = from c in children orderby c.levelIndex ascending select c;

            foreach (MadLevelIcon levelIcon in sorted)
            {
                if (levelIcon.levelIndex >= levelCount)
                {
                    // disable leftovers
                    MadGameObject.SetActive(levelIcon.gameObject, false);
                }
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Gets all active icons available in the layout.
    /// </summary>
    /// <returns></returns>
    public MadLevelIcon[] GetAllIcons()
    {
        // find under the page
        var icons = MadTransform.FindChildren <MadLevelIcon>(
            transform, (ic) => MadGameObject.IsActive(ic.gameObject), 3);

        return(icons.ToArray());
    }
    void RebuildClean()
    {
        var generated = MadTransform.FindChildren <MadSprite>(transform, (sprite) => sprite.name.StartsWith("generated_"));

        foreach (var obj in generated)
        {
            MadGameObject.SafeDestroy(obj.gameObject);
        }
    }
    // deactivates all other icons under the draggable than given
    private void DeactivateAllOther(HashSet <MadLevelIcon> activeIcons)
    {
        var allIcons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);

        foreach (var icon in allIcons)
        {
            if (!activeIcons.Contains(icon))
            {
                MadGameObject.SetActive(icon.gameObject, false);
            }
        }
    }
Exemple #5
0
    void BuildDragging(MadDragStopDraggable dragHandler, int dragStops)
    {
        var pages = MadTransform.FindChildren <Transform>(dragHandler.transform, (t) => t.name.StartsWith("Page"), 0);

        pages.Sort((a, b) => { return(a.localPosition.x.CompareTo(b.localPosition.x)); });

        for (int i = 0; i < pages.Count; ++i)
        {
            int dragStopIndex = dragHandler.AddDragStop(pages[i].localPosition.x, 0);
            var page          = new Page(dragStopIndex);
            this.pages.Add(page);
        }
    }
Exemple #6
0
    public void MinMaxDepthRecursively(out int min, out int max)
    {
        min = guiDepth;
        max = guiDepth;

        var sprites = MadTransform.FindChildren <MadSprite>(transform);

        foreach (var sprite in sprites)
        {
            min = Mathf.Min(min, sprite.guiDepth);
            max = Mathf.Max(max, sprite.guiDepth);
        }
    }
    void UpdateLayers()
    {
        layers.Clear();

        layers.AddRange(MadTransform.FindChildren <MadLevelBackgroundLayer>(transform));
        layers = layers.OrderBy(o => o.name).ToList(); // sort by name

        foreach (var l in layers)
        {
            var sprite = l.GetComponent <MadSprite>();
            sprite.hideFlags = HideFlags.HideInInspector;
        }
    }
Exemple #8
0
    private int NextDepth()
    {
        int maxDepth = sprite.guiDepth;

        foreach (var s in MadTransform.FindChildren <MadSprite>(sprite.transform))
        {
            if (s.guiDepth > maxDepth)
            {
                maxDepth = s.guiDepth;
            }
        }

        return(maxDepth + 1);
    }
Exemple #9
0
    private void BuildDragging()
    {
        var pages = MadTransform.FindChildren <Transform>(draggable.transform, (t) => t.name.StartsWith("Page"), 0);

        pages.Sort((a, b) => {
            var aNum = int.Parse(a.name.Split(' ')[1]);
            var bNum = int.Parse(b.name.Split(' ')[1]);
            return(aNum.CompareTo(bNum));
        });

        draggable.ClearDragStops();

        this.pages.Clear();
        for (int i = 0; i < pages.Count; ++i)
        {
            int dragStopIndex = draggable.AddDragStop(pages[i].localPosition.x, pages[i].localPosition.y);
            var page          = new Page(dragStopIndex, pages[i].transform);
            this.pages.Add(page);
        }

        switch (pagingMethod)
        {
        case PagingMethod.HorizontalSimple:
            draggable.direction = MadDragStopDraggable.Direction.Horizontal;
            break;

        case PagingMethod.VerticalSimple:
            draggable.direction = MadDragStopDraggable.Direction.Vertical;
            break;

        case PagingMethod.HorizontalZoom:
            draggable.direction = MadDragStopDraggable.Direction.Horizontal;
            break;

        case PagingMethod.VerticalZoom:
            draggable.direction = MadDragStopDraggable.Direction.Vertical;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        draggable.directionInvert = pagingInvert;
    }
    public override MadLevelIcon FindClosestIcon(Vector3 position)
    {
        var icons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform, (ic) => true, 0);

        float        closestsDistance = float.PositiveInfinity;
        MadLevelIcon closestIcon      = null;

        foreach (var icon in icons)
        {
            float distance = Vector3.Distance(icon.transform.position, position);
            if (distance < closestsDistance)
            {
                closestsDistance = distance;
                closestIcon      = icon;
            }
        }

        return(closestIcon);
    }
Exemple #11
0
    public override MadLevelIcon FindClosestIcon(Vector3 position)
    {
        MadLevelIcon closestIcon     = null;
        float        closestDistance = float.MaxValue;

        var icons = MadTransform.FindChildren <MadLevelIcon>(transform);

        foreach (var icon in icons)
        {
            float distance = Vector3.Distance(position, icon.transform.position);
            if (distance < closestDistance)
            {
                closestIcon     = icon;
                closestDistance = distance;
            }
        }

        return(closestIcon);
    }
Exemple #12
0
    private void CleanUp(bool forceDelete)
    {
        int levelCount = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        var children   = MadTransform.FindChildren <MadLevelIcon>(transform, (icon) => icon.hasLevelConfiguration);

        if (forceDelete)
        {
            foreach (var child in children)
            {
                DestroyImmediate(child.gameObject);
            }

            // remove all pages
            var pages = MadTransform.FindChildren <Transform>(transform, (t) => t.name.StartsWith("Page "));
            foreach (var page in pages)
            {
                DestroyImmediate(page.gameObject);
            }
        }
        else
        {
            var sorted = from c in children orderby c.levelIndex ascending select c;

            foreach (MadLevelIcon levelIcon in sorted)
            {
                if (levelIcon.levelIndex >= levelCount)
                {
                    // disable leftovers
                    MadGameObject.SetActive(levelIcon.gameObject, false);
                }
            }
        }

        // remove slides
        ClearSlide("SlideLeftAnchor");
        ClearSlide("SlideRightAnchor");
    }
    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);
    }
    /// <summary>
    /// Will replace all icons in the layout with selected icon. Position, scale and rotation will be preserved.
    /// This method is meant for editor-use only.
    /// </summary>
    /// <param name="newIcon"></param>
    public void ReplaceIcons(GameObject newIcon)
    {
        if (Application.isPlaying)
        {
            Debug.LogError("This method can be called only from the editor");
            return;
        }

        MadUndo.LegacyRegisterSceneUndo("Replaced Icons");

        var icons       = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);
        var activeIcons = from i in icons where MadGameObject.IsActive(i.gameObject) select i;

        // keep track of unlock on complete settings
        Dictionary <int, List <int> > unlockOnCompleteDict = new Dictionary <int, List <int> >();
        List <MadLevelIcon>           createdIcons         = new List <MadLevelIcon>();

        foreach (var icon in activeIcons)
        {
            var position      = icon.transform.position;
            var rotation      = icon.transform.rotation;
            var localScale    = icon.transform.localScale;
            var name          = icon.name;
            var baseDepth     = icon.guiDepth;
            var levelIndex    = icon.levelIndex;
            var configuration = icon.configuration;

            // build unlock on complete dict
            List <int> toUnlockList = new List <int>();
            foreach (var unlock in icon.unlockOnComplete)
            {
                toUnlockList.Add(unlock.levelIndex);
            }
            unlockOnCompleteDict[icon.levelIndex] = toUnlockList;


            MadUndo.DestroyObjectImmediate(icon.gameObject);

            var nIcon = CreateIcon(draggable.transform, name, iconTemplate);
            nIcon.transform.position    = position;
            nIcon.transform.rotation    = rotation;
            nIcon.transform.localScale  = localScale;
            nIcon.guiDepth              = baseDepth;
            nIcon.levelIndex            = levelIndex;
            nIcon.configuration         = configuration;
            nIcon.hasLevelConfiguration = true;

            createdIcons.Add(nIcon);


            var childSprites = MadTransform.FindChildren <MadSprite>(nIcon.transform);
            foreach (var cs in childSprites)
            {
                cs.guiDepth += baseDepth;
            }

            MadUndo.RegisterCreatedObjectUndo(nIcon.gameObject, "Replaced Icons");
        }

        icons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);

        // apply unlock on complete list
        foreach (var icon in createdIcons)
        {
            List <int> unlockList = unlockOnCompleteDict[icon.levelIndex];
            foreach (var unlockLevelIndex in unlockList)
            {
                var          query        = from i in icons where i.levelIndex == unlockLevelIndex select i;
                MadLevelIcon iconToUnlock = query.First();
                icon.unlockOnComplete.Add(iconToUnlock);
            }
        }
    }
    public void PlayFinishAnimation(MadSprite chosenSprite, bool completed)
    {
        levelNameText.eventFlags = MadSprite.EventFlags.None;
        argumentsText.eventFlags = MadSprite.EventFlags.None;
        backToMenu.eventFlags    = MadSprite.EventFlags.None;

        Color transparent = new Color(1, 1, 1, 0);
        Color opaque      = new Color(1, 1, 1, 1);

        levelNameText.AnimColorTo(transparent, 1, MadiTween.EaseType.linear);
        argumentsText.AnimColorTo(transparent, 1, MadiTween.EaseType.linear);
        backToMenu.AnimColorTo(transparent, 1, MadiTween.EaseType.linear);

        if (completed)
        {
            levelCompletedText.tint    = transparent;
            levelCompletedText.visible = true;
            levelCompletedText.AnimColorTo(opaque, 1, MadiTween.EaseType.linear);
        }
        else
        {
            levelNotCompletedText.tint    = transparent;
            levelNotCompletedText.visible = true;
            levelNotCompletedText.AnimColorTo(opaque, 1, MadiTween.EaseType.linear);
        }

        foreach (var sprite in other)
        {
            var children = MadTransform.FindChildren <MadSprite>(sprite.transform);

            sprite.eventFlags = MadSprite.EventFlags.None;
            foreach (var s in children)
            {
                s.eventFlags = MadSprite.EventFlags.None;
            }

            if (sprite != chosenSprite)
            {
                sprite.AnimColorTo(transparent, 1, MadiTween.EaseType.linear);

                foreach (var s in children)
                {
                    s.AnimColorTo(transparent, 1, MadiTween.EaseType.linear);
                }
            }
        }

        chosenSprite.AnimMoveTo(new Vector3(), 1, MadiTween.EaseType.easeOutSine);

        MadiTween.ScaleTo(chosenSprite.gameObject, MadiTween.Hash(
                              "scale", new Vector3(7, 7, 7),
                              "time", 0.5f,
                              "easetype", MadiTween.EaseType.easeInQuint,
                              "delay", 1.5f
                              ));

        MadiTween.ValueTo(chosenSprite.gameObject, MadiTween.Hash(
                              "from", chosenSprite.tint,
                              "to", transparent,
                              "time", 0.5f,
                              "onupdate", "OnTintChange",
                              "easetype", MadiTween.EaseType.easeInQuint,
                              "delay", 1.5f
                              ));

        foreach (var s in MadTransform.FindChildren <MadSprite>(chosenSprite.transform))
        {
            MadiTween.ValueTo(s.gameObject, MadiTween.Hash(
                                  "from", s.tint,
                                  "to", transparent,
                                  "time", 0.5f,
                                  "onupdate", "OnTintChange",
                                  "easetype", MadiTween.EaseType.easeInQuint,
                                  "delay", 1.5f
                                  ));
        }
    }
Exemple #16
0
    void Build()
    {
        int     levelCount    = configuration.LevelCount(MadLevel.Type.Level);
        Vector2 currentOffset = Vector2.zero;

        MadLevelIcon previousIcon = null;

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

        iconTemplate.MinMaxDepthRecursively(out min, out max);
        int depthDiff = (max - min) + 1;

        const string name = "level {0:D3}";

        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 = MadTransform.CreateChild(
                    draggable.transform, string.Format(name, levelIndex + 1), iconTemplate);

                // adjust gui depth for each icon
                levelIcon.guiDepth += levelIndex * depthDiff;
                var sprites = MadTransform.FindChildren <MadSprite>(levelIcon.transform);
                foreach (var sprite in sprites)
                {
                    sprite.guiDepth += levelIndex * depthDiff;
                }

                // position & scale
                levelIcon.pivotPoint = MadSprite.PivotPoint.Center;
                levelIcon.transform.localPosition = currentOffset;
                currentOffset += offset;

                levelIcon.transform.localScale = Vector3.one;
            }

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

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

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

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

            previousIcon = levelIcon;
        }

        BuildBackgroundTexture();
    }