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

356 lines
16 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
2021-05-01 22:06:12 +08:00
using ET.EventType;
2021-04-08 20:09:59 +08:00
namespace ET
{
public class BagUIAwakeSyatem : AwakeSystem<BagUI>
{
public override void Awake(BagUI self)
{
self.Awake();
}
}
public class BagUIDestroySyatem : DestroySystem<BagUI>
{
public override void Destroy(BagUI self)
{
self.Destroy();
}
}
public class BagUI : Entity
{
public const int ExpId = 110201;
public const int YuanBaoId = 110202;
public const int CoinId = 110203;
public const int VoucherId = 110204;
public const int GemId = 110205;
private FUI_BagUI bagUI;
private int _dragIndex;
private bool isSplit;
public static bool isMulti;
private Scene zoneScene;
2021-04-08 20:09:59 +08:00
public void Awake()
{
bagUI = GetParent<FUI_BagUI>();
zoneScene = this.ZoneScene();
2021-04-08 20:09:59 +08:00
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
isSplit = bagUI.m_btnSlipt.self.selected;
isMulti = bagUI.m_btnMulti.self.selected;
//!+获取背包数据
{
M2C_GetBag m2cGetBag = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetBag>(new C2M_GetBag());
2021-04-08 20:09:59 +08:00
if (!m2cGetBag.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(m2cGetBag.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = m2cGetBag.BagMapList
});
}
//!+添加事件
{
int listCount = bagUI.m_slotList.numChildren;
for (int index = 0; index < listCount; index++)
{
GButton btn = bagUI.m_slotList.GetChildAt(index).asButton;
int temp = index;
//!显示页签
#if UNITY_STANDALONE
btn.onRollOver.Set(() =>
{
2021-04-11 19:50:39 +08:00
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
2021-04-08 20:09:59 +08:00
{
TabHelper.OpenUI(data);
}
});
//!隐藏页签
btn.onRollOut.Set(TabHelper.HideUI);
#endif
//!删除、拆分、使用
btn.onClick.Set1(async context =>
{
#if UNITY_STANDALONE
if (isSplit)
{
//!拆分
if (context.inputEvent.isDoubleClick)
{
2021-04-11 19:50:39 +08:00
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要拆分走的数量:", tipType: TipType.DoubleInput);
2021-04-08 20:09:59 +08:00
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;
M2C_SplitItem ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SplitItem>(new C2M_SplitItem() { Index = temp, Count = count });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
}
}
}
}
else
#endif
{
//!双击使用
if (context.inputEvent.isDoubleClick)
{
if (zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight)
2021-04-08 20:09:59 +08:00
{
TipHelper.OpenUI("战斗中,不能使用!");
return;
}
2021-04-11 19:50:39 +08:00
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
2021-04-08 20:09:59 +08:00
{
if (data.ItemType == ItemType.EquipItem)
{
M2C_PutOn ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_PutOn>(new C2M_PutOn() { Index = temp });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
Game.EventSystem.Publish(new ET.EventType.UpdateWornEquipUI
{
list = ret.WornBagMapList
}).Coroutine();
}
else if (data.ItemType == ItemType.GoodsItem)
{
M2C_UseGoods ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_UseGoods>(new C2M_UseGoods() { Index = temp });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
{
list = ret.MainUISlotList
}).Coroutine();
}
}
}
#if !UNITY_STANDALONE
else
{
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out var data))
{
TabHelper.OpenUI(data);
}
}
#endif
}
});
#if UNITY_STANDALONE
//!右键
btn.onRightClick.Set1(async context =>
{
if (context.inputEvent.isDoubleClick)
{
if (zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight)
2021-04-08 20:09:59 +08:00
{
TipHelper.OpenUI("战斗中,不能使用!");
return;
}
2021-04-11 19:50:39 +08:00
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
2021-04-08 20:09:59 +08:00
{
if (data.ItemType != ItemType.NoneItem)
{
StoreUI storeUI = FUIComponent.Instance.Get(FUIPackage.Bag_StoreUI)?.GetComponent<StoreUI>();
if (storeUI != null)
{
if (isMulti)
await storeUI.SendPutProto(temp, data.Count);
else
await storeUI.SendPutProto(temp, 1);
}
else
{
ShopUI shopUI = FUIComponent.Instance.Get(FUIPackage.Shop_ShopUI)?.GetComponent<ShopUI>();
if (shopUI != null)
await ShopUI.SendPutProto(this.zoneScene, temp, 1);
2021-04-08 20:09:59 +08:00
else
{
MarketUI marketUI = FUIComponent.Instance.Get(FUIPackage.Shop_MarketUI)?.GetComponent<MarketUI>();
if (marketUI != null)
await ShopUI.SendPutProto(zoneScene,temp, 1);
2021-04-08 20:09:59 +08:00
}
}
}
}
}
});
#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.Bag, temp));//控制拖拽加载器中的图标
_dragIndex = temp;
});
//!Drop
btn.onDrop.Set1(async context =>
{
if (!(context.data is UIDragArgs args)) return;
if (args.uiType == UIDragArgs.UIType.Bag)
{
args.Release();
2021-04-11 19:50:39 +08:00
if (!ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(_dragIndex, out ClientItemData data))
2021-04-08 20:09:59 +08:00
return;
if (data.ItemType == ItemType.NoneItem)
return;
if (_dragIndex == temp) return;
M2C_ChangeItemPos ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ChangeItemPos>(new C2M_ChangeItemPos() { Pos1 = _dragIndex, Pos2 = temp });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
}
else if (args.uiType == UIDragArgs.UIType.Store)
{
2021-04-11 19:50:39 +08:00
int storeIndex = args.index;
2021-04-08 20:09:59 +08:00
args.Release();
StoreUI storeUI = FUIComponent.Instance.Get(FUIPackage.Bag_StoreUI)?.GetComponent<StoreUI>();
if (storeUI != null)
await storeUI.PutOutStore(storeIndex);
}
});
}
//!整理背包按钮事件
bagUI.m_btnSort.onClick.Set(async () =>
{
M2C_SortBag ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SortBag>(new C2M_SortBag());
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
});
//!进化按钮
bagUI.m_btnUpgrade.onClick.Set(() =>
{
Game.EventSystem.Publish(new ET.EventType.OpenUpgradeUI
{
zoneScene = bagUI.ZoneScene()
}).Coroutine();
bagUI.GetComponent<FUIWindowComponent>().Window.Right();
});
//!增加代金券
bagUI.m_btnAddVoucher.self.onClick.Set(() =>
{
2021-04-11 19:50:39 +08:00
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要兑换的元宝数量,元宝:代金券=12", tipType: TipType.DoubleInput);
2021-04-08 20:09:59 +08:00
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;
M2C_ChargeVoucher ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ChargeVoucher>(new C2M_ChargeVoucher() { YuanBao = count });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
}
}
});
//!增加金币
bagUI.m_btnAddCoin.self.onClick.Set(() =>
{
2021-04-11 19:50:39 +08:00
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要兑换的星币数量,星币:铜币=110", tipType: TipType.DoubleInput);
2021-04-08 20:09:59 +08:00
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;
M2C_ChargeCoin ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ChargeCoin>(new C2M_ChargeCoin() { Gem = count });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
}
}
});
bagUI.m_btnSlipt.self.onClick.Set(() =>
{
isSplit = bagUI.m_btnSlipt.self.selected;
});
bagUI.m_btnMulti.self.onClick.Set(() =>
{
isMulti = bagUI.m_btnMulti.self.selected;
});
2021-05-01 22:06:12 +08:00
this.bagUI.m_btnStarSoulBag.self.onClick.Set((() =>
{
Game.EventSystem.Publish(new OpenStarSoulBagUI() { zoneScene = this.zoneScene });
}));
2021-04-08 20:09:59 +08:00
//!money
RefreshMoney();
}
}
private void RefreshMoney()
{
NumericComponent num = zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<NumericComponent>();
2021-04-08 20:09:59 +08:00
bagUI.m_txtYunabao.text = $"元宝:{ num.GetAsInt(NumericType.YuanBao)}";
bagUI.m_txtDaijinquan.text = $"代金券:{ num.GetAsInt(NumericType.Voucher)}";
bagUI.m_txtGem.text = $"星币:{MathHelper.RoundToLong(num.Get(NumericType.Gem)):###,###}";
2021-04-11 19:50:39 +08:00
float coin = num.Get(NumericType.Coin);
(long gold, int sliver, int cupper) = TabHelper.GetCoinFormat(MathHelper.RoundToLong(coin));
2021-04-08 20:09:59 +08:00
bagUI.m_txtGold.text = gold + string.Empty;
bagUI.m_txtSliver.text = sliver + string.Empty;
bagUI.m_txtCoin.text = cupper + string.Empty;
}
public void Destroy()
{
}
}
}