com.badlogic.gdx.scenes.scene2d.InputListener Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.InputListener. 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: 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 #2
Source File: VisCheckBox.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
public VisCheckBox (String text, VisCheckBoxStyle style) {
	super(text, style);
	clearChildren();

	bgImage = new Image(style.checkBackground);
	tickImage = new Image(style.tick);
	imageStackCell = add(imageStack = new Stack(bgImage, tickImage));
	Label label = getLabel();
	add(label).padLeft(5);
	label.setAlignment(Align.left);
	setSize(getPrefWidth(), getPrefHeight());

	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (isDisabled() == false) FocusManager.switchFocus(getStage(), VisCheckBox.this);
			return false;
		}
	});
}
 
Example #3
Source File: Dialogs.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
/**
 * Dialog with given text and single OK button.
 * @param title dialog title
 */
public static VisDialog showOKDialog (Stage stage, String title, String text) {
	final VisDialog dialog = new VisDialog(title);
	dialog.closeOnEscape();
	dialog.text(text);
	dialog.button(ButtonType.OK.getText()).padBottom(3);
	dialog.pack();
	dialog.centerWindow();
	dialog.addListener(new InputListener() {
		@Override
		public boolean keyDown (InputEvent event, int keycode) {
			if (keycode == Keys.ENTER) {
				dialog.fadeOut();
				return true;
			}
			return false;
		}
	});
	stage.addActor(dialog.fadeIn());
	return dialog;
}
 
Example #4
Source File: VisImageTextButton.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
private void init (String text) {
	defaults().space(3);

	image = new Image();
	image.setScaling(Scaling.fit);
	add(image);

	label = new Label(text, new LabelStyle(style.font, style.fontColor));
	label.setAlignment(Align.center);
	add(label);

	setStyle(style);

	setSize(getPrefWidth(), getPrefHeight());

	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (isDisabled() == false) FocusManager.switchFocus(getStage(), VisImageTextButton.this);
			return false;
		}
	});
}
 
Example #5
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 #6
Source File: RestrictBackButton.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void start(Callback callback) {
    Stage stage = resources.get("stage");
    InputListener listener = new InputListener() {
        @Override public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) {
                event.cancel();
                return true;
            }
            return super.keyDown(event, keycode);
        }
    };

    stage.addCaptureListener(listener);
    resources.put("restrictBackButton", listener);
    callback.taskEnded();
}
 
Example #7
Source File: AllowTouchDownToActor.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public final void start(final Callback callback) {
    final Actor target = getTargetActor();
    stage = target.getStage();
    if (stage == null)
        throw new IllegalStateException("actor not on stage!");
    listener = new InputListener() {
        @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!event.getTarget().isDescendantOf(target)) {
                event.cancel();
                return false;
            }
            return true;
        }
    };
    stage.addCaptureListener(listener);
    resources.put("allowTouchDownTo", listener);
    callback.taskEnded();
}
 
Example #8
Source File: VisImageButton.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
private void init () {
	image = new Image();
	image.setScaling(Scaling.fit);
	add(image);
	setSize(getPrefWidth(), getPrefHeight());

	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (isDisabled() == false) FocusManager.switchFocus(getStage(), VisImageButton.this);
			return false;
		}
	});

	updateImage();
}
 
Example #9
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public CustomList(CustomListStyle style, CellRenderer<T> r) {
	selection = new ArraySelection<T>(items);
	selection.setActor(this);
	selection.setRequired(true);

	cellRenderer = r;

	setStyle(style);
	setSize(getPrefWidth(), getPrefHeight());

	addListener(new InputListener() {
		public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
			if (pointer == 0 && button != 0)
				return false;
			if (selection.isDisabled())
				return false;
			CustomList.this.touchDown(y);
			return true;
		}
	});
}
 
Example #10
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 #11
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 6 votes vote down vote up
private void createStatusUIs(Entity[] sortedUnits) {
	for (int i = 0; i < sortedUnits.length; i++) {
		final Entity entity = sortedUnits[i];
		statusUIs[i] = new StatusUI(entity);
		final StatusUI statusui = statusUIs[i];

		statusui.addListener(new InputListener() {
			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
				return true;
			}
		});

		stage.addActor(statusui);
	}
}
 
