mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 12:45:45 +01:00
Fixed re-balanced Corporation issues. Converted several popups in the Corporation mechanic to support Enter/Esc hotkeys
This commit is contained in:
parent
5dcb1a02b2
commit
a9bd883395
1142
dist/engine.bundle.js
vendored
1142
dist/engine.bundle.js
vendored
File diff suppressed because it is too large
Load Diff
1107
dist/vendor.bundle.js
vendored
1107
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -521,6 +521,10 @@ export let CONSTANTS: IMap<any> = {
|
||||
Agriculture industry
|
||||
|
||||
* Stock Market, Travel, and Corporation main menu links are now properly styled
|
||||
* Many pop-up/dialog boxes now support the 'Enter' and 'Esc' hotkeys. If you
|
||||
find a pop-up/dialog box that doesnt support this, let me know specifically which one
|
||||
('Enter' for the default option, 'Esc' for cancelling and closing the pop-up box)
|
||||
* Added "brace_style = preserve_inline" configuration to Script Editor Beautifier
|
||||
`
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import { Reviver,
|
||||
import { appendLineBreaks } from "../../utils/uiHelpers/appendLineBreaks";
|
||||
import { createElement } from "../../utils/uiHelpers/createElement";
|
||||
import { createPopup } from "../../utils/uiHelpers/createPopup";
|
||||
import { createPopupCloseButton } from "../../utils/uiHelpers/createPopupCloseButton";
|
||||
import { formatNumber, generateRandomString } from "../../utils/StringHelperFunctions";
|
||||
import { getRandomInt } from "../../utils/helpers/getRandomInt";
|
||||
import { isString } from "../../utils/helpers/isString";
|
||||
@ -1286,13 +1287,8 @@ Industry.prototype.createResearchBox = function() {
|
||||
}));
|
||||
|
||||
// Close button
|
||||
boxContent.appendChild(createElement("button", {
|
||||
boxContent.appendChild(createPopupCloseButton(researchTreeBox, {
|
||||
class: "std-button",
|
||||
clickListener: () => {
|
||||
if (researchTreeBox != null) {
|
||||
removeElement(researchTreeBox);
|
||||
}
|
||||
},
|
||||
display: "block",
|
||||
innerText: "Close",
|
||||
}));
|
||||
@ -2098,14 +2094,17 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
});
|
||||
var confirmBtn;
|
||||
var input = createElement("input", {
|
||||
type:"number", value:mat.buy ? mat.buy : null, placeholder: "Purchase amount",
|
||||
margin: "5px",
|
||||
placeholder: "Purchase amount",
|
||||
type: "number",
|
||||
value: mat.buy ? mat.buy : null,
|
||||
onkeyup:(e)=>{
|
||||
e.preventDefault();
|
||||
if (e.keyCode === 13) {confirmBtn.click();}
|
||||
}
|
||||
});
|
||||
confirmBtn = createElement("a", {
|
||||
innerText:"Confirm", class:"a-link-button",
|
||||
confirmBtn = createElement("button", {
|
||||
innerText:"Confirm", class:"std-button",
|
||||
clickListener:()=>{
|
||||
if (isNaN(input.value)) {
|
||||
dialogBoxCreate("Invalid amount");
|
||||
@ -2118,8 +2117,8 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
}
|
||||
}
|
||||
});
|
||||
var clearButton = createElement("a", {
|
||||
innerText:"Clear Purchase", class:"a-link-button",
|
||||
var clearButton = createElement("button", {
|
||||
innerText:"Clear Purchase", class:"std-button",
|
||||
clickListener:()=>{
|
||||
mat.buy = 0;
|
||||
removeElementById(purchasePopupId);
|
||||
@ -2127,12 +2126,11 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var cancelBtn = createElement("a", {
|
||||
innerText:"Cancel", class:"a-link-button",
|
||||
clickListener:()=>{
|
||||
removeElementById(purchasePopupId);
|
||||
}
|
||||
const cancelBtn = createPopupCloseButton(purchasePopupId, {
|
||||
class: "std-button",
|
||||
innerText: "Cancel",
|
||||
});
|
||||
|
||||
createPopup(purchasePopupId, [txt, input, confirmBtn, clearButton, cancelBtn]);
|
||||
input.focus();
|
||||
}
|
||||
@ -2307,7 +2305,7 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
var br = createElement("br", {});
|
||||
var confirmBtn;
|
||||
var inputQty = createElement("input", {
|
||||
type:"text", marginTop:"4px",
|
||||
type: "text", marginTop: "4px",
|
||||
value: mat.sllman[1] ? mat.sllman[1] : null, placeholder: "Sell amount",
|
||||
onkeyup:(e)=>{
|
||||
e.preventDefault();
|
||||
@ -2315,16 +2313,17 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
}
|
||||
});
|
||||
var inputPx = createElement("input", {
|
||||
type:"text", marginTop:"4px",
|
||||
type: "text", marginTop: "4px",
|
||||
value: mat.sCost ? mat.sCost : null, placeholder: "Sell price",
|
||||
onkeyup:(e)=>{
|
||||
onkeyup: (e) => {
|
||||
e.preventDefault();
|
||||
if (e.keyCode === 13) {confirmBtn.click();}
|
||||
}
|
||||
});
|
||||
confirmBtn = createElement("a", {
|
||||
innerText:"Confirm", class:"a-link-button", margin:"6px",
|
||||
clickListener:()=>{
|
||||
confirmBtn = createElement("button", {
|
||||
class: "std-button",
|
||||
innerText: "Confirm",
|
||||
clickListener: () => {
|
||||
//Parse price
|
||||
var cost = inputPx.value.replace(/\s+/g, '');
|
||||
cost = cost.replace(/[^-()\d/*+.MP]/g, ''); //Sanitize cost
|
||||
@ -2387,12 +2386,11 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var cancelBtn = createElement("a", {
|
||||
innerText:"Cancel", class:"a-link-button", margin: "6px",
|
||||
clickListener:()=>{
|
||||
removeElementById(sellPopupid);
|
||||
}
|
||||
const cancelBtn = createPopupCloseButton(sellPopupid, {
|
||||
class: "std-button",
|
||||
innerText: "Cancel",
|
||||
});
|
||||
|
||||
createPopup(sellPopupid, [txt, br, inputQty, inputPx, confirmBtn, cancelBtn]);
|
||||
inputQty.focus();
|
||||
}
|
||||
@ -2779,9 +2777,14 @@ Corporation.prototype.storeCycles = function(numCycles=1) {
|
||||
Corporation.prototype.process = function() {
|
||||
var corp = this;
|
||||
if (this.storedCycles >= CyclesPerIndustryStateCycle) {
|
||||
var state = this.getState(), marketCycles=1;
|
||||
const state = this.getState();
|
||||
const marketCycles = 1;
|
||||
this.storedCycles -= (marketCycles * CyclesPerIndustryStateCycle);
|
||||
|
||||
this.divisions.forEach(function(ind) {
|
||||
ind.process(marketCycles, state, corp);
|
||||
});
|
||||
|
||||
//At the start of a new cycle, calculate profits from previous cycle
|
||||
if (state === "START") {
|
||||
this.revenue = new Decimal(0);
|
||||
@ -2820,11 +2823,6 @@ Corporation.prototype.process = function() {
|
||||
this.updateSharePrice();
|
||||
}
|
||||
|
||||
this.divisions.forEach(function(ind) {
|
||||
ind.process(marketCycles, state, corp);
|
||||
});
|
||||
|
||||
|
||||
this.state.nextState();
|
||||
|
||||
if (routing.isOn(Page.Corporation)) {this.updateUIContent();}
|
||||
@ -3208,14 +3206,8 @@ Corporation.prototype.updateUIHeaderTabs = function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var noBtn = createElement("span", {
|
||||
class:"popup-box-button",
|
||||
innerText:"Cancel",
|
||||
clickListener: function() {
|
||||
removeElementById("cmpy-mgmt-expand-industry-popup");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const noBtn = createPopupCloseButton(container, {innerText: "Cancel"});
|
||||
|
||||
//Make an object to keep track of what industries you're already in
|
||||
var ownedIndustries = {}
|
||||
@ -3261,6 +3253,7 @@ Corporation.prototype.updateUIHeaderTabs = function() {
|
||||
container.appendChild(content);
|
||||
document.getElementById("entire-game-container").appendChild(container);
|
||||
container.style.display = "flex";
|
||||
nameInput.focus();
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
@ -3804,9 +3797,6 @@ Corporation.prototype.updateCorporationOverviewContent = function() {
|
||||
console.log("WARNING: Could not find overview text elemtn in updateCorporationOverviewContent()");
|
||||
return;
|
||||
}
|
||||
var totalFunds = this.funds,
|
||||
totalRevenue = new Decimal(0),
|
||||
totalExpenses = new Decimal(0);
|
||||
|
||||
// Formatted text for profit
|
||||
var profit = this.revenue.minus(this.expenses).toNumber(),
|
||||
@ -3827,7 +3817,7 @@ Corporation.prototype.updateCorporationOverviewContent = function() {
|
||||
`Your earnings (Post-Tax): ${numeralWrapper.format(playerEarnings * (this.dividendTaxPercentage / 100), "$0.000a")} / s<br>`;
|
||||
}
|
||||
|
||||
var txt = "Total Funds: " + numeralWrapper.format(totalFunds.toNumber(), '$0.000a') + "<br>" +
|
||||
var txt = "Total Funds: " + numeralWrapper.format(this.funds.toNumber(), '$0.000a') + "<br>" +
|
||||
"Total Revenue: " + numeralWrapper.format(this.revenue.toNumber(), "$0.000a") + " / s<br>" +
|
||||
"Total Expenses: " + numeralWrapper.format(this.expenses.toNumber(), "$0.000a") + "/ s<br>" +
|
||||
"Total Profits: " + profitStr + " / s<br>" +
|
||||
@ -3918,13 +3908,11 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var cancelBtn = createElement("a", {
|
||||
innerText:"Cancel", class:"a-link-button", display:"inline-block", margin:"3px",
|
||||
clickListener:()=>{
|
||||
removeElementById(popupId);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
const cancelBtn = createPopupCloseButton(popupId, {
|
||||
class: "std-button",
|
||||
innerText: "Cancel",
|
||||
});
|
||||
|
||||
createPopup(popupId, [text, citySelector, confirmBtn, cancelBtn]);
|
||||
return false;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export const CorporationUpgrades: IMap<any[]> = {
|
||||
"to consumers through their dreams. Each level of this upgrade provides a passive " +
|
||||
"increase in awareness of all of your companies (divisions) by 0.004 / market cycle," +
|
||||
"and in popularity by 0.001 / market cycle. A market cycle is approximately " +
|
||||
"20 seconds."],
|
||||
"15 seconds."],
|
||||
|
||||
//Makes advertising more effective
|
||||
"3": [3, 4e9, 1.12, 0.005,
|
||||
|
@ -272,7 +272,10 @@ $(document).keydown(function(e) {
|
||||
function beautifyScript() {
|
||||
var editor = ace.edit('javascript-editor');
|
||||
var code = editor.getValue();
|
||||
code = beautify(code, { indent_size: 4 })
|
||||
code = beautify(code, {
|
||||
indent_size: 4,
|
||||
brace_style: "preserve-inline",
|
||||
});
|
||||
editor.setValue(code);
|
||||
}
|
||||
|
||||
|
@ -2015,6 +2015,7 @@ let Terminal = {
|
||||
yesBtn.innerHTML = "Travel to BitNode Nexus";
|
||||
noBtn.innerHTML = "Cancel";
|
||||
yesBtn.addEventListener("click", function() {
|
||||
console.log("yesBtn event listener");
|
||||
hackWorldDaemon(Player.bitNodeN, true);
|
||||
return yesNoBoxClose();
|
||||
});
|
||||
|
@ -11,10 +11,21 @@ import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
||||
export let yesNoBoxOpen: boolean = false;
|
||||
|
||||
const yesNoBoxContainer: HTMLElement | null = document.getElementById("yes-no-box-container");
|
||||
const yesNoBoxYesButton: HTMLElement | null = document.getElementById("yes-no-box-yes");
|
||||
const yesNoBoxNoButton: HTMLElement | null = document.getElementById("yes-no-box-no");
|
||||
const yesNoBoxTextElement: HTMLElement | null = document.getElementById("yes-no-box-text");
|
||||
|
||||
export function yesNoBoxHotkeyHandler(e: KeyboardEvent) {
|
||||
if (e.keyCode === 27) {
|
||||
yesNoBoxClose();
|
||||
} else if (e.keyCode === 13) {
|
||||
const yesBtn: HTMLElement | null = document.getElementById("yes-no-box-yes");
|
||||
if (yesBtn) {
|
||||
yesBtn.click();
|
||||
} else {
|
||||
console.error(`Could not find YesNoBox Yes button DOM element`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function yesNoBoxClose(): boolean {
|
||||
if (yesNoBoxContainer) {
|
||||
yesNoBoxContainer.style.display = "none";
|
||||
@ -29,18 +40,6 @@ export function yesNoBoxClose(): boolean {
|
||||
return false; //So that 'return yesNoBoxClose()' is return false in event listeners
|
||||
}
|
||||
|
||||
export function yesNoBoxHotkeyHandler(e: KeyboardEvent) {
|
||||
if (e.keyCode === 27) {
|
||||
yesNoBoxClose();
|
||||
} else if (e.keyCode === 13) {
|
||||
if (yesNoBoxNoButton) {
|
||||
yesNoBoxNoButton.click();
|
||||
} else {
|
||||
console.error(`Could not find YesNoBox No button DOM element`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function yesNoBoxGetYesButton() {
|
||||
return clearEventListeners("yes-no-box-yes");
|
||||
}
|
||||
@ -55,6 +54,8 @@ export function yesNoBoxCreate(txt: string) {
|
||||
|
||||
if (yesNoBoxTextElement) {
|
||||
yesNoBoxTextElement.innerHTML = txt;
|
||||
} else {
|
||||
console.error(`Text element not found for YesNoBox`);
|
||||
}
|
||||
|
||||
if (yesNoBoxContainer) {
|
||||
@ -73,11 +74,22 @@ export function yesNoBoxCreate(txt: string) {
|
||||
* Yes-No pop up box with text input field
|
||||
*/
|
||||
const yesNoTextInputBoxContainer: HTMLElement | null = document.getElementById("yes-no-text-input-box-container");
|
||||
const yesNoTextInputBoxYesButton: HTMLElement | null = document.getElementById("yes-no-text-input-box-yes");
|
||||
const yesNoTextInputBoxNoButton: HTMLElement | null = document.getElementById("yes-no-text-input-box-no");
|
||||
const yesNoTextInputBoxInput: HTMLInputElement | null = document.getElementById("yes-no-text-input-box-input") as HTMLInputElement;
|
||||
const yesNoTextInputBoxTextElement: HTMLElement | null = document.getElementById("yes-no-text-input-box-text");
|
||||
|
||||
export function yesNoTxtInpBoxHotkeyHandler(e: KeyboardEvent) {
|
||||
if (e.keyCode === 27) {
|
||||
yesNoTxtInpBoxClose();
|
||||
} else if (e.keyCode === 13) {
|
||||
const yesBtn: HTMLElement | null = document.getElementById("yes-no-text-input-box-yes");
|
||||
if (yesBtn) {
|
||||
yesBtn.click();
|
||||
} else {
|
||||
console.error(`Could not find YesNoTxtInputBox Yes button DOM element`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function yesNoTxtInpBoxClose(): boolean {
|
||||
if (yesNoTextInputBoxContainer != null) {
|
||||
yesNoTextInputBoxContainer.style.display = "none";
|
||||
@ -87,6 +99,10 @@ export function yesNoTxtInpBoxClose(): boolean {
|
||||
}
|
||||
yesNoBoxOpen = false;
|
||||
yesNoTextInputBoxInput!.value = "";
|
||||
|
||||
// Remove hotkey handler
|
||||
document.removeEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -121,5 +137,8 @@ export function yesNoTxtInpBoxCreate(txt: string) {
|
||||
console.error("Container not found for YesNoTextInputBox");
|
||||
}
|
||||
|
||||
// Add event listener for Esc and Enter hotkeys
|
||||
document.addEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
|
||||
|
||||
yesNoTextInputBoxInput!.focus();
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
/* Creates a Close/Cancel button that is used for removing popups */
|
||||
|
||||
import { createElement } from "./createElement";
|
||||
import { getElementById } from "./getElementById";
|
||||
import { removeElement } from "./removeElement";
|
||||
|
||||
interface ICreatePopupCloseButtonOptions {
|
||||
class?: string;
|
||||
display?: string;
|
||||
innerText?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export function createPopupCloseButton(popup: Element | string, options: ICreatePopupCloseButtonOptions) {
|
||||
let button: HTMLButtonElement;
|
||||
|
||||
|
||||
// TODO event listener works with escape. Add and remove event listener
|
||||
// from document
|
||||
function closePopupWithEscFn(e: any): void {
|
||||
@ -21,21 +22,25 @@ export function createPopupCloseButton(popup: Element | string, options: ICreate
|
||||
}
|
||||
|
||||
button = createElement("button", {
|
||||
class: "std-button",
|
||||
class: options.class ? options.class : "popup-box-button",
|
||||
display: options.display ? options.display : "inline-block",
|
||||
innerText: options.innerText == null ? "Cancel" : options.innerText,
|
||||
clickListener: () => {
|
||||
if (popup instanceof Element) {
|
||||
removeElement(popup);
|
||||
} else {
|
||||
try {
|
||||
const popupEl = getElementById(popup);
|
||||
removeElement(popupEl);
|
||||
const popupEl = document.getElementById(popup);
|
||||
if (popupEl instanceof Element) {
|
||||
removeElement(popupEl);
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(`createPopupCloseButton() threw: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
document.removeEventListener("keydown", closePopupWithEscFn);
|
||||
return false;
|
||||
},
|
||||
}) as HTMLButtonElement;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user