using Cal.DataTable; using FairyGUI; using System; using System.Collections.Generic; using System.Text; using ET.EventType; using UnityEngine; namespace ET { public class StartSoulUpgradeUIAwakeSyatem: AwakeSystem { public override void Awake(StartSoulUpgradeUI self) { self.Awake(); } } public class StartSoulUpgradeUIDestroySyatem: DestroySystem { public override void Destroy(StartSoulUpgradeUI self) { self.Destroy(); } } public class StartSoulUpgradeUI: Entity { public FUI_StartSoulUpgradeUI ui; private Scene zoneScene; private enum SelectType { Item, Material } private SelectType type; private bool isInit; private long id; private List selectedId = new List(); StringBuilder sb = new StringBuilder(); private StarSoulBag bag; public void Awake() { zoneScene = this.ZoneScene(); ui = GetParent(); AwakeAsync().Coroutine(); } private async ETVoid AwakeAsync() { if (!isInit) { isInit = true; ui.m_txtItem.text = "选择星魂"; ui.m_txtMarterial.text = "选择作为材料的星魂"; ui.m_txtPrice.text = null; this.ui.m_parExp.value = 0; this.ui.m_txtLevel.text = null; this.ui.m_txtBefore.text = null; this.ui.m_txtAfter.text = null; RegisterEvent(); } StarSoulBagUI.clickEvent += OnBagUIClick; var gv = this.zoneScene.GetComponent(); bag ??= this.zoneScene.GetComponent().MyUnit.GetComponent(); selectedId.Clear(); await ETTask.CompletedTask; } private void RegisterEvent() { ui.m_comType.self.onChanged.Set1(concent => { if (!int.TryParse(ui.m_comType.self.value, out int index)) return; type = (SelectType) index; }); this.ui.m_btnMake.self.onClick.Set(async () => { if (this.selectedId.Count == 0) return; if (this.id == 0) return; if (selectedId.Contains(id)) { TipHelper.OpenUI("被升级的星魂不能作为材料"); return; } var proto = new C2M_UpgradeStarSoulItem { itemId = this.id}; proto.idList.AddRange(this.selectedId); this.selectedId.Clear(); var ret = await zoneScene.GetComponent() .Call(proto); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } this.ui.m_txtMarterial.text = "选择作为材料的星魂"; this.ShowAfter(); }); this.ui.m_btnSelectAll0Level.self.onClick.Set(() => { if(this.type == SelectType.Item) return; if (!(this.zoneScene.GetComponent().Get(FUIPackage.Bag_StarSoulBagUI)?.GetComponent() is { } bagUI)) { Game.EventSystem.Publish(new OpenStarSoulBagUI() { zoneScene = this.zoneScene }); bagUI = this.zoneScene.GetComponent().Get(FUIPackage.Bag_StarSoulBagUI)?.GetComponent(); } this.selectedId.Clear(); bagUI.SelectAll0LevelItem(this.selectedId); RefreshGold(); }); } private void OnBagUIClick(long id) { if (type == SelectType.Item) { this.id = id; this.ui.m_txtItem.text = $"已选择星魂"; ShowBefore(); } else { int index = selectedId.IndexOf(id); var gv = this.zoneScene.GetComponent(); bag ??= this.zoneScene.GetComponent().MyUnit.GetComponent(); if (index != -1) { this.selectedId.RemoveAt(index); } else { if (this.selectedId.Count >= 20) { TipHelper.OpenUI("最多选择20个材料"); return; } var item = bag.Get(id); if (item.isLocked || item.isUsed) { return; } selectedId.Add(id); } RefreshGold(); } } private void RefreshGold() { this.ui.m_txtMarterial.text = $"已选择{this.selectedId.Count}个星魂材料"; int gold = 0; foreach (long l in this.selectedId) { var item = bag.Get(l); StarSoulLevelConfig soulLevelConfig = StarSoulLevelConfigCategory.Instance.GetByQualityAndLevel(item.quality,item.level); gold += soulLevelConfig.NeedCoin; } this.ui.m_txtPrice.text = $"需要{gold}金币"; } private void ShowBefore() { var data = bag.Get(id); if (data == null) { Debug.Log($"item==null where id = {id}"); return; } ShowExp(data); this.ui.m_txtLevel.text = $"当前等级:{data.level}"; ui.m_txtBefore.text = GetString(data); } private void ShowAfter() { var data = bag.Get(id); if (data == null) { Debug.Log($"item==null where id = {id}"); return; } ShowExp(data); this.ui.m_txtLevel.text = $"当前等级:{data.level}"; ui.m_txtAfter.text = GetString(data); } private void ShowExp(StarSoulItem data) { byte level = (byte) (data.level + 1); if (level <= 20) { StarSoulLevelConfig starSoulLevelConfig = StarSoulLevelConfigCategory.Instance.GetByQualityAndLevel(data.quality,level); double old = this.ui.m_parExp.max; if (old != starSoulLevelConfig.NeedExp) { this.ui.m_parExp.max = starSoulLevelConfig.NeedExp; this.ui.m_parExp.value = 0; } this.ui.m_parExp.TweenValue(data.exp,1); } else { this.ui.m_parExp.value = 0; } } private string GetString(StarSoulItem data) { sb.Clear(); TabHelper.GenerateStarSoulString(this.sb,this.bag, data); return sb.ToString(); } public void Destroy() { this.selectedId.Clear(); StarSoulBagUI.clickEvent -= OnBagUIClick; } } }