示例#1
0
    // ---------------------------------
    //  Callback
    // ---------------------------------

    void OnCompoudClick(CSUI_CompoundItem ci)
    {
        if (!GameConfig.IsMultiMode)
        {
            int index = m_CompoudItems.FindIndex(item0 => item0 == ci);
            if (index != -1)
            {
                if (!CSUI_MainWndCtrl.IsWorking())
                {
                    return;
                }

                if (m_Factory.CompoudItemsCount <= index)
                {
                    return;
                }

                Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>();
                if (pkg == null)
                {
                    Debug.LogError("CSUI_Factory.OnCompoundClick: pkg is null!");
                    return;
                }

                CompoudItem ci_data = null;
                ItemProto   item_data;
                if (!m_Factory.GetTakeAwayCompoundItem(index, out ci_data))
                {
                    if (ci_data != null)
                    {
                        item_data = ItemProto.GetItemData(ci_data.itemID);
                        CSUI_MainWndCtrl.ShowStatusBar(CSUtils.GetNoFormatString(UIMsgBoxInfo.mIsCompounding.GetString(), item_data.GetName()), Color.red);
                    }
                    return;
                }

                item_data = ItemProto.GetItemData(ci_data.itemID);

                int pacakgeEmptyCount = pkg.package.GetSlotList(ci_data.itemID).vacancyCount;
                if (!pkg.package.CanAdd(m_Factory.Data.m_CompoudItems[index].itemID, ci.Count))
                {
                    // Status bar
                    //lz-2016.07.16 背包空间不足这条提示是基地复制器和玩家复制器通用的,在基地用的时候,基地的提示只能显示一行,不能换行
                    string tip = PELocalization.GetString(8000050).Replace("\\n", " ");
                    CSUI_MainWndCtrl.ShowStatusBar(tip, Color.red);
                    if (item_data.maxStackNum > 1 || pacakgeEmptyCount == 0)
                    {
                        return;
                    }
                }

                int originalCount = ci_data.itemCnt;
                int addCount      = originalCount;
                if (item_data.maxStackNum > 1)
                {
                    pkg.Add(ci_data.itemID, ci_data.itemCnt);
                }
                else
                {
                    if (originalCount > pacakgeEmptyCount)
                    {
                        addCount = pacakgeEmptyCount;
                    }
                    pkg.Add(ci_data.itemID, addCount);
                }

                ci_data.itemCnt = originalCount - addCount;
                if (ci_data.itemCnt == 0)
                {
                    m_Factory.TakeAwayCompoudItem(index);
                    CSUI_MainWndCtrl.ShowStatusBar(CSUtils.GetNoFormatString(UIMsgBoxInfo.mTakeAwayCompoundItem.GetString(), item_data.GetName()));
                }
            }
        }
        else
        {
            int index = m_CompoudItems.FindIndex(item0 => item0 == ci);
            if (index != -1)
            {
                if (m_Factory.CompoudItemsCount <= index ||
                    m_Factory.Data.m_CompoudItems[index] == null ||
                    m_Factory.Data.m_CompoudItems[index].curTime < m_Factory.Data.m_CompoudItems[index].time)
                {
                    return;
                }
                m_Factory._ColonyObj._Network.FCT_Fetch(index);
            }
        }
    }