diff --git a/src/BitNode/ui/BitverseRoot.tsx b/src/BitNode/ui/BitverseRoot.tsx index 9867348fb..b3abfe90c 100644 --- a/src/BitNode/ui/BitverseRoot.tsx +++ b/src/BitNode/ui/BitverseRoot.tsx @@ -51,7 +51,6 @@ interface IPortalProps { function BitNodePortal(props: IPortalProps): React.ReactElement { const [portalOpen, setPortalOpen] = useState(false); const classes = useStyles(); - const router = use.Router(); const bitNode = BitNodes[`BitNode${props.n}`]; if (bitNode == null) { return <>O; @@ -63,9 +62,12 @@ function BitNodePortal(props: IPortalProps): React.ReactElement { cssClass = classes.level2; } else if (props.level === 1) { cssClass = classes.level1; - } else { + } else if (props.level === 3) { cssClass = classes.level3; } + if (props.level === 2) { + cssClass = classes.level2; + } return ( <> diff --git a/src/Crime/CrimeHelpers.ts b/src/Crime/CrimeHelpers.ts index e42d141c5..9eb60e5d1 100644 --- a/src/Crime/CrimeHelpers.ts +++ b/src/Crime/CrimeHelpers.ts @@ -17,7 +17,7 @@ export function determineCrimeSuccess(p: IPlayer, type: string): boolean { } if (!found) { - dialogBoxCreate(`ERR: Unrecognized crime type: ${type} This is probably a bug please contact the developer`, false); + dialogBoxCreate(`ERR: Unrecognized crime type: ${type} This is probably a bug please contact the developer`); return false; } diff --git a/src/Hacknet/HacknetNode.ts b/src/Hacknet/HacknetNode.ts index 73fcee017..4982b606b 100644 --- a/src/Hacknet/HacknetNode.ts +++ b/src/Hacknet/HacknetNode.ts @@ -107,7 +107,7 @@ export class HacknetNode implements IHacknetNode { this.moneyGainRatePerSecond = calculateMoneyGainRate(this.level, this.ram, this.cores, prodMult); if (isNaN(this.moneyGainRatePerSecond)) { this.moneyGainRatePerSecond = 0; - dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer", false); + dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer"); } } diff --git a/src/Locations/ui/HospitalLocation.tsx b/src/Locations/ui/HospitalLocation.tsx index 171e90546..99c35c3bc 100644 --- a/src/Locations/ui/HospitalLocation.tsx +++ b/src/Locations/ui/HospitalLocation.tsx @@ -9,7 +9,6 @@ import Button from "@mui/material/Button"; import { IPlayer } from "../../PersonObjects/IPlayer"; import { getHospitalizationCost } from "../../Hospital/Hospital"; -import { AutoupdatingStdButton } from "../../ui/React/AutoupdatingStdButton"; import { Money } from "../../ui/React/Money"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; diff --git a/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx b/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx index 697eaf2e5..6a301a771 100644 --- a/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx +++ b/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx @@ -58,7 +58,7 @@ export function CovenantPurchasesRoot(props: IProps): React.ReactElement { player.sleeves.push(new Sleeve(player)); rerender(); } else { - dialogBoxCreate(`You cannot afford to purchase a Duplicate Sleeve`, false); + dialogBoxCreate(`You cannot afford to purchase a Duplicate Sleeve`); } } diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts index 1861c09ae..3be461937 100644 --- a/src/Server/ServerPurchases.ts +++ b/src/Server/ServerPurchases.ts @@ -46,7 +46,7 @@ export function getPurchaseServerMaxRam(): number { export function purchaseServer(hostname: string, ram: number, cost: number, p: IPlayer): void { //Check if player has enough money if (!p.canAfford(cost)) { - dialogBoxCreate("You don't have enough money to purchase this server!", false); + dialogBoxCreate("You don't have enough money to purchase this server!"); return; } diff --git a/src/StockMarket/ui/StockTickerPositionText.tsx b/src/StockMarket/ui/StockTickerPositionText.tsx index 58a52b334..40ed61e8f 100644 --- a/src/StockMarket/ui/StockTickerPositionText.tsx +++ b/src/StockMarket/ui/StockTickerPositionText.tsx @@ -104,11 +104,11 @@ export function StockTickerPositionText(props: IProps): React.ReactElement { return ( <> Max Shares: {numeralWrapper.formatShares(stock.maxShares)} - + Ask Price:
- + Bid Price: diff --git a/src/TextFile.ts b/src/TextFile.ts index da165cc56..ea1d03bef 100644 --- a/src/TextFile.ts +++ b/src/TextFile.ts @@ -65,7 +65,7 @@ export class TextFile { * Shows the content to the user via the game's dialog box. */ show(): void { - dialogBoxCreate(`${this.fn}

${this.text}`, true); + dialogBoxCreate(`${this.fn}

${this.text}`); } /** diff --git a/src/ui/React/AccordionButton.tsx b/src/ui/React/AccordionButton.tsx deleted file mode 100644 index 5f9699d92..000000000 --- a/src/ui/React/AccordionButton.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Basic stateless button that uses the 'accordion-button' css class. - * This class has a black background so that it does not clash with the default - * accordion coloring - */ -import * as React from "react"; - -interface IProps { - addClasses?: string; - disabled?: boolean; - id?: string; - onClick?: (e: React.MouseEvent) => any; - style?: any; - text: string; - tooltip?: string; -} - -type IInnerHTMLMarkup = { - __html: string; -}; - -export function AccordionButton(props: IProps): React.ReactElement { - const hasTooltip = props.tooltip != null && props.tooltip !== ""; - - // TODO Add a disabled class for accordion buttons? - let className = "accordion-button"; - if (hasTooltip) { - className += " tooltip"; - } - - if (typeof props.addClasses === "string") { - className += ` ${props.addClasses}`; - } - - // Tooltip will be set using inner HTML - const tooltipMarkup: IInnerHTMLMarkup = { - __html: props.tooltip ? props.tooltip : "", - }; - - return ( - - ); -} diff --git a/src/ui/React/AlertManager.tsx b/src/ui/React/AlertManager.tsx index a75a9c15b..dff242c2a 100644 --- a/src/ui/React/AlertManager.tsx +++ b/src/ui/React/AlertManager.tsx @@ -32,9 +32,8 @@ export function AlertManager(): React.ReactElement { ); function close(): void { - console.log("close"); setAlerts((old) => { - return old.slice(0, -1); + return old.slice(1, 1e99); }); } diff --git a/src/ui/React/AutoupdatingParagraph.tsx b/src/ui/React/AutoupdatingParagraph.tsx deleted file mode 100644 index 938e348ae..000000000 --- a/src/ui/React/AutoupdatingParagraph.tsx +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Basic paragraph (p Element) that automatically re-renders itself every X seconds - * - * NOT recommended for usage - only if you really have to - */ -import * as React from "react"; - -interface IProps { - intervalTime?: number; - style?: any; - getContent: () => JSX.Element; - getTooltip?: () => JSX.Element; -} - -interface IState { - i: number; -} - -export class AutoupdatingParagraph extends React.Component { - /** - * Timer ID for auto-updating implementation (returned value from setInterval()) - */ - interval = 0; - - constructor(props: IProps) { - super(props); - this.state = { - i: 0, - }; - } - - componentDidMount(): void { - const time = this.props.intervalTime ? this.props.intervalTime : 1000; - this.interval = window.setInterval(() => this.tick(), time); - } - - componentWillUnmount(): void { - clearInterval(this.interval); - } - - tick(): void { - this.setState((prevState) => ({ - i: prevState.i + 1, - })); - } - - hasTooltip(): boolean { - if (this.props.getTooltip != null) { - return !!this.props.getTooltip(); - } - return true; - } - - tooltip(): JSX.Element { - if (!this.props.getTooltip) return <>; - return this.props.getTooltip(); - } - - render(): React.ReactNode { - return ( -
-

{this.props.getContent()}

- {this.hasTooltip() && {this.tooltip()}} -
- ); - } -} diff --git a/src/ui/React/AutoupdatingStdButton.tsx b/src/ui/React/AutoupdatingStdButton.tsx deleted file mode 100644 index 1382ee62b..000000000 --- a/src/ui/React/AutoupdatingStdButton.tsx +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Basic stateless button that automatically re-renders itself every X seconds - * Uses the 'std-button' css class - * - * NOT recommended for usage - only if you really have to - */ -import * as React from "react"; - -interface IProps { - label?: string; - disabled?: boolean; - intervalTime?: number; - onClick?: (e: React.MouseEvent) => any; - style?: any; - text: string | JSX.Element; - tooltip?: string; -} - -interface IState { - i: number; -} - -type IInnerHTMLMarkup = { - __html: string; -}; - -export class AutoupdatingStdButton extends React.Component { - /** - * Timer ID for auto-updating implementation (returned value from setInterval()) - */ - interval = 0; - - constructor(props: IProps) { - super(props); - this.state = { - i: 0, - }; - } - - componentDidMount(): void { - const time = this.props.intervalTime ? this.props.intervalTime : 1000; - this.interval = window.setInterval(() => this.tick(), time); - } - - componentWillUnmount(): void { - clearInterval(this.interval); - } - - tick(): void { - this.setState((prevState) => ({ - i: prevState.i + 1, - })); - } - - render(): React.ReactNode { - const hasTooltip = this.props.tooltip != null && this.props.tooltip !== ""; - - let className = this.props.disabled ? "std-button-disabled" : "std-button"; - if (hasTooltip) { - className += " tooltip"; - } - - // Tooltip will eb set using inner HTML - const tooltipMarkup: IInnerHTMLMarkup = { - __html: this.props.tooltip ? this.props.tooltip : "", - }; - - return ( - - ); - } -} diff --git a/src/ui/React/DialogBox.tsx b/src/ui/React/DialogBox.tsx index 1e72842d1..0011a68fe 100644 --- a/src/ui/React/DialogBox.tsx +++ b/src/ui/React/DialogBox.tsx @@ -1,43 +1,12 @@ -import { createPopup } from "./createPopup"; -import { getRandomInt } from "../../utils/helpers/getRandomInt"; +import { AlertEvents } from "./AlertManager"; import React from "react"; +import { jsx } from "@emotion/react"; -interface IProps { - content: JSX.Element; -} - -function MessagePopup(props: IProps): React.ReactElement { - return <>{props.content}; -} - -export function dialogBoxCreate(txt: string | JSX.Element, preformatted = false): void { - const popupId = - `popup-` + - Array.from(Array(16)) - .map(() => `${getRandomInt(0, 9)}`) - .join(""); - if (typeof txt === "string") { - if (preformatted) { - // For text files as they are often computed data that - // shouldn't be wrapped and should retain tabstops. - createPopup(popupId, MessagePopup, { - content:
,
-      });
-    } else {
-      createPopup(popupId, MessagePopup, {
-        content: (
-          

"), - }} - /> - ), - }); - } +export function dialogBoxCreate(txt: string | JSX.Element): void { + if (typeof txt !== "string") { + AlertEvents.emit(txt); } else { - createPopup(popupId, MessagePopup, { - content: txt, - }); + AlertEvents.emit(

);
   }
 }
diff --git a/src/ui/React/ParagraphWithTooltip.tsx b/src/ui/React/ParagraphWithTooltip.tsx
deleted file mode 100644
index 0248e1f01..000000000
--- a/src/ui/React/ParagraphWithTooltip.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Text (p Element) with Tooltip
- */
-import * as React from "react";
-
-export interface IParagraphWithTooltipProps {
-  style?: any;
-  content: JSX.Element;
-  tooltip: string | React.ReactElement | JSX.Element;
-}
-
-export class ParagraphWithTooltip extends React.Component {
-  render(): React.ReactNode {
-    return (
-      
-

{this.props.content}

- {this.props.tooltip} -
- ); - } -} diff --git a/src/ui/React/PopupButton.tsx b/src/ui/React/PopupButton.tsx deleted file mode 100644 index 0782d025c..000000000 --- a/src/ui/React/PopupButton.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Basic button for popup dialog boxes - * It creates an event handler such that pressing Esc will perform the click handler. - * - * Should only be used in other React components, otherwise it may not be properly - * unmounted - */ -import * as React from "react"; -import * as ReactDOM from "react-dom"; - -import { KEY } from "../../utils/helpers/keyCodes"; -import { removeElement } from "../uiHelpers/removeElement"; - -export interface IPopupButtonProps { - class?: string; - popup: HTMLElement | string; - style?: any; - text: string; - onClose?: () => void; -} - -export class PopupButton extends React.Component { - constructor(props: IPopupButtonProps) { - super(props); - this.handleClick = this.handleClick.bind(this); - this.keyListener = this.keyListener.bind(this); - } - - componentDidMount(): void { - document.addEventListener("keydown", this.keyListener); - } - - componentWillUnmount(): void { - document.removeEventListener("keydown", this.keyListener); - } - - handleClick(): void { - if (this.props.onClose) this.props.onClose(); - //We might be able to remove this? - //Clickhandler from the props will override this anyhow. - let popup: HTMLElement | null; - if (typeof this.props.popup === "string") { - popup = document.getElementById(this.props.popup); - } else { - popup = this.props.popup; - } - // TODO Check if this is okay? This is essentially calling to unmount a parent component - if (popup instanceof HTMLElement) { - ReactDOM.unmountComponentAtNode(popup); // Removes everything inside the wrapper container - removeElement(popup); // Removes the wrapper container - } - } - - keyListener(e: KeyboardEvent): void { - //This doesn't really make sense, a button doesnt have to listen to escape IMO - //Too affraid to remove it since im not sure what it will break.. But yuck.. - if (e.keyCode === KEY.ESC) { - this.handleClick(); - } - } - - render(): React.ReactNode { - const className = this.props.class ? this.props.class : "std-button"; - - return ( - - ); - } -} diff --git a/src/ui/React/PopupCloseButton.tsx b/src/ui/React/PopupCloseButton.tsx deleted file mode 100644 index 26791c7de..000000000 --- a/src/ui/React/PopupCloseButton.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Close button for popup dialog boxes - * It creates an event handler such that pressing Esc will close the binded popup - * - * Should only be used in other React components, otherwise it may not be properly - * unmounted - */ -import * as React from "react"; -import * as ReactDOM from "react-dom"; - -import { removeElement } from "../uiHelpers/removeElement"; -import { IPopupButtonProps, PopupButton } from "./PopupButton"; - -export interface IPopupCloseButtonProps extends IPopupButtonProps { - class?: string; - popup: HTMLElement | string; - style?: any; - text: string; - onClose: () => void; -} - -export class PopupCloseButton extends PopupButton { - constructor(props: IPopupCloseButtonProps) { - super(props); - - this.closePopup = this.closePopup.bind(this); - } - - closePopup(): void { - if (this.props.onClose) this.props.onClose(); - let popup: HTMLElement | null; - if (typeof this.props.popup === "string") { - popup = document.getElementById(this.props.popup); - } else { - popup = this.props.popup; - } - - // TODO Check if this is okay? This is essentially calling to unmount a - // parent component - if (popup instanceof HTMLElement) { - // Removes everything inside the wrapper container - ReactDOM.unmountComponentAtNode(popup); - removeElement(popup); // Removes the wrapper container - } - } - - render(): React.ReactNode { - const className = this.props.class ? this.props.class : "std-button"; - - return ( - - ); - } -} diff --git a/src/ui/React/StdButtonPurchased.tsx b/src/ui/React/StdButtonPurchased.tsx deleted file mode 100644 index 851a218f2..000000000 --- a/src/ui/React/StdButtonPurchased.tsx +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Stateless button that represents something that has been purchased. - */ -import * as React from "react"; - -interface IStdButtonPurchasedProps { - onClick?: (e: React.MouseEvent) => any; - style?: any; - text: string; - tooltip?: string; -} - -type IInnerHTMLMarkup = { - __html: string; -}; - -export class StdButtonPurchased extends React.Component { - constructor(props: IStdButtonPurchasedProps) { - super(props); - this.hasTooltip = this.hasTooltip.bind(this); - this.tooltip = this.tooltip.bind(this); - } - - hasTooltip(): boolean { - return this.props.tooltip != null && this.props.tooltip !== ""; - } - - tooltip(): string { - if (!this.props.tooltip) return ""; - return this.props.tooltip; - } - - render(): React.ReactNode { - let className = "std-button-bought"; - if (this.hasTooltip()) { - className += " tooltip"; - } - - // Tooltip will be set using inner HTML - let tooltipMarkup: IInnerHTMLMarkup = { - __html: "", - }; - if (this.hasTooltip()) { - tooltipMarkup = { - __html: this.tooltip(), - }; - } - - return ( - - ); - } -} diff --git a/src/utils/helpers/exceptionAlert.ts b/src/utils/helpers/exceptionAlert.ts index 5ec74f019..251b38687 100644 --- a/src/utils/helpers/exceptionAlert.ts +++ b/src/utils/helpers/exceptionAlert.ts @@ -21,6 +21,5 @@ export function exceptionAlert(e: IError | string): void { "message as well as details about how to reproduce the bug.

" + "If you want to be safe, I suggest refreshing the game WITHOUT saving so that your " + "safe doesn't get corrupted", - false, ); }