| Config/script.js | "use strict";
this.name               = "manifest_mfd";
this.author               = "spara";
this.description         = "Manifest info as an MFD";
//public function to notify about content changes
this.notifyCargoChange = function() {
	this.$updateManifestMFD();
}
//tracks changes in cargo space
this.$prevCargoSpaceUsed = player.ship.cargoSpaceUsed;
//update the mfd message and start a framecallback on launch
this.shipWillLaunchFromStation = function() {
	this.$updateManifestMFD();
	if (!this.$manifestMFD) {
		this.$manifestMFD = addFrameCallback(this.$manifestMonitor.bind(this));
	}
}
//remove framecallback on docking
this.shipWillDockWithStation = function() {
	if (this.$manifestMFD) {
		removeFrameCallback(this.$manifestMFD);
		delete this.$manifestMFD;
	}
}
//monitor volume changes in cargo hold.
this.$manifestMonitor = function() {
	var currCargoSpaceUsed = player.ship.cargoSpaceUsed;
	//cargo scooped, destroyed or jettisoned
	if (currCargoSpaceUsed !== this.$prevCargoSpaceUsed) {
		this.$updateManifestMFD();
		this.$prevCargoSpaceUsed = currCargoSpaceUsed;
	}
}
//update the mfd message
this.$updateManifestMFD = function() {
	if (player.ship.equipmentStatus("EQ_MANIFEST_MFD") === "EQUIPMENT_OK") {
		var message = "Cargo " + player.ship.cargoSpaceUsed + " t (" + player.ship.cargoSpaceCapacity + " t):\n";
		if (manifest.list.length === 0) message = message + " None.";
		else {
			var pieces = new Array();
			for (var i = 0; i < manifest.list.length; i++) {
				var m = manifest.list[i];
				pieces.push(m.quantity + " " + String.fromCharCode(215) + " "+ m.displayName);
			}
			var twoColumnRows = pieces.length - 9;
			var i = 0;
			if (twoColumnRows > 0) {
				var hairSpace = String.fromCharCode(31);
				var hairSpaceLength = defaultFont.measureString(hairSpace);
				for (i = 0; i < twoColumnRows; i++) {
					var line = " " + pieces[i];
					var currentLength = global.defaultFont.measureString(line);
					var padsNeeded = Math.floor((7.5 - currentLength) / hairSpaceLength);
					if (padsNeeded >= 1) {
						var pads = new Array(padsNeeded).join(hairSpace);
					}
					line = line + pads;
					message = message + line + pieces[i+9] + "\n";
				}
			}
			var rows = 9;
			if (pieces.length < 9) rows = pieces.length;
			for (var j = i; j < rows; j++) {
				message = message + " " + pieces[j] + "\n";
			}
		}
		player.ship.setMultiFunctionText("manifest_mfd", message);
	}
	else player.ship.setMultiFunctionText("manifest_mfd", null);
}
 |