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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.TextButton#addListener() . 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-pd   File: PdAudioRemoteTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testSendArray(String label, final String name, final int position, final float...values)
{
	String valText = "";
	if(values.length < 8)
		for(float v : values) valText += "," + String.valueOf(v);
	else
		valText = ",...";
	if(valText.length()>0) valText = "(" + valText.substring(1) + ")";
	valText = "at " + String.valueOf(position) + " " + valText;
	TextButton bt = new TextButton(label + " " + valText, skin);
	bt.addListener(new ChangeListener() {
		@Override
		public void changed(ChangeEvent event, Actor actor) {
			Pd.audio.writeArray(name, position, values, 0, values.length);
		}
	});
	table.add("Write array to " + name);
	table.add(bt);
	table.row();
}
 
Example 2
Source Project: gdx-pd   File: PdAudioRemoteTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testSendList(String label, final Object...values)
{
	String valText = "";
	for(Object v : values) valText += "," + v.toString();
	valText = "(" + valText.substring(1) + ")";
	
	TextButton bt = new TextButton(label + " " + valText, skin);
	bt.addListener(new ChangeListener() {
		
		@Override
		public void changed(ChangeEvent event, Actor actor) {
			Pd.audio.sendList("recv_list", values);
		}
	});
	table.add("Send List on recv_list");
	table.add(bt);
	table.row();
}
 
Example 3
/**
 * Adds exit button with listener in right bottom corner
 */
private void createBackButton() {
    // Create Button
    backButton = new TextButton("EXIT", VisUI.getSkin());

    // Set position in bottom right corner
    backButton.setX(Gdx.graphics.getWidth()-60);
    backButton.setY(0);
    backButton.setWidth(60);
    backButton.setHeight(60);
    backButton.setVisible(true);

    // Add Listener that sets the screen to the start screen of the game when button is clicked
    backButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            StandardizedInterface.getInstance().StimuliSystem.stopStimulus();
            frameCounter = 0;
            game.setScreen(new MainMenuScreen(game));
        }
    });

    // Add Button to stage
    stage.addActor(backButton);
}
 
Example 4
Source Project: gdx-ai   File: ResumeVsJoinTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Actor createActor (final Skin skin) {
	Table table = new Table();

	LabelStyle labelStyle = new LabelStyle(skin.get(LabelStyle.class));
	labelStyle.background = skin.newDrawable("white", .6f, .6f, .6f, 1);
	String branchChildren = "\n    spinAround\n    selectTarget\n    pursue";
	table.add(new Label("parallel policy:\"sequence\" orchestrator:\"resume\"" + branchChildren, labelStyle)).pad(5);
	table.add(new Label("vs", skin)).padLeft(10).padRight(10);
	table.add(new Label("parallel policy:\"sequence\" orchestrator:\"join\"" + branchChildren, labelStyle)).pad(5);

	table.row().padTop(15);

	TextButton startButton = new TextButton("Start", skin);
	startButton.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			oldScreen = container.getScreen();
			container.setScreen(new TestScreen(ResumeVsJoinTest.this, skin));
		}
	});
	table.add();
	table.add(startButton);
	table.add();
	return table;
}
 
Example 5
Source Project: riiablo   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 6
Source Project: Cubes   File: MultiplayerConnectMenu.java    License: MIT License 6 votes vote down vote up
public MultiplayerConnectMenu() {
  super();
  title = new Label(Localization.get("menu.multiplayer.title"), skin.get("title", Label.LabelStyle.class));
  address = new TextField("", skin);
  address.setMessageText(Localization.get("menu.multiplayer.address"));
  port = new TextField("", skin);
  port.setMessageText(Localization.get("menu.multiplayer.port", 24842)); //Not "Settings.getIntegerSettingValue(Settings.NETWORKING_PORT)" because the port is set on the server
  port.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
  connect = new TextButton(Localization.get("menu.multiplayer.connect"), skin);
  back = MenuTools.getBackButton(this);

  connect.addListener(new ChangeListener() {
    @Override
    public void changed(ChangeEvent event, Actor actor) {
      Adapter.setMenu(new MultiplayerLoadingMenu(address.getText().isEmpty() ? "localhost" : address.getText(), port.getText().isEmpty() ? 24842 : Integer.parseInt(port.getText())));
    }
  });

  stage.addActor(title);
  stage.addActor(address);
  stage.addActor(port);
  stage.addActor(connect);
  stage.addActor(back);
}
 
