diff --git a/src/Corporation/ui/CorporationUIEventHandler.js b/src/Corporation/ui/CorporationUIEventHandler.js index a3b6e11d8..2a7db33aa 100644 --- a/src/Corporation/ui/CorporationUIEventHandler.js +++ b/src/Corporation/ui/CorporationUIEventHandler.js @@ -1474,171 +1474,6 @@ export class CorporationEventHandler { input.focus(); } - // Creates a popup that lets the player throw an office party - createThrowOfficePartyPopup(office) { - const popupId = "cmpy-mgmt-throw-office-party-popup"; - const txt = createElement("p", { - innerText:"Enter the amount of money you would like to spend PER EMPLOYEE " + - "on this office party", - }); - const totalCostTxt = createElement("p", { - innerText:"Throwing this party will cost a total of $0", - }); - let confirmBtn; - const input = createElement("input", { - type: "number", margin: "5px", placeholder: "$ / employee", - inputListener: () => { - if (isNaN(input.value) || input.value < 0) { - totalCostTxt.innerText = "Invalid value entered!" - } else { - const totalCost = input.value * office.employees.length; - totalCostTxt.innerText = "Throwing this party will cost a total of " + numeralWrapper.format(totalCost, '$0.000a'); - } - }, - onkeyup:(e)=>{ - e.preventDefault(); - if (e.keyCode === KEY.ENTER) {confirmBtn.click();} - }, - }); - confirmBtn = createElement("button", { - class: "std-button", - innerText: "Throw Party", - clickListener:()=>{ - if (isNaN(input.value) || input.value < 0) { - dialogBoxCreate("Invalid value entered"); - } else { - var totalCost = input.value * office.employees.length; - if (this.corp.funds.lt(totalCost)) { - dialogBoxCreate("You don't have enough company funds to throw this.corp party!"); - } else { - this.corp.funds = this.corp.funds.minus(totalCost); - var mult; - for (let fooit = 0; fooit < office.employees.length; ++fooit) { - mult = office.employees[fooit].throwParty(input.value); - } - dialogBoxCreate("You threw a party for the office! The morale and happiness " + - "of each employee increased by " + numeralWrapper.formatPercentage((mult-1))); - removeElementById(popupId); - } - } - return false; - }, - }); - const cancelBtn = createPopupCloseButton(popupId, { class: "std-button", innerText: "Cancel" }); - - createPopup(popupId, [txt, totalCostTxt, input, confirmBtn, cancelBtn]); - input.focus(); - } - - // Creates a popup that lets the player upgrade the current OfficeSpace's size - createUpgradeOfficeSizePopup(office) { - const popupId = "cmpy-mgmt-upgrade-office-size-popup"; - const initialPriceMult = Math.round(office.size / OfficeInitialSize); - const costMultiplier = 1.09; - const upgradeCost = OfficeInitialCost * Math.pow(costMultiplier, initialPriceMult); - - // Calculate cost to upgrade size by 15 employees - let mult = 0; - for (let i = 0; i < 5; ++i) { - mult += (Math.pow(costMultiplier, initialPriceMult + i)); - } - const upgradeCost15 = OfficeInitialCost * mult; - - //Calculate max upgrade size and cost - let maxMult = (this.corp.funds.dividedBy(OfficeInitialCost)).toNumber(); - let maxNum = 1; - mult = Math.pow(costMultiplier, initialPriceMult); - while(maxNum < 50) { //Hard cap of 50x (extra 150 employees) - if (mult >= maxMult) {break;} - let multIncrease = Math.pow(costMultiplier, initialPriceMult + maxNum); - if (mult + multIncrease > maxMult) { - break; - } else { - mult += multIncrease; - } - ++maxNum; - } - const upgradeCostMax = OfficeInitialCost * mult; - - const text = createElement("p", { - innerText:"Increase the size of your office space to fit additional employees!", - }); - const text2 = createElement("p", { innerText: "Upgrade size: " }); - - const confirmBtn = createElement("button", { - class: this.corp.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button", - display:"inline-block", margin:"4px", innerText:"by 3", - tooltip:numeralWrapper.format(upgradeCost, "$0.000a"), - clickListener:()=>{ - if (this.corp.funds.lt(upgradeCost)) { - dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); - } else { - office.size += OfficeInitialSize; - this.corp.funds = this.corp.funds.minus(upgradeCost); - dialogBoxCreate("Office space increased! It can now hold " + office.size + " employees"); - this.rerender(); - } - removeElementById(popupId); - return false; - }, - }); - const confirmBtn15 = createElement("button", { - class: this.corp.funds.lt(upgradeCost15) ? "a-link-button-inactive" : "a-link-button", - display:"inline-block", margin:"4px", innerText:"by 15", - tooltip:numeralWrapper.format(upgradeCost15, "$0.000a"), - clickListener:()=>{ - if (this.corp.funds.lt(upgradeCost15)) { - dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); - } else { - office.size += (OfficeInitialSize * 5); - this.corp.funds = this.corp.funds.minus(upgradeCost15); - dialogBoxCreate("Office space increased! It can now hold " + office.size + " employees"); - this.rerender(); - } - removeElementById(popupId); - return false; - }, - }); - const confirmBtnMax = createElement("button", { - class:this.corp.funds.lt(upgradeCostMax) ? "a-link-button-inactive" : "a-link-button", - display:"inline-block", margin:"4px", innerText:"by MAX (" + maxNum*OfficeInitialSize + ")", - tooltip:numeralWrapper.format(upgradeCostMax, "$0.000a"), - clickListener:()=>{ - if (this.corp.funds.lt(upgradeCostMax)) { - dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); - } else { - office.size += (OfficeInitialSize * maxNum); - this.corp.funds = this.corp.funds.minus(upgradeCostMax); - dialogBoxCreate("Office space increased! It can now hold " + office.size + " employees"); - this.rerender(); - } - removeElementById(popupId); - return false; - }, - }); - const cancelBtn = createPopupCloseButton(popupId, { innerText: "Cancel" }); - cancelBtn.style.margin = "4px"; - - createPopup(popupId, [text, text2, confirmBtn, confirmBtn15, confirmBtnMax, cancelBtn]); - } - - // Purchases a new Warehouse - purchaseWarehouse(division, city) { - const corp = this.corp; - if (corp.funds.lt(WarehouseInitialCost)) { - dialogBoxCreate("You do not have enough funds to do this!"); - } else { - division.warehouses[city] = new Warehouse({ - corp: corp, - industry: division, - loc: city, - size: WarehouseInitialSize, - }); - corp.funds = corp.funds.minus(WarehouseInitialCost); - this.rerender(); - } - } - rerender() { this.corp.rerender(); } diff --git a/src/Corporation/ui/IndustryOffice.tsx b/src/Corporation/ui/IndustryOffice.tsx index 93758e70f..c2b2438b8 100644 --- a/src/Corporation/ui/IndustryOffice.tsx +++ b/src/Corporation/ui/IndustryOffice.tsx @@ -9,6 +9,9 @@ import { EmployeePositions } from "../EmployeePositions"; import { numeralWrapper } from "../../ui/numeralFormat"; import { getSelectText } from "../../../utils/uiHelpers/getSelectData"; +import { createPopup } from "../../ui/React/createPopup"; +import { UpgradeOfficeSizePopup } from "./UpgradeOfficeSizePopup"; +import { ThrowPartyPopup } from "./ThrowPartyPopup"; interface IProps { routing: any; @@ -565,17 +568,29 @@ export function IndustryOffice(props: IProps): React.ReactElement { } else { autohireEmployeeButtonClass += " std-button"; } - const autohireEmployeeButtonOnClick = () => { - if (office.atCapacity()) { return; } + function autohireEmployeeButtonOnClick(): void { + if (office.atCapacity()) return; office.hireRandomEmployee(); props.corp.rerender(); } - // Upgrade Office Size Button - const upgradeOfficeSizeOnClick = props.eventHandler.createUpgradeOfficeSizePopup.bind(props.eventHandler, office); + function openUpgradeOfficeSizePopup(): void { + const popupId = "cmpy-mgmt-upgrade-office-size-popup"; + createPopup(popupId, UpgradeOfficeSizePopup, { + office: office, + corp: props.corp, + popupId: popupId, + }); + } - // Throw Office Party - const throwOfficePartyOnClick = props.eventHandler.createThrowOfficePartyPopup.bind(props.eventHandler, office); + function openThrowPartyPopup(): void { + const popupId = "cmpy-mgmt-throw-office-party-popup"; + createPopup(popupId, ThrowPartyPopup, { + office: office, + corp: props.corp, + popupId: popupId, + }); + } return (