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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.EventListener. 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: 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 #2
Source File: AboutModActivity.java    From ingress-apk-mod with Apache License 2.0 6 votes vote down vote up
public TextButton addButton(String name, String value, EventListener listener) {
    if (buttonsTable == null) {
        add(buttonsTable = new Table()).colspan(2).expandX().fillX().padBottom(8);
    }

    buttonsTable.row();
    if (name == null) {
        buttonsTable.add().expandX();
    } else {
        buttonsTable.add(new Label(name, smallWhite)).expandX().right().padRight(12);
    }

    TextButton button = new TextButton(value, skin);
    if (listener != null) {
        button.addListener(listener);
    }
    buttonsTable.add(button).width(Value.percentWidth(0.5F)).right().padRight(8);
    buttons.add(button);

    return button;
}
 
Example #3
Source File: DropDownSetting.java    From Cubes with MIT License 6 votes vote down vote up
@Override
public Actor getActor(final String settingName, VisualSettingManager visualSettingManager) {
  final SelectBox<String> selectBox = new SelectBox<String>(visualSettingManager.getSkin()) {
    @Override
    protected String toString(String s) {
      return Settings.getLocalisedSettingName(settingName + "." + s);
    }
  };
  selectBox.setItems(options);
  selectBox.setSelected(selected);
  selectBox.addListener(new EventListener() {
    @Override
    public boolean handle(Event event) {
      if (!(event instanceof SettingsMenu.SaveEvent)) return false;
      set(selectBox.getSelected());
      return true;
    }
  });
  return selectBox;
}
 
Example #4
Source File: ServerRunningMenu.java    From Cubes with MIT License 6 votes vote down vote up
public ServerRunningMenu(Save save, int port) {
  super(Localization.get("menu.general.loading"), Localization.get("menu.server.stop"));
  this.save = save;
  this.port = port;

  addButtonListener(new EventListener() {
    @Override
    public boolean handle(Event event) {
      if (!(event instanceof ChangeListener.ChangeEvent)) return false;
      try {
        Adapter.gotoMainMenu();
      } catch (StopLoopException ignored) {
      }
      return true;
    }
  });
}
 
Example #5
Source File: FlopsyScreen.java    From flopsydroid with Apache License 2.0 6 votes vote down vote up
public FlopsyScreen(FlopsyDroidGame game, OnGlobalListener listener) {
    mStage = new Stage();

    mGlobalListener = listener;

    game.getAssetManager().load("flopsy.sprites", TextureAtlas.class);
    game.getAssetManager().finishLoading();
    mTextureAtlas = game.getAssetManager().get("flopsy.sprites", TextureAtlas.class);

    mLabelStyle = new Label.LabelStyle();
    mLabelStyle.font = new BitmapFont(Gdx.files.internal("flappyfont.fnt"),
            Gdx.files.internal("flappyfont.png"), false);

    mStage.addListener(new EventListener() {
        @Override
        public boolean handle(Event event) {

            if(event.getTarget().equals(mAndy)) {
                mGround.onDroidCollision();
                return true;
            }

            return false;
        }
    });
}
 
Example #6
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 #7
Source File: DelegateInputEventsLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, LmlTag tag, final Actor actor, String rawAttributeData) {
    final String id = parser.parseString(rawAttributeData);
    // Post for one frame to let the layout to be fully parsed (target actor may be parsed after this attribute).
    actor.addAction(Actions.run(new Runnable() {
        @Override
        public void run() {
            final Actor targetActor = parser.getActorsMappedByIds().get(id);
            if (targetActor == null) {
                parser.throwErrorIfStrict("Cannot find actor for ID: " + id);
                return;
            }

            actor.addListener(new EventListener() {
                @Override
                public boolean handle(Event event) {
                    if (event instanceof InputEvent) {
                        return targetActor.notify(event, false);
                    }
                    return false;
                }
            });
        }
    }));
}
 
Example #8
Source File: AllowCloseWindows.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");
    EventListener listener = resources.getIfExists("restrictCloseWindowsListener");
    if (listener != null) {
        stage.removeCaptureListener(listener);
    }
    if (windowClass == null) {
        callback.taskEnded();
        return;
    }
    listener = new WindowListener() {
        @Override protected void hide(WindowEvent event) {
            if (!windowClass.isInstance(event.getWindow())) {
                event.cancel();
            }
        }
    };
    stage.addCaptureListener(listener);
    resources.put("restrictCloseWindowsListener", listener);
    callback.taskEnded();
}
 
