Planets.nu - Idle Object Visualizer Plugin

NU plugin which displays all planets, starbases, and ships that are marked idle, ready, or permanently ready

  1. // ==UserScript==
  2. // @name Planets.nu - Idle Object Visualizer Plugin
  3. // @namespace kedalion/idleObjectVisualizer
  4. // @version 0.71
  5. // @date 2018-12-22
  6. // @author kedalion
  7. // @description NU plugin which displays all planets, starbases, and ships that are marked idle, ready, or permanently ready
  8. // @include http://planets.nu/*
  9. // @include http://play.planets.nu/*
  10. // @include http://test.planets.nu/*
  11. // @include https://mobile.planets.nu/*
  12. // @include https://planets.nu/*
  13. // @resource userscript https://greasyfork.org/en/scripts/6442-planets-nu-idle-object-visualizer-plugin
  14. // @homepage http://planets.nu/discussion/utility-script-idle-object-visualizer-plugin
  15.  
  16. // ==/UserScript==
  17.  
  18. /*
  19. Change log:
  20. 0.71 Updated include for new URL [2018-12-22]
  21. 0.70 Port to mobile version of client [2018-12-22]
  22. 0.66 Removed a typo in a function call [2017-06-06]
  23. 0.65 Removed bugs for newer games where ships don't show properly [2017-06-05]
  24. 0.64 Removed double initialization of variables and added comments. [2017-06-05]
  25. 0.63 Fixed conflict with ship tow indicator (thanks Mabeco) [2017-06-04]
  26. 0.62 Added alternative ship coloring as used by Glyn [2017-06-04]
  27. 0.61 Move script location to greasyfork.org [2014-11-13]
  28. 0.6 Move script location to monkeyguts.com [2014-05-30]
  29. 0.58 No fleet view for single objects [2014-04-26]
  30. 0.57 Added filters for ship types [2014-04-24]
  31. 0.56 Added ready markers to ship icons in detail list. Fixed issues with full allies: both own and ally ships were blue. Planet and Starbase are always displayed in mini-list to prevent ships changing position in mini-list when switching to planet or base and back. [2014-04-24]
  32. 0.55 Fixed small bug in planet color [2014-04-15]
  33. 0.54 Added auto enabled after selection in map tools [2014-02-18]
  34. 0.53 Fixed line width bug [2014-02-16]
  35. 0.51 Added enable/disable buttons [2014-02-11]
  36. 0.5 Initial alpha release [2014-02-11]
  37. */
  38. function wrapper() { // wrapper for injection
  39.  
  40. if (vgap.version < 3.0) {
  41. console.log("IdleObjectVisualizer plugin requires at least NU version 3.0. Plugin disabled.");
  42. return;
  43. }
  44.  
  45. var plugin_version = 0.71;
  46.  
  47. console.log("IdleObjectVisualizer plugin version: v" + plugin_version + "." );
  48.  
  49. objectTypeEnum = {
  50. PLANETS : 0,
  51. BASES : 1,
  52. SHIPS : 2,
  53. FILTERSHIPS : 3
  54. };
  55.  
  56. /**
  57. * Specify your plugin
  58. * You need to have all those methods defined or errors will be thrown.
  59. * I inserted the print-outs in order to demonstrate when each method is
  60. * being called. Just comment them out once you know your way around.
  61. *
  62. * For any access to plugin class variables and methods,
  63. * "vgap.plugins["idleObjectVisualizerPlugin"].my_variable" has to be used
  64. * instead of "this.my_variable".
  65. */
  66. var idleObjectVisualizerPlugin = {
  67.  
  68. /**
  69. * processload: executed whenever a turn is loaded: either the current turn or
  70. * an older turn through time machine
  71. */
  72. processload : function() {
  73. //console.log("ProcessLoad: plugin called.");
  74. vgap.plugins["idleObjectVisualizerPlugin"].mobile_version = vgap.plugins["idleObjectVisualizerPlugin"].checkIfMobileVersion();
  75. },
  76.  
  77. /**
  78. * loaddashboard: executed to rebuild the dashboard content after a turn is loaded
  79. */
  80. loaddashboard : function() {
  81. //console.log("LoadDashboard: plugin called.");
  82. },
  83.  
  84. /**
  85. * showdashboard: executed when switching from starmap to dashboard
  86. */
  87. showdashboard : function() {
  88. //console.log("ShowDashboard: plugin called.");
  89. vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
  90. },
  91.  
  92. /**
  93. * showsummary: executed when returning to the main screen of the dashboard
  94. */
  95. showsummary : function() {
  96. //console.log("ShowSummary: plugin called.");
  97. vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
  98. },
  99.  
  100. /**
  101. * loadmap: executed after the first turn has been loaded to create the map
  102. * as far as I can tell not executed again when using time machine
  103. */
  104. loadmap : function() {
  105. if (!vgap.plugins["idleObjectVisualizerPlugin"].mobile_version) {
  106. vgap.map.addMapTool("<span style=\"color:#FF8000\">Idle Visualizer</span>", "ShowMinerals", vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled);
  107. vgap.map.addMapTool("<span style=\"color:#FF8000\">Ship Type Filter</span>", "ShowMinerals", vgap.plugins["idleObjectVisualizerPlugin"].showOverlayFilter);
  108. } else {
  109. vgap.map.addMapTool("Idle Object Visualizer", "idleobjectmenu orangecolor", function () {vgap.plugins["idleObjectVisualizerPlugin"].toggleIdleObjectMenu(); });
  110. vgap.map.addMapTool("Idle Object Visualizer", "typeselectormenu orangecolor", function () {vgap.plugins["idleObjectVisualizerPlugin"].toggleShipFilterObjectMenu(); });
  111.  
  112.  
  113. var head = document.getElementsByTagName('head')[0];
  114. if (head) {
  115. var newCss = document.createElement('style');
  116. newCss.type = "text/css";
  117. newCss.innerHTML = ".orangecolor::before {color: #FF8C00}";
  118. newCss.innerHTML += ".idleobjectmenu::before { content: \"\\f129\"}";
  119. newCss.innerHTML += ".typeselectormenu::before { content: \"\\f0ca\"}";
  120. head.appendChild(newCss);
  121. }
  122.  
  123. if (head) {
  124. var newCss = document.createElement('style');
  125. newCss.type = "text/css";
  126. newCss.innerHTML = "#IdleObjectTools {" +
  127. "position: absolute; " +
  128. "right: 40px; " +
  129. "z-index: 9;" +
  130. "top: 0px;" +
  131. "width: 40px;" +
  132. "height: 300px;" +
  133. "}" +
  134. "#IdleObjectTools .mapbutton {" +
  135. "position: relative;" +
  136. "margin-left: 10px;" +
  137. "margin-bottom: 10px;" +
  138. "float:right;" +
  139. "}";
  140.  
  141. newCss.innerHTML += ".activecolor::before {color: #00a000}";
  142. newCss.innerHTML += ".redcolor::before {color: #FF0000}";
  143. newCss.innerHTML += ".idlemenuhide::before { content: \"\\f105\";}";
  144. newCss.innerHTML += ".idledisable::before { content: \"\\f011\";}";
  145. newCss.innerHTML += ".idlecoloration::before { content: \"\\f53f\";}";
  146. newCss.innerHTML += ".highlightnotready::before { content: \"\\f0c8\";}";
  147. newCss.innerHTML += ".highlightready::before { content: \"\\f00c\"; }";
  148. newCss.innerHTML += ".highlightalwaysready::before { content: \"\\f560\";}";
  149. newCss.innerHTML += ".idleplanets::before { content: \"\\f57d\"; }";
  150. newCss.innerHTML += ".idlebases::before { content: \"\\f447\"; }";
  151. newCss.innerHTML += ".idleships::before { content: \"\\f197\"; }";
  152. newCss.innerHTML += "#IdleObjectShipFilter {" +
  153. "position: absolute; " +
  154. "right: 40px; " +
  155. "z-index: 9;" +
  156. "top: 0px;" +
  157. "width: 40px;" +
  158. "height: 300px;" +
  159. "}" +
  160. "#IdleObjectShipFilter .mapbutton {" +
  161. "position: relative;" +
  162. "margin-left: 10px;" +
  163. "margin-bottom: 10px;" +
  164. "float:right;" +
  165. "}";
  166.  
  167. for (var i = 1; i < vgap.plugins["idleObjectVisualizerPlugin"].shipTypes.length; i++)
  168. {
  169. var startLetter = vgap.plugins["idleObjectVisualizerPlugin"].shipTypes[i].substring(0, 1);
  170. newCss.innerHTML += ".shiptype" + i + "::before { content: '" + startLetter + "';}";
  171. }
  172.  
  173. head.appendChild(newCss);
  174. }
  175. }
  176. },
  177.  
  178. /**
  179. * showmap: executed when switching from dashboard to starmap
  180. */
  181. showmap : function() {
  182. //console.log("ShowMap: plugin called.");
  183. },
  184.  
  185. /**
  186. * draw: executed on any click or drag on the starmap
  187. */
  188. draw : function() {
  189. //console.log("Draw: plugin called.");
  190. vgap.plugins["idleObjectVisualizerPlugin"].drawStatusObjects();
  191. vgap.plugins["idleObjectVisualizerPlugin"].drawFilteredShips();
  192. },
  193.  
  194. /**
  195. * loadplanet: executed a planet is selected on dashboard or starmap
  196. */
  197. loadplanet : function() {
  198. //console.log("LoadPlanet: plugin called.");
  199. },
  200.  
  201. /**
  202. * loadstarbase: executed a planet is selected on dashboard or starmap
  203. */
  204. loadstarbase : function() {
  205. //console.log("LoadStarbase: plugin called.");
  206. },
  207.  
  208. /**
  209. * loadship: executed a planet is selected on dashboard or starmap
  210. */
  211. loadship : function() {
  212. //console.log("LoadShip: plugin called.");
  213. },
  214.  
  215. /***************************************************************************************
  216. * Custom plugin variables
  217. ***************************************************************************************/
  218.  
  219. //things that get saved to disk
  220. version : plugin_version,
  221. plugin_name: "IdleObjectVisualizerPlugin",
  222. //storage_path : "nuIdleObjectPlugin.",
  223.  
  224. // default value for settings:
  225. // plugin enabled default setting
  226. enabled : false,
  227.  
  228. typeSelectorMenuActive : false,
  229. idleObjectMenuActive : false,
  230.  
  231. // object type default values (planets, bases, ships)
  232. drawSelection : [ false, false, true ],
  233.  
  234. // default status (0 = idle, 1 = ready, 2 = permanently ready)
  235. drawStatus : 0,
  236.  
  237. // colors for planets, bases, ships, filtered ships
  238. colors : [ "#990099", "#3399FF", "#FFFF00" , "#FF8000"],
  239.  
  240. // default value if all ships should have same color markers (false) or according to values in 'shipColors' for ship types
  241. colorShipTypes: false,
  242.  
  243. // width of marker circles
  244. lineWidth : 5,
  245.  
  246. // default size of circles (additionally, custom sizes in 'shipMarkerSizes' are used with custom ship type coloring
  247. shipMarkerSize : 15,
  248.  
  249. //ship type groups and their members
  250. shipTypes : ["Merlins", "Refinery Ships", "Fireclouds", "HYP Ships", "Cobols", "Terraformers", "Decloakers", "Freighters"],
  251. shipSelection : [ false, false, false, false, false, false, false, false ],
  252. shipGroupMembers : [ [105], [104,97], [56], [51,77,87,110], [96], [180,64,107,8,3], [7,41,1041,1039,39], []],
  253. // possible custom colors for ship types (with alternative color scheme enabled)
  254. shipColors: [ "", "", "#0511FF", "", "", "FF0000", "", "#00FF00"],
  255. // possible custom circle sizes for ship types (with alternative color scheme enabled)
  256. shipMarkerSizes: [ -1, -1, 25, -1, -1, 10, -1, 20],
  257.  
  258. oldShipScan: null,
  259. mobile_version: false,
  260.  
  261. /***************************************************************************************
  262. * Custom plugin methods
  263. ***************************************************************************************/
  264.  
  265. /**
  266. * Determine if new client version (> 4.0 aka mobile version) is running
  267. */
  268. checkIfMobileVersion: function() {
  269.  
  270. url = window.location.href;
  271. if (vgap.version >= 4.0) {
  272. console.log("Mobile client code detected...");
  273. return true;
  274. } else {
  275. console.log("Non-mobile client code detected...");
  276. return false;
  277. }
  278. },
  279.  
  280. /**
  281. * Enables and disables the plugin
  282. */
  283. enablePlugin : function() {
  284.  
  285. vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorTools(true);
  286.  
  287. vgap.map.draw();
  288. },
  289.  
  290. /**
  291. * Draw locations of object with desired status on the map
  292. */
  293. drawStatusObjects : function() {
  294.  
  295. if (!this.enabled) {
  296. return;
  297. }
  298.  
  299. if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.PLANETS]) {
  300.  
  301. var color_string = this.colors[objectTypeEnum.PLANETS];
  302.  
  303. for ( var p = 0; p < vgap.planets.length; p++) {
  304. var planet = vgap.planets[p];
  305.  
  306. if (planet.ownerid != vgap.player.id) {
  307. continue;
  308. }
  309.  
  310. if (planet.readystatus != this.drawStatus) {
  311. continue;
  312. }
  313.  
  314. this.drawScaledCircle(planet.x, planet.y, 19, color_string, null, 0.5);
  315. }
  316. }
  317.  
  318. if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.BASES]) {
  319.  
  320. var color_string = this.colors[objectTypeEnum.BASES];
  321.  
  322. for ( var p = 0; p < vgap.starbases.length; p++) {
  323. var base = vgap.starbases[p];
  324. var planet = vgap.getPlanet(base.planetid);
  325.  
  326. if (planet.ownerid != vgap.player.id) {
  327. continue;
  328. }
  329.  
  330. if (base.readystatus != this.drawStatus) {
  331. continue;
  332. }
  333.  
  334. this.drawScaledCircle(planet.x, planet.y, 11, color_string, null, 0.7);
  335. }
  336. }
  337.  
  338. if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.SHIPS]) {
  339.  
  340. var color_string = this.colors[objectTypeEnum.SHIPS];
  341.  
  342. for ( var p = 0; p < vgap.ships.length; p++) {
  343. var ship = vgap.ships[p];
  344.  
  345. if (ship.ownerid != vgap.player.id) {
  346. continue;
  347. }
  348.  
  349. if (ship.readystatus != this.drawStatus) {
  350. continue;
  351. }
  352.  
  353. var color_string = this.colors[objectTypeEnum.SHIPS];
  354. var marker_size = this.shipMarkerSize;
  355.  
  356. if (this.colorShipTypes) {
  357. for (var i=0; i<this.shipSelection.length; i++) {
  358.  
  359. //freighters are special
  360. if (i == 7) {
  361. if (ship.beams == 0 && ship.bays == 0 && ship.torps == 0) {
  362. if (this.shipColors[i] !== "") {
  363. color_string = this.shipColors[i];
  364. }
  365. if (this.shipMarkerSizes[i] > 0) {
  366. marker_size = this.shipMarkerSizes[i];
  367. }
  368. break;
  369. }
  370. } else {
  371. for (var t=0; t<this.shipGroupMembers[i].length; t++) {
  372. if (ship.hullid == this.shipGroupMembers[i][t]) {
  373. if (this.shipColors[i] !== "") {
  374. color_string = this.shipColors[i];
  375. }
  376. if (this.shipMarkerSizes[i] > 0) {
  377. marker_size = this.shipMarkerSizes[i];
  378. }
  379. break;
  380. }
  381. }
  382. }
  383. }
  384. }
  385.  
  386. this.drawScaledCircle(ship.x, ship.y, marker_size, color_string, null, 0.5);
  387.  
  388. }
  389. }
  390. },
  391.  
  392.  
  393. /**
  394. * Highlight location of selected ship types on the map
  395. */
  396. drawFilteredShips : function() {
  397.  
  398. var drawAny = false;
  399.  
  400. for (var i=0; i<this.shipSelection.length; i++) {
  401. if (this.shipSelection[i]) {
  402. drawAny = true;
  403. break;
  404. }
  405. }
  406.  
  407. if (drawAny) {
  408.  
  409. var color_string = this.colors[objectTypeEnum.FILTERSHIPS];
  410.  
  411. for ( var p = 0; p < vgap.ships.length; p++) {
  412. var ship = vgap.ships[p];
  413.  
  414. if (ship.ownerid != vgap.player.id) {
  415. continue;
  416. }
  417.  
  418. var drawIt = false;
  419. for (var i=0; i<this.shipSelection.length; i++) {
  420. if (this.shipSelection[i]) {
  421. //freighters are special
  422. if (i == 7) {
  423. if (ship.beams == 0 && ship.bays == 0 && ship.torps == 0) {
  424. drawIt = true;
  425. }
  426. } else {
  427. for (var t=0; t<this.shipGroupMembers[i].length; t++) {
  428. if (ship.hullid == this.shipGroupMembers[i][t]) {
  429. drawIt = true;
  430. break;
  431. }
  432. }
  433. }
  434.  
  435. }
  436. if (drawIt) {
  437. this.drawScaledCircle(ship.x, ship.y, 25, color_string, null, 0.8);
  438. break;
  439. }
  440. }
  441. }
  442. }
  443.  
  444. },
  445.  
  446. /**
  447. * Generate the content for the enemy ship dashboard tab
  448. * @param x x coordinate of ship
  449. * @param y y coordinate of ship
  450. * @param radius radius of circle
  451. * @param color_str color of the drawing
  452. * @param paperset where to draw
  453. * @param alpha alpha value to use
  454. */
  455. drawScaledCircle : function(x, y, radius, color, paperset, alpha) {
  456. if (!vgap.map.isVisible(x, y, radius))
  457. return;
  458. radius *= vgap.map.zoom;
  459. if (radius <= 1)
  460. radius = 1;
  461. if (paperset == null)
  462. paperset = vgap.map.ctx;
  463. paperset.strokeStyle = colorToRGBA(color, alpha);
  464.  
  465. //save original line width
  466. var org_line_width = paperset.lineWidth;
  467.  
  468. paperset.lineWidth = this.lineWidth;
  469. //paperset.setAlpha(0.5);
  470. paperset.beginPath();
  471. paperset.arc(vgap.map.screenX(x), vgap.map.screenY(y), radius, 0, Math.PI * 2, false);
  472. paperset.stroke();
  473.  
  474. //restore previous line width
  475. paperset.lineWidth = org_line_width;
  476.  
  477. },
  478.  
  479. /**
  480. * Toggle the checkbox deciding which player's ships are being displayed
  481. * @param id id of player to toggle
  482. */
  483. toggleSelection : function(id) {
  484.  
  485. if (id < 0 || id > 2) {
  486. return;
  487. }
  488. //console.log("Toggling: " + id);
  489.  
  490. vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[id] = !vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[id];
  491. vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled();
  492. },
  493.  
  494. selectDrawStatus: function(status) {
  495. if (status < 0 || status > 2) {
  496. return;
  497. }
  498.  
  499. vgap.plugins["idleObjectVisualizerPlugin"].drawStatus = status;
  500. vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled();
  501. },
  502.  
  503.  
  504. /**
  505. * Toggle the checkbox deciding which player's ships are being displayed
  506. * @param id id of player to toggle
  507. */
  508. toggleColorSelection : function() {
  509.  
  510. vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes = !vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes;
  511. },
  512.  
  513. /**
  514. * Enable the plugin and show the top menu for selecting what objects (planets/bases/ships) to visualize and for which status
  515. */
  516. showIdleSelectorToolsEnabled : function() {
  517. vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorTools(true);
  518. vgap.map.draw();
  519. },
  520.  
  521. toggleIdleObjectMenu : function() {
  522. if (vgap.plugins["idleObjectVisualizerPlugin"].idleObjectMenuActive) {
  523. $("#IdleObjectTools").remove();
  524. vgap.plugins["idleObjectVisualizerPlugin"].idleObjectMenuActive = false;
  525. }
  526. else {
  527. vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled();
  528. }
  529. },
  530.  
  531. toggleShipFilterObjectMenu : function() {
  532. if (vgap.plugins["idleObjectVisualizerPlugin"].typeSelectorMenuActive) {
  533. $("#IdleObjectShipFilter").remove();
  534. vgap.plugins["idleObjectVisualizerPlugin"].typeSelectorMenuActive = false;
  535. }
  536. else
  537. {
  538. vgap.plugins["idleObjectVisualizerPlugin"].showTypeSelectorTools();
  539. }
  540. },
  541. /**
  542. * Show/refresh the top menu for selecting what objects (planets/bases/ships) to visualize and for which status
  543. */
  544. showIdleSelectorTools : function(enable) {
  545.  
  546. if (enable != null) {
  547. this.enabled = enable;
  548. }
  549.  
  550. if (vgap.plugins["idleObjectVisualizerPlugin"].mobile_version) {
  551. // prevent overlap with other menu
  552. $("#IdleObjectShipFilter").remove();
  553. vgap.plugins["idleObjectVisualizerPlugin"].typeSelectorMenuActive = false;
  554.  
  555. vgap.plugins["idleObjectVisualizerPlugin"].idleObjectMenuActive = true;
  556.  
  557. $("#IdleObjectTools").remove();
  558. $("<div id='IdleObjectTools' " + "></div>").appendTo("#MapControls");
  559. vgap.map.addMapTool("Close Idle Object Visualizer Menu", "idlemenuhide", function () { vgap.plugins['idleObjectVisualizerPlugin'].toggleIdleObjectMenu(); }, "#IdleObjectTools");
  560. vgap.map.addMapTool("Close and disable", "idledisable redcolor", function () {vgap.plugins['idleObjectVisualizerPlugin'].showIdleSelectorTools(false); vgap.plugins['idleObjectVisualizerPlugin'].toggleIdleObjectMenu(); vgap.map.draw();}, "#IdleObjectTools")
  561. vgap.map.addMapTool("Color by ship type", "idlecoloration" + (vgap.plugins['idleObjectVisualizerPlugin'].colorShipTypes ? " activecolor" : ""), function () {vgap.plugins['idleObjectVisualizerPlugin'].toggleColorSelection(); vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled();}, "#IdleObjectTools")
  562. // selectors 'not ready', 'ready', 'always ready'
  563. vgap.map.addMapTool("Not ready", "highlightnotready" + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 0 ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].selectDrawStatus(0)}, "#IdleObjectTools");
  564. vgap.map.addMapTool("Ready", "highlightready" + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 1 ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].selectDrawStatus(1)}, "#IdleObjectTools");
  565. vgap.map.addMapTool("Always ready", "highlightalwaysready" + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 2 ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].selectDrawStatus(2)}, "#IdleObjectTools");
  566. // toggle ships
  567. vgap.map.addMapTool("Ships'", "idleships" + (vgap.plugins['idleObjectVisualizerPlugin'].drawSelection[objectTypeEnum.SHIPS] ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].toggleSelection(objectTypeEnum.SHIPS)}, "#IdleObjectTools");
  568. // toggle bases
  569. vgap.map.addMapTool("Bases'", "idlebases fab" + (vgap.plugins['idleObjectVisualizerPlugin'].drawSelection[objectTypeEnum.BASES] ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].toggleSelection(objectTypeEnum.BASES)}, "#IdleObjectTools");
  570. // toggle planets
  571. vgap.map.addMapTool("Planets'", "idleplanets" + (vgap.plugins['idleObjectVisualizerPlugin'].drawSelection[objectTypeEnum.PLANETS] ? " activecolor" : ""), function() {vgap.plugins["idleObjectVisualizerPlugin"].toggleSelection(objectTypeEnum.PLANETS)}, "#IdleObjectTools");
  572. } else {
  573. $("#IdleToolsContainer").remove();
  574. var html = "<li id='IdleToolsContainer'><div id='ToolSelector'><table><tr>"; // style='border: 1px solid #000000;'>";
  575. html += "<td><label><input id='idle_type_color_option' type='checkbox' "
  576. + (vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes ? "checked" : "")
  577. + " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleColorSelection(); vgap.map.draw();'>"
  578. + "</input>Ship Colors</label></td>";
  579. html += "<td>&nbsp; &nbsp; </td>";
  580. html += "<td>Status <select id='OverlaySelect' onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].drawStatus=parseInt($(\"#OverlaySelect\").val());vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(); vgap.map.draw();'>";
  581.  
  582. html += "<option value=0 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 0 ? "selected" : "")
  583. + ">Not ready</option>";
  584. html += "<option value=1 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 1 ? "selected" : "") + ">Ready</option>";
  585. html += "<option value=2 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 2 ? "selected" : "")
  586. + ">Permanent Ready</option>";
  587.  
  588. html += "</select></td>";
  589.  
  590. html += "<td><label><input id='idle_type_planets' type='checkbox' "
  591. + (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.PLANETS] ? "checked" : "")
  592. + " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.PLANETS
  593. + "); vgap.map.draw();'></input>Planets</label></td>";
  594. html += "<td><label><input id='idle_type_bases' type='checkbox' "
  595. + (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.BASES] ? "checked" : "")
  596. + " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.BASES
  597. + "); vgap.map.draw();'></input>Bases</label></td>";
  598. html += "<td><label><input id='idle_type_ships' type='checkbox' "
  599. + (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.SHIPS] ? "checked" : "")
  600. + " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.SHIPS
  601. + "); vgap.map.draw();'></input>Ships</label></td>";
  602. if (vgap.plugins["idleObjectVisualizerPlugin"].enabled) {
  603.  
  604. html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(false); vgap.map.draw();'><span style='background: #33CC33; padding: 5px;'> Disable </span></td>";
  605. //html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].enabled = false; vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(false); vgap.map.draw();'><span style='background: #33CC33; padding: 5px;'> Disable </span></td>";
  606. } else {
  607. html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(true); vgap.map.draw();'><span style='background: #CC0000; padding: 5px;'> Enable </span></td>";
  608. //html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].enabled = true; vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(true); vgap.map.draw();'><span style='background: #CC0000; padding: 5px;'> Enable </span></td>";
  609. }
  610.  
  611. html += "<td><a class='rNavRight' onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].resetIdleSelectorTools();'></a></td>";
  612. html += "</td></tr></table></div></li>";
  613. $("#PlanetsMenu").prepend(html);
  614. }
  615.  
  616. },
  617.  
  618. resetIdleSelectorTools : function() {
  619.  
  620. $("#IdleToolsContainer").remove();
  621. },
  622.  
  623. /**
  624. * Show/refresh the menu for selecting what ships types to highlight
  625. */
  626. showTypeSelectorTools : function() {
  627. if (vgap.plugins["idleObjectVisualizerPlugin"].mobile_version) {
  628.  
  629. // prevent overlap with other menu
  630. $("#IdleObjectTools").remove();
  631. vgap.plugins["idleObjectVisualizerPlugin"].idleObjectMenuActive = false;
  632.  
  633.  
  634. vgap.plugins["idleObjectVisualizerPlugin"].typeSelectorMenuActive = true;
  635. $("#IdleObjectShipFilter").remove();
  636. $("<div id='IdleObjectShipFilter' " + "></div>").appendTo("#MapControls");
  637. vgap.map.addMapTool("Close Type Filter Menu", "idlemenuhide", function () { vgap.plugins['idleObjectVisualizerPlugin'].toggleShipFilterObjectMenu(); }, "#IdleObjectShipFilter");
  638. // vgap.map.addMapTool("Color by ship type", "idlecoloration" + (vgap.plugins['idleObjectVisualizerPlugin'].colorShipTypes ? " activecolor" : ""), function () {vgap.plugins['idleObjectVisualizerPlugin'].toggleColorSelection();}, "#IdleObjectShipFilter")
  639. for (var i = 1; i < vgap.plugins["idleObjectVisualizerPlugin"].shipTypes.length; i++)
  640. {
  641. vgap.map.addMapTool("Highlight all " + vgap.plugins["idleObjectVisualizerPlugin"].shipTypes[i], "shiptype" + i + (vgap.plugins['idleObjectVisualizerPlugin'].shipSelection[i] ? " activecolor" : ""), vgap.plugins["idleObjectVisualizerPlugin"].toggleFilterSelectionHelper.bind(i) , "#IdleObjectShipFilter");
  642. }
  643. }
  644. },
  645.  
  646. /**
  647. * Show the panel for selecting which ship types to show the ship locations for
  648. */
  649. showOverlayFilter : function () {
  650.  
  651. var html = "<div id='OverlayFilter'><table>";
  652.  
  653. for (var i=0; i<vgap.plugins["idleObjectVisualizerPlugin"].shipTypes.length; i++) {
  654.  
  655.  
  656. var check_text = "";
  657. if (vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[i]) {
  658. check_text = " checked";
  659. }
  660. html += "<tr><td><input type='checkbox' " + check_text + " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleFilterSelection(" + i + "); vgap.map.draw(); '></input></td><td>" + vgap.plugins["idleObjectVisualizerPlugin"].shipTypes[i] + "</td></tr>";
  661. }
  662. html += "</table></div>";
  663. //$("#PlanetsMenu").append(html);
  664.  
  665. var inMore = vgap.planetScreenOpen || vgap.shipScreenOpen || vgap.starbaseScreenOpen;
  666. if (inMore) {
  667. html = "<h1>Show ship locations for:</h1>" + html;
  668. html += "<a class='MoreBack' onclick='vgap.closeMore();vgap.more.empty();return false;'>OK</a>";
  669. vgap.more.empty();
  670. $(html).appendTo(vgap.more);
  671.  
  672. $("#OverlayFilter").height($(window).height() - 100);
  673. vgap.showMore(300);
  674. }
  675. else {
  676. html = "<div class='TitleBar'><div class='CloseScreen' onclick='vgap.closeLeft();vgap.lc.empty();'></div><div class='TopTitle'>Show ship locations for:</div></div>" + html;
  677. vgap.lc.empty();
  678. $(html).appendTo(vgap.lc);
  679. vgap.openLeft();
  680. $("#OverlayFilter").height($(window).height() - 40);
  681. $("#OverlayFilter").width(380);
  682. }
  683. $("#OverlayFilter").jScrollPane();
  684. },
  685.  
  686.  
  687. toggleFilterSelectionHelper : function() {
  688. vgap.plugins["idleObjectVisualizerPlugin"].toggleFilterSelection(this);
  689. vgap.plugins["idleObjectVisualizerPlugin"].showTypeSelectorTools();
  690. vgap.map.draw();
  691. },
  692.  
  693. /**
  694. * Toggle the checkbox deciding which type of ships are being displayed
  695. * @param id id of ship group to toggle
  696. */
  697. toggleFilterSelection : function (id) {
  698. if (id < 0 || id >= vgap.plugins["idleObjectVisualizerPlugin"].shipSelection.length) {
  699. return;
  700. }
  701. vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[id] =! vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[id];
  702. //console.log("Toggling: " + id + " now: " + vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[id]);
  703. this.showOverlayFilter();
  704.  
  705. },
  706.  
  707. }; //end idleObjectVisualizerPlugin
  708.  
  709. // register your plugin with NU
  710. vgap.registerPlugin(idleObjectVisualizerPlugin, "idleObjectVisualizerPlugin");
  711.  
  712. vgap.plugins["idleObjectVisualizerPlugin"].oldClearTools = vgapMap.prototype.clearTools;
  713.  
  714. vgapMap.prototype.clearTools = function(result) {
  715.  
  716. //vgap.plugins["idleObjectVisualizerPlugin"].enabled = false;
  717. vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
  718.  
  719. //clear all ship filters
  720. for (var i=0; i<vgap.plugins["idleObjectVisualizerPlugin"].shipSelection.length; i++) {
  721. vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[i] = false;
  722. }
  723.  
  724. $("#IdleObjectShipFilter").remove();
  725. $("#IdleObjectTools").remove();
  726. vgap.plugins["idleObjectVisualizerPlugin"].idleObjectMenuActive = false;
  727. vgap.plugins["idleObjectVisualizerPlugin"].typeSelectorMenuActive = false;
  728.  
  729. //execute the normal clearTools function
  730. vgap.plugins["idleObjectVisualizerPlugin"].oldClearTools.apply(this, arguments);
  731.  
  732. };
  733.  
  734.  
  735. vgap.plugins["idleObjectVisualizerPlugin"].oldShipScan = sharedContent.prototype.shipScan;
  736. sharedContent.prototype.shipScan = function (ship) {
  737.  
  738. var plugin = vgap.plugins["idleObjectVisualizerPlugin"];
  739.  
  740. // use NU method
  741. var html = plugin.oldShipScan(ship);
  742.  
  743. // then augment the results
  744. var html_element = $(html);
  745. var img_element = html_element.children()[0];
  746.  
  747. if (ship.ownerid == vgap.player.id && plugin.enabled
  748. && plugin.drawSelection[objectTypeEnum.SHIPS] && ship.readystatus == plugin.drawStatus)
  749. {
  750. img_element.style = "border: 2px solid " + plugin.colors[objectTypeEnum.SHIPS];
  751. } else {
  752. img_element.style = "border: 2px solid #F3F5F5";
  753. }
  754.  
  755. return $('<div>').append( html_element.clone() ).html();
  756. };
  757.  
  758.  
  759. leftContent.prototype.oldPicSize = leftContent.prototype.picSize;
  760. leftContent.prototype.picSize = function (mainPic, numItems) {
  761.  
  762. var plugin = vgap.plugins["idleObjectVisualizerPlugin"];
  763. // use NU method
  764. if (!plugin.enabled) {
  765.  
  766. this.oldPicSize(mainPic, numItems);
  767. } else {
  768.  
  769. var picHeight = $(window).height() - 500;
  770. if (picHeight > 250)
  771. picHeight = 250;
  772. if (picHeight < 75)
  773. picHeight = 75;
  774. mainPic.height(picHeight);
  775.  
  776. var fleetwidth = 400 - picHeight;
  777. var fleetheight = picHeight;
  778.  
  779. var fleetpic = 50;
  780. while (true) {
  781. var rows = Math.floor(fleetheight / (fleetpic + 2 + 5));
  782. var cols = Math.floor(fleetwidth / (fleetpic + 2 + 5));
  783. if ((rows * cols) >= numItems)
  784. break;
  785.  
  786. fleetpic -= 1;
  787. }
  788. $(".FleetPic").width(fleetpic);
  789. $(".FleetPic").height(fleetpic);
  790. }
  791. },
  792.  
  793.  
  794. leftContent.prototype.oldShowFleetReady = leftContent.prototype.showFleetReady;
  795. leftContent.prototype.showFleetReady = function () {
  796.  
  797. var plugin = vgap.plugins["idleObjectVisualizerPlugin"];
  798. // use NU method
  799. this.oldShowFleetReady();
  800.  
  801. // augment the result
  802. if (!plugin.enabled) {
  803. return;
  804. }
  805.  
  806. var id = $("#FleetPlanet").data("id");
  807. if (id) {
  808. var planet = vgap.getPlanet(id);
  809.  
  810. if ( (planet.ownerid == vgap.player.id) && plugin.drawSelection[objectTypeEnum.PLANETS] && (planet.readystatus == plugin.drawStatus)) {
  811. $("#FleetPlanet").wrap("<div style='float: left; position: relative; border: 1.5px solid " + plugin.colors[objectTypeEnum.PLANETS] +"'/>");
  812. } else {
  813. $("#FleetPlanet").wrap("<div style='float: left; position: relative; border: 1.5px solid #000000'/>");
  814. }
  815. $("#FleetPlanet").wrap("<div style='border: 1px solid #000000'/>");
  816. }
  817.  
  818.  
  819. id = $("#FleetStarbase").data("id");
  820. if (id) {
  821. var planet = vgap.getPlanet(id);
  822. var starbase = vgap.getStarbase(id);
  823. if (planet.ownerid == vgap.player.id && plugin.drawSelection[objectTypeEnum.BASES] && starbase.readystatus == plugin.drawStatus) {
  824. $("#FleetStarbase").wrap("<div style='float: left; position: relative; border: 1.5px solid " + plugin.colors[objectTypeEnum.BASES] +"'/>");
  825. } else {
  826. $("#FleetStarbase").wrap("<div style='float: left; position: relative; border: 1.5px solid #000000'/>");
  827. }
  828. $("#FleetStarbase").wrap("<div style='border: 1px solid #000000'/>");
  829. }
  830.  
  831. var ships = vgap.shipsAt(this.obj.x, this.obj.y);
  832. for (var i = 0; i < ships.length; i++) {
  833. var ship = ships[i];
  834.  
  835. if (ship.ownerid == vgap.player.id && plugin.drawSelection[objectTypeEnum.SHIPS] && ship.readystatus == plugin.drawStatus) {
  836. $("#FleetContainer #" + ship.id).wrap("<div style='float: left; position: relative; border: 1.5px solid " + plugin.colors[objectTypeEnum.SHIPS] +"'/>");
  837. } else {
  838. $("#FleetContainer #" + ship.id).wrap("<div style='float: left; position: relative; border: 1.5px solid #000000'/>");
  839. }
  840. $("#FleetContainer #" + ship.id).wrap("<div style='border: 1px solid #000000'/>");
  841. }
  842. };
  843.  
  844. } //wrapper for injection
  845.  
  846. var script = document.createElement("script");
  847. script.type = "application/javascript";
  848. script.textContent = "(" + wrapper + ")();";
  849.  
  850. document.body.appendChild(script);
  851. document.body.removeChild(script);