# Making the power bar your own

> Replace everything on the power bar with a Plugin of records and a page, from a status label or a ticker of any width to a whole bar of your own in your own style.

Part of [Plugins](/docs/plugins) in the Evil Engine docs.

The power bar is the thin row of text across the top of the window, over the menus, a map and every overlay. Everything on it is data: segments and bars are records, and how they look is a page. A Plugin with nothing but a `Records/` folder can add a label, move the engine's segments between slots, recolour the bar or replace it whole, and one with a page in `Content/` can restyle every box and font.

The bar is the player's own. A server never puts anything on it, and a Plugin offers a bar but never switches to it: the player picks one with the `cl_powerbar` convar.

## Your first bar

Make a Plugin folder in `user://plugins/` (on Linux, `~/.local/share/godot/app_userdata/Evil Engine/plugins/`) with a manifest:

```
mybar/
  plugin.toml
  Records/bar.toml
```

```toml
id = "mybar"
name = "My bar"
version = "1.0.0"
api = 1
```

Then `Records/bar.toml`:

```toml
[barsegment."barsegment/tick"]
text = "{sv_tickrate} Hz"
tip = "The server's tick rate"
class = "text-(--bar-dim)"

[barsegment."barsegment/map"]
text = "{map} · {game}"
command = "status"

[barsegment."barsegment/music"]
base = "evil:barsegment/music"
width = 32

[bar."bar/default"]
base = "evil:bar/default"
left = ["evil:barsegment/clock", "mybar:barsegment/tick"]
right = ["mybar:barsegment/map", "mybar:barsegment/music"]
tokens = { bg = "#101820", edge = "#f2aa4c" }
```

Start the game, open the console with the backtick and run:

```
cl_powerbar mybar:bar/default
```

The bar redraws at once and keeps your choice in `settings.cfg`. `cl_powerbar evil:bar/default` puts the engine's back.

Every record you write is named in your Plugin's namespace, so `[barsegment."barsegment/tick"]` in `mybar` is `mybar:barsegment/tick`. Records from every `.toml` under `Records/` are read in path order at boot, and the boot transcript prints a line for each file. A key a record doesn't know, or a brace that doesn't close, is refused by its path and the file is left out, with the reason in the transcript and the console.

## Editing while the game runs

After you save a record, run `powerbar_reload` in the console. It reads every Plugin's records again, prints any problem, and redraws the bar. A style page reloads by itself whenever you save it.

## Segments

A `barsegment` is one thing on the bar.

