Search in sources :

Example 81 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project skin-composer by raeleus.

the class SplitPaneListeners method splitPaneSplitListener.

public static EventListener splitPaneSplitListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simSplitPane = (DialogSceneComposerModel.SimSplitPane) simActor;
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            getPopTable().key(Keys.ENTER, popTable::hide);
            getPopTable().key(Keys.NUMPAD_ENTER, popTable::hide);
            getPopTable().key(Keys.ESCAPE, popTable::hide);
        }

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            update();
        }

        public void update() {
            var popTable = getPopTable();
            popTable.clearChildren();
            var label = new Label("Split:", skin, "scene-label-colored");
            popTable.add(label).spaceRight(5);
            var splitSpinner = new Spinner(0, .1f, false, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            var splitMinSpinner = new Spinner(0, .1f, false, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            var splitMaxSpinner = new Spinner(0, .1f, false, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            splitSpinner.setName("pad-left");
            splitSpinner.setValue(simSplitPane.split);
            splitSpinner.setMinimum((double) simSplitPane.splitMin);
            splitSpinner.setMaximum((double) simSplitPane.splitMax);
            popTable.add(splitSpinner);
            splitSpinner.getTextField().addListener(ibeamListener);
            splitSpinner.getButtonMinus().addListener(handListener);
            splitSpinner.getButtonPlus().addListener(handListener);
            splitSpinner.addListener(new TextTooltip("The distance in pixels that the user is allowed to scroll beyond the bounds if overscroll is enabled.", tooltipManager, skin, "scene"));
            splitSpinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.splitPaneSplit((float) ((Spinner) actor).getValue());
                }
            });
            popTable.row();
            label = new Label("Split Min:", skin, "scene-label-colored");
            popTable.add(label).spaceRight(5);
            splitMinSpinner.setName("pad-left");
            splitMinSpinner.setValue(simSplitPane.splitMin);
            splitMinSpinner.setMinimum(0);
            splitMinSpinner.setMaximum(simSplitPane.splitMax);
            popTable.add(splitMinSpinner);
            splitMinSpinner.getTextField().addListener(ibeamListener);
            splitMinSpinner.getButtonMinus().addListener(handListener);
            splitMinSpinner.getButtonPlus().addListener(handListener);
            splitMinSpinner.addListener(new TextTooltip("The minimum speed that scroll returns to the widget bounds when overscroll is enabled.", tooltipManager, skin, "scene"));
            splitMinSpinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.splitPaneSplitMin((float) ((Spinner) actor).getValue());
                    splitSpinner.setMinimum(splitMinSpinner.getValue());
                    splitMaxSpinner.setMinimum(splitMinSpinner.getValue());
                }
            });
            popTable.row();
            label = new Label("Split Max:", skin, "scene-label-colored");
            popTable.add(label).spaceRight(5);
            splitMaxSpinner.setName("pad-left");
            splitMaxSpinner.setValue(simSplitPane.splitMax);
            splitMaxSpinner.setMinimum(simSplitPane.splitMin);
            splitMaxSpinner.setMaximum(1);
            popTable.add(splitMaxSpinner);
            splitMaxSpinner.getTextField().addListener(ibeamListener);
            splitMaxSpinner.getButtonMinus().addListener(handListener);
            splitMaxSpinner.getButtonPlus().addListener(handListener);
            splitMaxSpinner.addListener(new TextTooltip("The maximum speed that scroll returns to the widget bounds when overscroll is enabled.", tooltipManager, skin, "scene"));
            splitMaxSpinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.splitPaneSplitMax((float) ((Spinner) actor).getValue());
                    splitSpinner.setMaximum(splitMaxSpinner.getValue());
                    splitMinSpinner.setMaximum(splitMaxSpinner.getValue());
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : PopTableClickListener(com.ray3k.stripe.PopTableClickListener) Spinner(com.ray3k.stripe.Spinner) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) SimSplitPane(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimSplitPane)

Example 82 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project skin-composer by raeleus.

the class BigSpinner method addWidgets.

