using Cal.DataTable; using ET; using FairyGUI; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ET { public class StoreUIAwakeSyatem : AwakeSystem { public override void Awake(StoreUI self) { self.Awake(); } } public class StoreUIDestroySyatem : DestroySystem { public override void Destroy(StoreUI self) { self.Destroy(); } } public class StoreUI : Entity { private FUI_StoreUI ui; private int totalPage = 2; private const int CountPerPage = 60; private int currPage = 0; private Scene zoneScene; private StringBuilder sb = new StringBuilder(); public void Awake() { zoneScene = this.ZoneScene(); ui = GetParent(); AwakeAsync().Coroutine(); } private async ETVoid AwakeAsync() { //!临时变量 await GetStoreSlot(ui); //!整理 ui.m_btnSort.self.onClick.Set(async () => { M2C_SortStore ret = await zoneScene.GetComponent().Call(new C2M_SortStore { Page = currPage }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } ShowSlot(ui, ret.StoreList); }); //!拖拽进仓库 ui.m_slotList.onDrop.Set1(async context => { if (!(context.data is UIDragArgs args)) return; if (args.uiType != UIDragArgs.UIType.Bag) return; int bagIndex = args.index; args.Release(); #if UNITY_STANDALONE if (!BagUI.isMulti) { await SendPutProto(bagIndex,1); return; } FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要存储的数量:", tipType: TipType.DoubleInput); tipUI.m_btnYes.self.onClick.Set(TipYesCallBack); tipUI.AddEventCallBack(TipYesCallBack); async void TipYesCallBack() { if (int.TryParse(tipUI.m_IptTxt.text, out int count)) { if (count <= 0) return; await SendPutProto(bagIndex,count); } } #else if (!BagUI.isMulti) await SendPutProto(bagIndex, 1); else { var tipUI = TipHelper.OpenUI("请输入您要放出的数量:", tipType: TipType.DoubleInput); tipUI.m_btnYes.self.onClick.Clear(); tipUI.m_btnYes.self.onClick.Add(TipYesCallBack); tipUI.AddEventCallBack(TipYesCallBack); async void TipYesCallBack() { if (int.TryParse(tipUI.m_IptTxt.text, out int count)) { if (count <= 0) return; await SendPutProto(bagIndex, count); } } } #endif }); int listCount = ui.m_slotList.numChildren; for (int index = 0; index < listCount; index++) { GButton btn = ui.m_slotList.GetChildAt(index).asButton; btn.onClick.Clear(); int temp = index; //!显示页签 TabHelper.SetTab(btn, () => { int _temp =temp + this.currPage*CountPerPage; if (ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(_temp, out ClientItemData data)) { TabHelper.OpenUI(zoneScene,data); } }); #if UNITY_STANDALONE //!右键 btn.onRightClick.Set1(async context => { int _temp =temp + this.currPage*CountPerPage; if (!context.inputEvent.isDoubleClick) return; if (zoneScene.GetComponent().MyUnit.IsFight) { TipHelper.OpenUI("战斗中,不能使用!"); return; } if (!ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(_temp, out ClientItemData data)) return; if (data.ItemType == ItemType.NoneItem) return; var bagUI = FUIComponent.Instance.Get(FUIPackage.Bag_BagUI)?.GetComponent(); if (bagUI == null) return; if (BagUI.isMulti) await SendPutOutProto(temp, data.Count); else await SendPutOutProto(temp, 1); }); #endif //!拖拽 btn.draggable = true; btn.onDragStart.Set1(context => { int _temp =temp + this.currPage*CountPerPage; //!防止直接拖动该组件 context.PreventDefault(); //if (!context.inputEvent.ctrl) return; DragDropManager.inst.StartDrag(btn, btn.icon, UIDragArgs.Create(UIDragArgs.UIType.Store, _temp));//!控制拖拽加载器中的图标 }); } //!+切换页数按钮事件 ui.m_btnLast.self.onClick.Set(async () => { if (currPage-- <= 0) { currPage = 0; return; } await GetStoreSlot(ui); }); ui.m_btnNext.self.onClick.Set(async () => { if (currPage++ >= totalPage - 1) { currPage = totalPage - 1; return; } await GetStoreSlot(ui); }); //!+存钱 ui.m_btnSaveCoin.self.onClick.Set(() => { FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要存储的铜钱数量:", tipType: TipType.DoubleInput); tipUI.m_btnYes.self.onClick.Set(TipYesCallBack); tipUI.AddEventCallBack(TipYesCallBack); async void TipYesCallBack() { if (!long.TryParse(tipUI.m_IptTxt.text, out long count)) return; if (count <= 0) return; await SendPutProto(count); } async ETTask SendPutProto(long count) { M2C_PutCoinInStore ret = await zoneScene.GetComponent().Call(new C2M_PutCoinInStore { Coin = count }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } ShowSlot(ui, null, ret.Coin); } }); //!+取钱 ui.m_btnGetCoin.self.onClick.Set(() => { FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要取出的铜钱数量:", tipType: TipType.DoubleInput); tipUI.m_btnYes.self.onClick.Set(TipYesCallBack); tipUI.AddEventCallBack(TipYesCallBack); async void TipYesCallBack() { if (!long.TryParse(tipUI.m_IptTxt.text, out long count)) return; if (count <= 0) return; await SendPutProto(count); } async ETTask SendPutProto(long count) { M2C_TakeCoinOutStore ret = await zoneScene.GetComponent().Call(new C2M_TakeCoinOutStore { Coin = count }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } ShowSlot(ui, null, ret.Coin); } }); //!+扩展 ui.m_btnExtand.self.onClick.Set(async () => { M2C_QueryExtandPrice query = await zoneScene.GetComponent().Call(new C2M_QueryExtandPrice { }); if (!query.Message.IsNullOrEmpty()) { TipHelper.OpenUI(query.Message); return; } string str = null; str = query.Coin != 0 ? $"是否花费{query.Coin / 10000}金币扩展仓库!" : $"是否花费{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_ExtandStore ret = await zoneScene.GetComponent().Call(new C2M_ExtandStore { }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } }); }); //search ui.m_btnSearch.self.onClick.Set(() => { string searchName = this.ui.m_iptSearch.text; if(searchName.IsNullOrEmpty()) return; int count = 0; this.sb.Clear(); foreach (var kv in ClientItemDataComponent.Instance.StoreItemDic) { var itemData = kv.Value; if (itemData.ItemId==0) { continue; } var itemName=BagHelper.GetIconName(itemData.ItemId).Item1; if (itemName.Contains(searchName)) { sb.Append($"第{kv.Key / CountPerPage + 1}页 第{kv.Key%CountPerPage+1}个格子 : {itemName}\n"); if (count++ > 30) { sb.Append("此关键字物品过多,无法显示"); break; } } } TipHelper.OpenUI(sb.ToString()); }); await ETTask.CompletedTask; } public async ETTask SendPutProto(int bagIndex, int count) { M2C_PutInStore ret = await zoneScene.GetComponent().Call(new C2M_PutInStore { BagIndex = bagIndex, Count = count, Page = currPage }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list =ret.BagMapList }); ShowSlot(ui, ret.StoreList); } private async ETTask GetStoreSlot(FUI_StoreUI ui) { M2C_GetStore ret = await zoneScene.GetComponent().Call(new C2M_GetStore() { Page = currPage }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } totalPage = ret.Total; ShowSlot(ui, ret.StoreList, ret.Coin); } private void ShowSlot(FUI_StoreUI ui, List storeList, long coinCount = -1) { ui ??= FUIComponent.Instance.Get(FUIPackage.Bag_StoreUI) as FUI_StoreUI; ui.m_txtPage.text = $"{currPage + 1}/{totalPage}"; if (coinCount != -1) { (long gold, int sliver, int coin) = TabHelper.GetCoinFormat(coinCount); ui.m_txtGold.text = "" + gold; ui.m_txtSliver.text = "" + sliver; ui.m_txtCoin.text = "" + coin; } if (storeList == null) { return; } int totalCount = ui.m_slotList.numItems; int startIndex = this.currPage * CountPerPage; for (int i = startIndex; i < startIndex+CountPerPage; i++) { ClientItemDataComponent.Instance.StoreItemDic.Remove(i); } foreach (BagMap bagMap in storeList) { int index = bagMap.Index; NetItem item = bagMap.NetItem; //!添加数据 if (!ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(index, out ClientItemData data)) { data = EntityFactory.CreateWithParent(ClientItemDataComponent.Instance); ClientItemDataComponent.Instance.StoreItemDic[index] = data; } data.ItemId = item.ItemId; data.ItemType = item.ItemType; data.Count = item.Count; data.IsLock = item.IsLock; if (data.ItemType == ItemType.EquipItem) { //!装备赋值 data.Equip = new ET.Equip(bagMap.EquipTransMessage); } } for (int i = 0; i < totalCount; i++) { var index = startIndex + i; var btn = this.ui.m_slotList.GetChildAt(i).asButton; var dic = ClientItemDataComponent.Instance.StoreItemDic; if (!dic.TryGetValue(index, out ClientItemData data)) { btn.title = null; btn.icon = null; continue; } btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, BagHelper.GetIconName(data.ItemId).Item2); btn.title = data.Count.ToString(); } } public async ETTask PutOutStore(int storeIndex) { if (!BagUI.isMulti) { await SendPutOutProto(storeIndex, 1); return; } FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要取出的数量:", tipType: TipType.DoubleInput); tipUI.m_btnYes.self.onClick.Clear(); tipUI.m_btnYes.self.onClick.Add(TipYesCallBack); tipUI.AddEventCallBack(TipYesCallBack); async void TipYesCallBack() { if (!int.TryParse(tipUI.m_IptTxt.text, out int count)) { return; } if (count <= 0) return; await this.SendPutOutProto(storeIndex, count); } } private async ETTask SendPutOutProto(int index, int count) { M2C_TakeOffStore ret = await zoneScene.GetComponent().Call(new C2M_TakeOffStore { StoreIndex = index, Count = count, Page = currPage }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list=ret.BagMapList }); ShowSlot(null, ret.StoreList); } public void Destroy() { } } }