From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XTransformDocument.cs | 243 +++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XTransformDocument.cs (limited to 'Client/Assets/Scripts/XMainClient/XTransformDocument.cs') diff --git a/Client/Assets/Scripts/XMainClient/XTransformDocument.cs b/Client/Assets/Scripts/XMainClient/XTransformDocument.cs new file mode 100644 index 00000000..0e691e17 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XTransformDocument.cs @@ -0,0 +1,243 @@ +using System; +using System.Collections.Generic; +using KKSG; +using UILib; +using UnityEngine; +using XMainClient.UI; +using XMainClient.UI.UICommon; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XTransformDocument : XDocComponent + { + public override uint ID + { + get + { + return XTransformDocument.uuID; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("XTransformDocument"); + + public static XTableAsyncLoader AsyncLoader = new XTableAsyncLoader(); + + private static ItemTransform m_ItemTransformTable = new ItemTransform(); + + private List m_ItemList = new List(); + + private uint m_ItemType = 1u; + + private ulong m_TempRoleID; + + private int m_TempItemID; + + public static void Execute(OnLoadedCallback callback = null) + { + XTransformDocument.AsyncLoader.AddTask("Table/ItemTransform", XTransformDocument.m_ItemTransformTable, false); + XTransformDocument.AsyncLoader.Execute(null); + } + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + } + + protected override void OnReconnected(XReconnectedEventArgs arg) + { + } + + protected override void EventSubscribe() + { + base.EventSubscribe(); + } + + public static void OnTransform(bool bTrans, XEntity entity, bool bInit, bool bReplace) + { + bool flag = !bInit && entity.EngineObject != null; + if (flag) + { + if (bTrans) + { + XSingleton.singleton.CreateAndPlay("Effects/FX_Particle/VehicleFX/Vehicle_shangma", entity.EngineObject, Vector3.zero, Vector3.one, 1f, false, 3f, true); + } + else + { + bool flag2 = !bReplace; + if (flag2) + { + XSingleton.singleton.CreateAndPlay("Effects/FX_Particle/VehicleFX/Vehicle_xiama", entity.EngineObject, Vector3.zero, Vector3.one, 1f, false, 3f, true); + } + } + } + } + + public static void TryReqLeftTime() + { + bool flag = DlgBase.singleton.IsVisible(); + if (flag) + { + XTransformDocument specificDocument = XDocuments.GetSpecificDocument(XTransformDocument.uuID); + specificDocument.ReqLeftTime(); + } + } + + private void _Recycle() + { + for (int i = 0; i < this.m_ItemList.Count; i++) + { + this.m_ItemList[i].Recycle(); + } + this.m_ItemList.Clear(); + } + + private int _ShowItemListByType(uint type) + { + HashSet hashSet = HashPool.Get(); + for (int i = 0; i < XTransformDocument.m_ItemTransformTable.Table.Length; i++) + { + ItemTransform.RowData rowData = XTransformDocument.m_ItemTransformTable.Table[i]; + bool flag = rowData.type == type; + if (flag) + { + hashSet.Add((int)rowData.itemid); + } + } + this._Recycle(); + bool flag2 = hashSet.Count > 0; + if (flag2) + { + Dictionary dictionary = DictionaryPool.Get(); + XBag itemBag = XSingleton.singleton.Doc.XBagDoc.ItemBag; + for (int j = 0; j < itemBag.Count; j++) + { + XItem xitem = itemBag[j]; + bool flag3 = !hashSet.Contains(xitem.itemID); + if (!flag3) + { + XNormalItem data; + bool flag4 = !dictionary.TryGetValue(xitem.itemID, out data); + if (flag4) + { + data = XDataPool.GetData(); + dictionary.Add(xitem.itemID, data); + data.itemID = xitem.itemID; + data.itemConf = xitem.itemConf; + this.m_ItemList.Add(data); + } + data.itemCount += xitem.itemCount; + } + } + DictionaryPool.Release(dictionary); + } + HashPool.Release(hashSet); + return this.m_ItemList.Count; + } + + private bool _OnItemClicked(IXUIButton btn) + { + int num = (int)btn.ID; + bool flag = num < 0 || num >= this.m_ItemList.Count; + bool result; + if (flag) + { + result = true; + } + else + { + this._ReqTranformOther(this.m_TempRoleID, this.m_ItemList[num].itemID); + result = true; + } + return result; + } + + public void ReqLeftTime() + { + RpcC2G_TransformOp rpcC2G_TransformOp = new RpcC2G_TransformOp(); + rpcC2G_TransformOp.oArg.op = 2; + XSingleton.singleton.Send(rpcC2G_TransformOp); + } + + public void ReqSwitch() + { + RpcC2G_TransformOp rpcC2G_TransformOp = new RpcC2G_TransformOp(); + rpcC2G_TransformOp.oArg.op = 0; + XSingleton.singleton.Send(rpcC2G_TransformOp); + } + + public void TryTransformOther(string name, ulong roleID) + { + this.m_TempRoleID = roleID; + int num = this._ShowItemListByType(this.m_ItemType); + int num2 = num; + if (num2 != 0) + { + if (num2 != 1) + { + DlgBase.singleton.Set(new ButtonClickEventHandler(this._OnItemClicked), this.m_ItemList); + } + else + { + this.m_TempItemID = this.m_ItemList[0].itemID; + for (int i = 0; i < XTransformDocument.m_ItemTransformTable.Table.Length; i++) + { + ItemTransform.RowData rowData = XTransformDocument.m_ItemTransformTable.Table[i]; + bool flag = rowData.itemid == (uint)this.m_TempItemID; + if (flag) + { + XSingleton.singleton.ShowModalDialog(XStringDefineProxy.GetString("TRANSFORM_CONFIRM", new object[] + { + name, + (this.m_ItemList[0].itemConf != null) ? XSingleton.singleton.ChooseProfString(this.m_ItemList[0].itemConf.ItemName, 0u) : string.Empty, + rowData.time + }), XStringDefineProxy.GetString(XStringDefine.COMMON_OK), XStringDefineProxy.GetString(XStringDefine.COMMON_CANCEL), new ButtonClickEventHandler(this._OnTransformConfirmClicked)); + break; + } + } + } + } + else + { + XSingleton.singleton.ShowSystemTip(ErrorCode.ERR_TRANS_ITEMNOTENOUGH, "fece00"); + } + } + + private bool _OnTransformConfirmClicked(IXUIButton btn) + { + XSingleton.singleton.CloseModalDlg(); + this._ReqTranformOther(this.m_TempRoleID, this.m_TempItemID); + return true; + } + + private void _ReqTranformOther(ulong roleID, int itemid) + { + RpcC2G_TransformOp rpcC2G_TransformOp = new RpcC2G_TransformOp(); + rpcC2G_TransformOp.oArg.op = 1; + rpcC2G_TransformOp.oArg.roleid = roleID.ToString(); + rpcC2G_TransformOp.oArg.itemid = (uint)itemid; + XSingleton.singleton.Send(rpcC2G_TransformOp); + } + + public void OnGetTransformOp(TransformOpArg oArg, TransformOpRes oRes) + { + bool flag = oRes.errorcode > ErrorCode.ERR_SUCCESS; + if (flag) + { + XSingleton.singleton.ShowSystemTip(oRes.errorcode, "fece00"); + } + else + { + int op = oArg.op; + if (op == 2) + { + bool flag2 = DlgBase.singleton.IsVisible(); + if (flag2) + { + DlgBase.singleton.SetTransformLeftTime(oRes.timeleft); + } + } + } + } + } +} -- cgit v1.1-26-g67d0