using LitJson; using SC.XR.Unity; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; using XRTool.Util; public class InviteDlg : UnitySingleton { public Button searchBtn; public Button inviteBtn; public Button clearBtn; public Button closeBtn; public GameObject noLinkMan; public Text shoumsgText; public SCInputField searchInputField; public UserList userList; public GameObject hisTextObj; public Image inviteBtnImage; public List InviteUnionIdList = new List();//选择还未被邀请 public List InvitingUnionIdList = new List();//已经邀请了还没同意或者拒绝 // Start is called before the first frame update protected override void Awake() { base.Awake(); WSHandler.Office.OnUserSearch += UserSearch; WSHandler.Office.OnInviteUsers += InviteUsers; WSHandler.Office.OnCallRecordsList += CallRecordsList; } protected override void OnDestroy() { base.OnDestroy(); WSHandler.Office.OnUserSearch -= UserSearch; WSHandler.Office.OnInviteUsers -= InviteUsers; WSHandler.Office.OnCallRecordsList -= CallRecordsList; } private void InviteUsers(JsonData data) { if (data["data"]["code"].ToString() == "200") { for (int i = 0; i < InviteUnionIdList.Count; i++) { InvitingUnionIdList.Add(InviteUnionIdList[i]); } InviteUnionIdList.Clear(); RoomOtherUser.Instance.UpdateList(); } } private List inviteUserConfigList = new List(); private void UserSearch(JsonData data) { switch (data["data"]["code"].ToString()) { case "200": HideHistory(); if (inviteUserConfigList.Count > 0) { inviteUserConfigList.Clear(); } if (data["data"]["data"].Count > 0) { noLinkMan.SetActive(false); for (int i = 0; i < data["data"]["data"].Count; i++) { InviteUserConfig inviteUserConfig = new InviteUserConfig(data["data"]["data"][i]["unionId"].ToString(), data["data"]["data"][i]["phone"].ToString(), data["data"]["data"][i]["avatar"].ToString(), data["data"]["data"][i]["nickName"].ToString(), data["data"]["data"][i]["online"].ToString()); inviteUserConfigList.Add(inviteUserConfig); } userList.Init(inviteUserConfigList); inviteUserConfigList.Clear(); } else { noLinkMan.SetActive(true); shoumsgText.text = "无有效的联系人"; } break; case "5001": HideHistory(); noLinkMan.SetActive(true); shoumsgText.text = "无有效的联系人"; break; default: break; } } private List historyConfigList = new List(); public void ShowHistory() { InviteUnionIdList.Clear(); clearBtn.gameObject.SetActive(false); userList.DestoryAll(); hisTextObj.SetActive(true); InitInviteBtn(); WSHandler.Office.GetRecordsList(); } private List zaixianList = new List(); private List mangluList = new List(); private List lixianList = new List(); private void AddHisInviteUserList(List inviteUserConfigs) { if (inviteUserConfigs.Count > 0) { for (int i = 0; i < inviteUserConfigs.Count; i++) { historyConfigList.Add(inviteUserConfigs[i]); } } } private void CallRecordsList(JsonData data) { if (data.Keys.Contains("data")) { if (data["data"]["data"].Count > 0) { noLinkMan.SetActive(false); for (int i = 0; i < data["data"]["data"].Count; i++) { if (!string.IsNullOrEmpty(data["data"]["data"][i]["nickName"].ToString())) { InviteUserConfig inviteUserConfig = new InviteUserConfig(data["data"]["data"][i]["contacts"].ToString(), data["data"]["data"][i]["phone"].ToString(), data["data"]["data"][i]["avatar"].ToString(), data["data"]["data"][i]["nickName"].ToString(), data["data"]["data"][i]["online"].ToString()); switch (data["data"]["data"][i]["online"].ToString()) { case "1": zaixianList.Add(inviteUserConfig); break; case "2": mangluList.Add(inviteUserConfig); break; case "0": lixianList.Add(inviteUserConfig); break; } } } AddHisInviteUserList(zaixianList); AddHisInviteUserList(mangluList); AddHisInviteUserList(lixianList); userList.Init(historyConfigList); zaixianList.Clear(); mangluList.Clear(); lixianList.Clear(); historyConfigList.Clear(); } else { noLinkMan.SetActive(true); shoumsgText.text = "暂时无记录"; } } else { noLinkMan.SetActive(true); shoumsgText.text = "暂时无记录"; } } public void HideHistory() { userList.DestoryAll(); hisTextObj.SetActive(false); } void Start() { searchBtn.onClick.AddListener(ClickOnSearch); clearBtn.onClick.AddListener(ClickOnClear); closeBtn.onClick.AddListener(ClickOnClose); searchInputField.onValueChanged.AddListener(Inputscearchchanged); inviteBtn.onClick.AddListener(ClickOnInvite); //searchInputField.onEndEdit.AddListener(InputsearchEnd); } public void InitInviteBtn() { inviteBtn.enabled = false; Color color = Color.white; color.r = 71 / 255f; color.g = 126 / 255f; color.b = 186 / 255f; color.a = 220 / 255f; inviteBtnImage.color = color; } public void RecoverInviteBtn() { inviteBtn.enabled = true; Color color = Color.white; color.r = 76 / 255f; color.g = 166 / 255f; color.b = 255 / 255f; color.a = 230 / 255f; inviteBtnImage.color = color; } private void ClickOnInvite() { if (InvitingUnionIdList != null && InviteUnionIdList != null && InviteUnionIdList.Count > 0) { if (IsContains(InvitingUnionIdList, InviteUnionIdList)) { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "邀请列表有用户正在通话中"); } else { if (!string.IsNullOrEmpty(RoomMainInfo.roomNum)) { if (RemoteRtc.Instance.customPeerList != null) { if (RemoteRtc.Instance.customPeerList.getPeers().Count + InvitingUnionIdList.Count + InviteUnionIdList.Count > RoomMainInfo.roomMaxPeopleNum - 1) { PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间人数大于房间总人数"); } else { this.gameObject.SetActive(false); WSHandler.Office.InviteUsers(RoomMainInfo.roomNum, InviteUnionIdList); ClickOnClear(); } } } } } } public bool IsContains(List vs1, List vs2) { List vs3 = new List(); vs3 = vs1.Intersect(vs2).ToList(); if (vs3.Count > 0) { vs3 = null; return true; } else { vs3 = null; return false; } } //private void InputsearchEnd(string content) //{ // if (content != "") // { // clearBtn.gameObject.SetActive(true); // } //} private void Inputscearchchanged(string content) { if (content == "") { if (gameObject.activeSelf) { ShowHistory(); clearBtn.gameObject.SetActive(false); } } else { clearBtn.gameObject.SetActive(true); } } private void ClickOnSearch() { if (searchInputField.text != "") { if (searchInputField.text.Length >2) { WSHandler.Office.UserSearch(searchInputField.text); } else { HideHistory(); noLinkMan.SetActive(true); shoumsgText.text = "无有效的联系人"; } } } private void ClickOnClear() { if (searchInputField.text != "") { searchInputField.text = ""; } clearBtn.gameObject.SetActive(false); } private void ClickOnClose() { InviteUnionIdList.Clear(); this.gameObject.SetActive(false); ClickOnClear(); } }