void openMessage(MainData.FriendBody friend) { GameObject result = transform.FindChild("list").FindChild("result").gameObject; if (result.activeSelf) { backFromSearchReult(); } backEvent = new EventDelegate(backFromMessage); transform.FindChild("title").FindChild("label").GetComponent <UILabel>().text = "和" + friend.fName + "的聊天"; messageListContainer.parent.parent.parent.gameObject.SetActive(false); messageDetailContainer.parent.parent.gameObject.SetActive(true); MessageUpdate messageUpdate = messageDetailContainer.GetComponent <MessageUpdate>(); messageUpdate.friend = friend; messageUpdate.count = 0; //聊天内容显示 refreshMessage(friend); Transform inputers = messageDetailContainer.parent.parent.FindChild("inputers"); //发送文字逻辑 UIButton send_button = inputers.FindChild("send").GetComponent <UIButton>(); EventDelegate send_event = new EventDelegate(this, "sendStringMessage"); send_event.parameters[0] = new EventDelegate.Parameter(); send_event.parameters[0].obj = friend; send_button.onClick.Clear(); send_button.onClick.Add(send_event); //发送图片逻辑 send_button = inputers.FindChild("add-pic").GetComponent <UIButton>(); send_event = new EventDelegate(this, "openPhotogapher"); send_event.parameters[0] = new EventDelegate.Parameter(); send_event.parameters[0].obj = friend; send_button.onClick.Clear(); send_button.onClick.Add(send_event); }
void refreshMessage(MainData.FriendBody friend) { MyUtilTools.clearChild(messageDetailContainer); List <MainData.MessageBody> messages = getRecentlyMessage(friend); messageStarty = 450; for (int i = messages.Count - 1; i >= 0; i--) { MainData.MessageBody message = messages[i]; initMessage(message); } UIPanel panel = messageDetailContainer.parent.GetComponent <UIPanel>(); if (messages.Count > 0) { float y = 450 - messageStarty - panel.baseClipRegion.w + 50; panel.clipOffset = new Vector2(0, -y); messageDetailContainer.parent.localPosition = new Vector3(0, y + 50, 0); } else { panel.clipOffset = Vector2.zero; messageDetailContainer.parent.localPosition = new Vector3(0, 50, 0); } }
public void openPhotogapher(MainData.FriendBody friend) { EventDelegate event_delegate = new EventDelegate(this, "sendPicture"); event_delegate.parameters[0] = new EventDelegate.Parameter(); event_delegate.parameters[1] = new EventDelegate.Parameter(); event_delegate.parameters[1].obj = friend; photoEvent.open(event_delegate); }
void doFriendPass(MainData.FriendBody friend) { ByteBuffer buffer = ByteBuffer.Allocate(1024); buffer.skip(4); buffer.WriteString("FriendPass"); buffer.WriteLong(MainData.instance.user.id);//编号 buffer.WriteLong(friend.fid); buffer.WriteByte(1); NetUtil.getInstance.SendMessage(buffer); }
int getNewCount() { List <MainData.FriendBody> friends = MainData.instance.user.friends; int count = 0; for (int i = 0; i < friends.Count; i++) { MainData.FriendBody friend = friends[i]; if (friend.pass == 0) { count++; } } return(count); }
public static List <MainData.MessageBody> getRecentlyMessage(MainData.FriendBody friend) { List <MainData.MessageBody> temps = new List <MainData.MessageBody>(); for (int i = 0; i < MainData.instance.user.messages.Count; i++) { MainData.MessageBody message = MainData.instance.user.messages[i]; if (message.sendId == friend.fid || message.sendId == friend.uid) { temps.Add(message); } } temps.Sort(); return(temps); }
void openSearchResult(string resultStr, MainData.FriendBody friend) { string[] ss = resultStr.Split(","[0]); int type = int.Parse(ss[0]); if (type == 0) { DialogUtil.tip("找不到用户"); return; } GameObject result = transform.FindChild("list").FindChild("result").gameObject; result.SetActive(true); transform.FindChild("list").FindChild("body").GetComponent <UIPanel>().alpha = 0.2f; result.GetComponent <JustChangeLayer>().change(10); CameraUtil.push(8, 2); Transform sure = result.transform.FindChild("bg").FindChild("down").FindChild("sure"); UIButton sure_button = sure.GetComponent <UIButton>(); UILabel sure_label = sure.GetComponent <UILabel>(); UILabel content = result.transform.FindChild("content").GetComponent <UILabel>(); if (type == 1) { sure_label.text = "添加好友"; sure_button.onClick.Clear(); justUseAddFriend = ss[1]; content.text = ss[1]; sure_button.onClick.Add(new EventDelegate(sendAddMessage)); } else if (type == 2) { sure_label.text = "聊 天"; sure_button.onClick.Clear(); if (friend.pass == 0) { sure_button.enabled = false; content.text = ss[1] + "(已申请,对方尚未通过)"; } else { content.text = ss[1]; EventDelegate chat_event = new EventDelegate(this, "openMessage"); chat_event.parameters[0] = new EventDelegate.Parameter(); chat_event.parameters[0].obj = friend; sure_button.onClick.Add(chat_event); } } }
void doOpenOther(MainData.FriendBody friend) { if (MyUtilTools.stringIsNull(friend.other)) { return; } transform.FindChild("new-body").GetComponent <UIWidget>().alpha = 0.2f; Transform pop = transform.FindChild("pop"); pop.gameObject.SetActive(true); pop.GetComponent <JustChangeLayer>().change(10); CameraUtil.push(8, 2); UILabel content = pop.FindChild("content").GetComponent <UILabel>(); content.text = friend.other; }
List <MainData.FriendBody> getListByType(byte type) { List <MainData.FriendBody> friends = MainData.instance.user.friends; List <MainData.FriendBody> result = new List <MainData.FriendBody>(); for (int i = 0; i < friends.Count; i++) { MainData.FriendBody friend = friends[i]; if (friend.pass == type) { result.Add(friend); } } result.Sort(); return(result); }
void sendPicture(Texture2D texture, MainData.FriendBody friend) { LoadUtil.show(true, "图片发送中请稍后"); System.DateTime now = System.DateTime.Now; string dateStr = now.Year + "-" + now.Month + "-" + now.Day + " " + now.Hour + "-" + now.Minute + "-" + now.Second; string picName = "[" + MainData.instance.user.id + "," + friend.fid + "] " + dateStr + ".jpg"; SendMessageEntity entity = new SendMessageEntity(); entity.buffer.skip(4); entity.buffer.WriteString("FriendMessage"); entity.buffer.WriteLong(MainData.instance.user.id); //自己编号 entity.buffer.WriteLong(friend.fid); //好友编号 entity.buffer.WriteByte(1); //0 文字内容,1图片 entity.buffer.WriteString(picName); //上传的文件名字 EventDelegate ok_event = new EventDelegate(this, "sendPictureOk"); ok_event.parameters[0] = new EventDelegate.Parameter(); ok_event.parameters[0].obj = entity; JustRun.Instance.upLoadPic(picName, texture.EncodeToJPG(), ok_event, new EventDelegate(sendPictureFail)); }
public void sendStringMessage(MainData.FriendBody friend) { UIInput input = transform.FindChild("message-detail").FindChild("inputers").FindChild("inputer").GetComponent <UIInput>(); if (MyUtilTools.stringIsNull(input.value)) { DialogUtil.tip("不能发送空的消息"); return; } ByteBuffer buffer = ByteBuffer.Allocate(1024); buffer.skip(4); buffer.WriteString("FriendMessage"); buffer.WriteLong(MainData.instance.user.id); //自己编号 buffer.WriteLong(friend.fid); //好友编号 buffer.WriteByte(0); //0 文字内容,1图片 buffer.WriteString(input.value); //内容 NetUtil.getInstance.SendMessage(buffer); input.value = ""; }
void refreshNew() { List <MainData.FriendBody> friends = getListByType(0); passContainer.parent.GetComponent <UIPanel>().clipOffset = Vector2.zero; passContainer.parent.localPosition = Vector3.zero; MyUtilTools.clearChild(passContainer); float starty = 520, len = 100; for (int i = 0; i < friends.Count; i++) { MainData.FriendBody friend = friends[i]; GameObject pass_obj = NGUITools.AddChild(passContainer.gameObject, pref_pass); pass_obj.name = "pass" + i; UISprite icon = pass_obj.transform.FindChild("icon").GetComponent <UISprite>(); icon.spriteName = friend.fFace; UILabel name = pass_obj.transform.FindChild("name").GetComponent <UILabel>(); name.text = friend.fName; UILabel other = pass_obj.transform.FindChild("other").GetComponent <UILabel>(); MyUtilTools.insertStr(other, friend.other, 250); UIButton other_button = other.GetComponent <UIButton>(); EventDelegate other_event = new EventDelegate(this, "doOpenOther"); other_event.parameters[0] = new EventDelegate.Parameter(); other_event.parameters[0].obj = friend; other_button.onClick.Add(other_event); UIButton sure = pass_obj.transform.FindChild("sure").GetComponent <UIButton>(); EventDelegate sure_event = new EventDelegate(this, "doFriendPass"); sure_event.parameters[0] = new EventDelegate.Parameter(); sure_event.parameters[0].obj = friend; sure.onClick.Add(sure_event); UIButton cancle = pass_obj.transform.FindChild("cancle").GetComponent <UIButton>(); EventDelegate cancle_event = new EventDelegate(this, "doFriendRefuse"); cancle_event.parameters[0] = new EventDelegate.Parameter(); cancle_event.parameters[0].obj = friend; cancle.onClick.Add(cancle_event); UILabel time = pass_obj.transform.FindChild("time").GetComponent <UILabel>(); time.text = friend.time; pass_obj.transform.localPosition = new Vector3(0, starty, 0); starty -= len; } }
void refreshMain() { Transform list = transform.FindChild("list"); Transform body = list.FindChild("body"); Transform container = body.FindChild("container"); body.GetComponent <UIPanel>().clipOffset = Vector2.zero; body.localPosition = Vector3.zero; UILabel countLabel = container.FindChild("new").FindChild("Label").GetComponent <UILabel>(); countLabel.text = "新朋友([00ff00]" + getNewCount() + "[-])"; MyUtilTools.clearChild(messageListContainer); List <MainData.FriendBody> friends = getListByType(1); float starty = 0, len = 100; //好友数据 for (int i = 0; i < friends.Count; i++) { MainData.FriendBody friend = friends[i]; GameObject message_obj = NGUITools.AddChild(messageListContainer.gameObject, pref_message); message_obj.name = "message" + i; message_obj.AddComponent <FriendListUpdate>().friend = friend; UISprite icon = message_obj.transform.FindChild("icon").GetComponent <UISprite>(); icon.spriteName = friend.fFace; FriendListDelete delete = icon.gameObject.AddComponent <FriendListDelete>();//长安删除逻辑 delete.friendEvent = this; delete.friend = friend; UILabel name = message_obj.transform.FindChild("name").GetComponent <UILabel>(); name.text = friend.fName; Transform content = message_obj.transform.FindChild("content"); UIButton content_button = content.GetComponent <UIButton>(); EventDelegate button_delegate = new EventDelegate(this, "openMessage"); button_delegate.parameters[0] = new EventDelegate.Parameter(); button_delegate.parameters[0].obj = friend; content_button.onClick.Add(button_delegate); message_obj.transform.localPosition = new Vector3(0, starty, 0); starty -= len; } }
public void search() { UIInput input = transform.FindChild("list").FindChild("body").FindChild("container").FindChild("search").FindChild("inputer").GetComponent <UIInput>(); if (MyUtilTools.stringIsNull(input.value)) { DialogUtil.tip("请输入要查找的用户的昵称或者手机号"); return; } bool needNet = true; List <MainData.FriendBody> friends = MainData.instance.user.friends; MainData.FriendBody target = null; for (int i = 0; i < friends.Count; i++) { MainData.FriendBody friend = friends[i]; if (friend.fName.Equals(input.value) || friend.account.Equals(input.value)) { needNet = false; target = friend; break; } } if (needNet) { ByteBuffer buffer = ByteBuffer.Allocate(1024); buffer.skip(4); buffer.WriteString("FriendSearch"); buffer.WriteString(input.value);//内容 NetUtil.getInstance.SendMessage(buffer); } else { string resultStr = "2" + "," + target.fName; openSearchResult(resultStr, target); } }
void Update() { if (messageListContainer.parent.parent.parent.gameObject.activeSelf) { List <MainData.FriendBody> friends = MainData.instance.user.friends; int count = 0; for (int i = 0; i < friends.Count;) { MainData.FriendBody friend = friends[i]; if (friend.pass == 1) { if (friend.flag == JustRun.DEL_FLAG) { friends.RemoveAt(i); continue; } count++; } i++; } if (count != messageListContainer.childCount) { refreshMain(); } } if (passContainer.parent.parent.gameObject.activeSelf) { List <MainData.FriendBody> friends = MainData.instance.user.friends; int count = 0; for (int i = 0; i < friends.Count;) { MainData.FriendBody friend = friends[i]; if (friend.pass == 0) { if (friend.flag == JustRun.DEL_FLAG) { friends.RemoveAt(i); continue; } count++; } i++; } if (count != passContainer.childCount) { refreshNew(); } if (MyUtilTools.tryToLogic("FriendPass") != null || count == 0) { backToCenter(); } } ByteBuffer buffer = MyUtilTools.tryToLogic("FriendDel"); if (buffer != null) { string tip = buffer.ReadString(); DialogUtil.tip(tip, true); } buffer = MyUtilTools.tryToLogic("FriendApply"); if (buffer != null) { string tip = buffer.ReadString(); DialogUtil.tip(tip, true); } buffer = MyUtilTools.tryToLogic("FriendSearch"); if (buffer != null) { string result = buffer.ReadString(); openSearchResult(result, null); } }