Пример #1
0
 public static void Remove(LobbyRow row)
 {
     if (List.Contains(row))
     {
         if (row.gameObject != null)
         {
             GameObject.Destroy(row.gameObject);
         }
         List.Remove(row);
     }
 }
Пример #2
0
    public static LobbyRow Create(Transform parent, LobbyChan lobby)
    {
        GameObject obj = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Channel/LobbyRow"));

        //obj.name = string.Format("Lobby_{0:0000}", List.Count + 1);
        obj.name                    = string.Format("Lobby_{0:0000}", lobby.gameIndex);
        obj.transform.parent        = parent;
        obj.transform.localPosition = new Vector3(0f, 0f, -2f);
        obj.transform.localScale    = Vector3.one;
        LobbyRow row = obj.GetComponent <LobbyRow>();

        row.SetData(lobby);
        List.Add(row);
        return(row);
    }
Пример #3
0
    private void FilterWhenLobbyAdded(LobbyChan lobby)
    {
        List <Criteria> criterias = containerFilter.GetComponent <LobbyFilter>().criterias;
        List <Dictionary <string, object> > dictLobby    = new List <Dictionary <string, object> >();
        List <Dictionary <string, object> > dictCriteria = new List <Dictionary <string, object> >();

        dictLobby.Add(lobby.ToDictionary());
        foreach (Criteria cri in criterias)
        {
            dictCriteria.Add(cri.iDict);
        }
        List <Dictionary <string, object> > dictFilter = Utility.ComparableCriteria.filterByCriterias(dictLobby, dictCriteria);
        List <LobbyChan> lobbiesFilter = new List <LobbyChan>();

        foreach (Dictionary <string, object> lb in dictFilter)
        {
            LobbyRow.Create(parentListLobby.transform, (LobbyChan)lb[Fields.LobbyFilter.OBJECT_REFRENCE]);
        }
        parentListLobby.Reposition();
    }
Пример #4
0
    IEnumerator _OnReDrawLobby(List <LobbyChan> lobbi)
    {
        while (LobbyRow.List.Count > 0)
        {
            LobbyRow.Remove(LobbyRow.List[0]);
        }
        parentListLobby.Reposition();
        yield return(new WaitForEndOfFrame());

        foreach (LobbyChan lobby in lobbi)
        {
            LobbyRow.Create(parentListLobby.transform, lobby);
        }
        lobbyDrag.collider.enabled = false;
        lobbyDrag.collider.enabled = true;
        parentListLobby.Reposition();
        if (containerFilter.GetComponent <LobbyFilter>().isButtonCancelClick)
        {
            containerFilter.GetComponent <LobbyFilter>().isButtonCancelClick = !containerFilter.GetComponent <LobbyFilter>().isButtonCancelClick;
        }
    }
