using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
//自动淘金选项
|
public class GoldRushAutoCell : CellView
|
{
|
[SerializeField] Toggle autoToggle;
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] Text nameText;
|
[SerializeField] CountControler countControler;
|
|
[SerializeField] Transform lockGo;
|
[SerializeField] Text lockText;
|
|
int arrIndex;
|
int itemLV;
|
public void Display(int _index)
|
{
|
arrIndex = _index;
|
int itemID = GoldRushManager.Instance.autoRefreshItemIDs[arrIndex];
|
itemLV = GoldRushManager.Instance.GetAutoItemLV(arrIndex);
|
bool isOn = itemLV > 0;
|
itemLV = itemLV > 0 ? itemLV : 1;
|
if (IsLock(itemID, out int funcID))
|
{
|
lockGo.SetActive(true);
|
lockText.text = Language.Get("L1038", FuncOpenLVConfig.Get(funcID).Name);
|
countControler.SetActive(false);
|
autoToggle.SetActive(false);
|
}
|
else
|
{
|
lockGo.SetActive(false);
|
countControler.SetActive(true);
|
autoToggle.SetActive(true);
|
autoToggle.onValueChanged.AddListener((value) =>
|
{
|
autoToggle.isOn = value;
|
GoldRushManager.Instance.SetAutoItemLV(arrIndex, value ? itemLV : 0);
|
});
|
autoToggle.isOn = isOn;
|
countControler.Init(ChangeWorkerCount, GoldRushItemConfig.maxLVDic[itemID], itemLV,
|
AddWorker, DecWorker, Language.Get("L1113"));
|
}
|
|
var config = GoldRushItemConfig.GetConfig(itemID, itemLV);
|
if (config == null)
|
{
|
return;
|
}
|
itemCell.Init(new ItemCellModel(itemID, false, config.ItemCount));
|
itemCell.button.AddListener(() =>
|
{
|
ItemTipUtility.Show(itemID);
|
});
|
|
nameText.text = GoldRushManager.Instance.GetCampItemName(config);
|
|
|
}
|
|
|
bool IsLock(int itemID, out int funcID)
|
{
|
funcID = 0;
|
if (GoldRushManager.Instance.itemIDUnLockFuncIDDict.ContainsKey(itemID))
|
{
|
funcID = GoldRushManager.Instance.itemIDUnLockFuncIDDict[itemID];
|
if (!FuncOpen.Instance.IsFuncOpen(funcID))
|
{
|
return true;
|
}
|
|
return false;
|
}
|
return false;
|
}
|
|
void ChangeWorkerCount(int lv)
|
{
|
itemLV = lv;
|
if (!autoToggle.isOn)
|
{
|
return;
|
}
|
if (lv == GoldRushManager.Instance.GetAutoItemLV(arrIndex))
|
{
|
return;
|
}
|
GoldRushManager.Instance.SetAutoItemLV(arrIndex, lv);
|
}
|
|
bool AddWorker(int lv)
|
{
|
return true;
|
}
|
|
bool DecWorker(int count)
|
{
|
if (count <= 1)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
|
}
|