Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.ClickListener

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.ClickListener. These examples are extracted from open source projects. 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 Project: gdx-vfx   Source File: EffectRosterViewController.java    License: Apache License 2.0 6 votes vote down vote up
private void addEffectToChain(final EffectEntryModel effectModel) {
    if (effectsChain.containsKey(effectModel)) {
        // If the effect is already in the chain, re-add it to the end of the list.
        removeEffectFromChain(effectModel);
    }

    EffectEntryViewController viewController = new EffectEntryViewController(lmlParser, effectModel);
    Group viewRoot = viewController.getViewRoot();
    vgEffectsChain.addActor(viewRoot);
    effectsChain.put(viewController.getModel(), viewController);
    vfxManager.addEffect(viewController.getModel().getEffect());

    viewRoot.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            removeEffectFromChain(effectModel);
        }
    });
}
 
Example 2
Source Project: talos   Source File: UIStage.java    License: Apache License 2.0 6 votes vote down vote up
public void initExampleList (PopupMenu examples) {
	FileHandle list = Gdx.files.internal("samples/list.xml");
	XmlReader xmlReader = new XmlReader();
	XmlReader.Element root = xmlReader.parse(list);
	Array<XmlReader.Element> samples = root.getChildrenByName("sample");
	for (XmlReader.Element sample : samples) {
		String name = sample.getAttribute("name");
		final String fileName = sample.getAttribute("file");
		MenuItem item = new MenuItem(name);
		examples.addItem(item);

		item.addListener(new ClickListener() {
			@Override
			public void clicked (InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				//openProject(fileName);
				TalosMain.Instance().ProjectController().lastDirTrackingDisable();
				TalosMain.Instance().ProjectController().setProject(ProjectController.TLS);
				TalosMain.Instance().ProjectController().loadProject(Gdx.files.internal("samples/" + fileName));
				TalosMain.Instance().ProjectController().lastDirTrackingEnable();
				TalosMain.Instance().ProjectController().unbindFromFile();
			}
		});
	}
}
 
Example 3
Source Project: talos   Source File: SettingsDialog.java    License: Apache License 2.0 6 votes vote down vote up
public void addPathSetting(String name, final String id) {
    Table inputTable = new Table();

    inputTable.add(new Label(name, getSkin())).width(220);
    final TextField inputPathField = new TextField("", getSkin());
    inputTable.add(inputPathField).padLeft(13).width(270);
    TextButton browseInputBtn = new TextButton("Browse", getSkin());
    inputTable.add(browseInputBtn).padLeft(3);

    add(inputTable).pad(5).left().expandX().padTop(10);
    row();

    textFieldMap.put(id, inputPathField);

    browseInputBtn.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            showFolderSelect(id);
        }
    });
}
 
Example 4
Source Project: talos   Source File: MainMenu.java    License: Apache License 2.0 6 votes vote down vote up
public void updateRecentsList(Array<String> list) {
    openRecentPopup.clear();

    for(String path: list) {
        final FileHandle handle = Gdx.files.absolute(path);
        if(!handle.exists()) continue;;
        String name = handle.name();
        MenuItem item = new MenuItem(name);
        item.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if(handle.extension().equals("tls")) {
                    TalosMain.Instance().ProjectController().setProject(ProjectController.TLS);
                    TalosMain.Instance().ProjectController().loadProject(handle);
                } else {
                    TalosMain.Instance().Addons().projectFileDrop(handle);
                }
            }
        });
        openRecentPopup.addItem(item);
    }
}
 
Example 5
Source Project: talos   Source File: ModuleBoardWidget.java    License: Apache License 2.0 6 votes vote down vote up
public ModuleBoardWidget(NodeStage mainStage) {
    super();
    this.mainStage = mainStage;

    curvePoints[0] = new Vector2();
    curvePoints[1] = new Vector2();
    curvePoints[2] = new Vector2();
    curvePoints[3] = new Vector2();

    addActor(groupContainer);
    addActor(moduleContainer);

    shapeRenderer = new ShapeRenderer();

    addListener(new ClickListener() {

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if(event.isHandled()) return super.keyUp(event, keycode);
            if(keycode == Input.Keys.DEL || keycode == Input.Keys.FORWARD_DEL) {
                deleteSelectedWrappers();
            }
            return super.keyUp(event, keycode);
        }
    });
}
 
