InviteDlgUserItem.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using UnityEngine.UI;
  6. public class InviteDlgUserItem : MonoBehaviour
  7. {
  8. public TMP_Text itemName;
  9. public TMP_Text level;
  10. public Image stateImage;
  11. public TMP_Text stateText;
  12. public Image headImage;
  13. private InviteUserConfig inviteUserConfig;
  14. public Toggle toggle;
  15. private void Start()
  16. {
  17. toggle = transform.GetComponent<Toggle>();
  18. toggle.onValueChanged.AddListener((state) =>
  19. {
  20. OnValueChange(state);
  21. });
  22. }
  23. public void SetData(Sprite headImage, string level , InviteUserConfig userConfig)
  24. {
  25. if (headImage != null)
  26. this.headImage.sprite = headImage;
  27. itemName.text = userConfig.NickName;
  28. this.level.text = level;
  29. this.inviteUserConfig = userConfig;
  30. switch (userConfig.Online)
  31. {
  32. case "1":
  33. stateImage.color = Color.green;
  34. stateText.text = "在线";
  35. toggle.interactable = true;
  36. break;
  37. case "2":
  38. stateImage.color = Color.blue;
  39. stateText.text = "通话中";
  40. toggle.interactable = false;
  41. break;
  42. case "0":
  43. stateImage.color = Color.red;
  44. stateText.text = "离线";
  45. toggle.interactable = false;
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. public void ResetData()
  52. {
  53. itemName.text = "韩风";
  54. this.level.text = "组长";
  55. stateImage.color = Color.red;
  56. stateText.text = "离线";
  57. inviteUserConfig = null;
  58. }
  59. private void OnValueChange(bool isOn)
  60. {
  61. if (InviteDlg.Instance && inviteUserConfig != null)
  62. {
  63. if (isOn)
  64. {
  65. InviteDlg.Instance.InviteUnionIdList.Add(inviteUserConfig);
  66. if (InviteDlg.Instance.InviteUnionIdList.Count > 0)
  67. {
  68. InviteDlg.Instance.RecoverInviteBtn();
  69. }
  70. }
  71. else
  72. {
  73. if (InviteDlg.Instance.InviteUnionIdList.Contains(inviteUserConfig))
  74. {
  75. InviteDlg.Instance.InviteUnionIdList.Remove(inviteUserConfig);
  76. }
  77. if (InviteDlg.Instance.InviteUnionIdList.Count <= 0)
  78. {
  79. InviteDlg.Instance.InitInviteBtn();
  80. }
  81. }
  82. }
  83. }
  84. }