/GForm

A plugin for pmmp(pocketmine-mp) to create form easily.

Primary LanguagePHP

Documentation | 说明文档 :

About GForm ✋

GForm is a Plugin running on pocketmine MP Can help you quickly create in-game forms. There are three types of forms (for detailed description, click the corresponding form type):point_down:

How to use it ❓

Step one:

You can download releases directly and put the packaged '. Phar' file in your plugins folder and call the API.

Or

Download the source code directly and load it through 'devtools'. This is recommended for developers.

Step two:

Call the plugin in the corresponding file:

$this->Form = $this->getServer()->getPluginManager()->getPlugin("GForm");

Use API

👉 Create custom form:

// $Title is form title,$Callback is a callback function。
$Example = $this->Form->CreateCustomForm(string $Title, ?callable $Callback);

// Show the form to the player after configuration,$player instanceof Player == true。
$Example->sendForm($player);

Form components and application examples:

/*
 * Title: Title - required. You can set the title at the beginning of creation, and use this method as the final title after calling this method.
 * Parameter 1: title content. string
 */
$Example->setTitle = "这是一个标题 | This is a Title";

/*
 * Slider: slider - optional.
 * Parameter 1: label displayed on the slider. string
 * Parameter 2: slider sliding minimum value, default: 0. Int
 * Parameter 3: maximum sliding value of slider, default :100. Int
 * Parameter 4: the default value that the slider first displays, default :0. Int
 */
$Example->setSlider("这是一个滑块 | This is a Slider", 0, 100, 0);

/*
 * Label: Label - optional.
 * Parameter 1: label content. string
 */
$Example->setLabel("这是一个标签 | This is a label");

/*
 * Step bar: step_ Slider - optional.
 * Parameter 1: the label displayed above the step bar. string
 * Parameter 2: an array of information (Only useful for callback). array
 */
$Example->setSteps("这是一个步骤条 | This is a Stepslider", ["1","2","3"]);

/*
 * Toggle: toggle - optional.
 * Parameter 1: display the label in front of the switch. string
 * Parameter 2: display switch status by default, default :false. bool
 */
$Example->setToggle("这是一个开关 | This is a Toggle", false);

/*
 * Drop down menu: dropdown - optional.
 * Parameter 1: the label displayed on the drop-down menu. string
 * Parameter 2: an array containing menu data. array
 */
$Example->setDropdown("这是一个下拉菜单 | This is Dropdown", ["item1","item2"]);

👉 Create modal form

// $Title is form title,$Callback is a callback function。
$Example = $this->Form->CreateModalForm(string $Title, ?callable $Callback);
// Show the form to the player after configuration,$player instanceof Player == true。
$Example->sendForm($player);

Form components and application examples:

/*
 * Title: Title - required.
 * Parameter 1: title content. string
 */
$Example->setTitle = "这是一个标题 | This is a Title";

/*
 * Content: content - required.
 * Parameter 1: the content displayed in the form. string
 */
$Example->setContent("这是内容 | This is Content");

/*
 * Button group: buttons - required.
 * Parameter 1: an array containing the contents of two buttons. array
 */
$Example->setButton(["正确 | Yes", "错误 | No"]);

👉 Create Form form

// $Title is form title,$Callback is a callback function。
$Example = $this->Form->CreateSimpleForm(string $Title, ?callable $Callback);
// Show the form to the player after configuration,$player instanceof Player == true。
$Example->sendForm($player);

Form components and application examples:

/*
 * Title: Title - required.
 * Parameter 1: title content. string
 */
$Example->setTitle = "这是一个标题 | This is a Title";
/*
 * Content: content - required.
 * Parameter 1: the content displayed in the form. string
 */
$Example->setContent("这是内容 | This is Content");

/*
 * Buttons: buttons - at least one, more than one.
 * Parameter 1: label displayed on the button. string
 * Parameter 2: URL or path of the image displayed in front of the button. string
 * Parameter 3: parameter 2 type, optional :URL | path, default :URL. string
 */
$Example->setButton("这是一个按钮 | This is a Button", "https://example.com/example.jpg", "url");

🔧Configuration

✔️ Config_Version: Configuration file version.

Auto_Hide_Error_Form: Failed to create a form. The error form is automatically hidden. default :false.

✔️ Default_Require_Text: The content that is automatically filled when the necessary content is empty.

✔️ Step_Bar_Empty: Fill in the default content when the step bar is empty. Default: ["E", "R", "R", "O", "R"]

✔️ Dropdown_Empty: Fill in the default content when the drop-down menu is empty. Default: ["E", "R", "R", "O", "R"]

✔️ Default_Img: When the image address is empty, the default image. Default: "textures/blocks/redstone_block.png"

✔️ Color_Symbol: Custom color symbol. Default: §

Get table data

Returns an array containing the current table data:

$Data = $Example->getFormData();

About callback function

Believe me, you really need it. 🙉

Callback function example:

// $player is the player object of the operation form.$data Is the data returned after the form is manipulated (the form is closed).
$Example = $this->plugin->Form->CreateCustomForm("Example Form", function (Player $player, $data) {
    $this->plugin->getLogger()->info(var_dump($data));
    // .... What you want to do.
});

Return $data descriptions:

Custom form: Returns an array.

Modal form: Returns a Boolean value.

Form type form: Returns the index of the button to be clicked.

关于 GForm ✋

