private IMenuItem CreateUserBlock(string username, ChatObj chat) { MenuItemGrid item = new MenuItemGrid(username, 5, 3); MenuItemText usernameBlock = new MenuItemText("username"); item.AddChild(0, 0, 4, 1, usernameBlock); usernameBlock.SetText(username); usernameBlock.SetFontSize(8, 15); usernameBlock.SetTextStyle(UnityEngine.FontStyle.Bold); MenuItemText lastMsgBlock = new MenuItemText("lastMsg"); item.AddChild(0, 1, 4, 2, lastMsgBlock); string text = chat.Messages.Last().Message; if (text.Length > MAX_MSG_LEN) { text = text.Substring(0, MAX_MSG_LEN - 3); text += "..."; } lastMsgBlock.SetText(text); lastMsgBlock.SetFontSize(5, 10); lastMsgBlock.SetAlignment(UnityEngine.TextAnchor.MiddleLeft); MenuItemButton openChat = new MenuItemButton("openChat"); item.AddChild(4, 0, 1, 3, openChat); openChat.SetText(">"); openChat.Clicked += () => ChatSelected?.Invoke(chat); return(item); }
private void InitMenuItems() { _root = new MenuItemGrid("chatAppGrid", 6, 1); MenuItemGrid leftGrid = new MenuItemGrid("leftPanelGrid", 1, 7); _root.AddChild(0, 0, 1, 1, leftGrid); _root.AddChild(1, 0, 5, 1, _chatBlock.GetRoot()); MenuItemGrid leftPanelTabs = new MenuItemGrid("leftPanelTabs", 2, 1); leftGrid.AddChild(0, 0, 1, 1, leftPanelTabs); MenuItemText recentText = new MenuItemText("recentText"); recentText.SetText("Recent"); recentText.SetFontSize(5, 20); recentText.SetAlignment(UnityEngine.TextAnchor.MiddleCenter); leftPanelTabs.AddChild(0, 0, 1, 1, recentText); MenuItemText friendsText = new MenuItemText("friendsText"); friendsText.SetText("Friends"); friendsText.SetFontSize(5, 20); friendsText.SetAlignment(UnityEngine.TextAnchor.MiddleCenter); leftPanelTabs.AddChild(1, 0, 1, 1, friendsText); leftPanelTabs.ItemClicked += OnLeftPanelTabClick; _leftPanel = leftGrid; }
private void RenderRoomList(List <Room> list) { _roomListGrid.RemoveChild(_loading); _loading.Dispose(); int i = 0; foreach (Room r in list) { if (i >= 10) { break; } MenuItemText roomName = new MenuItemText($"roomName{i}"); roomName.SetText(r.Name); roomName.SetFontSize(5, 15); _roomListGrid.AddChild(0, i, 3, 1, roomName); MenuItemText roomCapacity = new MenuItemText($"roomCapacity{i}"); roomCapacity.SetText($"{r.Players.Count}/{r.Capacity}"); roomCapacity.SetFontSize(5, 15); _roomListGrid.AddChild(3, i, 1, 1, roomCapacity); MenuItemButton connect = new MenuItemButton($"roomConnect{i}"); connect.SetText("Connect"); connect.Clicked += () => ConnectRoom(r); _roomListGrid.AddChild(4, i, 2, 1, connect); i++; } }
private void RenderPage(int pageNum) { if (_friends == null) { Refresh(); } _root.GetChildren().ForEach(x => x.Dispose()); _root.Clear(); for (int i = 0; i <= ROWS; ++i) { if (pageNum * ROWS + i >= _friends.Count) { break; } FriendsAppUser friend = _friends[pageNum * ROWS + i]; MenuItemText username = new MenuItemText($"username{friend.UserId}"); username.SetText(friend.Username); _root.AddChild(0, i, 3, 1, username); if (friend.CurrentRoomId.HasValue) { MenuItemButton connectBtn = new MenuItemButton($"connect{friend.UserId}"); connectBtn.SetText("Connect"); connectBtn.Clicked += () => { _api.DefaultApps.RoomList.ChangeRoom(friend.CurrentRoomId.Value); }; _root.AddChild(3, i, 1, 1, connectBtn); } MenuItemButton removeFriend = new MenuItemButton($"remove{friend.UserId}"); removeFriend.SetText("Remove"); removeFriend.Clicked += () => { _api.DefaultApps.Friends.RemoveFriend(friend.UserId).Wait(); Refresh(); }; _root.AddChild(4, i, 1, 1, removeFriend); } if (pageNum > 0) { MenuItemButton prevPage = new MenuItemButton("prevPage"); prevPage.SetText("<"); prevPage.Clicked += () => { RenderPage(pageNum - 1); }; _root.AddChild(0, ROWS, 1, 1, prevPage); } if ((pageNum + 1) * ROWS < _friends.Count) { MenuItemButton nextPage = new MenuItemButton("nextPage"); nextPage.SetText(">"); nextPage.Clicked += () => { RenderPage(pageNum + 1); }; _root.AddChild(4, ROWS, 1, 1, nextPage); } }
public IMenuItem CreateMessageObj(ChatObjMsg msg) { int lines = (int)Math.Ceiling(msg.Message.Length / (float)CHARS_PER_LINE) + 1; MenuItemGrid item = new MenuItemGrid(msg.Time.ToString(), 1, lines); MenuItemText header = new MenuItemText("header"); item.AddChild(0, 0, 1, 1, header); header.SetTextStyle(FontStyle.Bold); header.SetFontSize(5, HEADER_FONT_SIZE); TextAnchor alignment; if (msg.From == _userId) { alignment = TextAnchor.MiddleRight; header.SetText("You"); } else { alignment = TextAnchor.MiddleLeft; header.SetText(_toUsername); } header.SetAlignment(alignment); string text = msg.Message; int i; string textPart; MenuItemText message; for (i = 0; i < lines - 2; ++i) { textPart = text.Substring(i * CHARS_PER_LINE, CHARS_PER_LINE); message = new MenuItemText($"message_line{i+1}"); message.SetFontSize(5, FONT_SIZE); message.SetText(textPart); message.SetAlignment(alignment); item.AddChild(0, i + 1, 1, 1, message); } textPart = text.Substring(i * CHARS_PER_LINE); message = new MenuItemText($"message_line{i + 1}"); message.SetFontSize(5, FONT_SIZE); message.SetText(textPart); message.SetAlignment(alignment); item.AddChild(0, i + 1, 1, 1, message); return(item); }
private void RenderPage(int pageNum) { if (_requests == null) { Refresh(); } _root.GetChildren().ForEach(x => x.Dispose()); _root.Clear(); for (int i = 0; i <= ROWS; ++i) { if (pageNum * ROWS + i >= _requests.Count) { break; } FriendsAppUser user = _requests[pageNum * ROWS + i]; MenuItemText username = new MenuItemText($"username{user.UserId}"); username.SetText(user.Username); _root.AddChild(0, i, 3, 1, username); MenuItemButton acceptBtn = new MenuItemButton($"accept{user.UserId}"); acceptBtn.SetText("Accept"); acceptBtn.Clicked += () => { _api.DefaultApps.Friends.AcceptFriendRequest(user.UserId).Wait(); Refresh(); }; _root.AddChild(3, i, 1, 1, acceptBtn); MenuItemButton rejectBtn = new MenuItemButton($"reject{user.UserId}"); rejectBtn.SetText("Reject"); rejectBtn.Clicked += () => { _api.DefaultApps.Friends.DeleteFriendRequest(user.UserId).Wait(); Refresh(); }; _root.AddChild(4, i, 1, 1, rejectBtn); } if (pageNum > 0) { MenuItemButton prevPage = new MenuItemButton("prevPage"); prevPage.SetText("<"); prevPage.Clicked += () => { RenderPage(pageNum - 1); }; _root.AddChild(0, ROWS, 1, 1, prevPage); } if ((pageNum + 1) * ROWS < _requests.Count) { MenuItemButton nextPage = new MenuItemButton("nextPage"); nextPage.SetText(">"); nextPage.Clicked += () => { RenderPage(pageNum + 1); }; _root.AddChild(4, ROWS, 1, 1, nextPage); } }
private void RenderPage(int pageNum) { if (_friends == null || _users == null) { Refresh(); } _root.GetChildren().ForEach(x => x.Dispose()); _root.Clear(); for (int i = 0; i <= ROWS; ++i) { if (pageNum * ROWS + i >= _users.Count) { break; } UserDetailMsg user = _users[pageNum * ROWS + i]; MenuItemText username = new MenuItemText($"username{user.Username}"); username.SetText(user.Username); _root.AddChild(0, i, 3, 1, username); if (!_friends.Contains(user.UserId)) { MenuItemButton addFriend = new MenuItemButton($"addFriend{user.Username}"); addFriend.SetText("Add Friend"); addFriend.Clicked += () => { _api.DefaultApps.Friends.SendFriendRequest(user.UserId).Wait(); MenuItemText requestSent = new MenuItemText("requestSent"); _root.RemoveChild(addFriend); addFriend.Dispose(); _root.AddChild(3, i, 1, 1, requestSent); }; _root.AddChild(3, i, 1, 1, addFriend); } } if (pageNum > 0) { MenuItemButton prevPage = new MenuItemButton("prevPage"); prevPage.SetText("<"); prevPage.Clicked += () => { RenderPage(pageNum - 1); }; _root.AddChild(0, ROWS, 1, 1, prevPage); } if ((pageNum + 1) * ROWS < _users.Count) { MenuItemButton nextPage = new MenuItemButton("nextPage"); nextPage.SetText(">"); nextPage.Clicked += () => { RenderPage(pageNum + 1); }; _root.AddChild(3, ROWS, 1, 1, nextPage); } }
public void OpenChat(ChatObj chat) { _currChat = chat; _toUserId = chat.User1 == _userId ? chat.User2 : chat.User1; _toUsername = _api.DefaultApps.Friends.ListFriends().Wait().Find(x => x.UserId == _toUserId)?.Username; _headerItem.SetText(_toUsername); if (_toUsername == null) { _toUsername = "******"; } Rerender(); }
private IMenuItem CreateBlock(FriendsAppUser friend) { MenuItemGrid item = new MenuItemGrid(friend.Username, 5, 1); MenuItemText username = new MenuItemText("username"); item.AddChild(0, 0, 4, 1, username); username.SetText(friend.Username); username.SetFontSize(8, 15); username.SetTextStyle(UnityEngine.FontStyle.Bold); MenuItemButton selectButton = new MenuItemButton("selectButton"); item.AddChild(4, 0, 1, 1, selectButton); selectButton.SetText(">"); selectButton.Clicked += () => FriendSelected?.Invoke(friend.UserId); return(item); }
private void CreateMenuItems() { _root = new MenuItemGrid("roomListGrid", 7, 7); MenuItemText roomText = new MenuItemText("roomText"); roomText.SetText("Room List"); roomText.SetTextColor(Color.black); roomText.SetAlignment(TextAnchor.MiddleCenter); _root.AddChild(0, 0, 2, 1, roomText); MenuItemText searchText = new MenuItemText("searchText"); searchText.SetText("Search:"); searchText.SetAlignment(TextAnchor.LowerLeft); searchText.SetFontSize(5, 7); _root.AddChild(0, 2, 2, 1, searchText); MenuItemInput searchInput = new MenuItemInput("searchInput"); searchInput.SetPlaceholder("Name..."); _root.AddChild(0, 3, 2, 1, searchInput); searchInput.SetPadding(10f, 0f, 10f, 10f); MenuItemCheckbox notEmpty = new MenuItemCheckbox("notEmpty"); notEmpty.SetValue(false); notEmpty.SetText("Filter empty"); _root.AddChild(0, 4, 2, 1, notEmpty); notEmpty.SetPadding(10f, 6f); MenuItemCheckbox notFull = new MenuItemCheckbox("notFull"); notFull.SetValue(false); notFull.SetText("Filter full"); _root.AddChild(0, 5, 2, 1, notFull); notFull.SetPadding(10f, 6f); MenuItemButton filter = new MenuItemButton("filter"); filter.SetText("Filter"); filter.Clicked += () => { List <Room> roomList = GetRoomList(searchInput.GetText(), notEmpty.IsChecked(), notFull.IsChecked()); RenderRoomList(roomList); }; _root.AddChild(0, 6, 2, 1, filter); filter.SetPadding(20f, 4f); _roomListGrid = new MenuItemGrid("roomItems", 6, 10); _root.AddChild(2, 0, 5, 7, _roomListGrid); }
public void InitMenuItems() { _root = new MenuItemGrid("chatBlock", 1, 10); _headerItem = new MenuItemText("headerChat"); _root.AddChild(0, 0, 1, 1, _headerItem); _headerItem.SetText("None"); _headerItem.SetFontSize(2, 20); _headerItem.SetAlignment(UnityEngine.TextAnchor.MiddleLeft); _chatItem = new MenuItemScrollable("chatScrollable", UnityEngine.TextAnchor.LowerCenter); _root.AddChild(0, 1, 1, 7, _chatItem); _bottomBlock = new MenuItemGrid("bottomPartChatBlock", 5, 1); _root.AddChild(0, 8, 1, 2, _bottomBlock); _msgInput = new MenuItemInput("chatMsgInput"); _bottomBlock.AddChild(0, 0, 4, 1, _msgInput); _msgInput.SetPlaceholder("Message..."); _msgInput.SetLineType(UnityEngine.UI.InputField.LineType.MultiLineSubmit); _msgInput.onSubmit += OnSendClicked; _sendButton = new MenuItemButton("chatSendButton"); _bottomBlock.AddChild(4, 0, 1, 1, _sendButton); _sendButton.SetText("Send"); _sendButton.Clicked += OnSendClicked; }