void GenerateList(string filter) { var children = new List <GameObject>(); foreach (Transform child in PlayerPanel.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); PlayerPanel.Enable(); IEnumerable <Player> filtered = users.Where(t => t.Username.ToLower().Contains(filter.ToLower())) .OrderByDescending(t => pinnedPlayers.Any(u => u.ObjectId.Equals(t.ObjectId))).ThenBy(t => t.Username); foreach (Player player in filtered) { // GameObject ListItem = Instantiate(Resources.Load("List Item")) as GameObject; dfPanel listItem = PlayerPanel.AddPrefab(ListItem) as dfPanel; // as UserListItem; listItem.Width = PlayerPanel.Width - PlayerPanel.FlowPadding.left - PlayerPanel.FlowPadding.right; listItem.Click += new MouseEventHandler(listItem_Click); ListItemExtras extras = listItem.GetComponent <ListItemExtras>(); extras.Player = player; dfLabel username = listItem.Find("Username Label").GetComponent <dfLabel>(); username.Text = player.Username; username.DisabledColor = new Color32(100, 100, 100, 255); dfSprite onlineSprite = listItem.Find("Online Sprite").GetComponent <dfSprite>(); if (player.IsOnline) { onlineSprite.SpriteName = "OUYA_O 24px"; } else { onlineSprite.SpriteName = "OUYA_A 24px"; } dfButton actionButton = listItem.Find("Action Button").GetComponent <dfButton>(); bool f = pinnedPlayers.Any(t => t.ObjectId.Equals(player.ObjectId)); if (f) { actionButton.Text = "Unpin"; // listItem.BackgroundColor = new Color32(200, 255, 200, 255); listItem.BackgroundColor = new Color32(255, 255, 255, 255); actionButton.Click += new MouseEventHandler(actionButtonUnpin_Click); } else { actionButton.Text = "Pin"; actionButton.Click += new MouseEventHandler(actionButtonPin_Click); } } }
void listItem_Click(dfControl control, dfMouseEventArgs mouseEvent) { ListItemExtras parent = control.GetComponent <ListItemExtras>(); print("Name: " + parent.Player.Username); InvitePanel.InvitePlayer(parent.Player); }
void actionClick_remove(dfControl control, dfMouseEventArgs mouseEvent) { ListItemExtras parent = control.transform.parent.gameObject.GetComponent <ListItemExtras>(); Task deleteTask = parent.FriendRequest.DeleteAsync(); StartCoroutine(WaitForRequest(deleteTask)); }
void actionClick_accept(dfControl control, dfMouseEventArgs mouseEvent) { ListItemExtras parent = control.transform.parent.gameObject.GetComponent <ListItemExtras>(); parent.FriendRequest[STATUS] = S_ACCEPTED; Task saveTask = parent.FriendRequest.SaveAsync(); StartCoroutine(WaitForRequest(saveTask)); }
void actionButtonPin_Click(dfControl control, dfMouseEventArgs mouseEvent) { mouseEvent.Use(); ListItemExtras parent = control.transform.parent.gameObject.GetComponent <ListItemExtras>(); pinnedPlayers.Add(parent.Player); SavePinnedPlayers(pinnedPlayers); FilterText = false; FilterTextbox.Text = "Filter users..."; FilterText = true; GenerateList(""); }
void actionClick_add(dfControl control, dfMouseEventArgs mouseEvent) { ListItemExtras parent = control.transform.parent.gameObject.GetComponent <ListItemExtras>(); print("Username: " + parent.Player.Username); ParseObject request = new ParseObject(FRIEND_REQUEST); request[REQUEST_FROM] = Player.CurrentUser; request[REQUEST_TO] = parent.Player; request[STATUS] = S_PENDING; parent.FriendRequest = request; Task saveTask = request.SaveAsync(); StartCoroutine(WaitForRequest(saveTask)); }
void actionButtonUnpin_Click(dfControl control, dfMouseEventArgs mouseEvent) { mouseEvent.Use(); ListItemExtras parent = control.transform.parent.gameObject.GetComponent <ListItemExtras>(); var p = pinnedPlayers.Where(t => t.ObjectId.Equals(parent.Player.ObjectId)).FirstOrDefault(); if (p != null) { pinnedPlayers.Remove(p); } else { print("p is null"); } SavePinnedPlayers(pinnedPlayers); FilterText = false; FilterTextbox.Text = "Filter users..."; FilterText = true; GenerateList(""); }
void GenerateList(string filter) { //Player current = Player.CurrentUser as Player; //current.Get<string>("email"); //IList<Player> players = null; //try //{ // players = current.Get<IList<Player>>("pinnedPlayers"); //} //catch (Exception e) //{ //} //if (players == null) //{ // print("players is null"); // players = new List<Player>() { users.LastOrDefault() }; //} //print("count " + players.Count); //players.Add(users.FirstOrDefault()); //current["pinnedPlayers"] = players; //current.SaveAsync(); //current.PinnedPlayers.FetchAllAsync().ContinueWith(t => //{ // if (current.PinnedPlayers != null) // { // foreach (Player p in current.PinnedPlayers) // { // print("Player: " + p.Username); // } // } // current.PinnedPlayers.Add(users.LastOrDefault()); // current.SaveAsync(); // print("Saving pinnedPlayers"); //}); var children = new List <GameObject>(); foreach (Transform child in UserPanel.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); UserPanel.Enable(); IEnumerable <Player> filtered = users.Where(t => t.Username.ToLower().Contains(filter.ToLower())).OrderByDescending(t => t.ObjectId.Equals(Player.CurrentUser.ObjectId)) .ThenByDescending(t => friendList.Contains(t.ObjectId)); foreach (Player player in filtered) { ParseObject friend = null; if (friends != null) { friend = friends.Where(t => ((Player)t[REQUEST_FROM]).ObjectId.Equals(player.ObjectId) || ((Player)t[REQUEST_TO]).ObjectId.Equals(player.ObjectId)).FirstOrDefault(); // friend = friends.FirstOrDefault(); // print("Friend: " + ((Player)friend[REQUEST_TO]).ObjectId); // print("Player: " + player.ObjectId); } // GameObject ListItem = Instantiate(Resources.Load("List Item")) as GameObject; dfPanel listItem = UserPanel.AddPrefab(ListItem) as dfPanel; // as UserListItem; listItem.Width = UserPanel.Width - UserPanel.FlowPadding.left - UserPanel.FlowPadding.right; ListItemExtras extras = listItem.GetComponent <ListItemExtras>(); extras.Player = player; extras.FriendRequest = friend; dfLabel username = listItem.Find("Username Label").GetComponent <dfLabel>(); username.Text = player.Username; username.DisabledColor = new Color32(100, 100, 100, 255); dfLabel email = listItem.Find("Email label").GetComponent <dfLabel>(); email.Text = player.Email; email.DisabledColor = new Color32(100, 100, 100, 255); dfSprite onlineSprite = listItem.Find("Online Sprite").GetComponent <dfSprite>(); if (player.IsOnline) { onlineSprite.SpriteName = "OUYA_O 24px"; } else { onlineSprite.SpriteName = "OUYA_A 24px"; } dfButton actionButton = listItem.Find("Action Button").GetComponent <dfButton>(); if (friend == null) { actionButton.Text = "Add"; actionButton.Click += new MouseEventHandler(actionClick_add); } else { string status = friend[STATUS] as string; Player from = friend[REQUEST_FROM] as Player; if (Player.CurrentUser.ObjectId.Equals(from.ObjectId)) { switch (status) { case S_ACCEPTED: actionButton.Text = "Remove"; actionButton.Click += new MouseEventHandler(actionClick_remove); listItem.BackgroundColor = new Color32(200, 255, 200, 255); break; case S_REJECTED: actionButton.Text = "Sorry"; break; case S_PENDING: actionButton.Text = "Pending"; actionButton.Disable(); break; } } else { switch (status) { case S_ACCEPTED: actionButton.Text = "Remove"; actionButton.Click += new MouseEventHandler(actionClick_remove); listItem.BackgroundColor = new Color32(200, 255, 200, 255); break; case S_REJECTED: actionButton.Text = "Rejected"; break; case S_PENDING: actionButton.Text = "Accept"; actionButton.Click += new MouseEventHandler(actionClick_accept); break; } } } if (player.Username.Equals(Player.CurrentUser.Username)) { actionButton.Hide(); } } }