mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 01:23:49 +01:00
fixed prompt
This commit is contained in:
parent
1fdb5c33c7
commit
3f5b412547
32
dist/vendor.bundle.js
vendored
32
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -103,6 +103,7 @@ import { Programs } from "./Programs/Programs";
|
||||
import { Script } from "./Script/Script";
|
||||
import { findRunningScript, findRunningScriptByPid } from "./Script/ScriptHelpers";
|
||||
import { isScriptFilename } from "./Script/isScriptFilename";
|
||||
import { PromptEvent } from "./ui/React/PromptManager";
|
||||
|
||||
import { AllServers, AddToAllServers, createUniqueRandomIp } from "./Server/AllServers";
|
||||
import { RunningScript } from "./Script/RunningScript";
|
||||
@ -2894,31 +2895,11 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
txt = JSON.stringify(txt);
|
||||
}
|
||||
|
||||
// The id for this popup will consist of the first 20 characters of the prompt string..
|
||||
// Thats hopefully good enough to be unique
|
||||
const popupId = `prompt-popup-${txt.slice(0, 20)}`;
|
||||
const textElement = createElement("p", { innerHTML: txt });
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
const yesBtn = createElement("button", {
|
||||
class: "popup-box-button",
|
||||
innerText: "Yes",
|
||||
clickListener: () => {
|
||||
removeElementById(popupId);
|
||||
resolve(true);
|
||||
},
|
||||
PromptEvent.emit({
|
||||
txt: txt,
|
||||
resolve: resolve,
|
||||
});
|
||||
|
||||
const noBtn = createElement("button", {
|
||||
class: "popup-box-button",
|
||||
innerText: "No",
|
||||
clickListener: () => {
|
||||
removeElementById(popupId);
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
|
||||
createPopup(popupId, [textElement, yesBtn, noBtn]);
|
||||
});
|
||||
},
|
||||
wget: async function (url: any, target: any, ip: any = workerScript.serverIp): Promise<boolean> {
|
||||
|
@ -68,6 +68,7 @@ import { Unclickable } from "../Exploits/Unclickable";
|
||||
import { Snackbar } from "./React/Snackbar";
|
||||
import { LogBoxManager } from "./React/LogBoxManager";
|
||||
import { AlertManager } from "./React/AlertManager";
|
||||
import { PromptManager } from "./React/PromptManager";
|
||||
import { InvitationModal } from "../Faction/ui/InvitationModal";
|
||||
|
||||
import { enterBitNode } from "../RedPill";
|
||||
@ -389,6 +390,7 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
|
||||
<Snackbar />
|
||||
<LogBoxManager />
|
||||
<AlertManager />
|
||||
<PromptManager />
|
||||
<InvitationModal />
|
||||
</Context.Router.Provider>
|
||||
</Context.Player.Provider>
|
||||
|
52
src/ui/React/PromptManager.tsx
Normal file
52
src/ui/React/PromptManager.tsx
Normal file
@ -0,0 +1,52 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import { Modal } from "../../ui/React/Modal";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Button from "@mui/material/Button";
|
||||
|
||||
export const PromptEvent = new EventEmitter<[Prompt]>();
|
||||
|
||||
interface Prompt {
|
||||
txt: string;
|
||||
resolve: (result: boolean) => void;
|
||||
}
|
||||
|
||||
export function PromptManager(): React.ReactElement {
|
||||
const [prompt, setPrompt] = useState<Prompt | null>(null);
|
||||
useEffect(
|
||||
() =>
|
||||
PromptEvent.subscribe((p: Prompt) => {
|
||||
setPrompt(p);
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
function close(): void {
|
||||
if (prompt === null) return;
|
||||
prompt.resolve(false);
|
||||
setPrompt(null);
|
||||
}
|
||||
|
||||
function yes(): void {
|
||||
if (prompt === null) return;
|
||||
prompt.resolve(true);
|
||||
setPrompt(null);
|
||||
}
|
||||
function no(): void {
|
||||
if (prompt === null) return;
|
||||
prompt.resolve(false);
|
||||
setPrompt(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{prompt != null && (
|
||||
<Modal open={true} onClose={close}>
|
||||
<Typography>{prompt.txt}</Typography>
|
||||
<Button onClick={yes}>Yes</Button>
|
||||
<Button onClick={no}>No</Button>
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user