这是一个运行于PocketMine-MP上的一个插件,可以帮助你快速创建游戏内的表单。包括三种类型的表单(详细说明点击相应表单类型即可):

如何使用 ❓

第一步

你可以直接下载Releases里面已经打包好的.phar文件放到你的 plugins 文件夹内,调用 API 即可。

或者

直接下载源码通过Devtools加载。这对开发者来说是推荐的。

第二步

在相应文件中调用插件:

$this->Form = $this->getServer()->getPluginManager()->getPlugin("GForm");

使用 API

👉创建 Custom 型表单

// $Title 为标题,$Callback 为回调函数。
$Example = $this->Form->CreateCustomForm(string $Title, ?callable $Callback);
// 配置完成后向玩家展示表单,$player instanceof Player == true。
$Example->sendForm($player);

表单组件和应用示例

/*
 * 标题:Title-必须。在刚开始创建的时候就可以设置标题,调用此方法后以此方法为最后标题。
 * 参数1:标题内容。string
 */
$Example->setTitle = "这是一个标题 | This is a Title";

/*
 * 滑块:Slider-可选。
 * 参数1:显示在滑块上的标签。string
 * 参数2:滑块滑动最小值,默认0。int
 * 参数3:滑块滑动最大值,默认100。int
 * 参数4:滑块最先显示的默认值,默认0。int
 */
$Example->setSlider("这是一个滑块 | This is a Slider", 0, 100, 0);

/*
 * 标签:Label-可选。
 * 参数1:标签内容。
 */
$Example->setLabel("这是一个标签 | This is a label");

/*
 * 步骤条:Step_slider-可选。
 * 参数1:展示在步骤条上面的标签。string
 * 参数2:一个信息数组(不会显示在表单里,只有回调时才有用)。array
 */
$Example->setSteps("这是一个步骤条 | This is a Stepslider", ["1","2","3"]);

/*
 * 开关:Toggle-可选。
 * 参数1:展示在开关前的标签。string
 * 参数2:默认展示开关状态,默认false。bool
 */
$Example->setToggle("这是一个开关 | This is a Toggle", false);

/*
 * 下拉菜单:Dropdown-可选。
 * 参数1:展示在下拉菜单上的标签。string
 * 参数2:一个包含菜单数据的数组。array
 */
$Example->setDropdown("这是一个下拉菜单 | This is Dropdown", ["item1","item2"]);

👉 创建 Modal 型表单

// $Title 为标题,$Callback 为回调函数。
$Example = $this->Form->CreateModalForm(string $Title, ?callable $Callback);
// 配置完成后向玩家展示表单,$player instanceof Player == true。
$Example->sendForm($player);

表单组件和应用示例

/*
 * 标题:Title-必须。
 * 参数1:标题内容。string
 */
$Example->setTitle = "这是一个标题 | This is a Title";

/*
 * 内容:Content-必须。
 * 参数1:展示在表单里的内容。string
 */
$Example->setContent("这是内容 | This is Content");

/*
 * 按钮组:Buttons-必须。
 * 参数1:一个包含两个按钮内容的数组。array
 */
$Example->setButton(["正确 | Yes", "错误 | No"]);

👉 创建 Form 型表单

// $Title 为标题,$Callback 为回调函数。
$Example = $this->Form->CreateSimpleForm(string $Title, ?callable $Callback);
// 配置完成后向玩家展示表单,$player instanceof Player == true。
$Example->sendForm($player);

表单组件和应用示例

/*
 * 标题:Title-必须。
 * 参数1:标题内容。string
 */
$Example->setTitle = "这是一个标题 | This is a Title";
/*
 * 内容:Content-必须。
 * 参数1:展示在表单里的内容。string
 */
$Example->setContent("这是内容 | This is Content");

/*
 * 按钮:Buttons-至少一个,可多个。
 * 参数1:显示在按钮上的标签。string
 * 参数2:显示在按钮前的图片的URL或Path。string
 * 参数3:参数2类型,可选url | path,默认url。string
 */
$Example->setButton("这是一个按钮 | This is a Button", "https://example.com/example.jpg", "url");

🔧配置文件

✔️ Config_Version: 配置文件版本。

Auto_Hide_Error_Form: 创建表单失败自动隐藏错误表单。默认关闭。

✔️ Default_Require_Text: 当必要内容为空时自动填充的内容。

✔️ Step_Bar_Empty: 当步骤条为空填充默认内容。默认:["E", "R", "R", "O", "R"]

✔️ Dropdown_Empty: 当下拉菜单为空填充默认内容。默认:["E", "R", "R", "O", "R"]

✔️ Default_Img: 当图片地址为空时默认图片。默认:"textures/blocks/redstone_block.png"

✔️ Color_Symbol: 自定义颜色符。默认:§

获取表格数据

返回一个包含当前表格数据的数组:

$Data = $Example->getFormData();

关于回调函数

没有这个表单就只是展示的东西。你肯定需要它。:hear_no_evil:

回调函数示例

// $player 为操作表单的玩家对象。$data 为操作表单后(表单被关闭)返回的数据。
$Example = $this->plugin->Form->CreateCustomForm("Example Form", function (Player $player, $data) {
    $this->plugin->getLogger()->info(var_dump($data));
    // .... 你想做的事。
});

返回数据$data说明

Custom 型表单:返回一个数组。

Modal 型表单:返回布尔值。

Form 型表单:返回被点击按钮的索引。

表单类型介绍

Custom

Custom1

Custom2

Modal

Modal

Form

Form