PlazaRoomItem.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Sfs2X.Entities;
  5. using Sfs2X.Entities.Data;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class RoomData
  9. {
  10. #region Config
  11. private static string IDLabel = "i";
  12. private static string OwnerLabel = "o";
  13. private static string DurationLabel = "d";
  14. private static string MaxPlayerLabel = "m";
  15. private static string NameLabel = "n";
  16. private static string StartTimeLabel = "s";
  17. private static string EndTimeLabel = "e";
  18. public TimeSpan RemainTime
  19. {
  20. get
  21. {
  22. if (IsSystemRoom)
  23. {
  24. return new TimeSpan(1, 0, 0, 0);
  25. }
  26. else
  27. {
  28. return EndTime.Subtract(StartTime);
  29. }
  30. }
  31. }
  32. public int ID;
  33. public int Duration;
  34. public int MaxPlayer;
  35. public long Owner;
  36. public bool IsSystemRoom;
  37. public string Name;
  38. public DateTime StartTime;
  39. public DateTime EndTime;
  40. #endregion
  41. public RoomData(ISFSObject arg)
  42. {
  43. ID = arg.GetInt(IDLabel);
  44. Owner = arg.GetLong(OwnerLabel);
  45. Duration = arg.GetInt(DurationLabel);
  46. MaxPlayer = arg.GetInt(MaxPlayerLabel);
  47. Name = arg.GetUtfString(NameLabel);
  48. StartTime = DateUtil.GetTime(arg.GetClass(StartTimeLabel).ToString().TrimEnd('0'));
  49. EndTime = DateUtil.GetTime(arg.GetClass(EndTimeLabel).ToString().TrimEnd('0'));
  50. if (ID == 1)
  51. IsSystemRoom = true;
  52. //Debug.Log(ID);
  53. //Debug.Log(Owner);
  54. //Debug.Log(Duration);
  55. //Debug.Log(MaxPlayer);
  56. //Debug.Log(Name);
  57. //Debug.Log(StartTime);
  58. //Debug.Log(EndTime);
  59. //Debug.Log(RemainHour);
  60. //Debug.Log(IsSystemRoom);
  61. }
  62. public PlazaRoomItem CreateItem()
  63. {
  64. PlazaRoomItem plazaRoomItem = ManaReso.Get("PlazaRoomItem", Folder.UI, false, ManaReso.Get("Z_Grid"), false, ObjType.PlazaRoomItem, typeof(PlazaRoomItem)).GetComponent<PlazaRoomItem>();
  65. plazaRoomItem.Regist();
  66. return plazaRoomItem;
  67. }
  68. public static bool operator ==(RoomData r1, RoomData r2)
  69. {
  70. if (r1.ID == r2.ID)
  71. {
  72. return true;
  73. }
  74. else
  75. {
  76. return false;
  77. }
  78. }
  79. public static bool operator !=(RoomData r1, RoomData r2)
  80. {
  81. return !(r1 == r2);
  82. }
  83. public override bool Equals(object obj)
  84. {
  85. return this == (RoomData) obj;
  86. }
  87. public override int GetHashCode()
  88. {
  89. return ID.GetHashCode();
  90. }
  91. }
  92. public class PlazaRoomItem : MonoBehaviour
  93. {
  94. #region Config
  95. public bool Registed;
  96. public RoomData RoomData;
  97. public Text ID;
  98. public Text Name;
  99. public Text Status;
  100. public Text Duration;
  101. public Text People;
  102. public Text ButtonLab;
  103. public Image Img0;
  104. public Button Button;
  105. #endregion
  106. public void Regist()
  107. {
  108. if (Registed)
  109. return;
  110. else
  111. Registed = true;
  112. Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
  113. Auxiliary.CompileDic(transform, dictionary);
  114. ID = dictionary["ID"].GetComponent<Text>();
  115. Name = dictionary["Name"].GetComponent<Text>();
  116. Status = dictionary["Status"].GetComponent<Text>();
  117. Duration = dictionary["Duration"].GetComponent<Text>();
  118. People = dictionary["People"].GetComponent<Text>();
  119. Img0 = dictionary["Img0"].GetComponent<Image>();
  120. Button = dictionary["Btn"].GetComponent<Button>();
  121. ButtonLab = dictionary["BtnLab"].GetComponent<Text>();
  122. }
  123. public PlazaRoomItem Init(RoomData roomData)
  124. {
  125. RoomData = roomData;
  126. if (RoomData.IsSystemRoom)
  127. {
  128. ID.SetActive(false);
  129. Img0.SetActive(true);
  130. }
  131. else
  132. {
  133. ID.SetActive(true);
  134. Img0.SetActive(false);
  135. ID.text = RoomData.ID.ToString();
  136. }
  137. if (RoomData.RemainTime.TotalMinutes > 10)
  138. {
  139. ManaLan.Add(Status, new LanStr("UI", "Z_Running"));
  140. Status.color = Lib.RoomRunning;
  141. }
  142. else
  143. {
  144. ManaLan.Add(Status, new LanStr("UI", "Z_Closing"));
  145. Status.color = Lib.RoomClosing;
  146. }
  147. Name.text = RoomData.Name;
  148. Duration.text = RoomData.Duration.ToString();
  149. //foreach (var VARIABLE in GardenSmartFoxManager.GardenSmartFox.SmartFox.GetRoomListFromGroup("default"))
  150. //{
  151. // Debug.Log(VARIABLE.Id);
  152. //}
  153. Room room = GardenSmartFoxManager.GardenSmartFox.SmartFox.GetRoomById(RoomData.ID);
  154. if (room == null || room.UserCount < room.MaxUsers)
  155. {
  156. ManaLan.Add(People, new LanStr("UI", "Z_Available"));
  157. People.color = Lib.RoomRunning;
  158. Button.image.material = null;
  159. ManaLan.Add(ButtonLab, new LanStr("UI", "Z_Join"));
  160. }
  161. else
  162. {
  163. ManaLan.Add(People, new LanStr("UI", "Z_Full"));
  164. People.color = Lib.RoomClosing;
  165. Button.image.material = Lib.GrayMat;
  166. ManaLan.Add(ButtonLab, new LanStr("UI", "Z_Full"));
  167. }
  168. return this;
  169. }
  170. }