VPA-Keyboard

For planets.nu -- Add VPA-key strokes, and commands

当前为 2016-05-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name VPA-Keyboard
  3. // @author Quapla
  4. // @copyright Basecode: Kero van Gelder, 2016 - latest: Quapla
  5. // @license Lesser Gnu Public License, version 3
  6. // @description For planets.nu -- Add VPA-key strokes, and commands
  7. // @namespace quapla/VPA-Keyboard
  8. // @include http://planets.nu/*
  9. // @include http://play.planets.nu/*
  10. // @include http://test.planets.nu/*
  11. // @version 1.0.1
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. // Reference: Kero van Gelder's Keayboard: http://chmeee.org/ext/planets.nu/Keyboard.user.js
  16.  
  17.  
  18. sharedContent.prototype.planetSurvey_McNimblesToolkit = sharedContent.prototype.planetSurvey;
  19. sharedContent.prototype.planetSurvey = function(planetId) {
  20. vgap.currentPlanetSurvey = planetId;
  21. this.planetSurvey_McNimblesToolkit(planetId);
  22. }
  23.  
  24. sharedContent.prototype.editNote_McNimblesToolkit = sharedContent.prototype.editNote;
  25. sharedContent.prototype.editNote = function(noteId, noteType) {
  26. vgap.currentNoteId = noteId;
  27. vgap.currentNoteType = noteType;
  28. this.editNote_McNimblesToolkit(noteId, noteType);
  29. $("#EditNote").focus();
  30. }
  31.  
  32. vgapShipScreen.prototype.shipMission_McNimblesToolkit = vgapShipScreen.prototype.shipMission;
  33. vgapShipScreen.prototype.shipMission = function() {
  34. this.shipMissionOpen = true;
  35. this.shipMission_McNimblesToolkit();
  36. }
  37.  
  38. vgapShipScreen.prototype.selectMission_McNimblesToolkit = vgapShipScreen.prototype.selectMission;
  39. vgapShipScreen.prototype.selectMission = function(missionId) {
  40. this.selectMission_McNimblesToolkit(missionId);
  41. this.shipMissionOpen = false;
  42. }
  43.  
  44. vgapShipScreen.prototype.primaryEnemy_McNimblesToolkit = vgapShipScreen.prototype.primaryEnemy;
  45. vgapShipScreen.prototype.primaryEnemy = function() {
  46. this.primaryEnemyOpen = true;
  47. this.primaryEnemy_McNimblesToolkit();
  48. }
  49. vgapShipScreen.prototype.selectEnemy_McNimblesToolkit = vgapShipScreen.prototype.selectEnemy;
  50. vgapShipScreen.prototype.selectEnemy = function(enemyId) {
  51. this.selectEnemy_McNimblesToolkit(enemyId);
  52. this.primaryEnemyOpen = false;
  53. }
  54. vgaPlanets.prototype.closeMore_McNimblesToolkit = vgaPlanets.prototype.closeMore;
  55. vgaPlanets.prototype.closeMore = function(callback) {
  56. vgap.closeMore_McNimblesToolkit(callback);
  57. this.primaryEnemyOpen = false;
  58. vgap.currentPlanetSurvey = null;
  59. vgap.shipScreen.shipMissionOpen = false;
  60. }
  61.  
  62. vgaPlanets.prototype.hotkey_McNimblesToolkit = vgaPlanets.prototype.hotkey;
  63. vgaPlanets.prototype.hotkey = function(event) {
  64. if (vgap.shipScreen.primaryEnemyOpen) {
  65. var enemy = 0;
  66. if (event.keyCode >= 48 && event.keyCode <= 57) enemy = event.keyCode - 48;
  67. if (event.keyCode >= 65 && event.keyCode <= 90) enemy = event.keyCode - 65 + 10;
  68. if (enemy <= vgap.players.length) {
  69. vgap.shipScreen.selectEnemy(enemy);
  70. return;
  71. }
  72. }
  73.  
  74. if (vgap.shipScreen.shipMissionOpen) {
  75. var missionId = -1;
  76. if (event.keyCode == 67) missionId = 9; // 'c', Cloak
  77. else if (event.keyCode == 69) missionId = 0; // 'e', Explore
  78. else if (event.keyCode == 73) missionId = 7; // 'i', Intercept
  79. else if (event.keyCode == 75) missionId = 3; // 'k', Kill
  80. else if (event.keyCode == 76) missionId = 2; // 'l', Lay Mines
  81. else if (event.keyCode == 77) missionId = 1; // 'm', Mine Sweep
  82. else if (event.keyCode == 83 && event.shiftKey) missionId = 8; // 'S', Special / Super Spy
  83. else if (event.keyCode == 83) missionId = 4; // 's', Sensor Sweep
  84. else if (event.keyCode == 84) missionId = 6; // 't', Tow
  85. if (missionId >= 0) {
  86. vgap.shipScreen.selectMission(missionId);
  87. return;
  88. }
  89. }
  90.  
  91. if (vgap.editNoteOpen) {
  92. if (event.keyCode == 13 && event.ctrlKey) {
  93. this.saveNote(vgap.currentNoteId, vgap.currentNoteType);
  94. return;
  95. }
  96. }
  97.  
  98. if (event.keyCode == 27) {
  99. if (this.findObjectFeatureActivated) vgap.map.hideFindObjectFeature();
  100. else if (vgap.moreOpen) this.closeMore();
  101. else if (this.lcOpen) this.deselectAll();
  102. else this.hotkey_McNimblesToolkit(event);
  103. return;
  104. }
  105.  
  106. if (vgap.hotkeysOn) {
  107. switch (event.keyCode) {
  108. case 8:
  109. if ((this.starbaseScreenOpen || this.planetScreenOpen || this.shipScreenOpen) && !this.moreOpen) {
  110. vgap.rPrev();
  111. return;
  112. }
  113. case 78: // 'n'
  114. if (event.shiftKey) {
  115. if (this.planetScreenOpen) {
  116. shtml.editNote(vgap.planetScreen.planet.id, 1);
  117. return;
  118. } else if (vgap.currentPlanetSurvey > 0) { // ship screen is open, but unowned planet is selected
  119. shtml.editNote(vgap.currentPlanetSurvey, 1);
  120. return
  121. } else if (this.shipScreenOpen) {
  122. shtml.editNote(vgap.shipScreen.ship.id, 2);
  123. return;
  124. } else if (this.starbaseScreenOpen) {
  125. shtml.editNote(vgap.starbaseScreen.starbase.id, 3);
  126. return;
  127. }
  128. }
  129. break;
  130. case 88: // 'x'
  131. this.map.clearTools();
  132. return;
  133. case 90: // 'z'
  134. this.map.zoomFarInOrOut_OnWaypointOrPlanet();
  135. return;
  136. case 188: // '<'
  137. if (event.shiftKey) {
  138. vgap.unrotateActiveObject();
  139. return;
  140. }
  141. case 190: // '>'
  142. if (event.shiftKey) {
  143. vgap.rotateActiveObject();
  144. return;
  145. }
  146. }
  147. }
  148.  
  149. this.hotkey_McNimblesToolkit(event);
  150. }
  151.  
  152. vgapMap.prototype.zoomFarInOrOut_OnWaypointOrPlanet = function() {
  153. var zoomedOut = (this.zoom < 29);
  154. if (zoomedOut) {
  155. this.zoomFactorBeforeZoomingInDeeply = this.zoom;
  156. this.setZoom(42);
  157. } else {
  158. this.setZoom(this.zoomFactorBeforeZoomingInDeeply);
  159. }
  160. var x, y;
  161. if (this.activeShip) {
  162. x = this.activeShip.targetx;
  163. y = this.activeShip.targety;
  164. } else if (this.activePlanet) {
  165. x = this.activePlanet.x;
  166. y = this.activePlanet.y;
  167. } else {
  168. x = this.centerX;
  169. y = this.centerY;
  170. }
  171.  
  172. this.centerX = x;
  173. this.centerY = y;
  174. this.canvas.x = x - $(window).width() / 2 / this.zoom;
  175. this.canvas.y = y - $(window).height() / 2 / this.zoom;
  176. this.draw();
  177. }
  178.  
  179. vgaPlanets.prototype.rotateActiveObject = function() {
  180. if (vgap.planetScreenOpen) {
  181. var planet = vgap.map.activePlanet;
  182. if (planet.isbase) {
  183. vgap.map.selectStarbase(planet.id);
  184. } else {
  185. var ships = vgap.shipsAt(planet.x, planet.y);
  186. if (ships.length > 0) vgap.map.selectShip(ships[0].id);
  187. // else only a planet
  188. }
  189. } else if (vgap.starbaseScreenOpen) {
  190. var planet = vgap.map.activePlanet;
  191. var ships = vgap.shipsAt(planet.x, planet.y);
  192. if (ships.length > 0) {
  193. vgap.map.selectShip(ships[0].id);
  194. } else {
  195. vgap.map.selectPlanet(planet.id);
  196. }
  197. } else if (vgap.shipScreenOpen) {
  198. var ship = vgap.map.activeShip;
  199. var ships = vgap.shipsAt(ship.x, ship.y)
  200. var index = ships.indexOf(ship);
  201. if (index == ships.length - 1) {
  202. var planet = vgap.planetAt(ship.x, ship.y)
  203. if (planet) {
  204. vgap.map.selectPlanet(planet.id);
  205. } else if (ships.length > 1) {
  206. vgap.map.selectShip(ships[0].id);
  207. } // else Cannot rotate 1 ship
  208. } else {
  209. vgap.map.selectShip(ships[index+1].id);
  210. }
  211. }
  212. }
  213.  
  214. vgaPlanets.prototype.unrotateActiveObject = function() {
  215. if (vgap.planetScreenOpen) {
  216. var planet = vgap.map.activePlanet;
  217. var ships = vgap.shipsAt(planet.x, planet.y);
  218. if (ships.length > 0) {
  219. vgap.map.selectShip(ships[ships.length-1].id);
  220. } else if (planet.isbase) {
  221. vgap.map.selectStarbase(planet.id);
  222. } // else only a planet
  223. } else if (vgap.starbaseScreenOpen) {
  224. var planet = vgap.map.activePlanet;
  225. vgap.map.selectPlanet(planet.id);
  226. } else if (vgap.shipScreenOpen) {
  227. var ship = vgap.map.activeShip;
  228. var ships = vgap.shipsAt(ship.x, ship.y)
  229. var index = ships.indexOf(ship);
  230. if (index == 0) {
  231. var planet = vgap.planetAt(ship.x, ship.y)
  232. if (planet) {
  233. if (planet.isbase) {
  234. vgap.map.selectStarbase(planet.id);
  235. } else {
  236. vgap.map.selectPlanet(planet.id);
  237. }
  238. } else {
  239. if (ships.length > 1) vgap.map.selectShip(ships[ships.length-1].id);
  240. }
  241. } else {
  242. vgap.map.selectShip(ships[index-1].id);
  243. }
  244. }
  245. }