Beispiel #1
0
    public void InitHeroSlotUI()
    {
        GameObject prefab = Resources.Load(HERO_TIEM_PATH) as GameObject;
        GameObject obj    = NGUITools.AddChild(this.gameObject, prefab);

        obj.transform.parent = _heroPanel.dragDropRoot.transform;

        obj.transform.Find("Hero_Head_Sprite").gameObject.SetActive(true);
        obj.transform.Find("Hero_Body_Sprite").gameObject.SetActive(false);

        dragItemUI = obj.GetComponent <UIHeroDragItem>();
        dragItemUI.InitForSlot();
        dragItemUI.attachSlotUI = this;

        UIHeroHeadItem slotItem = obj.GetComponent <UIHeroHeadItem>();

        SlgPB.Hero hero = InstancePlayer.instance.model_User.model_heroGroup.GetHero(model_UnitGroup.heroId);
        slotItem.UpdateUI(hero);

        UIHeroDragItem dragItem = obj.GetComponent <UIHeroDragItem>();

        dragItem.attachSlotUI  = this;
        dragItem.heroPanel     = _heroPanel;
        dragItem.slotUIManager = _heroPanel._battleFormationPanel.slotUIManager;
    }
Beispiel #2
0
    public void UpdateScrollView()
    {
        List <UIHeroCategory.Hero> herosCategory = _formationHeroCategory.GetSortHero();

        if (!isInitScrllView)
        {
            int i = 0;
            isInitScrllView = true;

            foreach (UIHeroCategory.Hero heroCategory in herosCategory)
            {
                GameObject prefab = Resources.Load(HERO_ITEM_PATH) as GameObject;
                GameObject obj    = NGUITools.AddChild(_grid.gameObject, prefab);
                _grid.AddChild(obj.transform);

                obj.name = UIHelper.GetItemSuffix(++i);

                UIHeroBodyItem heroBodyItem = obj.GetComponent <UIHeroBodyItem> ();
                heroBodyItem.UpdateUI(heroCategory);

                UIHeroHeadItem heroHeadItem = obj.GetComponent <UIHeroHeadItem> ();
                heroHeadItem.UpdateUI(heroCategory.pb_Hero);

                UIHeroDragItem heroDragItem = obj.GetComponent <UIHeroDragItem> ();
                heroDragItem.heroPanel     = this;
                heroDragItem.slotUIManager = _battleFormationPanel.slotUIManager;

                obj.transform.Find("Hero_Head_Sprite").gameObject.SetActive(false);
                obj.transform.Find("Hero_Body_Sprite").gameObject.SetActive(true);
            }

            // scrollView cell 排序
            _grid.animateSmoothly = false;
            _grid.repositionNow   = true;

            // 小于单行最多显示 停止滑动
            if (herosCategory.Count < BattleFormationPanel.UNIT_SHOW_MAX)
            {
                _scrollView.enabled = false;
            }
            else
            {
                _scrollView.enabled = true;
            }
        }
        else
        {
            int id = 0;
            foreach (UIHeroCategory.Hero heroCategory in herosCategory)
            {
                string     cellPath = UIHelper.GetItemSuffix(++id);
                GameObject cell     = _grid.transform.Find(cellPath).gameObject;

                UIHeroBodyItem heroBodyItem = cell.GetComponent <UIHeroBodyItem> ();
                heroBodyItem.UpdateUI(heroCategory);
            }
        }
    }
    public void ResetTeamSlotItemUI()
    {
        UIHeroHeadItem headItemUI = this.GetComponent <UIHeroHeadItem> ();

        if (headItemUI != null)
        {
            headItemUI.ResetDepth();
        }

        cloneDragItem = null;
    }