Example #9
Source File: SpawnController.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void place(Creature creature, int x, int y) {
    WorldObjectView spawnView = dieToIconToSpawn.get(creature.description);
    placed.add(creature);
    refreshStartButton();
    world.add(x, y, creature);
    WorldObjectView worldView = world.getController(ViewController.class).getView(creature);
    EventListener listener = createMoveSpawnedListener(creature, worldView, spawnView);
    EventListener prev = moveListeners.remove(worldView);
    if (prev != null) {
        worldView.removeListener(prev);
    }
    moveListeners.put(worldView, listener);
    worldView.addListener(listener);
    spawnView.getColor().a = 0f;
    spawnView.setTouchable(Touchable.disabled);
}
 
Example #10
Source File: Tooltip.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Attaches tooltip to current target, must be called if tooltip listener was removed from target (for example by
 * calling target.clearListeners() )
 */
public void attach () {
	if (target == null) return;
	Array<EventListener> listeners = target.getListeners();
	for (EventListener listener : listeners) {
		if (listener instanceof TooltipInputListener) {
			throw new IllegalStateException("More than one tooltip cannot be added to the same target!");
		}
	}

	target.addListener(listener);
}
 
Example #11
Source File: ImageTextButtonListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener imageTextButtonStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var imageTextButton = (DialogSceneComposerModel.SimImageTextButton) simActor;
    var popTableClickListener = new StyleSelectorPopTable(ImageTextButton.class, imageTextButton.style == null ? "default" : imageTextButton.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.imageTextButtonStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #12
Source File: RestrictCloseWindows.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");
    EventListener listener = resources.getIfExists("restrictCloseWindowsListener");
    if (listener != null) {
        stage.removeCaptureListener(listener);
    }
    listener = new WindowListener() {
        @Override protected void hide(WindowEvent event) {
            event.cancel();
        }
    };
    stage.addCaptureListener(listener);
    resources.put("restrictCloseWindowsListener", listener);
    callback.taskEnded();
}
 
Example #13
Source File: GdxHelper.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static void showStageEvents(final Stage stage) {
    EventListener listener = new EventListener() {
        private final Vector2 tmp = new Vector2();
        private Actor actor = new Actor() {
            @Override public void draw(Batch batch, float parentAlpha) {
                if (target == null)
                    return;
                batch.end();
                Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
                Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
                Gdx.gl.glLineWidth(6);
                Config.shapeRenderer.setColor(Color.ORANGE);
                Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0));
                float x = pos.x, y = pos.y;
                Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight()));
                float maxX = top.x, maxY = top.y;
                Config.shapeRenderer.rect(x, y, maxX - x, maxY - y);

                Config.shapeRenderer.end();
                batch.begin();
            }
        };

        {
            stage.addActor(actor);
        }

        public Actor target;

        @Override public boolean handle(Event event) {
            target = event.getTarget();
            return false;
        }
    };
    stage.addListener(listener);
}
 
Example #14
Source File: InvitesWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private EventListener createListener(final String player) {
    return new ChangeListener() {
        @Override public void changed(ChangeEvent event, Actor actor) {
            selected = player;
            hide();
        }
    };
}
 
