EN
games/rob-revisited / src / Revisited / Ui / Controls.php · commit f9a1307
<?phpnamespace App\Revisited\Ui;/** * The "Commandes" panel: every control of the game, keyboard and mouse, gamepad and touch screen, drawn with key * caps. Opened from the pause menu, with H / F1, and once by itself at the start of a new game. */final class Controls{    /** [keys, what it does]; keys separated by " / " become caps */    public const KEYBOARD = [        ['Z Q S D / ↑ ← ↓ →', 'Marcher, tourner (WASD aussi)'],        ['Souris', 'Regarder : maintenir un clic et glisser'],        ['Maj', 'Courir (maintenu : sprint après 1 s)'],        ['Espace', 'Sauter (en combat : esquiver)'],        ['E / G', 'Action : ramasser, boire… / l\'objet suivant'],        ['F / Clic', 'Attaquer (main droite) : clic sans glisser'],        ['V / Clic D', 'Main gauche : brandir la torche, tenir le bouclier levé'],        ['X', 'Échanger les mains'],        ['C / Ctrl', 'S\'accroupir'],        ['I / K / B / L', 'Sac, artisanat, corps et soins, talents'],        ['Tab / N', 'Scanner (radar, GPS)'],        ['M / J', 'Carte, journal'],        ['T / R', 'Dormir (choisir la durée) / se reposer'],        ['Clic jauge', 'Santé, faim, soif… : les actions utiles'],        ['1 / 2 / 3 / 4', 'Raccourcis rapides'],        ['H / F1', 'Cette aide'],        ['P', 'Pause (Échap : fermer un écran, pause)'],    ];    public const PAD = [        ['Stick G', 'Marcher'],        ['Stick D', 'Regarder'],        ['A', 'Sauter (en combat : esquiver)'],        ['X / clic stick D', 'Action / l\'objet suivant'],        ['RT', 'Attaquer (main droite)'],        ['LT', 'Main gauche : torche, bouclier (maintenu)'],        ['LB', 'Courir, puis sprint'],        ['RB', 'S\'accroupir'],        ['Y', 'Inventaire'],        ['Clic stick G', 'Journal'],        ['Select', 'Carte'],        ['B', 'Fermer, retour'],        ['Start', 'Pause'],    ];    public const TOUCH = [        ['Joystick', 'Marcher (pouce gauche)'],        ['Glisser', 'Regarder (moitié droite)'],        ['ACTION', 'L\'action proposée (» : autre objet)'],        ['SAUT', 'Sauter (en combat : esquiver)'],        ['ATTAQUE', 'Frapper (main droite)'],        ['TORCHE', 'Brandir la torche (PARER : bouclier)'],        ['COURIR', 'Course activée / coupée'],        ['BAS', 'S\'accroupir'],        ['SAC', 'Inventaire et onglets'],        ['RADAR', 'Scanner : radar et bio-scan'],        ['CARTE', 'Carte explorée'],        ['Jauges', 'Touche une jauge : actions utiles'],        ['ESC', 'Pause, fermer'],    ];    /** Draws the panel; $first: the welcome version (shown at a new game). */    public function draw(Canvas $c, bool $touch, bool $first, float $time): void    {        // the foot of the panel: the advice (two lines at most), then the button; on a phone (big text) the panel grows        $foot = 'Survivre : boire, manger, se chauffer, soigner ses blessures. Le scanner, le corps et la carte t\'aident.';        $fit = $c->fit($foot, 13, 856 - 2 * Canvas::PAD, 2);        $lh = max(13.0, $c->minPx / max(0.01, $c->s), 13 * $c->boost);        $footH = $lh * 1.15 * count($fit['lines']);        $label = $touch ? 'Touche l\'écran pour commencer' : 'Entrée, Échap ou clic pour continuer';        $pw = min(856.0, max(300.0, $c->measure($label, 13) + 40));        $ph = max(22.0, $lh + 8);        $bottom = max(686.0, 632 + $footH + 6 + $ph + 6);        $c->rect(0, 0, Canvas::W, Canvas::H, [4, 8, 12, 170]);        $c->panel(28, 34, 904, min(716.0, $bottom) - 34, 232, [255, 196, 80, 220]);        $c->text('Commandes', 52, 48, 28, [255, 255, 255]);        $c->text($first ? 'Rob Calder reprend conscience. Voici comment le guider — ce panneau revient avec H ou F1, et depuis la pause.'            : 'Ce panneau s\'ouvre avec H ou F1, et depuis le menu de pause.', 52, 84, 14, [190, 204, 216]);        $c->line(904, 52, 918, 66, [210, 220, 230], 2);        $c->line(918, 52, 904, 66, [210, 220, 230], 2);        $c->hit(892, 40, 36, 36, 'close');        $cols = [            ['CLAVIER ET SOURIS', self::KEYBOARD, 52.0, 330.0],            ['MANETTE', self::PAD, 398.0, 250.0],            ['ÉCRAN TACTILE', self::TOUCH, 664.0, 250.0],        ];        if ($touch) {            // on a phone (big text) only the touch controls, on the whole width: a keyboard is not there            $cols = [['ÉCRAN TACTILE', self::TOUCH, 52.0, 852.0]];        }        $row = max(26.0, $c->lineH(13, 1.0) + 8);        foreach ($cols as [$title, $rows, $x, $w]) {            $c->text($title, $x, 116, 13, [255, 204, 110]);            $c->rect($x, 134, $w + 4, 1, [255, 255, 255, 40]);            $y = 144.0;            $wide = $title === 'CLAVIER ET SOURIS' || $touch;            foreach ($rows as [$keys, $what]) {                $kx = $x;                foreach (explode(' / ', $keys) as $i => $k) {                    if ($i > 0) {                        $c->text('/', $kx + 2, $y + 4, 12, [130, 144, 158], 'left', false);                        $kx += 12;                    }                    $kx += self::cap($c, $kx, $y, $k) + 4;                }                $tx = (float) max((float) $x + ($wide ? 150.0 : 96.0), $kx + 6.0);                $h = $c->textBox($what, $tx - Canvas::PAD, $y + 3, $x + $w - $tx + 2 * Canvas::PAD, 13, [226, 232, 238], 'left', 2, 1.15);                $y += max($row, $h + 3);            }        }        $c->rect(52, 626, 856, 1, [255, 255, 255, 40]);        $c->textBox($foot, 48, 632, 864, 13, [170, 186, 200], 'left', 2, 1.15);        $blink = 0.65 + 0.35 * sin($time * 4);        $py = min(716.0, $bottom) - $ph - 6;        $c->pill(480 - $pw / 2, $py, $pw, $ph, [255, 196, 80, (int) (200 * $blink)]);        $c->text($label, 480, $py + ($ph - $lh) / 2, 13, [30, 24, 14], 'center', false);        $c->hit(480 - $pw / 2, $py - 4, $pw, $ph + 8, 'close');    }    /** A key cap; returns its width. */    public static function cap(Canvas $c, float $x, float $y, string $k): float    {        $w = max(22.0, $c->measure($k, 12) + 14);        $h = max(20.0, $c->lineH(12, 1.0) + 4);        $c->rect($x, $y + 2, $w, $h + 1, [0, 0, 0, 120]);        $c->rect($x, $y, $w, $h, [226, 230, 236, 235]);        $c->rect($x, $y, $w, 2, [255, 255, 255, 255]);        $c->rect($x, $y + $h - 3, $w, 3, [170, 178, 188, 255]);        $c->box($x, $y, $w, $h);        $c->text($k, $x + $w / 2, $y + ($h - $c->lineH(12, 1.0)) / 2 + 1, 12, [20, 26, 34], 'center', false);        return $w;    }}