funo-network/fn.libs.forms

This package is abandoned and no longer maintained. No replacement package was suggested.

https://github.com/FunoNetwork/fn.libs.forms

dev-master 2019-12-25 01:54 UTC

This package is auto-updated.

Last update: 2020-08-25 03:33:04 UTC


README

A form library for PocketMine-MP, inspired by EasyForms, FormAPI and BlockSniper. Better name suggestions are welcome

TODO

  • Add the remaining elements
  • Allow setting a global callback for dropdowns instead of only individual options?

Usage

You can use this library as a virion or a plugin.

Button List Example

$form = new SimpleForm("Servers");

$form->addButton("Hunger Games", function() {
    $player->transfer("hg.example.com");
});

$form->onClose(function() {
    $player->sendMessage("Closed form");
});

$player->sendForm($form);

Modal Form Example

$form = new ModalForm("Reset Account", "Do you wish to delete your account? You will lose all your progress.");
$form->setYesButtonText("Yes");
$form->setNoButtonText("Cancel");
$form->onResponse(function($data) {
    // I cant remember what the data is but yeah
});

Custom Form Example

$form = new CustomForm("Chat Effects");
$form->addLabel("Customize your chat!\n\n");

$dropdown = $form->addDropdown("Chat Colour");
foreach(["Default", "Aqua", "Gold"] as $colour) {
    $dropdown->addOption($colour, (bool) ($session->getPreference("chatColour") == $colour), function() use ($session, $colour) {
        $session->setPreference("chatColour", $colour, false);
    }
}

$form->addToggle("Display rank", (bool) $session->getPreference("displayRank"), function(bool $value) use ($session) {
    $session->setPreference("displayRank", $value, false);
});

$player->sendForm($form);

It is possible to omit the callbacks for toggles so that clicking wont do anything.

Note

Basic support for server settings forms is included. You will have to handle the packets yourself, however.

License

Licensed under the MIT License. See the file named LICENSE for more information.

Copyright (c) 2019 Funo Network.