| Key | What it is |
| --- | --- |
| `shows` | `text` (the default), `ticker` or `music`. |
| `text` | What it says, with readings in braces (below). |
| `empty` | What it says instead while a reading in `text` has no value. Without it, the segment hides then. It shows whole, never cut or scrolled. |
| `tip` | Shown on hover, with readings too. |
| `width` | In characters, 1 to 200. A ticker's window (12 when it doesn't say), or the most a text shows before it's cut to an ellipsis, with the whole text as its tip. |
| `every` | Seconds between a ticker's steps, 0.05 to 10 (0.25 when it doesn't say). |
| `gap` | What a ticker shows between its end and its start again (four spaces when it doesn't say). |
| `class` | Utility classes added to the segment, such as `text-(--bar-dim) font-bold`. |
| `command` | A console line run when the segment is clicked, as if you typed it there. |
| `base` | Another `barsegment` it takes every key it doesn't set from. |

A ticker slides its text one character to the left every `every` seconds, looping through its `gap`, and text that fits sits still. A character is a grapheme, so an emoji or an accented letter is one.

A `music` segment draws the track with previous, play or pause, next, a scrubber and the time, driving the same player as the music overlay. Its `text` is `{track}` when it doesn't say, and its `empty` shows while nothing is loaded.

## Readings

`{name}` in a `text`, `empty` or `tip` reads a value as the bar draws, and `{name:format}` formats it. `{{` and `}}` are literal braces.

| Reading | Value |
| --- | --- |
| `time` | The local date and time. Its format is .NET's custom date and time format, `ddd MMM d h:mm tt` when it doesn't say: `{time:HH:mm}`. |
| `where` | The screen the player is on: Main Menu, Singleplayer, Music, Sandbox, Paused and so on. |
| `map`, `game` | The map in play and its game's title. Nothing in the menus. |
| `players` | The session's player count. Nothing in the menus. |
| `fps` | Frames a second: `{fps:0}`. |
| `track` | The playing track's title and artist. |
| `track_title`, `track_artist`, `track_at`, `track_length` | Its parts, with the times as `m:ss`. |

Any other name is a convar's, read as the console prints it, so `{sv_tickrate}` follows the tick rate and `{sv_lighting}` shows `baked` or `realtime`. A number reading or a numeric convar takes .NET's numeric format: `{sv_tickrate:000}`. A name that's neither a reading nor a convar reads nothing, and the console says so once.

A segment hides while any reading in its `text` has no value, so `{map} · {game}` only shows in a map. A segment with no readings always shows.

## Bars

A `bar` is the whole row.

| Key | What it is |
| --- | --- |
| `left`, `centre`, `right` | Its slots, each a list of segment ids. A slot you list replaces your base's, `[]` empties it, and a slot you leave out is your base's. |
| `style` | The page it draws through: an engine style's name (`evil`) or your page's id (below). |
| `height` | In px, 12 to 96 (22 when it doesn't say). The bar's px follow the screen's DPI scale rather than the window's size, so 22 is 22 pixels at 1x and 33 at 1.5x. |
| `tokens` | Colours (`#rrggbb` or `#rrggbbaa`) and px lengths, set on the page as `--bar-<name>`. |
| `fonts` | Font files by content id, loaded as the family `bar-<name>` while the bar draws. |
| `base` | Another `bar` it takes its slots, style, height, tokens and fonts from. Tokens and fonts merge over the base's by name. |

The engine's bar is `evil:bar/default`: `evil:barsegment/clock` on the left, `evil:barsegment/where` in the centre and `evil:barsegment/music` on the right, in the `evil` style. That style draws in Barlow Semi Condensed (`font-condensed`) at 14 px and reads the tokens `bg`, `edge`, `ink`, `bright`, `dim` and `faint`, so a bar over it can recolour it with no page of its own.

## A page of your own

A style is a page, and yours lives in your Plugin's `Content/`. `style = "mybar:bar/neon"` draws through `Content/bar/neon.evilgui`. A link or image starting with `/` reaches the engine's client folder, so your page uses the engine's controls and icons without copying them.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="tailwind.css">
<link rel="components" href="/Html/Theme/controls.evilgui">
</head>
<body class="m-0 h-screen w-screen overflow-hidden font-[family-name:bar-text] text-xs text-white">
<div class="flex h-full items-center gap-3 bg-fuchsia-950 px-3">
  <div id="left" class="flex items-center gap-3"></div>
  <div class="grow"></div>
  <div id="centre" class="flex items-center gap-3"></div>
  <div class="grow"></div>
  <div id="right" class="flex items-center gap-3"></div>
</div>
<a id="kit-text" hidden data-part="text" class="shrink-0 whitespace-pre rounded bg-fuchsia-900 px-2"></a>
<div id="kit-music" hidden class="group flex shrink-0 items-center gap-2">
  <span data-part="text" class="shrink-0 whitespace-pre"></span>
  <div data-part="controls" class="flex shrink-0 items-center gap-2">
    <a data-part="play"><img src="/Music/Icons/play.svg" data-pause="/Music/Icons/pause.svg" class="h-3 w-3"></a>
    <a data-part="next"><img src="/Music/Icons/next.svg" class="h-3 w-3"></a>
    <span data-part="time" class="shrink-0 whitespace-pre"></span>
  </div>
</div>
</body>
</html>
```

```toml
[bar."bar/neon"]
base = "mybar:bar/default"
style = "mybar:bar/neon"
height = 26
fonts = { text = "mybar:fonts/mono.ttf" }
```

The bar fills the elements with `id` `left`, `centre` and `right`, and clones a hidden kit into them for each segment: `kit-text`, `kit-ticker` and `kit-music`. A kind with no kit of its own borrows `kit-text`. Inside a kit it fills elements by `data-part`, which can be the kit's root:

| Part | What the bar does |
| --- | --- |
| `text` | Sets its text. |
| `controls` | Hides it while no track is loaded. |
| `previous`, `play`, `next` | Makes them links that drive the player, greyed out while the host shares their music. An `img` in `play` swaps to its `data-pause` while playing. |
| `seek` | The scrubber, an `e-slider` from 0 to 1000. |
| `time` | Sets `at / length`. |

A segment with a `width` sets `--segment-width` on its root in `ch`, so your page can size a ticker's box from it, as `evil` does with `min-w-(--segment-width)` to keep the controls beside it still while proportional text scrolls. Each segment's root carries attributes for your variants: `data-segment` (its id), `data-empty` while it shows its `empty`, `data-command` while it has a command, and on music `data-playing` and `data-locked`. Its `class` is added to the kit's, and its `tip` becomes its `title`. A segment's root should be an `a`, so a segment with a command takes clicks. Slot children you write yourself, with no `data-segment`, stay as they are.

A style that doesn't load falls back to `evil`, with a warning in the console.

## Not yet

- A Plugin's own readings from code: Plugin code doesn't run yet, so the readings are the engine's and every convar. Once Plugin code runs in a session, a Plugin will add readings named after itself, which read nothing in the menus.
- Picking a bar from a list in Client Settings. For now it's `cl_powerbar`, or a line in your `autoexec.cfg`.
- The bar on the bottom edge, and pages making room for it rather than drawing under it.

---

- [Previous: Writing your first Plugin](/docs/plugins/first-plugin)
- [Next: Crosshairs of your own](/docs/plugins/crosshair)
