using vnxbqy.UI; using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using System.Linq; public class TreasurePavilionUpgradeChooseCell : CellView { [SerializeField] ItemCell itemCell; [SerializeField] TextEx txtItemName; [SerializeField] TextEx txtItemCount; [SerializeField] Slider slider; int pieceGuBaoId; TreasurePavilionUpgradeChooseModel model { get { return ModelCenter.Instance.GetModelEx(); } } public void Display(int pieceGuBaoId) { this.pieceGuBaoId = pieceGuBaoId; Dictionary nowDict; if (!model.TryGetPieceDictInfo(GubaoPieceInfoType.Have, model.nowGubaoId, model.nowStar, model.nowQuality, out nowDict)) return; Dictionary useDict; if (!model.TryGetPieceDictInfo(GubaoPieceInfoType.Choose, model.nowGubaoId, model.nowStar, model.nowQuality, out useDict)) useDict = new Dictionary(); int allCount; if (!nowDict.TryGetValue(pieceGuBaoId, out allCount)) allCount = 0; int hasCount; if (!useDict.TryGetValue(pieceGuBaoId, out hasCount)) hasCount = 0; int itemId = ILGubaoConfig.Get(pieceGuBaoId).UnlockItemID; itemCell.Init(new ItemCellModel(itemId, false, (ulong)allCount)); itemCell.countText.SetActive(false); itemCell.button.SetListener(() => { ItemTipUtility.Show(itemId); }); txtItemName.text = UIHelper.AppendColor(model.nowQuality, ItemConfig.Get(itemId).ItemName); txtItemCount.text = StringUtility.Contact(hasCount, "/", allCount); slider.minValue = 0; slider.maxValue = allCount; slider.value = hasCount; slider.onValueChanged.RemoveAllListeners(); slider.onValueChanged.AddListener(OnSliderValueChanged); } void OnSliderValueChanged(float value) { int maxValueCount = GetMaxValueCount(); value = Mathf.Clamp(value, 0, slider.maxValue); if (value > maxValueCount) value = maxValueCount; slider.value = value; model.SetGubaoPieceDict(GubaoPieceInfoType.Choose, model.nowGubaoId, model.nowStar, model.nowQuality, pieceGuBaoId, (int)value); model.UpdateInfoAction?.Invoke(); } int GetMaxValueCount() { Dictionary useDict; if (!model.TryGetPieceDictInfo(GubaoPieceInfoType.Choose, model.nowGubaoId, model.nowStar, model.nowQuality, out useDict)) return 0; int count; if (!useDict.TryGetValue(pieceGuBaoId, out count)) return 0; useDict.Remove(pieceGuBaoId); int maxTotalCount = ILGubaoStarConfig.GetNeedGubaPieceCountByQuality(model.nowGubaoId, model.nowStar, model.nowQuality); int result = Mathf.Max(0, maxTotalCount - useDict.Values.Sum()); return result; } }