Example #1
0
    public override IEnumerator Open(float duration = 0.25F)
    {
        prevButton.DOAnchorPosX(80, duration);
        nextButton.DOAnchorPosX(-80, duration);
        backButton.DOAnchorPosY(95, duration);
        title.DOAnchorPosY(-80, duration);
        yield return(worldMap.Close(0));

        yield return(worldMap.Open(MemoryCard.Load().GetLastUnlockedWorld()));
    }
    public void BuildPath(List <Vector2> positions)
    {
        MemoryCard           mc     = MemoryCard.Load();
        List <LevelProgress> levels = mc.levels[currentWorld].levels;

        for (int i = 0; i < levels.Count; i++)
        {
            var go = Instantiate(levelPrefab, levelRoot).GetComponent <RectTransform>();
            go.anchoredPosition = positions[i];
            go.GetComponent <LevelButton>().SetInfo(
                i,
                currentWorld,
                levels[i].GetStars(worldList.worlds[currentWorld].levels[i]));
        }
    }
    private IEnumerator ShowLevelButtons()
    {
        var memory = MemoryCard.Load();

        if (memory.levels.Count == 0)
        {
            memory.levels.Add(new LevelProgress());
            memory.Save();
        }
        for (int i = LastUnlockedLevel(memory.levels) - 1; i >= 0; i--)
        {
            var go = Instantiate(levelButtonPrefab, buttonRoot);
            go.GetComponent <LevelButton>().SetData(data.levels[i], memory.levels[i], i);
        }
        yield return(null);
    }
    public IEnumerator Change(int bias)
    {
        MemoryCard mc = MemoryCard.Load();
        int        lastUnlockedWorld = mc.levels.Count - 1;

        if (currentWorld + bias < 0 || currentWorld + bias > lastUnlockedWorld)
        {
            yield break;
        }
        var index = Mathf.Clamp(currentWorld + bias, 0, lastUnlockedWorld);

        yield return(Close());

        currentWorld = index;
        yield return(Open(index));
    }
    public IEnumerator OpenPanel(TreasureInfo info, int steps)
    {
        CameraMovement.canBeMoved++;

        header.transform.DOScale(0, 0);
        stepPanel.Hide();
        diamondPanel.Hide();

        foreach (var button in buttons)
        {
            button.GetComponent <RectTransform>().DOAnchorPosY(-buttonsY, 0);
        }

        group.DOFade(1, 0.5f);
        group.interactable   = true;
        group.blocksRaycasts = true;

        yield return(new WaitForSeconds(0.5f));

        header.transform.DOScale(1f, 0.5f);

        var level = LevelManager.me.levels.levels[MemoryCard.GetSelectedLevel()];

        yield return(diamondPanel.Appear(info.littleTreasures.Count, level.map.treasures.Count));

        yield return(stepPanel.Appear(steps, level.maxSteps));

        SaveProgress(info, steps);

        bool thereIsANextLevel = MemoryCard.Load().levels.Count - 1 > MemoryCard.GetSelectedLevel();

        foreach (var button in buttons)
        {
            if (!(button == nextLevel && thereIsANextLevel))
            {
                button.GetComponent <RectTransform>().DOAnchorPosY(buttonsY, 0.1f);
                yield return(new WaitForSeconds(0.1f));
            }
        }
    }
    public void SaveProgress(TreasureInfo info, int steps)
    {
        var memory = MemoryCard.Load();

        if (memory.levels[MemoryCard.GetSelectedLevel()].bigTreasures == 0)
        {
            // Desbloquear nova fase
            memory.levels.Add(new LevelProgress());
        }

        memory.levels[MemoryCard.GetSelectedLevel()].steps =
            steps < memory.levels[MemoryCard.GetSelectedLevel()].steps ?
            steps : memory.levels[MemoryCard.GetSelectedLevel()].steps;

        memory.levels[MemoryCard.GetSelectedLevel()].treasures =
            info.littleTreasures.Count > memory.levels[MemoryCard.GetSelectedLevel()].treasures ?
            info.littleTreasures.Count : memory.levels[MemoryCard.GetSelectedLevel()].treasures;

        memory.levels[MemoryCard.GetSelectedLevel()].bigTreasures =
            info.bigTreasures.Count > memory.levels[MemoryCard.GetSelectedLevel()].bigTreasures ?
            info.bigTreasures.Count : memory.levels[MemoryCard.GetSelectedLevel()].bigTreasures;

        memory.Save();
    }