using Cal.DataTable; using FairyGUI; using System; using System.Collections.Generic; using UnityEngine; namespace ET { public class StarSoulBagUIAwakeSyatem: AwakeSystem { public override void Awake(StarSoulBagUI self) { self.Awake(); } } public class StarSoulBagUIDestroySyatem: DestroySystem { public override void Destroy(StarSoulBagUI self) { self.Destroy(); } } public class StarSoulBagUI: Entity { private enum SortType: byte { Time = 0, SuitType = 1, PosType = 2, } public FUI_StarSoulBagUI ui; private Scene zoneScene; private StarSoulBag bag; private bool isInit; private SortType sortType = SortType.Time; private Quality sortQuality = Quality.Common; private List list = new List(); private LinkedList tempList = new LinkedList(); public static event Action clickEvent; public void Awake() { zoneScene = this.ZoneScene(); ui = GetParent(); if (!this.isInit) { isInit = true; this.ui.m_slotList.SetVirtual(); // this.rollOverAction = this.OnRollOver; this.ui.m_slotList.itemRenderer = OnItemRender; RegistEvent(); } AwakeAsync().Coroutine(); } private async ETVoid AwakeAsync() { bag ??= this.zoneScene.GetComponent(); ShowSlots(); await ETTask.CompletedTask; } private void ShowSlots() { this.SortByQulity(); this.ui.m_slotList.numItems = this.list.Count; this.ui.m_slotList.RefreshVirtualList(); this.ui.m_txtCapity.text = $"容量:{bag.ItemCount}/1000"; } private void OnItemRender(int index, GObject item) { FUI_ButtonStarSoulSlot btn = FUI_ButtonStarSoulSlot.GetFormPool(this.zoneScene, item); long id = list[index]; var data = this.bag.Get(id); ItemDataView(btn, data); TabHelper.SetTab(btn.self, () => { #if !UNITY_STANDALONE long id = list[index]; clickEvent?.Invoke(id); #endif TabHelper.OpenStarSoulUI(this.bag, id); }, true); #if UNITY_STANDALONE btn.self.onClick.Set1(context => { long id = list[index]; clickEvent?.Invoke(id); }); #endif btn.self.onRightClick.Set1(context => { string tip = null; tip = data.isUsed? "是否卸载此星魂?" : "是否放置此星魂到装备上?"; var tipUi = TipHelper.OpenUI(tip, tipType: TipType.Double); tipUi.m_btnYes.self.onClick.Set(async () => { var ret = await this.zoneScene.GetComponent() .Call(new C2M_PutonStarSoulItem { itemId = id }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } }); }); btn.m_btnLock.self.onClick.Set1(context => { context.StopPropagation(); this.zoneScene.GetComponent().Session .Send(new C2M_LockStarSoulItem() { itemId = id, isLock = btn.m_btnLock.self.selected }); }); } private static void ItemDataView(FUI_ButtonStarSoulSlot btn, StarSoulItem data) { StarSoulTypeConfig soulTypeConfig = StarSoulTypeConfigCategory.Instance.Get(data.typeId); btn.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, soulTypeConfig.Icon); btn.m_txtLevel.text = data.level + string.Empty; btn.m_txtUsed.text = data.isUsed? "用" : null; btn.self.title = soulTypeConfig.Name; int viceCount = 0; foreach (int i in data.viceAttribute) { if (i != 0) viceCount++; } string str = null; for (int i = 0; i < 4; i++) { if (i < viceCount) { str += TabHelper.YellowStar; } else { str += TabHelper.SliverStar; } } btn.m_txtStar.text = str; Color color = ColorHelper.GetColorByStr(TabHelper.GetQualityColor(data.quality)); btn.m_img.color = color; btn.m_btnLock.self.selected = data.isLocked; } private void RegistEvent() { this.ui.m_sortType.onChanged.Set(SortTypeChanged); this.ui.m_quality.onChanged.Set(QualityTypeChanged); } private void SortTypeChanged() { sortType = (SortType) this.ui.m_sortType.selectedIndex; ReFresh(); } private void QualityTypeChanged() { this.sortQuality = (Quality) (this.ui.m_quality.selectedIndex + 1); ReFresh(); } private void SortByQulity() { this.list.Clear(); foreach (var kv in this.bag.itemDic) { var item = kv.Value; if (item.quality == this.sortQuality) this.list.Add(item.Id); } if (this.sortType == SortType.Time) { return; } tempList.Clear(); foreach (long l in this.list) { var item = this.bag.Get(l); if (item == null) { Log.Error($"item == null where id = {l}"); continue; } var curr = this.tempList.First; if (curr == null) { this.tempList.AddLast(item); continue; } bool isAdd = false; while (curr != null) { var compareItem = curr.Value; if (compareItem == null) continue; if (this.sortType == SortType.SuitType) { if (compareItem.typeId > item.typeId) { tempList.AddBefore(curr, item); isAdd = true; break; } } else if (this.sortType == SortType.PosType) { if (compareItem.posType > item.posType) { tempList.AddBefore(curr, item); isAdd = true; break; } } curr = curr.Next; } if (!isAdd) { tempList.AddLast(item); } } this.list.Clear(); foreach (var starsoulIttem in tempList) { this.list.Add(starsoulIttem.Id); } tempList.Clear(); } public void ReFresh() { AwakeAsync().Coroutine(); } public void SelectAll0LevelItem(List selectedId) { int count = 0; foreach (long l in this.list) { var item = this.bag.Get(l); if (item.isLocked || item.isUsed) continue; if (count >= 20) return; selectedId.Add(l); count++; } } public void Destroy() { list.Clear(); } } }