Example 7
private Table createVerbPanel() {
	Table verbs = new Table();

	verbs.defaults().pad(MARGIN);

	for (int i = 0; i < VERBS.size(); i++) {
		if (i % VERB_COLS == 0)
			verbs.row();

		TextButton b = new TextButton(VERBS_DESC.get(i), style.verbButtonStyle);
		b.setName(VERBS.get(i));
		b.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				currentVerb = event.getListenerActor().getName();
				infoLine.setText(((TextButton) event.getListenerActor()).getText());
				target = null;
			}
		});

		verbs.add(b).fill().expand();
	}

	return verbs;
}
 
Example 8
Source Project: gdx-ai   File: ParallelVsSequenceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Actor createActor (final Skin skin) {
	Table table = new Table();

	LabelStyle labelStyle = new LabelStyle(skin.get(LabelStyle.class));
	labelStyle.background = skin.newDrawable("white", .6f, .6f, .6f, 1);
	String branchChildren = "\n    selectTarget\n    pursue";
	table.add(new Label("parallel policy:\"sequence\" orchestrator:\"resume\"" + branchChildren, labelStyle)).pad(5);
	table.add(new Label("vs", skin)).padLeft(10).padRight(10);
	table.add(new Label("sequence" + branchChildren, labelStyle)).pad(5);

	table.row().padTop(15);

	TextButton startButton = new TextButton("Start", skin);
	startButton.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			oldScreen = container.getScreen();
			container.setScreen(new TestScreen(ParallelVsSequenceTest.this, skin));
		}
	});
	table.add();
	table.add(startButton);
	table.add();
	return table;
}
 
Example 9
Source Project: Cubes   File: BooleanSetting.java    License: MIT License 5 votes vote down vote up
@Override
public Actor getActor(String settingName, VisualSettingManager visualSettingManager) {
  final TextButton textButton = new TextButton(b ? "True" : "False", visualSettingManager.getSkin());
  textButton.addListener(new ChangeListener() {
    @Override
    public void changed(ChangeEvent event, Actor actor) {//easier than SettingsMenu.SaveEvent and works
      set(!get());
      textButton.setText(b ? "True" : "False");
    }
  });
  return textButton;
}
 
Example 10
Source Project: gdx-gltf   File: CollapsableUI.java    License: Apache License 2.0 5 votes vote down vote up
public CollapsableUI(Skin skin, String name, boolean visible) {
	toggle = new TextButton(name, skin, "toggle");
	toggle.setChecked(visible);
	add(toggle).row();
	optTable = new Table(skin);
	optCell = add();
	row();
	show(visible);
	toggle.addListener(new ChangeListener() {
		@Override
		public void changed(ChangeEvent event, Actor actor) {
			show(toggle.isChecked());
		}
	});
}
 
Example 11
Source Project: RuinsOfRevenge   File: ScreenPause.java    License: MIT License 5 votes vote down vote up
public ScreenPause(final ResourceLoader resources, final RuinsOfRevenge game) {
	super(new Stage(), game);
	this.resources = resources;
	this.game = game;

	skin = resources.getSkin("uiskin");

	TextButton play = new TextButton("Continue Playing", skin);
	TextButton settings = new TextButton("Settings", skin);
	TextButton backToMM = new TextButton("Back to Main Menu", skin);

	play.addListener(continueListener);
	settings.addListener(settingsListener);
	backToMM.addListener(backToMMListener);

	table = new Table(skin);
	table.add(play).size(320, 64).space(8);
	table.row();
	table.add(settings).size(320, 64).space(8);
	table.row();
	table.add(backToMM).size(320, 64).space(8);
	table.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
	stage.addActor(table);
	stage.addListener(new KeyUpListener() {
		@Override
		public boolean keyUp(InputEvent event, int keycode) {
			if (keycode == Config.get().key("escape"))
				game.popScreen();
			return false;
		}
	});
}
 
Example 12
Source Project: gdx-pd   File: PdAudioRemoteTest.java    License: Apache License 2.0 5 votes vote down vote up
private void testSendSymbol(String label, final String symbol)
{
	TextButton bt = new TextButton(label + " (" + symbol + ")", skin);
	bt.addListener(new ChangeListener() {
		
		@Override
		public void changed(ChangeEvent event, Actor actor) {
			Pd.audio.sendSymbol("recv_sym", symbol);
		}
	});
	table.add("Send Symbol on recv_sym");
	table.add(bt);
	table.row();
}
 
