Пример #1
0
    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);
                }
            }
        }
    }
Пример #2
0
    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);
                }
            }
        }
    }
Пример #3
0
    public void CheckChallengesForCompletion()
    {
        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();
            for (int i = 0; i < challengeCount; i++)
            {
                IChallenge challenge = currentChallengeLog.GetChallengeData(i) as IChallenge;
                if (challenge != null)
                {
                    int challengeKey = Challenge.GetChallengeKey(packIndex, levelIndex, i);
                    if (challenge.CheckForCompletedChallenge())
                    {
                        if (challengeDictionary == null)
                        {
                            challengeDictionary = new Dictionary <int, bool>();
                            challengeDictionary.Add(challengeKey, true);

                            saveDataAccessor.SetData(SaveKeys.COMPLETED_CHALLENGES_SAVE_KEY, challengeDictionary);
                            DataTracker.dataTracker.SaveData();
                        }
                        else if (!challengeDictionary.ContainsKey(challengeKey))
                        {
                            challengeDictionary.Add(challengeKey, true);

                            saveDataAccessor.SetData(SaveKeys.COMPLETED_CHALLENGES_SAVE_KEY, challengeDictionary);
                            DataTracker.dataTracker.SaveData();
                        }
                        else
                        {
                            challengeDictionary[challengeKey] = true;
                        }
                    }
                }
            }
        }
    }
Пример #4
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);
        }
    }
Пример #5
0
    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);
        }
    }