123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.Util;
- using XRTool.WorldUI;
- using SC.XR.Unity;
- using UnityEngine.UI;
- using System;
- using LitJson;
- using System.Text.RegularExpressions;
- using ShadowStudio.Mgr;
- using ShadowStudio.Model;
- using Studio.Scripts;
- using Studio.WebSocket.Message;
- using static SC.XR.Unity.SCInputField;
- namespace ShadowStudio.UI
- {
- [RequireComponent(typeof(WorldDlg))]
- public class CreateRoomDlg : UnitySingleton<CreateRoomDlg>
- {
- private SCInputField roomNameInputField;
- private Button createBtn;
- // private bool isLock = false;
- private Text roomNameRemind;
- private Button closeBtn;
- private string roomType;
- private string id;
- private GameObject privateRoomUI;
- private SCInputField roomExplainInputField;
- private GameObject publicRoomUI;
- private SCInputField roomPassInputField;
- private SCInputField roomNumInputField;
- private SCInputField roomExplainInputField1;
- private Text roomPassRemind;
- private Text roomNumRemind;
- private Transform toggleBtnTran;
- private ToggleGroup toggleBtnGroup;
- private ToggleGroup choosePubTypeToggleGroup;
- private Transform choosePubTypeToggleTran;
- //被zby替换的代码
- //private RoomConfig roomConfig;
- private RoomConfig itemConfig;
- WorldDlg dlg;
- Toggle[] togglegroup;
- void Start()
- {
- HomeProxy.Instance.CreateRoomAction += CreateRoomHandler;
- dlg = GetComponent<WorldDlg>();
- dlg.showDlg();
- privateRoomUI = dlg.GetBreadthChild<Transform>("PrivateRoomUI").gameObject;
- publicRoomUI = dlg.GetBreadthChild<Transform>("PublicRoomUI").gameObject;
- roomNameInputField = dlg.GetBreadthChild<SCInputField>("RoomNameInputField");
- roomNameInputField.onEndEdit.AddListener(InputRoomNameEnd);
- roomNameInputField.onValueChanged.AddListener(RoomNameValueChanged);
- roomExplainInputField = dlg.GetBreadthChild<SCInputField>("RoomExplainInputField");
- createBtn = dlg.GetBreadthChild<Button>("CreateBtn");
- createBtn.onClick.AddListener(OnClickCreat);
- roomNameRemind = dlg.GetBreadthChild<Text>("RoomNameRemind");
- roomPassRemind = dlg.GetBreadthChild<Text>("RoomPassRemind");
- roomNumRemind = dlg.GetBreadthChild<Text>("RoomNumRemind");
- closeBtn = dlg.GetBreadthChild<Button>("CloseBtn");//广度优先查找 切记不要重名
- closeBtn.onClick.AddListener(OnClickClose);
- roomPassInputField = dlg.GetBreadthChild<SCInputField>("RoomPassInputField");
- roomPassInputField.onEndEdit.AddListener(InputPassNameEnd);
- roomPassInputField.onValueChanged.AddListener(RoomPassValueChanged);
- roomNumInputField = dlg.GetBreadthChild<SCInputField>("RoomNumInputField");
- roomNumInputField.onEndEdit.AddListener(InputNumNameEnd);
- roomNumInputField.onValueChanged.AddListener(RoomNumValueChanged);
- roomExplainInputField1 = dlg.GetBreadthChild<SCInputField>("RoomExplainInputField1");
- toggleBtnTran = dlg.GetBreadthChild<Transform>("ToggleBtnGroup");
- Toggle[] toggles = toggleBtnTran.GetComponentsInChildren<Toggle>(true);
- for (int i = 0; i < toggles.Length; i++)
- {
- Toggle toggle = toggles[i];
- toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
- if (i == 0)
- {
- toggles[i].isOn = HomeProxy.Instance.IsCreatePrivateRoom;
- }
- }
- choosePubTypeToggleTran = dlg.GetBreadthChild<Transform>("ChoosePubTypeToggleGroup");
- roomNameRemind.gameObject.SetActive(false);
- roomPassRemind.gameObject.SetActive(false);
- roomNumRemind.gameObject.SetActive(false);
- privateRoomUI.SetActive(HomeProxy.Instance.IsCreatePrivateRoom);
- publicRoomUI.SetActive(!HomeProxy.Instance.IsCreatePrivateRoom);
- if (UserInfoMgr.Instance.userConfig.Nick_name.Length > 9)
- {
- string str = UserInfoMgr.Instance.userConfig.Nick_name.Substring(0, 6);
- roomNameInputField.text = str + "..." + "的房间";
- }
- else
- {
- roomNameInputField.text = UserInfoMgr.Instance.userConfig.Nick_name + "的房间";
- }
- if (roomNumInputField.text == "")
- {
- switch (UserInfoMgr.Instance.userConfig.Is_activate)
- {
- case "0":
- roomNumInputField.text = 2 + "";
- break;
- case "1":
- roomNumInputField.text = 10 + "";
- break;
- default:
- roomNumInputField.text = 2 + "";
- break;
- }
- }
- roomExplainInputField.lineType = LineType.MultiLineSubmit;
- roomExplainInputField1.lineType = LineType.MultiLineSubmit;
- }
- public void Init()
- {
- if (roomExplainInputField != null)
- {
- roomExplainInputField.text = "";
- roomExplainInputField1.text = "";
- roomPassInputField.text = "";
- }
- }
- private void OnEnable()
- {
- if (dlg != null)
- dlg.showDlg();
- }
- private void OnClickClose()
- {
- dlg.hideDlg(() => {
- Debug.Log("关闭结束");
- MenuListDlg.Instance.UpdateData();
- HomeMgr.Instance.ShowView(HomeMgr.CREATESEARCHRROOMDLG);
- HomeMgr.Instance.roomListDlg.SetActive(true);
- });
- }
- private void RoomNameValueChanged(string roomname)
- {
- roomNameRemind.gameObject.SetActive(false);
- }
- private void InputRoomNameEnd(string roomname)
- {
- if (roomname == "")
- {
- roomNameRemind.gameObject.SetActive(true);
- roomNameRemind.text = LanguageMgr.Instance.GetMessage("1048").Message;
- }
- else
- {
- if (roomname.Length < 3)
- {
- roomNameRemind.gameObject.SetActive(true);
- roomNameRemind.text = LanguageMgr.Instance.GetMessage("1049").Message;
- }
- else
- {
- if (roomname.Contains(" "))
- {
- roomNameRemind.gameObject.SetActive(true);
- roomNameRemind.text = LanguageMgr.Instance.GetMessage("1050").Message;
- }
- }
- }
- }
- private void OnToggle(bool isOn, Toggle toggle)
- {
- if (isOn)
- {
- HomeProxy.Instance.IsOpenPrivateOrPublicRoom(toggle.name == "ChoosePriBtn");
- privateRoomUI.SetActive(HomeProxy.Instance.IsCreatePrivateRoom);
- publicRoomUI.SetActive(!HomeProxy.Instance.IsCreatePrivateRoom);
- switch (toggle.name)
- {
- case "ChoosePriBtn":
- if (roomExplainInputField1.text != "")
- {
- roomExplainInputField.text = roomExplainInputField1.text;
- }
- break;
- case "ChoosePubBtn":
- if (roomExplainInputField.text != "")
- {
- roomExplainInputField1.text = roomExplainInputField.text;
- }
- if (togglegroup == null)
- {
- togglegroup = choosePubTypeToggleTran.GetComponentsInChildren<Toggle>(true);
- for (int i = 0; i < togglegroup.Length; i++)
- {
- Toggle toggle1 = togglegroup[i];
- togglegroup[i].onValueChanged.AddListener((bool isOn1) => { OnClickCreatPub(isOn1, toggle1); });
- if (i == 0)
- {
- togglegroup[i].isOn = true;
- roomType = "1";
- }
- }
- }
- break;
- }
- }
- }
- private void RoomPassValueChanged(string roompass)
- {
- roomPassRemind.gameObject.SetActive(false);
- }
- private void InputPassNameEnd(string roompass)
- {
- if (roompass != "")
- {
- if (roompass.Contains(" "))
- {
- roomPassRemind.gameObject.SetActive(true);
- roomPassRemind.text = LanguageMgr.Instance.GetMessage("1052").Message;
- }
- else
- {
- Regex regPass = new Regex(@"^[0-9]*$");
- bool ismatchpass = regPass.IsMatch(roompass);
- if (!ismatchpass)
- {
- roomPassRemind.gameObject.SetActive(true);
- roomPassRemind.text = LanguageMgr.Instance.GetMessage("1051").Message;
- }
- }
- }
- }
- private void RoomNumValueChanged(string roomnum)
- {
- roomNumRemind.gameObject.SetActive(false);
- }
- private void InputNumNameEnd(string roomnum)
- {
- if (roomnum != "")
- {
- if (roomnum.Contains(" "))
- {
- roomNumRemind.gameObject.SetActive(true);
- roomNumRemind.text = LanguageMgr.Instance.GetMessage("1086").Message;
- }
- else
- {
- Regex regPass = new Regex(@"^[0-9]*$");
- bool ismatchpass = regPass.IsMatch(roomnum);
- if (!ismatchpass)
- {
- roomNumRemind.gameObject.SetActive(true);
- roomNumRemind.text = LanguageMgr.Instance.GetMessage("1087").Message;
- }
- else
- {
- int num = int.Parse(roomnum);
- if (UserInfoMgr.Instance.userConfig.Is_activate == "0")
- {
- if (num <= 0 || num > 2)
- {
- roomNumRemind.gameObject.SetActive(true);
- roomNumRemind.text = "当前账号创建房间的人数上限为2";
- }
- else
- {
- if (roomnum.Length >= 2)
- {
- string str = roomnum.Substring(roomnum.Length - 1, 1);
- roomNumInputField.text = str;
- }
- }
- }
- else
- {
- if (num <= 0 || num > 10)
- {
- roomNumRemind.gameObject.SetActive(true);
- roomNumRemind.text = "当前账号创建房间的人数上限为10";
- }
- else
- {
- if (num < 10)
- {
- if (roomnum.Length >= 2)
- {
- string str = roomnum.Substring(roomnum.Length - 1, 1);
- roomNumInputField.text = str;
- }
- }
- }
- }
- }
- }
- }
- }
- private void OnClickCreat()
- {
- if (roomNameInputField.text == "")
- {
- roomNameRemind.gameObject.SetActive(true);
- roomNameRemind.text = LanguageMgr.Instance.GetMessage("1048").Message;
- }
- else if (roomNameRemind.gameObject.activeSelf)
- {
- return;
- }
- else
- {
- if (privateRoomUI.activeSelf)
- {
- OnClickCreatPri();
- }
- else
- {
- OnClickCreatPub();
- }
- }
- }
- private void OnClickCreatPri()
- {
- HomeProxy.Instance.RequestCreateRoom(roomNameInputField.text, roomExplainInputField.text);
- }
- private void OnClickCreatPub()
- {
- if (roomNumRemind.gameObject.activeSelf)
- {
- return;
- }
- else
- {
- if (roomNumInputField.text == "")
- {
- switch (UserInfoMgr.Instance.userConfig.Is_activate)
- {
- case "0":
- roomNumInputField.text = 2 + "";
- break;
- case "1":
- roomNumInputField.text = 10 + "";
- break;
- }
- }
- Regex regPass = new Regex(@"^[0-9]*[1-9][0-9]*$");
- bool ismatchpass = regPass.IsMatch(roomNumInputField.text);
- if (!ismatchpass)
- {
- CommonMethod.ShowTextTusi();
- if (TuSi.Instance)
- {
- TuSi.Instance.ShowTextContent("请正确输入房间人数!");
- //LanguageMgr.Instance.GetMessage("1056").Message
- }
- }
- else
- {
- if (int.Parse(roomNumInputField.text) > 0)
- {
- HomeProxy.Instance.RequestCreateRoom(roomNameInputField.text, roomExplainInputField1.text, roomPassInputField.text, int.Parse(roomType), int.Parse(roomNumInputField.text));
- }
- else
- {
- CommonMethod.ShowTextTusi();
- if (TuSi.Instance)
- {
- TuSi.Instance.ShowTextContent("请正确输入房间人数!");
- //LanguageMgr.Instance.GetMessage("1056").Message
- }
- }
- }
- }
- }
- private void OnClickCreatPub(bool isOn, Toggle toggle)
- {
- if (isOn)
- {
- switch (toggle.name)
- {
- case "ChooseViewToggle_CheckBox":
- roomType = "1";
- break;
- case "ChooseIntToggle_CheckBox":
- roomType = "2";
- break;
- }
- }
- }
- private void CreateRoomHandler(int roomID)
- {
- id = roomID.ToString();
- MenuIcon.itemPos = createBtn.transform.position;
- MenuIcon.inID = roomID.ToString();
- CommonMethod.ShowLoading();
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- if (WSHandler._roomClient != null)
- {
- WSHandler._roomClient.OnWebErrorClose -= onWebErrorClose;
- }
- WSHandler.Room.OnInit += onInit;
- WSHandler.Room.OnJoinRoom += onJoinRoom;
- WSHandler.roominit(id);
- WSHandler._roomClient.OnWebErrorClose += onWebErrorClose;
- if (HomeProxy.Instance.IsCreatePrivateRoom)
- {
- itemConfig = new RoomConfig(id, "1", roomNameInputField.text, roomExplainInputField.text, "", "0", "0", "0", UserInfoMgr.Instance.userConfig.Nick_name, "1");
- }
- else
- {
- itemConfig = new RoomConfig(id, "2", roomNameInputField.text, roomExplainInputField1.text, roomPassInputField.text, roomNumInputField.text, roomType, "0", UserInfoMgr.Instance.userConfig.Nick_name, "1");
- }
- AgoraRTCManager.Instance.ChannelName = id;
- }
- private static void onWebErrorClose(string data)
- {
- }
- private void onInit(JsonData data)
- {
- CommonMethod.SelfPeer(data["data"]["peerId"].ToString(), UserInfoMgr.Instance.userConfig.Nick_name);
- if (privateRoomUI.activeSelf)
- {
- WSHandler.Room.JoinRoom(id, "");
- }
- else
- {
- WSHandler.Room.JoinRoom(id, roomPassInputField.text);
- }
- AgoraRTCManager.Instance.ChannelName = id;
- }
- private void onJoinRoom(List<GoodsInfo> goods, List<Peer> peers, List<SceneConfig> scenes, SceneConfig currentScene)
- {
- CommonMethod.IsReceive = true;
- CommonMethod.HideLoading();
- //被zby替换的代码
- //HomeViewMgr.Instance.roomList.hide();
- HomeMgr.Instance._menuListDlg.Hide();
- CreateSearchRoomDlg.Instance.dlg.hideDlg();
- CommonMethod.GoodsInfoList = goods;
- CommonMethod.PeerList = peers;
- CommonMethod.scenes = scenes;
- CommonMethod.currentScene = currentScene;
- //被zby替换的代码
- //CommonMethod.roomConfig = this.roomConfig;
- //if (roomConfig.Room_password != "")
- //{
- // CommonMethod.roomPassWord = roomConfig.Room_password;
- //}
- CommonMethod.roomConfig = this.itemConfig;
- if (!string.IsNullOrEmpty(itemConfig.Room_password))
- {
- CommonMethod.roomPassWord = itemConfig.Room_password;
- }
- else
- {
- CommonMethod.roomPassWord = "";
- }
- CommonMethod.ShowNetLoading("NetWork", "正在创建房间....");
- Invoke("gotoLoadSence", 1.3f);
- }
- void gotoLoadSence()
- {
- CommonMethod.HideNetLoading("NetWork");
- //被zby替换的代码
- //HomeViewMgr.Instance.LoadSence();
- HomeMgr.Instance.LoadSence();
- }
- protected override void OnDestroy()
- {
- WSHandler.Room.OnInit -= onInit;
- WSHandler.Room.OnJoinRoom -= onJoinRoom;
- if (HomeProxy.Instance)
- {
- HomeProxy.Instance.CreateRoomAction -= CreateRoomHandler;
- }
- }
- }
- }
|