jaghaimo / stelnet

A collection of intel boards for Starsector.
https://fractalsoftworks.com/forum/index.php?topic=20836
GNU General Public License v3.0
18 stars 15 forks source link

Input fields #68

Closed jaghaimo closed 3 years ago

jaghaimo commented 3 years ago

Proof of concept

package stelnet.board;

import com.fs.starfarer.api.campaign.CustomUIPanelPlugin;
import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
import com.fs.starfarer.api.input.InputEventAPI;
import com.fs.starfarer.api.ui.CustomPanelAPI;
import com.fs.starfarer.api.ui.IntelUIAPI;
import com.fs.starfarer.api.ui.PositionAPI;
import com.fs.starfarer.api.ui.TooltipMakerAPI;
import java.util.List;

public class InputTest extends BaseIntelPlugin {

    public static String input = "";
    public static IntelUIAPI intelUi;

    @Override
    public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
        input = "";
        intelUi = ui;
        ui.updateUIForItem(this);
    }

    @Override
    public void createLargeDescription(CustomPanelAPI panel, float width, float height) {
        final IntelInfoPlugin intel = this;
        CustomPanelAPI newPanel = panel.createCustomPanel(
            width,
            height,
            new CustomUIPanelPlugin() {
                @Override
                public void positionChanged(PositionAPI position) {}

                @Override
                public void renderBelow(float alphaMult) {}

                @Override
                public void render(float alphaMult) {}

                @Override
                public void advance(float amount) {}

                @Override
                public void processInput(List<InputEventAPI> events) {
                    for (InputEventAPI event : events) {
                        if (!event.isKeyDownEvent()) {
                            continue;
                        }
                        InputTest.input += Character.toString(event.getEventChar());
                        event.consume();
                        InputTest.intelUi.updateUIForItem(intel);
                    }
                }
            }
        );
        panel.addComponent(newPanel);
        TooltipMakerAPI tooltip = panel.createUIElement(width, height, false);
        tooltip.addPara("Click on the field to reset content.", 10);
        tooltip.addButton(input, "FAKE_INPUT", width, 20, 0);
        panel.addUIElement(tooltip);
    }

    @Override
    public boolean hasLargeDescription() {
        return true;
    }

    @Override
    public boolean hasSmallDescription() {
        return false;
    }
}
jaghaimo commented 3 years ago

kek

jaghaimo commented 3 years ago

Not needed, Alex will be adding true input forms in 0.95.1.