Example 6
Source Project: talos   Source File: AttachmentTypeToggle.java    License: Apache License 2.0 6 votes vote down vote up
public AttachmentTypeToggle(Skin skin) {
    setSkin(skin);
    setBackground(getSkin().getDrawable("panel_button_bg"));

    drawableMap.put(AttachmentPoint.AttachmentType.POSITION, getSkin().getDrawable("icon-target"));
    drawableMap.put(AttachmentPoint.AttachmentType.ROTATION, getSkin().getDrawable("icon-angle"));
    drawableMap.put(AttachmentPoint.AttachmentType.TRANSPARENCY, getSkin().getDrawable("icon-transparency"));
    drawableMap.put(AttachmentPoint.AttachmentType.COLOR, getSkin().getDrawable("icon-color"));

    button = new ImageButton(drawableMap.get(AttachmentPoint.AttachmentType.POSITION));

    addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            currentType = currentType.next();
            setButtonDrawable();
        }
    });

    setButtonDrawable();
}
 
Example 7
Source Project: Unlucky   Source File: SelectScreen.java    License: MIT License 6 votes vote down vote up
/**
 * Handles the position and events of the exit button
 */
protected void handleExitButton(final Screen screen) {
    // init exit button
    ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
    style.imageUp = new TextureRegionDrawable(rm.menuExitButton[0][0]);
    style.imageDown = new TextureRegionDrawable(rm.menuExitButton[1][0]);
    exitButton = new ImageButton(style);
    exitButton.setSize(18, 18);
    exitButton.setPosition(177, 99);
    stage.addActor(exitButton);

    // fade back to previous screen
    exitButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!game.player.settings.muteSfx) rm.buttonclick0.play(game.player.settings.sfxVolume);
            game.menuScreen.transitionIn = 0;
            setFadeScreen(screen);
        }
    });
}
 
Example 8
Source Project: gdx-ai   Source File: BehaviorTreeTests.java    License: Apache License 2.0 6 votes vote down vote up
private List<String> createTestList () {
	// Create behavior names
	int numTests = tests.length;
	String[] testNames = new String[numTests];
	for (int i = 0; i < numTests; i++) {
		testNames[i] = tests[i].getName();
	}

	final List<String> testList = new List<String>(skin);
	testList.setItems(testNames);
	testList.addListener(new ClickListener() {
		@Override
		public void clicked (InputEvent event, float x, float y) {
			changeTest(testList.getSelectedIndex());
		}
	});
	return testList;
}
 
Example 9
Source Project: Cardshifter   Source File: PlayerView.java    License: Apache License 2.0 6 votes vote down vote up
public PlayerView(CardshifterClientContext context, PlayerMessage message) {
    this.context = context;
    this.table = new Table(context.getSkin());
    this.id = message.getId();
    this.index = message.getIndex();
    ResViewFactory rvf = new ResViewFactory(context.getSkin());
    this.resources = rvf.forFormat(rvf.res("SCRAP"), rvf.str(" "), rvf.res("MANA"), rvf.str(" "), rvf.coloredRes("HEALTH", "MAX_HEALTH"));
    this.properties = new HashMap<String, Integer>(message.getProperties());
    this.table.add(message.getName()).row();
    this.table.add(this.resources.getActor()).row();
    this.table.add(actions);
    table.setTouchable(Touchable.enabled);
    table.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (callback != null) {
                callback.addEntity(PlayerView.this);
            }
        }
    });
    resources.update(properties);
}
 
