joinServerMenu.tscript 8.4 KB

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