private void InitFinalize()
 {
     if (asyncLoading)
     {
         if (MadLevel.hasExtension && MadLevel.CanContinue())
         {
             asyncOperation = MadLevel.ContinueAsync();
         }
         else
         {
             Debug.LogWarning("Level loading screen is meant to be in extension as 'before' scene.");
             asyncOperation = MadLevel.LoadNextAsync();
         }
     }
 }
    void CompleteAllLevels()
    {
        if (!CheckPlaying())
        {
            return;
        }

        var levelNames = MadLevel.GetAllLevelNames();

        foreach (var levelName in levelNames)
        {
            MadLevelProfile.SetCompleted(levelName, true);
        }

        MadLevel.ReloadCurrent();
    }
    void UnlockAllLevels()
    {
        if (!CheckPlaying())
        {
            return;
        }

        var levelNames = MadLevel.GetAllLevelNames();

        foreach (var levelName in levelNames)
        {
            MadLevelProfile.SetLocked(levelName, false);
        }

        MadLevel.ReloadCurrent();
    }
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    void Start()
    {
        var sprite = GetComponent <MadSprite>();

        if (sprite != null)
        {
            sprite.onMouseEnter += (s) =>
                                   sprite.AnimScaleTo(Vector3.one * 1.5f, 1, MadiTween.EaseType.easeOutElastic);
            sprite.onMouseExit += (s) =>
                                  sprite.AnimScaleTo(Vector3.one, 1, MadiTween.EaseType.easeOutElastic);
            sprite.onMouseDown += sprite.onTap = (s) => {
                MadLevelProfile.Reset();
                MadLevel.ReloadCurrent();
            };
        }
    }
Beispiel #5
0
    private void Execute()
    {
        // gain stars
        for (int i = 1; i <= starsCount; i++) // i = 1, 2, 3...
        {
            string starName = "star_" + i;    // this is the star property name
            MadLevelProfile.SetLevelBoolean(MadLevel.currentLevelName, starName, true);
        }

        // complete level
        if (completeLevel)
        {
            MadLevelProfile.SetCompleted(MadLevel.currentLevelName, true);
        }

        // go back to level select screen
        MadLevel.LoadLevelByName("Level Select"); // name from level configuration
    }
    void ResetProfile(string profile)
    {
        if (!CheckPlaying())
        {
            return;
        }

        if (EditorUtility.DisplayDialog(
                "Reset Profile " + profile + "?",
                "Are you sure you want to reset profile '" + profile + "'? This cannot be undone.",
                "Yes", "No"))
        {
            string prevProfile = MadLevelProfile.profile;
            MadLevelProfile.profile = selectedProfileName;
            MadLevelProfile.Reset();
            MadLevelProfile.profile = prevProfile;

            MadLevel.ReloadCurrent();
        }
    }
    private void Update()
    {
        frameNumber++;

        if (!asyncLoading)
        {
            if (frameNumber >= notAsyncLoadingStartFrame)
            {
                if (MadLevel.hasExtension && MadLevel.CanContinue())
                {
                    MadLevel.Continue();
                }
                else
                {
                    Debug.LogWarning("Level loading screen is meant to be in extension as 'before' scene.");
                    MadLevel.LoadNext();
                }
            }
        }
    }
Beispiel #8
0
    void UpdateHandleMobileBackButton()
    {
        if (SystemInfo.deviceType == DeviceType.Handheld)
        {
            if (handleMobileBackButton && Input.GetKey(KeyCode.Escape))
            {
                switch (handleMobileBackButtonAction)
                {
                case OnMobileBack.LoadPreviousLevel:
                    MadLevel.LoadPrevious();
                    break;

                case OnMobileBack.LoadSpecifiedLevel:
                    MadLevel.LoadLevelByName(handleMobileBackButtonLevelName);
                    break;

                default:
                    Debug.LogError("Unknown action: " + handleMobileBackButtonAction);
                    break;
                }
            }
        }
    }
    public void LoadLevel()
    {
        if (hasLevelConfiguration)
        {
            var level = configuration.GetLevel(MadLevel.Type.Level, levelGroup, levelIndex);
            MadLevel.LoadLevelByName(level.name);
        }
        else
        {
            if (!string.IsNullOrEmpty(levelSceneName))
            {
                MadLevelProfile.recentLevelSelected = level.name;

                MadLevel.currentLevelName = level.name;
                MadLevel.arguments        = "";
                Application.LoadLevel(levelSceneName);
            }
            else
            {
                Debug.LogError("Level scene name not set. I don't know what to load!");
                return;
            }
        }
    }
Beispiel #10
0
 public Level GetLevel(MadLevel.Type type, int index) {
     return GetLevel(type, -1, index);
 }
Beispiel #11
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;
 }
Beispiel #12
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;
 }
Beispiel #13
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, string groupName) {
     return FindLastLevelName(groupName, (level) => level.type == levelType);
 }
Beispiel #14
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(null, (level) => level.type == levelType);
 }
Beispiel #15
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;
        }
    }
Beispiel #16
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, string group = null) {
        CheckHasConfiguration();
        var output = new List<string>();
        for (int i = 0; i < activeConfiguration.levels.Count; ++i) {
            var level = activeConfiguration.levels[i];
            if (group != null && level.group.name != group) {
                continue;
            }

            if (level.type == type) {
                output.Add(level.name);
            }
        }
        
        return output.ToArray();
    }
Beispiel #17
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;
    }
Beispiel #18
0
 public Level FindPreviousLevel(string currentLevelName, MadLevel.Type type) {
     return FindPreviousLevel(currentLevelName, type, false);
 }
Beispiel #19
0
    /// <summary>
    /// Gets the icon representation for the first level (in order).
    /// </summary>
    /// <returns>The first level icon.</returns>
    public MadLevelIcon GetFirstIcon()
    {
        string firstLevelName = MadLevel.FindFirstLevelName(MadLevel.Type.Level);

        return(GetIcon(firstLevelName));
    }
Beispiel #20
0
    /// <summary>
    /// Gets the icon representation for the last level (in order).
    /// </summary>
    /// <returns>The last level icon.</returns>
    public MadLevelIcon GetLastIcon()
    {
        string lastLevelName = MadLevel.FindLastLevelName(MadLevel.Type.Level);

        return(GetIcon(lastLevelName));
    }
Beispiel #21
0
 // ===========================================================
 // Methods
 // ===========================================================
 
 /// <summary>
 /// Reloads current level. If this level has an extension, it will load first scene of its extension.
 /// </summary>
 public static void ReloadCurrent() {
     MadLevel.LoadLevelByName(currentLevelName);
 }
Beispiel #22
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();
     }
 }
Beispiel #23
0
 public int LevelCount(MadLevel.Type type) {
     return LevelCount(type, -1);
 }
Beispiel #24
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;
    }
Beispiel #25
0
 public int FindLevelIndex(MadLevel.Type type, string levelName) {
     return FindLevelIndex(type, -1, levelName);
 }
Beispiel #26
0
 void OnMouseDown()
 {
     Debug.Log("Level lost", this);
     MadLevel.LoadLevelByName("Level Select");
 }
Beispiel #27
0
 public MadLevelQuery OfLevelType(MadLevel.Type levelType) {
     hasLevelType = true;
     this.levelType = levelType;
     return this;
 }