private void addWidgets() {
    buttonMinus = new Button(style.buttonMinusStyle);
    buttonPlus = new Button(style.buttonPlusStyle);
    textField = new TextField("", style.textFieldStyle) {

        @Override
        public void next(boolean up) {
            if (up) {
                if (transversalPrevious != null) {
                    getStage().setKeyboardFocus(transversalPrevious);
                    if (transversalPrevious instanceof TextField) {
                        ((TextField) transversalPrevious).selectAll();
                    }
                } else {
                    super.next(up);
                }
            } else {
                if (transversalNext != null) {
                    getStage().setKeyboardFocus(transversalNext);
                    if (transversalNext instanceof TextField) {
                        ((TextField) transversalNext).selectAll();
                    }
                } else {
                    super.next(up);
                }
            }
        }
    };
    textField.setAlignment(Align.center);
    textField.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.UP) {
                addValue();
                fire(new ChangeListener.ChangeEvent());
            } else if (keycode == Keys.DOWN) {
                subtractValue();
                fire(new ChangeListener.ChangeEvent());
            }
            return false;
        }
    });
    textField.setTextFieldFilter(new TextField.TextFieldFilter() {

        @Override
        public boolean acceptChar(TextField textField1, char c) {
            boolean returnValue = false;
            if ((c >= 48 && c <= 57) || c == 45 || (!rounding && c == 46)) {
                returnValue = true;
            }
            return returnValue;
        }
    });
    updateText();
    if (null != orientation)
        switch(orientation) {
            case HORIZONTAL:
                add(buttonMinus);
                add(textField).prefWidth(style.textFieldStyle.background.getMinWidth()).minWidth(style.textFieldStyle.background.getMinWidth()).growX();
                add(buttonPlus);
                break;
            case HORIZONTAL_FLIPPED:
                add(buttonPlus);
                add(textField).prefWidth(style.textFieldStyle.background.getMinWidth()).minWidth(style.textFieldStyle.background.getMinWidth()).growX();
                add(buttonMinus);
                break;
            case VERTICAL:
                add(buttonPlus);
                row();
                add(textField).prefWidth(style.textFieldStyle.background.getMinWidth()).minWidth(style.textFieldStyle.background.getMinWidth()).growX();
                row();
                add(buttonMinus);
                break;
            case VERTICAL_FLIPPED:
                add(buttonMinus);
                row();
                add(textField).prefWidth(style.textFieldStyle.background.getMinWidth()).minWidth(style.textFieldStyle.background.getMinWidth()).growX();
                row();
                add(buttonPlus);
                break;
            case RIGHT_STACK:
                {
                    add(textField).prefWidth(style.textFieldStyle.background.getMinWidth()).minWidth(style.textFieldStyle.background.getMinWidth()).growX();
                    VerticalGroup group = new VerticalGroup();
                    add(group);
                    group.addActor(buttonPlus);
                    group.addActor(buttonMinus);
                    break;
                }
            case LEFT_STACK:
                {
                    VerticalGroup group = new VerticalGroup();
                    add(group);
                    group.addActor(buttonPlus);
                    group.addActor(buttonMinus);
                    add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                    break;
                }
            default:
                break;
        }
    buttonMinus.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            subtractValue();
        }
    });
    buttonPlus.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            addValue();
        }
    });
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            BigSpinner parent = (BigSpinner) actor;
            String text = textField.getText();
            if (text.matches("\\-?(\\d+\\.?\\d*)|(\\.\\d+)")) {
                BigDecimal value = new BigDecimal(text);
                if (usingMinimum && value.compareTo(parent.value) < 0) {
                    value = parent.minimum;
                } else if (usingMaximum && value.compareTo(parent.value) > 0) {
                    value = parent.maximum;
                }
                parent.value = value;
            } else {
                if (usingMinimum) {
                    parent.value = parent.minimum;
                } else {
                    parent.value = BigDecimal.valueOf(0);
                }
            }
        }
    });
    textField.addListener(new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            BigSpinner parent = (BigSpinner) textField.getParent();
            if (usingMinimum && parent.value.compareTo(parent.minimum) < 0) {
                parent.value = parent.minimum;
            }
            if (usingMaximum && parent.value.compareTo(parent.maximum) > 0) {
                parent.value = parent.maximum;
            }
            parent.updateText();
        }
    });
    final BigSpinner spinner = this;
    addCaptureListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            event.setTarget(spinner);
        }
    });
}
Also used : BigDecimal(java.math.BigDecimal) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Example 83 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Eidolons by IDemiurge.

the class PlaceTooltip method updateAct.

