"use strict";

this.name = "market_ads";
this.author = "spara";
this.description = "Add ads to the market screen when docked";

this.startUp = function() {
	this.$marketHud = "market_ads_hud.plist";//init market hud
	this.$restoreHud = player.ship.hud;//init restore hud
	this.$restoreTargetSensitivity = player.ship.reticleTargetSensitive;//for restoring target sensivity
}

this.guiScreenChanged = function(to, from) {
	//no ads in-flight
	if (!player.ship.docked) return;
	if (guiScreen.indexOf("GUI_SCREEN_MARKET") !== -1) { //swap to market hud
		if (player.ship.hud !== this.$marketHud) {
			this.$restoreHud = player.ship.hud;
			this.$restoreTargetSensitivity = player.ship.reticleTargetSensitive;
		}
		
		//set ads & swap hud
		var adService = worldScripts["market_ads_service"];
		var leftAd = adService._getHorizontalAd();
		var rightAd = adService._getHorizontalAd();
		
		player.ship.setCustomHUDDial("marketAdLeft", leftAd);
		player.ship.setCustomHUDDial("marketAdRight", rightAd);
		
		player.ship.hud = this.$marketHud;
	} 
	//restore hud
	else if (player.ship.hud === this.$marketHud) {
		player.ship.hud = this.$restoreHud;
		player.ship.reticleTargetSensitive = this.$restoreTargetSensitivity;
	}
}

