Esempio n. 1
0
    //通过频道类型获取频道文字

    //添加聊天数据到指定频道 zonghe siliao duiwu
    public void AddChatMsg2Chanel(Protomsg.SC_ChatInfo msg, string uichanel)
    {
        if (ChatBoxCom == null)
        {
            return;
        }

        var msglist = ChatBoxCom.GetChild(uichanel);

        if (msglist == null)
        {
            return;
        }

        //////聊天频道 1附近 2全服 3私聊 4队伍

        //组装内容
        var msgui = UIPackage.CreateObject("GameUI", "liaotian_content").asCom;
        //var content = "\\[" + "[color=#FFcc99]" + msg.Time + "[/color]" + "]";//时间
        var content = "[color=#66ff66]" + "[" + Tool.GetTextFromChatChanel(msg.Channel) + "]" + "[/color]";

        content += "" + msg.SrcName + "" + ":";//名字
        content += "" + Tool.GetContetColorFromChatChanel(msg.Channel) + msg.Content + "[/color]";
        msgui.GetChild("content").asTextField.text = content;

        //点击
        msgui.onClick.Add(() => {
            Debug.Log("chat click:" + msg.SrcName + " uid:" + msg.SrcPlayerUID);
            if (GameScene.Singleton.m_MyMainUnit == null)
            {
                return;
            }
            if (msg.SrcPlayerUID > 0 && msg.SrcPlayerUID != GameScene.Singleton.m_MyMainUnit.ControlID)
            //if (msg.SrcPlayerUID > 0)
            {
                var headselect = UIPackage.CreateObject("GameUI", "playerclick").asCom;
                GRoot.inst.ShowPopup(headselect);
                headselect.GetChild("siliao").asButton.onClick.Add(() =>
                {
                    DestPlayerName = msg.SrcName;
                    DestPlayerUID  = msg.SrcPlayerUID;

                    var curpagename = ChatBoxCom.GetController("page").selectedPage;
                    if (curpagename != "zonghe" && curpagename != "siliao")
                    {
                        OpenChatBox("zonghe", DestPlayerName, DestPlayerUID);
                    }
                    else
                    {
                        SetSendMsgChanel(3);
                    }

                    GRoot.inst.HidePopup(headselect);
                });
                //注销组队功能
                //headselect.GetChild("zudui").asButton.onClick.Add(() =>
                //{
                //    Protomsg.CS_OrganizeTeam msg1 = new Protomsg.CS_OrganizeTeam();
                //    msg1.Player1 = GameScene.Singleton.m_MyMainUnit.ControlID;
                //    msg1.Player2 = msg.SrcPlayerUID;
                //    MyKcp.Instance.SendMsg(GameScene.Singleton.m_ServerName, "CS_OrganizeTeam", msg1);
                //    GRoot.inst.HidePopup(headselect);
                //});
                headselect.GetChild("haoyou").asButton.onClick.Add(() =>
                {
                    Protomsg.CS_AddFriendRequest msg1 = new Protomsg.CS_AddFriendRequest();
                    msg1.Uid = msg.SrcPlayerUID;
                    MyKcp.Instance.SendMsg(GameScene.Singleton.m_ServerName, "CS_AddFriendRequest", msg1);
                    GRoot.inst.HidePopup(headselect);
                });
                //玩家信息
                headselect.GetChild("info").asButton.onClick.Add(() =>
                {
                    new HeroSimpleInfo(msg.SrcCharacterID);
                    GRoot.inst.HidePopup(headselect);
                });
            }
        });



        msglist.asList.AddChild(msgui);
        if (msglist.asList.GetChildIndex(msgui) > 0 && msglist.asList.IsChildInView(msglist.asList.GetChildAt(msglist.asList.GetChildIndex(msgui) - 1)))
        {
            msglist.asList.ScrollToView(msglist.asList.GetChildIndex(msgui));
        }

        //主界面聊天信息
        if (uichanel == "zonghe")
        {
            GameUI.AddChatMsg(content);
        }
    }