@Override
public void updateAct(float delta) {
    clearChildren();
    TextureRegion r = TextureCache.getOrCreateR(place.getImagePath());
    ValueContainer container = new ValueContainer(r, place.getName());
    float size = GdxMaster.adjustSize(128);
    if (size < r.getRegionHeight() && size < r.getRegionWidth())
        container.overrideImageSize(size, size);
    add(container);
    setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
    // return ;
    if (place.getRoutes().isEmpty()) {
        return;
    }
    row();
    TablePanel<ValueContainer> routesInfo = new TablePanel<>();
    routesInfo.defaults().space(5);
    add(routesInfo);
    routesInfo.addListener(new ClickListener() {

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            if (toActor == routesInfo)
                return;
            if (toActor == null) {
                if (getWidth() >= x)
                    return;
                if (getWidth() >= y)
                    return;
            }
            if (GdxMaster.getAncestors(toActor).contains(routesInfo))
                return;
            if (!checkActorExitRemoves(toActor))
                return;
            super.exit(event, x, y, pointer, toActor);
            GuiEventManager.trigger(MapEvent.ROUTES_PANEL_HOVER_OFF);
        }
    });
    int i = 0;
    for (Route sub : place.getRoutes()) {
        // reverse pic pos
        TextureRegion tex = TextureCache.getOrCreateR(sub.getImagePath());
        ValueContainer routeInfo = new ValueContainer(tex, sub.getName(), sub.getLength() + " leagues");
        routeInfo.setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
        routesInfo.add(routeInfo).left().padLeft(5).uniform(true, false);
        routeInfo.setUserObject(sub);
        routeInfo.addListener(new ClickListener() {

            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                // getTapCount()
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
                return super.touchDown(event, x, y, pointer, button);
            }

            @Override
            public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
                super.exit(event, x, y, pointer, toActor);
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, null);
            }

            @Override
            public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                super.enter(event, x, y, pointer, fromActor);
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
            }
        });
        if (i % 2 == 1)
            routesInfo.row();
        i++;
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PlaceActor(eidolons.libgdx.screens.map.obj.PlaceActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ValueContainer(eidolons.libgdx.gui.generic.ValueContainer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Route(eidolons.game.module.adventure.map.Route) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TablePanel(eidolons.libgdx.gui.panels.TablePanel)

Example 84 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Eidolons by IDemiurge.

the class EditorParticleMaster method clicked.

public void clicked(int x, int y) {
    String path = EditorMapView.getInstance().getGuiStage().getEmitterPalette().getSelectedEmitterPath();
    EmitterActor last = particles.create(path, x, y);
    last.start();
    stack.push(last);
    final DAY_TIME time = this.time;
    last.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (button == 1) {
                removeEmitter(last, time);
            }
            return super.touchDown(event, x, y, pointer, button);
        }
    });
    MapMaster.addToListMap(map, time, last);
    // layer
    // centering? emitters probably self-center...
    last.setPosition(x, y);
    layers.get(time).addActor(last);
    GuiEventManager.trigger(MapEvent.EMITTER_CREATED, last);
}
Also used : DAY_TIME(main.content.enums.macro.MACRO_CONTENT_CONSTS.DAY_TIME) EmitterActor(eidolons.libgdx.anims.particles.EmitterActor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 85 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Eidolons by IDemiurge.

the class EmitterPalette method init.

public void init() {
    clear();
    setSize(GdxMaster.getWidth() - 300, 256);
    // int columns = (int) (getWidth() / 64);
    defaults().padLeft(200).top().right().width(GdxMaster.getWidth() - 300);
    Map<String, List<File>> presets = new LinkedHashMap<>();
    List<File> subfolders = FileManager.getFilesFromDirectory(PathFinder.getSfxPath(), true);
    subfolders.forEach(file -> {
        if (!file.isDirectory()) {
            MapMaster.addToListMap(presets, "main", file);
        } else
            presets.put(file.getName(), FileManager.getFilesFromDirectory(file.getPath(), false));
    });
    LabelStyle style = StyleHolder.getSizedLabelStyle(FONT.MAIN, 15);
    for (String sub : presets.keySet()) {
        HorizontalFlowGroup table = new HorizontalFlowGroup(0);
        table.setWidth(getWidth() - 100);
        boolean bg = presets.get(sub).size() < 55;
        for (File preset : presets.get(sub)) {
            // textButton?
            ValueContainer label = new ValueContainer(new Label(preset.getName(), style));
            NinePatch patch = NinePatchFactory.getTooltip();
            patch.scale(0.7f, 0.7f);
            if (bg)
                label.setBackground(new NinePatchDrawable(patch));
            label.addListener(new ClickListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) {
                    // EmitterMaster.
                    }
                    EditorManager.setMode(MAP_EDITOR_MOUSE_MODE.EMITTER);
                    if (selectedLabel != null)
                        selectedLabel.setColor(1, 1, 1, 1);
                    if (sub.equals("main"))
                        selected = preset.getName();
                    else
                        selected = StrPathBuilder.build(sub, preset.getName());
                    selectedLabel = label;
                    label.setColor(1, 0.3f, 0.8f, 1);
                    return super.touchDown(event, x, y, pointer, button);
                }
            });
            table.addActor(label);
        }
        addTab(table, sub);
    }
}
Also used : NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) HorizontalFlowGroup(com.kotcrab.vis.ui.layout.HorizontalFlowGroup) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ValueContainer(eidolons.libgdx.gui.generic.ValueContainer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) File(java.io.File) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)358 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)183 Actor (com.badlogic.gdx.scenes.scene2d.Actor)174 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)144 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)110 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)109 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)86 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)53 Stage (com.badlogic.gdx.scenes.scene2d.Stage)49 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)47 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)45 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)35 Texture (com.badlogic.gdx.graphics.Texture)34 Spinner (com.ray3k.stripe.Spinner)32 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)31 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)29 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)26 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)25 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)25 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22