Example #12
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 6 votes vote down vote up
private void createActionUIs(Entity[] sortedUnits) {
	for (int i = 0; i < sortedUnits.length; i++) {
		if (sortedUnits[i].isPlayerUnit()) {
			final Entity entity = sortedUnits[i];
			actionUIs[i] = new ActionsUI(entity);
			final ActionsUI actionui = actionUIs[i];

			actionui.addListener(new InputListener() {
				@Override
				public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
					return true;
				}
			});

			stage.addActor(actionui);
		}
	}
}
 
Example #13
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 #14
Source File: EditDialog.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public EditDialog(String title, Skin skin) {
		super(title, skin);

		this.skin = skin;

		setResizable(false);
		setKeepWithinStage(false);

		infoLbl = new Label("", skin);
		infoLbl.setWrap(true);
		centerPanel = new Table(skin);
		infoCell = getContentTable().add((Widget) infoLbl).prefWidth(200).height(Gdx.graphics.getHeight() * 0.5f);
		getContentTable().add(new ScrollPane(centerPanel, skin)).maxHeight(Gdx.graphics.getHeight() * 0.8f)
				.maxWidth(Gdx.graphics.getWidth() * 0.7f).minHeight(Gdx.graphics.getHeight() * 0.5f)
				.minWidth(Gdx.graphics.getWidth() * 0.5f);

		getContentTable().setHeight(Gdx.graphics.getHeight() * 0.7f);

		centerPanel.addListener(new InputListener() {
			@Override
			public void enter(InputEvent event, float x, float y, int pointer,
					com.badlogic.gdx.scenes.scene2d.Actor fromActor) {
//				EditorLogger.debug("ENTER - X: " + x + " Y: " + y);
				getStage().setScrollFocus(centerPanel);
			}
		});

		button("OK", true);
		button("Cancel", false);
		// DISABLE the enter key because conflicts when newline in TextFields
//		key(Keys.ENTER, true);
		key(Keys.ESCAPE, false);

		padBottom(10);
		padLeft(10);
		padRight(10);
	}
 
Example #15
Source File: VisTextButton.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void init () {
	style = (VisTextButtonStyle) getStyle();

	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (isDisabled() == false) FocusManager.switchFocus(getStage(), VisTextButton.this);
			return false;
		}
	});
}
 
Example #16
Source File: VisSelectBox.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void init () {
	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			FocusManager.resetFocus(getStage());
			return false;
		}
	});
}
 
Example #17
Source File: HotbarActor.java    From Cubes with MIT License 5 votes vote down vote up
public HotbarActor(PlayerInventory inventory) {
  this.playerInventory = inventory;
  setDrawable(new HotbarDrawable());
  pack();
  addListener(new InputListener() {

    @Override
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
      int slot = (int) Math.floor((event.getStageX() - getX()) / 48f);
      playerInventory.hotbarSelected = slot;
      playerInventory.sync();
      return true;
    }
  });
}
 
Example #18
Source File: VisList.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void init () {
	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			FocusManager.resetFocus(getStage());
			return false;
		}
	});
}
 
Example #19
Source File: VisTree.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void init () {
	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			Focusable focusable = FocusManager.getFocusedWidget();
			if (focusable instanceof Actor == false || isAscendantOf((Actor) focusable) == false) {
				FocusManager.resetFocus(getStage());
			}
			return false;
		}
	});
}
 
