CTT/Unity/Assets/HotfixView/UI/BagUI/BagUI.cs

351 lines
16 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using ET.EventType;
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;
public static event Action<int> clickEvent;
public void Awake()
{
bagUI = GetParent<FUI_BagUI>();
zoneScene = this.ZoneScene();
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());
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;
btn.onClick.Clear();
//!删除、拆分、使用
btn.onClick.Set1(async context =>
{
#if UNITY_STANDALONE
if (isSplit)
{
//!拆分
if (context.inputEvent.isDoubleClick)
{
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;
M2C_SplitItem ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_SplitItem>(new C2M_SplitItem() { Index = temp, Count = count });
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)
{
TipHelper.OpenUI("战斗中,不能使用!");
return;
}
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
{
if (data.ItemType == ItemType.EquipItem)
{
M2C_PutOn ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_PutOn>(new C2M_PutOn() { Index = temp });
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 });
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();
}
}
}
else
{
clickEvent?.Invoke(temp);
}
}
});
//!显示页签
TabHelper.SetTab(btn,() =>
{
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
{
TabHelper.OpenUI(zoneScene,data);
}
});
#if UNITY_STANDALONE
//!右键
btn.onRightClick.Set1(async context =>
{
if (context.inputEvent.isDoubleClick)
{
if (zoneScene.GetComponent<UnitComponent>().MyUnit.IsFight)
{
TipHelper.OpenUI("战斗中,不能使用!");
return;
}
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(temp, out ClientItemData data))
{
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);
else
{
MarketUI marketUI = FUIComponent.Instance.Get(FUIPackage.Shop_MarketUI)?.GetComponent<MarketUI>();
if (marketUI != null)
await ShopUI.SendPutProto(zoneScene,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.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();
if (!ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(_dragIndex, out ClientItemData data))
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 });
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)
{
int storeIndex = args.index;
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());
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(() =>
{
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要兑换的元宝数量,元宝:代金券=12", 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;
M2C_ChargeVoucher ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ChargeVoucher>(new C2M_ChargeVoucher() { YuanBao = count });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
}
}
});
//!增加金币
bagUI.m_btnAddCoin.self.onClick.Set(() =>
{
FUI_TipUI tipUI = TipHelper.OpenUI("请输入您要兑换的星币数量,星币:铜币=110", 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;
M2C_ChargeCoin ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ChargeCoin>(new C2M_ChargeCoin() { Gem = count });
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;
});
this.bagUI.m_btnStarSoulBag.self.onClick.Set((() =>
{
Game.EventSystem.Publish(new OpenStarSoulBagUI() { zoneScene = this.zoneScene });
this.bagUI.HideWindow();
}));
//!money
RefreshMoney();
}
}
private void RefreshMoney()
{
NumericComponent num = zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<NumericComponent>();
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)):###,###}";
float coin = num.Get(NumericType.Coin);
(long gold, int sliver, int cupper) = TabHelper.GetCoinFormat(MathHelper.RoundToLong(coin));
bagUI.m_txtGold.text = gold + string.Empty;
bagUI.m_txtSliver.text = sliver + string.Empty;
bagUI.m_txtCoin.text = cupper + string.Empty;
}
public void Destroy()
{
}
}
}