diff --git a/markdown/bitburner.md b/markdown/bitburner.md index 492c0f9cb..44f735f05 100644 --- a/markdown/bitburner.md +++ b/markdown/bitburner.md @@ -66,6 +66,7 @@ | [StockOrder](./bitburner.stockorder.md) | Return value of [getOrders](./bitburner.tix.getorders.md) | | [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) | | [TIX](./bitburner.tix.md) | Stock market API | +| [UserInterface](./bitburner.userinterface.md) | User Interface API. | | [Warehouse](./bitburner.warehouse.md) | Warehouse for a division in a city | | [WarehouseAPI](./bitburner.warehouseapi.md) | Corporation Warehouse API | diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index ab908198d..41ab69aa4 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -51,6 +51,7 @@ export async function main(ns) { | [sleeve](./bitburner.ns.sleeve.md) | [Sleeve](./bitburner.sleeve.md) | Namespace for sleeve functions. | | [stanek](./bitburner.ns.stanek.md) | [Stanek](./bitburner.stanek.md) | Namespace for stanek functions. RAM cost: 0 GB | | [stock](./bitburner.ns.stock.md) | [TIX](./bitburner.tix.md) | Namespace for stock functions. | +| [ui](./bitburner.ns.ui.md) | [UserInterface](./bitburner.userinterface.md) | Namespace for user interface functions. RAM cost: 0 GB | ## Methods diff --git a/markdown/bitburner.ns.ui.md b/markdown/bitburner.ns.ui.md new file mode 100644 index 000000000..445717055 --- /dev/null +++ b/markdown/bitburner.ns.ui.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [ui](./bitburner.ns.ui.md) + +## NS.ui property + +Namespace for user interface functions. RAM cost: 0 GB + +Signature: + +```typescript +readonly ui: UserInterface; +``` diff --git a/markdown/bitburner.userinterface.gettheme.md b/markdown/bitburner.userinterface.gettheme.md new file mode 100644 index 000000000..7df681300 --- /dev/null +++ b/markdown/bitburner.userinterface.gettheme.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [getTheme](./bitburner.userinterface.gettheme.md) + +## UserInterface.getTheme() method + +Get the current theme + +Signature: + +```typescript +getTheme(): UserInterfaceTheme; +``` +Returns: + +UserInterfaceTheme + +An object containing the theme's colors + +## Remarks + +RAM cost: cost: 0 GB + diff --git a/markdown/bitburner.userinterface.md b/markdown/bitburner.userinterface.md new file mode 100644 index 000000000..3241407f3 --- /dev/null +++ b/markdown/bitburner.userinterface.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) + +## UserInterface interface + +User Interface API. + +Signature: + +```typescript +interface UserInterface +``` + +## Methods + +| Method | Description | +| --- | --- | +| [getTheme()](./bitburner.userinterface.gettheme.md) | Get the current theme | + diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 3054eb604..e1b8f3291 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -348,6 +348,10 @@ export const RamCosts: IMap = { remove: RamCostConstants.ScriptStanekDeleteAt, }, + ui: { + getTheme: 0, + }, + heart: { // Easter egg function break: 0, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index ab0344c2e..2329230e2 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -64,7 +64,7 @@ import { NetscriptSleeve } from "./NetscriptFunctions/Sleeve"; import { NetscriptExtra } from "./NetscriptFunctions/Extra"; import { NetscriptHacknet } from "./NetscriptFunctions/Hacknet"; import { NetscriptStanek } from "./NetscriptFunctions/Stanek"; - +import { NetscriptUserInterface } from './NetscriptFunctions/UserInterface'; import { NetscriptBladeburner } from "./NetscriptFunctions/Bladeburner"; import { NetscriptCodingContract } from "./NetscriptFunctions/CodingContract"; import { NetscriptCorporation } from "./NetscriptFunctions/Corporation"; @@ -455,6 +455,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { const formulas = NetscriptFormulas(Player, workerScript, helper); const singularity = NetscriptSingularity(Player, workerScript, helper); const stockmarket = NetscriptStockMarket(Player, workerScript, helper); + const ui = NetscriptUserInterface(Player, workerScript, helper); const base: INS = { ...singularity, @@ -465,7 +466,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { sleeve: sleeve, corporation: corporation, stanek: stanek, - + ui: ui, formulas: formulas, stock: stockmarket, args: workerScript.args, diff --git a/src/NetscriptFunctions/UserInterface.ts b/src/NetscriptFunctions/UserInterface.ts new file mode 100644 index 000000000..b684623ad --- /dev/null +++ b/src/NetscriptFunctions/UserInterface.ts @@ -0,0 +1,20 @@ +import { INetscriptHelper } from "./INetscriptHelper"; +import { WorkerScript } from "../Netscript/WorkerScript"; +import { IPlayer } from "../PersonObjects/IPlayer"; +import { getRamCost } from "../Netscript/RamCostGenerator"; +import { UserInterface as IUserInterface, UserInterfaceTheme } from "../ScriptEditor/NetscriptDefinitions"; +import { Settings } from "../Settings/Settings"; + +export function NetscriptUserInterface( + player: IPlayer, + workerScript: WorkerScript, + helper: INetscriptHelper, +): IUserInterface { + return { + getTheme: function (): UserInterfaceTheme { + helper.updateDynamicRam("getTheme", getRamCost("ui", "getTheme")); + return {...Settings.theme}; + }, + } +} + diff --git a/src/Script/RamCalculations.ts b/src/Script/RamCalculations.ts index a5ed7c24a..fbcfcabd2 100644 --- a/src/Script/RamCalculations.ts +++ b/src/Script/RamCalculations.ts @@ -194,6 +194,8 @@ async function parseOnlyRamCalculate( func = workerScript.env.vars.sleeve[ref]; } else if (ref in workerScript.env.vars.stock) { func = workerScript.env.vars.stock[ref]; + } else if (ref in workerScript.env.vars.ui) { + func = workerScript.env.vars.ui[ref]; } else { func = workerScript.env.vars[ref]; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f1602a461..0d5728e2a 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -3739,6 +3739,21 @@ interface Stanek { remove(rootX: number, rootY: number): boolean; } +/** + * User Interface API. + * @public + */ +interface UserInterface { +/** + * Get the current theme + * @remarks + * RAM cost: cost: 0 GB + * + * @returns An object containing the theme's colors + */ + getTheme(): UserInterfaceTheme; +} + /** * Collection of all functions passed to scripts * @public @@ -3821,6 +3836,12 @@ export interface NS extends Singularity { */ readonly corporation: Corporation; + /** + * Namespace for user interface functions. + * RAM cost: 0 GB + */ + readonly ui: UserInterface; + /** * Arguments passed into the script. * @@ -5882,3 +5903,45 @@ interface Division { /** Cities in which this division has expanded */ cities: string[]; } + + +/** + * Interface Theme + * @internal + */ +interface UserInterfaceTheme { + [key: string]: string | undefined; + primarylight: string; + primary: string; + primarydark: string; + successlight: string; + success: string; + successdark: string; + errorlight: string; + error: string; + errordark: string; + secondarylight: string; + secondary: string; + secondarydark: string; + warninglight: string; + warning: string; + warningdark: string; + infolight: string; + info: string; + infodark: string; + welllight: string; + well: string; + white: string; + black: string; + hp: string; + money: string; + hack: string; + combat: string; + cha: string; + int: string; + rep: string; + disabled: string; + backgroundprimary: string; + backgroundsecondary: string; + button: string; +} diff --git a/src/ui/React/ThemeEditorModal.tsx b/src/ui/React/ThemeEditorModal.tsx index 79ce1b43d..52876562f 100644 --- a/src/ui/React/ThemeEditorModal.tsx +++ b/src/ui/React/ThemeEditorModal.tsx @@ -11,7 +11,8 @@ import PaletteSharpIcon from "@mui/icons-material/PaletteSharp"; import { Color, ColorPicker } from "material-ui-color"; import { ThemeEvents } from "./Theme"; import { Settings, defaultSettings } from "../../Settings/Settings"; -import { ITheme, getPredefinedThemes } from "../../Settings/Themes"; +import { getPredefinedThemes } from "../../Settings/Themes"; +import { UserInterfaceTheme } from "../../ScriptEditor/NetscriptDefinitions"; interface IProps { open: boolean; @@ -75,7 +76,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement { )) || <>; - function setTheme(theme: ITheme): void { + function setTheme(theme: UserInterfaceTheme): void { setCustomTheme(theme); Object.assign(Settings.theme, theme); ThemeEvents.emit(); @@ -105,7 +106,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement { ThemeEvents.emit(); } - function setTemplateTheme(theme: ITheme): void { + function setTemplateTheme(theme: UserInterfaceTheme): void { setTheme(theme); }