Beispiel #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);
        }
    }
Beispiel #2
0
    //创建聊天界面
    public void CreateChatBox()
    {
        if (FriendsCom == null)
        {
            FriendsCom = UIPackage.CreateObject("GameUI", "FriendMain").asCom;
            GRoot.inst.AddChild(FriendsCom);
            FriendsCom.xy = Tool.GetPosition(1f, 0.5f);


            //
            FriendsCom.visible = false;
            FriendsCom.GetChild("close").onClick.Add(() => {
                FriendsCom.visible = false;
            });

            FriendsCom.GetChild("add").onClick.Add(() => {
                //输入名字
                var inputnamecom = UIPackage.CreateObject("GameUI", "InputFriendID").asCom;
                GRoot.inst.AddChild(inputnamecom);
                inputnamecom.xy = Tool.GetPosition(0.5f, 0.5f);

                inputnamecom.GetChild("ok").asButton.onClick.Add(() =>
                {
                    var txt = inputnamecom.GetChild("input").asTextInput.text;
                    if (txt.Length <= 0)
                    {
                        Tool.NoticeWords("请输入ID!", null);
                        inputnamecom.Dispose();
                        return;
                    }
                    var idarray = txt.Split('_');
                    if (idarray.Length != 2)
                    {
                        Tool.NoticeWords("ID错误!", null);
                        inputnamecom.Dispose();
                        return;
                    }
                    int uid = 0;
                    int cid = 0;
                    try
                    {
                        uid = Convert.ToInt32(idarray[0]); //报异常
                        cid = Convert.ToInt32(idarray[1]); //报异常
                    }
                    catch (SystemException e)
                    {
                        Tool.NoticeWords("ID错误!", null);
                        inputnamecom.Dispose();
                        return;
                    }


                    Protomsg.CS_AddFriendRequest msg1 = new Protomsg.CS_AddFriendRequest();
                    msg1.Uid         = uid;
                    msg1.Characterid = cid;
                    MyKcp.Instance.SendMsg(GameScene.Singleton.m_ServerName, "CS_AddFriendRequest", msg1);

                    inputnamecom.Dispose();
                });
            });
        }
    }