PHP code example of dresnite / easyui

1. Go to this page and download the library: Download dresnite/easyui library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dresnite / easyui example snippets


$form = new SimpleForm("This is the title");
$form->addButton(new Button("Say hi", null, function(Player $player) {
    $player->sendMessage("Hello!");
}));
$player->sendForm($form);

$form = new SimpleForm("This is the title");
$form->addButton(new Button("Press me!", new ButtonIcon("https://introduce-the-image-url.here"), function(Player $player) {
    $player->sendMessage("Hey! Thanks for pressing me :)");
}));
$player->sendForm($form);

new SimpleForm("This is the title", "This is the header text");

$form->setCloseListener(function(Player $player) {
    echo "The form was closed!";
})

$form = new ModalForm("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 :/");
});


$form->setAcceptText("Yes");
$form->setDenyText("Yesn't");

$form = new CustomForm("This is the title!");
$form->addElement("my_text", new Input("This is the input header text!"));

$dropdown = new Dropdown("This is the dropdown header text");
$dropdown->addOption(new Option("broadcast", "Broadcast message"));
$dropdown->addOption(new Option("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");
        }
    }
});

class ExampleForm extends SimpleForm {

    public function __construct() {
        parent::__construct("Form title");
    }

    protected function onCreation(): void {
        $button = new Button("A very very big button");
        $button->setIcon(new ButtonIcon("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 {
    
    public function __construct() {
        parent::__construct("The title", "The content text");
    }

    protected function onAccept(Player $player): void {
        $player->sendMessage("You pressed 'Accept' <3");
    }

    protected function onDeny(Player $player): void {
        $player->sendMessage("You pressed 'Deny' >:(");
    }

}

class ExampleForm extends CustomForm {

    public function __construct() {
        parent::__construct("The title goes here");
    }

    public function onCreation(): void {
        // You can add the elements here
    }

    public function onSubmit(Player $player, FormResponse $response): void {
        // You can modify the response here
    }


}

$player->sendForm(new ExampleForm());