joinServerMenu.tscript 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. function JoinServerMenu::onWake(%this)
  2. {
  3. $MenuList = JoinServerList;
  4. JoinServerList.listPosition = 0;
  5. JoinServerList.syncGui();
  6. }
  7. if(!isObject( JoinServerActionMap ) )
  8. {
  9. new ActionMap(JoinServerActionMap){};
  10. JoinServerActionMap.bindCmd( keyboard, q, "JoinServerMenu.query();" );
  11. JoinServerActionMap.bindCmd( gamepad, btn_x, "JoinServerMenu.query();" );
  12. JoinServerActionMap.bindCmd( keyboard, e, "JoinServerMenu.queryLan();" );
  13. JoinServerActionMap.bindCmd( gamepad, btn_y, "JoinServerMenu.queryLan();" );
  14. JoinServerActionMap.bindCmd( keyboard, Enter, "JoinServerMenu::join();" );
  15. JoinServerActionMap.bindCmd( gamepad, btn_a, "JoinServerMenu::join();" );
  16. }
  17. //----------------------------------------
  18. function JoinServerMenu::query(%this)
  19. {
  20. //Nuke the current list and indicate we're working on a query...
  21. JoinServerList.clear();
  22. queryMasterServer(
  23. 0, // Query flags
  24. $Client::GameTypeQuery, // gameTypes
  25. $Client::MissionTypeQuery, // missionType
  26. 0, // minPlayers
  27. 100, // maxPlayers
  28. 0, // maxBots
  29. 2, // regionMask
  30. 0, // maxPing
  31. 100, // minCPU
  32. 0 // filterFlags
  33. );
  34. }
  35. //----------------------------------------
  36. function JoinServerMenu::queryLan(%this)
  37. {
  38. //Nuke the current list and indicate we're working on a query...
  39. JoinServerList.clear();
  40. queryLANServers(
  41. $pref::Net::Port, // lanPort for local queries
  42. 0, // Query flags
  43. $Client::GameTypeQuery, // gameTypes
  44. $Client::MissionTypeQuery, // missionType
  45. 0, // minPlayers
  46. 100, // maxPlayers
  47. 0, // maxBots
  48. 2, // regionMask
  49. 0, // maxPing
  50. 100, // minCPU
  51. 0 // filterFlags
  52. );
  53. }
  54. //----------------------------------------
  55. function JoinServerMenu::cancel(%this)
  56. {
  57. cancelServerQuery();
  58. JS_queryStatus.setVisible(false);
  59. }
  60. //----------------------------------------
  61. function JoinServerMenu::join(%this)
  62. {
  63. cancelServerQuery();
  64. JoinGame(JoinServerList.listPosition);
  65. }
  66. //----------------------------------------
  67. function JoinServerMenu::refresh(%this)
  68. {
  69. cancelServerQuery();
  70. %index = JoinServerList.listPosition;
  71. // The server info index is stored in the row along with the
  72. // rest of displayed info.
  73. if( setServerInfo( %index ) )
  74. querySingleServer( $ServerInfo::Address, 0 );
  75. }
  76. //----------------------------------------
  77. function JoinServerMenu::refreshSelectedServer( %this )
  78. {
  79. querySingleServer( $JoinGameAddress, 0 );
  80. }
  81. //----------------------------------------
  82. function JoinServerMenu::update(%this)
  83. {
  84. // Copy the servers into the server list.
  85. JS_queryStatus.setVisible(false);
  86. JoinServerList.clear();
  87. %sc = getServerCount();
  88. for( %i = 0; %i < %sc; %i ++ ) {
  89. setServerInfo(%i);
  90. %serverEntry = %this.addServerEntry();
  91. %serverEntry-->serverNameTxt.text = $ServerInfo::Name;
  92. %serverEntry-->serverDetailsTxt.text = $ServerInfo::MissionName @ " | v" @ $ServerInfo::Version @ " | " @ $ServerInfo::MissionType;
  93. %serverEntry-->pingTxt.text = $ServerInfo::Ping @ " ms";
  94. %serverEntry-->playerCountTxt.text = $ServerInfo::PlayerCount @ "|" @ $ServerInfo::MaxPlayers;
  95. %serverEntry.resize(0, 0, JoinServerList.extent.x, %serverEntry.extent.y);
  96. JoinServerList.add(%serverEntry);
  97. }
  98. JoinServerList.syncGui();
  99. }
  100. //----------------------------------------
  101. function onServerQueryStatus(%status, %msg, %value)
  102. {
  103. echo("ServerQuery: " SPC %status SPC %msg SPC %value);
  104. // Update query status
  105. // States: start, update, ping, query, done
  106. // value = % (0-1) done for ping and query states
  107. //if (!JS_queryStatus.isVisible())
  108. // JS_queryStatus.setVisible(true);
  109. switch$ (%status) {
  110. case "start":
  111. MessagePopup("", %msg, 5000);
  112. JoinServerList.clear();
  113. case "ping":
  114. MessagePopup("", "Pinging Servers", 5000);
  115. case "query":
  116. MessagePopup("", "Querying Servers", 5000);
  117. case "done":
  118. MessagePopup("", %msg, 1000);
  119. JoinServerMenu.update();
  120. }
  121. }
  122. function JoinServerMenu::addServerEntry(%this)
  123. {
  124. %entry = new GuiContainer() {
  125. position = "0 0";
  126. extent = "900 40";
  127. profile = GuiMenuDefaultProfile;
  128. tooltipProfile = "GuiToolTipProfile";
  129. horizSizing = "width";
  130. vertSizing = "bottom";
  131. class = "JoinServerServerEntry";
  132. new GuiButtonCtrl() {
  133. profile = GuiMenuButtonProfile;
  134. position = "0 0";
  135. extent = "900 40";
  136. horizSizing = "width";
  137. vertSizing = "height";
  138. internalName = "button";
  139. class = "JoinServerEntryButton";
  140. };
  141. new GuiTextCtrl() {
  142. position = "0 0";
  143. extent = "700 20";
  144. profile = "MenuSubHeaderText";
  145. tooltipProfile = "GuiToolTipProfile";
  146. internalName = "serverNameTxt";
  147. };
  148. new GuiTextCtrl() {
  149. position = $optionsEntryPad SPC 17;
  150. extent = "700 18";
  151. profile = "GuiMLTextProfile";
  152. tooltipProfile = "GuiToolTipProfile";
  153. internalName = "serverDetailsTxt";
  154. };
  155. new GuiTextCtrl() {
  156. position = "700 0";
  157. extent = "70 40";
  158. horizSizing = "left";
  159. vertSizing = "center";
  160. profile = "MenuSubHeaderCenteredText";
  161. tooltipProfile = "GuiToolTipProfile";
  162. internalName = "pingTxt";
  163. };
  164. new GuiTextCtrl() {
  165. position = "770 0";
  166. extent = "130 40";
  167. horizSizing = "left";
  168. vertSizing = "center";
  169. profile = "MenuSubHeaderCenteredText";
  170. tooltipProfile = "GuiToolTipProfile";
  171. internalName = "playerCountTxt";
  172. };
  173. };
  174. return %entry;
  175. }
  176. function JoinServerEntryButton::onHighlighted(%this, %highlighted)
  177. {
  178. %container = %this.getParent();
  179. %container-->serverNameTxt.profile = %highlighted ? MenuSubHeaderTextHighlighted : MenuSubHeaderText;
  180. %container-->serverDetailsTxt.profile = %highlighted ? GuiMLTextProfileHighlighted : GuiMLTextProfile;
  181. %container-->pingTxt.profile = %highlighted ? MenuSubHeaderCenteredTextHighlighted : MenuSubHeaderCenteredText;
  182. %container-->playerCountTxt.profile = %highlighted ? MenuSubHeaderCenteredTextHighlighted : MenuSubHeaderCenteredText;
  183. }
  184. function JoinServerMenu::addStatusEntry(%this)
  185. {
  186. %entry = new GuiContainer() {
  187. position = "0 0";
  188. extent = "900 40";
  189. profile = GuiMenuDefaultProfile;
  190. tooltipProfile = "GuiToolTipProfile";
  191. horizSizing = "width";
  192. vertSizing = "bottom";
  193. class = "JoinServerStatusEntry";
  194. new GuiTextCtrl() {
  195. position = "0 0";
  196. extent = "730 20";
  197. profile = "MenuSubHeaderCenteredText";
  198. tooltipProfile = "GuiToolTipProfile";
  199. internalName = "statusTxt";
  200. };
  201. };
  202. return %entry;
  203. }
  204. function JoinServerStatusEntry::updateProgress(%this)
  205. {
  206. %this-->statusText.text = %this-->statusText.text @ "."; //ellipses.......
  207. %this.schedule(500, "updateProgress");
  208. }
  209. function JoinServerList::syncGui(%this)
  210. {
  211. %this.callOnChildren("setHighlighted", false);
  212. if(%this.listPosition < %this.getCount())
  213. {
  214. %btn = %this.getObject(%this.listPosition);
  215. %btn-->button.setHighlighted(true);
  216. }
  217. //
  218. //Update the button imagery to comply to the last input device we'd used
  219. %device = Canvas.getLastInputDevice();
  220. if(%device $= "mouse")
  221. %device = "keyboard";
  222. JoinServerBackBtn.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIBackOut"));
  223. JoinServerJoinBtn.setBitmap(JoinServerActionMap.getCommandButtonBitmap(%device, "JoinServerMenu::join();"));
  224. JoinServerQLanBtn.setBitmap(JoinServerActionMap.getCommandButtonBitmap(%device, "JoinServerMenu.queryLan();"));
  225. JoinServerQServerBtn.setBitmap(JoinServerActionMap.getCommandButtonBitmap(%device, "JoinServerMenu.query();"));
  226. JoinServerJoinBtn.setActive(JoinServerList.getCount() > 0);
  227. }