IT
apps/winzik / src / Form / PluginsForm.php · commit 6576d6f
<?phpnamespace App\Form;use App\Core\WinZik;use JumPHP\Gui\Button;use JumPHP\Gui\Label;use JumPHP\Gui\ListBox;/** * Form19 of 2001: the plug-ins of the PLUGS folder (Plugins Clavier, Plugins LED). In 2001 each one was a program * talking to WinZik through a socket (port 1984, SDK.txt); here they are part of WinZik, one at a time as then. * * @property Label $state * @property Button $refresh * @property ListBox $plugins * @property Label $about * @property Button $stop * @property Button $start * @property Button $quit */final class PluginsForm extends WinZikDialog{    protected function loaded(array $params = []): void    {        $this->onRefreshClick($this->refresh);    }    public function onRefreshClick(Button $sender): void    {        $this->plugins->items = array_map(fn (array $p) => $p[0], array_values(WinZik::PLUGINS));        $current = array_search($this->wz->plugin(), array_keys(WinZik::PLUGINS), true);        $this->plugins->selected = $current === false ? 0 : (int)$current;        $this->onPluginsChange($this->plugins, (int)$this->plugins->selected, '');    }    protected function tick(float $dt): void    {        parent::tick($dt);        // Timer1: the caption says if a plug-in runs        $on = $this->wz->plugin() !== '';        $this->state->text = $on ? 'PLUGINS : ACTIVE  (' . WinZik::PLUGINS[$this->wz->plugin()][0] . ')' : 'PLUGINS : DESACTIVE';        $this->stop->enabled = $on;    }    public function onPluginsChange(ListBox $sender, int $index, string $item): void    {        $key = array_keys(WinZik::PLUGINS)[$index] ?? null;        $this->about->text = $key === null ? '' : WinZik::PLUGINS[$key][1];    }    public function onPluginsActivate(ListBox $sender, int $index, string $item): void    {        $this->onStartClick($this->start);    }    public function onStartClick(Button $sender): void    {        $key = array_keys(WinZik::PLUGINS)[(int)$this->plugins->selected] ?? '';        $this->wz->usePlugin($key);        $this->wz->save();    }    public function onStopClick(Button $sender): void    {        $this->wz->usePlugin('');        $this->wz->save();    }    public function onQuitClick(Button $sender): void    {        $this->close();    }}