From 5b9bf9bacaa17408367abf69ce7f34fc7a6b995e Mon Sep 17 00:00:00 2001 From: YTBJero Date: Fri, 18 Feb 2022 22:23:00 +0700 Subject: [PATCH] FIx --- .poggit.yml | 2 +- .../Clothes/checkStuff/checkRequirement.php | 4 +- src/TungstenVn/Clothes/form/clothesForm.php | 4 +- src/TungstenVn/Clothes/form/cosplaysForm.php | 2 +- .../libs/jojoe77777/FormAPI/CustomForm.php | 132 ++++++++++++++++++ .../Clothes/libs/jojoe77777/FormAPI/Form.php | 56 ++++++++ .../libs/jojoe77777/FormAPI/FormAPI.php | 40 ++++++ .../libs/jojoe77777/FormAPI/ModalForm.php | 79 +++++++++++ .../libs/jojoe77777/FormAPI/SimpleForm.php | 75 ++++++++++ 9 files changed, 388 insertions(+), 6 deletions(-) create mode 100644 src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/CustomForm.php create mode 100644 src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/Form.php create mode 100644 src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/FormAPI.php create mode 100644 src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/ModalForm.php create mode 100644 src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/SimpleForm.php diff --git a/.poggit.yml b/.poggit.yml index 7e976c5..09bb201 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -8,5 +8,5 @@ projects: icon: icon.png libs: - src: jojoe77777/FormAPI/libFormAPI - version: ^1.3.0 + version: ^1.3 ... diff --git a/src/TungstenVn/Clothes/checkStuff/checkRequirement.php b/src/TungstenVn/Clothes/checkStuff/checkRequirement.php index 7bfcf78..0dcf18c 100644 --- a/src/TungstenVn/Clothes/checkStuff/checkRequirement.php +++ b/src/TungstenVn/Clothes/checkStuff/checkRequirement.php @@ -2,7 +2,7 @@ namespace TungstenVn\Clothes\checkStuff; -use jojoe77777\FormAPI\SimpleForm; +use TungstenVn\Clothes\libs\jojoe77777\FormAPI\SimpleForm; use TungstenVn\Clothes\copyResource\copyResource; use TungstenVn\Clothes\Clothes; @@ -32,4 +32,4 @@ public function checkRequirement() } } } -} +} \ No newline at end of file diff --git a/src/TungstenVn/Clothes/form/clothesForm.php b/src/TungstenVn/Clothes/form/clothesForm.php index c5f1dc3..6fb5b82 100644 --- a/src/TungstenVn/Clothes/form/clothesForm.php +++ b/src/TungstenVn/Clothes/form/clothesForm.php @@ -5,7 +5,7 @@ use pocketmine\player\Player; use TungstenVn\Clothes\Clothes; -use jojoe77777\FormAPI\SimpleForm; +use TungstenVn\Clothes\libs\jojoe77777\FormAPI\SimpleForm; use TungstenVn\Clothes\skinStuff\resetSkin; use TungstenVn\Clothes\skinStuff\setSkin; @@ -114,4 +114,4 @@ public function resetSkin(Player $player) $reset->setSkin($player); } -} +} \ No newline at end of file diff --git a/src/TungstenVn/Clothes/form/cosplaysForm.php b/src/TungstenVn/Clothes/form/cosplaysForm.php index 6d9846d..5172059 100644 --- a/src/TungstenVn/Clothes/form/cosplaysForm.php +++ b/src/TungstenVn/Clothes/form/cosplaysForm.php @@ -5,7 +5,7 @@ use pocketmine\player\Player; use TungstenVn\Clothes\Clothes; -use jojoe77777\FormAPI\SimpleForm; +use TungstenVn\Clothes\libs\jojoe77777\FormAPI\SimpleForm; use TungstenVn\Clothes\skinStuff\resetSkin; use TungstenVn\Clothes\skinStuff\setSkin; diff --git a/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/CustomForm.php b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/CustomForm.php new file mode 100644 index 0000000..5f9d6d4 --- /dev/null +++ b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/CustomForm.php @@ -0,0 +1,132 @@ +data["type"] = "custom_form"; + $this->data["title"] = ""; + $this->data["content"] = []; + } + + public function processData(&$data) : void { + if(is_array($data)) { + $new = []; + foreach ($data as $i => $v) { + $new[$this->labelMap[$i]] = $v; + } + $data = $new; + } + } + + /** + * @param string $title + */ + public function setTitle(string $title) : void { + $this->data["title"] = $title; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @param string $text + * @param string|null $label + */ + public function addLabel(string $text, ?string $label = null) : void { + $this->addContent(["type" => "label", "text" => $text]); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param string $text + * @param bool|null $default + * @param string|null $label + */ + public function addToggle(string $text, bool $default = null, ?string $label = null) : void { + $content = ["type" => "toggle", "text" => $text]; + if($default !== null) { + $content["default"] = $default; + } + $this->addContent($content); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param string $text + * @param int $min + * @param int $max + * @param int $step + * @param int $default + * @param string|null $label + */ + public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : void { + $content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max]; + if($step !== -1) { + $content["step"] = $step; + } + if($default !== -1) { + $content["default"] = $default; + } + $this->addContent($content); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param string $text + * @param array $steps + * @param int $defaultIndex + * @param string|null $label + */ + public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : void { + $content = ["type" => "step_slider", "text" => $text, "steps" => $steps]; + if($defaultIndex !== -1) { + $content["default"] = $defaultIndex; + } + $this->addContent($content); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param string $text + * @param array $options + * @param int $default + * @param string|null $label + */ + public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : void { + $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param string $text + * @param string $placeholder + * @param string $default + * @param string|null $label + */ + public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : void { + $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]); + $this->labelMap[] = $label ?? count($this->labelMap); + } + + /** + * @param array $content + */ + private function addContent(array $content) : void { + $this->data["content"][] = $content; + } + +} diff --git a/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/Form.php b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/Form.php new file mode 100644 index 0000000..7eceb8d --- /dev/null +++ b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/Form.php @@ -0,0 +1,56 @@ +callable = $callable; + } + + /** + * @deprecated + * @see Player::sendForm() + * + * @param Player $player + */ + public function sendToPlayer(Player $player) : void { + $player->sendForm($this); + } + + public function getCallable() : ?callable { + return $this->callable; + } + + public function setCallable(?callable $callable) { + $this->callable = $callable; + } + + public function handleResponse(Player $player, $data) : void { + $this->processData($data); + $callable = $this->getCallable(); + if($callable !== null) { + $callable($player, $data); + } + } + + public function processData(&$data) : void { + } + + public function jsonSerialize(){ + return $this->data; + } +} diff --git a/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/FormAPI.php b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/FormAPI.php new file mode 100644 index 0000000..ac27571 --- /dev/null +++ b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/FormAPI.php @@ -0,0 +1,40 @@ +data["type"] = "modal"; + $this->data["title"] = ""; + $this->data["content"] = $this->content; + $this->data["button1"] = ""; + $this->data["button2"] = ""; + } + + /** + * @param string $title + */ + public function setTitle(string $title) : void { + $this->data["title"] = $title; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @return string + */ + public function getContent() : string { + return $this->data["content"]; + } + + /** + * @param string $content + */ + public function setContent(string $content) : void { + $this->data["content"] = $content; + } + + /** + * @param string $text + */ + public function setButton1(string $text) : void { + $this->data["button1"] = $text; + } + + /** + * @return string + */ + public function getButton1() : string { + return $this->data["button1"]; + } + + /** + * @param string $text + */ + public function setButton2(string $text) : void { + $this->data["button2"] = $text; + } + + /** + * @return string + */ + public function getButton2() : string { + return $this->data["button2"]; + } +} diff --git a/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/SimpleForm.php b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/SimpleForm.php new file mode 100644 index 0000000..6e5d0e8 --- /dev/null +++ b/src/TungstenVn/Clothes/libs/jojoe77777/FormAPI/SimpleForm.php @@ -0,0 +1,75 @@ +data["type"] = "form"; + $this->data["title"] = ""; + $this->data["content"] = $this->content; + } + + public function processData(&$data) : void { + $data = $this->labelMap[$data] ?? null; + } + + /** + * @param string $title + */ + public function setTitle(string $title) : void { + $this->data["title"] = $title; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @return string + */ + public function getContent() : string { + return $this->data["content"]; + } + + /** + * @param string $content + */ + public function setContent(string $content) : void { + $this->data["content"] = $content; + } + + /** + * @param string $text + * @param int $imageType + * @param string $imagePath + * @param string $label + */ + public function addButton(string $text, int $imageType = -1, string $imagePath = "", ?string $label = null) : void { + $content = ["text" => $text]; + if($imageType !== -1) { + $content["image"]["type"] = $imageType === 0 ? "path" : "url"; + $content["image"]["data"] = $imagePath; + } + $this->data["buttons"][] = $content; + $this->labelMap[] = $label ?? count($this->labelMap); + } + +}