Skip to content

Normal Form

VennV edited this page Jul 29, 2024 · 2 revisions

According to the introduction at HOME, this is the first menu type of the three, and is also the easiest menu to make

Its implementation steps will be as follows:

Example Code:

use pocketmine\player\Player;

use venndev\vformoopapi\Form;
use venndev\vformoopapi\attributes\VForm;
use venndev\vformoopapi\attributes\normal\VButton;
use vennvdev\vformoopapi\utils\TypeForm;

#[VForm(
  title: "Your Menu Title",
  type: TypeForm::NORMAL_FORM,
  content: "Your Menu Content"
)]
final class YourClass extends Form{
  
  public function __construct(Player $player){
   parent::__construct($player);
   $this->setContent("This is example for NormalForm"); //<-- This is the content at 'content' before the class
  }

  #[VButton(
    text: "Your Text", //Button1
    image: "Your Path"    
  )]
  public function YourTextFunction(Player $player, mixed $data) : void{
   $player->sendMessage("You have pressed button 1");
  }

  #[VButton(
    text: "Your Text 2" //button2
  )]
  public function YourFunction(Player $player, mixed $data) : void{
   $player->sendMessage("You pressed button 2");
  }
  
  #[VButton(
    text: "Your Text 3", //button3
    label: "This is button 3's label"
  )]
  public function YourFunction(Player $player, mixed $data) : void{
   $player->sendMessage("You pressed button 3");
  }
  
    protected function onClose(Player $player): void
    {
        $player->sendMessage("You have closed the form");
    }

    // This method is called when the form is submitted
    protected function onCompletion(Player $player, mixed $data): void
    {
        // TODO: Implement onCompletion() method.
    }
}
  • NOTE:
  • You need to do something like Example Code for the menu to work
  • #[VButton()] => Create Button for menu
  • #[VForm()] => Create new menu
  • image => Add your image for button
  • label => Add label for button
Clone this wiki locally