410 lines
16 KiB
C#
410 lines
16 KiB
C#
|
|
using Cal.DataTable;
|
|
using ET;
|
|
using FairyGUI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class StoreUIAwakeSyatem : AwakeSystem<StoreUI>
|
|
{
|
|
public override void Awake(StoreUI self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
public class StoreUIDestroySyatem : DestroySystem<StoreUI>
|
|
{
|
|
public override void Destroy(StoreUI self)
|
|
{
|
|
self.Destroy();
|
|
}
|
|
}
|
|
public class StoreUI : Entity
|
|
{
|
|
private FUI_StoreUI ui;
|
|
private readonly List<int> _needClearIndex = new List<int>();
|
|
|
|
private int totalPage = 2;
|
|
private const int CountPerPage = 60;
|
|
|
|
private int currPage = 0;
|
|
private Scene zoneScene;
|
|
|
|
public void Awake()
|
|
{
|
|
zoneScene = this.ZoneScene();
|
|
ui = GetParent<FUI_StoreUI>();
|
|
AwakeAsync().Coroutine();
|
|
}
|
|
private async ETVoid AwakeAsync()
|
|
{
|
|
//!临时变量
|
|
|
|
await GetStoreSlot(ui);
|
|
|
|
//!整理
|
|
ui.m_btnSort.self.onClick.Set(async () =>
|
|
{
|
|
M2C_SortStore ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SortStore>(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, () =>
|
|
{
|
|
if (ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(temp, out ClientItemData data))
|
|
{
|
|
TabHelper.OpenUI(zoneScene,data);
|
|
}
|
|
});
|
|
#if UNITY_STANDALONE
|
|
//!右键
|
|
btn.onRightClick.Set1(async context =>
|
|
{
|
|
if (!context.inputEvent.isDoubleClick) return;
|
|
if (zoneScene.GetComponent<UnitComponent>().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<BagUI>();
|
|
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 =>
|
|
{
|
|
//!防止直接拖动该组件
|
|
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<SessionComponent>().Call<M2C_PutCoinInStore>(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<SessionComponent>().Call<M2C_TakeCoinOutStore>(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<SessionComponent>().Call<M2C_QueryExtandPrice>(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<SessionComponent>().Call<M2C_ExtandStore>(new C2M_ExtandStore { });
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
});
|
|
});
|
|
|
|
await ETTask.CompletedTask;
|
|
}
|
|
public async ETTask SendPutProto(int bagIndex, int count)
|
|
{
|
|
M2C_PutInStore ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_PutInStore>(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<SessionComponent>().Call<M2C_GetStore>(new C2M_GetStore() { Page = currPage });
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
{
|
|
TipHelper.OpenUI(ret.Message);
|
|
return;
|
|
}
|
|
totalPage = ret.Total;
|
|
ShowSlot(ui, ret.StoreList, ret.Coin);
|
|
}
|
|
public void ShowSlot(FUI_StoreUI ui, List<BagMap> 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;
|
|
this._needClearIndex.Clear();
|
|
|
|
for (int i = 0; i < totalCount; i++)
|
|
{
|
|
this._needClearIndex.Add(i);
|
|
}
|
|
foreach (BagMap bagMap in storeList)
|
|
{
|
|
int index = bagMap.Index - this.currPage * CountPerPage;
|
|
this._needClearIndex.Remove(index);
|
|
NetItem item = bagMap.NetItem;
|
|
//!添加数据
|
|
if (!ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(index, out ClientItemData data))
|
|
{
|
|
data = EntityFactory.CreateWithParent<ClientItemData>(ClientItemDataComponent.Instance);
|
|
ClientItemDataComponent.Instance.StoreItemDic.Add(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);
|
|
}
|
|
}
|
|
foreach (var kp in ClientItemDataComponent.Instance.StoreItemDic)
|
|
{
|
|
int index = kp.Key;
|
|
if (this._needClearIndex.Contains(index)) continue;
|
|
GButton btn = ui.m_slotList.GetChildAt(index).asButton;
|
|
ClientItemData data = kp.Value;
|
|
//!显示
|
|
switch (data.ItemType)
|
|
{
|
|
default:
|
|
btn.icon = null;
|
|
btn.title = null;
|
|
break;
|
|
case ItemType.EquipItem:
|
|
EquipBase equipBase = DataTableHelper.Get<EquipBase>(data.ItemId);
|
|
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, equipBase.IconName);
|
|
btn.title = data.Count.ToString();
|
|
break;
|
|
case ItemType.GoodsItem:
|
|
GoodsBase goodsBase = DataTableHelper.Get<GoodsBase>(data.ItemId);
|
|
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, goodsBase.IconName);
|
|
btn.title = data.Count.ToString();
|
|
break;
|
|
case ItemType.MaterialsItem:
|
|
MaterialBase materialBase = DataTableHelper.Get<MaterialBase>(data.ItemId);
|
|
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, materialBase.IconName);
|
|
btn.title = data.Count.ToString();
|
|
break;
|
|
}
|
|
}
|
|
//!对后面的格子进行处理
|
|
foreach (int index in this._needClearIndex)
|
|
{
|
|
//!数据
|
|
if (!ClientItemDataComponent.Instance.StoreItemDic.TryGetValue(index, out ClientItemData data))
|
|
{
|
|
data = EntityFactory.CreateWithParent<ClientItemData>(ClientItemDataComponent.Instance);
|
|
ClientItemDataComponent.Instance.StoreItemDic.Add(index, data);
|
|
}
|
|
data.ItemType = ItemType.NoneItem;
|
|
//!显示
|
|
GButton realbtn = ui.m_slotList.GetChildAt(index).asButton;
|
|
realbtn.icon = null;
|
|
realbtn.title = null;
|
|
}
|
|
|
|
}
|
|
|
|
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<SessionComponent>().Call<M2C_TakeOffStore>(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()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|