//展示界面
        public void ShowView(UIViewName viewName, params object[] args)
        {
            //获取界面配置
            UIViewConfig config = GetConfig(viewName);

            if (config == null)
            {
                return;
            }
            ViewBaseView view = null;

            if (config.unique)
            {
                //判断是否打开了
                for (int i = 0; i < viewList.Count; ++i)
                {
                    if (viewList[i].config.viewName == viewName)
                    {
                        view = viewList[i];
                        break;
                    }
                }
                //判断是否已被打开,没有打开个新的
                if (view != null)
                {
                    if (view.layerController == null)
                    {
                        UtilityLog.LogError(string.Format("Show view error: {0}, not layer", viewName));
                        return;
                    }
                    //设置参数,重新放入窗口层级控制器
                    // view.SetArguments(args);
                    view.layerController.Push(view);
                }
                else
                {
                    ShowViewFromCacheOrCreateNew(config, args);
                }
            }
            else
            {
                ShowViewFromCacheOrCreateNew(config, args);
            }
            //刷新显示、隐藏状态
            UpdateViewHideState();
        }
        //打开一个新的
        private ViewBaseView ShowNewView(UIViewConfig config)
        {
            if (!UIControllerViews.ContainsKey(config.viewLayer))
            {
                UtilityLog.LogError("Show new view failed. Layer error.");
                return(null);
            }
            //加载
            ViewBaseView view = CreateUIView(config);

            if (view)
            {
                //创建完毕,初始化
                view.Init();
                view.transform.SetParent(UIControllerViews[config.viewLayer].transform, false);
                view.GetComponent <RectTransform>().Normalize();
            }
            return(view);
        }
        //先尝试从缓存中打开,如果失败则打开一个新的
        private void ShowViewFromCacheOrCreateNew(UIViewConfig config, params object[] args)
        {
            //先尝试从缓存区中读取
            ViewBaseView view = GetViewFromCache(config);

            //缓存区内没有,打开新的
            if (view == null)
            {
                view = ShowNewView(config);
            }
            if (view != null)
            {
                PushViewToLayer(view, args);
            }
            else
            {
                UtilityLog.LogError(string.Format("Show view failed -> {0}", config.viewName));
            }
        }
        //读入界面
        private ViewBaseView CreateUIView(UIViewConfig config)
        {
            GameObject obj = null;

            obj = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(string.Format("Assets/Resources/Prefabs/UIView/{0}.prefab", config.assetName));
            if (obj != null)
            {
                obj = Instantiate(obj);
            }

            if (obj)
            {
                var viewBase = obj.GetComponent <ViewBaseView>();
                return(viewBase);
            }
            else
            {
                UtilityLog.LogError(string.Format("Load view error: no view : {0}", config.assetName));
                return(null);
            }
        }
        //从池中获取界面
        private ViewBaseView GetViewFromCache(UIViewConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            ViewBaseView        view  = null;
            List <ViewBaseView> cache = null;

            switch (config.cacheScheme)
            {
            case UIViewCacheScheme.Cache:
                cache = screenUICache;
                break;

            case UIViewCacheScheme.TempCache:
                cache = screenUITempCache;
                break;

            default:
                break;
            }
            if (cache != null)
            {
                for (int i = 0; i < cache.Count; ++i)
                {
                    if (cache[i].config.viewName == config.viewName)
                    {
                        view = cache[i];
                        //从缓冲区中移除
                        cache.RemoveAt(i);
                        break;
                    }
                }
            }
            return(view);
        }
