141 lines
3.8 KiB
C#
141 lines
3.8 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
// 装备强化列表
|
|||
|
// 由于需要有限制的多选,会存储不同的SelectItem。
|
|||
|
public class EquipEnhanceContainer : UIContainerSelect {
|
|||
|
|
|||
|
public int multiSelectNum = -1; // 多选的情况下,最多可选择数量,默认-1,表示可无限多选
|
|||
|
public UIItemSelect curHightLight; // 当前高亮选中Item。
|
|||
|
|
|||
|
public override void OnSelectedObj(object obj)
|
|||
|
{
|
|||
|
ContentPos selectPos = _ValueList.Find((pos) =>
|
|||
|
{
|
|||
|
if (pos.Obj == obj)
|
|||
|
return true;
|
|||
|
return false;
|
|||
|
});
|
|||
|
|
|||
|
if (selectPos == null)
|
|||
|
return;
|
|||
|
|
|||
|
if (!((UIItemSelect)selectPos.ShowItem).IsCanSelect())
|
|||
|
return;
|
|||
|
|
|||
|
if(curHightLight != null)
|
|||
|
{
|
|||
|
curHightLight.UnSelected();
|
|||
|
((UIItemSelect)selectPos.ShowItem).Selected();
|
|||
|
curHightLight = (UIItemSelect)selectPos.ShowItem;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if(_Selecteds.Count != 0)
|
|||
|
{
|
|||
|
((UIItemSelect)_Selecteds[0].ShowItem).UnSelected();
|
|||
|
}
|
|||
|
((UIItemSelect)selectPos.ShowItem).Selected();
|
|||
|
curHightLight = (UIItemSelect)selectPos.ShowItem;
|
|||
|
}
|
|||
|
|
|||
|
// 多选的情况下,控制添加情况
|
|||
|
if (_IsMultiSelect)
|
|||
|
{
|
|||
|
if(_Selecteds.Contains(selectPos))
|
|||
|
{
|
|||
|
((EquipEnhanceItem)selectPos.ShowItem).UnAdd();
|
|||
|
_Selecteds.Remove(selectPos);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// 当不存在时,仅当多选数目没到上限时,添加
|
|||
|
if(_Selecteds.Count < multiSelectNum)
|
|||
|
{
|
|||
|
((EquipEnhanceItem)selectPos.ShowItem).Add();
|
|||
|
_Selecteds.Add(selectPos);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (_SelectedCallBack != null)
|
|||
|
{
|
|||
|
_SelectedCallBack(selectPos.Obj);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if(!_Selecteds.Contains(selectPos))
|
|||
|
{
|
|||
|
_Selecteds.Clear();
|
|||
|
_Selecteds.Add(selectPos);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (_SelectedCallBack != null && _Selecteds.Contains(selectPos) && !_IsMultiSelect)
|
|||
|
{
|
|||
|
_SelectedCallBack(obj);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (_DisSelectedCallBack != null && !_Selecteds.Contains(selectPos) && !_IsMultiSelect)
|
|||
|
{
|
|||
|
_DisSelectedCallBack(obj);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void InitSelectContent(IEnumerable list, IEnumerable selectedList, SelectedObjCallBack onSelect = null, SelectedObjCallBack onDisSelect = null, Hashtable exhash = null)
|
|||
|
{
|
|||
|
|
|||
|
foreach (ContentPos item in _Selecteds)
|
|||
|
{
|
|||
|
if (item.ShowItem != null)
|
|||
|
{
|
|||
|
((EquipEnhanceItem)item.ShowItem).UnSelected();
|
|||
|
((EquipEnhanceItem)item.ShowItem).UnAdd();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
curHightLight = null;
|
|||
|
|
|||
|
_SelectedCallBack = onSelect;
|
|||
|
_DisSelectedCallBack = onDisSelect;
|
|||
|
|
|||
|
gameObject.SetActive(true);
|
|||
|
|
|||
|
_SelectedList = selectedList;
|
|||
|
|
|||
|
base.InitContentItem(list, OnSelectedObj, exhash);
|
|||
|
|
|||
|
ShowItems();
|
|||
|
}
|
|||
|
|
|||
|
public override List<T> GetSelecteds<T>()
|
|||
|
{
|
|||
|
List<T> selectedObjs = new List<T>();
|
|||
|
if(_IsMultiSelect == false)
|
|||
|
{
|
|||
|
if(_Selecteds.Count > 0)
|
|||
|
{
|
|||
|
selectedObjs.Add((T)_Selecteds[0].Obj);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
for(int i = 0; i < multiSelectNum && i < _Selecteds.Count; ++i)
|
|||
|
{
|
|||
|
if(_Selecteds[i].Obj == null)
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
selectedObjs.Add((T)_Selecteds[i].Obj);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return selectedObjs;
|
|||
|
}
|
|||
|
|
|||
|
}
|