### Form Base Class Custom Callback Handling (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Demonstrates setting and getting the callback function for a form dynamically. This allows for conditional form behavior based on player permissions or other factors. ```php setTitle("Dynamic Menu"); $form->setContent("Select an action:"); $form->addButton("Option A", -1, "", "a"); $form->addButton("Option B", -1, "", "b"); // Set callback later based on conditions if($player->hasPermission("admin")) { $form->setCallable(function(Player $player, $data) { if($data === null) return; $player->sendMessage("Admin selected: $data"); }); } else { $form->setCallable(function(Player $player, $data) { if($data === null) return; $player->sendMessage("Player selected: $data"); }); } // Check if callback exists $callback = $form->getCallable(); if($callback !== null) { $player->sendForm($form); } ?> ``` -------------------------------- ### Create SimpleForm Button Menu in PHP Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Demonstrates how to create a SimpleForm, which presents a menu of clickable buttons to the player. The callback function handles player interaction, receiving the button label or index. It supports images via paths or URLs. ```php sendMessage("You closed the form!"); return; } // $data contains the button label (or index if no label set) switch($data) { case "teleport": $player->sendMessage("Teleporting to spawn..."); break; case "inventory": $player->sendMessage("Opening inventory..."); break; case "settings": $player->sendMessage("Opening settings..."); break; } }); $form->setTitle("Main Menu"); $form->setContent("Welcome! Select an option:"); // Add buttons with labels for easy handling $form->addButton("Teleport to Spawn", SimpleForm::IMAGE_TYPE_PATH, "textures/items/ender_pearl", "teleport"); $form->addButton("View Inventory", SimpleForm::IMAGE_TYPE_URL, "https://example.com/inventory.png", "inventory"); $form->addButton("Settings", -1, "", "settings"); // No image $player->sendForm($form); ``` -------------------------------- ### Including FormAPI as a Virion in Poggit Source: https://github.com/daisukedaisuketeam/formapi/blob/master/README.md This snippet shows how to include the FormAPI library as a virion in your plugin's Poggit configuration. This allows your plugin to use FormAPI's functionalities by referencing it in the `.poggit.yml` file. ```yaml projects: YourPlugin: libs: - src: jojoe77777/FormAPI/libFormAPI version: ^2.1.1 ``` -------------------------------- ### Create ModalForm Yes/No Dialog in PHP Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Shows how to create a ModalForm, a dialog box for confirmation with two buttons. The callback receives a boolean indicating which button was pressed (true for button1, false for button2). ```php sendMessage("Teleporting you home..."); // Perform teleport action } else { // Player clicked button2 (No/Cancel) $player->sendMessage("Teleport cancelled."); } }); $form->setTitle("Confirm Teleport"); $form->setContent("Are you sure you want to teleport home?\nThis will cost 100 coins."); $form->setButton1("Yes, teleport me!"); // Returns true when clicked $form->setButton2("No, cancel"); // Returns false when clicked $player->sendForm($form); ``` -------------------------------- ### Integrate FormAPI into PocketMine-MP Plugin Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Demonstrates how to implement SimpleForm, CustomForm, and ModalForm within a PocketMine-MP plugin class. It includes command handling and callback logic for processing user input from various form types. ```php sendMessage("This command can only be used in-game!"); return true; } switch($command->getName()) { case "menu": $this->openMainMenu($sender); return true; case "settings": $this->openSettingsForm($sender); return true; } return false; } private function openMainMenu(Player $player): void { $form = new SimpleForm(function(Player $player, $data) { if($data === null) return; switch($data) { case "settings": $this->openSettingsForm($player); break; case "teleport": $this->confirmTeleport($player); break; } }); $form->setTitle("Main Menu"); $form->setContent("Welcome, " . $player->getName() . "!"); $form->addButton("Settings", SimpleForm::IMAGE_TYPE_PATH, "textures/ui/settings_glyph_color_2x", "settings"); $form->addButton("Teleport Home", SimpleForm::IMAGE_TYPE_PATH, "textures/items/ender_pearl", "teleport"); $player->sendForm($form); } private function openSettingsForm(Player $player): void { $form = new CustomForm(function(Player $player, ?array $data) { if($data === null) { $player->sendMessage("Settings cancelled."); return; } $player->sendMessage("Settings saved!"); $player->sendMessage("Nickname: " . $data["nickname"]); $player->sendMessage("Particles: " . ($data["particles"] ? "On" : "Off")); $player->sendMessage("Chat opacity: " . $data["opacity"] . "%"); }); $form->setTitle("Player Settings"); $form->addInput("Nickname:", "Enter nickname", $player->getName(), "nickname"); $form->addToggle("Show Particles", true, "particles"); $form->addSlider("Chat Opacity", 0, 100, 10, 100, "opacity"); $player->sendForm($form); } private function confirmTeleport(Player $player): void { $form = new ModalForm(function(Player $player, bool $data) { if($data) { $player->sendMessage("Teleporting home..."); } else { $player->sendMessage("Teleport cancelled."); } }); $form->setTitle("Confirm Teleport"); $form->setContent("Are you sure you want to teleport home?"); $form->setButton1("Yes"); $form->setButton2("No"); $player->sendForm($form); } } ``` -------------------------------- ### Create CustomForm Input Form in PHP Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Illustrates creating a CustomForm for complex input, supporting various elements like text fields, toggles, sliders, dropdowns, and step sliders. The callback receives an associative array of user responses, keyed by the element labels. ```php sendMessage("Form cancelled!"); return; } // Access values by their labels $nickname = $data["nickname"]; // string $pvpEnabled = $data["pvp"]; // bool $flySpeed = $data["fly_speed"]; // int/float $difficulty = $data["difficulty"]; // int (index) $gameMode = $data["gamemode"]; // int (index) $player->sendMessage("Settings saved!"); $player->sendMessage("Nickname: " . $nickname); $player->sendMessage("PVP: " . ($pvpEnabled ? "Enabled" : "Disabled")); $player->sendMessage("Fly Speed: " . $flySpeed); }); $form->setTitle("Player Settings"); // Add a text label (informational only) $form->addLabel("Configure your player settings below:", "info_label"); // Add text input with placeholder and default value $form->addInput("Enter your nickname:", "Type here...", $player->getName(), "nickname"); // Add toggle switch with default value $form->addToggle("Enable PVP", true, "pvp"); // Add slider with min, max, step, and default $form->addSlider("Fly Speed", 1, 10, 1, 5, "fly_speed"); // Add dropdown with options $form->addDropdown("Select Difficulty", ["Peaceful", "Easy", "Normal", "Hard"], 2, "difficulty"); // Add step slider (discrete steps) $form->addStepSlider("Game Mode", ["Survival", "Creative", "Adventure", "Spectator"], 0, "gamemode"); $player->sendForm($form); ``` -------------------------------- ### Form Base Class - Callback Management Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Methods for managing dynamic callback functions for form submissions. ```APIDOC ## METHOD Form::setCallable / Form::getCallable ### Description Allows dynamic assignment and retrieval of the callback function executed when a player interacts with the form. ### Method PHP Method ### Parameters - **callable** (callable) - Required - The function to execute upon form submission, receiving (Player $player, $data). ### Request Example $form->setCallable(function(Player $player, $data) { $player->sendMessage("Selected: " . $data); }); ### Response - **callable|null** - Returns the currently assigned callback function or null if none is set. ``` -------------------------------- ### SimpleForm::addButton Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a button to a SimpleForm instance with optional image support and custom data identifiers. ```APIDOC ## METHOD SimpleForm::addButton ### Description Adds a clickable button to a SimpleForm menu. Supports optional icons from local texture paths or URLs. ### Method PHP Method ### Parameters - **text** (string) - Required - The label displayed on the button. - **imageType** (int) - Optional - The type of image (SimpleForm::IMAGE_TYPE_PATH or SimpleForm::IMAGE_TYPE_URL). Use -1 for no image. - **imagePath** (string) - Optional - The path or URL to the image resource. - **label** (string) - Optional - A custom identifier returned in the callback data. ### Request Example $form->addButton("Shop", SimpleForm::IMAGE_TYPE_PATH, "textures/items/emerald", "shop"); ### Response - **void** - Updates the internal button list of the form instance. ``` -------------------------------- ### Add Menu Button with Image to SimpleForm (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a clickable button to a SimpleForm menu, supporting local texture paths or URLs for icons. The callback receives a data identifier or index. ```php sendMessage("Opening shop..."); break; case "warps": $player->sendMessage("Opening warps menu..."); break; case "kit": $player->sendMessage("Selecting kit..."); break; case 3: // No label set, returns index $player->sendMessage("Opening help..."); break; } }); $form->setTitle("Server Menu"); $form->setContent("Choose an option:"); // Button with local texture path $form->addButton("Shop", SimpleForm::IMAGE_TYPE_PATH, "textures/items/emerald", "shop"); // Button with URL image $form->addButton("Warps", SimpleForm::IMAGE_TYPE_URL, "https://example.com/warp-icon.png", "warps"); // Button without image (use -1 for imageType) $form->addButton("Select Kit", -1, "", "kit"); // Button without label (callback receives index instead) $form->addButton("Help"); $player->sendForm($form); ?> ``` -------------------------------- ### Add Selection Dropdown using CustomForm::addDropdown (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a dropdown selection menu with predefined options. Returns the selected index (integer) of the option. The actual option can be retrieved using this index on the provided array. ```php sendMessage("Selected world: " . $worldOptions[$worldIndex]); $player->sendMessage("Selected rank: " . $rankOptions[$rankIndex]); }); $form->setTitle("Selection Menu"); // Dropdown without default (defaults to first option) $form->addDropdown("Select World:", ["Overworld", "Nether", "End"], null, "world"); // Dropdown with default selection (index 2 = "MVP") $form->addDropdown("Select Rank:", ["Member", "VIP", "MVP", "Admin"], 2, "rank"); $player->sendForm($form); ``` -------------------------------- ### Add Discrete Step Slider using CustomForm::addStepSlider (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a slider that snaps to predefined text options. Returns the selected index (integer) of the option. Similar to dropdown, the actual option can be retrieved using this index. ```php sendMessage("Graphics: " . $qualities[$qualityIndex]); $player->sendMessage("Time of day: " . $times[$timeIndex]); }); $form->setTitle("Graphics Settings"); // Step slider without default (defaults to first step) $form->addStepSlider("Graphics Quality:", ["Low", "Medium", "High", "Ultra"], -1, "quality"); // Step slider with default index (2 = "Noon") $form->addStepSlider("Time of Day:", ["Dawn", "Morning", "Noon", "Evening", "Night"], 2, "time"); $player->sendForm($form); ``` -------------------------------- ### Add Numeric Slider using CustomForm::addSlider (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a numeric slider with configurable minimum, maximum, step increment, and default value. The returned value is an integer representing the selected number. ```php sendMessage("Volume: $volume%"); $player->sendMessage("Effect radius: $radius blocks"); $player->sendMessage("Max health set to: $health"); }); $form->setTitle("Game Settings"); // Basic slider with just min and max $form->addSlider("Volume", 0, 100, -1, -1, "volume"); // Slider with step increment $form->addSlider("Effect Radius", 1, 50, 5, -1, "radius"); // Slider with step and default value $form->addSlider("Max Health", 1, 20, 1, 20, "health"); $player->sendForm($form); ``` -------------------------------- ### Add Text Input Field using CustomForm::addInput (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds a text input field to a custom form. Supports placeholder text and default values. The input value is returned as a string. ```php sendMessage("Sending '$message' to $targetPlayer (Reason: $reason)"); }); $form->setTitle("Send Message"); // Basic input with just label $form->addInput("Target Player:", "", null, "target"); // Input with placeholder $form->addInput("Message:", "Enter your message here...", null, "message"); // Input with placeholder and default value $form->addInput("Reason:", "Optional reason", "General", "reason"); $player->sendForm($form); ``` -------------------------------- ### Add Boolean Toggle Switch using CustomForm::addToggle (PHP) Source: https://context7.com/daisukedaisuketeam/formapi/llms.txt Adds an on/off toggle switch to a custom form. Returns a boolean value (true for on, false for off) in the response. It can have a default value set to true or false. ```php setFlying(true); $player->sendMessage("Flight enabled!"); } if($data["god_mode"]) { $player->sendMessage("God mode activated!"); } if($data["invisible"]) { $player->sendMessage("You are now invisible!"); } }); $form->setTitle("Player Abilities"); // Toggle without default (defaults to false) $form->addToggle("Enable Flight", null, "fly"); // Toggle with default value set to true $form->addToggle("God Mode", true, "god_mode"); // Toggle with default value set to false $form->addToggle("Invisibility", false, "invisible"); $player->sendForm($form); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.