示例#1
0
    public void StageApproved()
    {
        audio.PlayOneShot(stageApprovedAudio, PlayerPrefs.GetFloat(PlayerPrefsKeys.VOLUME));
        //terminar loading e lançar janela de level aprovado, com callback das linhas abaixo
        Flow.AddCustomStage(tileset, currentWorld, totalMines, inputName.GetComponent <UITextField>().Text, -1);

        Flow.header.transform.FindChild("OptionsPanel").gameObject.SetActive(false);

        Flow.nextPanel = PanelToLoad.CustomStages;

        Application.LoadLevel("Mainmenu");
    }
示例#2
0
    void CreateChallengeContainerImproved(IJSonObject item, IJSonObject data)
    {
        CustomStage cs = new CustomStage();

        cs.creatorName = item["username"].ToString();
        cs.id          = item["customLevelID"].Int32Value;
        cs.isChallenge = true;
        if (item["time"].IsNull && item["isMe"].BooleanValue)
        {
            cs.isNew = true;
        }
        else
        {
            cs.isNew = false;
        }
        cs.name   = item["name"].ToString();
        cs.world  = item["worldID"].Int32Value - 3;
        cs.hostID = item["creatorID"].StringValue;
        cs.isMe   = item["isMe"].BooleanValue;

        int                numberOfMines = 0;
        string             testTileset   = "";
        List <List <int> > tileset       = new List <List <int> >();

        for (int i = 0; i < 8; i++)
        {
            List <int> row = new List <int>();
            for (int j = 0; j < 8; j++)
            {
                testTileset += item["tileset"].StringValue[i * 8 + j].ToString();
                row.Add(int.Parse(item["tileset"].StringValue[i * 8 + j].ToString()));
                if (int.Parse(item["tileset"].StringValue[i * 8 + j].ToString()) == 1)
                {
                    numberOfMines++;
                }
            }
            tileset.Add(row);
        }
        cs.numberOfMines = numberOfMines;
        cs.tileset       = tileset;
        //falta definir as estrelas, se for ter mesmo

        //Debug.Log("chegou um challenge de tileset " + testTileset);

        Flow.customGames.Add(cs);

        if (item["creatorID"].StringValue != Save.GetString(PlayerPrefsKeys.ID) && !item["isMe"].BooleanValue)
        {
            //Debug.Log("non me interessa pq n tem nada a ver comigo");
            return;
        }

        if (!cs.isNew)
        {
            foreach (CustomStage c in Flow.customGames)
            {
                if (c.id == cs.id && Flow.customGames.IndexOf(c) != Flow.customGames.Count - 1 && (c.isMe || item["creatorID"].StringValue == Save.GetString(PlayerPrefsKeys.ID)))
                {
                    //Debug.Log("impedindo que crie um container novo para um ranking que ja existe");
                    return;
                }
            }
            foreach (IJSonObject subItem in data.ArrayItems)
            {
                //Debug.Log(subItem);
                if (subItem["customLevelID"].Int32Value == cs.id && subItem["time"].IsNull && subItem["isMe"].BooleanValue)
                {
                    //Debug.Log("impedindo que crie um container novo para um uma challenge nova que vai existir");
                    return;
                }
            }
        }

        IUIListObject g = null;

        if (cs.isNew)
        {
            g = newPanel.transform.FindChild("NewScroll").GetComponent <UIScrollList>().CreateItem(newContainerPrefab);
            g.transform.FindChild("Name").GetComponent <SpriteText>().Text      = cs.creatorName;
            g.transform.FindChild("Mines").GetComponent <SpriteText>().Text     = "Mines: " + cs.numberOfMines;
            g.transform.FindChild("StageName").GetComponent <SpriteText>().Text = cs.name;
            g.transform.FindChild("World" + (1 + cs.world).ToString()).gameObject.SetActive(true);

            //Debug.Log("adicionei no novo");
        }
        else if (!cs.isNew)
        {
            g = oldPanel.transform.FindChild("OldScroll").GetComponent <UIScrollList>().CreateItem(oldContainerPrefab);
            g.transform.FindChild("Name").GetComponent <SpriteText>().Text  = cs.name;
            g.transform.FindChild("Mines").GetComponent <SpriteText>().Text = "Mines: " + cs.numberOfMines;
            g.transform.FindChild("Host").GetComponent <SpriteText>().Text  = "Hosted by " + cs.creatorName;
            g.transform.FindChild("World" + (1 + cs.world).ToString()).gameObject.SetActive(true);

            //Debug.Log("adicionei no velho");
        }

        g.transform.GetComponent <ChallengesButton>().challengeIndex = Flow.customGames.IndexOf(cs);
        g.transform.GetComponent <ChallengesButton>().gameIndex      = item["customGameID"].Int32Value;
        //Debug.Log("custom game id (challenge): " + g.transform.GetComponent<ChallengesButton>().gameIndex);
        QuickSwapToNew();

        foreach (CustomStage c in Flow.customStages)
        {
            if (c.id == cs.id || (Flow.DecodeList(c.tileset) == Flow.DecodeList(cs.tileset) && c.world == cs.world) && c.name == cs.name)
            {
                g.transform.GetComponent <ChallengesButton>().customLevelsIndex = Flow.customStages.IndexOf(c);
                return;
            }
        }

        Flow.AddCustomStage(cs.tileset, cs.world, cs.numberOfMines, cs.name, cs.id, cs.isNew, cs.isChallenge, cs.creatorName);
        g.transform.GetComponent <ChallengesButton>().customLevelsIndex = Flow.customStages.Count - 1;
        customLevelScroll.AddContainer(cs);
        Debug.Log("adicionei o level " + cs.name);
    }