default.bind.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. if ( isObject( moveMap ) )
  23. moveMap.delete();
  24. new ActionMap(moveMap);
  25. //------------------------------------------------------------------------------
  26. // Non-remapable binds
  27. //------------------------------------------------------------------------------
  28. function escapeFromGame()
  29. {
  30. if ( $Server::ServerType $= "SinglePlayer" )
  31. MessageBoxYesNo( "Exit", "Exit from this Mission?", "disconnect();", "");
  32. else
  33. MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
  34. }
  35. moveMap.bindCmd(keyboard, "escape", "", "handleEscape();");
  36. //------------------------------------------------------------------------------
  37. // Movement Keys
  38. //------------------------------------------------------------------------------
  39. $movementSpeed = 1; // m/s
  40. function setSpeed(%speed)
  41. {
  42. if(%speed)
  43. $movementSpeed = %speed;
  44. }
  45. function moveleft(%val)
  46. {
  47. $mvLeftAction = %val * $movementSpeed;
  48. }
  49. function moveright(%val)
  50. {
  51. $mvRightAction = %val * $movementSpeed;
  52. }
  53. function moveforward(%val)
  54. {
  55. $mvForwardAction = %val * $movementSpeed;
  56. }
  57. function movebackward(%val)
  58. {
  59. $mvBackwardAction = %val * $movementSpeed;
  60. }
  61. function moveup(%val)
  62. {
  63. %object = ServerConnection.getControlObject();
  64. if(%object.isInNamespaceHierarchy("Camera"))
  65. $mvUpAction = %val * $movementSpeed;
  66. }
  67. function movedown(%val)
  68. {
  69. %object = ServerConnection.getControlObject();
  70. if(%object.isInNamespaceHierarchy("Camera"))
  71. $mvDownAction = %val * $movementSpeed;
  72. }
  73. function turnLeft( %val )
  74. {
  75. $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  76. }
  77. function turnRight( %val )
  78. {
  79. $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  80. }
  81. function panUp( %val )
  82. {
  83. $mvPitchDownSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  84. }
  85. function panDown( %val )
  86. {
  87. $mvPitchUpSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
  88. }
  89. function getMouseAdjustAmount(%val)
  90. {
  91. // based on a default camera FOV of 90'
  92. return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
  93. }
  94. function getGamepadAdjustAmount(%val)
  95. {
  96. // based on a default camera FOV of 90'
  97. return(%val * ($cameraFov / 90) * 0.01) * 10.0;
  98. }
  99. function yaw(%val)
  100. {
  101. %yawAdj = getMouseAdjustAmount(%val);
  102. if(ServerConnection.isControlObjectRotDampedCamera())
  103. {
  104. // Clamp and scale
  105. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  106. %yawAdj *= 0.5;
  107. }
  108. $mvYaw += %yawAdj;
  109. }
  110. function pitch(%val)
  111. {
  112. %pitchAdj = getMouseAdjustAmount(%val);
  113. if(ServerConnection.isControlObjectRotDampedCamera())
  114. {
  115. // Clamp and scale
  116. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  117. %pitchAdj *= 0.5;
  118. }
  119. $mvPitch += %pitchAdj;
  120. }
  121. function jump(%val)
  122. {
  123. $mvTriggerCount2++;
  124. }
  125. function gamePadMoveX( %val )
  126. {
  127. $mvXAxis_L = %val;
  128. }
  129. function gamePadMoveY( %val )
  130. {
  131. $mvYAxis_L = %val;
  132. }
  133. function gamepadYaw(%val)
  134. {
  135. %yawAdj = getGamepadAdjustAmount(%val);
  136. if(ServerConnection.isControlObjectRotDampedCamera())
  137. {
  138. // Clamp and scale
  139. %yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
  140. %yawAdj *= 0.5;
  141. }
  142. if(%yawAdj > 0)
  143. {
  144. $mvYawLeftSpeed = %yawAdj;
  145. $mvYawRightSpeed = 0;
  146. }
  147. else
  148. {
  149. $mvYawLeftSpeed = 0;
  150. $mvYawRightSpeed = -%yawAdj;
  151. }
  152. }
  153. function gamepadPitch(%val)
  154. {
  155. %pitchAdj = getGamepadAdjustAmount(%val);
  156. if(ServerConnection.isControlObjectRotDampedCamera())
  157. {
  158. // Clamp and scale
  159. %pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
  160. %pitchAdj *= 0.5;
  161. }
  162. if(%pitchAdj > 0)
  163. {
  164. $mvPitchDownSpeed = %pitchAdj;
  165. $mvPitchUpSpeed = 0;
  166. }
  167. else
  168. {
  169. $mvPitchDownSpeed = 0;
  170. $mvPitchUpSpeed = -%pitchAdj;
  171. }
  172. }
  173. moveMap.bind( keyboard, a, moveleft );
  174. moveMap.bind( keyboard, d, moveright );
  175. moveMap.bind( keyboard, left, moveleft );
  176. moveMap.bind( keyboard, right, moveright );
  177. moveMap.bind( keyboard, w, moveforward );
  178. moveMap.bind( keyboard, s, movebackward );
  179. moveMap.bind( keyboard, up, moveforward );
  180. moveMap.bind( keyboard, down, movebackward );
  181. moveMap.bind( keyboard, e, moveup );
  182. moveMap.bind( keyboard, c, movedown );
  183. moveMap.bind( keyboard, space, jump );
  184. moveMap.bind( mouse, xaxis, yaw );
  185. moveMap.bind( mouse, yaxis, pitch );
  186. moveMap.bind( gamepad, thumbrx, "D", "-0.23 0.23", gamepadYaw );
  187. moveMap.bind( gamepad, thumbry, "D", "-0.23 0.23", gamepadPitch );
  188. moveMap.bind( gamepad, thumblx, "D", "-0.23 0.23", gamePadMoveX );
  189. moveMap.bind( gamepad, thumbly, "D", "-0.23 0.23", gamePadMoveY );
  190. moveMap.bind( gamepad, btn_a, jump );
  191. moveMap.bindCmd( gamepad, btn_back, "disconnect();", "" );
  192. moveMap.bindCmd(gamepad, dpadl, "toggleLightColorViz();", "");
  193. moveMap.bindCmd(gamepad, dpadu, "toggleDepthViz();", "");
  194. moveMap.bindCmd(gamepad, dpadd, "toggleNormalsViz();", "");
  195. moveMap.bindCmd(gamepad, dpadr, "toggleLightSpecularViz();", "");
  196. //------------------------------------------------------------------------------
  197. // Mouse Trigger
  198. //------------------------------------------------------------------------------
  199. function mouseFire(%val)
  200. {
  201. $mvTriggerCount0++;
  202. }
  203. function altTrigger(%val)
  204. {
  205. $mvTriggerCount1++;
  206. }
  207. moveMap.bind( mouse, button0, mouseFire );
  208. moveMap.bind( mouse, button1, altTrigger );
  209. //------------------------------------------------------------------------------
  210. // Gamepad Trigger
  211. //------------------------------------------------------------------------------
  212. function gamepadFire(%val)
  213. {
  214. if(%val > 0.1 && !$gamepadFireTriggered)
  215. {
  216. $gamepadFireTriggered = true;
  217. $mvTriggerCount0++;
  218. }
  219. else if(%val <= 0.1 && $gamepadFireTriggered)
  220. {
  221. $gamepadFireTriggered = false;
  222. $mvTriggerCount0++;
  223. }
  224. }
  225. function gamepadAltTrigger(%val)
  226. {
  227. if(%val > 0.1 && !$gamepadAltTriggerTriggered)
  228. {
  229. $gamepadAltTriggerTriggered = true;
  230. $mvTriggerCount1++;
  231. }
  232. else if(%val <= 0.1 && $gamepadAltTriggerTriggered)
  233. {
  234. $gamepadAltTriggerTriggered = false;
  235. $mvTriggerCount1++;
  236. }
  237. }
  238. moveMap.bind(gamepad, triggerr, gamepadFire);
  239. moveMap.bind(gamepad, triggerl, gamepadAltTrigger);
  240. //------------------------------------------------------------------------------
  241. // Zoom and FOV functions
  242. //------------------------------------------------------------------------------
  243. if($Player::CurrentFOV $= "")
  244. $Player::CurrentFOV = $pref::Player::DefaultFOV / 2;
  245. // toggleZoomFOV() works by dividing the CurrentFOV by 2. Each time that this
  246. // toggle is hit it simply divides the CurrentFOV by 2 once again. If the
  247. // FOV is reduced below a certain threshold then it resets to equal half of the
  248. // DefaultFOV value. This gives us 4 zoom levels to cycle through.
  249. function toggleZoomFOV()
  250. {
  251. $Player::CurrentFOV = $Player::CurrentFOV / 2;
  252. if($Player::CurrentFOV < 5)
  253. resetCurrentFOV();
  254. if(ServerConnection.zoomed)
  255. setFOV($Player::CurrentFOV);
  256. else
  257. {
  258. setFov(ServerConnection.getControlCameraDefaultFov());
  259. }
  260. }
  261. function resetCurrentFOV()
  262. {
  263. $Player::CurrentFOV = ServerConnection.getControlCameraDefaultFov() / 2;
  264. }
  265. function turnOffZoom()
  266. {
  267. ServerConnection.zoomed = false;
  268. setFov(ServerConnection.getControlCameraDefaultFov());
  269. // Rather than just disable the DOF effect, we want to set it to the level's
  270. // preset values.
  271. //DOFPostEffect.disable();
  272. ppOptionsUpdateDOFSettings();
  273. }
  274. function setZoomFOV(%val)
  275. {
  276. if(%val)
  277. toggleZoomFOV();
  278. }
  279. function toggleZoom(%val)
  280. {
  281. if (%val)
  282. {
  283. ServerConnection.zoomed = true;
  284. setFov($Player::CurrentFOV);
  285. DOFPostEffect.setAutoFocus( true );
  286. DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
  287. DOFPostEffect.enable();
  288. }
  289. else
  290. {
  291. turnOffZoom();
  292. }
  293. }
  294. moveMap.bind(keyboard, f, setZoomFOV);
  295. moveMap.bind(keyboard, r, toggleZoom);
  296. moveMap.bind( gamepad, btn_b, toggleZoom );
  297. //------------------------------------------------------------------------------
  298. // Camera & View functions
  299. //------------------------------------------------------------------------------
  300. function toggleFreeLook( %val )
  301. {
  302. if ( %val )
  303. $mvFreeLook = true;
  304. else
  305. $mvFreeLook = false;
  306. }
  307. function toggleFirstPerson(%val)
  308. {
  309. if (%val)
  310. {
  311. ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
  312. }
  313. }
  314. function toggleCamera(%val)
  315. {
  316. if (%val)
  317. commandToServer('ToggleCamera');
  318. }
  319. moveMap.bind( keyboard, z, toggleFreeLook );
  320. moveMap.bind(keyboard, tab, toggleFirstPerson );
  321. moveMap.bind(keyboard, "alt c", toggleCamera);
  322. moveMap.bind( gamepad, btn_back, toggleCamera );
  323. //------------------------------------------------------------------------------
  324. // Demo recording functions
  325. //------------------------------------------------------------------------------
  326. function startRecordingDemo( %val )
  327. {
  328. if ( %val )
  329. startDemoRecord();
  330. }
  331. function stopRecordingDemo( %val )
  332. {
  333. if ( %val )
  334. stopDemoRecord();
  335. }
  336. moveMap.bind( keyboard, F3, startRecordingDemo );
  337. moveMap.bind( keyboard, F4, stopRecordingDemo );
  338. //------------------------------------------------------------------------------
  339. // Helper Functions
  340. //------------------------------------------------------------------------------
  341. function dropCameraAtPlayer(%val)
  342. {
  343. if (%val)
  344. commandToServer('dropCameraAtPlayer');
  345. }
  346. function dropPlayerAtCamera(%val)
  347. {
  348. if (%val)
  349. commandToServer('DropPlayerAtCamera');
  350. }
  351. moveMap.bind(keyboard, "F8", dropCameraAtPlayer);
  352. moveMap.bind(keyboard, "F7", dropPlayerAtCamera);
  353. function bringUpOptions(%val)
  354. {
  355. if (%val)
  356. Canvas.pushDialog(OptionsDlg);
  357. }
  358. GlobalActionMap.bind(keyboard, "ctrl o", bringUpOptions);
  359. //------------------------------------------------------------------------------
  360. // Debugging Functions
  361. //------------------------------------------------------------------------------
  362. //------------------------------------------------------------------------------
  363. //
  364. // Start profiler by pressing ctrl f3
  365. // ctrl f3 - starts profile that will dump to console and file
  366. //
  367. function doProfile(%val)
  368. {
  369. if (%val)
  370. {
  371. // key down -- start profile
  372. echo("Starting profile session...");
  373. profilerReset();
  374. profilerEnable(true);
  375. }
  376. else
  377. {
  378. // key up -- finish off profile
  379. echo("Ending profile session...");
  380. profilerDumpToFile("profilerDumpToFile" @ getSimTime() @ ".txt");
  381. profilerEnable(false);
  382. }
  383. }
  384. GlobalActionMap.bind(keyboard, "ctrl F3", doProfile);
  385. //------------------------------------------------------------------------------
  386. // Misc.
  387. //------------------------------------------------------------------------------
  388. GlobalActionMap.bind(keyboard, "tilde", toggleConsole);
  389. GlobalActionMap.bindCmd(keyboard, "alt k", "cls();","");
  390. GlobalActionMap.bindCmd(keyboard, "alt enter", "", "Canvas.attemptFullscreenToggle();");