ItemUtil.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using ET;
  2. using FairyGUI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UI.CommonGame;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class ItemUtil
  11. {
  12. /// <param name="showTips">是否弹购买成功飘字,默认是</param>
  13. /// <param name="openSource">是否打开来源界面。默认否</param>
  14. /// <param name="showTxtBuyTips">是否显示购买提示</param>
  15. 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 = "")
  16. {
  17. if (itemId == ConstItemID.GOLD)
  18. {
  19. AddGold(num, onSuccess);
  20. }
  21. else if (itemId == ConstItemID.POWER)
  22. {
  23. AddPower();
  24. }
  25. else
  26. {
  27. BuyItemConteoller.Show(itemId, num, ConstBuyType.TYPE_ITEM, onSuccess, showTips, openSource, maxCount);
  28. BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;
  29. }
  30. }
  31. public static void AddPower(string prefix = "", Action onSuccess = null)
  32. {
  33. int maxLimit = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.POWER).maxLimit;
  34. int lastBuyCount = maxLimit - ItemDataManager.GetItemExchangeTimes(ConstItemID.POWER);
  35. string showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买{0}/{1}次", lastBuyCount, maxLimit);
  36. BuyConfirmController.Show(ConstItemID.POWER, 1, () =>
  37. {
  38. if (onSuccess != null)
  39. {
  40. onSuccess();
  41. }
  42. }, showTxt);
  43. }
  44. public static void AddGold(long value = 0, Action onSuccess = null)
  45. {
  46. BuyConfirmController.Show(ConstItemID.GOLD, 1, () =>
  47. {
  48. if (onSuccess != null)
  49. {
  50. onSuccess();
  51. }
  52. });
  53. }
  54. public static void AddDiamondPurple()
  55. {
  56. // ViewManager.Show(ViewName.RECHARGE_STORE_VIEW);
  57. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  58. }
  59. //红钻(鲛绡)
  60. public static void AddDiamondRed(int value = 0, Action onSuccess = null)
  61. {
  62. ItemExchangeCfg currencyRatioCfg = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.DIAMOND_RED);// GetCurrencyRatioCfgById(ConstItemID.DIAMOND_RED);
  63. BuyItemConteoller.Show(currencyRatioCfg.id, value > 0 ? value : 1, ConstBuyType.TYPE_ITEM, onSuccess, true, true);
  64. BuyItemConteoller.showTxtBuyTips = true;
  65. }
  66. public static string GetItemName(int itemId)
  67. {
  68. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  69. return itemCfg.name;
  70. }
  71. public static string GetSuitName(int suitId)
  72. {
  73. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  74. return suitCfg.name;
  75. }
  76. public static int GetItemRarity(int itemId)
  77. {
  78. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  79. return itemCfg.rarity;
  80. }
  81. public static List<ItemData> CreateItemDataList(List<ItemInfoProto> items)
  82. {
  83. List<ItemData> itemList = new List<ItemData>();
  84. for (int i = 0; i < items.Count; i++)
  85. {
  86. ItemData itemData = createItemData(items[i].ConfigId, items[i].Count);
  87. itemList.Add(itemData);
  88. }
  89. return itemList;
  90. }
  91. public static List<ItemData> CreateItemDataList(int[][] bonus, bool isOnceBonus = false)
  92. {
  93. List<ItemData> itemList = new List<ItemData>();
  94. foreach (int[] item in bonus)
  95. {
  96. ItemData itemData = createItemData(item);
  97. itemList.Add(itemData);
  98. itemData.isOnceBonus = isOnceBonus;
  99. }
  100. return itemList;
  101. }
  102. public static List<ItemData> CreateItemDataList(int[][] bonus, int num)
  103. {
  104. List<ItemData> itemList = new List<ItemData>();
  105. foreach (int[] item in bonus)
  106. {
  107. int count = 0;
  108. if (item.Length > 1)
  109. {
  110. count = item[1];
  111. }
  112. else
  113. {
  114. count = 1;
  115. }
  116. ItemData itemData = createItemData(item[0], count * num);
  117. itemList.Add(itemData);
  118. }
  119. return itemList;
  120. }
  121. public static List<ItemData> CreateItemDataList(int itemId, long count)
  122. {
  123. List<ItemData> itemList = new List<ItemData>();
  124. ItemData itemData = createItemData(itemId, count);
  125. itemList.Add(itemData);
  126. return itemList;
  127. }
  128. public static ItemData createItemData(int[] bonus)
  129. {
  130. int itemID = bonus[0];
  131. int itemNum = 1;
  132. if (bonus.Length > 1)
  133. {
  134. itemNum = bonus[1];
  135. }
  136. return createItemData(itemID, itemNum);
  137. }
  138. public static ItemData createItemData(int itemId, long count)
  139. {
  140. ItemData itemData = ItemDataPool.GetItemData(itemId);
  141. itemData.num = count;
  142. return itemData;
  143. }
  144. public static Boolean CheckItemEnough(int itemId, int num)
  145. {
  146. long hasNum = ItemDataManager.GetItemNum(itemId);
  147. return hasNum >= num;
  148. }
  149. public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)
  150. {
  151. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);
  152. if (needItemId > 0)
  153. {
  154. int subType = ItemUtilCS.GetItemSubType(needItemId);
  155. if (subType == cfg1.type)
  156. {
  157. return true;
  158. }
  159. else if (cfg1.subMenusArr.Length > 0)
  160. {
  161. foreach (int id2 in cfg1.subMenusArr)
  162. {
  163. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  164. if (cfg2.type == subType)
  165. {
  166. return true;
  167. }
  168. }
  169. }
  170. }
  171. else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)
  172. {
  173. return true;
  174. }
  175. return false;
  176. }
  177. public static void SortItemIdsByOwned(int[] array)
  178. {
  179. Array.Sort(array, (int a, int b) =>
  180. {
  181. bool ownedA = ItemDataManager.GetItemNum(a) > 0;
  182. bool ownedB = ItemDataManager.GetItemNum(b) > 0;
  183. if (!ownedB && ownedA)
  184. {
  185. return 1;
  186. }
  187. else if (ownedB && !ownedA)
  188. {
  189. return -1;
  190. }
  191. return 0;
  192. });
  193. }
  194. public static string GetItemResExt(int itemType, int type, bool isIcon = false)
  195. {
  196. if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING && !isIcon)
  197. {
  198. return "jpg";
  199. }
  200. return "png";
  201. }
  202. public static void UpdateItemNumAndNeedNum(GObject obj, int itemId, int needNum, bool ChangeColor = false)
  203. {
  204. UI_ComCostCurrencyWithHas com = UI_ComCostCurrencyWithHas.Proxy(obj);
  205. long hasNum = ItemDataManager.GetItemNum(itemId);
  206. string needStrColor = ChangeColor ? "#B99F7B" : "#FDEED4";
  207. string strHasNum = StringUtil.GetColorText(hasNum.ToString(), hasNum < needNum ? "#C5645A" : needStrColor); hasNum.ToString();
  208. // com.m_txtNeed.text = needNum.ToString();
  209. com.m_txtCount.text = string.Format("{0}{1}{2}", strHasNum, StringUtil.GetColorText("/", needStrColor), StringUtil.GetColorText(needNum.ToString(), needStrColor));
  210. ItemCfg cfg1 = ItemCfgArray.Instance.GetCfg(itemId);
  211. com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg1.res);
  212. }
  213. public static void UpdateItemNeedNum(GObject obj, int itemId, int needNum, bool checkNum = true, string color = "#716B59")
  214. {
  215. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(obj);
  216. com.m_c1.selectedIndex = needNum == 0 ? 0 : 1;
  217. long hasNum = ItemDataManager.GetItemNum(itemId);
  218. string strNeedNum = !checkNum ? StringUtil.GetColorText(needNum.ToString(), color) : StringUtil.GetColorText(needNum.ToString(), hasNum < needNum ? "#D0A09B" : color); needNum.ToString();
  219. com.m_txtNeed.text = strNeedNum;
  220. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemId);
  221. com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
  222. UI_ComCostCurrency.ProxyEnd();
  223. }
  224. public static void UpdateItemNeedNum(GObject obj, int[] cost, bool checkNum = true, string color = "#716B59")
  225. {
  226. int itemId = cost[0];
  227. int needNum = cost[1];
  228. UI_ComCostCurrency com = UI_ComCostCurrency.Proxy(obj);
  229. com.m_c1.selectedIndex = needNum == 0 ? 0 : 1;
  230. long hasNum = ItemDataManager.GetItemNum(itemId);
  231. string strNeedNum = !checkNum ? StringUtil.GetColorText(needNum.ToString(), color) : StringUtil.GetColorText(needNum.ToString(), hasNum < needNum ? "#D0A09B" : color); needNum.ToString();
  232. com.m_txtNeed.text = strNeedNum;
  233. ItemCfg cfg = ItemCfgArray.Instance.GetCfg(itemId);
  234. com.m_loaIcon.url = ResPathUtil.GetCommonGameResPath(cfg.res);
  235. UI_ComCostCurrency.ProxyEnd();
  236. }
  237. public static void UpdateTag(GObject obj, string tag)
  238. {
  239. UI_ComTag item = UI_ComTag.Proxy(obj);
  240. int tagType = TagCfgArray.Instance.GetCfg(tag).type;
  241. item.m_txtTag.text = tag;
  242. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tagType);
  243. UI_ComTag.ProxyEnd();
  244. }
  245. }
  246. }