Пример #5
0
    void OnProcessPluginMessage(string command, string action, EsObject paremeters)
    {
        if (command == Fields.RESPONSE.FULL_UPDATE)
        {
            #region Lấy danh sách các lobby sau khi vào room
            LobbyRow.List.Clear();
            lobbies.Clear();
            EsObject[] children = paremeters.getEsObjectArray("children");
            foreach (EsObject obj in children)
            {
                LobbyChan lobby = new LobbyChan(obj);
                lobbies.Add(lobby);
                LobbyRow.Create(parentListLobby.transform, lobby);
            }
            if (children.Length > 0)
            {
                parentListLobby.Reposition();
            }
            parentListLobby.transform.parent.GetComponent <UIScrollView>().ResetPosition();
            RedrawUIGrid(parentListLobby);
            lobbyDrag.collider.enabled = true;
            //GameManager.Instance.FunctionDelay(delegate() { RedrawUIGrid(parentListLobby); lobbyDrag.collider.enabled = true; }, 0.01f);
            #endregion
        }
        else if (command == Fields.RESPONSE.LOBBY_ADD)
        {
            #region Có một lobby mới được tạo.
            EsObject  es    = paremeters.getEsObject("child");
            LobbyChan lobby = new LobbyChan(es);
            lobbies.Add(lobby);
            if (!isFiltered)
            {
                LobbyRow.Create(parentListLobby.transform, lobby);
                parentListLobby.Reposition();
            }
            else
            {
                FilterWhenLobbyAdded(lobby);
            }
            lobbyDrag.collider.enabled = false;
            lobbyDrag.collider.enabled = true;
            #endregion
        }
        else if (command == Fields.RESPONSE.LOBBY_UPDATE)
        {
            #region Có một lobby nào đó có thay đổi.
            EsObject es  = paremeters.getEsObject("child");
            LobbyRow row = LobbyRow.List.Find(o => o.lobby.gameId == es.getInteger("gameId"));
            if (row != null)
            {
                row.UpdateData(new LobbyChan(es));
            }
            #endregion
        }
        else if (command == Fields.RESPONSE.LOBBY_REMOVE)
        {
            #region Có một lobby nào đó thoát
            EsObject es    = paremeters.getEsObject("child");
            LobbyRow row   = LobbyRow.List.Find(o => o.lobby.gameId == es.getInteger("gameId"));
            int      index = lobbies.FindIndex(o => o.gameId == es.getInteger("gameId"));
            if (index != -1)
            {
                lobbies.RemoveAt(index);
            }
            LobbyRow.Remove(row);
            parentListLobby.Reposition();
            #endregion
        }
        else if (command == Fields.REQUEST.GET_USER_ONLINE)
        {
            #region Lấy danh sách những người chơi đang online khi vào room
            UserOnlineRowChan.List.Clear();

            EsObject[] children = paremeters.getEsObjectArray("users");
            foreach (EsObject obj in children)
            {
                if (obj.getString(Fields.PLAYER.USERNAME) == GameManager.Instance.mInfo.username)
                {
                    continue;
                }
                UserOnlineRowChan.Create(parentListUseOnline.transform, new User(obj));
            }
            if (children.Length > 0)
            {
                parentListUseOnline.repositionNow = true;
            }

            parentListUseOnline.transform.parent.GetComponent <UIScrollView>().ResetPosition();
            RedrawUIGrid(parentListUseOnline);
            userOnlineDrag.collider.enabled = true;
            #endregion
        }
        else if (command == Fields.RESPONSE.USER_ONLINE_UPDATE)
        {
            #region Khi có người mới tham gia hoặc thoát ra khởi room
            if (action == "addUserOnline")
            {
                EsObject es = paremeters.getEsObject(Fields.PLAYER.USERNAME);
                if (es.getString(Fields.PLAYER.USERNAME) != GameManager.Instance.mInfo.username)
                {
                    UserOnlineRowChan.Create(parentListUseOnline.transform, new User(es));
                    parentListLobby.repositionNow     = true;
                    parentListUseOnline.repositionNow = true;
                }
                userOnlineDrag.collider.enabled = false;
                userOnlineDrag.collider.enabled = true;
            }
            else if (action == "removeUserOnline")
            {
                EsObject       es  = paremeters.getEsObject(Fields.PLAYER.USERNAME);
                EUserOnlineRow row = UserOnlineRowChan.List.Find(o => o.user.username == es.getString(Fields.PLAYER.USERNAME));
                if (row != null)
                {
                    UserOnlineRowChan.Remove(row);
                    parentListLobby.repositionNow     = true;
                    parentListUseOnline.repositionNow = true;
                }
            }
            #endregion
        }
        else if (command == "quickJoinGame")
        {
            #region Chơi nhanh
            int gameId = paremeters.getInteger("gameId");
            if (gameId == -1)
            {
                NotificationView.ShowMessage("Hiện không có bàn chơi nào sẵn sàng.", 3f);
            }
            else
            {
                LobbyChan lobby = lobbies.Find(lb => lb.gameId == gameId);
                GameManager.Instance.selectedLobby = new LobbyChan(lobby.zoneId, lobby.roomId, lobby.gameId);
                if (PlaySameDevice.IsCanJoinGameplay)
                {
                    GameManager.Server.DoJoinGame("");
                }
            }
            #endregion
        }
        else if (command == "error")
        {
            WaitingView.Instance.Close();
            int id = paremeters.getInteger("error");
            if (id == 0)
            {
                Common.MessageRecharge("Bạn không đủ tiền để tham gia bàn chơi.");
            }
            else if (id == 1)
            {
                NotificationView.ShowMessage("Bàn chơi đã đủ người hoặc đã được thêm máy.");
            }
            else if (id == 2)
            {
                NotificationView.ShowMessage("Bạn đã bị đuổi khỏi bài chơi trước đó.");
            }
            else if (id == 4)
            {
                NotificationView.ShowMessage("Mật khẩu không chính xác.\n\nĐề nghị nhập lại.");
            }
            else if (id == 5)
            {
                string contentMsg = paremeters.getString("textNotification");
                int    gameId     = paremeters.getInteger("gameId");
                string password   = paremeters.variableExists("password") ? paremeters.getString("password") : "";
                NotificationView.ShowConfirm("Xác nhận",
                                             contentMsg,
                                             delegate()
                {
                    GameManager.Instance.selectedLobby = new LobbyChan(gameId);
                    GameManager.Server.DoJoinGame(password);
                }, null);
            }
        }
        else if (command == "tryCreateGame")
        {
            bool allowCreateRoom = paremeters.getBoolean("allowCreateGame");
            if (allowCreateRoom)
            {
                if (Common.ValidateChipToBetting(((ChannelChan)GameManager.Instance.selectedChannel).bettingValues[0], GameManager.PlayGoldOrChip))
                {
                    GameManager.LoadScene(ESceneName.CreateRoomChan);
                }
                else
                {
                    Common.MessageRecharge("Bạn không đủ tiền để tạo bàn chơi.");
                }
            }
            else
            {
                string contentMsg = paremeters.getString("textNotification");
                int    gameId     = paremeters.getInteger("gameId");
                string password   = paremeters.variableExists("password") ? paremeters.getString("password") : "";
                NotificationView.ShowConfirm("Xác nhận",
                                             contentMsg,
                                             delegate()
                {
                    GameManager.Instance.selectedLobby = new LobbyChan(gameId);
                    GameManager.Server.DoJoinGame(password);
                }, null);
            }
        }
    }
Пример #6
0
 public void test(LobbyChan lb)
 {
     LobbyRow.Create(parentListLobby.transform, lb);
 }