Example 13
Source Project: Codelabs   File: MainMenu.java    License: 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 14
Source Project: Cubes   File: MenuTools.java    License: MIT License 5 votes vote down vote up
public static TextButton getBackButton(final Menu menu) {
  TextButton textButton = new TextButton(Localization.get("menu.general.back"), Menu.skin);
  textButton.addListener(new ChangeListener() {
    @Override
    public void changed(ChangeEvent event, Actor actor) {
      Menu prev = MenuManager.getPrevious(menu);
      if (prev == null) return;
      Adapter.setMenu(prev);
    }
  });
  return textButton;
}
 
Example 15
Source Project: uracer-kotd   File: UIUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static TextButton newTextButton (String text, ClickListener listener) {
	TextButton btn = new TextButton(text, Art.scrSkin);
	btn.addListener(listener);
	return btn;
}
 
Example 16
@Override protected void doShow(Params params) {
    callback = params.callback;
    Table content = new Table(Config.skin);
    content.defaults().pad(2);
    content.setBackground("ui-creature-info-background");
    content.setTouchable(Touchable.enabled);
    table.add(content);

    Image image = new Image(Config.skin, "ability/" + params.ability.name + "-icon");
    Image line = new Image(Config.skin, "ui-creature-info-line");
    TextButton use = new LocTextButton("ui-use-ability");

    Thesaurus.Params dp = Thesaurus.params();
    params.ability.fillDescriptionParams(dp, params.creature);
    Label desc = new LocLabel(params.ability.locDescKey(), dp);
    desc.setWrap(true);
    desc.setAlignment(Align.center);

    content.add(image).size(image.getWidth() * 2, image.getHeight() * 2).padBottom(-6).padTop(0).row();
    content.add(new LocLabel(params.ability.locNameKey())).padBottom(3).row();
    content.add(line).width(50).row();
    content.add(desc).width(120).row();
    content.add(use).padBottom(6).padTop(6).width(90).row();

    Thesaurus.LocalizationData reason = new Thesaurus.LocalizationData();
    if (!params.ability.action.canBeApplied(params.creature, reason)) {
        use.setDisabled(true);
        CooldownEffect cooldown = params.creature.get(Attribute.cooldownFor(params.ability.name));
        LocLabel label;
        if (cooldown == null) {
            label = new LocLabel(reason.key, reason.params, StoreWindow.INACTIVE);
        } else {
            Thesaurus.Params p = Thesaurus.params()
                .with("desc", cooldown.locDescKey())
                .with("turn-count", String.valueOf(cooldown.getTurnCount()))
                .with("die", params.creature.description.nameLocKey());
            params.ability.fillDescriptionParams(p, params.creature);
            label = new LocLabel("ui-creature-info-window-effect-description", p, StoreWindow.INACTIVE);
        }
        label.setWrap(true);
        label.setAlignment(Align.center);
        content.add(label).padLeft(4).padRight(4).padBottom(3).width(120).row();
    } else {
        use.addListener(new ChangeListener() {
            @Override public void changed(ChangeEvent event, Actor actor) {
                doUse = true;
                hide();
            }
        });
    }


}
 
Example 17
Source Project: Cardshifter   File: MenuScreen.java    License: Apache License 2.0 4 votes vote down vote up
public MenuScreen(final CardshifterGame game) {
    final Preferences prefs = Gdx.app.getPreferences("cardshifter");
    this.table = new Table();
    this.game = game;
    this.table.setFillParent(true);
    
    Image imageObject = new Image(new Texture(Gdx.files.internal("bg2.png")));
    this.table.add(imageObject);
    this.table.row();

    Table inner = new Table();

    final TextField username = new TextField("", game.skin);
    String[] servers = isGWT() ? availableWSServers : availableServers;
    inner.add(username).expand().fill().colspan(servers.length).row();
    username.setText(prefs.getString("username", "YourUserName"));

    HorizontalGroup serverView = new HorizontalGroup();
    for (final String server : servers) {
        final String[] serverData = server.split(":");
        TextButton button = new TextButton(serverData[0], game.skin);
        button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                prefs.putString("username", username.getText());
                prefs.flush();
                String hostname = isGWT() ? "ws://" + serverData[0] : serverData[0];
                try {
                    ClientScreen clientScreen = new ClientScreen(game, hostname, Integer.parseInt(serverData[1]), username.getText());
                    game.setScreen(clientScreen);
                } catch (GdxRuntimeException e) {
                	MenuScreen.this.connectionLabel.setText("Connection Failed!");
                }
            }
        });
        serverView.addActor(button);
    }
    inner.add(serverView).expand().fill();
    table.add(inner);
    table.row();
    
    this.connectionLabel = new Label(" ", game.skin);
    this.table.add(this.connectionLabel);
    
}
 