Example 10
Source Project: skin-composer   Source File: EditWidget.java    License: MIT License 6 votes vote down vote up
private void addSimListener() {
    addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (simActor != null) {
                dialog.simActor = simActor;
                dialog.populateProperties();
                dialog.model.updatePreview();
                dialog.populatePath();
                
                var label = new FadeLabel(simActor.toString(), main.getSkin(), "scene-edit-tip");
                main.getStage().addActor(label);
                label.setPosition(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
            }
        }
    });
    addListener(main.getHandListener());
}
 
Example 11
private ClickListener createListener(final Group group, final Image selection, final LocLabel label, final CreatureEffect effect, final Creature creature) {
    return new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            group.addActor(selection);
            final int turnCount = effect.getTurnCount();
            if (turnCount > 1000) {
                //forever effect
                label.setKey("ui-creature-info-window-forever-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("die", creature.description.nameLocKey())
                );
            } else {
                label.setKey("ui-creature-info-window-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("turn-count", String.valueOf(turnCount))
                        .with("die", creature.description.nameLocKey())
                );
            }
        }
    };
}
 
Example 12
Source Project: Cardshifter   Source File: DeckCardView.java    License: Apache License 2.0 6 votes vote down vote up
public DeckCardView(Skin skin, int id, String name, DeckBuilderScreen screen) {
    super(skin);
    this.count = new Label("", skin);
    this.add(count).left().expand().fill();
    this.add(new Label(name, skin)).right();
    this.name = name;
    this.id = id;
    this.screen = screen;
    setName(name);
    
    this.setTouchable(Touchable.enabled);
    this.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            DeckCardView.this.screen.removeCardFromDeck(DeckCardView.this.id);
        }
    });
}
 
Example 13
Source Project: dice-heroes   Source File: TabPane.java    License: 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 14
Source Project: cocos-ui-libgdx   Source File: T.java    License: Apache License 2.0 6 votes vote down vote up
public T isButton(final TClickListener clickListener) {
    actor.setTouchable(Touchable.enabled);
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            actor.addAction(Actions.sequence(Actions.scaleTo(0.9f, 0.9f, 0.1f), Actions.scaleTo(1, 1, 0.1f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    if (clickListener != null) {
                        clickListener.onClick(actor);
                    }
                }
            })));
        }
    });

    return this;
}
 
Example 15
Source Project: cocos-ui-libgdx   Source File: TImage.java    License: Apache License 2.0 6 votes vote down vote up
public TImage isButton() {
    clearListeners();
    origonCenter();
    addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            addAction(Actions.sequence(Actions.scaleTo(0.9f, 0.9f, 0.1f), Actions.scaleTo(1, 1, 0.1f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    if (clickListener != null) {
                        clickListener.onClicked(TImage.this);
                    }
                }
            })));
        }
    });
    return this;
}
 
Example 16
@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 17
@Override
public void process(LmlParser parser, LmlTag tag, final ListView.ListViewTable listTable, String rawAttributeData) {
    final ActorConsumer<?, ListView.ListViewTable> action = parser.parseAction(rawAttributeData, listTable);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + listTable);
        return;
    }

    listTable.getListView().getScrollPane().addListener(new ClickListener(0) {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (event.getTarget() == event.getListenerActor()) {
                action.consume(listTable);
            }
        }
    });
}
 
Example 18
Source Project: gdx-texture-packer-gui   Source File: MainController.java    License: Apache License 2.0 6 votes vote down vote up
@OnEvent(ShowToastEvent.class) void onEvent(final ShowToastEvent event) {
    if (viewShown) {
        final Toast toast;
        if (event.getContent() != null) {
            toast = toastManager.show(event.getContent(), event.getDuration());
        } else {
            toast = toastManager.show(event.getMessage(), event.getDuration());
        }
        // Setup click listener (if provided).
        if (event.getClickAction() != null) {
            Table mainTable = toast.getMainTable();
            mainTable.setTouchable(Touchable.enabled);
            mainTable.addListener(new ClickListener() {
                @Override
                public void clicked(InputEvent e, float x, float y) {
                    if (e.getTarget() == e.getListenerActor()) {
                        event.getClickAction().run();
                        toastManager.remove(toast);
                    }
                }
            });
        }
    }
}
 
