211 lines
8.1 KiB
C#
211 lines
8.1 KiB
C#
using Cal.DataTable;
|
|
using ET;
|
|
using FairyGUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ET
|
|
{
|
|
public struct EquipForgeMaterialInfo
|
|
{
|
|
public string name;
|
|
public int count;
|
|
public int needCount;
|
|
}
|
|
public class ForgeUIAwakeSyatem : AwakeSystem<ForgeUI>
|
|
{
|
|
public override void Awake(ForgeUI self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
public class ForgeUIDestroySyatem : DestroySystem<ForgeUI>
|
|
{
|
|
public override void Destroy(ForgeUI self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
public class ForgeUI : Entity
|
|
{
|
|
private const int Max_FogeItemCount_Per_Page = 10;
|
|
private static EquipForge[] equipForgeArr;
|
|
|
|
private FUI_ForgeUI ui;
|
|
private Scene zoneScene;
|
|
|
|
public void Awake()
|
|
{
|
|
zoneScene = this.ZoneScene();
|
|
ui = GetParent<FUI_ForgeUI>();
|
|
AwakeAsync().Coroutine();
|
|
}
|
|
private async ETVoid AwakeAsync()
|
|
{
|
|
//!+临时变量
|
|
int currPage = 0, totalPage = 0;
|
|
JobType currJobType = JobType.UnKnown;
|
|
|
|
ui.m_pageList.selectedIndex = (int)currJobType;
|
|
|
|
equipForgeArr = equipForgeArr ?? DataTableHelper.GetAll<EquipForge>().ToArray();
|
|
totalPage = equipForgeArr.Length / Max_FogeItemCount_Per_Page + 1;
|
|
|
|
ShowForgeItemList(ui, currPage, currJobType);
|
|
//!+切换页数按钮事件
|
|
ui.m_btnLast.self.onClick.Set(() =>
|
|
{
|
|
if (currPage-- <= 0)
|
|
{
|
|
currPage = 0;
|
|
return;
|
|
}
|
|
ShowForgeItemList(ui, currPage, currJobType);
|
|
});
|
|
ui.m_btnNext.self.onClick.Set(() =>
|
|
{
|
|
if (currPage++ >= totalPage - 1)
|
|
{
|
|
currPage = totalPage - 1;
|
|
return;
|
|
}
|
|
ShowForgeItemList(ui, currPage, currJobType);
|
|
});
|
|
//!+切换页签事件
|
|
ui.m_pageList.onClickItem.Set(() =>
|
|
{
|
|
currJobType = (JobType)ui.m_pageList.selectedIndex;
|
|
ShowForgeItemList(ui, currPage, currJobType);
|
|
});
|
|
await ETTask.CompletedTask;
|
|
}
|
|
/// <summary>
|
|
/// 显示打造列表
|
|
/// </summary>
|
|
/// <param name="ui"></param>
|
|
/// <param name="currPage">当前页码</param>
|
|
/// <param name="currJobType">当前职业类型 0=全部 1=军官 2=运动员 3=护士 4=超能力</param>
|
|
private static void ShowForgeItemList(FUI_ForgeUI ui, int currPage, JobType currJobType)
|
|
{
|
|
var bagDic = ClientItemDataComponent.Instance.ItemDic;
|
|
int index = -1, count = Max_FogeItemCount_Per_Page, filterItemCount = 0;
|
|
ui.m_itenList.RemoveChildrenToPool();
|
|
foreach (EquipForge equipForge in equipForgeArr)
|
|
{
|
|
if (!(BagHelper.GetItemBase(equipForge.MadeEquipId) is EquipBase equipBase))
|
|
{
|
|
Log.Error($"item is not equip where id = {equipForge.MadeEquipId}");
|
|
continue;
|
|
}
|
|
if (equipBase.JobId != (int)currJobType) continue;
|
|
filterItemCount++;
|
|
if (count <= 0) continue;
|
|
index++;
|
|
if (((index - currPage * Max_FogeItemCount_Per_Page) | (((currPage + 1) * Max_FogeItemCount_Per_Page) - index - 1)) < 0) continue;
|
|
|
|
List<EquipForgeMaterialInfo> needMaterialInfoList = new List<EquipForgeMaterialInfo>();
|
|
GObject label = ui.m_itenList.AddItemFromPool();
|
|
FUI_LabelForgeItem labelItem = FUI_LabelForgeItem.GetFormPool(ui,label);
|
|
bool hasMaterial = true;
|
|
//!判断装备
|
|
if (equipForge.NeedEquipmentId != 0)
|
|
{
|
|
int equipCount = 0;
|
|
if (!bagDic.TryGetValueByKey2(equipForge.NeedEquipmentId, out var itemList) || itemList.Count == 0)
|
|
{
|
|
hasMaterial = false;
|
|
}
|
|
else
|
|
{
|
|
equipCount = 1;
|
|
}
|
|
needMaterialInfoList.Add(new EquipForgeMaterialInfo
|
|
{
|
|
name = BagHelper. GetIconName(equipForge.NeedEquipmentId).Item1,
|
|
count = equipCount,
|
|
needCount = 1,
|
|
});
|
|
}
|
|
//!判断材料
|
|
for (int i = equipForge.NeedMaterialArr.Length - 1; i >= 0; i--)
|
|
{
|
|
int materialCount = 0;
|
|
EquipForge.NeedMaterial needMaterial = equipForge.NeedMaterialArr[i];
|
|
if (!bagDic.TryGetValueByKey2(needMaterial.NeedMaterial_Id, out var itemList) || itemList.Count == 0)
|
|
{
|
|
hasMaterial = false;
|
|
}
|
|
else
|
|
{
|
|
foreach (ClientItemData item in itemList)
|
|
{
|
|
//if (materialCount >= needMaterial.NeedMaterialCount) break;
|
|
materialCount += item.Count;
|
|
}
|
|
if (materialCount < needMaterial.NeedMaterial_Count)
|
|
{
|
|
hasMaterial = false;
|
|
}
|
|
|
|
}
|
|
needMaterialInfoList.Add(new EquipForgeMaterialInfo
|
|
{
|
|
name = BagHelper. GetIconName(needMaterial.NeedMaterial_Id).Item1,
|
|
count = materialCount,
|
|
needCount = needMaterial.NeedMaterial_Count,
|
|
});
|
|
}
|
|
//!判断钱
|
|
var zoneScene = ui.ZoneScene();
|
|
Unit unit = zoneScene.GetComponent<UnitComponent>().MyUnit;
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
|
if (num.Get(NumericType.Coin) < equipForge.NeedCoin)
|
|
{
|
|
hasMaterial = false;
|
|
}
|
|
|
|
labelItem.m_loaderIcon.icon = UIPackage.GetItemURL(FUIPackage.Bag, equipBase.IconName);
|
|
labelItem.m_loaderIcon.onClick.Clear();
|
|
labelItem.m_txtName.text = equipBase.Name;
|
|
labelItem.m_txtLevel.text = equipBase.UseLevel + "";
|
|
(long gold, int sliver, int coin) = TabHelper.GetCoinFormat(equipForge.NeedCoin);
|
|
labelItem.m_txtGold.text = "" + gold;
|
|
labelItem.m_txtSliver.text = "" + sliver;
|
|
labelItem.m_txtCoin.text = "" + coin;
|
|
//!将按钮设置为可以点击
|
|
if (hasMaterial)
|
|
{
|
|
labelItem.m_canForge.selectedIndex = 1;
|
|
int equipForgeId = (int)equipForge.Id;
|
|
labelItem.m_btnForge.onClick.Set(async () =>
|
|
{
|
|
M2C_ForgeEquip ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ForgeEquip>(new C2M_ForgeEquip { Id = equipForgeId });
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
|
|
{
|
|
list=ret.BagMapList
|
|
});
|
|
});
|
|
}
|
|
else
|
|
labelItem.m_canForge.selectedIndex = 0;
|
|
|
|
//!显示页签
|
|
TabHelper.SetTab(labelItem.m_loaderIcon, () => TabHelper.OpenEquipForgeUI(equipForge.MadeEquipId, needMaterialInfoList));
|
|
count--;
|
|
}
|
|
ui.m_txtPage.text = $"{currPage + 1}/{filterItemCount / Max_FogeItemCount_Per_Page + 1}";
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|