Exemple #6
0
        public override void ExceHandleNotification(INotification notification)
        {
            //判断是否是转发内容
            if (notification.Name.Contains("=>"))
            {
                SendNotification(StringUtil.GeNotificationNameForNN(notification.Name), notification.Body, notification.Type);
                return;
            }

            // 处理公共请求
            HandleNotificationCommon(notification);


            ViewChooseStage     viewChooseStage   = null;
            List <CardDeckList> cardDeckListLoad  = new List <CardDeckList>();
            CardMoveAnimation   cardMoveAnimation = null;
            //回调函数
            UnityAction callBack = () =>
            {
                exceINotification = false;
                SendNotification(UIViewSystemEvent.UI_ANIMATION_SYS, null, UIViewSystemEvent.UI_ANIMATION_SYS_START);
            };
            bool callBackDelay = false;

            switch (notification.Name)
            {
            case UIViewSystemEvent.UI_ANIMATION_SYS:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_ANIMATION_SYS_START:
                    DoExceHandleNotification();
                    break;
                }
                break;

            case UIViewSystemEvent.UI_CARD_ENTRY_SYS:
                switch (notification.Type)
                {
                //卡牌的归属地发生了变化
                case UIViewSystemEvent.UI_CARD_ENTRY_SYS_CHANGE_GAME_CONTAINER_TYPE:
                    CardEntry cardEntryMove = notification.Body as CardEntry;
                    if (cardEntryMove.gameContainerType == "CardHand")
                    {
                        SendNotification(HandSystemEvent.HAND_CHANGE, notification.Body, StringUtil.GetNTByNotificationTypeAndPlayerCode(HandSystemEvent.HAND_CHANGE_DRAW_ONE_CARD, cardEntryMove.controllerPlayerItem.playerCode));
                        return;
                    }
                    if (cardEntryMove.lastGameContainerType == "CardHand")
                    {
                        SendNotification(HandSystemEvent.HAND_CHANGE, cardEntryMove, StringUtil.GetNTByNotificationTypeAndPlayerCode(HandSystemEvent.HAND_CHANGE_REMOVE_ONE_CARD, cardEntryMove.controllerPlayerItem.playerCode));
                    }
                    break;

                //卡牌在显示页面需要被隐藏
                case UIViewSystemEvent.UI_CARD_ENTRY_SYS_CARD_NEED_HIDE_IN_VIEW:
                    CardEntry cardEntryNeedHide = notification.Body as CardEntry;
                    if (cardEntryNeedHide.gameContainerType == "CardHand")
                    {
                        SendNotification(HandSystemEvent.HAND_CHANGE, notification.Body, StringUtil.GetNTByNotificationTypeAndPlayerCode(UIViewSystemEvent.UI_CARD_ENTRY_SYS_CARD_NEED_HIDE_IN_VIEW, cardEntryNeedHide.controllerPlayerItem.playerCode));
                    }
                    break;
                }
                break;

            case UIViewSystemEvent.UI_VIEW_CURRENT:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_VIEW_CURRENT_OPEN_ONE_VIEW:
                    //是否需要打开遮罩层
                    if (parameterMap.ContainsKey("OpenMaskLayer"))
                    {
                        string OpenMaskLayer = parameterMap["OpenMaskLayer"];
                        if ("Y" == OpenMaskLayer)
                        {
                            UIViewName uiMaskLayeView = UIViewConfig.getUIViewNameByNameStr("UIMaskLayeView");
                            UIControllerLIst.ShowView(uiMaskLayeView);
                        }
                    }
                    UIViewName viewNameOpen = UIViewConfig.getUIViewNameByNameStr(parameterMap["UIViewName"]);
                    UIControllerLIst.ShowView(viewNameOpen);
                    //初始化页面
                    UIControllerLIst.GetViewByName <ViewBaseView>(viewNameOpen).InitViewForParameter(this, notification.Body, parameterMap);
                    //一些界面打开时需要初始化
                    switch (viewNameOpen)
                    {
                    case UIViewName.CardDeckList:
                        PlayerItem          playerItem    = notification.Body as PlayerItem;
                        List <CardDeckList> cardDeckLists = UIControllerLIst.GetViewListByName <CardDeckList>(UIViewName.CardDeckList);
                        for (int num = 0; num < cardDeckLists.Count; num++)
                        {
                            if (cardDeckLists[num].playerItem == null)
                            {
                                cardDeckLists[num].playerItem = playerItem;
                                //设置位置
                                //0在左,1在右
                                //己方始终显示在左边
                                Vector3 position = new Vector3();
                                if (playerItem.playerCode == playerCode)
                                {
                                    position.x = -600;
                                }
                                else
                                {
                                    position.x = 430;
                                }
                                cardDeckLists[num].transform.localPosition = position;
                            }
                        }
                        break;
                    }
                    break;

                case UIViewSystemEvent.UI_VIEW_CURRENT_CLOSE_ONE_VIEW:
                    UIViewName viewNameClose = UIViewConfig.getUIViewNameByNameStr(notification.Body as string);
                    UIControllerLIst.HideView(viewNameClose);
                    //是否需要关闭遮罩层
                    if (parameterMap.ContainsKey("OpenMaskLayer"))
                    {
                        string OpenMaskLayer = parameterMap["OpenMaskLayer"];
                        if ("N" == OpenMaskLayer)
                        {
                            UIViewName uiMaskLayeView = UIViewConfig.getUIViewNameByNameStr("UIMaskLayeView");
                            UIControllerLIst.HideView(uiMaskLayeView);
                        }
                    }
                    break;
                }
                break;

            case UIViewSystemEvent.UI_CHOOSE_STAGE:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_CHOOSE_STAGE_LOAD_CARD_ENTRY:
                    viewChooseStage = UIControllerLIst.GetViewByName <ViewChooseStage>(UIViewName.ChooseStage);
                    List <CardEntry> shipCardEntryList = (List <CardEntry>)notification.Body;
                    //载入卡牌列表
                    viewChooseStage.LoadCardEntryList(shipCardEntryList);
                    //载入完成后绑定事件
                    foreach (CardIntactView cardIntactView in viewChooseStage.cardIntactViews)
                    {
                        //如果是自己的命令则绑定上点击事件
                        if (playerCode == playerCodeNotification)
                        {
                            cardIntactView.OnClick = () =>
                            {
                                SendNotification(UIViewSystemEvent.UI_CHOOSE_STAGE, cardIntactView.card, UIViewSystemEvent.UI_CHOOSE_STAGE_ONE_CARD);
                            };
                        }
                        else
                        {
                            //设置为空
                            cardIntactView.OnClick = () =>
                            {
                            };
                        }
                    }
                    break;

                case UIViewSystemEvent.UI_CHOOSE_STAGE_ONE_SHIP_CARD_ANIMATION:
                    viewChooseStage = UIControllerLIst.GetViewByName <ViewChooseStage>(UIViewName.ChooseStage);
                    CardEntry      choosedShipCard      = notification.Body as CardEntry;
                    CardIntactView targetCardIntactView = null;
                    //找到这张组件
                    foreach (CardIntactView cardIntactView in viewChooseStage.cardIntactViews)
                    {
                        if (cardIntactView.card.uuid == choosedShipCard.uuid)
                        {
                            cardDeckListLoad  = UIControllerLIst.GetViewListByName <CardDeckList>(UIViewName.CardDeckList);
                            cardMoveAnimation = UIControllerLIst.GetViewByName <CardMoveAnimation>(UIViewName.CardMoveAnimation);
                            //执行动画,获得卡牌的位置,list的位置
                            for (int num = 0; num < cardDeckListLoad.Count; num++)
                            {
                                //移动目标
                                if (cardDeckListLoad[num].playerItem.playerCode == playerCodeNotification)
                                {
                                    callBackDelay = true;
                                    cardMoveAnimation.MoveShipCardAnimation(cardIntactView, cardDeckListLoad[num], callBack);
                                }
                            }
                        }
                    }


                    break;
                }
                break;

            case UIViewSystemEvent.UI_CHOOSE_MAKE_STAGE:
                ViewChooseMakeStage viewChooseMakeStage = UIControllerLIst.GetViewByName <ViewChooseMakeStage>(UIViewName.ViewChooseMakeStage);
                switch (notification.Type)
                {
                //获取下一组数据
                case UIViewSystemEvent.UI_CHOOSE_MAKE_STAGE_LOAD_NEXT_LIST:
                    List <CardEntry> cardList = notification.Body as List <CardEntry>;
                    viewChooseMakeStage = UIControllerLIst.GetViewByName <ViewChooseMakeStage>(UIViewName.ViewChooseMakeStage);
                    viewChooseMakeStage.LoadNewCardList(cardList);
                    break;

                case UIViewSystemEvent.UI_CHOOSE_MAKE_STAGE_ONE_CARD_SUCCESS:

                    CardEntry card = notification.Body as CardEntry;
                    viewChooseMakeStage.ChangeOneCradForBuyed(card);
                    break;
                }
                break;

            case UIViewSystemEvent.UI_CARD_DECK_LIST:
                switch (notification.Type)
                {
                //读取牌组
                case UIViewSystemEvent.UI_CARD_DECK_LIST_LOAD:
                    PlayerItem playerItemLoad = notification.Body as PlayerItem;
                    cardDeckListLoad = UIControllerLIst.GetViewListByName <CardDeckList>(UIViewName.CardDeckList);
                    for (int num = 0; num < cardDeckListLoad.Count; num++)
                    {
                        if (cardDeckListLoad[num].playerItem.playerCode == playerItemLoad.playerCode)
                        {
                            cardDeckListLoad[num].LoadPlayerInfo();
                            foreach (CardHeadView cardHeadView in cardDeckListLoad[num].cardHeadViews)
                            {
                                cardHeadView.OnPointerEnter = () =>
                                {
                                    SendNotification(
                                        UIViewSystemEvent.UI_VIEW_CURRENT,
                                        cardHeadView,
                                        StringUtil.GetNTByNotificationTypeAndUIViewNameAndOtherType(
                                            UIViewSystemEvent.UI_VIEW_CURRENT_OPEN_ONE_VIEW,
                                            UIViewConfig.getNameStrByUIViewName(UIViewName.OneCardAllInfo),
                                            "CardHeadView"
                                            )
                                        );
                                };
                                cardHeadView.OnPointerExit = () =>
                                {
                                    SendNotification(
                                        UIViewSystemEvent.UI_VIEW_CURRENT,
                                        UIViewConfig.getNameStrByUIViewName(UIViewName.OneCardAllInfo),
                                        UIViewSystemEvent.UI_VIEW_CURRENT_CLOSE_ONE_VIEW);
                                };
                            }
                        }
                    }
                    break;
                }
                break;

            //费用控制组件
            case UIViewSystemEvent.UI_MANA_INFA_SYS:
                int          changeNum    = 0;
                ManaInfoView manaInfoView = null;
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_MANA_INFA_SYS_INIT:
                    VariableAttribute manaInitVariableAttribute = notification.Body as VariableAttribute;
                    manaInfoView = UIControllerLIst.GetViewByName <ManaInfoView>(UIViewName.ManaInfoView);
                    manaInfoView.UIManaInfoSysInit(manaInitVariableAttribute, myself, playerCodeNotification);
                    break;

                case UIViewSystemEvent.UI_MANA_INFA_SYS_NUM_CHANGE:
                    VariableAttribute manaChangeVariableAttribute = notification.Body as VariableAttribute;
                    manaInfoView = UIControllerLIst.GetViewByName <ManaInfoView>(UIViewName.ManaInfoView);
                    manaInfoView.ChangeManaUsable(manaChangeVariableAttribute, myself);
                    break;
                }
                break;

            //科技组件显示
            case UIViewSystemEvent.UI_TRAIT_COMBINATION_SYS:
                TraitCombinationView traitCombinationView = null;
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_TRAIT_COMBINATION_SYS_INIT:
                    List <TraitType> traitTypes = notification.Body as List <TraitType>;
                    traitCombinationView = UIControllerLIst.GetViewByName <TraitCombinationView>(UIViewName.TraitCombinationView);
                    traitCombinationView.UITraitCombinationSysInit(traitTypes, myself, playerCodeNotification);
                    break;

                case UIViewSystemEvent.UI_TRAIT_COMBINATION_SYS_ADD:
                    string traitType = notification.Body.ToString();
                    traitCombinationView = UIControllerLIst.GetViewByName <TraitCombinationView>(UIViewName.TraitCombinationView);
                    traitCombinationView.UITraitCombinationSysAdd(traitType, myself);
                    break;
                }
                break;

            //效果展示列控制
            case UIViewSystemEvent.UI_EFFECT_DISPLAY_SYS:
                EffectDisplayView effectDisplayView = null;
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_EFFECT_DISPLAY_SYS_PUT_ONE_EFFECT:
                    effectDisplayView = UIControllerLIst.GetViewByName <EffectDisplayView>(UIViewName.EffectDisplayView);
                    CardEntry effectCardNeedShow = notification.Body as CardEntry;
                    callBackDelay = true;
                    //回调函数
                    callBack = () =>
                    {
                        exceINotification = false;
                        SendNotification(EffectExecutionEvent.EFFECT_EXECUTION_SYS, null, EffectExecutionEvent.EFFECT_EXECUTION_SYS_EFFECT_SHOW_OVER);
                        SendNotification(UIViewSystemEvent.UI_ANIMATION_SYS, null, UIViewSystemEvent.UI_ANIMATION_SYS_START);
                    };
                    effectDisplayView.ShowCradEffectByCardEntryAuto(effectCardNeedShow, callBack);
                    break;

                case UIViewSystemEvent.UI_EFFECT_DISPLAY_SYS_ONE_EFFECT_NEED_CHOOSE_EXE:
                    effectDisplayView = UIControllerLIst.GetViewByName <EffectDisplayView>(UIViewName.EffectDisplayView);
                    CardEntry effectCardNeedChooseExe = notification.Body as CardEntry;
                    SendNotificationAddCardEntry sendNotificationAddCard = (OneUserSelectionItem oneUserSelectionItem) =>
                    {
                        SendNotification(OperateSystemEvent.OPERATE_SYS, oneUserSelectionItem, OperateSystemEvent.OPERATE_SYS_CHOOSE_ONE_USER_SELECTION_ITEM);
                    };
                    effectDisplayView.ShowCradEffectAndUserSelectionListByCardEntry(effectCardNeedChooseExe, sendNotificationAddCard);
                    break;

                case UIViewSystemEvent.UI_EFFECT_DISPLAY_SYS_ONE_EFFECT_NEED_CHOOSE_TARGET:
                    effectDisplayView = UIControllerLIst.GetViewByName <EffectDisplayView>(UIViewName.EffectDisplayView);
                    CardEntry effectCardNeedChooseTarget = notification.Body as CardEntry;
                    effectDisplayView.ShowCradEffectByCardEntry(effectCardNeedChooseTarget);
                    break;

                case UIViewSystemEvent.UI_EFFECT_DISPLAY_SYS_TO_HIDE:
                    effectDisplayView = UIControllerLIst.GetViewByName <EffectDisplayView>(UIViewName.EffectDisplayView);
                    effectDisplayView.cardIntactView.gameObject.SetActive(false);
                    break;
                }
                break;

            //科技组件显示
            case UIViewSystemEvent.UI_PLAYER_SCORE_SHOW_SYS:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_PLAYER_SCORE_SHOW_SYS_CHANGE:
                    ShipComponentView shipScoreComponentView = UIControllerLIst.GetViewByName <ShipComponentView>(UIViewName.ShipComponentView);
                    shipScoreComponentView.ChangeScoreShow(myself, Convert.ToInt32(notification.Body));
                    break;
                }
                break;

            //结束按钮的显示控制
            case UIViewSystemEvent.UI_NEXT_TURN_SHOW_SYS:
                NextTurnButton nextTurnButton = null;
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_NEXT_TURN_SHOW_SYS_SHOW:
                    if (myself)
                    {
                        nextTurnButton = UIControllerLIst.GetViewByName <NextTurnButton>(UIViewName.NextTurnButton);
                        nextTurnButton.ShowButton();
                    }
                    break;
                }
                break;

            //展示卡牌完整信息的控制
            case UIViewSystemEvent.UI_ONE_CARD_ALL_INFO:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_ONE_CARD_ALL_INFO_BUFF_CHANGE:
                    CardEntry      minionCellItem = notification.Body as CardEntry;
                    OneCardAllInfo oneCardAllInfo = UIControllerLIst.GetViewByName <OneCardAllInfo>(UIViewName.OneCardAllInfo);
                    if (oneCardAllInfo != null)
                    {
                        if (oneCardAllInfo.cardEntryShow.uuid == minionCellItem.uuid)
                        {
                            oneCardAllInfo.LoadingAllInfoByMinionCellItem(minionCellItem);
                        }
                    }
                    break;
                }
                break;

            case UIViewSystemEvent.UI_TURN_STAGE_SYS:
                switch (notification.Type)
                {
                case UIViewSystemEvent.UI_TURN_STAGE_SYS_STAGE_CHANGE:
                    //回调函数
                    UnityAction turnStageCallBack = () =>
                    {
                        SendNotification(EffectExecutionEvent.EFFECT_EXECUTION_SYS, null, EffectExecutionEvent.EFFECT_EXECUTION_SYS_EFFECT_SHOW_OVER);
                        SendNotification(UIViewSystemEvent.UI_ANIMATION_SYS, null, UIViewSystemEvent.UI_ANIMATION_SYS_START);
                    };
                    TurnSysProgressBarView turnSysProgressBarView = UIControllerLIst.GetViewByName <TurnSysProgressBarView>(UIViewName.TurnSysProgressBarView);
                    QuestStageCircuitItem  questStageCircuitItem  = notification.Body as QuestStageCircuitItem;
                    turnSysProgressBarView.LoadingAllStageInfoToChange(questStageCircuitItem, playerCode, turnStageCallBack);
                    break;
                }
                break;
            }
            if (callBackDelay == false)
            {
                callBack();
            }
        }