Example 19
Source Project: riiablo   Source File: SystemProfilerGUI.java    License: Apache License 2.0 6 votes vote down vote up
public SystemProfilerGUI(Skin skin, String style) {
  super("Profiler", skin, style);
  this.skin = skin;

  setVisible(false);
  setResizable(true);
  setResizeBorder(12);
  TextButton closeButton = new TextButton("X", skin);
  getTitleTable().add(closeButton).padRight(3);
  closeButton.addListener(new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      hide();
    }
  });
}
 
Example 20
Source Project: riiablo   Source File: LobbyScreen.java    License: Apache License 2.0 6 votes vote down vote up
TabbedPane(TextureRegion defaultBackground) {
  background.setRegion(this.defaultBackground = defaultBackground);
  setBackground(background);
  buttons.setMinCheckCount(0);
  clickListener = new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      Button button = (Button) event.getListenerActor();
      TabGroup previous = getActor();
      TabGroup content = map.get(button.getName());
      setActor(content);
      setBackground(content.background);
      content.exited();
      content.entered();
    }
  };
}
 
Example 21
Source Project: riiablo   Source File: Button.java    License: Apache License 2.0 6 votes vote down vote up
public Button(ButtonStyle style) {
  super(style);
  addListener(new ClickListener() {
    Sound button = null;

    {
      Riiablo.assets.load(buttonDescriptor);
    }

    @Override
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int b) {
      if (event.getButton() != Input.Buttons.LEFT || isDisabled()) {
        return super.touchDown(event, x, y, pointer, b);
      } else if (button == null) {
        Riiablo.assets.finishLoadingAsset(buttonDescriptor);
        button = Riiablo.assets.get(buttonDescriptor);
      }

      button.play();
      Riiablo.input.vibrate(10);
      return super.touchDown(event, x, y, pointer, b);
    }
  });
}
 
Example 22
Source Project: Mundus   Source File: FileChooserField.java    License: Apache License 2.0 6 votes vote down vote up
private void setupListeners() {

        fcBtn.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                FileChooser fileChooser = UI.INSTANCE.getFileChooser();
                fileChooser.setSelectionMode(mode);
                fileChooser.setListener(new SingleFileChooserListener() {
                    @Override
                    protected void selected(FileHandle file) {
                        fileHandle = file;
                        path = file.path();

                        textField.setText(file.path());
                        if (fileSelected != null) {
                            fileSelected.selected(file);
                        }
                    }
                });
                UI.INSTANCE.addActor(fileChooser.fadeIn());
            }
        });

    }
 
Example 23
Source Project: Mundus   Source File: ImageChooserField.java    License: Apache License 2.0 6 votes vote down vote up
private void setupListeners() {
    fcBtn.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            FileChooser fileChooser = UI.INSTANCE.getFileChooser();
            fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
            fileChooser.setListener(new SingleFileChooserListener() {
                public void selected(FileHandle file) {
                    if (FileFormatUtils.isImage(file)) {
                        setImage(file);
                    } else {
                        Dialogs.showErrorDialog(UI.INSTANCE, "This is no image");
                    }
                }
            });
            UI.INSTANCE.addActor(fileChooser.fadeIn());
        }
    });
}
 
Example 24
Source Project: libgdx-snippets   Source File: TreeTools.java    License: MIT License 6 votes vote down vote up
public static ClickListener createNodeClickListener(Tree tree, Runnable clicked) {

		return new ClickListener() {

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

				Tree.Node node = tree.getNodeAt(y);

				if (node != null && node.getChildren().size > 0) {
					node.setExpanded(!node.isExpanded());
					tree.getClickListener().clicked(event, x, y);
				}

				clicked.run();
			}
		};
	}
 
