Last active
May 10, 2020 13:05
-
-
Save PJZ9n/caa9fec440889bbf5af3ac60fb581b9f to your computer and use it in GitHub Desktop.
pocketmine\form\Formを使ったModalFormの処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace foo\bar; | |
| use pocketmine\form\Form; | |
| use pocketmine\Player; | |
| class ExampleForm implements Form | |
| { | |
| /** | |
| * フォームが送信された時に呼ばれる | |
| * | |
| * @param Player $player | |
| * @param mixed $data | |
| */ | |
| public function handleResponse(Player $player, $data): void | |
| { | |
| if ($data === null) { | |
| //×が押された(または閉じられた)場合 | |
| return;//ここで処理を終了する | |
| } | |
| if ($data === true) { | |
| //button1のボタンが押されたときの処理 | |
| } else if ($data === false) { | |
| //button2のボタンが押されたときの処理 | |
| } | |
| } | |
| /** | |
| * フォームの内容を返す(定義) | |
| * | |
| * @return array | |
| */ | |
| public function jsonSerialize(): array | |
| { | |
| return [ | |
| "type" => "modal", | |
| "title" => "タイトル", | |
| "content" => "選んでください", | |
| "button1" => "ボタン1", | |
| "button2" => "ボタン2", | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment