public void SetLevelChallengePreview(ChallengeLog challengeLog, string levelName)
    {
        int challengeCount = challengeLog?.GetChallengeCount() ?? 0;

        if (challengeCount <= 0)
        {
            noChallengeText.gameObject.SetActive(true);
            challengeParent.SetActive(false);
        }
        else
        {
            noChallengeText.gameObject.SetActive(false);
            challengeParent.SetActive(true);

            if (packIndex == -1 || levelIndex == -1)
            {
                Vector2 indexes = LevelParser.GetLevelPackLevelIndexes(levelName);
                packIndex  = (int)indexes.x;
                levelIndex = (int)indexes.y;
            }

            for (int i = 0; i < challengeEntries.Count; i++)
            {
                if (i <= challengeCount - 1)
                {
                    challengeEntries[i].gameObject.SetActive(true);
                    challengeEntries[i].UpdateChallengeEntry(challengeLog.GetChallengeData(i), packIndex, levelIndex);
                }
                else
                {
                    challengeEntries[i].gameObject.SetActive(false);
                }
            }
        }
    }
    public void UpdateChallengePreview()
    {
        Vector2      indexes      = LevelParser.GetLevelPackLevelIndexes(LevelLoader.GetLevelName());
        ChallengeLog challengeLog = ChallengeManager.GetCurrentChallengeLog((int)indexes.x, (int)indexes.y);

        challengePreview.SetLevelChallengePreview(challengeLog, LevelLoader.GetLevelName());
    }
    private void SubscribeChallenges(int pack, int level)
    {
        packIndex           = pack;
        levelIndex          = level;
        currentChallengeLog = GetCurrentChallengeLog(packIndex, levelIndex);

        if (currentChallengeLog != null)
        {
            SaveDataAccessor       saveDataAccessor    = new SaveDataAccessor();
            Dictionary <int, bool> challengeDictionary = saveDataAccessor.GetDataValue <Dictionary <int, bool> >(SaveKeys.COMPLETED_CHALLENGES_SAVE_KEY);

            int challengeCount = currentChallengeLog.GetChallengeCount();
            currentChallenges = new List <IChallenge>();

            for (int i = 0; i < challengeCount; i++)
            {
                int challengeKey = Challenge.GetChallengeKey(packIndex, levelIndex, i);
                if (challengeDictionary == null || !challengeDictionary.ContainsKey(challengeKey) || challengeDictionary[challengeKey] == false)
                {
                    IChallenge challenge = currentChallengeLog.GetChallengeData(i) as IChallenge;
                    challenge.SetUpChallenge();

                    currentChallenges.Add(challenge);
                }
            }
        }
    }
    private ChallengeLog CreateChallengeLog(int packIndex, int levelIndex)
    {
        if (!Directory.Exists($"Assets/Resources/ChallengeLogs/Level_Pack_{packIndex}"))
        {
            Directory.CreateDirectory($"Assets/Resources/ChallengeLogs/Level_Pack_{packIndex}");
        }

        ChallengeLog newChallengeLog = CreateInstance <ChallengeLog>();

        AssetDatabase.CreateAsset(newChallengeLog, $"Assets/Resources/ChallengeLogs/Level_Pack_{packIndex}/Level_{levelIndex}.asset");

        return(newChallengeLog);
    }
Exemple #5
0
    public void UnlockLevelButton()
    {
        locked = false;
        GetComponent <Button>().interactable = true;

        SaveDataAccessor saveDataAccessor = new SaveDataAccessor();
        ChallengeLog     challengeLog     = ChallengeManager.GetCurrentChallengeLog(manager.levelPackIndex + 1, buttonIndex + 1);

        Dictionary <int, bool> completedChallenges = saveDataAccessor.GetDataValue <Dictionary <int, bool> >(SaveKeys.COMPLETED_CHALLENGES_SAVE_KEY);

        if (challengeLog != null && completedChallenges != null)
        {
            for (int i = 0; i < challengeLog.GetChallengeCount(); i++)
            {
                int challengeKey = Challenge.GetChallengeKey(manager.levelPackIndex + 1, buttonIndex + 1, i);
                if (completedChallenges.TryGetValue(challengeKey, out bool challengeResult))
                {
                    if (!challengeResult)
                    {
                        completionIcon.SetActive(false);
                        return;
                    }
                }
                else
                {
                    completionIcon.SetActive(false);
                    return;
                }
            }

            completionIcon.SetActive(true);
        }
        else
        {
            completionIcon.SetActive(false);
        }
    }
Exemple #6
0
    public void SetChallengeLog()
    {
        Vector2 indexes = LevelParser.GetLevelPackLevelIndexes(LevelLoader.GetLevelName());

        challengeLog = ChallengeManager.GetCurrentChallengeLog((int)indexes.x, (int)indexes.y);
    }
    private void OnGUI()
    {
        selectedPackIndex  = EditorGUILayout.IntField("Pack", selectedPackIndex, GUILayout.MaxWidth(200f));
        selectedLevelIndex = EditorGUILayout.IntField("Level", selectedLevelIndex, GUILayout.MaxWidth(200f));

        if (GameObject.FindObjectOfType <GameManager>() != null)
        {
            currentChallengeLog = Resources.Load <ChallengeLog>($"ChallengeLogs/Level_Pack_{selectedPackIndex}/Level_{selectedLevelIndex}");
            if (currentChallengeLog == null)
            {
                ChallengeLogCreator window = GetWindow <ChallengeLogCreator>();
                if (GUI.Button(new Rect((window.position.width / 2) - 125f,
                                        (window.position.height / 2) - 30f,
                                        250f,
                                        60f), $"Create Challenge Log For Level {selectedPackIndex}-{selectedLevelIndex}"))
                {
                    currentChallengeLog = CreateChallengeLog(selectedPackIndex, selectedLevelIndex);
                }
            }
            else
            {
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField($"Challenge Log - Level {selectedPackIndex}-{selectedLevelIndex}", EditorStyles.boldLabel, GUILayout.MaxWidth(200f));
                if (GUILayout.Button("Add Challenge", GUILayout.MaxWidth(150f)))
                {
                    List <Type> challengeTypes    = GetAllChallengeTypes();
                    GenericMenu challengeDropDown = new GenericMenu();
                    foreach (Type type in challengeTypes)
                    {
                        challengeDropDown.AddItem(new GUIContent($"Add {type.ToString()}"), false, AddChallenge, CastChallenge(type));
                    }
                    challengeDropDown.ShowAsContext();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Separator();
                GUIStyle style = new GUIStyle();
                style.fontSize  = 28;
                style.fontStyle = FontStyle.Bold;
                EditorGUILayout.LabelField("Challenges", style);
                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                for (int i = 0; i < currentChallengeLog.GetChallengeCount(); i++)
                {
                    Challenge data = currentChallengeLog.GetChallengeData(i);

                    DrawBaseChallenge(i, data);
                    EditorGUILayout.Separator();
                }

                if (GUI.changed)
                {
                    EditorUtility.SetDirty(currentChallengeLog);
                }
            }
        }
        else
        {
            EditorGUILayout.LabelField("Navigate to a level scene to use this editor tool", EditorStyles.centeredGreyMiniLabel);
        }
    }