serverbrowserdetailscontainer.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. class ServerBrowserDetailsContainer extends ScriptedWidgetEventHandler
  2. {
  3. protected ServerBrowserTab m_Tab;
  4. protected Widget m_Root;
  5. protected TextWidget m_ServerNameText;
  6. protected TextWidget m_ServerTypeResult;
  7. protected TextWidget m_ServerModeResult;
  8. protected TextWidget m_LastCharacterResult;
  9. protected TextWidget m_ServerIP;
  10. #ifdef PLATFORM_WINDOWS
  11. #ifndef PLATFORM_CONSOLE
  12. protected GridSpacerWidget m_FriendsContainer;
  13. protected TextWidget m_FriendsResult;
  14. #endif
  15. #endif
  16. protected TextWidget m_TimeAccelerationResult;
  17. protected ImageWidget m_TimeIcon;
  18. protected TextWidget m_BattleyeResult;
  19. protected WrapSpacerWidget m_VersionContainer;
  20. protected TextWidget m_VersionResult;
  21. protected GridSpacerWidget m_ServerDecContainer;
  22. protected MultilineTextWidget m_ServerDesc;
  23. protected WrapSpacerWidget m_DetailsContainerRight;
  24. protected ImageWidget m_MapImage;
  25. protected ButtonWidget m_BtnShowFilters;
  26. protected ButtonWidget m_RefreshList;
  27. protected bool m_IsOnline;
  28. void ServerBrowserDetailsContainer(Widget root, ServerBrowserTab parent)
  29. {
  30. m_Root = root;
  31. m_Tab = parent;
  32. m_ServerNameText = TextWidget.Cast(root.FindAnyWidget("details_servername_label"));
  33. m_ServerTypeResult = TextWidget.Cast(root.FindAnyWidget("details_servertype_result_label"));
  34. m_ServerModeResult = TextWidget.Cast(root.FindAnyWidget("details_mode_result_label"));
  35. m_LastCharacterResult = TextWidget.Cast(root.FindAnyWidget("details_character_result_label"));
  36. m_ServerIP = TextWidget.Cast(root.FindAnyWidget("details_ip_result_label"));
  37. #ifdef PLATFORM_WINDOWS
  38. #ifndef PLATFORM_CONSOLE
  39. m_FriendsContainer = GridSpacerWidget.Cast(root.FindAnyWidget("details_friends_container"));
  40. m_FriendsResult = TextWidget.Cast(root.FindAnyWidget("details_friends_result_label"));
  41. #endif
  42. #endif
  43. m_TimeAccelerationResult = TextWidget.Cast(root.FindAnyWidget("details_time_result_label"));
  44. m_TimeIcon = ImageWidget.Cast(root.FindAnyWidget("detail_time_img"));
  45. m_BattleyeResult = TextWidget.Cast(root.FindAnyWidget("details_battleye_result_label"));
  46. m_VersionContainer = WrapSpacerWidget.Cast(root.FindAnyWidget("details_version_container"));
  47. m_VersionResult = TextWidget.Cast(root.FindAnyWidget("details_version_result_label"));
  48. m_ServerDecContainer = GridSpacerWidget.Cast(root.FindAnyWidget("details_description_container"));
  49. m_ServerDesc = MultilineTextWidget.Cast(root.FindAnyWidget("details_description_label"));
  50. m_DetailsContainerRight = WrapSpacerWidget.Cast(root.FindAnyWidget("details_container_right"));
  51. m_MapImage = ImageWidget.Cast(root.FindAnyWidget("map_image"));
  52. m_TimeIcon.LoadImageFile(0, "set:dayz_gui image:icon_sun");
  53. m_TimeIcon.LoadImageFile(1, "set:dayz_gui image:icon_sun_accel");
  54. m_TimeIcon.LoadImageFile(2, "set:dayz_gui image:icon_moon");
  55. m_TimeIcon.LoadImageFile(3, "set:dayz_gui image:icon_moon_accel");
  56. m_BtnShowFilters = ButtonWidget.Cast(parent.GetDetailsRoot().FindAnyWidget("show_filters_button"));
  57. m_RefreshList = ButtonWidget.Cast(parent.GetFilterRoot().FindAnyWidget("refresh_list_button"));
  58. }
  59. void SetDetails(GetServersResultRow serverInfo, bool online = false)
  60. {
  61. if (!online)
  62. {
  63. ClearDetails();
  64. return;
  65. }
  66. if (serverInfo)
  67. {
  68. SetName(serverInfo.m_Name);
  69. #ifdef PLATFORM_WINDOWS
  70. #ifndef PLATFORM_CONSOLE
  71. SetType(serverInfo.m_ShardId);
  72. SetMode(serverInfo.m_Disable3rdPerson);
  73. #endif
  74. #endif
  75. #ifdef PLATFORM_CONSOLE
  76. SetMode(serverInfo.m_ModeId);
  77. SetConsoleType(serverInfo.m_Official);
  78. #endif
  79. SetServerIP(serverInfo.GetIpPort());
  80. //! Server time acceleration text version is hidden for now
  81. /*
  82. SetTimeAcceleration(serverInfo.m_EnvironmentTimeMul, serverInfo.m_EnvironmentNightTimeMul);
  83. */
  84. SetTimeIcon(serverInfo.m_TimeOfDay, serverInfo.m_EnvironmentTimeMul);
  85. #ifdef PLATFORM_WINDOWS
  86. #ifndef PLATFORM_CONSOLE
  87. SetCharacter(serverInfo.m_CharactersAlive);
  88. SetFriends(serverInfo.m_SteamFriends);
  89. #endif
  90. #endif
  91. //! Server anticheat text is hidden for now
  92. /*
  93. SetBattleyeState(serverInfo.m_AntiCheat);
  94. */
  95. //! Server version text is hidden for now
  96. /*
  97. SetVersion(serverInfo.m_GameVersion);
  98. */
  99. SetServerDesc(serverInfo.m_Description);
  100. }
  101. //! Map image container and handling is hidden/disabled for now
  102. m_DetailsContainerRight.Show(false);
  103. //SetServerMap();
  104. }
  105. void ClearDetails()
  106. {
  107. m_ServerNameText.SetText("#STR_server_browser_details_no_server_selected");
  108. m_ServerTypeResult.SetText("-");
  109. m_ServerModeResult.SetText("-");
  110. m_ServerIP.SetText("-");
  111. m_TimeIcon.Show(false);
  112. m_TimeAccelerationResult.Show(true);
  113. m_TimeAccelerationResult.SetText("-");
  114. }
  115. protected void SetName(string name)
  116. {
  117. m_ServerNameText.SetText(name);
  118. m_ServerNameText.Update();
  119. }
  120. protected void SetType(string shardId)
  121. {
  122. string result = "#server_browser_tab_community";
  123. if (shardId.Length() == 3 && shardId.ToInt() < 200)
  124. result = "#server_browser_entry_official";
  125. m_ServerTypeResult.SetText(result);
  126. }
  127. #ifdef PLATFORM_CONSOLE
  128. protected void SetConsoleType(bool offical)
  129. {
  130. string result = "#server_browser_tab_community";
  131. if (offical)
  132. result = "#server_browser_entry_official";
  133. m_ServerTypeResult.SetText(result);
  134. }
  135. #endif
  136. protected void SetMode(int mode)
  137. {
  138. string result = "#STR_server_browser_no_server_selected";
  139. switch (mode)
  140. {
  141. case 0:
  142. {
  143. result = "#STR_server_browser_details_third_person";
  144. break;
  145. }
  146. case 1:
  147. {
  148. result = "#STR_server_browser_details_first_person";
  149. break;
  150. }
  151. }
  152. m_ServerModeResult.SetText(result);
  153. }
  154. protected void SetServerIP(string ip)
  155. {
  156. m_ServerIP.SetText(ip);
  157. }
  158. #ifdef PLATFORM_WINDOWS
  159. #ifndef PLATFORM_CONSOLE
  160. protected void SetCharacter(string characterName)
  161. {
  162. string result = "#STR_server_browser_char_not_alive";
  163. if (characterName != "")
  164. result = characterName;
  165. m_LastCharacterResult.SetText(result);
  166. }
  167. protected void SetFriends(string steamFriends = "")
  168. {
  169. string result = "-";
  170. if (steamFriends != "")
  171. result = steamFriends;
  172. m_FriendsResult.SetText(result);
  173. m_FriendsResult.Update();
  174. }
  175. #endif
  176. #endif
  177. protected void SetTimeAcceleration(float timeMul, float nightTimeMul)
  178. {
  179. m_TimeAccelerationResult.SetText(timeMul.ToString() + "/" + nightTimeMul.ToString());
  180. }
  181. void SetTimeIcon(string time, float multiplier)
  182. {
  183. if (time != "")
  184. {
  185. TStringArray arr = new TStringArray;
  186. time.Split(":", arr);
  187. if (arr.Count() == 2)
  188. {
  189. int hour = arr.Get(0).ToInt();
  190. int minute = arr.Get(1).ToInt();
  191. if (hour >= 19 || hour <= 5) //Night
  192. {
  193. if (multiplier > 1)
  194. m_TimeIcon.SetImage(3);
  195. else
  196. m_TimeIcon.SetImage(2);
  197. }
  198. else //Day
  199. {
  200. if (multiplier > 1)
  201. m_TimeIcon.SetImage(1);
  202. else
  203. m_TimeIcon.SetImage(0);
  204. }
  205. m_TimeIcon.Show(true);
  206. m_TimeAccelerationResult.Show(false);
  207. }
  208. }
  209. else
  210. {
  211. m_TimeIcon.Show(false);
  212. m_TimeAccelerationResult.Show(true);
  213. m_TimeAccelerationResult.SetText("-");
  214. }
  215. }
  216. protected void SetBattleyeState(int enabled = -1)
  217. {
  218. string result = "#STR_server_browser_no_server_selected";
  219. int color = ARGB(255, 255, 255, 255);
  220. switch (enabled)
  221. {
  222. case 0:
  223. {
  224. result = "#server_browser_entry_disabled";
  225. color = ARGB(255, 255, 0, 0);
  226. break:
  227. }
  228. case 1:
  229. {
  230. result = "#server_browser_entry_enabled";
  231. color = ARGB(255, 0, 255, 0);
  232. break:
  233. }
  234. }
  235. m_BattleyeResult.SetText(result);
  236. m_BattleyeResult.SetColor(color);
  237. }
  238. protected void SetVersion(string version)
  239. {
  240. m_VersionResult.SetText(version);
  241. }
  242. protected void SetServerDesc(string desc)
  243. {
  244. m_ServerDesc.SetText(desc);
  245. m_ServerDesc.Update();
  246. }
  247. protected void SetServerMap(GetServersResultRow serverInfo)
  248. {
  249. string mapImagePath = ServerBrowserHelperFunctions.GetServerMapImagePath(serverInfo.m_MapNameToRun);
  250. m_MapImage.LoadImageFile(0, mapImagePath);
  251. m_DetailsContainerRight.Show(true);
  252. }
  253. void Focus()
  254. {
  255. #ifdef PLATFORM_CONSOLE
  256. if (m_Tab.GetTabType() == TabType.FAVORITE)
  257. {
  258. SetFocus(m_RefreshList);
  259. }
  260. else
  261. {
  262. SetFocus(m_BtnShowFilters);
  263. }
  264. #endif
  265. }
  266. override bool OnFocus(Widget w, int x, int y)
  267. {
  268. m_Tab.OnDetailsFocus(w);
  269. return false;
  270. }
  271. override bool OnMouseEnter(Widget w, int x, int y)
  272. {
  273. return m_Tab.OnMouseEnter(w, x, y);
  274. }
  275. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  276. {
  277. return m_Tab.OnMouseLeave(w, enterW, x, y);
  278. }
  279. }