<?phpnamespace App\Form;use App\Core\LyricsDownload;use JumPHP\Gui\Button;use JumPHP\Gui\Label;use JumPHP\Gui\ProgressBar;/** * Form20 of 2001: the lyrics of the song downloaded from the old WinZik site (two tries), with what is going on. * The old site is read from the Internet Archive; the file goes to var/lyr and the lyrics show at once. * * @property Label $attempt * @property Label $artist * @property Label $song * @property Label $action * @property ProgressBar $progress * @property Label $where * @property Button $cancel */final class LyricsForm extends WinZikDialog{ private ?LyricsDownload $download = null; private float $closeIn = -1; protected function loaded(array $params = []): void { $this->closeIn = -1; $this->download = $this->wz->startDownload(); $tag = $this->wz->tag; $this->artist->text = "Nom de l'artiste : " . ($tag->artist !== '' ? $tag->artist : 'N/A'); $this->song->text = 'Nom de la chanson : ' . ($tag->title !== '' ? $tag->title : 'N/A'); if ($this->download === null) { $this->action->text = 'Action en cours : pas de morceau'; } $this->where->text = 'winster.free.fr/LYR/ (archive.org)'; } protected function tick(float $dt): void { parent::tick($dt); $d = $this->download; if ($d === null) { return; } $this->attempt->text = 'Essai n° : ' . $d->attempt; $this->action->text = 'Action en cours : ' . $d->action; $this->progress->value = (int)round($d->progress * 100); if ($d->finished()) { $this->cancel->text = 'Fermer'; if ($d->ok && $this->closeIn < 0) { $this->closeIn = 1.2; // "Telechargement terminer", then the lyrics play } } if ($this->closeIn > 0) { $this->closeIn -= $dt; if ($this->closeIn <= 0) { $this->wz->ui['lyrics']['visible'] = true; $this->close(); } } } public function onCancelClick(Button $sender): void { if ($this->download !== null && !$this->download->finished()) { $this->download->cancel(); // quitte = True } $this->close(); }}