CTT/Unity/Assets/HotfixView/UI/RefreshEquipUI/RefreshEquipUI.cs

211 lines
7.3 KiB
C#

using Cal.DataTable;
using ET;
using FairyGUI;
using System;
using static ET.C2M_MakeMunalEquip;
namespace ET
{
public class RefreshEquipUIAwakeSyatem : AwakeSystem<RefreshEquipUI>
{
public override void Awake(RefreshEquipUI self)
{
self.Awake();
}
}
public class RefreshEquipUIDestroySyatem : DestroySystem<RefreshEquipUI>
{
public override void Destroy(RefreshEquipUI self)
{
self.Destroy();
}
}
public class RefreshEquipUI : Entity
{
public FUI_RefreshEquipUI ui;
private int bagIndex;
private ClientItemData data;
private Window window;
enum RefreshType { Main, Affix }
private RefreshType refreshType;
private string lastStr;
private Scene zoneScene;
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_RefreshEquipUI>();
AwakeAsync().Coroutine();
window = ui.GetComponent<FUIWindowComponent>().Window;
}
private async ETVoid AwakeAsync()
{
refreshType = RefreshType.Main;
ui.m_comType.self.selectedIndex = (int)refreshType;
ui.m_btnEquip.self.icon = null;
lastStr = null;
bagIndex = 1;
ui.m_comType.self.onChanged.Set1(concent =>
{
if (!int.TryParse(ui.m_comType.self.value, out int index)) return;
refreshType = (RefreshType)index;
ShowBefore();
});
ui.m_btnEquip.self.onDrop.Set1(context =>
{
if (context.data is UIDragArgs args)
{
int index = args.index;
args.Release();
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(index, out data))
{
if (data.ItemType != ItemType.EquipItem)
{
TipHelper.OpenUI("只能对装备进行洗练!");
return;
}
bagIndex = index;
EquipBase equipBase = DataTableHelper.Get<EquipBase>(data.ItemId);
ui.m_btnEquip.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, equipBase.IconName.ToString());
ShowBefore();
}
}
});
ui.m_btnMake.self.onClick.Set(async () =>
{
if (bagIndex == -1) return;
window.ShowModalWait(1);
switch (refreshType)
{
case RefreshType.Main:
{
M2C_RefreshEquipMainAttribute ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_RefreshEquipMainAttribute>(new C2M_RefreshEquipMainAttribute { bagIndex = bagIndex });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
window.CloseModalWait(1);
return;
}
}
break;
case RefreshType.Affix:
{
M2C_RefreshEquipAffix ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_RefreshEquipAffix>(new C2M_RefreshEquipAffix { bagIndex = bagIndex });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
window.CloseModalWait(1);
return;
}
}
break;
default:
break;
}
End().Coroutine();
});
await ETTask.CompletedTask;
}
private async ETVoid End()
{
await TimerComponent.Instance.WaitAsync(1000);
M2C_GetBag getBag = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetBag>(new C2M_GetBag());
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = getBag.BagMapList,
});
if(lastStr!=null)
ui.m_txtBefore.text = lastStr;
ShowAfter();
window.CloseModalWait(1);
}
private void ShowBefore()
{
if (!ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(bagIndex, out data))
{
return;
}
Equip equip = data.Equip;
string str = "";
switch (refreshType)
{
case RefreshType.Main:
ShowAttribute(ref str, equip);
break;
case RefreshType.Affix:
ShowAffixAttribute(ref str, equip);
break;
default:
break;
}
ui.m_txtBefore.text = str;
}
private void ShowAfter()
{
if (!ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(bagIndex, out data))
{
return;
}
Equip equip = data.Equip;
string str = "";
switch (refreshType)
{
case RefreshType.Main:
ShowAttribute(ref str, equip);
break;
case RefreshType.Affix:
ShowAffixAttribute(ref str, equip);
break;
default:
break;
}
ui.m_txtAfter.text = str;
lastStr = str;
}
private void ShowAttribute(ref string str, Equip equip)
{
if (equip.mainAttribute.Count == 0)
{
str = "无法洗练";
return;
}
EquipBase equipBase = EquipBaseCategory.Instance.Get(equip.EquipId);
foreach (var kv in equip.mainAttribute)
{
float value = TabHelper.GetValueFromConfig((Cal.AttributeType)kv.Key, equipBase);
str += $"{TabHelper.GetAttributeString((Cal.AttributeType)kv.Key,value,1+kv.Value)}{TabHelper.GetPercent(kv.Value)}\n";
}
}
private void ShowAffixAttribute(ref string str, Equip equip)
{
if (equip.addtionalAttributes.Count == 0)
{
str = "无词缀";
return;
}
foreach (int affixId in equip.addtionalAttributes)
{
EquipAffixConfig equipAffixConfig = EquipAffixConfigCategory.Instance.Get(affixId);
if (equipAffixConfig != null)
{
foreach (EquipAffixConfig.Affix affix in equipAffixConfig.AffixArr)
{
str += $"{TabHelper.GetAttributeString((Cal.AttributeType)affix.Key, affix.Value)}\n";
}
}
str += "---------------------\n";
}
}
public void Destroy()
{
}
}
}