'Sac', 'craft' => 'Artisanat', 'body' => 'Corps', 'talents' => 'Talents', 'scanner' => 'Scanner', 'map' => 'Carte', 'journal' => 'Journal']; private const P_SLOTS = ['head' => ['head'], 'torso' => ['under', 'worn'], 'rarm' => ['worn', 'hands'], 'larm' => ['worn', 'hands'], 'rleg' => ['legs', 'feet'], 'lleg' => ['legs', 'feet']]; private const P_THINGS = [ 'water_spring' => 'Source', 'waterfall' => 'Cascade', 'bush_berry' => 'Buisson de baies', 'mushroom' => 'Champignon', 'tree_palm' => 'Palmier (fruits)', 'herb_heal' => 'Herbe cicatrisante', 'herb_fever' => 'Herbe de fièvre', 'reeds_tall' => 'Cannes sucrées', 'palm_coast' => 'Palmier côtier', 'crate' => 'Caisse', 'bones' => 'Ossements', 'tent' => 'Tente', 'hut' => 'Hutte', 'stilt_hut' => 'Case sur pilotis', ]; /** null: the list of the tab; else the row opened (item id, recipe index, part key, log id) */ public ?string $pDetail = null; /** @var array scroll of each page */ private array $pScroll = []; /** the finger down: [hit, y, scroll, dragged] */ private ?array $pPress = null; private float $pContentH = 0.0; private function pKey(): string { return $this->tab . ($this->pDetail !== null ? ':' . $this->pDetail : ''); } /** Phones: false when the screens close. */ private function phoneUpdate(UiInput $in, Game $g, HudData $d): bool { if ($in->back) { if ($this->pDetail !== null) { $this->pDetail = null; return true; } return false; } $key = $this->pKey(); $scroll = $this->pScroll[$key] ?? 0.0; if ($in->up || $in->down) { $scroll += $in->down ? 80 : -80; } $scroll -= $in->wheel * 70; if ($in->click) { $hit = $in->hit; // the bar acts at once; the rows wait for the finger to lift (a drag scrolls instead) if ($hit === 'close') { return false; } if ($hit === 'pback') { $this->pDetail = null; return true; } if ($hit !== null && str_starts_with($hit, 'tab:')) { $this->open(substr($hit, 4)); $this->pDetail = null; return true; } $this->pPress = [$hit, $in->my, $scroll, false]; } elseif ($this->pPress !== null) { if ($in->held) { $dy = $in->my - (float) $this->pPress[1]; if (abs($dy) > 12 || $this->pPress[3]) { $this->pPress[3] = true; $scroll = (float) $this->pPress[2] - $dy; } } else { $press = $this->pPress; $this->pPress = null; if (!$press[3] && $press[0] !== null) { if ($this->phoneAct((string) $press[0], $g, $d) === 'close') { return false; } $key = $this->pKey(); $scroll = $this->pScroll[$key] ?? 0.0; } } } $max = max(0.0, $this->pContentH - (self::P_BOTTOM - self::P_TOP) + 20); $this->pScroll[$key] = max(0.0, min($max, $scroll)); return true; } /** A row tapped. 'close': close the screens (a kit set up on the ground), else 'stay'. */ private function phoneAct(string $hit, Game $g, HudData $d): string { if ($this->gpsClick($hit, $g)) { return 'stay'; } [$what, $arg] = array_pad(explode(':', $hit, 2), 2, ''); switch ($what) { case 'ptalents': $this->open('talents'); return 'stay'; case 'plearn': $this->say($g->talents->learn((string) $this->pDetail)); return 'stay'; case 'ptal': case 'pitem': case 'prec': case 'ppart': case 'plog': $this->pDetail = $arg; return 'stay'; case 'puse': $id = (string) $this->pDetail; if (!$g->inv->has($id)) { return 'stay'; } if (self::isLocalCare($id)) { $this->open('body'); $this->selectTreatment($g, $id); $this->pDetail = array_keys(self::PARTS)[$this->part]; return 'stay'; } if ($g->inv->heldSlot($id) !== null || $g->inv->isWorn($id) !== null) { $this->say($g->unequip($g->inv->heldSlot($id) ?? (string) $g->inv->isWorn($id))); return 'stay'; } $this->say($g->useItem($id)); if ($g->inv->count($id) === 0) { $this->pDetail = null; } return in_array($id, ['campfire_kit', 'shelter_kit', 'trap_snare', 'trap_spike'], true) ? 'close' : 'stay'; case 'pdrop': $id = (string) $this->pDetail; if ($g->dropBag($id, 1) > 0) { $this->say('Tu poses : ' . Items::name($id) . '.'); } if ($g->inv->count($id) === 0) { $this->pDetail = null; foreach ($d->slots as $k => $s) { if ($s === $id) { $d->slots[$k] = null; } } } return 'stay'; case 'pslot': $id = (string) $this->pDetail; $n = (int) $arg; foreach ($d->slots as $k => $s) { if ($s === $id) { $d->slots[$k] = null; } } $d->slots[$n] = $id; $this->say(Items::name($id) . ' → raccourci ' . $n . '.'); return 'stay'; case 'pcraft': $r = $this->recipeList($g)[(int) $this->pDetail] ?? null; if ($r !== null) { $this->say($g->craft($r['id'])); foreach ($this->recipeList($g) as $i => $rr) { if ($rr['id'] === $r['id']) { $this->pDetail = (string) $i; } } } return 'stay'; case 'pcare': $this->say($g->useItem($arg, (string) $this->pDetail)); return 'stay'; case 'pcloth': $this->say($this->toggleClothes($g, $arg)); return 'stay'; case 'ppoint': [$x, $z, $label] = explode('|', $arg) + ['0', '0', '']; $d->pointer = [(float) $x, (float) $z, $label]; $this->say('La boussole montre : ' . $label . '.'); return 'stay'; } return 'stay'; } // ------------------------------------------------------------------------------------------ drawing private function phoneDraw(Canvas $c, Game $g, HudData $d): void { $c->rect(0, 0, Canvas::W, Canvas::H, [8, 12, 18, 245]); // the bar: back or close, the title $detail = $this->pDetail !== null && !in_array($this->tab, ['scanner', 'map'], true); $c->pill(10, 8, 120, 64, [255, 255, 255, 30]); $c->text($detail ? '‹ Retour' : '× Fermer', 70, 26, 18, [255, 255, 255], 'center'); $c->hit(6, 4, 132, 72, $detail ? 'pback' : 'close'); $title = $this->tab === 'map' ? $g->zone->name : (self::TABS[$this->tab] ?? ''); $c->text($title, 560, 24, 22, [255, 214, 140], 'center'); // the tabs: seven big buttons $x = 6.0; foreach (self::P_TABS as $id => $label) { $on = $id === $this->tab; $c->rect($x, 82, 130, 58, $on ? [120, 190, 255, 90] : [255, 255, 255, 18]); if ($on) { $c->rect($x, 136, 130, 4, [150, 210, 255, 240]); } $c->textBox($label, $x, 98, 130, 16, $on ? [255, 255, 255] : [180, 192, 204], 'center'); $c->hit($x, 78, 130, 66, 'tab:' . $id); $x += 136; } $y = self::P_TOP + 6 - ($this->pScroll[$this->pKey()] ?? 0.0); $start = $y; $y = match ($this->tab) { 'inventory' => $this->pDetail === null ? $this->pInventory($c, $g, $d, $y) : $this->pItem($c, $g, $d, $y), 'craft' => $this->pDetail === null ? $this->pCraftList($c, $g, $y) : $this->pRecipe($c, $g, $y), 'body' => $this->pDetail === null ? $this->pBody($c, $g, $y) : $this->pPart($c, $g, $y), 'talents' => $this->pDetail === null ? $this->pTalents($c, $g, $y) : $this->pTalent($c, $g, $y), 'scanner' => $this->pScanner($c, $g, $y), 'map' => $this->pMap($c, $g, $d, $y), default => $this->pDetail === null ? $this->pJournal($c, $g, $y) : $this->pLog($c, $g, $y), }; $this->pContentH = $y - $start; // the content's real height is known now: a page that got shorter (an item used, another tab) keeps a reachable scroll $key = $this->pKey(); $this->pScroll[$key] = max(0.0, min(max(0.0, $this->pContentH - (self::P_BOTTOM - self::P_TOP) + 20), $this->pScroll[$key] ?? 0.0)); if ($this->note !== '' && $this->noteAge < 5) { $lines = array_slice($c->wrap($this->note, 15, 900), 0, 3); $lh = 19 * $c->boost; $h = $lh * count($lines) + 16; $c->rect(0, 720 - $h, 960, $h, [20, 16, 6, 235]); foreach ($lines as $i => $line) { $c->text($line, 24, 720 - $h + 8 + $i * $lh, 15, [255, 226, 160]); } } } /** A big row; returns the y after it. Rows outside the content area are not drawn (no hit either). */ private function pRow(Canvas $c, float $y, string $title, string $sub = '', ?string $hit = null, ?string $icon = null, string $right = '', array $col = [240, 244, 248]): float { $lh = 18 * $c->boost; $subLines = $sub === '' ? [] : array_slice($c->wrap($sub, 14, $icon !== null ? 760 : 840), 0, 3); $h = max(76.0, 22 + 22 * $c->boost + $lh * count($subLines)); if ($y >= self::P_TOP - 1 && $y + $h <= self::P_BOTTOM) { $c->rect(8, $y, 944, $h, [255, 255, 255, $hit !== null ? 20 : 10]); $tx = 24.0; if ($icon !== null) { $c->icon($icon, 20, $y + ($h - 52) / 2, 52); $tx = 88.0; } $c->text($title, $tx, $y + 12, 18, $col); if ($right !== '') { $c->text($right, 900, $y + 12, 16, [200, 214, 226], 'right'); } foreach ($subLines as $i => $line) { $c->text($line, $tx, $y + 14 + 22 * $c->boost + $i * $lh, 14, [160, 174, 188]); } if ($hit !== null) { $c->text('›', 936, $y + $h / 2 - 14, 22, [150, 166, 180], 'right'); $c->hit(8, $y, 944, $h, $hit); } } return $y + $h + 6; } /** A big button row (centred label). */ private function pButton(Canvas $c, float $y, string $label, string $hit, array $col = [120, 190, 255], float $x = 8.0, float $w = 944.0): float { if ($y >= self::P_TOP - 1 && $y + 68 <= self::P_BOTTOM) { $c->rect($x, $y, $w, 68, [$col[0], $col[1], $col[2], 70]); $c->border($x, $y, $w, 68, [$col[0], $col[1], $col[2], 200]); $c->text($label, $x + $w / 2, $y + 22, 18, [255, 255, 255], 'center'); $c->hit($x, $y, $w, 68, $hit); } return $y + 74; } private function pText(Canvas $c, float $y, string $text, float $size = 16, array $col = [226, 232, 240]): float { $lh = $size * 1.3 * $c->boost; foreach ($c->wrap($text, $size, 900) as $line) { if ($y >= self::P_TOP - 1 && $y + $lh <= self::P_BOTTOM) { $c->text($line, 24, $y, $size, $col); } $y += $lh; } return $y + 8; } private function pHeader(Canvas $c, float $y, string $text): float { if ($y >= self::P_TOP - 1 && $y + 36 <= self::P_BOTTOM) { $c->text(mb_strtoupper($text), 24, $y + 8, 14, [255, 204, 110]); } return $y + 40; } // ------------------------------------------------------------------------------------------ the bag private function pInventory(Canvas $c, Game $g, HudData $d, float $y): float { $y = $this->pText($c, $y, sprintf('Charge : %.1f / %.0f kg', $g->inv->weight(), $g->inv->capacity()), 15, [170, 186, 200]); if ($this->items === []) { return $this->pText($c, $y, 'Ton sac est vide.'); } foreach ($this->items as $id) { $it = Items::get($id); $state = []; if ($g->inv->hand === $id) { $state[] = 'main droite'; } if ($g->inv->handLeft === $id) { $state[] = 'main gauche'; } if ($g->inv->isWorn($id) !== null) { $state[] = 'porté'; } if (isset($g->inv->cond[$id])) { $state[] = 'état ' . (int) $g->inv->condition($id) . ' %'; } $f = $g->inv->freshness($id); if ($f !== null && $f < 0.5) { $state[] = $f < 0.2 ? 'presque gâté' : 'pas très frais'; } $sub = (self::KIND[$it['kind']] ?? 'Objet') . ($state !== [] ? ' · ' . implode(', ', $state) : ''); $y = $this->pRow($c, $y, $it['name'], $sub, 'pitem:' . $id, $id, '×' . $g->inv->count($id)); } return $y; } private function pItem(Canvas $c, Game $g, HudData $d, float $y): float { $id = (string) $this->pDetail; if (!$g->inv->has($id)) { $this->pDetail = null; return $y; } $it = Items::get($id); if ($y >= self::P_TOP - 1) { $c->icon($id, 24, $y, 96); } $c->text($it['name'] . ' ×' . $g->inv->count($id), 140, $y + 18, 22, [255, 255, 255]); $c->text((self::KIND[$it['kind']] ?? 'Objet') . sprintf(' · %.2f kg', (float) $it['weight']) . ' · valeur ' . Catalog2::value($id) . ' cr.', 140, $y + 58, 14, [170, 186, 200]); $y += 110; $y = $this->pText($c, $y, (string) $it['desc']); foreach (self::stats($it) as [$label, $value, $good]) { $y = $this->pText($c, $y - 6, $label . ' : ' . $value, 15, $good ? [160, 230, 170] : [255, 160, 140]); } $worn = $g->inv->heldSlot($id) !== null || $g->inv->isWorn($id) !== null; $label = match (true) { $worn => $g->inv->heldSlot($id) !== null ? 'Ranger' : 'Retirer', self::isLocalCare($id) => 'Soigner une partie du corps', $it['kind'] === 'food' => 'Manger', $it['kind'] === 'drink' => 'Boire', $it['kind'] === 'clothing' => 'Enfiler', isset(Chests::KINDS[$id]) => 'Poser devant toi', in_array($it['kind'], ['weapon', 'tool'], true) => 'Prendre en main', default => 'Utiliser', }; $y = $this->pButton($c, $y + 4, $label, 'puse', [110, 200, 140]); $y = $this->pButton($c, $y, 'Poser par terre', 'pdrop', [200, 150, 110]); if ($y >= self::P_TOP - 1 && $y + 68 <= self::P_BOTTOM) { for ($k = 1; $k <= 4; $k++) { $on = ($d->slots[$k] ?? null) === $id; $this->pButton($c, $y, 'Raccourci ' . $k . ($on ? ' ✓' : ''), 'pslot:' . $k, $on ? [255, 196, 80] : [120, 190, 255], 8 + ($k - 1) * 237, 230); } } return $y + 74; } // ------------------------------------------------------------------------------------------ crafting private function pCraftList(Canvas $c, Game $g, float $y): float { $near = $g->nearFire(); $y = $this->pText($c, $y, $near ? 'Un feu est à côté : les recettes de cuisson sont possibles.' : 'Pas de feu à côté : les recettes au feu attendront.', 14, [170, 186, 200]); foreach ($this->recipeList($g) as $i => $r) { $ok = self::can($r, $g, $near); $need = []; foreach ($r['needs'] as $id => $n) { $need[] = $n . ' ' . mb_strtolower(Items::name($id)); } $y = $this->pRow($c, $y, $r['name'], ($ok ? 'Possible · ' : '') . implode(', ', $need), 'prec:' . $i, (string) array_key_first($r['gives']), '', $ok ? [160, 236, 170] : [200, 206, 214]); } return $y; } private function pRecipe(Canvas $c, Game $g, float $y): float { $r = $this->recipeList($g)[(int) $this->pDetail] ?? null; if ($r === null) { $this->pDetail = null; return $y; } $y = $this->pText($c, $y, $r['name'], 22, [255, 255, 255]); $y = $this->pHeader($c, $y, 'Il faut'); foreach ($r['needs'] as $id => $n) { $have = $g->inv->count(Crafting::source($id, $n, $g->inv)); $y = $this->pRow($c, $y, $n . ' ' . Items::name($id), 'Tu en as ' . $have, null, $id, '', $have >= $n ? [160, 236, 170] : [255, 150, 130]); } $tool = Crafting::toolFor($r, $g->inv); if ($tool !== null) { $y = $this->pRow($c, $y, 'Outil : ' . Items::name($tool), $g->inv->has($tool) ? 'Dans ton sac' : 'Il te manque', null, $tool, '', $g->inv->has($tool) ? [160, 236, 170] : [255, 150, 130]); } if ($r['fire']) { $y = $this->pText($c, $y, $g->nearFire() ? 'Près d\'un feu : oui.' : 'Il faut un feu à côté.', 15, $g->nearFire() ? [160, 236, 170] : [255, 150, 130]); } $gives = []; foreach ($r['gives'] as $id => $n) { $gives[] = $n . ' ' . Items::name($id); } $y = $this->pText($c, $y, 'Donne : ' . implode(', ', $gives) . ' · ' . $r['minutes'] . ' min', 15, [200, 214, 226]); return $this->pButton($c, $y + 4, 'Fabriquer', 'pcraft', self::can($r, $g, $g->nearFire()) ? [110, 200, 140] : [120, 130, 140]); } // ------------------------------------------------------------------------------------------ the talents private function pTalents(Canvas $c, Game $g, float $y): float { [$level, $xp, $fill] = TalentsView::levelLine($g); $pts = $g->talents->points(); if ($y >= self::P_TOP - 1 && $y + 64 <= self::P_BOTTOM) { $c->text($level, 24, $y + 4, 22, [255, 214, 140]); $c->rect(24, $y + 40, 600, 12, [255, 255, 255, 30]); $c->rect(24, $y + 40, 600 * $fill, 12, [255, 196, 90]); $c->text($xp, 640, $y + 36, 15, [220, 228, 236]); } $y += 64; $y = $this->pText($c, $y, $pts > 0 ? 'Points à dépenser : ' . $pts . '. Touche un talent pour l\'apprendre.' : 'Aucun point à dépenser : l\'expérience vient des bêtes vaincues.', 15, $pts > 0 ? [140, 235, 160] : [170, 186, 200]); foreach (Talents::BRANCHES as $b => $label) { $y = $this->pHeader($c, $y, $label); foreach (Talents::of($b) as $id) { [, $name, $max, $desc] = Talents::TREE[$id]; $rank = $g->talents->rank($id); $y = $this->pRow($c, $y, $name, $desc, 'ptal:' . $id, null, $rank . ' / ' . $max, $rank > 0 ? [255, 255, 255] : [214, 222, 230]); } } return $y; } private function pTalent(Canvas $c, Game $g, float $y): float { $id = (string) $this->pDetail; if (!isset(Talents::TREE[$id])) { $this->pDetail = null; return $y; } [$branch, $name, $max, $desc] = Talents::TREE[$id]; $rank = $g->talents->rank($id); $y = $this->pHeader($c, $y, Talents::BRANCHES[$branch]); $y = $this->pText($c, $y, $name, 20, [255, 255, 255]); $y = $this->pText($c, $y, $desc, 16); $y = $this->pText($c, $y, 'Rang ' . $rank . ' / ' . $max . ' · points à dépenser : ' . $g->talents->points(), 15, [200, 214, 226]); $why = $g->talents->cannot($id); return $this->pButton($c, $y + 4, $why === null ? 'Apprendre (1 point)' : ($rank >= $max ? 'Talent au plus haut' : 'Pas de point à dépenser'), 'plearn', $why === null ? [110, 200, 140] : [120, 130, 140]); } // ------------------------------------------------------------------------------------------ the body private function pBody(Canvas $c, Game $g, float $y): float { $v = $g->body->vitals(); $y = $this->pHeader($c, $y, 'État'); foreach (Hud::VITALS as $key => [$label, $icon]) { [$fill, $text] = Hud::vital($key, (float) ($v[$key] ?? 0)); $y = $this->pRow($c, $y, $label, '', null, $icon, $text, $fill < 0.25 ? [255, 140, 120] : [240, 244, 248]); } $y = $this->pHeader($c, $y, 'Forme physique'); [$level, $xp] = TalentsView::levelLine($g); $pts = $g->talents->points(); $y = $this->pRow($c, $y, $level, $xp . ($pts > 0 ? ' · ' . $pts . ' point' . ($pts > 1 ? 's' : '') . ' de talent' : ''), 'ptalents', null, '', [255, 214, 140]); foreach (BodyPanel::fitnessRows($g) as [$label, $val, , $value, $trend]) { $y = $this->pRow($c, $y, $label, $trend, null, null, $value, $val > 0.5 ? [150, 230, 160] : ($val < -0.5 ? [255, 150, 120] : [240, 244, 248])); } $conds = $g->body->conditions(); if ($conds !== []) { $y = $this->pHeader($c, $y, 'Troubles'); foreach ($conds as $cond) { $y = $this->pRow($c, $y, $cond['label'], 'Gravité ' . (int) round(100 * $cond['severity']) . ' %', null, null, '', [255, 190, 140]); } } $y = $this->pHeader($c, $y, 'Parties du corps (soins, vêtements)'); foreach (self::PARTS as $part => $label) { $wounds = array_filter($g->body->injuries(), fn (array $w) => $w['part'] === $part); $sub = $wounds === [] ? 'Rien à signaler' : implode(', ', array_map(fn (array $w) => $w['label'] . ($w['treated'] ? ' (soigné)' : ''), $wounds)); $bad = array_filter($wounds, fn (array $w) => !$w['treated']) !== []; $y = $this->pRow($c, $y, $label, $sub, 'ppart:' . $part, null, '', $bad ? [255, 150, 130] : [240, 244, 248]); } return $y; } private function pPart(Canvas $c, Game $g, float $y): float { $part = (string) $this->pDetail; if (!isset(self::PARTS[$part])) { $this->pDetail = null; return $y; } $y = $this->pText($c, $y, self::PARTS[$part], 22, [255, 255, 255]); $wounds = array_filter($g->body->injuries(), fn (array $w) => $w['part'] === $part); $y = $this->pHeader($c, $y, 'Blessures'); if ($wounds === []) { $y = $this->pText($c, $y, 'Aucune blessure ici.', 15, [160, 236, 170]); } foreach ($wounds as $w) { $y = $this->pRow($c, $y, $w['label'], 'Gravité ' . (int) round(100 * $w['severity']) . ' %' . ($w['treated'] ? ' · soignée' : ' · à soigner'), null, null, '', $w['treated'] ? [200, 214, 226] : [255, 150, 130]); } $y = $this->pHeader($c, $y, 'Soins (toucher pour appliquer)'); $cares = $this->cares($g); if ($cares === []) { $y = $this->pText($c, $y, 'Aucun soin dans ton sac : bandages, attelles, cataplasmes se fabriquent (onglet Artisanat).', 15, [170, 186, 200]); } foreach ($cares as $id) { $y = $this->pRow($c, $y, 'Appliquer : ' . Items::name($id), (string) Items::get($id)['desc'], 'pcare:' . $id, $id, '×' . $g->inv->count($id)); } $y = $this->pHeader($c, $y, 'Vêtements de cette partie'); foreach (self::P_SLOTS[$part] as $slot) { $on = $g->inv->$slot; $title = $on !== null ? 'Retirer : ' . $g->inv->label($on) : 'Enfiler (' . mb_strtolower(Inventory::SLOT_LABEL[$slot]) . ')'; $sub = $on !== null ? 'Protège, tient chaud · état ' . (int) $g->inv->condition($on) . ' %' : (BodyPanel::spare($g, $slot) !== null ? 'Le plus chaud de ton sac' : 'Rien de ce genre dans ton sac'); $y = $this->pRow($c, $y, $title, $sub, 'pcloth:' . $slot, $on); } return $y; } // ------------------------------------------------------------------------------------------ scanner, map private function pScanner(Canvas $c, Game $g, float $y): float { if (!$g->inv->has('scanner')) { return $this->pText($c, $y, 'Tu n\'as pas de scanner.'); } $bat = (int) round($g->scanBattery()); $y = $this->pRow($c, $y, 'Batterie ' . $bat . ' %', $this->scanOn ? 'Le radar balaie les environs.' : 'Batterie vide : elle se recharge au soleil.', null, 'scanner', Game::coordText($g->zone->id, $g->x, $g->z)); if ($this->scanOn) { $y = $this->pHeader($c, $y, 'Échos (toucher : la boussole les montre)'); $range = $g->zone->cave ? Game::SCAN_RANGE / 2 : Game::SCAN_RANGE; $echo = []; foreach ($g->zone->thingsNear($g->x, $g->z, $range) as $t) { $cat = match (true) { Chests::is($t) => 'Tes coffres', in_array($t->kind, ['water_spring', 'waterfall'], true) => 'Eau', in_array($t->kind, ['bush_berry', 'mushroom', 'tree_palm', 'herb_heal', 'herb_fever', 'reeds_tall', 'palm_coast'], true) => 'Nourriture, plantes', !empty($t->data['loot']) => 'À fouiller', default => null, }; if ($cat !== null) { $echo[] = [$cat, (string) ($t->data['label'] ?? self::P_THINGS[$t->kind] ?? $t->kind), $t->x, $t->z]; } } foreach ($g->creatures as $cr) { if (Wildlife::dist($g, $cr) < $range && empty($cr->data['companion'])) { $echo[] = [in_array($cr->species, ['grazer', 'bird', 'fish', 'climber'], true) ? 'Gibier' : 'Danger', Wildlife::label($cr->species), $cr->x, $cr->z]; } } foreach ($g->npcs as $n) { if (hypot($n->x - $g->x, $n->z - $g->z) < $range) { $echo[] = [$n->hostile ? 'Danger' : 'Personne', $n->name, $n->x, $n->z]; } } foreach ($g->zone->exits as $e) { $echo[] = ['Passage', $e['label'], $e['x'], $e['z']]; } usort($echo, fn (array $a, array $b) => hypot($a[2] - $g->x, $a[3] - $g->z) <=> hypot($b[2] - $g->x, $b[3] - $g->z)); $seen = []; foreach ($echo as [$cat, $label, $x, $z]) { $k = $cat . $label; if (isset($seen[$k]) || count($seen) >= 14) { continue; } $seen[$k] = true; $dist = (int) round(hypot($x - $g->x, $z - $g->z)); $y = $this->pRow($c, $y, $label, $cat . ' · ' . self::pBearing($g, $x, $z), 'ppoint:' . round($x, 1) . '|' . round($z, 1) . '|' . $label, null, $dist . ' m', $cat === 'Danger' ? [255, 150, 130] : [240, 244, 248]); } } $y = $this->pHeader($c, $y, 'GPS'); $y = $this->pButton($c, $y, 'Marquer ici', 'mark'); foreach ($g->waypoints as $wid => [$wname, $wzone]) { $on = $wid === $g->activeWaypoint; $y = $this->pRow($c, $y, $wname, ($on ? 'Actif · ' : '') . ($wzone === $g->zone->id ? 'dans cette zone' : 'ailleurs : ' . ($g->zone->name !== '' ? $wzone : '')), 'wp:' . $wid, null, (int) round($g->waypointDistance($wid)) . ' m', $on ? [120, 230, 255] : [240, 244, 248]); } return $y; } private static function pBearing(Game $g, float $x, float $z): string { $deg = fmod(Hud::bearing($x - $g->x, $z - $g->z) + 360.0, 360.0); return ['nord', 'nord-est', 'est', 'sud-est', 'sud', 'sud-ouest', 'ouest', 'nord-ouest'][(int) round($deg / 45) % 8]; } private function pMap(Canvas $c, Game $g, HudData $d, float $y): float { $this->pScroll[$this->pKey()] = 0.0; $this->drawMapAt($c, $g, $d, 210.0, self::P_TOP + 4, 540.0); $c->text(sprintf('Exploré %d %%', (int) round(100 * $g->exploredShare())), 24, self::P_TOP + 10, 15, [170, 186, 200]); $c->text('Toi : flèche blanche', 24, self::P_TOP + 40, 14, [230, 236, 242]); $c->text('Objectif : losange', 24, self::P_TOP + 66, 14, [255, 196, 80]); $c->text('Passages, lieux : carrés', 24, self::P_TOP + 92, 14, [120, 220, 240]); return $y; } // ------------------------------------------------------------------------------------------ the journal private function pJournal(Canvas $c, Game $g, float $y): float { $q = $g->quest(); $y = $this->pText($c, $y, 'Chapitre ' . $q['chapter'] . ' — ' . $q['title'], 20, [255, 214, 140]); foreach ($q['goals'] as $goal) { $y = $this->pRow($c, $y, ($goal['done'] ? '✓ ' : '• ') . $goal['text'], '', null, null, '', $goal['done'] ? [150, 166, 180] : [240, 244, 248]); } $y = $this->pHeader($c, $y, 'La navette'); $y = $this->pText($c, $y, Escape::status($g), 15); $y = $this->pHeader($c, $y, Quest::OPTIONAL['title']); foreach ($q['optional'] as $goal) { $y = $this->pRow($c, $y, ($goal['done'] ? '✓ ' : '• ') . $goal['text'], '', null, null, '', $goal['done'] ? [150, 166, 180] : [210, 216, 224]); } $y = $this->pHeader($c, $y, 'Journaux lus'); $any = false; foreach (['pod_log' => 'Journal de la nacelle', 'colony_log' => 'Journal de la mission Halde'] as $log => $title) { if (Quest::done($g, $log)) { $any = true; $y = $this->pRow($c, $y, $title, 'Lire, insérer ses lieux dans le GPS', 'plog:' . $log, $log); } } if (!$any) { $y = $this->pText($c, $y, 'Aucun journal pour l\'instant.', 15, [150, 160, 170]); } return $this->pText($c, $y, sprintf('Jour %d · %d nuit(s) · %d feu(x) · %d bête(s) abattue(s) · %d crédits', $g->day(), (int) ($g->flags['nights'] ?? 0), (int) ($g->flags['fires'] ?? 0), (int) ($g->flags['kills'] ?? 0), $g->inv->count('credit')), 14, [150, 166, 180]); } private function pLog(Canvas $c, Game $g, float $y): float { $log = (string) $this->pDetail; $y = $this->pText($c, $y, $g->logText($log), 16); return $this->pButton($c, $y + 4, 'Insérer dans le GPS', 'gpslog:' . $log); } }