| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 | 
							- using ET;
 
- using FairyGUI;
 
- using System;
 
- using System.Collections;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- 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 (!BuyCurrency(itemId, num, onSuccess))
 
-             {
 
-                 BuyItemConteoller.Show(itemId, num, ConstBuyType.TYPE_ITEM, onSuccess, showTips, openSource, maxCount);
 
-                 BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;
 
-             }
 
-         }
 
-         public static bool BuyCurrency(int itemId, long num, Action onSuccess = null)
 
-         {
 
-             switch (itemId)
 
-             {
 
-                 case ConstItemID.GOLD:
 
-                     AddGold(onSuccess);
 
-                     return true;
 
-                 case ConstItemID.POWER:
 
-                     AddPower();
 
-                     return true;
 
-                 case ConstItemID.DIAMOND_RED:
 
-                     AddDiamondRed(num);
 
-                     return true;
 
-                 case ConstItemID.DIAMOND_PURPLE:
 
-                     ItemUtil.AddDiamondPurple();
 
-                     return true;
 
-             }
 
-             return false;
 
-         }
 
-         public static void AddPower(Action onSuccess = null, int type = 0)
 
-         {
 
-             EnduringGiftBoxController.Show(ConstItemID.POWER, 1, () =>
 
-             {
 
-                 if (onSuccess != null)
 
-                 {
 
-                     onSuccess();
 
-                 }
 
-             }, "", type);
 
-         }
 
-         public static void AddGold(Action onSuccess = null, int type = 0)
 
-         {
 
-             EnduringGiftBoxController.Show(ConstItemID.GOLD, 1, () =>
 
-             {
 
-                 if (onSuccess != null)
 
-                 {
 
-                     onSuccess();
 
-                 }
 
-             }, "", type);
 
-         }
 
-         public static void AddDiamondPurple()
 
-         {
 
-             //ViewManager.Show<RechargeStoreView>();
 
-             ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
 
-             EventAgent.DispatchEvent(ConstMessage.CLOSE_SHOPPING_TIP);
 
-         }
 
-         //红钻(鲛绡)
 
-         public static void AddDiamondRed(long 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, 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, long 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, long countRandomeMin = 0)
 
-         {
 
-             ItemData itemData = ItemDataPool.GetItemData(itemId);
 
-             itemData.num = count;
 
-             itemData.numRandomeMin = countRandomeMin;
 
-             return itemData;
 
-         }
 
-         public static Boolean CheckItemEnough(int itemId, long num, bool showTips = false)
 
-         {
 
-             long hasNum = ItemDataManager.GetItemNum(itemId);
 
-             if (hasNum < num && showTips)
 
-             {
 
-                 ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-                 PromptController.Instance.ShowFloatTextPrompt(string.Format("【{0}】 不足", itemCfg.name));
 
-             }
 
-             return hasNum >= num;
 
-         }
 
-         public static Boolean CheckItemEnough(int[][] items, int count = 1)
 
-         {
 
-             return items.All(item => CheckItemEnough(item[0], item[1] * count));
 
-         }
 
-         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 UpdateItemNumAndNeedNum(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 UpdateItemNeedNum(GObject obj, int itemId, int needNum, bool checkNum = true, string color = "#716B59")
 
-         {
 
-             UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(obj);
 
-             com.m_c1.selectedIndex = needNum == 0 ? 0 : 1;
 
-             long hasNum = ItemDataManager.GetItemNum(itemId);
 
-             string strNeedNum = !checkNum ? StringUtil.GetColorText(needNum.ToString(), color) : StringUtil.GetColorText(needNum.ToString(), hasNum < needNum ? "#D0A09B" : color); needNum.ToString();
 
-             com.m_txtNeed.text = strNeedNum;
 
-             ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             com.m_loaIcon.url = ResPathUtil.GetIconPath(cfg);
 
-             UI_ComCostCurrency.ProxyEnd();
 
-         }
 
-         public static void UpdateItemNeedNum(GObject obj, int[] cost, bool checkNum = true, string color = "#716B59")
 
-         {
 
-             int itemId = cost[0];
 
-             int needNum = cost[1];
 
-             UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(obj);
 
-             com.m_c1.selectedIndex = needNum == 0 ? 0 : 1;
 
-             long hasNum = ItemDataManager.GetItemNum(itemId);
 
-             string strNeedNum = !checkNum ? StringUtil.GetColorText(needNum.ToString(), color) : StringUtil.GetColorText(needNum.ToString(), hasNum < needNum ? "#D0A09B" : color); needNum.ToString();
 
-             com.m_txtNeed.text = strNeedNum;
 
-             ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemId);
 
-             com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
 
-             UI_ComCostCurrency.ProxyEnd();
 
-         }
 
-         public static void UpdateTag(GObject obj, string tag)
 
-         {
 
-             UI_ComTag item = UI_ComTag.Proxy(obj);
 
-             int tagType = TagCfgArray.Instance.GetCfg(tag).type;
 
-             item.m_txtTag.text = tag;
 
-             item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
 
-             UI_ComTag.ProxyEnd();
 
-         }
 
-         /// <summary>
 
-         /// 合并奖励配置,会将同一物品id的奖励合并
 
-         /// </summary>
 
-         public static int[][] MergeBonus(int[][] item1, int[][] item2)
 
-         {
 
-             Dictionary<int, int> dictionary = new Dictionary<int, int>();
 
-             if (item1 != null)
 
-             {
 
-                 foreach (int[] item in item1)
 
-                 {
 
-                     if (dictionary.ContainsKey(item[0]))
 
-                     {
 
-                         dictionary[item[0]] += item[1];
 
-                     }
 
-                     else
 
-                     {
 
-                         dictionary.Add(item[0], item[1]);
 
-                     }
 
-                 }
 
-             }
 
-             if (item2 != null)
 
-             {
 
-                 foreach (int[] item in item2)
 
-                 {
 
-                     if (dictionary.ContainsKey(item[0]))
 
-                     {
 
-                         dictionary[item[0]] += item[1];
 
-                     }
 
-                     else
 
-                     {
 
-                         dictionary.Add(item[0], item[1]);
 
-                     }
 
-                 }
 
-             }
 
-             int[][] result = new int[dictionary.Count][];
 
-             int i = 0;
 
-             foreach (KeyValuePair<int, int> item in dictionary)
 
-             {
 
-                 result[i++] = new[] { item.Key, item.Value };
 
-             }
 
-             return result;
 
-         }
 
-         public static void CreateItemView(int[] item, GComponent component)
 
-         {
 
-             var itemData = createItemData(item);
 
-             component.data ??= new ItemView(component);
 
-             (component.data as ItemView)?.SetData(itemData);
 
-             (component.data as ItemView)?.ChangeTxtCountStyle();
 
-         }
 
-     }
 
- }
 
 
  |