diff --git a/src/Corporation/manageCorporation.js b/src/Corporation/manageCorporation.js index c18d9f886c475bcd4d04c1c918cf5b4cc069a942..1dc7d2476b6deacde575af237db90150fc7473fe 100644 --- a/src/Corporation/manageCorporation.js +++ b/src/Corporation/manageCorporation.js @@ -108,24 +108,25 @@ App.Corporate.manage = function() { const el = new DocumentFragment(); App.UI.DOM.appendNewElement("h1", el, "Division Management"); + const tabBar = new App.UI.Tabs.TabBar("SlaveInteract"); + for (let division of App.Corporate.divisionList) { if (!division.founded) { continue; } - - App.UI.DOM.appendNewElement("h2", el, `${division.name} Division`); + const frag = new DocumentFragment(); if (division.foundedDate !== 0) { - App.UI.DOM.appendNewElement("div", el, `Founded on ${asDateString(division.foundedDate)}.`, "founding"); + App.UI.DOM.appendNewElement("div", frag, `Founded on ${asDateString(division.foundedDate)}.`, "founding"); } - App.UI.DOM.appendNewElement("div", el, `This division focuses on ${division.focusDescription}.`); + App.UI.DOM.appendNewElement("div", frag, `This division focuses on ${division.focusDescription}.`); let div = document.createElement("div"); $(div).append(division.messageSlaveCount()); - el.append(div); + frag.append(div); let divMaint = division.getDisplayMaintenanceCost(); - addDiv(el, "It costs ", + addDiv(frag, "It costs ", App.UI.DOM.makeElement("span", cashFormat(Math.trunc(divMaint.cost)), ["cash", "dec"]), " to run. On average that is ", App.UI.DOM.makeElement("span", cashFormat(Math.trunc(divMaint.perUnit)), ["cash", "dec"]), @@ -133,18 +134,18 @@ App.Corporate.manage = function() { div = document.createElement("div"); $(div).append(division.messageSlaveOutput()); - el.append(div); + frag.append(div); let divSentenceStart = ["Currently the division", "It also"]; - App.UI.DOM.appendNewElement("h3", el, "Direct Control"); + App.UI.DOM.appendNewElement("h3", frag, "Direct Control"); if (division.fromMarket) { - addDiv(el, `${divSentenceStart.shift()} is ${division.slaveAction.present} `, + addDiv(frag, `${divSentenceStart.shift()} is ${division.slaveAction.present} `, App.UI.DOM.makeElement("span", numberWithPlural(division.activeSlaves, "slave"), "green")); if (division.activeSlaves < division.developmentCount) { let fillSlaveCount = division.availableRoom; - addDiv(el, `There is room to ${division.slaveAction.future} ${numberWithPluralOne(fillSlaveCount, "more slave")}.`); + addDiv(frag, `There is room to ${division.slaveAction.future} ${numberWithPluralOne(fillSlaveCount, "more slave")}.`); let buySlaveArray = [ {'name': 'Buy Slave', 'count': 1}, @@ -156,7 +157,7 @@ App.Corporate.manage = function() { } let singleSlaveCost = App.Corporate.slaveMarketPurchaseValue(division, 1); if (V.corp.Cash > singleSlaveCost) { - addDiv(el, `The corporation can purchase slaves directly from the market for about `, + addDiv(frag, `The corporation can purchase slaves directly from the market for about `, cashFormatColor(singleSlaveCost), "."); const links = []; @@ -171,25 +172,25 @@ App.Corporate.manage = function() { refresh(); })); } - el.append(App.UI.DOM.generateLinksStrip(links)); + frag.append(App.UI.DOM.generateLinksStrip(links)); } else { - addDiv(el, App.UI.DOM.makeElement("span", "The corporation cannot afford to purchase any slaves from the market.", "note"), " It requires about ", + addDiv(frag, App.UI.DOM.makeElement("span", "The corporation cannot afford to purchase any slaves from the market.", "note"), " It requires about ", App.UI.DOM.makeElement("span", cashFormat(singleSlaveCost), "cash"), ` to buy a ${asSingular(division.slaveAction.market)}.`); } } else { - addDiv(el, "There is ", App.UI.DOM.makeElement("em", "no room"), ` to ${division.slaveAction.future} more slaves.`); + addDiv(frag, "There is ", App.UI.DOM.makeElement("em", "no room"), ` to ${division.slaveAction.future} more slaves.`); } } if (division.toMarket) { let finishedSlaveNoun = division.nounFinishedSlave; if (division.heldSlaves > 0) { - addDiv(el, `${divSentenceStart.shift()} holds `, + addDiv(frag, `${divSentenceStart.shift()} holds `, App.UI.DOM.makeElement("span", numberWithPlural(division.heldSlaves, finishedSlaveNoun), "green"), "."); for (const nextDiv of division.relatedDivisions.to .filter(div => div.availableRoom > 0 && !App.Corporate.ownsIntermediaryDivision(division, div))) { - addDiv(el, `The ${nextDiv.name} Division can accept up to `, App.UI.DOM.makeElement("span", numberWithPlural(nextDiv.availableRoom, "slave"), "green"), "."); + addDiv(frag, `The ${nextDiv.name} Division can accept up to `, App.UI.DOM.makeElement("span", numberWithPlural(nextDiv.availableRoom, "slave"), "green"), "."); let sendSlaveArray = [ {'name': 'Send Slave', 'count': 1}, @@ -210,10 +211,10 @@ App.Corporate.manage = function() { refresh(); })); } - el.append(App.UI.DOM.generateLinksStrip(links)); + frag.append(App.UI.DOM.generateLinksStrip(links)); } - App.UI.DOM.appendNewElement("div", el, "The corporation can sell these slaves to the market."); + App.UI.DOM.appendNewElement("div", frag, "The corporation can sell these slaves to the market."); let sellSlaveArray = [ {'name': 'Sell Slave', 'count': 1}, @@ -229,9 +230,9 @@ App.Corporate.manage = function() { refresh(); })); } - el.append(App.UI.DOM.generateLinksStrip(links)); + frag.append(App.UI.DOM.generateLinksStrip(links)); } else { - App.UI.DOM.appendNewElement("div", el, `The division is not holding any ${asPlural(finishedSlaveNoun)}.`); + App.UI.DOM.appendNewElement("div", frag, `The division is not holding any ${asPlural(finishedSlaveNoun)}.`); } } @@ -240,7 +241,7 @@ App.Corporate.manage = function() { /* Expanding the division*/ let depExpandCost = division.sizeCost * 1000; - addDiv(el, "Expanding the division costs ", App.UI.DOM.makeElement("span", cashFormat(depExpandCost), ["cash", "dec"]), " Downsizing recoups 80% of the investment; slaves will be sold at the going rate."); + addDiv(frag, "Expanding the division costs ", App.UI.DOM.makeElement("span", `${cashFormat(depExpandCost)}.`, ["cash", "dec"]), " Downsizing recoups 80% of the investment; slaves will be sold at the going rate."); let buyDevArray = [ {'name': 'Expand Division', 'count': 1}, @@ -267,9 +268,9 @@ App.Corporate.manage = function() { })); } - el.append(App.UI.DOM.generateLinksStrip(links)); + frag.append(App.UI.DOM.generateLinksStrip(links)); - App.UI.DOM.appendNewElement("h3", el, "Rules"); + App.UI.DOM.appendNewElement("h3", frag, "Rules"); const options = new App.UI.OptionsGroup().customRefresh(refresh); for (const nextDiv of division.relatedDivisions.to @@ -312,11 +313,11 @@ App.Corporate.manage = function() { refresh(); }).off(); } - el.append(options.render()); + frag.append(options.render()); if (App.Corporate.numDivisions > 1) { // Cannot dissolve the last division - addDiv(el, + addDiv(frag, App.UI.DOM.link("Dissolve Division", () => { if (Dialog.isOpen()) { Dialog.close(); @@ -336,7 +337,9 @@ App.Corporate.manage = function() { }) ); } + tabBar.addTab(division.name, division.name.replace(/\s/g, ''), frag); } + el.append(tabBar.render()); return el; }