using Cal.DataTable; using ET.EventType; using ET; using FairyGUI; using System; using System.Collections.Generic; using UnityEngine; using System.Linq; using System.Text; namespace ET { public class GMUIAwakeSyatem : AwakeSystem { public override void Awake(GMUI self) { self.Awake(); } } public class GMUIDestroySyatem : DestroySystem { public override void Destroy(GMUI self) { self.Destroy(); } } public class GMUI : Entity { public FUI_GMUI ui; private Dictionary dic; private bool canSend; private GMConfig gMConfig; private ItemType itemType; private StringBuilder sb; public void Awake() { sb = new StringBuilder(); canSend = false; AwakeAsync().Coroutine(); } private async ETVoid AwakeAsync() { ui = GetParent(); ui.m_comType.self.selectedIndex = 0; Register(); Load(); await ETTask.CompletedTask; } private void Register() { ui.m_inpUid.onSubmit.Set(() => { GetCharacter().Coroutine(); }); ui.m_btnUid.self.onClick.Set(() => { GetCharacter().Coroutine(); }); ui.m_comType.self.onChanged.Set(Load); ui.m_comOp.self.onChanged.Set(() => { ShowOptionExampleText(ui.m_comOp.self.value); }); //发送 ui.m_btnSend.self.onClick.Set(async () => { if (!ui.m_inpCmd.text.IsNullOrEmpty()) { var ret_ = await SessionComponent.Instance.Call(new C2M_SendGMCMD { cmd = ui.m_inpCmd.text }); if (!ret_.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret_.Message); return; } return; } if (!canSend) return; if (gMConfig == null) return; if (gMConfig.ParamCount == 1) { if (ui.m_inpParam1.text.IsNullOrEmpty()) return; } else if (gMConfig.ParamCount ==2 ) { if (ui.m_inpParam1.text.IsNullOrEmpty()) return; if (ui.m_inpParam2.text.IsNullOrEmpty()) return; } string cmd = null; if (ui.m_comType.self.value == "othercmd") { cmd = $"othercmd/{ui.m_inpUid.text}/{ui.m_comOp.self.value}/{ui.m_inpParam1.text}/{ui.m_inpParam2.text}"; } else { cmd = $"cmd/{ui.m_comOp.self.value}/{ui.m_inpParam1.text}/{ui.m_inpParam2.text}"; } canSend = false; var ret = await SessionComponent.Instance.Call(new C2M_SendGMCMD {cmd = cmd }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } }); ui.m_btnCheck.self.onClick.Set(() => { ShowResult(); }); ui.m_comItemType.self.onChanged.Set(() => { if (int.TryParse(ui.m_comItemType.self.value, out var index)) itemType = (ItemType)index; }); ui.m_btnSearch.self.onClick.Set(() => { if (ui.m_inpSearch.text.IsNullOrEmpty()) return; String itemName = ui.m_inpSearch.text; sb.Clear(); switch (itemType) { case ItemType.NoneItem: break; case ItemType.EquipItem: foreach (var item in EquipBaseCategory.Instance.GetByName(itemName)) { sb.Append($"{item.Name} {item.Id}\n"); } ui.m_inpSearchRet.text = sb.ToString(); break; case ItemType.GoodsItem: foreach (var item in GoodsBaseCategory.Instance.GetByName(itemName)) { sb.Append($"{item.Name} {item.Id}\n"); } ui.m_inpSearchRet.text = sb.ToString(); break; case ItemType.MaterialsItem: foreach (var item in MaterialBaseCategory.Instance.GetByName(itemName)) { sb.Append($"{item.Name} {item.Id}\n"); } ui.m_inpSearchRet.text = sb.ToString(); break; default: break; } }); } private void Load() { dic = GMConfigCategory.Instance.configByTypeDic[ui.m_comType.self.value]; var arr = dic.Keys.ToArray(); ui.m_comOp.self.values = arr; for (int i = 0; i < arr.Length; i++) { var item = arr[i]; long id = dic[item]; GMConfig gMConfig = GMConfigCategory.Instance.Get(id); arr[i] = gMConfig.Name; } ui.m_comOp.self.items = arr; ShowOptionExampleText(ui.m_comOp.self.value); } private void ShowResult() { if (gMConfig == null) return; canSend = true; string ret = gMConfig.Result; switch (ui.m_comOp.self.value) { default: break; case "sys": ret = ret.Replace("{1}", ui.m_inpParam1.text); break; case "addItem": { if (!int.TryParse(ui.m_inpParam1.text, out var itemId)) return; if (!int.TryParse(ui.m_inpParam2.text, out var count)) return; ret = ret.Replace("{1}", BagHelper.GetIconName(itemId).Item1); ret = ret.Replace("{2}", count.ToString()); } break; case "addLevel": ret = ret.Replace("{1}", ui.m_inpParam1.text); break; case "addAllItem": { if (!int.TryParse(ui.m_inpParam1.text, out var itemId)) return; if (!int.TryParse(ui.m_inpParam2.text, out var count)) return; ret = ret.Replace("{1}", BagHelper.GetIconName(itemId).Item1); ret = ret.Replace("{2}", count.ToString()); } break; case "modifyPwd": { ret = ret.Replace("{1}", ui.m_inpParam1.text); ret = ret.Replace("{2}", ui.m_inpParam2.text); } break; case "TransLevel": ret.Replace("{1}", ui.m_inpParam1.text); break; case "passLevel": { if (!int.TryParse(ui.m_inpParam1.text, out var mapId)) return; int sceneId = mapId / 100; Sys_Scene sys_Scene = Sys_SceneCategory.Instance.Get(sceneId); if(sys_Scene==null) return; int layer = mapId % 100; if (layer > sys_Scene.Layers) return; ret = ret.Replace("{1}", sceneId.ToString()); ret = ret.Replace("{2}", layer.ToString()); } break; case "transJob": if (int.TryParse(ui.m_inpParam1.text, out var job)) { ret = ret.Replace("{1}", TabHelper.GetStrJob(job)); } break; } if (ui.m_comType.self.value == "othercmd") { ret = "发给玩家:\n" + ui.m_txtInfo.text + "\n\n" + ret; } ui.m_txtResult.text = ret; } private async ETVoid GetCharacter() { if (!int.TryParse(ui.m_inpUid.text, out int id)) { return; } var ret = await SessionComponent.Instance.Call(new C2M_GetUserInfo { Id = id }); if (!ret.Message.IsNullOrEmpty()) { TipHelper.OpenUI(ret.Message); return; } ui.m_txtInfo.text = $"uid:{id} 昵称:{ret.Name} 等级:{ret.Level} 职业:{CharacterHelper.GetJobTypeById(ret.JobId)}"; } private void ShowOptionExampleText(string value) { if (!dic.TryGetValue(value, out long id)) { ui.m_txtOp.text = $"未找到配置:{value}"; } gMConfig = GMConfigCategory.Instance.Get(id); ui.m_txtOp.text = gMConfig.Example; ui.m_txtTip1.text = gMConfig.Param1Tip; ui.m_txtTip.text = gMConfig.Param2Tip; } public void Destroy() { } } }