Java Code Examples for com.badlogic.gdx.scenes.scene2d.Actor#addListener()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Actor#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnBackPressedLmlAttribute.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
                action.consume(actor);
                return true;
            }
            return false;
        }
    });
}
 
Example 2
Source File: OnEnterPressedLmlAttribute.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ENTER) {
                action.consume(actor);
                return true;
            }
            return false;
        }
    });
}
 
Example 3
Source File: TabPane.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public void addTab(Actor header, Actor content) {
    if (listeners.containsKey(header))
        throw new IllegalArgumentException("header already exists");
    headers.add(header);
    contents.add(content);
    super.addActor(header);
    if (selectedIndex == -1)
        setSelectedIndex(0);
    invalidate();

    final int index = headers.size - 1;
    EventListener listener = new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            setSelectedIndex(index);
            event.cancel();
        }
    };
    header.addListener(listener);
    listeners.put(header, listener);
}
 
Example 4
Source File: OnBackPressedLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
                action.consume(actor);
                return true;
            }
            return false;
        }
    });
}
 
Example 5
Source File: OnRightClickLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Params> action = parser.parseAction(rawAttributeData, tmpParams);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new ClickListener(1) {
        @Override
        public void clicked(final InputEvent event, final float x, final float y) {
            tmpParams.actor = actor;
            tmpParams.x = x;
            tmpParams.y = y;
            tmpParams.stageX = event.getStageX();
            tmpParams.stageY = event.getStageY();
            action.consume(tmpParams);
            tmpParams.reset();
        }
    });
}
 
Example 6
Source File: KeyboardFocusChangedLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Params> action = parser.parseAction(rawAttributeData, tmpParams);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new FocusListener() {
        @Override public void keyboardFocusChanged(FocusEvent event, Actor target, boolean focused) {
            if (target == actor) {
                tmpParams.actor = actor;
                tmpParams.focused = focused;
                action.consume(tmpParams);
                tmpParams.reset();
            }
        }
    });
}
 
Example 7
Source File: ScrollFocusCaptureLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, Actor actor, final String rawAttributeData) {
    // Due to ListView tricky structure we should dig a little to get to the scrollable actor
    if (actor instanceof ListView.ListViewTable) {
        actor = ((ListView.ListViewTable) actor).getListView().getScrollPane();
    }

    boolean value = Boolean.parseBoolean(rawAttributeData);
    if (value) {
        // Add scroll focus capture listeners
        actor.addListener(new ScrollFocusCaptureInputListener());
    } else {
        // Remove scroll focus capture listener
        Iterator<EventListener> iterator = actor.getListeners().iterator();
        while (iterator.hasNext()) {
            EventListener listener = iterator.next();
            if (listener instanceof ScrollFocusCaptureInputListener) {
                iterator.remove();
            }
        }
    }
}
 
Example 8
Source File: EditorLogger.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public static void setConsole(Console console) {
	EditorLogger.console = console;
	EditorLogger.console.setDisplayKeyID(Keys.F1);
	console.setMaxEntries(1000);

	final Stage s = (Stage) console.getInputProcessor();
	final Actor actor = s.getActors().items[0];
	actor.addListener(new InputListener() {
		@Override
		public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
			
			if (toActor == null) {
				s.setScrollFocus(null);
			}
		}
	});

	console.setCommandExecutor(new EditorCommandExecutor());
}
 
Example 9
Source File: PatchedOnClickLmlAttribute.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(final InputEvent event, final float x, final float y) {
            if (event.isHandled()) return;
            action.consume(actor);
        }
    });
}
 
Example 10
Source File: DemoScreen.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
private void initDemoChange(InputMultiplexer multiplexer) {
    Stage demoChangeStage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT));
    Actor actor = new Actor();
    actor.setWidth(stage.getWidth());
    actor.setHeight(stage.getHeight());
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            updateCurrentIndex();
            changeDemo();
        }
    });
    demoChangeStage.addActor(actor);
    multiplexer.addProcessor(demoChangeStage);
}
 
Example 11
Source File: OnDoubleClickLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Params> action = parser.parseAction(rawAttributeData, tmpParams);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new ClickListener(0) {
        private boolean firstClickCaught = false;
        private long lastClickTime = 0;

        @Override
        public void clicked(final InputEvent event, final float x, final float y) {
            long currentEventTime = Gdx.input.getCurrentEventTime();
            long deltaTime = currentEventTime - lastClickTime;
            lastClickTime = currentEventTime;

            if (!firstClickCaught) {
                firstClickCaught = true;
            } else {
                if (deltaTime < SECOND_CLICK_TIME) {
                    firstClickCaught = false;

                    tmpParams.actor = actor;
                    tmpParams.x = x;
                    tmpParams.y = y;
                    tmpParams.stageX = event.getStageX();
                    tmpParams.stageY = event.getStageY();
                    action.consume(tmpParams);
                    tmpParams.reset();
                }
            }
        }
    });
}
 
Example 12
Source File: TimeThresholdChangeListenerLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new TimeThresholdChangeListener(0.5f) {
        @Override
        public void onChanged() {
            action.consume(actor);
        }
    });
}
 
Example 13
Source File: PatchedOnClickLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(final InputEvent event, final float x, final float y) {
            if (event.isCancelled() || event.getTarget() != actor) return;
            action.consume(actor);
        }
    });
}