void SaveProgress()
    {
        PlayerProgress currLevelProgress = new PlayerProgress(
            levelMode,
            levelNo,
            starPercent,
            timePassed,
            wrongTries,
            nextNumber,
            true,
            false
            );

        ProgressController.SaveProgress(currLevelProgress);

        // If there is no level or we could not get one star, do not unlock next level.
        if (levelNo == levels.Count || starPercent < starPercents[0])
        {
            UICont.DisableNextButton();
            return;
        }

        // We have a next level, so unlock it.
        PlayerProgress nextLevelProgress = ProgressController.GetProgress(levelMode, levelNo + 1);

        nextLevelProgress.locked = false;

        ProgressController.SaveProgress(nextLevelProgress);
    }
Example #2
0
    void Start()
    {
        if (progressController == null)
        {
            progressController = GetComponent <ProgressController>();
        }
        unlockedLevels = Mathf.Max(unlockedLevels, progressController.GetProgress().completedLevels + 1);
        for (var i = 0; i < transform.childCount; i++)
        {
            var levelButton  = transform.GetChild(i);
            var levelNumber  = levelButton.GetComponent <LevelNumber>().LevelNum;
            var buttonStatus = levelButton.GetComponent <LevelButtonStatusController>();

            if (levelNumber < unlockedLevels)
            {
                buttonStatus.SetButtonState(LevelButtonState.Unlocked);
            }
            else if (levelNumber == unlockedLevels)
            {
                buttonStatus.SetButtonState(LevelButtonState.Hidden);
            }
            else if (levelNumber > unlockedLevels)
            {
                buttonStatus.SetButtonState(LevelButtonState.Locked);
            }
        }
    }
Example #3
0
    void AddLevelCards()
    {
        for (int levelNo = 0; levelNo < countOfLevel; levelNo++)
        {
            Level level = levels[levelNo];

            GameObject levelPicker = Instantiate(levelPickerPrefab, contentObject);
            levelPicker.name = levelNo.ToString();

            Transform table = levelPicker.transform.Find("LevelTable").Find("Table");

            int designIndex = 0;
            for (int cardNo = 0; cardNo < table.childCount; cardNo++)
            {
                // TODO: This code is for testing. When we decide about colors,
                // we'll fix this code.

                Color testColor = levelPickerHiddenCards;
                //testColor.a = 0.4f;

                if (designIndex < level.design.Count && level.design[designIndex] == cardNo + 1)
                {
                    Sprite s = Resources.Load <Sprite>("Sprites/UISprites/CardSprite/UI_Icon_Card_Rect");
                    table.GetChild(cardNo).GetComponent <Image>().sprite = s;
                    table.GetChild(cardNo).GetComponent <Image>().color  = Color.white;

                    //table.GetChild(cardNo).GetComponent<Image>().enabled = true;
                    designIndex++;
                }
                else
                {
                    table.GetChild(cardNo).GetComponent <Image>().sprite = null;
                    table.GetChild(cardNo).GetComponent <Image>().color  = testColor;
                    //table.GetChild(cardNo).GetComponent<Image>().enabled = false;
                }
            }

            PlayerProgress progress = ProgressController.GetProgress(levelMode, levelNo + 1);

            Transform       levelInfo     = levelPicker.transform.Find("LevelInfo");
            TextMeshProUGUI levelText     = levelInfo.Find("LevelText").GetComponent <TextMeshProUGUI>();
            TextMeshProUGUI levelDiffText = levelPicker.transform.Find("LevelDifficulty").GetComponent <TextMeshProUGUI>();
            levelText.text = string.Format("{0} {1}", StringLiterals.levelText[(int)DataTransfer.language], (levelNo + 1));
            //I want it to look cool with textmesh pro thats why I am doing this...
            string leveldifficultyString = "";
            int    langIndex             = PlayerPrefs.HasKey("lang") ? PlayerPrefs.GetInt("lang") : 0;

            switch (level.difficulty)
            {
            case LevelDifficulty.EASY:
                leveldifficultyString = StringLiterals.easyText[langIndex];
                break;

            case LevelDifficulty.MEDIUM:
                leveldifficultyString = StringLiterals.mediumText[langIndex];
                break;

            case LevelDifficulty.HARD:
                leveldifficultyString = StringLiterals.hardText[langIndex];
                break;
            }

            levelDiffText.text = leveldifficultyString;

            Transform info          = levelInfo.Find("Info");
            Transform bestTimeInfo  = info.Find("Info_BestTime");;
            Transform bestTryInfo   = info.Find("Info_BestTry");
            Transform bestCountInfo = info.Find("Info_BestCount");

            if (levelMode == LevelMode.CLASSIC)
            {
                TextMeshProUGUI bestTimeInfoText = bestTimeInfo.GetComponentInChildren <TextMeshProUGUI>();
                bestTimeInfoText.text = (progress.completed) ? string.Format("{0:F2}", progress.bestTime) : "";
            }
            bestTimeInfo.gameObject.SetActive(levelMode == LevelMode.CLASSIC);

            if (levelMode == LevelMode.DO_NOT_FORGET || levelMode == LevelMode.CLASSIC)
            {
                TextMeshProUGUI bestTryInfoText = bestTryInfo.GetComponentInChildren <TextMeshProUGUI>();
                bestTryInfoText.text = (progress.completed) ? progress.bestTry.ToString() : "";
            }
            bestTryInfo.gameObject.SetActive(levelMode == LevelMode.DO_NOT_FORGET || levelMode == LevelMode.CLASSIC);

            if (levelMode == LevelMode.NO_MISTAKE)
            {
                TextMeshProUGUI bestCountInfoText = bestCountInfo.GetComponentInChildren <TextMeshProUGUI>();
                bestCountInfoText.text = (progress.completed) ? progress.bestCount.ToString() :  "";
            }
            bestCountInfo.gameObject.SetActive(levelMode == LevelMode.NO_MISTAKE);


            Transform stars = levelInfo.transform.Find("Stars");
            stars.GetComponentInChildren <Image>().fillAmount = progress.starPercent;

            Transform levelPickerButton = levelPicker.transform.Find("PickButton");
            Transform levelLockedIcon   = levelPicker.transform.Find("LockedIcon");

            if (levelNo != 0 && progress.locked == true)
            {
                levelLockedIcon.gameObject.SetActive(true);
            }
            else
            {
                AddButtonListener(levelPickerButton, levelNo);
            }
        }
    }