inotflying / VPacks

Generate resource-pack content for your plugin from items to UIs!
MIT License
63 stars 7 forks source link

how can i send the custom form to the player? #5

Open xxzleonardozxx opened 1 year ago

xxzleonardozxx commented 1 year ago

in the example there is FormBuilder but not in the plugin, there is $originalform but the code does not mention it, tried sending with formapi, nothing custom works.

static function getnewaForm(Player $player):void
    {
        $form = new SimpleForm(function (Player $player, $data){

        });

        $i = 0;
        while ($i < 9){
            $form->addButton("Button ID: $i", 0, "textures/items/apple");
            $i++;
        }
        $content = CustomUILoader::getContent();
        $style = $content->getUI()->getJsonUIs()->createSimpleFromStyle();
        $title = $style->addPanel("title")
            ->layer(5)
            ->size(new Size("100%", "10px"))
            ->anchor(Anchor::TOP_RIGHT())
            ->in(fn($elem) => $elem->addLabel("text")
                ->text(ScreenElement::getTitleBinding())
                ->fontType(FontType::MINECRAFTTEN())
                ->textAlignment(TextAlignment::CENTER())
                ->fontScaleFactor(2)
                ->anchor(Anchor::TOP_MIDDLE())
            )
            ->in(fn($elem) => $elem->addExtends("close_button", "common.close_button")->anchor(Anchor::TOP_RIGHT()));

        $buttonTemplate = $style->addStackPanel("gridded_button", Orientation::VERTICAL())
            ->anchor(Anchor::TOP_RIGHT())
            ->size(new Size("90px", "90px"))
            ->in(fn($elem) => $elem->addImage("image")
                ->size(new Size("45px", "45px"))
                ->layer(2)
                ->binding(DataBinding::overrideFromCollection(
                    SimpleFormStyle::getFormButtons(),
                    SimpleFormStyle::getButtonTextureBinding(),
                    ImageElement::getTextureBinding())
                )
                ->binding(DataBinding::overrideFromCollection(
                    SimpleFormStyle::getFormButtons(),
                    SimpleFormStyle::getButtonTextureFSBinding(),
                    ImageElement::getTextureFSBinding()
                ))
            )
            ->in(fn($elem) => $elem->addExtends("real_button", "common_buttons.light_text_button")
                ->anchor(Anchor::TOP_LEFT())
                ->size(new Size("45px", "20px"))
                ->setVar('pressed_button_name', 'button.form_button_click')
                ->setVar('border_visible', false)
                ->setVar('button_text', SimpleFormStyle::getButtonTextBinding())
                ->setVar('button_text_binding_type', BindingType::COLLECTION())
                ->setVar('button_text_grid_collection_name', SimpleFormStyle::getFormButtons())
                ->setVar('button_text_max_size', new Size("100%", "20px"))
                ->binding(DataBinding::collectionDetails(SimpleFormStyle::getFormButtons()))
            );

        $viewport = $style->addGrid("scrolling_view")
            ->anchor(Anchor::TOP_RIGHT())
            ->size(new Size("100%", "100%c"))
            ->offset(new Offset("5px", "5px"))
            ->gridItemTemplate($buttonTemplate->getId())
            ->gridRescalingType(Orientation::HORIZONTAL())
            ->collectionName(SimpleFormStyle::getFormButtons())
            ->binding(DataBinding::override(SimpleFormStyle::getButtonsLengthBinding(), GridElement::getMaximumGridItemsBinding()));

        $contents = $style->addExtends("contents", "common.scrolling_panel")
            ->anchor(Anchor::CENTER())
            ->size(new Size("100%", "100%"))
            ->offset(new Offset("0", "-8"))
            ->setVar("show_background", false)
            ->setVar("scrolling_content", $viewport->getId())
            ->setVar("scroll_size", new Size("5px", "100% - 20px"))
            ->setVar("scrolling_pane_size", new Size("100%", "100% - 20px"));

        $root = $style->addStackPanel($style->getRootName(), Orientation::VERTICAL())
            ->size(new Size("100% - 50px", "100% - 20px"));
        $root->addExtends("title", $title->getId());
        $root->addPanel("padding")->size(new Size("100%", "30px"));
        $root->addExtends("contents", $contents->getId());

        $style->setRootElement($root);
        $decorator =  $style->getDecorator();
        $player->sendForm($decorator->decorate($form));
    }
galaxytwenty commented 1 year ago

Same question here !