Example 25
Source Project: vis-ui   Source File: BasicColorPicker.java    License: Apache License 2.0 6 votes vote down vote up
private VisTable createColorsPreviewTable () {
	VisTable table = new VisTable(false);
	table.add(currentColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();
	table.add(new Image(style.iconArrowRight)).pad(0, 2, 0, 2);
	table.add(newColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();

	currentColorImg.setColor(color);
	newColorImg.setColor(color);

	currentColorImg.addListener(new ClickListener() {
		@Override
		public void clicked (InputEvent event, float x, float y) {
			restoreLastColor();
		}
	});

	return table;
}
 
Example 26
Source Project: Cardshifter   Source File: UsersList.java    License: Apache License 2.0 6 votes vote down vote up
public void handleUserStatus(UserStatusMessage message) {
    switch (message.getStatus()) {
        case OFFLINE:
            UserTable table = userMap.get(message.getUserId());
            if (table != null) {
                table.remove();
            }
            break;
        case ONLINE:
            table = userMap.get(message.getUserId());
            if (table == null) {
                final UserTable userTable = new UserTable(skin, message.getUserId(), message.getName());
                userMap.put(message.getUserId(), userTable);
                userTable.getTable().addListener(new ClickListener() {
                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                    	UsersList.this.selectUser(userTable);

                    }
                });
                this.table.add(userTable.getTable()).align(Align.left).row();
            }
            break;
    }
}
 
Example 27
public FilteredSelectBox(FilteredSelectBoxStyle style) {
	setStyle(style);
	setSize(getPrefWidth(), getPrefHeight());

	selection.setActor(this);
	selection.setRequired(true);

	selectBoxList = new SelectBoxList<>(this);

	addListener(clickListener = new ClickListener() {
		@Override
		public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
			if (pointer == 0 && button != 0)
				return false;
			if (disabled)
				return false;
			if (selectBoxList.hasParent())
				hideList();
			else
				showList();
			return true;
		}
	});

}
 
Example 28
Source Project: gdx-vfx   Source File: PatchedOnClickLmlAttribute.java    License: 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 29
Source Project: gdx-soundboard   Source File: FileChooser.java    License: MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    final Table content = getContentTable();
    content.add(fileListLabel).top().left().expandX().fillX().row();
    content.add(new ScrollPane(fileList, skin)).size(300, 150).fill().expand().row();

    if (fileNameEnabled) {
        content.add(fileNameLabel).fillX().expandX().row();
        content.add(fileNameInput).fillX().expandX().row();
        stage.setKeyboardFocus(fileNameInput);
    }

    if (newFolderEnabled) {
        content.add(newFolderButton).fillX().expandX().row();
    }
    
    if(directoryBrowsingEnabled){
        fileList.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                final FileListItem selected = fileList.getSelected();
                if (selected.file.isDirectory()) {
                    changeDirectory(selected.file);
                }
            }
        });
    }

    this.stage = stage;
    changeDirectory(baseDir);
    return super.show(stage, action);
}
 
Example 30
Source Project: talos   Source File: GlobalValueListContainer.java    License: Apache License 2.0 5 votes vote down vote up
private void build() {

        Table main = new Table();
        list = new CustomList<>(getSkin());
        list.setBackground(getSkin().getDrawable("dynamic_list_bg"));

        Stack stack = new Stack();
        Table listContainer = new Table();
        Table bottomPanelContainer = new Table();
        Table bottomPanel = new Table();
        stack.add(listContainer);
        stack.add(bottomPanelContainer);

        bottomPanelContainer.add().expandY().row();
        bottomPanelContainer.add(bottomPanel).padBottom(2f).left().expandX();

        ImageButton newRowButton = new ImageButton(getSkin().getDrawable("ic-input-file-add"));
        bottomPanel.add(newRowButton).left().padLeft(2);
        bottomPanel.add().expandX();

        listContainer.add(list).grow().minHeight(90);
        main.add(stack).grow();
        add(main).growX();

        newRowButton.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                addNewRow();
            }
        });
    }