Beispiel #1
0
 /// <summary>
 /// ワールド内で何番目のバトルステージかを取得
 /// </summary>
 private int GetBattleStageIndex(WorldData worldData, Master.SingleStageData battleStageData)
 {
     for (int i = 0, j = 0; i < worldData.stageMasterData.Length; i++)
     {
         if (worldData.stageMasterData[i].type == (int)Master.SingleStageData.StageType.Battle)
         {
             if (worldData.stageMasterData[i] == battleStageData)
             {
                 return(j);
             }
             j++;
         }
     }
     return(-1);
 }
    /// <summary>
    /// 内容構築
    /// </summary>
    public void Set(
        Master.SingleStageData master,
        SinglePlayApi.TSingleStage server,
        int battleStageIndex,
        bool isLastStage,
        Action <SingleStagePanel> onClick)
    {
        this.master  = master;
        this.server  = server;
        this.onClick = onClick;

        //解放済みかどうかでボタンとして押せるか押せないか切り替え
        this.button.interactable = this.isOpen;

        //状態による表示切替
        this.battleBase.gameObject.SetActive(this.isBattle);
        this.storyBase.gameObject.SetActive(this.isStory);
        this.lockImage.enabled = !this.isOpen;
        this.fishImage.enabled = this.isOpen;
        this.starMarkGroup.SetActive(this.isOpen);

        //クリアランクでの星数表示
        if (this.starMarkGroup.activeInHierarchy)
        {
            for (int i = 0; i < this.starMarks.Length; i++)
            {
                this.starMarks[i].enabled = i < (int)this.server.clearRank - 2;
            }
        }

        //ロックの場合グレースケール表示
        foreach (var graphic in this.grayScaleTargets)
        {
            graphic.material = this.isOpen ? null : SharedUI.Instance.grayScaleMaterial;
        }

        //最終ステージ以外はラインを表示
        this.line.SetActive(!isLastStage);

        //バトルステージ番号
        this.stageNoText.text = (battleStageIndex < 0) ? null : (battleStageIndex + 1).ToString();

        if (this.isBattle && this.isOpen)
        {
            //バトルステージの魚アイコン切り替え
            this.fishImage.sprite = AssetManager.FindHandle <Sprite>(SharkDefine.GetSingleStageIconSpritePath(this.master.key)).asset as Sprite;
        }
    }
    /// <summary>
    /// 開く
    /// </summary>
    public static void Open(
        SingleStageChallengeConfirmDialogContent prefab,
        Master.SingleStageData stageData,
        Rank rank,
        Action <uint> onStageStart)
    {
        bool isCleared = rank > Rank.None;

        //報酬リスト
        List <RewardData> rewards = new List <RewardData>();

        //このステージで入手可能な報酬一覧
        var lotDatas = Masters.SingleStageRewardDB
                       .GetList()
                       .Where(x => x.groupId == stageData.rewardGroupId)
                       .SelectMany(x1 => Masters.SingleStageRewardLotDB.GetList().FindAll(x2 => x2.lotGroupId == x1.lotGroupId))
                       .ToArray();

        foreach (var data in lotDatas)
        {
            if (!rewards.Exists(x => x.itemType == data.itemType && x.itemId == data.itemId))
            {
                rewards.Add(new RewardData {
                    itemType = data.itemType, itemId = data.itemId, itemNum = data.itemNum
                });
            }
        }

        //初回報酬
        var firstReward = Masters.SingleStageFirstRewardDB
                          .GetList()
                          .Where(x => x.groupId == stageData.rewardFirstGroupId)
                          .Select(x => new RewardData {
            itemType = x.itemType, itemId = x.itemId, itemNum = x.amount, isFirstReward = true
        });

        if (isCleared)
        {
            //初回報酬入手済みなら末尾に追加
            rewards.AddRange(firstReward);
        }
        else
        {
            //初回報酬未入手なら先頭に追加
            rewards.InsertRange(0, firstReward);
        }

        //ローダー準備
        var loader = new AssetListLoader(rewards
                                         .Select(x => CommonIconUtility.GetItemInfo(x.itemType, x.itemId))
                                         .Where(x => !x.IsCommonSprite())
                                         .Select(x => new AssetLoader <Sprite>(x.GetSpritePath())));

        //ロード中はタッチブロック
        SharedUI.Instance.DisableTouch();

        //ロード
        loader.Load(() =>
        {
            //タッチブロック解除
            SharedUI.Instance.EnableTouch();

            //ダイアログ開く
            var dialog  = SharedUI.Instance.ShowSimpleDialog();
            var content = dialog.AddContent(prefab);
            content.Set(dialog, stageData, rank, rewards, loader, onStageStart);
        });
    }
    /// <summary>
    /// 内容構築
    /// </summary>
    private void Set(
        SimpleDialog dialog,
        Master.SingleStageData stageData,
        Rank rank,
        List <RewardData> rewards,
        AssetListLoader loader,
        Action <uint> onStageStart)
    {
        this.dialog       = dialog;
        this.stageData    = stageData;
        this.isCleared    = rank > Rank.None;
        this.rewards      = rewards;
        this.loader       = loader;
        this.onStageStart = onStageStart;
        var worldData = Masters.SingleWorldDB.FindById(this.stageData.worldId);

        //ワールド名、ステージ名
        this.worldNameText.text = worldData.name;
        this.stageNameText.text = this.stageData.name;
        LayoutRebuilder.ForceRebuildLayoutImmediate(this.nameArea);

        //星マーク
        for (int i = 0; i < this.star.Length; i++)
        {
            this.star[i].enabled = ((int)rank - 2) > i;
        }

        //報酬データが8個以下なら
        if (this.rewards.Count < 9)
        {
            //非スクロールエリアに報酬アイコンを生成する
            this.nonScrollRewardArea.gameObject.SetActive(true);
            this.rewardScrollView.gameObject.SetActive(false);

            for (int i = 0; i < this.rewards.Count; i++)
            {
                var icon = Instantiate(this.rewardIconPrefab, this.nonScrollRewardArea.transform, false);
                this.OnUpdateRewardIconView(icon.gameObject, i);
            }
        }
        //報酬データが9個以上なら
        else
        {
            //スクロールエリアに報酬アイコンを生成する
            this.nonScrollRewardArea.gameObject.SetActive(false);
            this.rewardScrollView.gameObject.SetActive(true);
            this.rewardScrollView.Initialize(this.rewardIconPrefab.gameObject, this.rewards.Count, this.OnUpdateRewardIconView);
        }

        //必要コイン数
        this.needCoinNumText.text = this.stageData.needCoin.ToString();
        LayoutRebuilder.ForceRebuildLayoutImmediate(this.coinArea);

        //YesNoボタン追加:挑戦する、キャンセル
        var btnGroup        = this.dialog.AddButton(1);
        var challengeButton = btnGroup.buttons[0];

        challengeButton.text.text    = Masters.LocalizeTextDB.Get("Challenge");
        challengeButton.image.sprite = SharedUI.Instance.commonAtlas.GetSprite(SharkDefine.NO_BTN_SPRITE_NAME);
        challengeButton.onClick      = this.OnClickChallengeButton;

        //必要コイン数に満たない場合
        var userData = UserData.Get();

        if (userData == null || userData.coin < this.stageData.needCoin)
        {
            //グレースケールにして挑戦するボタンを押せなくする
            challengeButton.button.interactable = false;
            challengeButton.image.material      =
                challengeButton.text.material   = SharedUI.Instance.grayScaleMaterial;
        }

        //Closeボタン追加
        this.dialog.closeButtonEnabled = true;
    }