123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System;
- using System.Collections.Generic;
- using Fort23.UTool;
- using GameLogic.Bag;
- namespace Fort23.Mono
- {
- [UIBinding(prefab = "EqRecyclePanel" )]
- public partial class EqRecyclePanel : UIPanel
- {
-
- private string eqItemPolPoolName = "eqItem";
- private string awardItemPoolName = "awardItem";
- private List<WidgetItem> pendingEqs = new List<WidgetItem>();
- private void Init()
- {
- }
- protected override void AddEvent()
- {
- }
- protected override void DelEvent()
- {
- }
- public override void AddButtonEvent()
- {
- btnBack.onClick.AddListener(OnclickClose);
- btnRec.onClick.AddListener(OnClickRecycle);
- }
- private async void OnClickRecycle()
- {
- if (pendingEqs.Count <= 0)
- {
- LogTool.Log("暂无可以分解的装备");
- return;
- }
-
- foreach (WidgetItem widgetItem in pendingEqs)
- {
- ItemInfo itemInfo = BagController.Instance.allBagDic[widgetItem.itemInfo.guid];
- if(itemInfo.count.Value - widgetItem.itemInfo.count.Value <= 0)
- {
- //删除到0后,如果装备被穿了,不移除背包。
- if (itemInfo.eqInfo.isWear)
- {
- itemInfo.count.Value = 0;
- BagController.Instance.RemoveItem(itemInfo, false, false);
- }
- else{
- // BagController.Instance.allBagDic.Remove(widgetItem.itemInfo.guid);
- BagController.Instance.RemoveItem(itemInfo, false, true);
- }
- }
- else {
- // itemInfo.count.Value -= widgetItem.itemInfo.count.Value;
- BagController.Instance.ModifyItem(itemInfo, false);
- }
- }
-
-
- BagController.Instance.ReInitAllEqItem();
- foreach (KeyValuePair<string,ItemInfo> keyValuePair in awardDic)
- {
- BagController.Instance.AddItem(keyValuePair.Value.itemID, keyValuePair.Value.count.Value, keyValuePair.Value.guid);
- }
-
- AccountFileInfo.Instance.SavePlayerData(true);
-
- pendingEqs.Clear();
-
- RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top);
-
- rewardsPanel.InitRewardsPanel(awardDic, delegate
- {
- OnclickClose();
- awardDic.Clear();
- });
-
-
- }
- private void OnclickClose()
- {
- UIManager.Instance.HideUIUIPanel(this);
- UIManager.Instance.DormancyAllGComponent<WidgetItem>(eqItemPolPoolName);
- UIManager.Instance.DormancyAllGComponent<WidgetItem>(awardItemPoolName);
- }
- /// <summary>
- /// 回收奖励
- /// </summary>
- private Dictionary<string, ItemInfo> awardDic = new Dictionary<string, ItemInfo>();
- public async void InitEqRecyclePanel()
- {
- // GameObject eqGo = eqsUIObj[0] as GameObject;
- pendingEqs.Clear();
- awardDic.Clear();
- foreach (KeyValuePair<int,Dictionary<int,List<ItemInfo>>> keyValuePair in PlayerManager.Instance.eqController.allZyEqDic)
- {
- foreach (KeyValuePair<int,List<ItemInfo>> valuePair in keyValuePair.Value)
- {
- foreach (ItemInfo itemInfo in valuePair.Value)
- {
- if (!ValidityCheck(itemInfo))
- {
- continue;
- }
- WidgetItem widgetItem = await UIManager.Instance.
- CreateGComponentForObject<WidgetItem>(eqItem, null, isInstance : true,
- poolName:eqItemPolPoolName, root:itemRoot);
- widgetItem.InitWidget(itemInfo);
-
- pendingEqs.Add(widgetItem);
- for (int i = 0; i < itemInfo.eqInfo.basicEquipConfig.disItems.Length; i++)
- {
- AddToRecycleDic(itemInfo.eqInfo.basicEquipConfig.disItems[i], itemInfo.eqInfo.basicEquipConfig.count[i]);
- }
-
- }
- }
- }
- foreach (KeyValuePair<string,ItemInfo> keyValuePair in awardDic)
- {
- WidgetItem awardItem = await UIManager.Instance.
- CreateGComponentForObject<WidgetItem>(recItem, null, isInstance : true,
- poolName:awardItemPoolName, root:rewardRoot);
- awardItem.InitWidget(keyValuePair.Value);
- }
-
- }
- private void AddToRecycleDic(int itemID, int count)
- {
- ItemInfo itemInfo = new ItemInfo(itemID, count);
- if (awardDic.ContainsKey(itemInfo.guid))
- {
- awardDic[itemInfo.guid].count += count;
- }
- else {
- awardDic.Add(itemInfo.guid, itemInfo);
- }
- }
- /// <summary>
- /// 装备有效性检查
- /// </summary>
- /// <param name="itemInfo"></param>
- /// <returns></returns>
- private bool ValidityCheck(ItemInfo itemInfo)
- {
- if (itemInfo.eqInfo == null)
- {
- return false;
- }
- if (itemInfo.count.Value <= 0)
- {
- LogTool.Log(itemInfo.count.Value +"装备只有1个,而且被穿了:" + itemInfo.eqInfo.isWear);
- if (!itemInfo.eqInfo.isWear)
- {
- LogTool.Log("不应该出现,数量为0的装备还未穿戴?需要检查:eqConfigID"
- + itemInfo.eqInfo.basicEquipConfig.ID
- + "| itemID:" + itemInfo.itemID
- + "| guid:" + itemInfo.guid);
- }
-
- return false;
- }
- return true;
- }
- }
- }
|