PT
apps/winzik / src / Form / SkinForm.php · commit 6576d6f
<?phpnamespace App\Form;use App\Model\Skin;use JumPHP\Gui\Button;use JumPHP\Gui\Label;use JumPHP\Gui\ListBox;/** * Form9 of 2001, the skin viewer: the skins of the application (assets/skins) and the user's (var/skins: a folder * with an INFO.txt and the pictures, as in 2001). A click shows it at once, "Selectionner ce Skin" keeps it, * "Quitter" goes back to the one before. * * @property Button $refresh * @property ListBox $skins * @property Label $info * @property Button $market * @property Button $editor * @property Button $choose * @property Button $quit */final class SkinForm extends WinZikDialog{    /** @var list<Skin> */    private array $list = [];    private string $before = '';    protected function loaded(array $params = []): void    {        $this->before = $this->wz->skin->dir;        $this->onRefreshClick($this->refresh);    }    public function onRefreshClick(Button $sender): void    {        $this->list = $this->wz->skins();        $this->skins->items = array_map(fn (Skin $s) => $s->name, $this->list);        $current = -1;        foreach ($this->list as $i => $skin) {            if (realpath($skin->dir) === realpath($this->wz->skin->dir)) {                $current = $i;            }        }        $this->skins->selected = $current;        $this->info->text = count($this->list) . ' skin(s). Les vôtres : un dossier avec INFO.txt dans ' . $this->wz->storagePath('skins');    }    /** List1_Click: the skin is tried at once. */    public function onSkinsChange(ListBox $sender, int $index, string $item): void    {        if (isset($this->list[$index])) {            $this->wz->useSkin($this->list[$index]->dir);        }    }    public function onSkinsActivate(ListBox $sender, int $index, string $item): void    {        $this->onSkinsChange($sender, $index, $item);        $this->close();    }    public function onChooseClick(Button $sender): void    {        $this->onSkinsChange($this->skins, (int)$this->skins->selected, '');        $this->wz->save();        $this->close();    }    public function onMarketClick(Button $sender): void    {        $this->scenes()->pop();        $this->scenes()->push(MarketForm::class, ['kind' => 'skin']);    }    /** EDT, from the skin chosen in the list. */    public function onEditorClick(Button $sender): void    {        $skin = $this->list[(int)$this->skins->selected] ?? null;        $this->wz->save();        $this->scenes()->switchTo(SkinEditorForm::class, $skin !== null ? ['skin' => $skin->dir] : [], false);    }    public function onQuitClick(Button $sender): void    {        $this->wz->useSkin($this->before);        $this->close();    }}