using Cal.DataTable; using ET; using FairyGUI; using System; using System.Collections.Generic; using Equip = ET.Equip; namespace ET { public class ConsignmentUIAwakeSyatem : AwakeSystem, int> { public override void Awake(ConsignmentUI self, List map, int totalPage) { self.Awake(map, totalPage); } } public class ConsignmentUIDestroySyatem : DestroySystem { public override void Destroy(ConsignmentUI self) { self.Destroy(); } } public class ConsignmentUI : Entity { public FUI_ConsignmentUI ui; public int totalPage; public List consignMapList; private Scene zoneScene; public void Awake(List map, int totalPage) { zoneScene = this.ZoneScene(); ui = GetParent(); this.consignMapList = map; this.totalPage = totalPage; AwakeAsync().Coroutine(); } private async ETVoid AwakeAsync() { //!+临时变量 int itemTypeIndex = 0, jobTypeIndex = 0; int currPage = 0; ShowListItem(ui, currPage, totalPage, consignMapList); //!+出售按钮点击事件 ui.m_btnSell.self.onClick.Set(() => { //!临时变量 int selectedIndexInBag = -1; ClientItemData data = null; //!打开背包 //!打开输入窗口 if (!(FUIComponent.Instance.Get(FUIPackage.Consignment_ConsignmentPutInUI) is FUI_ConsignmentPutInUI inputUI)) { inputUI = FUI_ConsignmentPutInUI.CreateInstance(this.ui); inputUI.Name = FUIPackage.Consignment_ConsignmentPutInUI; FUIComponent.Instance.Add(inputUI, true); } FUIWindowComponent inputUIwindow = inputUI.GetOrAddComponent(); if (inputUIwindow.IsShowing) return; inputUIwindow.Show(); //ui.m_Effect.Play(); inputUIwindow.Window.Center(); //!设置图标为空白 inputUI.m_btnSlot.self.icon = null; //!物品放入事件 inputUI.m_btnSlot.self.onDrop.Set1(content => { if (content.data is UIDragArgs args) { int index = args.index; args.Release(); selectedIndexInBag = index; if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(index, out data)) { inputUI.m_btnSlot.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, BagHelper.GetIconName(data.ItemId).Item2); } } }); //!确实出售按钮点击事件 inputUI.m_btnSure.self.onClick.Set(async () => { if (data == null) return; if (!int.TryParse(inputUI.m_inpCount.text, out int count)) return; if (count <= 0) return; if (data.ItemType == ItemType.EquipItem) { if (count != 1) { FUI_TipUI tipUI = TipHelper.OpenUI("只能寄售【1个】装备!"); return; } } if (!long.TryParse(inputUI.m_inpGold.text, out long gold)) return; if (gold < 1000 || gold > long.MaxValue) { FUI_TipUI tipUI = TipHelper.OpenUI("出售价格最低【1000星币】!"); return; } long price = gold; M2C_PutInConsignment ret = await zoneScene.GetComponent().Call(new C2M_PutInConsignment { Index = selectedIndexInBag, Count = count, Price = price, Pwd = inputUI.m_inpPwd.text }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list = ret.BagMapList }); }); }); //!+购买按钮点击事件 ui.m_btnBuy.self.onClick.Set(() => { if (!ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(ui.m_itemList.selectedIndex, out ConsignmentItemData data)) { return; } string pwd = string.Empty; if (data.isNeedPwd) { FUI_TipUI tip = TipHelper.OpenUI("请输入密码:", true, TipType.DoubleInput); tip.m_btnYes.self.onClick.Clear(); tip.m_btnYes.self.onClick.Add(() => { pwd = tip.m_IptTxt.text; SendProto(data, pwd); }); return; } SendProto(data,pwd); async void SendProto(ConsignmentItemData _data, string _pwd) { M2C_BuyInConsignment ret = await zoneScene.GetComponent().Call(new C2M_BuyInConsignment { ConsignmentId = _data.Id, Pwd = _pwd }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list = ret.BagMapList }); } }); //!+点击物品类型下拉框事件 ui.m_ComboItemType.self.onChanged.Set1(async concent => { if (!int.TryParse(ui.m_ComboItemType.self.value, out int index)) return; itemTypeIndex = index; await SendGetConsigbmentProto(); }); //!+点击职业类型下拉框事件 ui.m_ComboJobType.self.onChanged.Set1(async concent => { if (!int.TryParse(ui.m_ComboJobType.self.value, out int index)) return; jobTypeIndex = index; await SendGetConsigbmentProto(); }); //!+切换页数按钮事件 ui.m_btnLastPage.self.onClick.Set(async () => { if (currPage-- <= 0) { currPage = 0; return; } await SendGetConsigbmentProto(); }); ui.m_btnNextPage.self.onClick.Set(async () => { if (currPage++ >= totalPage - 1) { currPage = totalPage - 1; return; } await SendGetConsigbmentProto(); }); async ETTask SendGetConsigbmentProto() { M2C_GetConsignment ret = await zoneScene.GetComponent().Call(new C2M_GetConsignment { ItemType = (ItemType)(itemTypeIndex), JobType = (JobType)(jobTypeIndex), Page = currPage }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } ShowListItem(ui, currPage, ret.TotalPage, ret.ConsignMapList); } await ETTask.CompletedTask; } private void ShowListItem(FUI_ConsignmentUI ui, int currPage, int totalPage, List consignMapList) { //!页码 ui.m_txtPage.text = $"{currPage + 1}/{totalPage}"; ui.m_itemList.RemoveChildrenToPool(); //!显示列表 int consignMapIndex = 0; foreach (ConsignMap consignMap in consignMapList) { int temp = consignMapIndex++; //!添加数据 if (!ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(temp, out ConsignmentItemData data)) { data = EntityFactory.CreateWithParent(ClientItemDataComponent.Instance); ClientItemDataComponent.Instance.ConsignmentDic.Add(temp, data); } NetItem item = consignMap.Item; data.Id = consignMap.ConsignItemId; data.ItemId = item.ItemId; data.ItemType = item.ItemType; data.Count = item.Count; data.isNeedPwd = consignMap.NeedPwd; if (data.ItemType == ItemType.EquipItem) { //!装备赋值 data.Equip = new Equip(consignMap.EquipTransMessage); } GButton btn = ui.m_itemList.AddItemFromPool().asButton; FUI_ButtonConsignmentItem btnitem = FUI_ButtonConsignmentItem.GetFormPool(this.ui, btn); //!显示页签 btn.onRollOver.Set(() => { if (ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(temp, out ConsignmentItemData __data)) { TabHelper.OpenUI(zoneScene,__data); } }); //!隐藏页签 btn.onRollOut.Set(TabHelper.HideUI); string itemName = null, itemIcon = null; IConfig itemBase = BagHelper.GetItemBase(consignMap.Item.ItemId); switch (itemBase) { case EquipBase equipBase: itemName = equipBase.Name; itemIcon = equipBase.IconName; btnitem.m_txtLevel.text = equipBase.UseLevel.ToString(); break; case GoodsBase goodsBase: itemName = goodsBase.Name; itemIcon = goodsBase.IconName; btnitem.m_txtLevel.text = "1"; break; case MaterialBase materialBase: itemName = materialBase.Name; itemIcon = materialBase.IconName; btnitem.m_txtLevel.text = "1"; break; } btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, itemIcon); btnitem.m_txtName.text = itemName; btnitem.m_txtTime.text = (DateTimeOffset.FromUnixTimeMilliseconds(consignMap.RemainTime).DateTime - DateTime.UtcNow).ToString("hh\\:mm"); btnitem.m_txtPrice.text = $"{consignMap.Price:###,###}星币"; btnitem.m_txtSeller.text = consignMap.Name; btnitem.m_txtCount.text = consignMap.Item.Count == 1 ? null : consignMap.Item.Count.ToString(); } } public void Destroy() { } } }