using Cal.DataTable; using FairyGUI; using System; using System.Collections.Generic; using System.Text; 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(); 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; 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.ShowAfter(); }); } private void OnBagUIClick(long id) { if (type == SelectType.Item) { this.id = id; this.ui.m_txtItem.text = $"已选择星魂"; ShowBefore(); } else { int index = selectedId.IndexOf(id); if (index != -1) { this.selectedId.RemoveAt(index); } else { if (this.selectedId.Count >= 20) { TipHelper.OpenUI("最多选择20个材料"); return; } selectedId.Add(id); } this.ui.m_txtMarterial.text = $"已选择{this.selectedId.Count}个星魂材料"; int gold = 0; StarSoulBag bag = this.zoneScene.GetComponent(); 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() { StarSoulBag bag = this.zoneScene.GetComponent(); 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() { StarSoulBag bag = this.zoneScene.GetComponent(); 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(); StarSoulAttributeConfig soulAttributeConfig = StarSoulAttributeConfigCategory.Instance.Get(data.mainAttribute); sb.AppendLine("[size=3] [/size]"); sb.AppendLine("固定属性:"); sb.AppendLine( $"[color=#99bf88]{TabHelper.GetAttributeString((Cal.AttributeType) soulAttributeConfig.Key, soulAttributeConfig.Value)}[/color]"); sb.AppendLine("[size=3] [/size]"); sb.AppendLine("随机属性:"); for (var i = 0; i < data.viceAttribute.Length; i++) { int __id = data.viceAttribute[i]; if (__id == 0) break; soulAttributeConfig = StarSoulAttributeConfigCategory.Instance.Get(__id); sb.AppendLine( $"[color=#99bf88]{TabHelper.GetAttributeString((Cal.AttributeType) soulAttributeConfig.Key, ItemHelper.GetRealViceValue(soulAttributeConfig.Value * (1 + data.viceAdd[i]), data.quality))}[/color]"); } return sb.ToString(); } public void Destroy() { this.selectedId.Clear(); StarSoulBagUI.clickEvent -= OnBagUIClick; } } }