/** * Initializes interface when buddy list data is received. */ private void OnBuddyListInit(BaseEvent evt) { // Populate list of buddies OnBuddyListUpdate(evt); // Set current user details as buddy // Nick nickInput.text = (sfs.BuddyManager.MyNickName != null ? sfs.BuddyManager.MyNickName : ""); // States foreach (string state in sfs.BuddyManager.BuddyStates) { string stateValue = state; GameObject newDropDownItem = Instantiate(stateItemPrefab) as GameObject; BuddyStateItemButton stateItem = newDropDownItem.GetComponent <BuddyStateItemButton>(); stateItem.stateValue = stateValue; stateItem.label.text = stateValue; stateItem.button.onClick.AddListener(() => OnStateItemClick(stateValue)); newDropDownItem.transform.SetParent(stateDropDown, false); // Set current state if (sfs.BuddyManager.MyState == state) { OnStateItemClick(state); } } // Online onlineToggle.isOn = sfs.BuddyManager.MyOnlineState; // Buddy variables BuddyVariable age = sfs.BuddyManager.GetMyVariable(BUDDYVAR_AGE); ageInput.text = ((age != null && !age.IsNull()) ? Convert.ToString(age.GetIntValue()) : ""); BuddyVariable mood = sfs.BuddyManager.GetMyVariable(BUDDYVAR_MOOD); moodInput.text = ((mood != null && !mood.IsNull()) ? mood.GetStringValue() : ""); }
/** * Populates the buddy list. */ private void OnBuddyListUpdate(BaseEvent evt) { // Remove current list content for (int i = buddyListContent.childCount - 1; i >= 0; --i) { GameObject.Destroy(buddyListContent.GetChild(i).gameObject); } buddyListContent.DetachChildren(); // Recreate list content foreach (Buddy buddy in sfs.BuddyManager.BuddyList) { GameObject newListItem = Instantiate(buddyListItemPrefab) as GameObject; BuddyListItem buddylistItem = newListItem.GetComponent <BuddyListItem>(); // Nickname buddylistItem.mainLabel.text = (buddy.NickName != null && buddy.NickName != "") ? buddy.NickName : buddy.Name; // Age BuddyVariable age = buddy.GetVariable(BuddyMessenger.BUDDYVAR_AGE); buddylistItem.mainLabel.text += (age != null && !age.IsNull()) ? " (" + age.GetIntValue() + " yo)" : ""; // Mood BuddyVariable mood = buddy.GetVariable(BuddyMessenger.BUDDYVAR_MOOD); buddylistItem.moodLabel.text = (mood != null && !mood.IsNull()) ? mood.GetStringValue() : ""; // Icon if (buddy.IsBlocked) { buddylistItem.stateIcon.sprite = IconBlocked; buddylistItem.chatButton.interactable = false; buddylistItem.blockButton.transform.GetChild(0).GetComponentInChildren <Image>().sprite = IconUnblock; } else { buddylistItem.blockButton.transform.GetChild(0).GetComponentInChildren <Image>().sprite = IconBlock; if (!buddy.IsOnline) { buddylistItem.stateIcon.sprite = IconOffline; buddylistItem.chatButton.interactable = false; } else { string state = buddy.State; if (state == "Available") { buddylistItem.stateIcon.sprite = IconAvailable; } else if (state == "Away") { buddylistItem.stateIcon.sprite = IconAway; } else if (state == "Occupied") { buddylistItem.stateIcon.sprite = IconOccupied; } } } // Buttons string buddyName = buddy.Name; // Required or the listeners will always receive the last buddy name buddylistItem.removeButton.onClick.AddListener(() => OnRemoveBuddyButtonClick(buddyName)); buddylistItem.blockButton.onClick.AddListener(() => OnBlockBuddyButtonClick(buddyName)); buddylistItem.chatButton.onClick.AddListener(() => OnChatBuddyButtonClick(buddyName)); buddylistItem.buddyName = buddyName; // Add item to list newListItem.transform.SetParent(buddyListContent, false); // Also update chat panel if open Transform panel = chatPanelsContainer.Find(buddyName); if (panel != null) { ChatPanel chatPanel = panel.GetComponent <ChatPanel>(); chatPanel.buddy = buddy; } } }