//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 13, 2017
|
//--------------------------------------------------------
|
|
using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
//装备捐献面板
|
namespace Snxxz.UI
|
{
|
|
public class DonateEquipTipsWin : Window
|
{
|
[SerializeField] ScrollerController _GridlineCtrl;
|
[SerializeField] Button _CloseBtn;
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
|
|
PackModel _playerPack;
|
PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
|
PlayerFairyAuTreasureData m_PlayerFairyAuTreasureData;
|
PlayerFairyAuTreasureData playerFairyAuTreasureData { get { return m_PlayerFairyAuTreasureData ?? (m_PlayerFairyAuTreasureData = ModelCenter.Instance.GetModel<PlayerFairyAuTreasureData>()); } }
|
private int _BagIndex = 0;//标记背包物品下标
|
|
private int MaxDonationAmount = 0;//最大捐献数量
|
List<string> phagocytosisID = new List<string>();//存储可以捐献的物品
|
|
#region Built-in
|
protected override void BindController()
|
{
|
MaxDonationAmount = int.Parse(FuncConfigConfig.Get("FamilyStoreSpace").Numerical1)+1;
|
}
|
|
protected override void AddListeners()
|
{
|
_CloseBtn.onClick.AddListener(CloseButton);
|
}
|
|
protected override void OnPreOpen()
|
{
|
playerPack.refreshItemCountEvent += BackpackRefresh;//背包物品清理
|
_GridlineCtrl.OnRefreshCell += OnRefreshGridCell;
|
Backpacking();//背包物品读取和创建
|
|
OnCreateGridLineCell(_GridlineCtrl);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
playerPack.refreshItemCountEvent -= BackpackRefresh;//背包物品清理
|
_GridlineCtrl.OnRefreshCell -= OnRefreshGridCell;
|
|
}
|
#endregion
|
|
|
void CloseButton()//关闭按钮
|
{
|
Close();
|
|
}
|
|
void Backpacking()//物品读取
|
{
|
Dictionary<int, ItemModel> backpack_dic = playerPack.GetSinglePack(PackType.Item).GetAllItems();
|
Dictionary<int, ProductOrderJudgment> _ProductOrderJudgment = new Dictionary<int, ProductOrderJudgment>();
|
phagocytosisID.Clear();
|
_ProductOrderJudgment = AttributeJudgment();///属性判断
|
if (backpack_dic.Count == 0)//得到背包的所有物品
|
return;
|
|
|
foreach (int item_id in backpack_dic.Keys)
|
{
|
|
ItemConfig _ChinItem = ItemConfig.Get((int)backpack_dic[item_id].itemId);
|
|
if (backpack_dic[item_id].isBind == 1)
|
continue;
|
foreach (int key in _ProductOrderJudgment.Keys)
|
{
|
if (_ChinItem.EquipPlace == key && _ChinItem.LV >= _ProductOrderJudgment[key].Class && _ChinItem.StarLevel >= _ProductOrderJudgment[key].TheStar && _ChinItem.ItemColor >= _ProductOrderJudgment[key].Color)
|
{
|
|
string IDnumber = backpack_dic[item_id].itemId.ToString() + "|" + item_id.ToString();//添加ID和位置索引
|
|
phagocytosisID.Add(IDnumber);
|
|
}
|
}
|
}
|
}
|
|
class ProductOrderJudgment
|
{
|
public int Class;//阶级
|
public int TheStar;//星级
|
public int Color;//颜色
|
|
|
}
|
|
Dictionary<int, ProductOrderJudgment> AttributeJudgment()//属性判断
|
{
|
Dictionary<int, ProductOrderJudgment> _DicConditions = new Dictionary<int, ProductOrderJudgment>();//条件字典
|
FuncConfigConfig Number1 = FuncConfigConfig.Get("FamilyStoreItemRule1");
|
FuncConfigConfig Number2 = FuncConfigConfig.Get("FamilyStoreItemRule2");
|
string[] strA = Number1.Numerical1.Split('|');
|
string[] strA1 = Number1.Numerical2.Split('|');
|
for (int i = 0; i < strA.Length; i++)
|
{
|
if (!_DicConditions.ContainsKey(int.Parse(strA[i])))
|
{
|
ProductOrderJudgment _ProductOrder = new ProductOrderJudgment();
|
_ProductOrder.Class = int.Parse(strA1[0]);
|
_ProductOrder.TheStar = int.Parse(strA1[1]);
|
_ProductOrder.Color = int.Parse(strA1[2]);
|
_DicConditions.Add(int.Parse(strA[i]), _ProductOrder);
|
}
|
}
|
|
string[] strB = Number2.Numerical1.Split('|');
|
string[] strB1 = Number2.Numerical2.Split('|');
|
for (int j = 0; j < strB.Length; j++)
|
{
|
if (!_DicConditions.ContainsKey(int.Parse(strB[j])))
|
{
|
ProductOrderJudgment _ProductOrder = new ProductOrderJudgment();
|
_ProductOrder.Class = int.Parse(strB1[0]);
|
_ProductOrder.TheStar = int.Parse(strB1[1]);
|
_ProductOrder.Color = int.Parse(strB1[2]);
|
_DicConditions.Add(int.Parse(strB[j]), _ProductOrder);
|
}
|
|
}
|
return _DicConditions;
|
}
|
|
|
void OnCreateGridLineCell(ScrollerController gridCtrl)//预制体创建
|
{
|
gridCtrl.Refresh();
|
int Index = Mathf.CeilToInt((float)phagocytosisID.Count / 5);
|
for (int i = 0; i < Index; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
|
gridCtrl.Restart();
|
}
|
|
void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
int line = cell.index;
|
for (int i = 0; i < 5; i++)
|
{
|
|
int index = line * 5 + i;
|
GameObject obj = cell.transform.GetChild(i).gameObject;
|
ItemCell _itemCell = obj.transform.Find("ItemCell").GetComponent<ItemCell>();
|
Button _ItemBtn = _itemCell.GetComponent<Button>();
|
if (index < phagocytosisID.Count)
|
{
|
obj.SetActive(true);
|
|
string[] _ParseStr = phagocytosisID[index].Split('|');
|
int _ItemID = int.Parse(_ParseStr[0]);
|
int _index = int.Parse(_ParseStr[1]);
|
ItemConfig Item = ItemConfig.Get(_ItemID);
|
PetEatEquipConfig tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(Item.ItemColor, Item.LV);//装备积分兑换表
|
|
ItemModel model = playerPack.GetItemByIndex(PackType.Item, _index);
|
if (model != null)
|
{
|
_itemCell.Init(model,true);
|
_ItemBtn.RemoveAllListeners();
|
_ItemBtn.AddListener(() =>
|
{
|
_BagIndex = _index;
|
itemTipsModel.SetItemTipsModel(PackType.Item, model.guid, false, true, ItemTipChildType.UnionWarehouseDonation);
|
itemTipsModel.curAttrData.SetTipsFuncBtn(ItemOperateType.donate, Donation);
|
itemTipsModel.ShowUICtrl();
|
});
|
}
|
}
|
else
|
{
|
obj.SetActive(false);
|
}
|
}
|
|
}
|
|
|
void Donation(ItemOperateType type, string s)//捐献
|
{
|
switch (type)
|
{
|
case ItemOperateType.donate:
|
////像服务端捐献发包
|
if (playerFairyAuTreasureData._DicfamilyStoreItem.Count >= MaxDonationAmount)
|
{
|
ScrollTip.ShowTip(Language.Get("Z1802"));
|
return;
|
}
|
CA609_tagCMFamilyStoreDonate _tagCA609 = new CA609_tagCMFamilyStoreDonate();
|
_tagCA609.ItemIndex = (byte)_BagIndex;
|
GameNetSystem.Instance.SendInfo(_tagCA609);
|
KnapSackEventMgr.Instance.HideItemPopWin();
|
break;
|
}
|
}
|
|
|
|
void BackpackRefresh(PackType type, int itemPlace, int id)//背包物品清理
|
{
|
|
Backpacking();//背包物品读取和创建
|
OnCreateGridLineCell(_GridlineCtrl);
|
}
|
}
|
}
|