| Scripts/docked_huds_button_data.js |
// JavaScript for Oolite (ECMAScript 5)
"use strict";
this.license = "CC-BY-NC-SA 4.0";
this.author = "Wildeblood";
this.name = "Docked_HUDs_data_sources";
this.version = "1.4.3"; // April 5th, 2026
this._startBlank = false; // Changed to true by the "welcome aboard" sequence.
this._useInFlight = false; // Always false in published version (experimental).
this._word_launch = expandDescription("[docked-huds-ds-word-launch]");
this._word_forward = expandDescription("[docked-huds-ds-word-forward]");
this._word_options = expandDescription("[docked-huds-ds-word-options]");
this._word_sleep = expandDescription("[docked-huds-ds-word-sleep]");
this._word_aft = expandDescription("[docked-huds-ds-word-aft]");
this._word_shipyard = expandDescription("[docked-huds-ds-word-shipyard]");
this._word_refuel = expandDescription("[docked-huds-ds-word-refuel]");
this._word_repairs = expandDescription("[docked-huds-ds-word-repairs]");
this._word_re_arm = expandDescription("[docked-huds-ds-word-re-arm]");
this._word_equipment = expandDescription("[docked-huds-ds-word-equipment]");
this._word_port = expandDescription("[docked-huds-ds-word-port]");
this._word_mail = expandDescription("[docked-huds-ds-word-mail]");
this._word_services = expandDescription("[docked-huds-ds-word-services]");
this._word_starboard = expandDescription("[docked-huds-ds-word-starboard]");
this._word_manifest = expandDescription("[docked-huds-ds-word-manifest]");
this._word_status_hi = expandDescription("[docked-huds-ds-word-status-hi]");
this._word_cash = expandDescription("[docked-huds-ds-word-cash]");
this._word_status = expandDescription("[docked-huds-ds-word-status]");
this._word_longrange = expandDescription("[docked-huds-ds-word-longrange]");
this._word_shortrange = expandDescription("[docked-huds-ds-word-shortrange]");
this._word_destination = expandDescription("[docked-huds-ds-word-destination]");
this._word_navigation = expandDescription("[docked-huds-ds-word-navigation]");
this._word_database = expandDescription("[docked-huds-ds-word-database]");
this._word_commodity = expandDescription("[docked-huds-ds-word-commodity]");
this._word_commodities = expandDescription("[docked-huds-ds-word-commodities]");
this._word_market = expandDescription("[docked-huds-ds-word-market]");
/* ========================================================
MONITORING GOINGS ON
_statusChanged, _repairsNeeded & _cashLow determine
whether F5 is described as "Status", "CASH" or "STATUS".
_repairsAvailable determines whether F3 is described as
"Equipment" or "REPAIRS".
=========================================================== */
this._repairsNeeded = null;
this._repairsAvailable = null;
this._statusChanged = false; // Becomes true if legal status or rank change.
this._legalStatus = null;
this._rank = null;
this._cashLow = false; // Becomes true if cashState falls.
this._cashState = null; // How many digits are in player.credits
/* ========================================================
STILL TO-DO
1. The flag, _repairsNeeded, is surprisingly frustrating.
It encourages me to check the F3 screen, where I learn
the repairs I need are not available on this low-tech
station. What's actually needed is a _repairsAvailable
flag.
2. IMPORTANT: efficient version of the viewDirectionChanged
function that doesn't just set all eight labels every time.
=========================================================== */
this._checkForDamage = function () {
this._repairsNeeded = false;
this._repairsAvailable = false;
var canRepair = 0;
var needRepair = 0;
var self = player.ship;
var eq = self.equipment;
var i = eq.length;
while (i--) {
if (eq[i].isVisible &&
self.equipmentStatus(eq[i]) === "EQUIPMENT_DAMAGED") {
needRepair += 1;
if (eq[i].techLevel <= (system.techLevel + 1)) canRepair += 1;
}
}
if (canRepair > 0) this._repairsAvailable = true;
if (needRepair > 0) this._repairsNeeded = true;
return this._repairsAvailable;
}
this._OLD_checkForDamage = function () {
var self = player.ship;
for (var i = 0; i < self.equipment.length; i++) {
if (self.equipment[i].isVisible &&
self.equipmentStatus(self.equipment[i]) === "EQUIPMENT_DAMAGED") {
this._repairsNeeded = true;
return true;
}
}
this._repairsNeeded = false;
return false;
}
/* ========================================================
BLANK OR SET ALL LABELS
Call gameResumed if we need to re-set all eight labels.
=========================================================== */
this._blankLabels = function () {
var setDial = player.ship.setCustomHUDDial;
for (var i = 1; i < 9; i++) {
setDial("functionKey" + i, "");
setDial("functionIndex" + i, "");
}
}
this.gamePaused = function () {
this._blankLabels();
var self = player.ship;
if (this._useInFlight && !self.docked) {
self.setCustomHUDDial("functionKey2", this._word_options);
self.setCustomHUDDial("functionIndex2", "2");
}
}
this.gameResumed = function () {
this._selectF1Text();
this._selectF2Text();
this._selectF3Text();
this._selectF4Text();
this._selectF5Text();
this._selectF6Text();
this._selectF7Text();
this._selectF8Text();
}
/* ========================================================
LABELS 1-4
These buttons are complicated by the fact that their
function differs when docked and in flight.
Buttons 5, 6, 7 & 8 should be simpler.
=========================================================== */
this._selectF1Text = function () {
var self = player.ship;
if (self.docked) {
self.setCustomHUDDial("functionKey1", this._word_launch);
self.setCustomHUDDial("functionIndex1", "1");
return;
} else {
if (this._useInFlight && self.viewDirection !== "VIEW_FORWARD") {
self.setCustomHUDDial("functionKey1", this._word_forward);
self.setCustomHUDDial("functionIndex1", "1");
return;
} else {
self.setCustomHUDDial("functionKey1", "");
self.setCustomHUDDial("functionIndex1", "");
return false;
}
}
}
this._selectF2Text = function () {
var self = player.ship;
if (guiScreen === "GUI_SCREEN_OPTIONS") {
self.setCustomHUDDial("functionKey2", "");
self.setCustomHUDDial("functionIndex2", "");
return;
} else if (self.docked) {
self.setCustomHUDDial("functionKey2", this._word_sleep);
self.setCustomHUDDial("functionIndex2", "2");
return;
} else {
if (this._useInFlight && self.viewDirection !== "VIEW_AFT") {
self.setCustomHUDDial("functionKey2", this._word_aft);
self.setCustomHUDDial("functionIndex2", "2");
return;
} else {
self.setCustomHUDDial("functionKey2", "");
self.setCustomHUDDial("functionIndex2", "");
return false;
}
}
}
this._selectF3Text = function () {
var self = player.ship;
if (self.docked) {
self.setCustomHUDDial("functionIndex3", "3");
if (guiScreen === "GUI_SCREEN_EQUIP_SHIP") {
self.setCustomHUDDial("functionKey3", this._word_shipyard);
return;
} else if (self.fuel < 7) {
self.setCustomHUDDial("functionKey3", this._word_refuel);
return;
} else if (this._checkForDamage()) {
self.setCustomHUDDial("functionKey3", this._word_repairs);
return;
} else if (self.missileCapacity > self.missiles.length) {
self.setCustomHUDDial("functionKey3", this._word_re_arm);
return;
} else {
self.setCustomHUDDial("functionKey3", this._word_equipment);
return;
}
} else {
if (this._useInFlight && self.viewDirection !== "VIEW_PORT") {
self.setCustomHUDDial("functionKey3", this._word_port);
self.setCustomHUDDial("functionIndex3", "3");
return;
} else {
self.setCustomHUDDial("functionKey3", "");
self.setCustomHUDDial("functionIndex3", "");
return false;
}
}
}
this._selectF4Text = function () {
var self = player.ship;
if (self.docked) {
if (guiScreen === "GUI_SCREEN_INTERFACES") {
self.setCustomHUDDial("functionKey4", "");
self.setCustomHUDDial("functionIndex4", "");
return;
}
self.setCustomHUDDial("functionIndex4", "4");
let es = worldScripts.EmailSystem;
if (es && es.$totalUnreadItems() > 0) {
self.setCustomHUDDial("functionKey4", this._word_mail);
return;
} else {
self.setCustomHUDDial("functionKey4", this._word_services);
return;
}
} else {
if (this._useInFlight && self.viewDirection !== "VIEW_STARBOARD") {
self.setCustomHUDDial("functionKey4", this._word_starboard);
self.setCustomHUDDial("functionIndex4", "4");
return;
} else {
self.setCustomHUDDial("functionKey4", "");
self.setCustomHUDDial("functionIndex4", "");
return false;
}
}
}
/* ========================================================
F5 EVENT LISTENERS
_checkForLowCash is called on every playerBought event
to alert the player if he is getting scandalously short
of money.
alertConditionChanged is used to monitor the player's
legal and killer-elite statuses.
=========================================================== */
this._checkForLowCash = function () {
if (!this._cashLow) {
var cash = player.credits.toString().length;
if (cash < this._cashState) {
this._cashLow = true;
this._cashState = cash;
this._selectF5Text();
} else {
this._cashLow = false;
}
}
}
this.playerBoughtCargo = function () {
this._checkForLowCash();
}
this.playerBoughtEquipment = function () {
this._checkForDamage();
this._checkForLowCash();
// this._selectF3Text();
this._selectF5Text();
}
this.playerBoughtNewShip = function () {
this._checkForLowCash();
}
this.alertConditionChanged = function () {
if (!this._statusChanged) {
if (this._legalStatus !== player.legalStatus ||
this._rank !== player.rank) {
this._statusChanged = true;
this._legalStatus = player.legalStatus;
this._rank = player.rank;
}
}
}
/* ========================================================
LABELS 5-8
These buttons are simpler because the text will be the
same whether docked or in flight. So, the condition tests
if (self.docked) or if (this._useInFlight) are able to
be combined.
=========================================================== */
this._selectF5Text = function () {
var self = player.ship;
if (self.docked || this._useInFlight) {
self.setCustomHUDDial("functionIndex5", "5");
if (guiScreen === "GUI_SCREEN_STATUS") {
self.setCustomHUDDial("functionKey5", this._word_manifest);
this._statusChanged = false;
return;
} else if (this._statusChanged || this._repairsNeeded) {
self.setCustomHUDDial("functionKey5", this._word_status_hi);
return;
} else if (this._cashLow) {
self.setCustomHUDDial("functionKey5", this._word_cash);
return;
} else {
self.setCustomHUDDial("functionKey5", this._word_status);
return;
}
} else {
self.setCustomHUDDial("functionKey5", "");
self.setCustomHUDDial("functionIndex5", "");
return false;
}
}
this._selectF6Text = function () {
var self = player.ship;
if (self.docked || this._useInFlight) {
self.setCustomHUDDial("functionIndex6", "6");
if (guiScreen === "GUI_SCREEN_SHORT_RANGE_CHART") {
self.setCustomHUDDial("functionKey6", this._word_longrange);
return;
} else if (guiScreen === "GUI_SCREEN_LONG_RANGE_CHART") {
self.setCustomHUDDial("functionKey6", this._word_shortrange);
return;
} else if (self.targetSystem === system.ID) {
self.setCustomHUDDial("functionKey6", this._word_destination);
return;
} else {
self.setCustomHUDDial("functionKey6", this._word_navigation);
return;
}
} else {
self.setCustomHUDDial("functionKey6", "");
self.setCustomHUDDial("functionIndex6", "");
return false;
}
}
this._selectF7Text = function () {
var self = player.ship;
if (self.docked || this._useInFlight) {
if (guiScreen === "GUI_SCREEN_SYSTEM_DATA") {
self.setCustomHUDDial("functionKey7", "");
self.setCustomHUDDial("functionIndex7", "");
return;
} else {
self.setCustomHUDDial("functionKey7", this._word_database);
self.setCustomHUDDial("functionIndex7", "7");
return;
}
} else {
self.setCustomHUDDial("functionKey7", "");
self.setCustomHUDDial("functionIndex7", "");
return false;
}
}
this._selectF8Text = function () {
var self = player.ship;
if (self.docked || this._useInFlight) {
self.setCustomHUDDial("functionIndex8", "8");
if (guiScreen === "GUI_SCREEN_MARKET") {
self.setCustomHUDDial("functionKey8", this._word_commodity);
return;
} else if (guiScreen === "GUI_SCREEN_MARKETINFO") {
self.setCustomHUDDial("functionKey8", this._word_commodities);
return;
} else {
self.setCustomHUDDial("functionKey8", this._word_market);
return;
}
} else {
self.setCustomHUDDial("functionKey8", "");
self.setCustomHUDDial("functionIndex8", "");
return false;
}
}
/* ========================================================
MAIN EVENT LISTENERS
=========================================================== */
this.viewDirectionChanged = function (to, from) {
if (this._useInFlight) {
this._selectF1Text();
this._selectF2Text();
this._selectF3Text();
this._selectF4Text();
if (to === "VIEW_GUI_SCREEN" || from === "VIEW_GUI_SCREEN") { // <=============================== CHANGED.
this._selectF5Text();
this._selectF6Text();
this._selectF7Text();
this._selectF8Text();
}
}
}
this.guiScreenChanged = function (to, from) {
if (player.ship.docked || this._useInFlight) {
switch (from) {
case "GUI_SCREEN_MAIN":
this.gameResumed(); // Sets all 8.
return;
case "GUI_SCREEN_OPTIONS":
this._selectF2Text();
break;
case "GUI_SCREEN_EQUIP_SHIP":
case "GUI_SCREEN_SHIPYARD":
this._selectF3Text();
if (to === "GUI_SCREEN_EQUIP_SHIP" ||
to === "GUI_SCREEN_SHIPYARD") {
return;
}
break;
case "GUI_SCREEN_INTERFACES":
this._selectF4Text();
break;
case "GUI_SCREEN_STATUS":
case "GUI_SCREEN_MANIFEST":
this._selectF5Text();
if (to === "GUI_SCREEN_STATUS" ||
to === "GUI_SCREEN_MANIFEST") {
return;
}
break;
case "GUI_SCREEN_SHORT_RANGE_CHART":
case "GUI_SCREEN_LONG_RANGE_CHART":
this._selectF6Text();
if (to === "GUI_SCREEN_SHORT_RANGE_CHART" ||
to === "GUI_SCREEN_LONG_RANGE_CHART") {
return;
}
break;
case "GUI_SCREEN_SYSTEM_DATA":
this._selectF7Text();
break;
case "GUI_SCREEN_MARKET":
case "GUI_SCREEN_MARKETINFO":
this._selectF8Text();
if (to === "GUI_SCREEN_MARKET" ||
to === "GUI_SCREEN_MARKETINFO") {
return;
}
break;
case "GUI_SCREEN_LOAD":
if (!this._startBlank) {
this.gameResumed(); // Sets all 8.
}
return;
}
switch (to) {
case "GUI_SCREEN_OPTIONS":
this._selectF2Text();
break;
case "GUI_SCREEN_EQUIP_SHIP":
case "GUI_SCREEN_SHIPYARD":
this._selectF3Text();
break;
case "GUI_SCREEN_INTERFACES":
this._selectF4Text();
break;
case "GUI_SCREEN_STATUS":
case "GUI_SCREEN_MANIFEST":
this._selectF5Text();
break;
case "GUI_SCREEN_SHORT_RANGE_CHART":
case "GUI_SCREEN_LONG_RANGE_CHART":
this._selectF6Text();
break;
case "GUI_SCREEN_SYSTEM_DATA":
this._selectF7Text();
break;
case "GUI_SCREEN_MARKET":
case "GUI_SCREEN_MARKETINFO":
this._selectF8Text();
break;
}
}
}
/* ========================================================
EVENT LISTENERS, Cont.d
=========================================================== */
this.startUpComplete = function () {
this._statusChanged = false;
this._legalStatus = player.legalStatus;
this._rank = player.rank;
this._cashState = player.credits.toString().length;
}
this.shipWillLaunchFromStation = function () {
this._blankLabels();
}
this.shipLaunchedFromStation = function () {
if (this._useInFlight) {
this.gameResumed();
}
}
/* ========================================================
THE END
=========================================================== */ |
| Scripts/docked_huds_start_sequence.js |
// JavaScript for Oolite (ECMAScript 5)
"use strict";
this.license = "CC-BY-NC-SA 4.0";
this.author = "Wildeblood";
this.name = "Docked_HUDs_start_sequence";
this.version = "1.4.3"; // April 5th, 2026
this._startUpHUD = "docked-start-sequence-hud.plist";
this._onceOnly = true;
this._easterEggs = false;
/* ========================================================
To replay the start sequence later, call:
worldScripts.Docked_HUDs_start_sequence._startSequence();
THE SEQUENCE (takes 11.4 seconds):
=========================================================== */
this._theSequence = function _theSequence () {
var setDial = player.ship.setCustomHUDDial;
var buttons = worldScripts.Docked_HUDs_data_sources;
this._step++;
switch (this._step) {
case 1:
player.ship.hud = this._startUpHUD; // =========== Thrice!
setDial("functionKey1", expandDescription("[docked-huds-main-power]"));
setDial("hudControl", expandDescription("[docked-huds-welcome-aboard]"));
break;
case 2:
setDial("functionKey2", expandDescription("[docked-huds-pilot-aboard]"));
break;
case 3:
buttons._selectF5Text();
setDial("hudControl", expandDescription("[docked-huds-welcome-aboard-commander]"));
break;
case 4:
buttons._selectF6Text();
break;
case 5:
buttons._selectF7Text();
break;
case 6:
buttons._selectF8Text();
if (this._easterEggs) {
setDial("hudControl", expandDescription("[docked-huds-easter-egg-1]"));
}
break;
case 7:
buttons._selectF3Text();
setDial("hudControl", ""); // Clear hudControl
break;
case 8:
buttons._selectF4Text();
break;
default:
if (this._step > 8) { // Although default covers all, the original logic had '> 8'
buttons._selectF1Text();
buttons._selectF2Text();
if (worldScripts.Docked_HUDs) {
worldScripts.Docked_HUDs._selectDockedHUD();
}
this._abortSequence(); // Stop the sequence timer
}
}
}
this._startSequence = function () {
var self = player.ship;
self.hud = this._startUpHUD; // ====================== Twice!
var setDial = self.setCustomHUDDial;
for (var i = 1; i < 9; i++) {
setDial("functionKey" + i, "");
}
self.hudHidden = false;
this._step = 0;
this._sequenceTimer = new Timer(this, _theSequence.bind(this), 1, 1.3);
}
this._abortSequence = function () {
if (this._sequenceTimer) {
this._sequenceTimer.stop();
delete this._sequenceTimer;
}
if (this._onceOnly) {
for (prop in worldScripts[this.name]) {
if (prop !== "oolite_manifest_identifier" &&
prop !== "name" && prop !== "version") {
delete worldScripts[this.name][prop];
}
}
this.version = "0.0";
}
}
/* ========================================================
EVENT LISTENERS
=========================================================== */
this.startUpComplete = function () {
delete this.startUpComplete;
var ds = worldScripts.Docked_HUDs_data_sources;
if (ds) {
ds._startBlank = true;
} else {
this._onceOnly = true;
this._abortSequence();
}
}
this.guiScreenChanged = function (to, from) {
if (from === "GUI_SCREEN_LOAD") {
player.ship.hud = this._startUpHUD; // =========== Once!
this._startSequence();
} else if (to === "GUI_SCREEN_OPTIONS") {
this._abortSequence();
}
}
this.shipWillLaunchFromStation = function () {
this._abortSequence();
}
this.gamePaused = function () {
this._abortSequence();
}
/* ========================================================
THE END
=========================================================== */ |