// ==UserScript==
// @name Planets.nu - Idle Object Visualizer Plugin
// @namespace kedalion/idleObjectVisualizer
// @version 0.63
// @date 2017-06-04
// @author kedalion
// @description NU plugin which displays all planets, starbases, and ships that are marked idle, ready, or permanently ready
// @include http://planets.nu/*
// @include http://play.planets.nu/*
// @include http://test.planets.nu/*
// @resource userscript https://greasyfork.org/en/scripts/6442-planets-nu-idle-object-visualizer-plugin
// @homepage http://planets.nu/discussion/utility-script-idle-object-visualizer-plugin
// ==/UserScript==
/*
Change log:
0.63 Fixed conflict with ship tow indicator (thanks Mabeco) [2017-06-04]
0.62 Added alternative ship coloring as used by Glyn [2017-06-04]
0.61 Move script location to greasyfork.org [2014-11-13]
0.6 Move script location to monkeyguts.com [2014-05-30]
0.58 No fleet view for single objects [2014-04-26]
0.57 Added filters for ship types [2014-04-24]
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]
0.55 Fixed small bug in planet color [2014-04-15]
0.54 Added auto enabled after selection in map tools [2014-02-18]
0.53 Fixed line width bug [2014-02-16]
0.51 Added enable/disable buttons [2014-02-11]
0.5 Initial alpha release [2014-02-11]
*/
function wrapper() { // wrapper for injection
if (vgap.version < 3.0) {
console.log("IdleObjectVisualizer plugin requires at least NU version 3.0. Plugin disabled.");
return;
}
var plugin_version = 0.63;
console.log("IdleObjectVisualizer plugin version: v" + plugin_version + "." );
objectTypeEnum = {
PLANETS : 0,
BASES : 1,
SHIPS : 2,
FILTERSHIPS : 3
};
/**
* Specify your plugin
* You need to have all those methods defined or errors will be thrown.
* I inserted the print-outs in order to demonstrate when each method is
* being called. Just comment them out once you know your way around.
*
* For any access to plugin class variables and methods,
* "vgap.plugins["idleObjectVisualizerPlugin"].my_variable" has to be used
* instead of "this.my_variable".
*/
var idleObjectVisualizerPlugin = {
/**
* processload: executed whenever a turn is loaded: either the current turn or
* an older turn through time machine
*/
processload : function() {
//console.log("ProcessLoad: plugin called.");
},
/**
* loaddashboard: executed to rebuild the dashboard content after a turn is loaded
*/
loaddashboard : function() {
//console.log("LoadDashboard: plugin called.");
},
/**
* showdashboard: executed when switching from starmap to dashboard
*/
showdashboard : function() {
//console.log("ShowDashboard: plugin called.");
vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
},
/**
* showsummary: executed when returning to the main screen of the dashboard
*/
showsummary : function() {
//console.log("ShowSummary: plugin called.");
vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
},
/**
* loadmap: executed after the first turn has been loaded to create the map
* as far as I can tell not executed again when using time machine
*/
loadmap : function() {
//console.log("LoadMap: plugin called.");
vgap.map.addMapTool("<span style=\"color:#FF8000\">Idle Visualizer</span>", "ShowMinerals", vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorToolsEnabled);
vgap.map.addMapTool("<span style=\"color:#FF8000\">Ship Type Filter</span>", "ShowMinerals", vgap.plugins["idleObjectVisualizerPlugin"].showOverlayFilter);
vgap.plugins["idleObjectVisualizerPlugin"].enabled = false;
vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[0] = false;
vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[1] = false;
vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[2] = true;
vgap.plugins["idleObjectVisualizerPlugin"].drawStatus = 0;
for (var i=0; i<vgap.plugins["idleObjectVisualizerPlugin"].shipSelection.length; i++) {
vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[i] = false;
}
},
/**
* showmap: executed when switching from dashboard to starmap
*/
showmap : function() {
//console.log("ShowMap: plugin called.");
},
/**
* draw: executed on any click or drag on the starmap
*/
draw : function() {
//console.log("Draw: plugin called.");
vgap.plugins["idleObjectVisualizerPlugin"].drawStatusObjects();
vgap.plugins["idleObjectVisualizerPlugin"].drawFilteredShips();
},
/**
* loadplanet: executed a planet is selected on dashboard or starmap
*/
loadplanet : function() {
//console.log("LoadPlanet: plugin called.");
},
/**
* loadstarbase: executed a planet is selected on dashboard or starmap
*/
loadstarbase : function() {
//console.log("LoadStarbase: plugin called.");
},
/**
* loadship: executed a planet is selected on dashboard or starmap
*/
loadship : function() {
//console.log("LoadShip: plugin called.");
},
/***************************************************************************************
* Custom plugin variables
***************************************************************************************/
//things that get saved to disk
version : plugin_version,
plugin_name: "IdleObjectVisualizerPlugin",
//storage_path : "nuIdleObjectPlugin.",
//other variables
enabled : false,
drawSelection : [ false, false, true ],
drawStatus : 0,
//drawMode : true,
colors : [ "#990099", "#3399FF", "#FFFF00" , "#FF8000"],
colorShipTypes: false,
//[ "#990099", "#3399FF", "#FFFF00" ],
//[ "#FF3399", "#3399FF", "#FFFF00" ],
//["#FFFF00","#66FF33","#009933"],
lineWidth : 5,
shipMarkerSize : 15,
//ship types
shipTypes : ["Merlins", "Refinery Ships", "Fireclouds", "HYP Ships", "Cobols", "Terraformers", "Decloakers", "Freighters"],
shipSelection : [ false, false, false, false, false, false, false, false ],
shipGroupMembers : [ [105], [104,97], [56], [51,77,87,110], [96], [180,64,107,8,3], [7,41,1041,1039,39], []],
shipColors: [ "", "", "#0511FF", "", "", "FF0000", "", "#00FF00"],
shipMarkerSizes: [ -1, -1, 25, -1, -1, 10, -1, 20],
oldPlanetScan: null,
oldStarbaseScan: null,
oldShipScan: null,
/***************************************************************************************
* Custom plugin methods
***************************************************************************************/
/**
* Enables and disables the plugin
*/
enablePlugin : function() {
// if (vgap.plugins["idleObjectVisualizerPlugin"].enabled) {
// vgap.plugins["idleObjectVisualizerPlugin"].enabled = false;
// } else {
//vgap.plugins["idleObjectVisualizerPlugin"].enabled = true;
vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorTools(true);
// }
// vgap.plugins["idleObjectVisualizerPlugin"].syncButtons();
vgap.map.draw();
},
/**
* Draw locations of object with desired status on the map
*/
drawStatusObjects : function() {
if (!this.enabled) {
return;
}
if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.PLANETS]) {
var color_string = this.colors[objectTypeEnum.PLANETS];
for ( var p = 0; p < vgap.planets.length; p++) {
var planet = vgap.planets[p];
if (planet.ownerid != vgap.player.id) {
continue;
}
if (planet.readystatus != this.drawStatus) {
continue;
}
this.drawScaledCircle(planet.x, planet.y, 19, color_string, null, 0.5);
}
}
if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.BASES]) {
var color_string = this.colors[objectTypeEnum.BASES];
for ( var p = 0; p < vgap.starbases.length; p++) {
var base = vgap.starbases[p];
var planet = vgap.getPlanet(base.planetid);
if (planet.ownerid != vgap.player.id) {
continue;
}
if (base.readystatus != this.drawStatus) {
continue;
}
this.drawScaledCircle(planet.x, planet.y, 11, color_string, null, 0.7);
}
}
if (this.drawSelection[objectTypeEnum.ALL] || this.drawSelection[objectTypeEnum.SHIPS]) {
var color_string = this.colors[objectTypeEnum.SHIPS];
for ( var p = 0; p < vgap.ships.length; p++) {
var ship = vgap.ships[p];
if (ship.ownerid != vgap.player.id) {
continue;
}
if (ship.readystatus != this.drawStatus) {
continue;
}
var color_string = this.colors[objectTypeEnum.SHIPS];
var marker_size = this.shipMarkerSize;
if (this.colorShipTypes) {
for (var i=0; i<this.shipSelection.length; i++) {
//freighters are special
if (i == 7) {
if (ship.beams == 0 && ship.bays == 0 && ship.torps == 0) {
if (this.shipColors[i] !== "") {
color_string = this.shipColors[i];
}
if (this.shipMarkerSizes[i] > 0) {
marker_size = this.shipMarkerSizes[i];
}
break;
}
} else {
for (var t=0; t<this.shipGroupMembers[i].length; t++) {
if (ship.hullid == this.shipGroupMembers[i][t]) {
if (this.shipColors[i] !== "") {
color_string = this.shipColors[i];
}
if (this.shipMarkerSizes[i] > 0) {
marker_size = this.shipMarkerSizes[i];
}
break;
}
}
}
}
}
this.drawScaledCircle(ship.x, ship.y, marker_size, color_string, null, 0.5);
}
}
},
/**
* Highlight location of selected ship types on the map
*/
drawFilteredShips : function() {
var drawAny = false;
for (var i=0; i<this.shipSelection.length; i++) {
if (this.shipSelection[i]) {
drawAny = true;
break;
}
}
if (drawAny) {
var color_string = this.colors[objectTypeEnum.FILTERSHIPS];
for ( var p = 0; p < vgap.ships.length; p++) {
var ship = vgap.ships[p];
if (ship.ownerid != vgap.player.id) {
continue;
}
var drawIt = false;
for (var i=0; i<this.shipSelection.length; i++) {
if (this.shipSelection[i]) {
//freighters are special
if (i == 7) {
if (ship.beams == 0 && ship.bays == 0 && ship.torps == 0) {
drawIt = true;
}
} else {
for (var t=0; t<this.shipGroupMembers[i].length; t++) {
if (ship.hullid == this.shipGroupMembers[i][t]) {
drawIt = true;
break;
}
}
}
}
if (drawIt) {
this.drawScaledCircle(ship.x, ship.y, 25, color_string, null, 0.8);
break;
}
}
}
}
},
/**
* Generate the content for the enemy ship dashboard tab
* @param x x coordinate of ship
* @param y y coordinate of ship
* @param radius radius of circle
* @param color_str color of the drawing
* @param paperset where to draw
* @param alpha alpha value to use
*/
drawScaledCircle : function(x, y, radius, color, paperset, alpha) {
if (!vgap.map.isVisible(x, y, radius))
return;
radius *= vgap.map.zoom;
if (radius <= 1)
radius = 1;
if (paperset == null)
paperset = vgap.map.ctx;
paperset.strokeStyle = colorToRGBA(color, alpha);
//save original line width
var org_line_width = paperset.lineWidth;
paperset.lineWidth = this.lineWidth;
//paperset.setAlpha(0.5);
paperset.beginPath();
paperset.arc(vgap.map.screenX(x), vgap.map.screenY(y), radius, 0, Math.PI * 2, false);
paperset.stroke();
//restore previous line width
paperset.lineWidth = org_line_width;
},
/**
* Toggle the checkbox deciding which player's ships are being displayed
* @param id id of player to toggle
*/
toggleSelection : function(id) {
if (id < 0 || id > 2) {
return;
}
//console.log("Toggling: " + id);
vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[id] = !vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[id];
},
/**
* Toggle the checkbox deciding which player's ships are being displayed
* @param id id of player to toggle
*/
toggleColorSelection : function() {
vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes = !vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes;
},
/**
* Enable the plugin and show the top menu for selecting what objects (planets/bases/ships) to visualize and for which status
*/
showIdleSelectorToolsEnabled : function() {
vgap.plugins["idleObjectVisualizerPlugin"].showIdleSelectorTools(true);
vgap.map.draw();
},
/**
* Show/refresh the top menu for selecting what objects (planets/bases/ships) to visualize and for which status
*/
showIdleSelectorTools : function(enable) {
$("#IdleToolsContainer").remove();
if (enable != null)
this.enabled = enable;
var html = "<li id='IdleToolsContainer'><div id='ToolSelector'><table><tr>"; // style='border: 1px solid #000000;'>";
html += "<td><label><input id='idle_type_color_option' type='checkbox' "
+ (vgap.plugins["idleObjectVisualizerPlugin"].colorShipTypes ? "checked" : "")
+ " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleColorSelection(); vgap.map.draw();'>"
+ "</input>Ship Colors</label></td>";
html += "<td> </td>";
html += "<td>Status <select id='OverlaySelect' onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].drawStatus=parseInt($(\"#OverlaySelect\").val());vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(); vgap.map.draw();'>";
html += "<option value=0 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 0 ? "selected" : "")
+ ">Not ready</option>";
html += "<option value=1 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 1 ? "selected" : "") + ">Ready</option>";
html += "<option value=2 " + (vgap.plugins['idleObjectVisualizerPlugin'].drawStatus == 2 ? "selected" : "")
+ ">Permanent Ready</option>";
html += "</select></td>";
html += "<td><label><input id='idle_type_planets' type='checkbox' "
+ (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.PLANETS] ? "checked" : "")
+ " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.PLANETS
+ "); vgap.map.draw();'></input>Planets</label></td>";
html += "<td><label><input id='idle_type_bases' type='checkbox' "
+ (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.BASES] ? "checked" : "")
+ " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.BASES
+ "); vgap.map.draw();'></input>Bases</label></td>";
html += "<td><label><input id='idle_type_ships' type='checkbox' "
+ (vgap.plugins["idleObjectVisualizerPlugin"].drawSelection[objectTypeEnum.SHIPS] ? "checked" : "")
+ " onchange='vgap.plugins[\"idleObjectVisualizerPlugin\"].toggleSelection(" + objectTypeEnum.SHIPS
+ "); vgap.map.draw();'></input>Ships</label></td>";
if (vgap.plugins["idleObjectVisualizerPlugin"].enabled) {
html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(false); vgap.map.draw();'><span style='background: #33CC33; padding: 5px;'> Disable </span></td>";
//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>";
} else {
html += "<td onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].showIdleSelectorTools(true); vgap.map.draw();'><span style='background: #CC0000; padding: 5px;'> Enable </span></td>";
//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>";
}
html += "<td><a class='rNavRight' onclick='vgap.plugins[\"idleObjectVisualizerPlugin\"].resetIdleSelectorTools();'></a></td>";
html += "</td></tr></table></div></li>";
$("#PlanetsMenu").prepend(html);
},
resetIdleSelectorTools : function() {
$("#IdleToolsContainer").remove();
},
/**
* Show the panel for selecting which ship types to show the ship locations for
*/
showOverlayFilter : function () {
var html = "<div id='OverlayFilter'><table>";
for (var i=0; i<vgap.plugins["idleObjectVisualizerPlugin"].shipTypes.length; i++) {
var check_text = "";
if (vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[i]) {
check_text = " checked";
}
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>";
}
html += "</table></div>";
//$("#PlanetsMenu").append(html);
var inMore = vgap.planetScreenOpen || vgap.shipScreenOpen || vgap.starbaseScreenOpen;
if (inMore) {
html = "<h1>Show ship locations for:</h1>" + html;
html += "<a class='MoreBack' onclick='vgap.closeMore();vgap.more.empty();return false;'>OK</a>";
vgap.more.empty();
$(html).appendTo(vgap.more);
$("#OverlayFilter").height($(window).height() - 100);
vgap.showMore(300);
}
else {
html = "<div class='TitleBar'><div class='CloseScreen' onclick='vgap.closeLeft();vgap.lc.empty();'></div><div class='TopTitle'>Show ship locations for:</div></div>" + html;
vgap.lc.empty();
$(html).appendTo(vgap.lc);
vgap.openLeft();
$("#OverlayFilter").height($(window).height() - 40);
$("#OverlayFilter").width(380);
}
$("#OverlayFilter").jScrollPane();
},
/**
* Toggle the checkbox deciding which type of ships are being displayed
* @param id id of ship group to toggle
*/
toggleFilterSelection : function (id) {
if (id < 0 || id >= vgap.plugins["idleObjectVisualizerPlugin"].shipSelection.length) {
return;
}
//console.log("Toggling: " + id);
vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[id] =! vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[id];
this.showOverlayFilter();
},
}; //end idleObjectVisualizerPlugin
// register your plugin with NU
vgap.registerPlugin(idleObjectVisualizerPlugin, "idleObjectVisualizerPlugin");
vgap.plugins["idleObjectVisualizerPlugin"].oldClearTools = vgapMap.prototype.clearTools;
vgapMap.prototype.clearTools = function(result) {
//vgap.plugins["idleObjectVisualizerPlugin"].enabled = false;
vgap.plugins["idleObjectVisualizerPlugin"].resetIdleSelectorTools();
//clear all ship filters
for (var i=0; i<vgap.plugins["idleObjectVisualizerPlugin"].shipSelection.length; i++) {
vgap.plugins["idleObjectVisualizerPlugin"].shipSelection[i] = false;
}
//execute the normal clearTools function
vgap.plugins["idleObjectVisualizerPlugin"].oldClearTools.apply(this, arguments);
};
vgap.plugins["idleObjectVisualizerPlugin"].oldShipScan = sharedContent.prototype.shipScan;
sharedContent.prototype.shipScan = function (ship) {
var plugin = vgap.plugins["idleObjectVisualizerPlugin"];
// use NU method
var html = plugin.oldShipScan(ship);
// then augment the results
var html_element = $(html);
var img_element = html_element.children()[0];
if (ship.ownerid == vgap.player.id && plugin.enabled
&& plugin.drawSelection[objectTypeEnum.SHIPS] && ship.readystatus == plugin.drawStatus)
{
img_element.style = "border: 2px solid " + plugin.colors[objectTypeEnum.SHIPS];
} else {
img_element.style = "border: 2px solid #F3F5F5";
}
return $('<div>').append( html_element.clone() ).html();
};
leftContent.prototype.oldShowFleetReady = leftContent.prototype.showFleetReady;
leftContent.prototype.showFleetReady = function () {
var plugin = vgap.plugins["idleObjectVisualizerPlugin"];
// use NU method
this.oldShowFleetReady();
// augment the result
if (!plugin.enabled) {
return;
}
var id = $("#FleetPlanet").data("id");
if (id) {
var planet = vgap.getPlanet(id);
if ( (planet.ownerid == vgap.player.id) && plugin.drawSelection[objectTypeEnum.PLANETS] && (planet.readystatus == plugin.drawStatus)) {
$("#FleetPlanet").wrap("<div style='border: 1.5px solid " + plugin.colors[objectTypeEnum.PLANETS] +"'/>");
} else {
$("#FleetPlanet").wrap("<div style='border: 1.5px solid #000000'/>");
}
$("#FleetPlanet").wrap("<div style='border: 1px solid #000000'/>");
}
id = $("#FleetStarbase").data("id");
if (id) {
var planet = vgap.getPlanet(id);
var starbase = vgap.getStarbase(id);
if (planet.ownerid == vgap.player.id && plugin.drawSelection[objectTypeEnum.BASES] && starbase.readystatus == plugin.drawStatus) {
$("#FleetStarbase").wrap("<div style='border: 1.5px solid " + plugin.colors[objectTypeEnum.BASES] +"'/>");
} else {
$("#FleetStarbase").wrap("<div style='border: 1.5px solid #000000'/>");
}
$("#FleetStarbase").wrap("<div style='border: 1px solid #000000'/>");
}
var ships = vgap.shipsAt(this.obj.x, this.obj.y);
for (var i = 0; i < ships.length; i++) {
var ship = ships[i];
if (ship.ownerid == vgap.player.id && plugin.drawSelection[objectTypeEnum.SHIPS] && ship.readystatus == plugin.drawStatus) {
$("#FleetContainer #" + ship.id).wrap("<div style='border: 1.5px solid " + plugin.colors[objectTypeEnum.SHIPS] +"'/>");
} else {
$("#FleetContainer #" + ship.id).wrap("<div style='border: 1.5px solid #000000'/>");
}
$("#FleetContainer #" + ship.id).wrap("<div style='border: 1px solid #000000'/>");
}
};
} //wrapper for injection
var script = document.createElement("script");
script.type = "application/javascript";
script.textContent = "(" + wrapper + ")();";
document.body.appendChild(script);
document.body.removeChild(script);