Example #20
Source File: StageTest.java    From libgdx-inGameConsole with Apache License 2.0 5 votes vote down vote up
@Override public void create () {
	stage = new Stage();
	Gdx.input.setInputProcessor(stage);

	Skin skin = new Skin(Gdx.files.classpath("tests/test_skin/uiskin.json"));
	console = new GUIConsole(skin);
	console.setCommandExecutor(new MyCommandExecutor());
	console.setSizePercent(100, 50);

	stage.addListener(new InputListener() {
		@Override public boolean keyDown (InputEvent event, int keycode) {
			if (keycode == Input.Keys.F) {
				blink();
				return true;
			} else if (keycode == Input.Keys.TAB) {
				console.select();
				return true;
			} else if (keycode == Input.Keys.D) {
				System.out.println("Console " + (console.isDisabled() ? "enabled" : "disabled"));
				console.setDisabled(!console.isDisabled());
				return true;
			}
			return false;
		}
	});

	image = new Image(new Texture(Gdx.files.classpath("tests/badlogic" + "" + ".jpg")));
	image.setScale(.5f);
	stage.addActor(image);

	selectLabel = new Label("Select", skin);
	deselectLabel = new Label("Deselect", skin);
	stage.addActor(selectLabel);
	stage.addActor(deselectLabel);
	int padding = 25;
	selectLabel.setPosition(Gdx.graphics.getWidth() - selectLabel.getWidth() - deselectLabel.getWidth() - 2 * padding,
		selectLabel.getHeight());
	deselectLabel.setPosition(Gdx.graphics.getWidth() - deselectLabel.getWidth() - padding, deselectLabel.getHeight());
}
 
Example #21
Source File: IconTextButton.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public IconTextButton(Button.ButtonStyle style, String text, FontTBL.BitmapFont font) {
  add(button = new Button(style)).fill(false).pad(2).padLeft(1).padTop(3);
  add(label = new LabelButton(text, font)).grow().spaceLeft(25).row();
  setTouchable(Touchable.enabled);
  addListener(new InputListener() {
    @Override
    public boolean handle(Event e) {
      button.getClickListener().handle(e);
      label.clickListener.handle(e);
      return true;
    }
  });
}
 
Example #22
Source File: AllowTouchInput.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Callback callback) {
    Stage stage = resources.get("stage");
    InputListener listener = resources.getIfExists("restrictAllInput");
    if (listener != null) {
        stage.removeCaptureListener(listener);
        resources.remove("restrictAllInput");
    }
    callback.taskEnded();
}
 
Example #23
Source File: RestrictMenuButton.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Callback callback) {
    Stage stage = resources.get("stage");
    InputListener listener = new InputListener() {
        @Override public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.MENU) {
                event.cancel();
                return true;
            }
            return super.keyDown(event, keycode);
        }
    };
    stage.addCaptureListener(listener);
    resources.put("restrictMenuButton", listener);
    callback.taskEnded();
}
 
Example #24
Source File: WaitKeyUp.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(final Callback callback) {
    stage = resources.get("stage");
    listener = new InputListener() {
        @Override public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == keyCode) {
                stage.removeCaptureListener(this);
                callback.taskEnded();
                return true;
            }
            return super.keyUp(event, keycode);
        }
    };
    stage.addCaptureListener(listener);
}
 
Example #25
Source File: ControllerList.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
protected void setup() {
    // add a listener that selects an item if none is selected when the list gains focus
    addListener(new InputListener() {
        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            if (getSelectedIndex() < 0 && getItems().size > 0)
                setSelectedIndex(0);
        }
    });
}
 
Example #26
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void createPortraits(Entity[] sortedUnits) {
	portraits = new PortraitsUI(sortedUnits);

	portraits.addListener(new InputListener() {
		@Override
		public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
			return true;

		}
	});

	stage.addActor(portraits);
}
 
Example #27
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** If this key is pressed, {@link #result(Object)} is called with the specified object.
 * @see Keys */
public Dialog key (final int keycode, final Object object) {
	addListener(new InputListener() {
		@Override
		public boolean keyDown (InputEvent event, int keycode2) {
			if (keycode == keycode2) {
				result(object);
				if (!cancelHide) hide();
				cancelHide = false;
			}
			return false;
		}
	});
	return this;
}
 
Example #28
Source File: ScrollableTextArea.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected InputListener createInputListener () {
	return new ScrollTextAreaListener();
}
 
Example #29
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected InputListener createInputListener () {
	return new TextAreaListener();
}