| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | using ET;using FairyGUI;using System;using System.Collections;using System.Collections.Generic;using UI.CommonGame;using UnityEngine;namespace GFGGame{    public class ItemUtil    {        /// <param name="showTips">是否弹购买成功飘字,默认是</param>        /// <param name="openSource">是否打开来源界面。默认否</param>        /// <param name="showTxtBuyTips">是否显示购买提示</param>        public static void ExchangeItemById(int itemId, long num, bool showTips = true, Action onSuccess = null, bool openSource = false, int maxCount = 9990, bool showTxtBuyTips = false, string prefix = "")        {            if (itemId == ConstItemID.GOLD)            {                AddGold(num, onSuccess);            }            else if (itemId == ConstItemID.POWER)            {                AddPower();            }            else            {                BuyItemConteoller.Show(itemId, num, ConstBuyType.TYPE_ITEM, 0, onSuccess, showTips, openSource, maxCount);                BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;            }        }        public static void AddPower(string prefix = "", Action onSuccess = null)        {            int maxLimit = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.POWER).maxLimit;            int lastBuyCount = maxLimit - ItemDataManager.GetItemExchangeTimes(ConstItemID.POWER);            string showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买{0}/{1}次", lastBuyCount, maxLimit);            BuyConfirmController.Show(ConstItemID.POWER, 1, () =>            {                if (onSuccess != null)                {                    onSuccess();                }            }, showTxt);        }        public static void AddGold(long value = 0, Action onSuccess = null)        {            BuyConfirmController.Show(ConstItemID.GOLD, 1, () =>            {                if (onSuccess != null)                {                    onSuccess();                }            });        }        public static void AddDiamondPurple()        {            ViewManager.Show(ViewName.RECHARGE_STORE_VIEW);        }        //红钻(鲛绡)        public static void AddDiamondRed(int value = 0, Action onSuccess = null)        {            ItemExchangeCfg currencyRatioCfg = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.DIAMOND_RED);// GetCurrencyRatioCfgById(ConstItemID.DIAMOND_RED);            BuyItemConteoller.Show(currencyRatioCfg.id, value > 0 ? value : 1, ConstBuyType.TYPE_ITEM, 0, onSuccess, true, true);            BuyItemConteoller.showTxtBuyTips = true;        }        public static string GetItemName(int itemId)        {            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            return itemCfg.name;        }        public static string GetSuitName(int suitId)        {            SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);            return suitCfg.name;        }        public static int GetItemRarity(int itemId)        {            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            return itemCfg.rarity;        }        public static List<ItemData> CreateItemDataList(List<ItemInfoProto> items)        {            List<ItemData> itemList = new List<ItemData>();            for (int i = 0; i < items.Count; i++)            {                ItemData itemData = createItemData(items[i].ConfigId, items[i].Count);                itemList.Add(itemData);            }            return itemList;        }        public static List<ItemData> CreateItemDataList(int[][] bonus, bool isOnceBonus = false)        {            List<ItemData> itemList = new List<ItemData>();            foreach (int[] item in bonus)            {                ItemData itemData = createItemData(item);                itemList.Add(itemData);                itemData.isOnceBonus = isOnceBonus;            }            return itemList;        }        public static List<ItemData> CreateItemDataList(int[][] bonus, int num)        {            List<ItemData> itemList = new List<ItemData>();            foreach (int[] item in bonus)            {                int count = 0;                if (item.Length > 1)                {                    count = item[1];                }                else                {                    count = 1;                }                ItemData itemData = createItemData(item[0], count * num);                itemList.Add(itemData);            }            return itemList;        }        public static List<ItemData> CreateItemDataList(int itemId, long count)        {            List<ItemData> itemList = new List<ItemData>();            ItemData itemData = createItemData(itemId, count);            itemList.Add(itemData);            return itemList;        }        public static ItemData createItemData(int[] bonus)        {            int itemID = bonus[0];            int itemNum = 1;            if (bonus.Length > 1)            {                itemNum = bonus[1];            }            return createItemData(itemID, itemNum);        }        public static ItemData createItemData(int itemId, long count)        {            ItemData itemData = ItemDataPool.GetItemData(itemId);            itemData.num = count;            return itemData;        }        public static Boolean CheckItemEnough(int itemId, int num)        {            long hasNum = ItemDataManager.GetItemNum(itemId);            return hasNum >= num;        }        public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)        {            DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);            if (needItemId > 0)            {                int subType = ItemUtilCS.GetItemSubType(needItemId);                if (subType == cfg1.type)                {                    return true;                }                else if (cfg1.subMenusArr.Length > 0)                {                    foreach (int id2 in cfg1.subMenusArr)                    {                        DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);                        if (cfg2.type == subType)                        {                            return true;                        }                    }                }            }            else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)            {                return true;            }            return false;        }        public static void SortItemIdsByOwned(int[] array)        {            Array.Sort(array, (int a, int b) =>            {                bool ownedA = ItemDataManager.GetItemNum(a) > 0;                bool ownedB = ItemDataManager.GetItemNum(b) > 0;                if (!ownedB && ownedA)                {                    return 1;                }                else if (ownedB && !ownedA)                {                    return -1;                }                return 0;            });        }        public static string GetItemResExt(int itemType, int type, bool isIcon = false)        {            if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING && !isIcon)            {                return "jpg";            }            return "png";        }        public static void SetItemNumAndNeedNum(GObject obj, int itemId, int needNum, bool ChangeColor = false)        {            UI_ComCostCurrencyWithHas com = UI_ComCostCurrencyWithHas.Proxy(obj);            long hasNum = ItemDataManager.GetItemNum(itemId);            string needStrColor = ChangeColor ? "#B99F7B" : "#FDEED4";            string strHasNum = StringUtil.GetColorText(hasNum.ToString(), hasNum < needNum ? "#C5645A" : needStrColor); hasNum.ToString();            // com.m_txtNeed.text = needNum.ToString();            com.m_txtCount.text = string.Format("{0}{1}{2}", strHasNum, StringUtil.GetColorText("/", needStrColor), StringUtil.GetColorText(needNum.ToString(), needStrColor));            ItemCfg cfg1 = ItemCfgArray.Instance.GetCfg(itemId);            com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg1.res);        }        public static void SetItemNeedNum(GObject obj, int itemId, int needNum)        {            UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(obj);            long hasNum = ItemDataManager.GetItemNum(itemId);            string strNeedNum = StringUtil.GetColorText(needNum.ToString(), hasNum < needNum ? "#D0A09B" : "#8E7C6B"); needNum.ToString();            com.m_txtNeed.text = strNeedNum;            ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemId);            com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);            UI_ComCostCurrency.ProxyEnd();        }    }}
 |