EasyUI is an intuitive and easy-to-use form library for PocketMine-MP. Designed to let you focus on your project and not on how the library works.
You can download the virion in Poggit.
All the closures passed to EasyUI classes must declare a variable of the class Player as first and only argument, except for the CustomForm submit listener, which also requires FormResponse as second parameter.
Creating a form with a button without an icon:
$form = newSimpleForm("This is the title");
$form->addButton(newButton("Say hi", null, function(Player$player) {
$player->sendMessage("Hello!");
}));
$player->sendForm($form);Creating a form with a button with an icon:
$form = newSimpleForm("This is the title");
$form->addButton(newButton("Press me!", newButtonIcon("https://introduce-the-image-url.here"), function(Player$player) {
$player->sendMessage("Hey! Thanks for pressing me :)");
}));
$player->sendForm($form);Creating a form with a header text (optional):
newSimpleForm("This is the title", "This is the header text");Controlling what happens when a form closes (optional):
$form->setCloseListener(function(Player$player) {
echo"The form was closed!";
})Creating a modal form and handling what happens when the player presses "accept" or "deny":
$form = newModalForm("The title goes here!", "Do you want this plugin to save you a lot of time?");
$form->setAcceptListener(function(Player$player) {
$player->sendMessage("Great! Keep building good software");
});
$form->setDenyListener(function(Player$player) {
$player->sendMessage("Whatever :/");
});You can also change the text of the buttons:
$form->setAcceptText("Yes");
$form->setDenyText("Yesn't");Creating a custom form with an input and a dropdown
$form = newCustomForm("This is the title!");
$form->addElement("my_text", newInput("This is the input header text!"));
$dropdown = newDropdown("This is the dropdown header text");
$dropdown->addOption(newOption("broadcast", "Broadcast message"));
$dropdown->addOption(newOption("send_to_myself", "Send message to myself"));
$form->addElement("what_to_do", $dropdown);
$form->setSubmitListener(function(Player$player, FormResponse$response) {
$submittedText = $response->getInputSubmittedText("my_text");
$submittedOption = $response->getDropdownSubmittedOptionId("what_to_do");
if($submittedOption === "send_to_myself") {
$player->sendMessage($submittedText);
} elseif($submittedOption === "broadcast") {
foreach($player->getServer()->getOnlinePlayers() as$onlinePlayer) {
$onlinePlayer->sendMessage("[BROADCAST] $submittedText");
}
}
});In some cases, the forms are huge and mess up the code. In those cases, you can use a more object oriented approach to keep the code as clean as possible.
class ExampleForm extends SimpleForm {
publicfunction__construct() {
parent::__construct("Form title");
}
protectedfunctiononCreation(): void {
$button = newButton("A very very big button");
$button->setIcon(newButtonIcon("https://a-cool-url.i.think"));
$button->setSubmitListener(function(Player$player) {
$player->sendMessage("Making this form was so easy!");
});
$this->addButton($button);
}
}class ExampleForm extends ModalForm {
publicfunction__construct() {
parent::__construct("The title", "The content text");
}
protectedfunctiononAccept(Player$player): void {
$player->sendMessage("You pressed 'Accept' <3");
}
protectedfunctiononDeny(Player$player): void {
$player->sendMessage("You pressed 'Deny' >:(");
}
}NOTE: onCreation() is also available on ModalForms.
class ExampleForm extends CustomForm {
publicfunction__construct() {
parent::__construct("The title goes here");
}
publicfunctiononCreation(): void {
// You can add the elements here
}
publicfunctiononSubmit(Player$player, FormResponse$response): void {
// You can modify the response here
}
}Then you can send the forms as you normally would with:
$player->sendForm(newExampleForm());