192 lines
5.8 KiB
C#
192 lines
5.8 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using GCGame.Table;
|
|||
|
|
|||
|
public class PopAutoMedicItemPanel : MonoBehaviour {
|
|||
|
|
|||
|
public static PopAutoMedicItemPanel Instance;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
//4.红 5.蓝
|
|||
|
private int _CurSelectType = -1;
|
|||
|
private List<int> SettingAutoItemIdList = new List<int>();
|
|||
|
private ClientCustomData.AutoMedicInfoStruct atuoMedicInfo;
|
|||
|
public void ShowItemByType(int type)
|
|||
|
{
|
|||
|
atuoMedicInfo = GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.PlayerCustomData.autoMedicInfo;
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case 4:
|
|||
|
{
|
|||
|
SettingAutoItemIdList = new List<int>();
|
|||
|
SettingAutoItemIdList.AddRange(atuoMedicInfo.autoHpIdList);
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
{
|
|||
|
SettingAutoItemIdList = new List<int>();
|
|||
|
SettingAutoItemIdList.AddRange(atuoMedicInfo.autoMpIdList);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
_CurSelectType = type;
|
|||
|
var autoUseItemTab = TableManager.GetAutoUseItem().Values;
|
|||
|
|
|||
|
var itemIdList = new List<int>();
|
|||
|
foreach(var item in autoUseItemTab)
|
|||
|
{
|
|||
|
if(item.SubClassID == type)
|
|||
|
{
|
|||
|
itemIdList.Add(item.Id);
|
|||
|
}
|
|||
|
}
|
|||
|
itemIdList.Sort(SortItemIdListByLevel);
|
|||
|
StartCoroutine(CraeteMedicItem(itemIdList));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public int SortItemIdListByLevel(int itemA, int itemB)
|
|||
|
{
|
|||
|
if (itemA == itemB)
|
|||
|
return 0;
|
|||
|
|
|||
|
var autoUseItemTabA = TableManager.GetAutoUseItemByID(itemA, 0);
|
|||
|
var autoUseItemTabB = TableManager.GetAutoUseItemByID(itemB, 0);
|
|||
|
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
|||
|
|
|||
|
if (autoUseItemTabA == null || autoUseItemTabB == null)
|
|||
|
return itemA < itemB ? -1 : 1;
|
|||
|
|
|||
|
var itemACount = backPack.GetItemCountByDataId(itemA);
|
|||
|
var itemBCount = backPack.GetItemCountByDataId(itemB);
|
|||
|
|
|||
|
if (itemACount > 0 && itemBCount <= 0)
|
|||
|
{
|
|||
|
return -1;
|
|||
|
}
|
|||
|
else if (itemACount <= 0 && itemBCount > 0)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return autoUseItemTabA.NeedLevel > autoUseItemTabB.NeedLevel ? 1 : -1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public GameObject itemPrefab;
|
|||
|
public Transform itemParent;
|
|||
|
|
|||
|
private List<AutoMedicItem> autoMedicItemPrefabList = new List<AutoMedicItem>();
|
|||
|
IEnumerator CraeteMedicItem(List<int> itemIdList)
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
|
|||
|
var _lackCount = 0;
|
|||
|
_lackCount = itemIdList.Count - autoMedicItemPrefabList.Count;
|
|||
|
|
|||
|
if(_lackCount > 0)
|
|||
|
{
|
|||
|
for(int index = 0; index < _lackCount; index++)
|
|||
|
{
|
|||
|
var item = GameObject.Instantiate(itemPrefab);
|
|||
|
item.transform.SetParent(itemParent);
|
|||
|
|
|||
|
item.transform.localScale = Vector3.one;
|
|||
|
item.transform.localPosition = Vector3.zero;
|
|||
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
|
|||
|
autoMedicItemPrefabList.Add(item.GetComponent<AutoMedicItem>());
|
|||
|
}
|
|||
|
}else
|
|||
|
{
|
|||
|
_lackCount = Mathf.Abs(_lackCount);
|
|||
|
for(int index = 0; index < autoMedicItemPrefabList.Count - _lackCount; index++)
|
|||
|
{
|
|||
|
autoMedicItemPrefabList[index].gameObject.SetActive(true);
|
|||
|
}
|
|||
|
for(int index = autoMedicItemPrefabList.Count - _lackCount; index < autoMedicItemPrefabList.Count; index++)
|
|||
|
{
|
|||
|
autoMedicItemPrefabList[index].gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for(int index = 0; index < itemIdList.Count; index++)
|
|||
|
{
|
|||
|
if(autoMedicItemPrefabList[index].gameObject.activeInHierarchy)
|
|||
|
{
|
|||
|
autoMedicItemPrefabList[index].InitItem(itemIdList[index], SettingAutoItemIdList.Contains(itemIdList[index]));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
public void AddItemToItemDateIdList(int itemId)
|
|||
|
{
|
|||
|
if (!SettingAutoItemIdList.Contains(itemId))
|
|||
|
SettingAutoItemIdList.Add(itemId);
|
|||
|
}
|
|||
|
|
|||
|
public void RemoveFromItemDateIdList(int itemId)
|
|||
|
{
|
|||
|
if (SettingAutoItemIdList.Contains(itemId))
|
|||
|
SettingAutoItemIdList.Remove(itemId);
|
|||
|
|
|||
|
if (SettingAutoItemIdList.Count == 0)
|
|||
|
SettingAutoItemIdList.Add(-1); //默认添加一个,表示不是第一次打开
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
//删除-1的引用
|
|||
|
if(SettingAutoItemIdList.Count > 1)
|
|||
|
{
|
|||
|
var count = SettingAutoItemIdList.Count - 1;
|
|||
|
for (int index = count; index >= 0; index--)
|
|||
|
{
|
|||
|
if (SettingAutoItemIdList[index] == -1)
|
|||
|
SettingAutoItemIdList.RemoveAt(index);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//保存之前做一次排序
|
|||
|
SettingAutoItemIdList.Sort(SortItemIdListByLevel);
|
|||
|
switch (_CurSelectType)
|
|||
|
{
|
|||
|
case 4:
|
|||
|
{
|
|||
|
atuoMedicInfo.autoHpIdList = new List<int>();
|
|||
|
atuoMedicInfo.autoHpIdList.AddRange(SettingAutoItemIdList);
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
{
|
|||
|
atuoMedicInfo.autoMpIdList = new List<int>();
|
|||
|
atuoMedicInfo.autoMpIdList.AddRange(SettingAutoItemIdList);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.SaveDataToServer();
|
|||
|
}
|
|||
|
|
|||
|
public void OnMaskClick()
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.PopAutoMedicItemPanel);
|
|||
|
}
|
|||
|
}
|