zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/HotfixView/UI/SkillUI/SkillUI.cs

282 lines
11 KiB
C#

using Cal.DataTable;
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ET
{
public class SkillUIAwakeSyatem : AwakeSystem<SkillUI>
{
public override void Awake(SkillUI self)
{
self.Awake();
}
}
public class SkillUIDestroySyatem : DestroySystem<SkillUI>
{
public override void Destroy(SkillUI self)
{
self.Destroy();
}
}
public class SkillUI : Entity
{
public FUI_SkillUI ui;
private List<int> autoSkillList = new List<int>();
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_SkillUI>();
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
//!+获取技能
M2C_GetSkill getskill = (M2C_GetSkill)await zoneScene.GetComponent<SessionComponent>().Session.Call(new C2M_GetSkill());
if (getskill.Message.IsNullOrEmpty())
{
ShowSkill(this.ui, getskill.SkillInfoLsit);
//!+加载自动技能
int autoSkillNum = ui.m_autoSkillList.numChildren;
if (autoSkillList.Count == 0)
{
for (int j = 0; j < autoSkillNum; j++)
{
autoSkillList.Add(0);
}
}
int index = -1;
foreach (int skillId in getskill.AutoSkillList)
{
index++;
if (skillId == 0) continue;
//SkillConfig skillConfig = DataTableHelper.Get<SkillConfig>(skillId * 100);
//!显示图标
GButton item = this.ui.m_autoSkillList.GetChildAt(index).asButton;
item.icon = UIPackage.GetItemURL(FUIPackage.Skill, skillId + string.Empty);
//!装载数据
autoSkillList[index] = skillId;
}
for (int i = 0; i < autoSkillNum; i++)
{
GButton item = this.ui.m_autoSkillList.GetChildAt(i).asButton;
//!放入(Drop)事件
int temp = i;
item.onDrop.Set1(context =>
{
if (!(context.data is UIDragArgs args)) return;
if (args.uiType == UIDragArgs.UIType.Skill)
{
int skillId = args.index;
args.Release();
autoSkillList[temp] = skillId;
item.icon = DragDropManager.inst.dragAgent.icon;
}
});
//!点击事件
item.onClick.Set(() =>
{
item.icon = null;
if (autoSkillList.Count > 0)
{
autoSkillList[temp] = 0;
}
});
}
//!+保存事件
this.ui.m_btnSave.onClick.Set(async () =>
{
C2M_SaveAutoSkill c2mSaveSkill = new C2M_SaveAutoSkill();
c2mSaveSkill.AutoSkillList.AddRange(autoSkillList);
M2C_SaveAutoSkill saveSKill = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SaveAutoSkill>(c2mSaveSkill);
if (!saveSKill.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(saveSKill.Message);
}
});
this.ui.m_btnFreeReSet.onClick.Set(async () =>
{
string str = $"是否免费重置技能,不返还材料!";
FUI_TipUI tipUI = TipHelper.OpenUI(str, tipType: TipType.Double);
tipUI.m_btnYes.self.onClick.Clear();
tipUI.m_btnYes.self.onClick.Add(async () =>
{
M2C_FreeReSetSkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_FreeReSetSkill>(new C2M_FreeReSetSkill { });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
});
});
ui.m_btnReSet.onClick.Set(async () =>
{
M2C_GetReSetSkillPrice query = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetReSetSkillPrice>(new C2M_GetReSetSkillPrice { });
if (!query.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(query.Message);
return;
}
string str = $"是否花费{query.Voucher}代金券重置技能,返还全部材料!";
FUI_TipUI tipUI = TipHelper.OpenUI(str, tipType: TipType.Double);
tipUI.m_btnYes.self.onClick.Clear();
tipUI.m_btnYes.self.onClick.Add(async () =>
{
M2C_ReSetSkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ReSetSkill>(new C2M_ReSetSkill { });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
});
});
}
await ETTask.CompletedTask;
}
private Dictionary<int, GButton> skillButtonDic = new Dictionary<int, GButton>();
private void ShowSkill(FUI_SkillUI skillUI, List<SkillInfo> infoList)
{
ClientUnitCharacter unitCharacter = ClientUnitCharacterComponent.Instance.Get();
ui.m_txtSkillPoint.text = $"可用技能点: {unitCharacter.SkillPoint}";
GComponent gComponent;
switch (unitCharacter.JobType)
{
default:
case JobType.UnKnown:
gComponent = null;
Log.Error($"{unitCharacter.JobType} is not right");
break;
case JobType.Officer:
{
FUI_Skill_JunGuan ui = skillUI.m_comJob1;
ui.Visible = true;
gComponent = ui.self;
}
break;
case JobType.Sportsman:
{
FUI_Skill_YunDongYuan ui = skillUI.m_comJob2;
ui.Visible = true;
gComponent = ui.self;
}
break;
case JobType.Nurse:
{
FUI_Skill_HuShi ui = skillUI.m_comJob3;
ui.Visible = true;
gComponent = ui.self;
}
break;
case JobType.Superman:
{
FUI_Skill_ChaoNengLi ui = skillUI.m_comJob4;
ui.Visible = true;
gComponent = ui.self;
}
break;
}
if (gComponent == null) return;
foreach (SkillInfo info in infoList)
{
int skillId = info.SkillId;
if (!skillButtonDic.TryGetValue(skillId, out GButton btn))
{
btn = gComponent.GetChild(string.Empty + skillId).asButton;
if (btn == null)
{
Log.Error($"dic not has the key = {skillId}");
continue;
}
skillButtonDic.Add(skillId, btn);
}
btn.onClick.Clear();
//skilldata.SkillId = skillId;
//skilldata.Level = info.SkillLevel;
SkillConfig skillConfig = DataTableHelper.Get<SkillConfig>(skillId * 100);
bool isPre = false;
int tempLevel = info.SkillLevel;
if (tempLevel == 0)
{
isPre = true;
tempLevel = 1;
}
btn.icon = UIPackage.GetItemURL(FUIPackage.Skill, skillId + string.Empty);
btn.grayed = isPre;
//!显示页签
TabHelper.SetTab(btn, () =>
{
if (DragDropManager.inst.dragging) return;
TabHelper.OpenSkilUI(skillConfig, tempLevel, isPre);
});
//!双击
btn.onClick.Add1(async context =>
{
if (!context.inputEvent.isDoubleClick)
return;
M2C_LearnSkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_LearnSkill>(new C2M_LearnSkill { SkillId = skillId });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
});
//!开始拖拽
if (isPre) continue;
btn.draggable = true;
btn.onDragStart.Set1(content =>
{
//防止直接拖动该组件
content.PreventDefault();
content.initiator.As<GButton>().parent.scrollPane.CancelDragging();
//设置拖拽大小
DragDropManager.inst.StartDrag(btn, btn.icon, UIDragArgs.Create(UIDragArgs.UIType.Skill, skillId));//控制拖拽加载器中的图标
});
}
}
private static Queue<FUI_SkillNameUI> skillNameUIQue;
private Scene zoneScene;
/// <summary>
/// 战斗时显示技能名称
/// // by 左倾月 on 2020/6/28 at 9:46
/// </summary>
/// <param name="unit"></param>
/// <param name="skillName"></param>
public static void ShowNameWhenPlaySkill(Unit unit, string skillName)
{
skillNameUIQue = skillNameUIQue ?? new Queue<FUI_SkillNameUI>();
if (skillNameUIQue.Count == 0)
{
FUI_SkillNameUI ui = FUI_SkillNameUI.CreateInstance(FUIComponent.Instance);
FUIComponent.Instance.Add(ui, true);
skillNameUIQue.Enqueue(ui);
}
FUI_SkillNameUI fui = skillNameUIQue.Dequeue();
fui.m_txtName.text = skillName;
fui.Visible = true;
fui.m_Effect.Play(CompelteCallBack);
Vector2 pt = PosHelper.WorldToScreen(unit.GetComponent<UnitView>().HeadPoint.position);
fui.self.SetXY(pt.x, pt.y);
void CompelteCallBack()
{
fui.Visible = false;
skillNameUIQue.Enqueue(fui);
}
}
public void Destroy()
{
}
}
}