$items [picture, id] ("" picture = an empty line) * @param list $titles [picture, x, y] */ public function __construct( public string $id, public array $items, public int $x, public int $y, public array $titles = [], public int $selected = 0, ) { } public function move(int $dir): void { $n = count($this->items); do { $this->selected = ($this->selected + $dir + $n) % $n; } while ($this->items[$this->selected][0] === ''); } public function selectedId(): string { return $this->items[$this->selected][1]; } public function draw(Gfx $g, Framebuffer $fb, int $tic): void { foreach ($this->titles as [$pic, $x, $y]) { if ($g->wad->has($pic)) { $fb->drawPatch($x, $y, $g->patch($pic)); } } foreach ($this->items as $i => [$pic, $_]) { $y = $this->y + $i * self::LINEHEIGHT; if (str_starts_with($pic, '@')) { // a save slot: the text in its box (M_LSLEFT, M_LSCNTR x 24, M_LSRGHT) if ($g->wad->has('M_LSLEFT')) { $fb->drawPatch($this->x - 8, $y + 7, $g->patch('M_LSLEFT')); for ($c = 0; $c < 24; $c++) { $fb->drawPatch($this->x + $c * 8, $y + 7, $g->patch('M_LSCNTR')); } $fb->drawPatch($this->x + 24 * 8, $y + 7, $g->patch('M_LSRGHT')); } StatusBar::drawText($g, $fb, $this->x, $y, substr($pic, 1)); } elseif ($pic !== '' && $g->wad->has($pic)) { $fb->drawPatch($this->x, $y, $g->patch($pic)); } } $skull = (intdiv($tic, 8) & 1) ? 'M_SKULL2' : 'M_SKULL1'; $fb->drawPatch($this->x - 32, $this->y - 5 + $this->selected * self::LINEHEIGHT, $g->patch($skull)); } /** A screen-wide picture (TITLEPIC, HELP1, INTERPIC...): patches of 320 x 200. */ public static function fullPicture(Gfx $g, Framebuffer $fb, string $name): void { if ($g->wad->has($name)) { $fb->drawPatch(0, 0, $g->patch($name)); } } /** A flat tiled over the screen (finale texts). */ public static function tileFlat(Gfx $g, Framebuffer $fb, string $flat): void { $num = $g->flatNum[strtoupper($flat)] ?? 0; $data = $g->flat($num); $rows = []; for ($y = 0; $y < 64; $y++) { $rows[$y] = str_repeat(substr($data, $y * 64, 64), 5); } $pixels = ''; for ($y = 0; $y < $fb->height; $y++) { $pixels .= $rows[$y & 63]; } $fb->pixels = $pixels; } }