Beispiel #4
0
    // 点击进入hero 详情页面
    public void HeroDetialPanelCB()
    {
        UIHeroDragItem dragUI = GetComponent <UIHeroDragItem> ();

        if (dragUI.state == UIHeroDragItem.STATE.SCROLLVIEW)
        {
            HeroDataManager          dataHeroManager = new HeroDataManager();
            DataHero                 dataHero        = DataManager.instance.dataHeroGroup.GetHeroPrimitive(heroId);
            HeroDataManager.HeroData uiHeroData      = dataHeroManager.InitHeroData(dataHero);

            UIController.instance.CreatePanel(UICommon.UI_PANEL_HEROUPLEVEL, uiHeroData);
        }
    }
 public void UpdateDraggingItemVisible()
 {
     // 从scrollView 拖拽
     if (cloneObject != null)
     {
         cloneDragItem = cloneObject.GetComponent <UIHeroDragItem> ();
         if (cloneDragItem != null)
         {
             cloneDragItem.item_body.SetActive(false);
             cloneDragItem.item_head.SetActive(true);
             cloneDragItem.GetComponent <UIHeroHeadItem>().IncreaseDepth();
         }
     }
 }
    // 设置 hero 或 Unit 上阵 Item 是否可以拖动
    public void SetHeroOrUnitDragable(bool isHero)
    {
        for (int i = 0; i < TEAM_COUNT; ++i)
        {
            for (int j = 0; j < POSITION_COUNT; ++j)
            {
                FormationSlotUI     unitSlotUI = _unitSlotMap [i] [j];
                FormationDragItemUI unitDragUI = unitSlotUI.dragItemUI;
                if (unitDragUI != null)
                {
                    unitDragUI.GetComponent <BoxCollider> ().enabled = !isHero;
                }

                UIHeroSlot     heroSlotUI = _heroSlotMap [i] [j];
                UIHeroDragItem heroDragUI = heroSlotUI.dragItemUI;
                if (heroDragUI != null)
                {
                    heroDragUI.GetComponent <BoxCollider> ().enabled = isHero;
                }
            }
        }
    }
    protected override void OnDragDropRelease(GameObject surface)
    {
        SetBoxColliderEnabled();
        ResetTeamSlotItemUI();

        if (surface != null)
        {
            switch (state)
            {
            case STATE.SCROLLVIEW:
            {
                // scrollView 移动空slot
                UIHeroSlot surfaceSlotUI = surface.GetComponent <UIHeroSlot>();
                if (surfaceSlotUI != null && !surfaceSlotUI.model_UnitGroup.HasHero())
                {
                    Model_UnitGroup model_UnitGroup = surfaceSlotUI.model_UnitGroup;

                    //上阵
                    Model_Formation.RESULT result = EnterBattleHero(model_UnitGroup);

                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        this.transform.position = surface.transform.position;
                        attachSlotUI            = surfaceSlotUI;
                        state = STATE.SLOT;
                        surfaceSlotUI.dragItemUI = this;

                        // 更新上阵Unit显示数量
                        _slotUIManager.UpdateBattleUnitNum(model_UnitGroup);

                        // 更新scrollView列表
                        UpdateHeroScrollView();

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        base.OnDragDropRelease(surface);
                        UpdateErrorPopupMsg(result);
                    }
                    return;
                }

//					// scrollView 移动到包含 item slot
                UIHeroDragItem dragItemUI = surface.GetComponent <UIHeroDragItem>();
                if (dragItemUI != null && dragItemUI.attachSlotUI != null)
                {
                    UIHeroSlot      slotUI          = dragItemUI.attachSlotUI;
                    Model_UnitGroup model_UnitGroup = slotUI.model_UnitGroup;

                    Model_Formation.RESULT result = EnterBattleHero(model_UnitGroup);
                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        dragItemUI.GetComponent <UIHeroHeadItem>().UpdateUI(model_UnitGroup.heroId);

                        // 更新上阵Unit显示数量
                        _slotUIManager.UpdateBattleUnitNum(model_UnitGroup);

                        // 更新scrollView列表
                        UpdateHeroScrollView();

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        UpdateErrorPopupMsg(result);
                    }

                    // 删除当前拖动 GameObject
                    base.OnDragDropRelease(surface);
                    return;
                }
            }
            break;

            case STATE.SLOT:

                /*
                 * 1 移动另一个slot
                 *   (1) slot 区域没有item
                 *   (2) slot 区域有item
                 * 2 移动到scrollView
                 * 3 移动到空白区
                 */

                // 1 移动另一个slot
                // (1)slot区域没有item
            {
                UIHeroSlot surfaceSlotUI = surface.GetComponent <UIHeroSlot>();
                if (surfaceSlotUI != null && !surfaceSlotUI.model_UnitGroup.HasHero())
                {
                    Model_Formation.RESULT result = ExchangeBattleHero(surfaceSlotUI.model_UnitGroup);
                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        // 更新上阵Unit显示数量 交换之前更新
                        _slotUIManager.UpdateBattleUnitNum(surfaceSlotUI.model_UnitGroup);
                        _slotUIManager.UpdateBattleUnitNum(attachSlotUI.model_UnitGroup);

                        this.transform.position = surfaceSlotUI.transform.position;

                        this.attachSlotUI.dragItemUI = null;
                        this.attachSlotUI            = surfaceSlotUI;
                        this.attachSlotUI.dragItemUI = this;

                        this.GetComponent <UIHeroHeadItem>().UpdateUI(surfaceSlotUI.model_UnitGroup.heroId);

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        base.OnDragDropRelease(surface);
                    }

                    UpdateHeroScrollView();
                    return;
                }
            }

                // (2) slot区域有item
                {
                    UIHeroDragItem surfaceDragItemUI = surface.GetComponent <UIHeroDragItem>();

                    if (surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI != null)
                    {
                        UIHeroSlot surfaceSlotUI = surfaceDragItemUI.attachSlotUI;

                        Model_Formation.RESULT result = ExchangeBattleHero(surfaceSlotUI.model_UnitGroup);
                        if (result == Model_Formation.RESULT.SUCCESS)
                        {
                            // 更显UI显示数据
                            UIHeroSlot     sourceSlotUI = this.attachSlotUI;
                            UIHeroDragItem sourceDragUI = this;

                            UIHeroSlot     targetSlotUI = surfaceDragItemUI.attachSlotUI;
                            UIHeroDragItem targetDragUI = surfaceDragItemUI;

                            UIHeroHeadItem sourceSlotItemUI = sourceDragUI.gameObject.GetComponent <UIHeroHeadItem>();
                            UIHeroHeadItem targetSlotItemUI = targetDragUI.gameObject.GetComponent <UIHeroHeadItem>();

                            Model_UnitGroup source = attachSlotUI.model_UnitGroup;
                            Model_UnitGroup target = targetSlotUI.model_UnitGroup;

                            sourceSlotItemUI.UpdateUI(source.heroId);
                            targetSlotItemUI.UpdateUI(target.heroId);

                            this.transform.position = sourceSlotUI.transform.position;

                            // 更新上阵Unit显示数量
                            _slotUIManager.UpdateBattleUnitNum(source);
                            _slotUIManager.UpdateBattleUnitNum(target);

                            // 更新Unit列表
                            _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                        }
                        else
                        {
                            base.OnDragDropRelease(surface);
                        }

                        UpdateHeroScrollView();

                        return;
                    }
                }

                // 2 移动到scrollView 下阵
                {
                    UIHeroDragItem surfaceDragItemUI   = surface.GetComponent <UIHeroDragItem>();
                    bool           isScrllViewCollider = surface.gameObject.name.Equals("scrollView_bg_hero");

                    if ((surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI == null) ||
                        isScrllViewCollider)
                    {
                        ExitBattleHero();

                        attachSlotUI.dragItemUI = null;

                        UpdateHeroScrollView();

                        _slotUIManager.UpdateBattleUnitNum(attachSlotUI.model_UnitGroup);

                        DestroyImmediate(this.gameObject);
                        return;
                    }
                }

                // 拖动到其他区域
                if (attachSlotUI != null)
                {
                    this.transform.position = attachSlotUI.transform.position;
                    return;
                }

                break;
            }
        }
        base.OnDragDropRelease(surface);
    }