'Ciel dégagé', 'rain' => 'Pluie', 'storm' => 'Orage', 'snow' => 'Neige', 'fog' => 'Brouillard']; private const HEADINGS = [0 => 'N', 45 => 'NE', 90 => 'E', 135 => 'SE', 180 => 'S', 225 => 'SO', 270 => 'O', 315 => 'NO']; /** vital => [label, icon, colour] */ public const VITALS = [ 'health' => ['Santé', 'v_health', [226, 92, 92]], 'blood' => ['Sang', 'v_blood', [200, 52, 62]], 'temperature' => ['Temp.', 'v_temperature', [240, 150, 90]], 'hunger' => ['Faim', 'v_hunger', [222, 166, 82]], 'thirst' => ['Soif', 'v_thirst', [80, 164, 232]], 'fatigue' => ['Repos', 'v_fatigue', [168, 160, 232]], 'morale' => ['Moral', 'v_morale', [232, 200, 82]], ]; /** the big centre hint shows while Hints gives more than this; under it, only the small marker */ public const BIG = 0.35; /** touch buttons: id => [x, y, radius, label] */ public const BUTTONS = [ 'attack' => [894.0, 546.0, 46.0, 'ATTAQUE'], 'jump' => [790.0, 586.0, 38.0, 'SAUT'], 'run' => [896.0, 440.0, 36.0, 'COURIR'], 'crouch' => [804.0, 488.0, 34.0, 'BAS'], 'inventory' => [896.0, 346.0, 32.0, 'SAC'], 'scanner' => [812.0, 396.0, 32.0, 'RADAR'], 'map' => [896.0, 262.0, 30.0, 'CARTE'], 'pause' => [30.0, 128.0, 22.0, 'II'], // shown only with something in the left hand (HudData::$leftButton gives its label) 'left' => [700.0, 560.0, 34.0, 'TORCHE'], ]; /** $talking: a dialogue is open (no log, no prompt: the dialogue panel takes their place) */ public function draw(Canvas $c, Game $g, HudData $d, bool $talking = false): void { $this->flash($c, $d); if ($d->touch) { // phones: a lighter dashboard: one line of time, the compass, one line of objective; details on tap $this->phoneTop($c, $g, $d); } else { $this->clockPanel($c, $g); $this->compass($c, $g, $d); $this->objective($c, $d); } // the aim $c->rect(479, 359, 2, 2, [255, 255, 255, 150]); if ($d->captured) { $c->rect(472, 359, 5, 2, [255, 255, 255, 110]); $c->rect(483, 359, 5, 2, [255, 255, 255, 110]); $c->rect(479, 352, 2, 5, [255, 255, 255, 110]); $c->rect(479, 363, 2, 5, [255, 255, 255, 110]); } if ($d->captureHint && !$talking) { $c->text('Maintiens le clic et glisse pour regarder autour de toi · H : commandes · P : pause', 480, 74, 12, [200, 214, 226], 'center'); } if ($d->hitMark > 0.02) { // the hit marker: a blow landed $a = (int) (230 * $d->hitMark); foreach ([[-1, -1], [1, -1], [-1, 1], [1, 1]] as [$sx, $sy]) { $c->line(480 + 6 * $sx, 360 + 6 * $sy, 480 + 13 * $sx, 360 + 13 * $sy, [255, 240, 220, $a], 2); } } if (!$talking) { $this->combat($c, $d); $this->aimBar($c, $d); $this->prompt($c, $d); $this->feed($c, $d); } $this->badges($c, $g, $d); $this->bar($c, $g, $d); if ($d->tooltip !== null && !$talking) { $lines = $c->wrap($d->tooltip, 13, 420); $h = 12 + 17 * count($lines); $c->panel(14, 624 - $h - 30, 446, $h, 225, [120, 190, 255, 200]); foreach ($lines as $i => $line) { $c->text($line, 24, 624 - $h - 24 + $i * 17, 13, [226, 234, 242]); } } if ($d->touch) { $this->buttons($c, $d); } } private function flash(Canvas $c, HudData $d): void { if ($d->flash <= 0.02) { return; } for ($k = 0; $k < 3; $k++) { $a = (int) (90 * $d->flash / ($k + 1)); $t = 26 + $k * 30; $col = [200, 20, 20, $a]; $c->rect(0, 0, Canvas::W, $t, $col); $c->rect(0, Canvas::H - $t, Canvas::W, $t, $col); $c->rect(0, $t, $t, Canvas::H - 2 * $t, $col); $c->rect(Canvas::W - $t, $t, $t, Canvas::H - 2 * $t, $col); } } /** Phones: the time and temperature, the compass, the objective: one big line each, nothing that overlaps. */ private function phoneTop(Canvas $c, Game $g, HudData $d): void { $h = $g->hour(); $c->panel(14, 14, 250, 44); $c->text(sprintf('%02d:%02d · %s', (int) $h, (int) (($h - (int) $h) * 60), self::celsius($g->airTemp())), 26, 22, 18, [240, 244, 248]); $c->hit(14, 14, 250, 44, 'vital:temperature'); $this->compass($c, $g, $d, true); if ($d->objective !== '') { $wrapped = $c->wrap($d->objective, 15, 290); $line = ($wrapped[0] ?? '') . (count($wrapped) > 1 ? '…' : ''); $c->panel(616, 14, 330, 44, 150, [255, 196, 80, 220]); $c->text($line, 630, 24, 15, [232, 236, 240]); } } private function clockPanel(Canvas $c, Game $g): void { $c->panel(14, 14, 226, 82); $c->icon($g->isNight() || $g->zone->cave ? 'v_fatigue' : 'v_morale', 24, 24, 36); $h = $g->hour(); $c->text(sprintf('Jour %d · %02d:%02d', $g->day(), (int) $h, (int) (($h - (int) $h) * 60)), 70, 21, 20, [240, 244, 248]); $w = $g->zone->cave ? 'Souterrain' : (self::WEATHER[$g->weather['kind'] ?? 'clear'] ?? 'Ciel dégagé'); $c->text($w . ' · ' . self::celsius($g->airTemp()), 70, 47, 15, [196, 210, 222]); $c->text($g->zone->name, 24, 72, 13, [150, 170, 186]); $stance = $g->swimming ? 'Nage' : ($g->crouching ? 'Accroupi' : ($g->sprinting ? 'Sprint' : ($g->running ? 'Course' : ''))); if ($stance !== '') { $c->text($stance, 230, 72, 13, [255, 214, 120], 'right'); } } /** Bearing in degrees (0 north = -z, 90 east = +x) of a direction. */ public static function bearing(float $dx, float $dz): float { $b = rad2deg(atan2($dx, -$dz)); return $b < 0 ? $b + 360 : $b; } private static function diff(float $a, float $b): float { $d = fmod($a - $b + 540.0, 360.0) - 180.0; return $d; } private function compass(Canvas $c, Game $g, HudData $d, bool $phone = false): void { $x0 = $phone ? 300.0 : 330.0; $w = $phone ? 290.0 : 300.0; $cx = $x0 + $w / 2; $c->panel($x0, 14, $w, 40, 150); $head = self::bearing(sin($g->yaw), cos($g->yaw)); $k = $w / 160; // units per degree (80° each side) for ($deg = 0; $deg < 360; $deg += 15) { $off = self::diff($deg, $head); if (abs($off) > 76) { continue; } $x = $cx + $off * $k; if (isset(self::HEADINGS[$deg]) && (!$phone || $deg % 90 === 0)) { $major = $deg % 90 === 0; $mark = Translator::lang() === 'en' ? str_replace('O', 'W', self::HEADINGS[$deg]) : self::HEADINGS[$deg]; // ouest = west $c->text(Translator::keep($mark), $x, 20, $major ? 17 : 13, $deg === 0 ? [255, 120, 100] : ($major ? [236, 240, 244] : [170, 184, 196]), 'center'); } else { $c->rect($x - 0.5, 40, 1, 8, [200, 214, 226, 140]); } } // the objective if ($d->target !== null) { $tb = self::bearing($d->target[0] - $g->x, $d->target[1] - $g->z); $off = self::diff($tb, $head); $x = $cx + max(-74.0, min(74.0, $off)) * $k; $col = [255, 196, 80]; if (abs($off) <= 74) { $c->triangle($x, 40, $x - 6, 48, $x + 6, 48, $col); $c->triangle($x - 6, 48, $x + 6, 48, $x, 56, $col); } else { $s = $off > 0 ? 1 : -1; $c->triangle($x + 8 * $s, 46, $x, 39, $x, 53, $col); } $dist = hypot($d->target[0] - $g->x, $d->target[1] - $g->z); $c->text($phone ? sprintf('%d m', (int) round($dist)) : sprintf('%s · %d m', $d->target[2], (int) round($dist)), $cx, 60, 13, [255, 214, 140], 'center'); } if ($phone) { $c->triangle($cx - 5, 14, $cx + 5, 14, $cx, 21, [255, 255, 255]); return; } // the GPS point (or the door toward it), and a place a gauge's menu pointed at $below = $d->target !== null ? 76.0 : 60.0; foreach ([[$g->waypointTarget(), [80, 230, 255], 'GPS : '], [$d->pointer, [180, 255, 170], '→ ']] as [$p, $col, $pre]) { if ($p === null) { continue; } $tb = self::bearing($p[0] - $g->x, $p[1] - $g->z); $off = self::diff($tb, $head); $x = $cx + max(-74.0, min(74.0, $off)) * $k; if (abs($off) <= 74) { $c->circle($x, 44, 5.5, [0, 0, 0, 160]); $c->circle($x, 44, 4.2, $col); } else { $s = $off > 0 ? 1 : -1; $c->triangle($x + 8 * $s, 44, $x, 38, $x, 50, $col); } $c->text(sprintf('%s%s · %d m', $pre, $p[2], (int) round(hypot($p[0] - $g->x, $p[1] - $g->z))), $cx, $below, 12, $col, 'center'); $below += 15; } $c->triangle($cx - 5, 14, $cx + 5, 14, $cx, 21, [255, 255, 255]); } private function objective(Canvas $c, HudData $d): void { if ($d->objective === '') { return; } $lines = $c->wrap($d->objective, 15, 270); $h = 34 + 19 * min(3, count($lines)); $c->panel(646, 14, 300, $h, 150, [255, 196, 80, 220]); $c->text($d->quest, 660, 21, 13, [255, 204, 110]); foreach (array_slice($lines, 0, 3) as $i => $line) { $c->text($line, 660, 41 + $i * 19, 15, [232, 236, 240]); } } /** Intentions of the target, shown in its panel. */ public const INTENTS = ['strike' => 'Va frapper !', 'charge' => 'Va charger !', 'aim' => 'Te vise !', 'keep' => 'Tenu par la flamme', 'flee' => 'Fuit']; /** * The combat mode: the target's panel at the top (name, health, its intention and the glow of a blow being wound up, * what to do about it), the popups of the fight under it. */ private function combat(Canvas $c, HudData $d): void { $i = $d->combat; $top = $d->touch ? 70.0 : 92.0; if ($i !== null) { $w = $d->touch ? 380.0 : 320.0; $x = 480 - $w / 2; $danger = in_array($i['intent'], ['strike', 'aim'], true); $pulse = $danger ? 0.5 + 0.5 * sin($d->time * 18) : 0.0; $c->panel($x, $top, $w, 50, 190, $danger ? [255, 90, 70, (int) (150 + 100 * $pulse)] : [255, 160, 110, 160]); if ($danger) { $glow = (int) (60 + 150 * $i['wind']); $c->border($x - 2, $top - 2, $w + 4, 54, [255, 70, 50, $glow], 2); } $c->textBox($i['name'], $x + 12, $top + 6, $w * 0.5, 14, [255, 236, 220]); $label = self::INTENTS[$i['intent'] ?? ''] ?? ''; if ($label !== '') { $col = $danger || $i['intent'] === 'charge' ? [255, 150, 120] : [190, 206, 220]; if ($danger || $i['intent'] === 'charge') { $ix = $x + $w - 12 - $c->measure($label, 13) - 18; $c->triangle($ix, $top + 20, $ix + 7, $top + 7, $ix + 14, $top + 20, [255, 120, 80]); $c->text('!', $ix + 7, $top + 9, 10, [20, 10, 6], 'center', false); } $c->text($label, $x + $w - 12, $top + 7, 13, $col, 'right'); } $hp = max(0.0, min(1.0, (float) $i['hp'])); $c->rect($x + 12, $top + 28, $w - 24, 8, [255, 255, 255, 30]); $c->rect($x + 12, $top + 28, ($w - 24) * $hp, 8, $hp > 0.5 ? [120, 210, 120] : ($hp > 0.25 ? [235, 190, 80] : [230, 80, 60])); if ($danger) { $c->rect($x + 12, $top + 40, ($w - 24) * (float) $i['wind'], 3, [255, 90, 60, 230]); $help = $d->touch ? ($d->shieldKey !== null ? 'ESQUIVE, PARER ou ATTAQUE (contre)' : 'ESQUIVE ou ATTAQUE maintenant (contre)') : ($d->shieldKey !== null ? $d->dodgeKey . ' : esquiver · ' . $d->shieldKey . ' : parer · ' . $d->attackKey . ' : contrer' : $d->dodgeKey . ' : esquiver · ' . $d->attackKey . ' maintenant : contrer'); $c->pill(480 - 170, $top + 54, 340, 20, [14, 18, 24, 170]); $c->textBox($help, 480 - 164, $top + 56, 328, 12, [255, 214, 190], 'center'); } } $py = $top + ($i !== null ? 80 : 150); foreach ($d->popups as [$text, $age, $col]) { $a = (int) (255 * max(0.0, min(1.0, 1.4 - $age) / 0.6)); $c->text($text, 480, $py - $age * 26, 18, [(int) $col[0], (int) $col[1], (int) $col[2], min(255, $a)], 'center'); $py += 24; } } /** The precision cursor: the bar, its zones (weak · plain · critical in the centre), the cursor sweeping. */ private function aimBar(Canvas $c, HudData $d): void { if ($d->aim === null) { return; } $w = 320.0; $x = 480 - $w / 2; $y = 300.0; $c->rect($x - 4, $y - 4, $w + 8, 26, [8, 12, 18, 170]); $c->rect($x, $y, $w, 18, [150, 160, 170, 90]); $good = 0.32; $c->rect($x + $w * (0.5 - $good), $y, $w * 2 * $good, 18, [110, 170, 230, 150]); $s = max(0.02, min(0.6, $d->sweet)); $c->rect($x + $w * (0.5 - $s / 2), $y, $w * $s, 18, [255, 200, 90, 230]); $cx = $x + $w * max(0.0, min(1.0, $d->aim)); $c->rect($cx - 2, $y - 6, 4, 30, [255, 255, 255]); $c->text($d->touch ? 'Touche ATTAQUE au centre : critique' : 'Frappe quand le curseur est au centre : critique', 480, $y + 26, 12, [230, 236, 242], 'center'); } private function prompt(Canvas $c, HudData $d): void { if ($d->prompt === null) { return; } if ($d->focusCount > 1) { // several things within reach: G (the pad's right stick, a tap here) chooses the next one $label = ($d->touch ? '» ' : 'G » ') . $d->focusIndex . '/' . $d->focusCount; $w = $c->measure($label, 13) + ($d->touch ? 30 : 18); $h = $d->touch ? 34.0 : 22.0; $y = $d->hint < self::BIG ? 352.0 : 444.0; $c->pill(480 - $w / 2, $y, $w, $h, [20, 26, 34, 170]); $c->text($label, 480, $y + ($h - 13) / 2 - 1, 13, [230, 236, 242], 'center'); $c->hit(480 - $w / 2, $y, $w, $h, 'prompt:next'); } if ($d->hint < self::BIG) { // the small marker: the key and the action, discreet, under the crosshair (never with the big hint: the same // words twice, one under the other); it fades in as the big one has gone $in = 1 - $d->hint / self::BIG; $kw = max(18.0, $c->measure($d->actKey, 11) + 10); $tw = $c->measure($d->prompt, 12); $x = 480 - ($kw + 6 + $tw) / 2; $a = (int) (160 * $in); $c->pill($x, 378, $kw, 17, [235, 238, 242, (int) ($a * 0.9)]); $c->text($d->actKey, $x + $kw / 2, 380, 11, [20, 26, 34], 'center', false); $v = (int) (80 + 150 * $in); $c->text($d->prompt, $x + $kw + 6, 379, 12, [$v, $v + 4, $v + 8]); $c->hit($x, 374, $kw + 6 + $tw, 24, 'prompt'); return; } $fade = min(1.0, ($d->hint - self::BIG) / (1 - self::BIG) * 1.5); $key = $d->actKey; $kw = $c->measure($key, 14) + 16; $tw = $c->measure($d->prompt, 17); $w = $kw + $tw + 30; $x = 480 - $w / 2; $c->rect($x, 404, $w, 34, [12, 16, 22, (int) (165 * $fade)]); $c->border($x, 404, $w, 34, [190, 210, 230, (int) (46 * $fade)]); $c->pill($x + 8, 410, $kw, 22, [235, 238, 242, (int) (230 * $fade)]); $c->text($key, $x + 8 + $kw / 2, 413, 14, [20, 26, 34], 'center', false); $tv = (int) (255 * $fade); $c->text($d->prompt, $x + 18 + $kw, 411, 17, [$tv, $tv, $tv]); $c->hit($x, 404, $w, 34, 'prompt'); } private function feed(Canvas $c, HudData $d): void { $y = 586.0; $shown = 0; $most = $d->touch ? 1 : 5; for ($i = count($d->feed) - 1; $i >= 0 && $shown < $most; $i--, $shown++) { [$text, $age] = $d->feed[$i]; $lines = $c->wrap($text, 15, $d->touch ? 600 : 430); $n = min($d->touch ? 2 : 4, count($lines)); if ($d->touch) { $lh = 19 * $c->boost; $y -= $n * $lh + 6; $fade = $age < 6 ? 1.0 : max(0.0, 1 - ($age - 6) / 3); $c->rect(14, $y - 3, 616, $n * $lh + 4, [8, 12, 18, (int) (130 * $fade)]); foreach (array_slice($lines, 0, $n) as $k => $line) { $c->text($line, 24, $y + $k * $lh, 15, [240, 244, 248, (int) (255 * $fade)]); } continue; } $y -= $n * 19 + 6; $fade = $age < 6 ? 1.0 : max(0.0, 1 - ($age - 6) / 3); if ($fade <= 0) { continue; } $c->rect(14, $y - 3, 446, $n * 19 + 4, [8, 12, 18, (int) (110 * $fade)]); $c->rect(14, $y - 3, 2, $n * 19 + 4, [150, 210, 255, (int) (200 * $fade)]); $v = (int) (90 + 160 * $fade); foreach (array_slice($lines, 0, $n) as $k => $line) { $c->text($line, 24, $y + $k * 19, 15, [$v, $v, (int) min(255, $v + 6)]); } } } private function badges(Canvas $c, Game $g, HudData $d): void { $x = 16.0; $y = 600.0; foreach ($d->conditions as $cond) { $sev = $cond['severity']; $col = $sev > 0.6 ? [214, 54, 54] : ($sev > 0.3 ? [222, 128, 40] : [200, 170, 60]); $w = $c->measure($cond['label'], 13) + 26; $c->pill($x, $y, $w, 22, [$col[0], $col[1], $col[2], 200]); $c->circle($x + 10, $y + 11, 3.5, [255, 255, 255]); $c->text($cond['label'], $x + 18, $y + 4, 13, [255, 255, 255]); $c->hit($x, $y - 2, $w, 26, 'cond:' . $cond['id']); $x += $w + 6; } if ($g->nearFire()) { $x += $this->goodBadge($c, $x, $y, 'Près du feu') + 6; } if ($g->sheltered() && !$g->zone->cave) { $x += $this->goodBadge($c, $x, $y, 'À l\'abri') + 6; } if ($d->feeling !== null && $x < 600) { // up to the touch buttons / the slots: two lines when long, the second one on the badges' line $w = 640 - $x; $f = $c->fit($d->feeling, 14, $w - 2 * Canvas::PAD, 2); $lh = $f['size'] * 1.15 * $c->boost; $c->textBox($d->feeling, $x + 2, $y + 3 - (count($f['lines']) - 1) * $lh, $w, 14, [255, 206, 170], 'left', 2, 1.15); } } private function goodBadge(Canvas $c, float $x, float $y, string $label): float { $w = $c->measure($label, 13) + 16; $c->pill($x, $y, $w, 22, [60, 140, 90, 190]); $c->text($label, $x + 8, $y + 4, 13, [240, 255, 244]); return $w; } /** "37,2 °C" */ public static function celsius(float $t): string { return Translator::num($t, 0) . ' °C'; } /** @return array{0: float, 1: string} a vital's fill (0..1) and its text */ public static function vital(string $key, float $v): array { return match ($key) { 'blood' => [max(0.0, min(1.0, ($v - Body::BLOOD_DEATH) / (Body::BLOOD_MAX - Body::BLOOD_DEATH))), Translator::num($v, 1) . ' L'], 'temperature' => [max(0.0, min(1.0, 1 - abs($v - 37.0) / 5)), Translator::num($v, 1) . ' °C'], default => [max(0.0, min(1.0, $v / 100)), (string) (int) round($v)], }; } private function bar(Canvas $c, Game $g, HudData $d): void { $c->panel(14, 630, $d->touch ? 576 : 932, 78, 178); $v = $g->body->vitals(); $x = 26.0; $shown = self::VITALS; $cellW = 80.0; if ($d->touch) { // phones: a lighter dashboard: the four gauges in the worst state, wider; a tap gives the rest $rank = []; foreach (self::VITALS as $key => $def) { $rank[$key] = self::vital($key, (float) ($v[$key] ?? 0))[0]; } asort($rank); $shown = array_intersect_key(self::VITALS, array_slice($rank, 0, 4, true)); $cellW = 140.0; } foreach ($shown as $key => [$label, $icon, $col]) { [$fill, $text] = self::vital($key, (float) ($v[$key] ?? 0)); $low = $fill < 0.25; $c->icon($icon, $x, 642, 26); $tc = $low ? (fmod($d->time, 1.0) < 0.5 ? [255, 110, 100] : [255, 200, 190]) : [244, 246, 250]; if ($d->touch) { // phones: the icon and the value, big enough to read $c->text($text, $x + 31, 646, $key === 'temperature' || $key === 'blood' ? 17 : 20, $tc); } else { $c->text($label, $x + 31, 639, 12, [160, 176, 190]); $c->text($text, $x + 31, 653, $key === 'temperature' || $key === 'blood' ? 15 : 17, $tc); } $c->rect($x, 682, 72, 6, [255, 255, 255, 26]); $bc = $low ? [230, 70, 60] : $col; if ($key === 'temperature') { $t = (float) ($v['temperature'] ?? 37); $bc = $t < 36 ? [90, 170, 240] : ($t > 38 ? [240, 110, 60] : [120, 210, 140]); } $c->rect($x, 682, 72 * $fill, 6, $bc); $c->rect($x, 682, 72 * $fill, 1, [255, 255, 255, 70]); $c->hit($x - 4, 636, $cellW, 58, 'vital:' . $key); $x += $cellW; } if ($d->touch) { $this->phoneSlots($c, $g, $d); return; } $c->rect(592, 640, 1, 58, [255, 255, 255, 40]); // the item in hand $c->text('EN MAIN', 604, 638, 11, [150, 166, 180]); $hand = $g->inv->hand !== null && $g->inv->has($g->inv->hand) ? $g->inv->hand : null; $left = $g->inv->handLeft !== null && $g->inv->has($g->inv->handLeft) ? $g->inv->handLeft : null; $c->rect(604, 654, 44, 44, [255, 255, 255, 18]); $c->border(604, 654, 44, 44, [255, 255, 255, 50]); if ($hand !== null) { $c->icon($hand, 608, 658, 36); foreach (array_slice($c->wrap(Items::name($hand), 13, 66), 0, $left !== null ? 2 : 3) as $i => $line) { $c->text($line, 654, 656 + $i * 15, 13, [236, 240, 244]); } } elseif ($left === null) { $c->text('Mains nues', 654, 668, 13, [150, 160, 170]); } if ($left !== null) { // the left hand: a small icon in the corner, its name under the right one $c->rect(598, 678, 24, 24, [10, 14, 20, 220]); $c->border(598, 678, 24, 24, [255, 204, 110, 150]); $c->icon($left, 600, 680, 20); $c->text('G : ' . Items::name($left), 654, $hand !== null ? 686 : 668, 12, [255, 214, 150]); } $c->hit(604, 640, 116, 60, 'hand'); // quick slots for ($i = 1; $i <= 4; $i++) { $sx = 726 + ($i - 1) * 54; $id = $d->slots[$i] ?? null; $has = $id !== null && $g->inv->has($id); $c->rect($sx, 642, 50, 56, [255, 255, 255, $has ? 22 : 10]); $c->border($sx, 642, 50, 56, $id !== null && $id === $hand ? [255, 204, 110, 200] : [255, 255, 255, 50]); $c->text((string) $i, $sx + 5, 644, 12, [170, 186, 200], 'left', false); if ($id !== null) { if ($has) { $c->icon($id, $sx + 9, 652, 32); $n = $g->inv->count($id); if ($n > 1) { $c->text((string) $n, $sx + 46, 682, 13, [255, 255, 255], 'right'); } } else { $c->text('—', $sx + 25, 660, 16, [110, 120, 130], 'center', false); } } $c->hit($sx, 642, 50, 56, 'slot:' . $i); } } /** Phones: the hand and the four quick slots as big square buttons in their own strip, bottom right (icons only). */ private function phoneSlots(Canvas $c, Game $g, HudData $d): void { $hand = $g->inv->hand !== null && $g->inv->has($g->inv->hand) ? $g->inv->hand : null; $c->panel(598, 630, 348, 78, 178); $x = 606.0; $c->rect($x, 638, 62, 62, [255, 204, 110, 40]); $c->border($x, 638, 62, 62, [255, 204, 110, 160]); $left = $g->inv->handLeft !== null && $g->inv->has($g->inv->handLeft) ? $g->inv->handLeft : null; if ($hand !== null) { $c->icon($hand, $x + 7, 645, 48); } elseif ($left === null) { $c->icon('v_health', $x + 15, 653, 32); } if ($left !== null) { $c->rect($x - 4, 668, 30, 30, [10, 14, 20, 220]); $c->border($x - 4, 668, 30, 30, [255, 204, 110, 150]); $c->icon($left, $x - 1, 671, 24); } $c->hit($x, 634, 62, 70, 'hand'); for ($i = 1; $i <= 4; $i++) { $sx = $x + 70 + ($i - 1) * 66; $id = $d->slots[$i] ?? null; $has = $id !== null && $g->inv->has($id); $c->rect($sx, 638, 60, 62, [255, 255, 255, $has ? 24 : 10]); $c->border($sx, 638, 60, 62, $id !== null && $id === $hand ? [255, 204, 110, 200] : [255, 255, 255, 60]); if ($has) { $c->icon((string) $id, $sx + 8, 645, 44); } else { $c->text((string) $i, $sx + 30, 656, 16, [110, 124, 138], 'center', false); } $c->hit($sx, 634, 60, 70, 'slot:' . $i); } } private function buttons(Canvas $c, HudData $d): void { foreach (self::BUTTONS as $id => [$x, $y, $r, $label]) { if ($id === 'scanner' && !$d->hasScanner) { continue; } if ($id === 'left') { if ($d->leftButton === null) { continue; } $label = $d->leftButton; } if ($id === 'jump' && $d->combat !== null) { $label = 'ESQUIVE'; // combat mode: the jump button dodges } $on = ($id === 'run' && $d->runToggle) || ($id === 'crouch' && $d->crouchToggle); $c->circle($x, $y, $r, $on ? [255, 196, 80, 150] : [14, 20, 28, 150]); $c->circle($x, $y, $r - 2, $on ? [255, 196, 80, 110] : [255, 255, 255, 20]); $c->text($label, $x, $y - 7, $r > 30 ? 13 : 12, [255, 255, 255], 'center'); $c->hit($x - $r, $y - $r, 2 * $r, 2 * $r, 'btn:' . $id); } } }