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

173 lines
5.8 KiB
C#

using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using Cal.DataTable;
namespace ET
{
public class ShopUIAwakeSyatem : AwakeSystem<ShopUI>
{
public override void Awake(ShopUI self)
{
self.Awake();
}
}
public class ShopUIDestroySyatem : DestroySystem<ShopUI>
{
public override void Destroy(ShopUI self)
{
self.Destroy();
}
}
public class ShopUI : Entity
{
public FUI_ShopUI ui;
private Scene zoneScene;
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_ShopUI>();
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
ui.m_pageList.selectedIndex = 0;
this.ShowItems(0);
ui.m_pageList.onClickItem.Set1(concent =>
{
this.ShowItems(ui.m_pageList.selectedIndex);
});
//!拖拽进
ui.m_slotList.onDrop.Set1(context =>
{
SellItem(context).Coroutine();
});
//!+展示Shop中的Item
await ETTask.CompletedTask;
}
private void ShowItems(int pageIndex)
{
this.ui.m_slotList.RemoveChildrenToPool();
var list = ShopComponent.GetShopBase(this.ui.ZoneScene(), pageIndex);
if (list == null)
return;
int index = 0;
foreach (ShopBase shopBase in list)
{
int temp = index++;
GButton btn = this.ui.m_slotList.AddItemFromPool().asButton;
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, BagHelper.GetIconName(shopBase.ItemId).Item2);
//!显示页签
#if UNITY_STANDALONE
btn.onRollOver.Set(() => TabHelper.OpenUI(shopBase.ItemId, TabHelper.GetAdditionalPrice(shopBase)));
//!隐藏页签
btn.onRollOut.Set(TabHelper.HideUI);
#endif
//!双击购买
btn.onClick.Set1(async content =>
{
if (content.inputEvent.isDoubleClick)
{
#if UNITY_STANDALONE
if (!content.inputEvent.ctrl)
{
await SendBuyProto(1);
return;
}
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您想购买的数量:", tipType: TipType.DoubleInput);
tipUI.m_btnYes.self.onClick.Clear();
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 SendBuyProto(count);
}
}
#else
await SendBuyProto(1);
#endif
async ETTask SendBuyProto(int count)
{
M2C_BuyInShop ret = await this.zoneScene.GetComponent<SessionComponent>().Call<M2C_BuyInShop>(new C2M_BuyInShop { PageIndex = this.ui.m_pageList.selectedIndex, SlotIndex = temp, Count = count });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list = ret.BagMapList });
}
}
#if !UNITY_STANDALONE
else
{
TabHelper.OpenUI(shopBase.ItemId, TabHelper.GetAdditionalPrice(shopBase));
}
#endif
});
}
}
public async ETVoid SellItem(EventContext 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 (!context.inputEvent.ctrl)
{
await SendPutProto(this.zoneScene,bagIndex,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))
{
if (count <= 0) return;
await SendPutProto(this.zoneScene, bagIndex,count);
}
}
#else
await SendPutProto(this.zoneScene,bagIndex,1);
#endif
}
public static async ETTask SendPutProto(Scene zoneScene, int bagIndex,int count)
{
M2C_SellItem ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SellItem>(new C2M_SellItem { SlotIndex = bagIndex, Count = count });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
}
public void Destroy()
{
}
}
}