PlazaRoomItem.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.GetTimeFromSecends(arg.GetLong(StartTimeLabel).ToString());
  49. EndTime = DateUtil.GetTimeFromSecends(arg.GetLong(EndTimeLabel).ToString());
  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 = ResourceManager.Get(ResourceLabel.PlazaRoomItem, Folder.UI, false, ResourceManager.Get(ObjectLabel.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.IsSystemRoom)
  138. {
  139. LanguageManager.Add(Name, new MulLanStr(LanguageLabel.UI__Z_SystemRoomName));
  140. }
  141. else
  142. {
  143. Name.text = RoomData.Name;
  144. }
  145. if (RoomData.IsSystemRoom)
  146. {
  147. LanguageManager.Add(Duration, new MulLanStr(LanguageLabel.UI__Z_Permanent));
  148. }
  149. else
  150. {
  151. Duration.text = RoomData.Duration.ToString();
  152. }
  153. RefreshStatus(true);
  154. Button.onClick.RemoveAllListeners();
  155. Button.onClick.AddListener
  156. (
  157. () =>
  158. {
  159. OnJoinBtn(roomData);
  160. }
  161. );
  162. return this;
  163. }
  164. public void RefreshStatus(bool available)
  165. {
  166. if (available)
  167. {
  168. LanguageManager.Add(People, new MulLanStr(LanguageLabel.UI__Z_Available));
  169. People.color = Lib.RoomRunning;
  170. Button.image.material = null;
  171. LanguageManager.Add(ButtonLab, new MulLanStr(LanguageLabel.UI__Z_Join));
  172. }
  173. else
  174. {
  175. LanguageManager.Add(People, new MulLanStr(LanguageLabel.UI__Z_Full));
  176. People.color = Lib.RoomClosing;
  177. Button.image.material = Lib.GrayMat;
  178. LanguageManager.Add(ButtonLab, new MulLanStr(LanguageLabel.UI__Z_Full));
  179. }
  180. if (RoomData.RemainTime.TotalMinutes > 10)
  181. {
  182. LanguageManager.Add(Status, new MulLanStr(LanguageLabel.UI__Z_Running));
  183. Status.color = Lib.RoomRunning;
  184. }
  185. else
  186. {
  187. LanguageManager.Add(Status, new MulLanStr(LanguageLabel.UI__Z_Closing));
  188. Status.color = Lib.RoomClosing;
  189. }
  190. }
  191. public static void OnJoinBtn(RoomData roomData)
  192. {
  193. AudioManager.PlayClip(Clip.BtnClip);
  194. SFSManager.GardenSmartFox.PlazaRoomController.BeginEnterPlazaRoom(roomData);
  195. SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.JoinPlazaRoom(roomData.ID);
  196. }
  197. }