Example 18
public EditSoundDialog(Skin skin, World parent, SoundDesc e) {
	super(skin);

	id = InputPanelFactory.createInputPanel(skin, "Sound ID", "The id of the sound", true);
	filename = InputPanelFactory.createInputPanel(skin, "Filename", "Filename of the sound",
			ModelTools.getSoundList(), true);
	loop = InputPanelFactory.createInputPanel(skin, "Loop", "True if the sound is looping", Param.Type.BOOLEAN,
			true, "false");
	volume = InputPanelFactory.createInputPanel(skin, "Volume", "Select the volume between 0 and 1",
			Param.Type.FLOAT, true, "1.0");
	pan = InputPanelFactory.createInputPanel(skin, "Pan",
			"Panning in the range -1 (full left) to 1 (full right). 0 is center position", Param.Type.FLOAT, true,
			"0.0");
	pitch = InputPanelFactory.createInputPanel(skin, "Pitch",
			"The pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0",
			Param.Type.FLOAT, true, "1.0");
	preload = InputPanelFactory.createInputPanel(skin, "Preload",
			"True if the sound has to be loaded when the scene is loaded.", Param.Type.BOOLEAN, true, "true");

	setInfo("Actors can have a list of sounds that can be associated to Sprites or played with the 'sound' action");

	init(parent, e, new InputPanel[] { id, filename, loop, volume, pan, pitch, preload });

	TextButton playButton = new TextButton("Play", skin, "no-toggled");

	playButton.addListener(new ChangeListener() {
		@Override
		public void changed(ChangeEvent event, Actor actor) {
			if (s != null) {
				s.dispose();
				s = null;
			}

			if (filename.getText() != null && !filename.getText().isEmpty()) {
				s = Gdx.audio.newSound(
						new FileHandle(Ctx.project.getAssetPath() + Project.SOUND_PATH + "/" + filename.getText()));

				s.play(Float.parseFloat(volume.getText()), Float.parseFloat(pitch.getText()),
						Float.parseFloat(pan.getText()));
			}

		}
	});

	Table bt = getButtonTable();
	bt.add(playButton);
}
 
Example 19
Source Project: gdx-ai   File: MessageTimerTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void create () {
	super.create();

	MessageManager.getInstance().clear();

	msgCounter = -1;

	testTable.add(new IntValueLabel("Message Counter: ", 0, container.skin) {
		@Override
		public int getValue () {
			return msgCounter;
		}
	}).left();

	testTable.row();
	testTable.add(new FloatValueLabel("Message Timestamp: ", 0, container.skin) {
		@Override
		public float getValue () {
			return msgTimestamp;
		}
	}).left();

	testTable.row();
	testTable.add(new FloatValueLabel("AI Time: ", 0, container.skin) {
		@Override
		public float getValue () {
			return GdxAI.getTimepiece().getTime();
		}
	}).left();

	testTable.row();
	timerEnabledButton = new TextButton("Stop timer", container.skin);
	timerEnabledButton.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			if (timerEnabledButton.isChecked()) {
				timerEnabledButton.setText("Stop Timer");
				sendMessage(0f, msgCounter + 1);
			} else {
				timerEnabledButton.setText("Start Timer");
			}

		}
	});
	testTable.add(timerEnabledButton).left();

	// Triggers the listener above, so sending the 1st message with no delay and counter 0
	timerEnabledButton.setChecked(true);
}
 
Example 20
Source Project: gdx-skineditor   File: FontPickerDialog.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 
 */
public FontPickerDialog(final SkinEditorGame game, Field field) {

	super("Bitmap Font Picker", game.skin);

	this.game = game;
	this.field = field;

	tableFonts = new Table(game.skin);
	tableFonts.left().top().pad(5);
	tableFonts.defaults().pad(5);

	fonts = game.skinProject.getAll(BitmapFont.class);

	updateTable();

	TextButton buttonNewFont = new TextButton("New Font", game.skin);
	buttonNewFont.addListener(new ChangeListener() {

		@Override
		public void changed(ChangeEvent event, Actor actor) {

			showNewFontDialog();

		}

	});


	ScrollPane scrollPane = new ScrollPane(tableFonts, game.skin);
	scrollPane.setFlickScroll(false);
	scrollPane.setFadeScrollBars(false);
	scrollPane.setScrollbarsOnTop(true);

	getContentTable().add(scrollPane).width(720).height(420).pad(20);
	getButtonTable().add(buttonNewFont);
	getButtonTable().padBottom(15);
	button("Cancel", false);
	key(com.badlogic.gdx.Input.Keys.ESCAPE, false);

}