Example #15
Source File: TextButtonListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener textButtonStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTextButton = (DialogSceneComposerModel.SimTextButton) simActor;
    var popTableClickListener = new StyleSelectorPopTable(TextButton.class, simTextButton.style == null ? "default" : simTextButton.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.textButtonStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #16
Source File: ImageButtonListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener imageButtonStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simImageButton = (DialogSceneComposerModel.SimImageButton) simActor;
    var popTableClickListener = new StyleSelectorPopTable(ImageButton.class, simImageButton.style == null ? "default" : simImageButton.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.imageButtonStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #17
Source File: AbstractListAdapter.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
protected void prepareViewBeforeAddingToTable (ItemT item, ViewT view) {
	boolean listenerMissing = true;
	for (EventListener listener : view.getListeners()) {
		if (listener instanceof AbstractListAdapter.ListClickListener) {
			listenerMissing = false;
			break;
		}
	}
	if (listenerMissing) {
		view.setTouchable(Touchable.enabled);
		view.addListener(new ListClickListener(view, item));
	}
}
 
Example #18
Source File: Tooltip.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Remove any attached tooltip from target actor
 * @param target that tooltips will be removed
 */
public static void removeTooltip (Actor target) {
	Array<EventListener> listeners = target.getListeners();
	for (EventListener listener : listeners) {
		if (listener instanceof TooltipInputListener) target.removeListener(listener);
	}
}
 
Example #19
Source File: ScrollPaneListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener scrollPaneStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simScrollPane = (DialogSceneComposerModel.SimScrollPane) simActor;
    var popTableClickListener = new StyleSelectorPopTable(ScrollPane.class, simScrollPane.style == null ? "default" : simScrollPane.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.scrollPaneStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #20
Source File: SelectBoxListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener selectBoxStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simSelectBox = (DialogSceneComposerModel.SimSelectBox) simActor;
    var popTableClickListener = new StyleSelectorPopTable(SelectBox.class, simSelectBox.style == null ? "default" : simSelectBox.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.selectBoxStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #21
Source File: MainMenu.java    From Codelabs with MIT License 5 votes vote down vote up
private TextButton createTextButton(String text, Skin skin,
		String styleName, EventListener listener) {
	TextButton textButton = new TextButton(text, skin, styleName);
	textButton.pad(10);
	textButton.addListener(listener);

	return textButton;
}
 
Example #22
Source File: ClientErrorMenu.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void render() {
  super.render();
  if (!firstRender) return;
  addButtonListener(new EventListener() {
    @Override
    public boolean handle(Event event) {
      if (!(event instanceof ChangeListener.ChangeEvent)) return false;
      Adapter.setMenu(new MainMenu());
      return true;
    }
  });
  firstRender = false;
}
 
Example #23
Source File: TextAreaListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener textAreaStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTextArea = (DialogSceneComposerModel.SimTextArea) simActor;
    var popTableClickListener = new StyleSelectorPopTable(TextField.class, simTextArea.style == null ? "default" : simTextArea.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.textAreaStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #24
Source File: StringSetting.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public Actor getActor(String settingName, VisualSettingManager visualSettingManager) {
  final TextField textField = new TextField(s, visualSettingManager.getSkin());
  textField.addListener(new EventListener() {
    @Override
    public boolean handle(Event event) {
      if (!(event instanceof SettingsMenu.SaveEvent)) return false;
      set(textField.getText());
      return true;
    }
  });
  return textField;
}
 
Example #25
Source File: ProgressBarListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener progressBarStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simProgressBar = (DialogSceneComposerModel.SimProgressBar) simActor;
    var popTableClickListener = new StyleSelectorPopTable(ProgressBar.class, simProgressBar.style == null ? "default-horizontal" : simProgressBar.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.progressBarStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #26
Source File: EntityStage.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void initializeActor(final EntityActor actor) {
	final Entity entity = actor.getEntity();
	// DANGER : I assume every entity has a 32x32 size (map tile width x map tile height)
	actor.setBounds(entity.getCurrentPosition().getTileX(), entity.getCurrentPosition().getTileY(), 1, 1);
	addActor(actor);
	final EventListener eventListener = new EntityClickListener(actor);
	actor.addListener(eventListener);
}
 
Example #27
Source File: SliderListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener sliderStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simSlider = (DialogSceneComposerModel.SimSlider) simActor;
    var popTableClickListener = new StyleSelectorPopTable(Slider.class, simSlider.style == null ? "default-horizontal" : simSlider.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.sliderStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #28
Source File: LabelListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener labelStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simLabel = (DialogSceneComposerModel.SimLabel) simActor;
    var popTableClickListener = new StyleSelectorPopTable(Label.class, simLabel.style == null ? "default" : simLabel.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.labelStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #29
Source File: ListListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener listStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simList = (DialogSceneComposerModel.SimList) simActor;
    var popTableClickListener = new StyleSelectorPopTable(List.class, simList.style == null ? "default" : simList.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.listStyle(styleData);
        }
    };
    
    return popTableClickListener;
}
 
Example #30
Source File: ButtonListeners.java    From skin-composer with MIT License 5 votes vote down vote up
public static EventListener buttonStyleListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simButton = (DialogSceneComposerModel.SimButton) simActor;
    var popTableClickListener = new StyleSelectorPopTable(Button.class, simButton.style == null ? "default" : simButton.style.name) {
        @Override
        public void accepted(StyleData styleData) {
            events.buttonStyle(styleData);
        }
    };
    
    return popTableClickListener;
}