// Constructor public FriendAddWindow(string nText, string nFriendName, FriendsGroup nGroup = null, FriendAddCallBack nYes = null, CallBack nNo = null) : base(nText, nYes, nNo) { // Default group if (nGroup == null) { nGroup = PlayerAccount.mine.friends.groups[0]; } // Default callback if (nYes == null) { accept = (name, toGroup) => { LogManager.General.Log(string.Format("Adding player '{0}' to friends list group {1}", name, toGroup.name)); Lobby.RPC("AddFriend", Lobby.lobby, name, toGroup.name); }; } friendName = nFriendName; group = nGroup; friendNameFocused = false; acceptText = "Add"; cancelText = "Cancel"; popupWindowHash = "FriendAddWindow".GetHashCode(); this.Init(); }
// Draw friend void DrawFriend(FriendsGroup friendsGroup, Friend friend) { if (string.IsNullOrEmpty(friend.accountId)) { LogManager.General.LogError("FriendsGUI: Account ID is empty"); return; } // TODO: ... var account = PlayerAccount.Get(friend.accountId); string playerName = account.playerName; if (string.IsNullOrEmpty(playerName)) { return; } // New row using (new GUIHorizontal()) { // Draw the player name DrawPlayerName(playerName, new GUIContent(playerName), friendNameStyle); // Space GUILayout.FlexibleSpace(); // Note noteContent.tooltip = friend.note; if (GUIHelper.Button(noteContent)) { new TextAreaWindow( _("Note for player <b>{0}</b>:", playerName), friend.note, newNote => { friend.note = newNote; Lobby.RPC("SetFriendNote", Lobby.lobby, playerName, friendsGroup.name, newNote); } ); } // Remove friend if (GUIHelper.Button(removeFriendContent)) { new Confirm( _("Do you really want to remove <b>{0}</b> from your friends list?", playerName), () => { Lobby.RPC("RemoveFriend", Lobby.lobby, playerName, friendsGroup.name); } ); } } }
// Draw friends group void DrawFriendsGroup(FriendsGroup friendsGroup) { // Header using (new GUIHorizontal(groupHeaderStyle)) { GUI.color = friendsGroup.color; GUILayout.Label(friendsGroup.name, groupNameStyle); GUI.color = Color.white; GUILayout.FlexibleSpace(); // Add friend if (GUIHelper.Button(addFriendContent)) { new FriendAddWindow( "Add a friend:", "", friendsGroup ); } // Remove group if (GUIHelper.Button(removeGroupContent)) { new Confirm( _("Do you really want to remove the group <b>{0}</b>? All friends in this group will be deleted from your list.", friendsGroup.name), () => { LogManager.General.Log(_("Removed friends list group {0}", friendsGroup.name)); Lobby.RPC("RemoveFriendsGroup", Lobby.lobby, friendsGroup.name); friendsList.RemoveGroup(friendsGroup.name); } ); } } // Draw friends in this group using (new GUIVertical("box")) { if (friendsGroup.friends.Count == 0) { GUILayout.Label("This group doesn't have any contacts yet.", friendNameStyle); } else { foreach (var friend in friendsGroup.friends) { DrawFriend(friendsGroup, friend); } } } }