mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
API: Add API to minimize and expand tail windows (#2556)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
## TailProperties.fontSize property
|
||||
|
||||
The font size of the tail window. Defaults to the font size set in the style editor.
|
||||
The font size of the log window. Defaults to the font size set in the style editor.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ number
|
||||
|
||||
</td><td>
|
||||
|
||||
The font size of the tail window. Defaults to the font size set in the style editor.
|
||||
The font size of the log window. Defaults to the font size set in the style editor.
|
||||
|
||||
|
||||
</td></tr>
|
||||
@@ -71,6 +71,25 @@ number
|
||||
Height of the log window content area
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
[minimized](./bitburner.tailproperties.minimized.md)
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
boolean
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
Whether the log window is minimized.
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
|
||||
13
markdown/bitburner.tailproperties.minimized.md
Normal file
13
markdown/bitburner.tailproperties.minimized.md
Normal file
@@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [TailProperties](./bitburner.tailproperties.md) > [minimized](./bitburner.tailproperties.minimized.md)
|
||||
|
||||
## TailProperties.minimized property
|
||||
|
||||
Whether the log window is minimized.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
minimized: boolean;
|
||||
```
|
||||
@@ -167,6 +167,17 @@ Sets the current styles
|
||||
Set the font size of the tail window of a script.
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
[setTailMinimized(minimized, pid)](./bitburner.userinterface.settailminimized.md)
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
Minimize or expand the tail window of a script.
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
|
||||
76
markdown/bitburner.userinterface.settailminimized.md
Normal file
76
markdown/bitburner.userinterface.settailminimized.md
Normal file
@@ -0,0 +1,76 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [setTailMinimized](./bitburner.userinterface.settailminimized.md)
|
||||
|
||||
## UserInterface.setTailMinimized() method
|
||||
|
||||
Minimize or expand the tail window of a script.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
setTailMinimized(minimized: boolean, pid?: number): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
<table><thead><tr><th>
|
||||
|
||||
Parameter
|
||||
|
||||
|
||||
</th><th>
|
||||
|
||||
Type
|
||||
|
||||
|
||||
</th><th>
|
||||
|
||||
Description
|
||||
|
||||
|
||||
</th></tr></thead>
|
||||
<tbody><tr><td>
|
||||
|
||||
minimized
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
boolean
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
pid
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
number
|
||||
|
||||
|
||||
</td><td>
|
||||
|
||||
_(Optional)_ Optional. The PID of the script. If omitted, the current script is used.
|
||||
|
||||
|
||||
</td></tr>
|
||||
</tbody></table>
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Equivalent to pressing the "Minimize"/"Expand" button on the tail window.
|
||||
|
||||
If called without arguments, this function minimizes/expands the tail window of the current script. If a PID is provided, it minimizes/expands the tail window of the specified script instead.
|
||||
|
||||
@@ -1472,6 +1472,7 @@ import nsDoc_bitburner_successresult_md from "../../markdown/bitburner.successre
|
||||
import nsDoc_bitburner_tailproperties_fontsize_md from "../../markdown/bitburner.tailproperties.fontsize.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_height_md from "../../markdown/bitburner.tailproperties.height.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_md from "../../markdown/bitburner.tailproperties.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_minimized_md from "../../markdown/bitburner.tailproperties.minimized.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_width_md from "../../markdown/bitburner.tailproperties.width.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_x_md from "../../markdown/bitburner.tailproperties.x.md?raw";
|
||||
import nsDoc_bitburner_tailproperties_y_md from "../../markdown/bitburner.tailproperties.y.md?raw";
|
||||
@@ -1496,6 +1497,7 @@ import nsDoc_bitburner_userinterface_resettheme_md from "../../markdown/bitburne
|
||||
import nsDoc_bitburner_userinterface_resizetail_md from "../../markdown/bitburner.userinterface.resizetail.md?raw";
|
||||
import nsDoc_bitburner_userinterface_setstyles_md from "../../markdown/bitburner.userinterface.setstyles.md?raw";
|
||||
import nsDoc_bitburner_userinterface_settailfontsize_md from "../../markdown/bitburner.userinterface.settailfontsize.md?raw";
|
||||
import nsDoc_bitburner_userinterface_settailminimized_md from "../../markdown/bitburner.userinterface.settailminimized.md?raw";
|
||||
import nsDoc_bitburner_userinterface_settailtitle_md from "../../markdown/bitburner.userinterface.settailtitle.md?raw";
|
||||
import nsDoc_bitburner_userinterface_settheme_md from "../../markdown/bitburner.userinterface.settheme.md?raw";
|
||||
import nsDoc_bitburner_userinterface_windowsize_md from "../../markdown/bitburner.userinterface.windowsize.md?raw";
|
||||
@@ -3063,6 +3065,7 @@ AllPages["nsDoc/bitburner.successresult.md"] = nsDoc_bitburner_successresult_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.fontsize.md"] = nsDoc_bitburner_tailproperties_fontsize_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.height.md"] = nsDoc_bitburner_tailproperties_height_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.md"] = nsDoc_bitburner_tailproperties_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.minimized.md"] = nsDoc_bitburner_tailproperties_minimized_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.width.md"] = nsDoc_bitburner_tailproperties_width_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.x.md"] = nsDoc_bitburner_tailproperties_x_md;
|
||||
AllPages["nsDoc/bitburner.tailproperties.y.md"] = nsDoc_bitburner_tailproperties_y_md;
|
||||
@@ -3087,6 +3090,7 @@ AllPages["nsDoc/bitburner.userinterface.resettheme.md"] = nsDoc_bitburner_userin
|
||||
AllPages["nsDoc/bitburner.userinterface.resizetail.md"] = nsDoc_bitburner_userinterface_resizetail_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.setstyles.md"] = nsDoc_bitburner_userinterface_setstyles_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.settailfontsize.md"] = nsDoc_bitburner_userinterface_settailfontsize_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.settailminimized.md"] = nsDoc_bitburner_userinterface_settailminimized_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.settailtitle.md"] = nsDoc_bitburner_userinterface_settailtitle_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.settheme.md"] = nsDoc_bitburner_userinterface_settheme_md;
|
||||
AllPages["nsDoc/bitburner.userinterface.windowsize.md"] = nsDoc_bitburner_userinterface_windowsize_md;
|
||||
|
||||
@@ -833,6 +833,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?:
|
||||
width: logProps.width,
|
||||
height: logProps.height,
|
||||
fontSize: logProps.fontSize ?? Settings.styles.tailFontSize,
|
||||
minimized: logProps.minimized,
|
||||
},
|
||||
title: runningScript.title,
|
||||
threads: runningScript.threads,
|
||||
|
||||
@@ -442,6 +442,7 @@ const ui = {
|
||||
closeTail: 0,
|
||||
setTailTitle: 0,
|
||||
setTailFontSize: 0,
|
||||
setTailMinimized: 0,
|
||||
getTheme: 0,
|
||||
setTheme: 0,
|
||||
resetTheme: 0,
|
||||
|
||||
@@ -105,6 +105,19 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
else runningScriptObj.tailProps?.setFontSize(helpers.number(ctx, "pixel", _pixel));
|
||||
},
|
||||
|
||||
setTailMinimized:
|
||||
(ctx) =>
|
||||
(_minimized, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const minimized = helpers.boolean(ctx, "minimized", _minimized);
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.setMinimized(minimized);
|
||||
},
|
||||
|
||||
windowSize: () => () => {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
},
|
||||
|
||||
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -210,8 +210,10 @@ interface TailProperties {
|
||||
width: number;
|
||||
/** Height of the log window content area */
|
||||
height: number;
|
||||
/** The font size of the tail window. Defaults to the font size set in the style editor. */
|
||||
/** The font size of the log window. Defaults to the font size set in the style editor. */
|
||||
fontSize: number;
|
||||
/** Whether the log window is minimized. */
|
||||
minimized: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6809,6 +6811,21 @@ interface UserInterface {
|
||||
*/
|
||||
setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
|
||||
/**
|
||||
* Minimize or expand the tail window of a script.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Equivalent to pressing the "Minimize"/"Expand" button on the tail window.
|
||||
*
|
||||
* If called without arguments, this function minimizes/expands the tail window of the current script. If a PID is
|
||||
* provided, it minimizes/expands the tail window of the specified script instead.
|
||||
*
|
||||
* @param pid - Optional. The PID of the script. If omitted, the current script is used.
|
||||
*/
|
||||
setTailMinimized(minimized: boolean, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Get the current window size
|
||||
* @remarks
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
||||
import React, { useEffect, useRef, useCallback, useMemo } from "react";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import { RunningScript } from "../../Script/RunningScript";
|
||||
import { killWorkerScriptByPid } from "../../Netscript/killWorkerScript";
|
||||
@@ -45,6 +45,7 @@ export class LogBoxProperties {
|
||||
width = 500;
|
||||
height = 500;
|
||||
fontSize: number | undefined = undefined;
|
||||
minimized = false;
|
||||
|
||||
rerender: () => void;
|
||||
rootRef: React.RefObject<Draggable>;
|
||||
@@ -79,6 +80,11 @@ export class LogBoxProperties {
|
||||
this.rerender();
|
||||
}
|
||||
|
||||
setMinimized(minimized: boolean): void {
|
||||
this.minimized = minimized;
|
||||
this.rerender();
|
||||
}
|
||||
|
||||
isVisible(): boolean {
|
||||
return this.rootRef.current !== null;
|
||||
}
|
||||
@@ -183,7 +189,6 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
const rerender = useRerender(Settings.TailRenderInterval);
|
||||
const propsRef = useRef(new LogBoxProperties(rerender, rootRef));
|
||||
script.tailProps = propsRef.current;
|
||||
const [minimized, setMinimized] = useState(false);
|
||||
|
||||
const textAreaKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.ctrlKey && e.key === "a") {
|
||||
@@ -198,7 +203,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
}
|
||||
};
|
||||
|
||||
const onResize = (e: React.SyntheticEvent, { size }: ResizeCallbackData) => {
|
||||
const onResize = (_: React.SyntheticEvent, { size }: ResizeCallbackData) => {
|
||||
propsRef.current.setSize(size.width, size.height);
|
||||
};
|
||||
|
||||
@@ -263,7 +268,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
}
|
||||
|
||||
function minimize(): void {
|
||||
setMinimized(!minimized);
|
||||
propsRef.current.setMinimized(!propsRef.current.minimized);
|
||||
}
|
||||
|
||||
function lineColor(s: string): "error" | "success" | "warn" | "info" | "primary" {
|
||||
@@ -345,7 +350,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
zIndex: 1400,
|
||||
minWidth: `${minWindowSize[0]}px`,
|
||||
minHeight: `${minWindowSize[1]}px`,
|
||||
...(minimized
|
||||
...(propsRef.current.minimized
|
||||
? {
|
||||
border: "none",
|
||||
margin: 0,
|
||||
@@ -370,7 +375,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
right: "-10px",
|
||||
bottom: "-16px",
|
||||
cursor: "nw-resize",
|
||||
display: minimized ? "none" : "inline-block",
|
||||
display: propsRef.current.minimized ? "none" : "inline-block",
|
||||
}}
|
||||
>
|
||||
<ArrowForwardIosIcon color="primary" style={{ transform: "rotate(45deg)", fontSize: "1.75rem" }} />
|
||||
@@ -392,12 +397,12 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
</IconButton>
|
||||
)}
|
||||
<IconButton
|
||||
title={minimized ? "Expand" : "Collapse"}
|
||||
title={propsRef.current.minimized ? "Expand" : "Minimize"}
|
||||
className={classes.titleButton}
|
||||
onClick={minimize}
|
||||
onTouchEnd={minimize}
|
||||
>
|
||||
{minimized ? <ExpandMoreIcon /> : <ExpandLessIcon />}
|
||||
{propsRef.current.minimized ? <ExpandMoreIcon /> : <ExpandLessIcon />}
|
||||
</IconButton>
|
||||
<IconButton title="Close window" className={classes.titleButton} onClick={onClose} onTouchEnd={onClose}>
|
||||
<CloseIcon />
|
||||
@@ -407,7 +412,10 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
|
||||
<Paper
|
||||
className={classes.logs}
|
||||
style={{ height: `calc(100% - ${minWindowSize[1]}px)`, display: minimized ? "none" : "flex" }}
|
||||
style={{
|
||||
height: `calc(100% - ${minWindowSize[1]}px)`,
|
||||
display: propsRef.current.minimized ? "none" : "flex",
|
||||
}}
|
||||
tabIndex={-1}
|
||||
ref={textArea}
|
||||
onKeyDown={textAreaKeyDown}
|
||||
|
||||
Reference in New Issue
Block a user